Skip to content

Commit 49f1173

Browse files
committed
wrapping up
1 parent 7b10973 commit 49f1173

File tree

1 file changed

+28
-103
lines changed

1 file changed

+28
-103
lines changed

src/MLJMultivariateStatsInterface.jl

Lines changed: 28 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -33,81 +33,6 @@ const FactorAnalysisResultType = MS.FactorAnalysis
3333
const default_kernel = (x, y) -> x'y #default kernel used in KernelPCA
3434

3535
# Definitions of model descriptions for use in model doc-strings.
36-
const PCA_DESCR = """
37-
Principal component analysis. Learns a linear transformation to
38-
project the data on a lower dimensional space while preserving most of the initial
39-
variance.
40-
"""
41-
const KPCA_DESCR = "Kernel principal component analysis."
42-
const ICA_DESCR = "Independent component analysis."
43-
const PPCA_DESCR = "Probabilistic principal component analysis"
44-
const FactorAnalysis_DESCR = "Factor Analysis"
45-
const LDA_DESCR = """
46-
Multiclass linear discriminant analysis. The algorithm learns a
47-
projection matrix `P` that projects a feature matrix `Xtrain` onto a lower dimensional
48-
space of dimension `outdim` such that the trace of the transformed between-class
49-
scatter matrix(`Pᵀ*Sb*P`) is maximized relative to the trace of the transformed
50-
within-class scatter matrix (`Pᵀ*Sw*P`).The projection matrix is scaled such that
51-
`Pᵀ*Sw*P=I` or `Pᵀ*Σw*P=I`(where `Σw` is the within-class covariance matrix) .
52-
Predicted class posterior probability for feature matrix `Xtest` are derived by
53-
applying a softmax transformationto a matrix `Pr`, such that rowᵢ of `Pr` contains
54-
computed distances(based on a distance metric) in the transformed space of rowᵢ in
55-
`Xtest` to the centroid of each class.
56-
"""
57-
const BayesianLDA_DESCR = """
58-
Bayesian Multiclass linear discriminant analysis. The algorithm
59-
learns a projection matrix `P` that projects a feature matrix `Xtrain` onto a lower
60-
dimensional space of dimension `outdim` such that the trace of the transformed
61-
between-class scatter matrix(`Pᵀ*Sb*P`) is maximized relative to the trace of the
62-
transformed within-class scatter matrix (`Pᵀ*Sw*P`). The projection matrix is scaled
63-
such that `Pᵀ*Sw*P = n` or `Pᵀ*Σw*P=I` (Where `n` is the number of training samples
64-
and `Σw` is the within-class covariance matrix).
65-
Predicted class posterior probability distibution are derived by applying Bayes rule
66-
with a multivariate Gaussian class-conditional distribution.
67-
"""
68-
const SubspaceLDA_DESCR = """
69-
Multiclass linear discriminant analysis. Suitable for high
70-
dimensional data (Avoids computing scatter matrices `Sw` ,`Sb`). The algorithm learns a
71-
projection matrix `P = W*L` that projects a feature matrix `Xtrain` onto a lower
72-
dimensional space of dimension `min(rank(Sw), nc - 1)` such that the trace of the transformed
73-
between-class scatter matrix(`Pᵀ*Sb*P`) is maximized relative to the trace of the
74-
transformed within-class scatter matrix (`Pᵀ*Sw*P`). The projection matrix is scaled
75-
such that `Pᵀ*Sw*P = mult*I` or `Pᵀ*Σw*P=mult/(n-nc)*I` (where `n` is the number of
76-
training samples, mult` is one of `n` or `1` depending on whether `Sb` is normalized,
77-
`Σw` is the within-class covariance matrix, and `nc` is the number of unique classes
78-
in `y`) and also obeys `Wᵀ*Sb*p = λ*Wᵀ*Sw*p`, for every column `p` in `P`.
79-
Predicted class posterior probability for feature matrix `Xtest` are derived by
80-
applying a softmax transformation to a matrix `Pr`, such that rowᵢ of `Pr` contains
81-
computed distances(based on a distance metric) in the transformed space of rowᵢ in
82-
`Xtest` to the centroid of each class.
83-
"""
84-
const BayesianSubspaceLDA_DESCR = """
85-
Bayesian Multiclass linear discriminant analysis. Suitable for high dimensional data
86-
(Avoids computing scatter matrices `Sw` ,`Sb`). The algorithm learns a projection
87-
matrix `P = W*L` (`Sw`), that projects a feature matrix `Xtrain` onto a lower
88-
dimensional space of dimension `nc-1` such that the trace of the transformed
89-
between-class scatter matrix(`Pᵀ*Sb*P`) is maximized relative to the trace of the
90-
transformed within-class scatter matrix (`Pᵀ*Sw*P`). The projection matrix is scaled
91-
such that `Pᵀ*Sw*P = mult*I` or `Pᵀ*Σw*P=mult/(n-nc)*I` and also obeys `Wᵀ*Sb*p = λ*Wᵀ*Sw*p`, for every column `p` in `P`.
92-
Posterior class probability distibution are derived by applying Bayes rule with a
93-
multivariate Gaussian class-conditional distribution
94-
"""
95-
const LinearRegressor_DESCR = """
96-
Linear Regression. Learns a linear combination of given
97-
variables to fit the response by minimizing the squared error between.
98-
"""
99-
const MultitargetLinearRegressor_DESCR = """
100-
Multitarget Linear Regression. Learns linear combinations of given
101-
variables to fit the responses by minimizing the squared error between.
102-
"""
103-
const RidgeRegressor_DESCR = """
104-
Ridge regressor with regularization parameter lambda. Learns a
105-
linear regression with a penalty on the l2 norm of the coefficients.
106-
"""
107-
const MultitargetRidgeRegressor_DESCR = """
108-
Multitarget Ridge regressor with regularization parameter lambda. Learns a
109-
Multitarget linear regression with a penalty on the l2 norm of the coefficients.
110-
"""
11136
const PKG = "MLJMultivariateStatsInterface"
11237

