Skip to content

Commit 99cf02c

Browse files
authored
Merge pull request #33 from JuliaAI/change-default-hyperparameters
Change default hyperparameter `inverse` in `KernelPCA`
2 parents 1d5a86a + b04463d commit 99cf02c

File tree

3 files changed

+29
-29
lines changed

3 files changed

+29
-29
lines changed

src/models/decomposition_models.jl

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ $PCA_DESCR
99
1010
# Keyword Parameters
1111
12-
- `maxoutdim::Int=0`: maximum number of output dimensions, uses the smallest dimension of
12+
- `maxoutdim::Int=0`: maximum number of output dimensions, uses the smallest dimension of
1313
training feature matrix if 0 (default).
14-
- `method::Symbol=:auto`: method to use to solve the problem, one of `:auto`,`:cov`
14+
- `method::Symbol=:auto`: method to use to solve the problem, one of `:auto`,`:cov`
1515
or `:svd`
1616
- `pratio::Float64=0.99`: ratio of variance preserved
17-
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: if set to nothing(default)
18-
centering will be computed and applied, if set to `0` no
19-
centering(assumed pre-centered), if a vector is passed, the centering is done with
17+
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: if set to nothing(default)
18+
centering will be computed and applied, if set to `0` no
19+
centering(assumed pre-centered), if a vector is passed, the centering is done with
2020
that vector.
2121
"""
2222
@mlj_model mutable struct PCA <: MMI.Unsupervised
@@ -74,14 +74,14 @@ $KPCA_DESCR
7474
7575
# Keyword Parameters
7676
77-
- `maxoutdim::Int = 0`: maximum number of output dimensions, uses the smallest
77+
- `maxoutdim::Int = 0`: maximum number of output dimensions, uses the smallest
7878
dimension of training feature matrix if 0 (default).
79-
- `kernel::Function=(x,y)->x'y`: kernel function of 2 vector arguments x and y, returns a
79+
- `kernel::Function=(x,y)->x'y`: kernel function of 2 vector arguments x and y, returns a
8080
scalar value
81-
- `solver::Symbol=:auto`: solver to use for the eigenvalues, one of `:eig`(default),
81+
- `solver::Symbol=:auto`: solver to use for the eigenvalues, one of `:eig`(default),
8282
`:eigs`
83-
- `inverse::Bool=false`: perform calculation for inverse transform
84-
- `beta::Real=1.0`: strength of the ridge regression that learns the inverse transform
83+
- `inverse::Bool=true`: perform calculations needed for inverse transform
84+
- `beta::Real=1.0`: strength of the ridge regression that learns the inverse transform
8585
when inverse is true
8686
- `tol::Real=0.0`: Convergence tolerance for eigs solver
8787
- `maxiter::Int=300`: maximum number of iterations for eigs solver
@@ -90,7 +90,7 @@ $KPCA_DESCR
9090
maxoutdim::Int = 0::(_ ≥ 0)
9191
kernel::Union{Nothing, Function} = default_kernel
9292
solver::Symbol = :eig::(_ in (:eig, :eigs))
93-
inverse::Bool = false
93+
inverse::Bool = true
9494
beta::Real = 1.0::(_ ≥ 0.0)
9595
tol::Real = 1e-6::(_ ≥ 0.0)
9696
maxiter::Int = 300::(_ ≥ 1)
@@ -102,7 +102,7 @@ function MMI.fit(model::KernelPCA, verbosity::Int, X)
102102
# default max out dim if not given
103103
maxoutdim = model.maxoutdim == 0 ? mindim : model.maxoutdim
104104
fitresult = MS.fit(
105-
MS.KernelPCA,
105+
MS.KernelPCA,
106106
permutedims(Xarray);
107107
kernel=model.kernel,
108108
maxoutdim=maxoutdim,
@@ -143,17 +143,17 @@ $ICA_DESCR
143143
144144
- `k::Int=0`: number of independent components to recover, set automatically if `0`
145145
- `alg::Symbol=:fastica`: algorithm to use (only `:fastica` is supported at the moment)
146-
- `fun::Symbol=:tanh`: approximate neg-entropy functor, via the function
146+
- `fun::Symbol=:tanh`: approximate neg-entropy functor, via the function
147147
`MultivariateStats.icagfun`, one of `:tanh` and `:gaus`
148148
- `do_whiten::Bool=true`: whether to perform pre-whitening
149149
- `maxiter::Int=100`: maximum number of iterations
150150
- `tol::Real=1e-6`: convergence tolerance for change in matrix W
151-
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: mean to use, if nothing (default)
152-
centering is computed andapplied, if zero, no centering, a vector of means can
151+
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: mean to use, if nothing (default)
152+
centering is computed andapplied, if zero, no centering, a vector of means can
153153
be passed
154-
- `winit::Union{Nothing,Matrix{<:Real}}=nothing`: initial guess for matrix `W` either
155-
an empty matrix (random initilization of `W`), a matrix of size `k × k` (if `do_whiten`
156-
is true), a matrix of size `m × k` otherwise. If unspecified i.e `nothing` an empty
154+
- `winit::Union{Nothing,Matrix{<:Real}}=nothing`: initial guess for matrix `W` either
155+
an empty matrix (random initilization of `W`), a matrix of size `k × k` (if `do_whiten`
156+
is true), a matrix of size `m × k` otherwise. If unspecified i.e `nothing` an empty
157157
`Matrix{<:Real}` is used.
158158
"""
159159
@mlj_model mutable struct ICA <: MMI.Unsupervised
@@ -216,14 +216,14 @@ $PPCA_DESCR
216216
217217
# Keyword Parameters
218218
219-
- `maxoutdim::Int=0`: maximum number of output dimensions, uses max(no_of_features - 1, 1)
219+
- `maxoutdim::Int=0`: maximum number of output dimensions, uses max(no_of_features - 1, 1)
220220
if 0 (default).
221221
- `method::Symbol=:ml`: method to use to solve the problem, one of `:ml`, `:em`, `:bayes`.
222222
- `maxiter::Int=1000`: maximum number of iterations.
223223
- `tol::Real=1e-6`: convergence tolerance.
224-
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: if set to nothing(default)
225-
centering will be computed and applied, if set to `0` no
226-
centering(assumed pre-centered), if a vector is passed, the centering is done with
224+
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: if set to nothing(default)
225+
centering will be computed and applied, if set to `0` no
226+
centering(assumed pre-centered), if a vector is passed, the centering is done with
227227
that vector.
228228
"""
229229
@mlj_model mutable struct PPCA <: MMI.Unsupervised
@@ -278,14 +278,14 @@ $PPCA_DESCR
278278
# Keyword Parameters
279279
280280
- `method::Symbol=:cm`: Method to use to solve the problem, one of `:ml`, `:em`, `:bayes`.
281-
- `maxoutdim::Int=0`: Maximum number of output dimensions, uses max(no_of_features - 1, 1)
281+
- `maxoutdim::Int=0`: Maximum number of output dimensions, uses max(no_of_features - 1, 1)
282282
if 0 (default).
283283
- `maxiter::Int=1000`: Maximum number of iterations.
284284
- `tol::Real=1e-6`: Convergence tolerance.
285285
- `eta::Real=tol`: Variance lower bound
286-
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: If set to nothing(default)
287-
centering will be computed and applied, if set to `0` no
288-
centering(assumed pre-centered), if a vector is passed, the centering is done with
286+
- `mean::Union{Nothing, Real, Vector{Float64}}=nothing`: If set to nothing(default)
287+
centering will be computed and applied, if set to `0` no
288+
centering(assumed pre-centered), if a vector is passed, the centering is done with
289289
that vector.
290290
"""
291291
@mlj_model mutable struct FactorAnalysis <: MMI.Unsupervised

