Skip to content

Commit 4d6f539

Browse files
committed
dev
1 parent 87ab57b commit 4d6f539

6 files changed

Lines changed: 28 additions & 18 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PosDefManifoldML"
22
uuid = "a07f4532-e2c9-11e9-2ea2-6d98fe4a1f21"
33
authors = ["Marco-Congedo <marco.congedo@gmail.com>"]
4-
version = "0.5.10"
4+
version = "0.5.11"
55

66
[deps]
77
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

docs/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
authors = ["Marco Congedo, Fahim Doumi, Saloni Jain, Anton Andreev"]
2-
version = "0.5.10"
2+
version = "0.5.11"
33

44
[deps]
55
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

src/PosDefManifoldML.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Unit "simulations.jl" of the PosDefManifoldML Package for Julia language
2-
# v 0.5.10 - last update June 2025
2+
# v 0.5.11 - last update June 2025
33
#
44
# MIT License
55
# Copyright (c) 2019-2025,

src/cv.jl

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ Currently *accuracy* and *balanced accuracy* are supported.
4444
`.modelType` is the type of the machine learning model used for performing the
4545
cross-validation, given as a string.
4646
47+
`.nTrials` is the total number of trials entering the cross-validation
48+
49+
`.matSize` is the size of the input matrices (trials)
50+
4751
`.predLabels` is an `f`-vector of `z` integer vectors holding the vectors of
4852
predicted labels. There is one vector for each fold (`f`) and each containes
4953
as many vector as classes (`z`), in turn each one containing the predicted labels
@@ -86,6 +90,8 @@ struct CVres <: CVresult
8690
cvType :: String
8791
scoring :: Union{String, Nothing}
8892
modelType :: Union{String, Nothing}
93+
nTrials :: Union{Int, Nothing}
94+
matSize :: Union{Int, Nothing}
8995
predLabels :: Union{Vector{Vector{Vector{I}}}, Nothing} where I<:Int
9096
losses :: Union{Vector{BitVector}, Nothing}
9197
cnfs :: Union{Vector{Matrix{I}}, Nothing} where I<:Int
@@ -101,16 +107,16 @@ end
101107
"""
102108
```julia
103109
CVres(s::String) =
104-
CVres(s, nothing, nothing, nothing, nothing, nothing, nothing,
105-
nothing, nothing, nothing, nothing, nothing, nothing)
110+
CVres(s, nothing, nothing, nothing, nothing, nothing, nothing, nothing,
111+
nothing, nothing, nothing, nothing, nothing, nothing, nothing)
106112
```
107113
108114
Construct an instance of the CVres structure giving only the `.cvtype`
109115
field. All other fields are filled with `nothing`. This is useful to construct
110116
manually crval objects.
111117
"""
112-
CVres(s::String)=CVres(s, nothing, nothing, nothing, nothing, nothing, nothing,
113-
nothing, nothing, nothing, nothing, nothing, nothing)
118+
CVres(s::String)=CVres(s, nothing, nothing, nothing, nothing, nothing, nothing, nothing,
119+
nothing, nothing, nothing, nothing, nothing, nothing, nothing)
114120

115121

116122

