Created
July 6, 2021 00:22
-
-
Save pazzo83/61b09a3821145baf889896c6f4160d6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MLJModelInterface, MLJBase, TSVD | |
MLJModelInterface.@mlj_model mutable struct TSVDTransformer <: MLJModelInterface.Unsupervised | |
nvals::Int = 2 | |
maxiter::Int = 1000 | |
end | |
struct TSVDTransformerResult | |
singular_values::Vector{Float64} | |
components::Matrix{Float64} | |
end | |
function MLJBase.fit(transformer::TSVDTransformer, verbosity::Int, X) | |
U, s, V = tsvd(X, transformer.nvals; maxiter=transformer.maxiter) | |
res = TSVDTransformerResult(s, V) | |
return res, nothing, NamedTuple() | |
end | |
function MLJBase.transform(::TSVDTransformer, result, X) | |
X_transformed = X * result.components | |
return X_transformed | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Done: https://github.com/JuliaAI/MLJTSVDInterface.jl .
It's still private for now.