test/models/decomposition_models.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ end
2222
inverse=true
2323
)
2424
# MLJ KernelPCA
25-
kpca_mlj = KernelPCA(inverse=true)
25+
kpca_mlj = KernelPCA()
2626
test_composition_model(kpca_ms, kpca_mlj, X, X_array)
2727
end
2828

test/testutils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function make_regression2(n=100, p=3, c=5;intercept=true, noise=0.1, rng=nothing
44
elseif rng isa Integer
55
rng = Random.MersenneTwister(rng)
66
end
7-
7+
88
X = randn(rng, n, p)
99
X = MLJBase.augment_X(randn(rng, n, p), intercept)
1010
A = randn(rng, p + Int(intercept), c)
@@ -23,7 +23,7 @@ function test_composition_model(ms_model, mlj_model, X, X_array ; test_inverse=t
2323
mlj_model_type = typeof(mlj_model)
2424
Xtr_ms = permutedims(
2525
MultivariateStats.predict(ms_model, permutedims(X_array))
26-
)
26+
)
2727
fitresult, _, _ = fit(mlj_model, 1, X)
2828
Xtr_mlj_table = transform(mlj_model, fitresult, X)
2929
Xtr_mlj = matrix(Xtr_mlj_table)

0 commit comments

Comments
 (0)