11338
# ===================================================================
@@ -430,13 +355,13 @@ Train the machine using `fit!(mach, rows=...)`.
430355
431356
# Hyper-parameters
432357
433-
- `maxoutdim=0`: Together with `pratio`, controls the output dimension outdim chosen
358+
- `maxoutdim=0`: Together with `variance_ratio`, controls the output dimension outdim chosen
434359
by the model. Specifically, suppose that k is the smallest integer such that retaining
435-
the k most significant principal components accounts for `pratio` of the total variance
436-
in the training data. Then outdim = min(k, maxoutdim). If maxoutdim=0 (default) then the
360+
the k most significant principal components accounts for `variance_ratio` of the total variance
361+
in the training data. Then outdim = min(outdim, maxoutdim). If maxoutdim=0 (default) then the
437362
effective maxoutdim is min(n, indim - 1) where n is the number of observations and indim
438363
the number of features in the training data.
439-
- `pratio::Float64=0.99`: The ratio of variance preserved after the transformation
364+
- `variance_ratio::Float64=0.99`: The ratio of variance preserved after the transformation
440365
- `method=:auto`: The method to use to solve the problem. Choices are
441366
- `:svd`: Support Vector Decomposition of the matrix.
442367
- `:cov`: Covariance matrix decomposition.
@@ -607,7 +532,7 @@ Train the machine using `fit!(mach, rows=...)`.
607532
608533
# Hyper-parameters
609534
610-
- `k::Int=0`: The number of independent components to recover, set automatically if `0`.
535+
- `outdim::Int=0`: The number of independent components to recover, set automatically if `0`.
611536
- `alg::Symbol=:fastica`: The algorithm to use (only `:fastica` is supported at the moment).
612537
- `fun::Symbol=:tanh`: The approximate neg-entropy function, one of `:tanh`, `:gaus`.
613538
- `do_whiten::Bool=true`: Whether or not to perform pre-whitening.
@@ -630,7 +555,8 @@ Train the machine using `fit!(mach, rows=...)`.
630555
631556
The fields of `fitted_params(mach)` are:
632557
633-
# TODO: Now that this is fixed, document
558+
- `projection`: The estimated component matrix.
559+
- `mean`: The estimated mean vector.
634560
635561
# Report
636562
@@ -661,7 +587,7 @@ signal = permutedims(hcat(signal...))'
661587
mixing_matrix = [ 1 1 1; 0.5 2 1; 1.5 1 2]
662588
X = MLJ.table(signal * mixing_matrix)
663589
664-
model = ICA(k = 3, tol=0.1)
590+
model = ICA(outim = 3, tol=0.1)
665591
mach = machine(model, X) |> fit! # this errors ERROR: MethodError: no method matching size(::MultivariateStats.ICA{Float64}, ::Int64)
666592
667593
Xproj = transform(mach, X)
@@ -737,7 +663,7 @@ The fields of `fitted_params(mach)` are:
737663
738664
- `projected_class_means`: The matrix comprised of class-specific means as columns,
739665
of size `(indim, nc)`, where `indim` is the number of input features (columns) and
740-
`nc` the number of target classes.
666+
`nclasses` the number of target classes.
741667
- `projection_matrix`: The learned projection matrix, of size `(indim, outdim)`, where
742668
`indim` and `outdim` are the input and output dimensions respectively.
743669
@@ -747,13 +673,13 @@ The fields of `report(mach)` are:
747673
748674
- `classes`: The classes seen during model fitting.
749675
- `outdim`: The dimensions the model is projected to.
750-
- `class_means`: The matrix comprised of class-specific means as
676+
- `projected_class_means`: The matrix comprised of class-specific means as
751677
columns (see above).
752678
- `mean`: The mean of the untransformed training data, of length `indim`.
753679
- `class_weights`: The weights of each class.
754680
- `Sb`: The between class scatter matrix.
755681
- `Sw`: The within class scatter matrix.
756-
- `nc`: The number of classes directly observed in the training data (which can be
682+
- `nclasses`: The number of classes directly observed in the training data (which can be
757683
less than the total number of classes in the class pool)
758684
759685
# Examples
@@ -847,7 +773,7 @@ The fields of `fitted_params(mach)` are:
847773
848774
- `projected_class_means`: The matrix comprised of class-specific means as columns,
849775
of size `(indim, nc)`, where `indim` is the number of input features (columns) and
850-
`nc` the number of target classes.
776+
`nclasses` the number of target classes.
851777
- `projection_matrix`: The learned projection matrix, of size `(indim, outdim)`, where
852778
`indim` and `outdim` are the input and output dimensions respectively.
853779
- `priors`: The class priors for classification. As inferred from training target `y`,
@@ -859,25 +785,25 @@ The fields of `report(mach)` are:
859785
860786
- `classes`: The classes seen during model fitting.
861787
- `outdim`: The dimensions the model is projected to.
862-
- `class_means`: The matrix comprised of class-specific means as
788+
- `projected_class_means`: The matrix comprised of class-specific means as
863789
columns (see above).
864790
- `mean`: The mean of the untransformed training data, of length `indim`.
865791
- `class_weights`: The weights of each class.
866792
- `Sb`: The between class scatter matrix.
867793
- `Sw`: The within class scatter matrix.
868-
- `nc`: The number of classes directly observed in the training data (which can be
794+
- `nclasses`: The number of classes directly observed in the training data (which can be
869795
less than the total number of classes in the class pool)
870796
871797
# Examples
872798
873799
```
874800
using MLJ
875801
876-
BLDA = @load BayesianLDA pkg=MultivariateStats
802+
BayesianLDA = @load BayesianLDA pkg=MultivariateStats
877803
878804
X, y = @load_iris # a table and a vector
879805
880-
model = BLDA()
806+
model = BayesianLDA()
881807
mach = machine(model, X, y) |> fit!
882808
883809
Xproj = transform(mach, X)
@@ -903,7 +829,6 @@ In the case of classification, the class probability for a new observation
903829
reflects the proximity of that observation to training observations
904830
associated with that class, and how far away the observation is from those
905831
associated with other classes. Specifically, the distances, in the transformed
906-
(projected) space, of a new observation, from the centroid of each target class,
907832
is computed; the resulting vector of distances (times minus one) is passed to a
908833
softmax function to obtain a class probability prediction. Here "distance"
909834
is computed using a user-specified distance function.
@@ -952,33 +877,34 @@ Train the machine using `fit!(mach, rows=...)`.
952877
953878
The fields of `fitted_params(mach)` are:
954879
955-
- `class_means`: The matrix comprised of class-specific means as
880+
- `projected_class_means`: The matrix comprised of class-specific means as
956881
columns (of size `(d,m)`), where d corresponds to input features and m corresponds to class.
957-
- `projection_matrix`: The matrix used to project `X` into a lower dimensional space.
882+
- `projection_matrix`: The learned projection matrix, of size `(indim, outdim)`, where
883+
`indim` and `outdim` are the input and output dimensions respectively.
958884
959885
# Report
960886
961887
The fields of `report(mach)` are:
962888
963889
- `explained_variance_ratio`: The ratio of explained variance to total variance. Each dimension corresponds to an eigenvalue.
964890
- `classes`: The classes seen during model fitting.
965-
- `class_means`: The matrix comprised of class-specific means as
891+
- `projected_class_means`: The matrix comprised of class-specific means as
966892
columns (see above).
967893
- `mean`: The mean of the untransformed training data, of length `indim`.
968894
- `class_weights`: The weights of each class.
969-
- `nc`: The number of classes directly observed in the training data (which can be
895+
- `nclasses`: The number of classes directly observed in the training data (which can be
970896
less than the total number of classes in the class pool)
971897
972898
# Examples
973899
974900
```
975901
using MLJ
976902
977-
SLDA = @load SubspaceLDA pkg=MultivariateStats
903+
SubspaceLDA = @load SubspaceLDA pkg=MultivariateStats
978904
979905
X, y = @load_iris # a table and a vector
980906
981-
model = SLDA()
907+
model = SubspaceLDA()
982908
mach = machine(model, X, y) |> fit!
983909
984910
Xproj = transform(mach, X)
@@ -992,7 +918,6 @@ See also
992918
SubspaceLDA
993919

994920
"""
995-
996921
$(MMI.doc_header(BayesianSubspaceLDA))
997922
998923
@@ -1048,7 +973,7 @@ The fields of `fitted_params(mach)` are:
1048973
1049974
- `projected_class_means`: The matrix comprised of class-specific means as columns,
1050975
of size `(indim, nc)`, where `indim` is the number of input features (columns) and
1051-
`nc` the number of target classes.
976+
`nclasses` the number of target classes.
1052977
- `projection_matrix`: The learned projection matrix, of size `(indim, outdim)`, where
1053978
`indim` and `outdim` are the input and output dimensions respectively.
1054979
- `priors`: The class priors for classification. As inferred from training target `y`,
@@ -1060,23 +985,23 @@ The fields of `report(mach)` are:
1060985
1061986
- `explained_variance_ratio`: The ratio of explained variance to total variance. Each dimension corresponds to an eigenvalue.
1062987
- `classes`: The classes seen during model fitting.
1063-
- `class_means`: The matrix comprised of class-specific means as
988+
- `projected_class_means`: The matrix comprised of class-specific means as
1064989
columns (see above).
1065990
- `mean`: The mean of the untransformed training data, of length `indim`.
1066991
- `class_weights`: The weights of each class.
1067-
- `nc`: The number of classes directly observed in the training data (which can be
992+
- `nclasses`: The number of classes directly observed in the training data (which can be
1068993
less than the total number of classes in the class pool)
1069994
1070995
# Examples
1071996
1072997
```
1073998
using MLJ
1074999
1075-
BSLDA = @load BayesianSubspaceLDA pkg=MultivariateStats
1000+
BayesianSubspaceLDA = @load BayesianSubspaceLDA pkg=MultivariateStats
10761001
10771002
X, y = @load_iris # a table and a vector
10781003
1079-
model = BSLDA()
1004+
model = BayesianSubspaceLDA()
10801005
mach = machine(model, X, y) |> fit!
10811006
10821007
Xproj = transform(mach, X)

0 commit comments

Comments
 (0)