diff --git a/Manifest.toml b/Manifest.toml index 804c596..b172a1b 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -12,31 +12,37 @@ git-tree-sha1 = "e214a9b9bd1b4e1b4f15b22c0994862b66af7ff7" uuid = "68821587-b530-5797-8361-c406ea357684" version = "3.5.0+3" +[[Artifacts]] +deps = ["Pkg"] +git-tree-sha1 = "c30985d8821e0cd73870b17b0ed0ce6dc44cb744" +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" +version = "1.3.0" + [[Base64]] uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" [[Compat]] deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] -git-tree-sha1 = "0198d18b28c093bef39872a22f1a897218a925f5" +git-tree-sha1 = "919c7f3151e79ff196add81d7f4e45d91bbf420b" uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" -version = "3.8.0" +version = "3.25.0" [[CompilerSupportLibraries_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "7c4f882c41faa72118841185afc58a2eb00ef612" +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "8e695f735fca77e9708e795eda62afdb869cbb70" uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "0.3.3+0" +version = "0.3.4+0" [[DataAPI]] -git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252" +git-tree-sha1 = "ad84f52c0b8f05aa20839484dbaf01690b41ff84" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" -version = "1.1.0" +version = "1.4.0" [[DataStructures]] deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "73eb18320fe3ba58790c8b8f6f89420f0a622773" +git-tree-sha1 = "88d48e133e6d3dd68183309877eac74393daa7eb" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.11" +version = "0.17.20" [[Dates]] deps = ["Printf"] @@ -58,20 +64,25 @@ version = "0.22.6" [[FillArrays]] deps = ["LinearAlgebra", "Random", "SparseArrays"] -git-tree-sha1 = "3eb5253af6186eada40de3df524a1c10f0c6bfa2" +git-tree-sha1 = "4863cbb7910079369e258dee4add9d06ead5063a" uuid = "1a297f60-69ca-5386-bcde-b61e274b549b" -version = "0.8.6" +version = "0.8.14" [[GLMNet]] deps = ["Distributed", "Distributions", "Printf", "Random", "SparseArrays", "StatsBase", "glmnet_jll"] -git-tree-sha1 = "bd82e0cc37f5061d1ce29a8376a774fba759cd68" +git-tree-sha1 = "7b2fd9b16e415f721d72b56f8b057e6919414762" uuid = "8d5ece8b-de18-5317-b113-243142960cc6" -version = "0.5.1" +version = "0.5.2" [[InteractiveUtils]] deps = ["Markdown"] uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" +[[JLLWrappers]] +git-tree-sha1 = "04b49c556240b62d5a799e94c63d5fc14d3c07cd" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.1.4" + [[LIBLINEAR]] deps = ["DelimitedFiles", "Libdl", "SparseArrays", "Test"] git-tree-sha1 = "42cacc29d9b4ae77b6702c181bbfa58f14d8ef7a" @@ -104,30 +115,29 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" [[Missings]] deps = ["DataAPI"] -git-tree-sha1 = "de0a5ce9e5289f27df672ffabef4d1e5861247d5" +git-tree-sha1 = "ed61674a0864832495ffe0a7e889c0da76b0f4c8" uuid = "e1d29d7a-bbdc-5cf2-9ac0-f12de2c33e28" -version = "0.4.3" +version = "0.4.4" [[Mmap]] uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[OpenBLAS_jll]] -deps = ["Libdl", "Pkg"] -git-tree-sha1 = "72163ef83570d258af87ed91f301c5b51a5e08e9" +deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] +git-tree-sha1 = "0c922fd9634e358622e333fc58de61f05a048492" uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" -version = "0.3.9+0" +version = "0.3.9+5" [[OpenSpecFun_jll]] -deps = ["CompilerSupportLibraries_jll", "Libdl", "Pkg"] -git-tree-sha1 = "d51c416559217d974a1113522d5919235ae67a87" +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "9db77584158d0ab52307f8c04f8e7c08ca76b5b3" uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" -version = "0.5.3+3" +version = "0.5.3+4" [[OrderedCollections]] -deps = ["Random", "Serialization", "Test"] -git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1" +git-tree-sha1 = "cf59cfed2e2c12e8a2ff0a4f1e9b2cd8650da6db" uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" -version = "1.1.0" +version = "1.3.2" [[PDMats]] deps = ["Arpack", "LinearAlgebra", "SparseArrays", "SuiteSparse", "Test"] @@ -141,9 +151,9 @@ uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [[PosDefManifold]] deps = ["LinearAlgebra", "Statistics"] -git-tree-sha1 = "47e697630cb91f4e27faab613361d67f47d4a5fd" +git-tree-sha1 = "9d2e1da251012e519228a386a39fe2aa32eee12e" uuid = "f45a3650-5c51-11e9-1e9a-133aa5e309cf" -version = "0.4.7" +version = "0.4.8" [[Printf]] deps = ["Unicode"] @@ -151,9 +161,9 @@ uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" [[QuadGK]] deps = ["DataStructures", "LinearAlgebra"] -git-tree-sha1 = "dc84e810393cfc6294248c9032a9cdacc14a3db4" +git-tree-sha1 = "12fbe86da16df6679be7521dfb39fbc861e1dc7b" uuid = "1fd47b50-473d-5c70-9696-f719f8f3bcdc" -version = "2.3.1" +version = "2.4.1" [[REPL]] deps = ["InteractiveUtils", "Markdown", "Sockets"] @@ -171,9 +181,9 @@ version = "0.6.1" [[Rmath_jll]] deps = ["Libdl", "Pkg"] -git-tree-sha1 = "1660f8fefbf5ab9c67560513131d4e933012fc4b" +git-tree-sha1 = "d76185aa1f421306dec73c057aa384bad74188f0" uuid = "f50d1b31-88e8-58de-be2c-1cc44531875f" -version = "0.2.2+0" +version = "0.2.2+1" [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" @@ -206,9 +216,9 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[SpecialFunctions]] deps = ["OpenSpecFun_jll"] -git-tree-sha1 = "e19b98acb182567bcb7b75bb5d9eedf3a3b5ec6c" +git-tree-sha1 = "d8d8b8a9f4119829410ecd706da4cc8594a1e020" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.10.0" +version = "0.10.3" [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"] @@ -222,9 +232,9 @@ version = "0.32.2" [[StatsFuns]] deps = ["Rmath", "SpecialFunctions"] -git-tree-sha1 = "f290ddd5fdedeadd10e961eb3f4d3340f09d030a" +git-tree-sha1 = "3b9f665c70712af3264b61c27a7e1d62055dafd1" uuid = "4c63d2b9-4356-54db-8cca-17b64c39e42c" -version = "0.9.4" +version = "0.9.6" [[SuiteSparse]] deps = ["Libdl", "LinearAlgebra", "Serialization", "SparseArrays"] diff --git a/Project.toml b/Project.toml index 9a74a8c..3da3d5f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PosDefManifoldML" uuid = "a07f4532-e2c9-11e9-2ea2-6d98fe4a1f21" authors = ["Marco-Congedo "] -version = "0.4.3" +version = "0.4.4" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" @@ -15,11 +15,11 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] -Distributions = "0.22" +Distributions = "0.22.6" +GLMNet = "0.5.2" LIBSVM = "0.4.0" -PosDefManifold = "0.4.7" -StatsBase = "0.32" -GLMNet = "0.5.1" +PosDefManifold = "0.4.8" +StatsBase = "0.32.2" julia = "1" [extras] diff --git a/docs/Manifest.toml b/docs/Manifest.toml index ad88a12..314bc96 100644 --- a/docs/Manifest.toml +++ b/docs/Manifest.toml @@ -13,15 +13,21 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" [[DocStringExtensions]] deps = ["LibGit2", "Markdown", "Pkg", "Test"] -git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a" +git-tree-sha1 = "50ddf44c53698f5e784bbebb3f4b21c5807401b1" uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" -version = "0.8.1" +version = "0.8.3" [[Documenter]] -deps = ["Base64", "Dates", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] -git-tree-sha1 = "646ebc3db49889ffeb4c36f89e5d82c6a26295ff" +deps = ["Base64", "Dates", "DocStringExtensions", "IOCapture", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Test", "Unicode"] +git-tree-sha1 = "a4875e0763112d6d017126f3944f4133abb342ae" uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4" -version = "0.24.7" +version = "0.25.5" + +[[IOCapture]] +deps = ["Logging"] +git-tree-sha1 = "377252859f740c217b936cebcd918a44f9b53b59" +uuid = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +version = "0.1.1" [[InteractiveUtils]] deps = ["Markdown"] @@ -29,9 +35,9 @@ uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" [[JSON]] deps = ["Dates", "Mmap", "Parsers", "Unicode"] -git-tree-sha1 = "b34d7cef7b337321e97d22242c3c2b91f476748e" +git-tree-sha1 = "81690084b6198a2e1da36fcfda16eeca9f9f24e4" uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" -version = "0.21.0" +version = "0.21.1" [[LibGit2]] deps = ["Printf"] @@ -51,10 +57,10 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[Parsers]] -deps = ["Dates", "Test"] -git-tree-sha1 = "75d07cb840c300084634b4991761886d0d762724" +deps = ["Dates"] +git-tree-sha1 = "50c9a9ed8c714945e01cd53a21007ed3865ed714" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "1.0.1" +version = "1.0.15" [[Pkg]] deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] diff --git a/docs/Project.toml b/docs/Project.toml index 280ce40..4287f24 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -1,8 +1,8 @@ authors = ["Marco Congedo, Saloni Jain, Anton Andreev"] -version = "0.4.2" +version = "0.4.4" [deps] Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" [compat] -Documenter = "~0.24" +Documenter = "~0.25" diff --git a/docs/src/MainModule.md b/docs/src/MainModule.md index 1c9ff39..3007567 100644 --- a/docs/src/MainModule.md +++ b/docs/src/MainModule.md @@ -20,21 +20,21 @@ The main module does not contain functions. As typical in machine learning packages, a type is created (a `struct` in Julia) to specify a ML model. *Supertype* -``` +```julia abstract type MLmodel end ``` is the abstract type for all machine learning models. *Supertype* -``` +```julia abstract type PDmodel<:MLmodel end ``` is the abstract type for all machine learning models acting on the positive definite (PD) **manifold** (for example, see [`MDM`](@ref)). *Supertype* -``` +```julia abstract type TSmodel<:MLmodel end ``` @@ -46,7 +46,7 @@ models acting on the **tangent space** (for example, see [`ENLR`](@ref)). In all concerned functions *class labels* are given as a vector of integers, of type -``` +```julia IntVector=Vector{Int} ``` @@ -57,7 +57,7 @@ of classes. ### working with metrics -In order to work with metrics for the manifold of positive definite matrices, make sure you install the *PosDefManifold* package. +In order to work with metrics for the manifold of positive definite matrices, make sure you install the *PosDefManifold* package. ### the ℍVector type diff --git a/docs/src/contribute.md b/docs/src/contribute.md index 6a729b5..052d248 100644 --- a/docs/src/contribute.md +++ b/docs/src/contribute.md @@ -17,13 +17,13 @@ Implementing your `ABC` model entails the following five steps: if your model acts on the manifold of PSD matrices, this will be -``` +```julia abstract type ABCmodel<:PDmodel end ``` if your model act on the tangent space, this will be -``` +```julia abstract type ABCmodel<:TSmodel end ``` @@ -31,7 +31,7 @@ abstract type ABCmodel<:TSmodel end This will look like: -``` +```julia mutable struct ABC <: ABCmodel metric :: Metric defaultkwarg1 :: Type_of_defaultkwarg1 @@ -67,7 +67,7 @@ if the `ABC` model has hyperparameters. Your `fit` function declaration will look like: -``` +```julia function fit( model :: ABCmodel, 𝐏Tr :: ℍVector, # if the model acts on the tangent space use: @@ -84,13 +84,13 @@ Here you can use as many `kwarg` arguments as you wish. Currently, all ML models have a `verbose` argument. Your `fit` function should starts with: -``` +```julia ⌚=now() # time in milliseconds ℳ=deepcopy(model) # output model ``` and ends with -``` +```julia verbose && println(defaultFont, "Done in ", now()-⌚,".") return ℳ ``` @@ -110,7 +110,7 @@ which should be given as options to the user, as done for these models. See how Once you have finished, a call such as -``` +```julia m1 = fit(ABC(), PTr, yTr) ``` @@ -123,7 +123,7 @@ to the `predict` function and return the model. Your `predict` function declaration will look like: -``` +```julia function predict(model :: ABCmodel, 𝐏Te :: Union{ℍVector, Matrix{Float64}}, # if the model acts on the tangent space use: @@ -139,13 +139,13 @@ where in general here you will not need `kwarg` arguments. Your `predict` function should starts with: -``` +```julia ⌚=now() # time in milliseconds ``` and ends with -``` +```julia verbose && println(defaultFont, "Done in ", now()-⌚,".") verbose && println(titleFont, "\nPredicted ",_what2Str(what),":", defaultFont) return 🃏 diff --git a/docs/src/index.md b/docs/src/index.md index 47a58f0..69e9fcb 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -31,11 +31,11 @@ To contribute, please check the secion [How to Contribute](@ref). ## About the Authors [Marco Congedo](https://sites.google.com/site/marcocongedo), corresponding -author, is a research scientist of [CNRS](http://www.cnrs.fr/en) (Centre National de la Recherche Scientifique), working at [UGA](https://www.univ-grenoble-alpes.fr/english/) (University of Grenoble Alpes). **Contact**: first name dot last name at gmail dot com +author, is a Research Director of [CNRS](http://www.cnrs.fr/en) (Centre National de la Recherche Scientifique), working at [UGA](https://www.univ-grenoble-alpes.fr/english/) (University of Grenoble Alpes). **Contact**: first name dot last name at gmail dot com Anton Andreev is a research engineer working at the same institution. -Saloni Jain is a student at the +Saloni Jain at the time of writing the package was a student at the [Indian Institute of Technology, Kharagpur](http://www.iitkgp.ac.in/), India. ## Overview diff --git a/docs/src/tutorial.md b/docs/src/tutorial.md index 434a221..9ac77c0 100644 --- a/docs/src/tutorial.md +++ b/docs/src/tutorial.md @@ -14,10 +14,10 @@ Furthermore, models acting on the tangent space can take as input Euclidean feat **get data** -A real data example will be added soon. For now, let us create simulated data for a **2-class example**. +Let us create simulated data for a **2-class example**. First, let us create symmetric positive definite matrices (real positive definite matrices): -``` +```julia using PosDefManifoldML, PosDefManifold PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1); @@ -40,7 +40,7 @@ The **minimum distance to mean (MDM)** classifier is an example of classifier ac An MDM model is created and fit with training data such as -``` +```julia m = fit(MDM(Fisher), PTr, yTr) ``` @@ -50,13 +50,13 @@ as declared in the parent package [PosDefManifold](https://marco-congedo.github. Since the Fisher metric is the default (for all ML models), the above is equivalent to: -``` +```julia m = fit(MDM(), PTr, yTr) ``` In order to adopt another metric: -``` +```julia m1 = fit(MDM(logEuclidean), PTr, yTr) ``` @@ -64,25 +64,25 @@ m1 = fit(MDM(logEuclidean), PTr, yTr) In order to predict the labels of unlabeled data (which we have stored in `PTe`), we invoke -``` +```julia yPred=predict(m, PTe, :l) ``` The prediction error in percent can be retrived with -``` +```julia predictErr(yTe, yPred) ``` the predicton accuracy as -``` +```julia predictAcc(yTe, yPred) ``` and the confusion matrix as -``` +```julia confusionMat(yTe, yPred) ``` @@ -91,13 +91,13 @@ matrices in `PTe`. If instead we wish to estimate the probabilities for the matrices in `PTe` of belonging to each class: -``` +```julia predict(m, PTe, :p) ``` Finally, the output functions of the MDM are obtaine by (see [`predict`](@ref)) -``` +```julia predict(m, PTe, :f) ``` @@ -105,7 +105,7 @@ predict(m, PTe, :f) The balanced accuracy estimated by a *k-fold cross-validation* is obtained such as (10-fold by default) -``` +```julia cv = cvAcc(MDM(), PTr, yTr) ``` @@ -113,7 +113,7 @@ Struct `cv` has been created and therein you have access to average accuracy and and confusion matrices for all folds. For example, print the average confusion matrix: -``` +```julia cv.avgCnf ``` @@ -131,7 +131,7 @@ that the [`fit`](@ref) and [`predict`](@ref) methods for ENLR models accept opti Let us get some simulated data (see the previous example for explanations). -``` +```julia PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1); ``` @@ -141,7 +141,7 @@ PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1); By default, the Fisher metric ic adopted and a lasso model is fitted. The best value for the lambda hyperparameter is found by cross-validation: -``` +```julia m1 = fit(ENLR(), PTr, yTr; w=:balanced) ``` @@ -150,50 +150,51 @@ argument (we may as well just use `w=:b`) we have requested to compute a balance The optimal value of lambda for this training data is -``` +```julia m1.best.lambda ``` As in *GLMNet.jl*, the intercept and beta terms are retrived by -``` + +```julia m1.best.a0 m1.best.betas ``` The number of non-zero beta coefficients can be found, for example, by -``` +```julia length(unique(m1.best.betas))-1 ``` In order to fit a ridge LR model: -``` +```julia m2 = fit(ENLR(), PTr, yTr; w=:b, alpha=0) ``` Values of `alpha` in range ``(0, 1)`` fit instead an elastic net LR model. In the following we also request not to standardize predictors: -``` +```julia m3 = fit(ENLR(Fisher), PTr, yTr; w=:b, alpha=0.9, standardize=false) ``` In order to find the regularization path we use the `fitType` keyword argument: -``` +```julia m1 = fit(ENLR(Fisher), PTr, yTr; w=:b, fitType=:path) ``` The values of lambda along the path are given by -``` +```julia m1.path.lambda ``` We can also find the best value of the lambda hyperparameter and the regularization path at once, calling: -``` +```julia m1 = fit(ENLR(Fisher), PTr, yTr; w=:b, fitType=:all) ``` @@ -212,7 +213,7 @@ Note that with the last call we have done here above both the `.best` and `.path By default, prediction is obtained from the best model and we request to predict the labels: -``` +```julia yPred=predict(m1, PTe) # prediction accuracy (in proportion) @@ -232,13 +233,13 @@ predict(m1, PTe, :f) In order to request the predition of labels for all models in the regularization path: -``` +```julia yPred=predict(m1, PTe, :l, :path, 0) ``` while for a specific model in the path (e.g., the 1Oth model): -``` +```julia yPred=predict(m1, PTe, :l, :path, 10) ``` @@ -248,14 +249,14 @@ The balanced accuracy estimated by a *k-fold cross-validation* is obtained with some specific optional keyword arguments for models acting in the tangent space, for example: -``` +```julia cv = cvAcc(ENLR(), PTr, yTr; w=:b) ``` In order to perform another cross-validation arranging the training data differently in the folds: -``` +```julia cv = cvAcc(ENLR(), PTr, yTr; w=:b, shuffle=true) ``` @@ -283,7 +284,7 @@ besides the linear one, which has no parameter. Like for ENLR, for SVM models al Let us get some simulated data as in the previous examples. -``` +```julia PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1); ``` @@ -293,7 +294,7 @@ PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1); By default, a C-Support Vector Classification model is fitted: -``` +```julia m1 = fit(SVM(), PTr, yTr; w=:b) ``` @@ -301,19 +302,19 @@ Notice that as for the example above with for ENLR model, we have requested to c In order to fit a Nu-Support Vector Classification model: -``` +```julia m2 = fit(SVM(), PTr, yTr; w=:b, svmType=NuSVC) ``` For using other kernels, e.g.: -``` +```julia m3 = fit(SVM(), PTr, yTr; w=:b, svmType=NuSVC, kernel=Linear) ``` In the following we also request not to rescale predictors: -``` +```julia m3 = fit(SVM(), PTr, yTr; w=:b, svmType=NuSVC, kernel=Linear, rescale=()) ``` @@ -328,7 +329,7 @@ details on all available optional arguments. Just the same as for the other models: -``` +```julia yPred=predict(m1, PTe) # prediction accuracy (in proportion) @@ -350,6 +351,6 @@ Again, the balanced accuracy estimated by a *k-fold cross-validation* is obtaine some specific optional keyword arguments for models acting in the tangent space, for example: -``` +```julia cv = cvAcc(SVM(), PTr, yTr; w=:b) ``` diff --git a/src/cv.jl b/src/cv.jl index 352a9db..3a5344c 100644 --- a/src/cv.jl +++ b/src/cv.jl @@ -11,7 +11,7 @@ # accuracy of all machine learning models. """ -``` +```julia struct CVacc cvType :: String scoring :: Union{String, Nothing} @@ -65,7 +65,7 @@ struct CVacc end """ -``` +```julia CVacc(s::String) = CVacc(s, nothing, nothing, nothing, nothing, nothing, nothing, nothing) @@ -79,7 +79,7 @@ CVacc(s::String)=CVacc(s, nothing, nothing, nothing, nothing, nothing, nothing, """ -``` +```julia function cvAcc(model :: MLmodel, 𝐏Tr :: ℍVector, yTr :: IntVector; @@ -151,7 +151,7 @@ for balancing weights. **See also**: [`fit`](@ref), [`predict`](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data @@ -298,11 +298,12 @@ end """ -``` +```julia function cvSetup(k :: Int, nCV :: Int; shuffle :: Bool = false) ``` + Given `k` elements and a parameter `nCV`, a nCV-fold cross-validation is obtained defining `nCV` permutations of *k* elements in *nTest=k÷nCV* (integer division) elements for the test and @@ -334,7 +335,7 @@ Return the 2-tuple with: - A vector of `nCV` vectors holding the indices for the corresponding test sets. **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold cvSetup(10, 2) diff --git a/src/enlr.jl b/src/enlr.jl index 16056c9..b150c93 100644 --- a/src/enlr.jl +++ b/src/enlr.jl @@ -11,7 +11,7 @@ # as specific instances. """ -``` +```julia abstract type ENLRmodel<:TSmodel end ``` @@ -22,7 +22,7 @@ abstract type ENLRmodel<:TSmodel end """ -``` +```julia mutable struct ENLR <: ENLRmodel metric :: Metric = Fisher; alpha :: Real = 1.0 @@ -37,6 +37,7 @@ mutable struct ENLR <: ENLRmodel best :: GLMNet.GLMNetPath end ``` + ENLR machine learning models are incapsulated in this mutable structure. Fields: @@ -81,7 +82,7 @@ It holds the regularization path that is created when the [`fit`](@ref) function is invoked with optional keyword parameter `fitType` = `:path` or = `:all`: -``` +```julia struct GLMNetPath{F<:Distribution} family::F # Binomial() a0::Vector{Float64} # intercept values for each solution @@ -101,7 +102,7 @@ cross-validation used for estimating the optimal lambda hyperparameter by the [`fit`](@ref) function when this is invoked with optional keyword parameter `fitType` = `:best` (default) or = `:all`: -``` +```julia struct GLMNetCrossValidation path::GLMNetPath # the cv path nfolds::Int # the number of folds for the cv @@ -119,7 +120,7 @@ when the [`fit`](@ref) function is invoked. **Examples**: -``` +```julia # Note: creating models with the default creator is possible, # but not useful in general. @@ -181,7 +182,7 @@ end """ -``` +```julia function fit(model :: ENLRmodel, 𝐏Tr :: Union{ℍVector, Matrix{Float64}}, yTr :: IntVector; @@ -415,7 +416,7 @@ for details [🎓](@ref). **Tutorial**: [Example using the ENLR model](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data @@ -568,7 +569,7 @@ end """ -``` +```julia function predict(model :: ENLRmodel, 𝐏Te :: Union{ℍVector, Matrix{Float64}}, what :: Symbol = :labels, @@ -643,7 +644,7 @@ tangent space is multi-threaded. **See also**: [`fit`](@ref), [`cvAcc`](@ref), [`predictErr`](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data diff --git a/src/mdm.jl b/src/mdm.jl index eb68c4d..9b87e7f 100644 --- a/src/mdm.jl +++ b/src/mdm.jl @@ -19,7 +19,7 @@ abstract type MDMmodel<:PDmodel end """ -``` +```julia mutable struct MDM <: MDMmodel metric :: Metric = Fisher; featDim :: Int @@ -59,7 +59,7 @@ It is used to optimize the computation of distances if the model is fitted useing the Fisher metric (default). **Examples**: -``` +```julia using PosDefManifoldML, PosDefManifold # create an empty model @@ -92,7 +92,7 @@ end """ -``` +```julia function fit(model :: MDMmodel, 𝐏Tr :: ℍVector, yTr :: IntVector; @@ -149,7 +149,7 @@ without crowding the REPL. **See also**: [`predict`](@ref), [`cvAcc`](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data @@ -213,7 +213,7 @@ end """ -``` +```julia function predict(model :: MDMmodel, 𝐏Te :: ℍVector, what :: Symbol = :labels; @@ -311,7 +311,7 @@ end """ -``` +```julia function getMean(metric :: Metric, 𝐏 :: ℍVector; w :: Vector = [], @@ -378,7 +378,7 @@ end """ -``` +```julia function getDistances(metric :: Metric, means :: ℍVector, 𝐏 :: ℍVector; diff --git a/src/svm.jl b/src/svm.jl index 1a1f98b..26cab25 100644 --- a/src/svm.jl +++ b/src/svm.jl @@ -9,7 +9,7 @@ # and it applies SVM classification using Julia's SVM wrapper. """ -``` +```julia abstract type SVMmodel<:TSmodel end ``` Abstract type for **Support-Vector Machine (SVM)** @@ -18,7 +18,7 @@ learning models. See [MLmodel](@ref). abstract type SVMmodel<:TSmodel end """ -``` +```julia mutable struct SVM <: SVMmodel metric :: Metric svmType :: Type @@ -81,7 +81,7 @@ see the documentation of the [`ENLR`](@ref) structure. (declared [here](https://github.com/mpastell/LIBSVM.jl/blob/master/src/LibSVMtypes.jl)). **Examples**: -``` +```julia # Note: creating models with the default creator is possible, # but not useful in general. @@ -146,7 +146,7 @@ end """ -``` +```julia function fit(model :: SVMmodel, 𝐏Tr :: Union{ℍVector, Matrix{Float64}}, yTr :: IntVector=[]; @@ -257,7 +257,7 @@ resources on the LIBSVM package [🎓](@ref). **Tutorial**: [Example using SVM models](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data @@ -377,7 +377,7 @@ end """ -``` +```julia function predict(model :: SVMmodel, 𝐏Te :: Union{ℍVector, Matrix{Float64}}, what :: Symbol = :labels; @@ -403,7 +403,7 @@ will be multi-threaded. **See also**: [`fit`](@ref), [`cvAcc`](@ref), [`predictErr`](@ref). **Examples** -``` +```julia using PosDefManifoldML, PosDefManifold # generate some data diff --git a/src/tools.jl b/src/tools.jl index 81c4758..d84dab2 100644 --- a/src/tools.jl +++ b/src/tools.jl @@ -10,7 +10,7 @@ # Riemannian and Euclidean machine learning classifiers. """ -``` +```julia function tsMap( metric :: Metric, 𝐏 :: ℍVector; w :: Vector = [], @@ -84,7 +84,7 @@ are multi-threaded. Multi-threading is automatically disabled if the number of threads Julia is instructed to use is *<2* or *<2k*. **Examples**: -``` +```julia using PosDefManifoldML # generate four random symmetric positive definite 3x3 matrices @@ -142,7 +142,7 @@ end """ -``` +```julia function tsWeights(y::Vector{Int}; classWeights=[]) ``` @@ -176,7 +176,7 @@ implicitly passing symbol `:balanced` (or just `:b`) or a tuple with the class weights as optional keyword argument `w`. **Examples** -``` +```julia # generate some data; the classes are unbalanced PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.1) @@ -194,8 +194,9 @@ m=fit(ENLR(), PTr, yTr; w=(0.5, 1.5)) # which is equivalent to m=fit(ENLR(), PTr, yTr; w=tsWeights(yTr; classWeights=(0.5, 1.5))) +``` -# This is how it works: +This is how it works: julia> y=[1, 1, 1, 1, 2, 2] 6-element Array{Int64,1}: @@ -235,7 +236,6 @@ julia> tsWeights(y, classWeights=[1, 4]) and, again, all weights sum up to 1 -``` """ function tsWeights(y::Vector{Int}; classWeights=[]) @@ -262,7 +262,7 @@ end """ -``` +```julia function gen2ClassData(n :: Int, k1train :: Int, k2train :: Int, @@ -292,7 +292,7 @@ Return a 4-tuple with **Examples** -``` +```julia using PosDefManifoldML PTr, PTe, yTr, yTe=gen2ClassData(10, 30, 40, 60, 80, 0.25) @@ -355,7 +355,7 @@ end """ -``` +```julia function confusionMat(yTrue::IntVector, yPred::IntVector) ``` @@ -377,7 +377,7 @@ Therefore, the entries of the confusion matrix sum up to 1.0. **Examples** -``` +```julia using PosDefManifoldML julia> confusionMat([1, 1, 1, 2, 2], [1, 1, 1, 1, 2]) # return: [0.6 0.0; 0.2 0.2] @@ -405,7 +405,7 @@ function confusionMat(yTrue::IntVector, yPred::IntVector) end """ -``` +```julia (1) function predictAcc(yTrue::IntVector, yPred::IntVector; scoring:: Symbol = :b, @@ -446,7 +446,7 @@ and their mean is taken. **Examples** -``` +```julia using PosDefManifoldML julia> predictAcc([1, 1, 1, 2, 2], [1, 1, 1, 1, 2]; scoring=:a) # regular accuracy, return: 0.8 @@ -498,7 +498,7 @@ end """ -``` +```julia (1) function predictErr(yTrue::IntVector, yPred::IntVector; scoring:: Symbol = :b, @@ -530,7 +530,7 @@ predictErr(CM:: Matrix{R}; scoring=scoring, digits=8))≠nothing ? round(1.0-acc; digits=digits) : nothing """ -``` +```julia function rescale!(X::Matrix{T}, bounds::Tuple=(-1, 1); dims::Int=1) where T<:Real ```