@@ -231,17 +237,21 @@ using PosDefManifoldML, PosDefManifold
231237
P, _dummyP, y, _dummyy = gen2ClassData(10, 60, 80, 30, 40, 0.2)
232238
233239
# Perform 10-fold cross-validation using the minimum distance to mean classifier
234-
cv = crval(MDM(Fisher), P, y)
240+
# adopting the Fisher-Rao (affine-invariant) metric (default)
241+
cv = crval(MDM(), P, y)
242+
243+
# Adopting the log-Euclidean metric
244+
cv = crval(MDM(logEuclidean), P, y)
235245
236-
# Do the same applying a pre-conditioning pipeline
246+
# Apply a pre-conditioning pipeline to adopt the pseudo affine-invariant metric
237247
p = @→ Recenter(; eVar=0.999) Compress Shrink(Fisher; radius=0.02)
238-
cv = crval(MDM(Fisher), P, y; pipeline = p)
248+
cv = crval(MDM(Euclidean), P, y; pipeline = p)
239249
240250
# Apply a pre-conditioning pipeline and project the data
241251
# onto the tangent space at I without recentering the matrices.
242252
# Note that this makes sense only for tangent space ML models.
243253
p = @→ Recenter(; eVar=0.999) Compress Shrink(Fisher; radius=0.02)
244-
cv = crval(ENLR(Fisher), P, y; pipeline = p, meanISR=I)
254+
cv = crval(ENLR(), P, y; pipeline = p, meanISR=I)
245255
246256
# Perform 10-fold cross-validation using the lasso logistic regression classifier
247257
cv = crval(ENLR(Fisher), P, y)
@@ -253,7 +263,6 @@ cv = crval(SVM(Fisher), P, y)
253263
cv = crval(SVM(Fisher), P, y; kernel=kernel.Polynomial)
254264
255265
# Perform 8-fold cross-validation instead
256-
# (and see that you can go pretty fast if your PC has 8 threads)
257266
cv = crval(SVM(Fisher), P, y; nFolds=8)
258267
259268
# ...balance the weights for tangent space projection
@@ -414,7 +423,8 @@ function crval(model :: MLmodel,
414423
end
415424

416425
# create cv struct
417-
cv = CVres("$nFolds-fold", sStr, _model2Str(model), predLab, errls, CM, mCM, as, avg, std, zstat, pvalue, Dates.value(exetime))
426+
cv = CVres("$nFolds-fold", sStr, _model2Str(model), length(𝐏), size(𝐏, 1), predLab, errls,
427+
CM, mCM, as, avg, std, zstat, pvalue, Dates.value(exetime))
418428

419429
# restore the number of threads for BLAS as the user had before invoking this function
420430
&& (BLAS.set_num_threads(blasThreads))
@@ -563,6 +573,8 @@ function Base.show(io::IO, ::MIME{Symbol("text/plain")}, cv::CVres)
563573
println(io, separatorFont, ".cvType :", defaultFont," $(cv.cvType)")
564574
cv.scoring nothing && println(io, separatorFont, ".scoring :", defaultFont," $(cv.scoring)")
565575
cv.modelType nothing && println(io, separatorFont, ".modelType:", defaultFont," $(cv.modelType)")
576+
cv.nTrials nothing && println(io, separatorFont, ".nTrials :", defaultFont," $(cv.nTrials)")
577+
cv.matSize nothing && println(io, separatorFont, ".matSize :", defaultFont," $(cv.matSize)")
566578
cv.predLabels nothing && println(io, separatorFont, ".predLabels ", defaultFont,"a vector of #classes vectors of predicted labels per fold")
567579
cv.losses nothing && println(io, separatorFont, ".losses ", defaultFont,"a vector of binary loss per fold")
568580
cv.cnfs nothing && println(io, separatorFont, ".cnfs ", defaultFont,"a confusion matrix per fold (frequencies)")

src/extras/LOCAL_BUILD.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
# you have identified the 'srcDir' to be used in the push command.
2626

2727
begin
28-
juliaCodeDir = homedir()*"\\Documents\\Documenti\\Code\\julia\\"
28+
juliaCodeDir = homedir()*"\\Documents\\Code\\julia\\"
2929
scrDir = juliaCodeDir*"PosDefManifoldML\\src\\"
3030
docsDir = juliaCodeDir*"PosDefManifoldML\\docs\\"
3131

src/mdm.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,14 @@ function fit(model :: MDMmodel,
237237
w=W[i], ✓w, meanInit=meanInit[i], tol, ⏩) for i=1:z])
238238

239239
# store the inverse of the means for optimizing distance computations
240-
# if the metric is Fisher and the matrices are small
241-
if.metric==Fisher
242-
if size(𝐏Tr[1], 1)<=100
240+
# if the metric is Fisher and the matrices are not too large
241+
if.metric==Fisher && size(𝐏Tr[1], 1)<=100
243242
if
244243
.imeans=ℍVector(undef, length(ℳ.means))
245244
@threads for i=1:length(ℳ.means) @inbounds.imeans[i]=inv(ℳ.means[i]) end
246245
else
247246
.imeans=ℍVector([inv(G) for G .means])
248247
end
249-
end
250248
else.imeans=nothing
251249
end
252250

0 commit comments

Comments
 (0)