-
Notifications
You must be signed in to change notification settings - Fork 2
/
kplsqda.jl
53 lines (47 loc) · 1.82 KB
/
kplsqda.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
kplsqda(X, y; kwargs...)
kplsqda(X, y, weights::Weight; kwargs...)
KPLS-QDA.
* `X` : X-data (n, p).
* `y` : Univariate class membership (n).
* `weights` : Weights (n) of the observations.
Must be of type `Weight` (see e.g. function `mweight`).
Keyword arguments:
* `nlv` : Nb. latent variables (LVs) to compute.
Must be >= 1
* `kern` : Type of kernel used to compute the Gram matrices.
Possible values are: `:krbf`, `:kpol`. See respective
functions `krbf` and `kpol` for their keyword arguments.
* `prior` : Type of prior probabilities for class
membership. Possible values are: `:unif` (uniform),
`:prop` (proportional), or a vector (of length equal to
the number of classes) giving the prior weight for each class
(the vector must be sorted in the same order as `mlev(x)`).
* `alpha` : Scalar (∈ [0, 1]) defining the continuum
between QDA (`alpha = 0`) and LDA (`alpha = 1`).
* `scal` : Boolean. If `true`, each column of `X`
is scaled by its uncorrected standard deviation.
Same as function `plsqda` (PLS-QDA) except that
a kernel PLSR (function `kplsr`), instead of a
PLSR (function `plskern`), is run on the Y-dummy table.
See function `kplslda` for examples.
"""
function kplsqda(X, y; kwargs...)
par = recovkwargs(Par, kwargs)
Q = eltype(X[1, 1])
weights = mweightcla(Q, y; prior = par.prior)
kplsqda(X, y, weights; kwargs...)
end
function kplsqda(X, y, weights::Weight; kwargs...)
par = recovkwargs(Par, kwargs)
@assert par.nlv >= 1 "Argument 'nlv' must be in >= 1"
res = dummy(y)
ni = tab(y).vals
fmpls = kplsr(X, res.Y, weights; kwargs...)
fmda = list(Qda, par.nlv)
@inbounds for i = 1:par.nlv
fmda[i] = qda(fmpls.T[:, 1:i], y, weights; kwargs...)
end
fm = (fmpls = fmpls, fmda = fmda)
Plslda(fm, res.lev, ni)
end