ChemometricsTools.jl usage

I am trying to use the example of Curve Resolution as describe in the docs here but using the tecator.csv dataset as the triliq.csv is missing (could not find it). I try different things but I am stuck getting zeros and ones only in the weights C_MCRALS. MWE as follow:

using ChemometricsTools
Raw = ChemometricsToolsDataset("tecator.csv")
Mixture = Matrix(Raw)[:,1:99]); # only absorbance spectra
pure = [10,11,20,21,28,29];
PURE = Mixture[pure,:];
impure = [collect(1:9); collect(12:19);collect(22:27)];
Mixture = Mixture[impure,:];

( W_NMF, H_NMF ) = NMF(Mixture; Factors = 3, maxiters = 300, tolerance = 1e-8)
(C_Simplisma,S_Simplisma, vars) = SIMPLISMA(Mixture; Factors = 18)
vars
#Find purest variables that are not neighbors with one another
cuts = S_Simplisma[ [1,3,17], :];
( C_MCRALS, S_MCRALS, err ) = MCRALS(Mixture, nothing, RangeNorm(cuts')(cuts')';
                                    Factors = 3, maxiters = 10,
                                    norm = (true, false),
                                    nonnegative = (true, true) )

And this is what I get

julia> C_MCRALS
23×3 Array{Float64,2}:
 0.0  0.0  1.0
 0.0  0.0  1.0
 0.0  0.0  1.0
 0.0  0.0  1.0
 ⋮            
 0.0  0.0  1.0
 0.0  0.0  1.0
 0.0  0.0  1.0
 0.0  0.0  1.0

julia> S_MCRALS
3×99 Array{Float64,2}:
 0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0     …  0.0      0.0      0.0      0.0      0.0     0.0      0.0      0.0    
 0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0      0.0        0.0      0.0      0.0      0.0      0.0     0.0      0.0      0.0    
 2.76599  2.76854  2.77107  2.77363  2.77626  2.77899  2.78187  2.78493  2.7882     3.10123  3.08192  3.06295  3.04433  3.0261  3.00824  2.99068  2.97337

I also tried with my data, and I get the same thing. I am pretty sure I am not understanding the arguments in here. Any suggestion on your side @ckneale? Thanks! (I also posted an issue, but I don’t think it is.)

Playing around with the norm settings actually helps.

1 Like

So sorry I didn’t see this! I’m the developer/maintainer of that package.

So, what I think most MCRALS implementations do behind the scenes is range norm (min-max scale) spectra between 0-1. I really reccommend doing this. Also tinkering with norm constraints can definitely help. I think there’s probably still some bugs in that part of the package so if you run into anything inconsistent/problematic please speak up. I think I wrote the majority of that file in an after-noon - bound to be something wrong along the way.

I noticed you filed a ticket for an enhancement - Thank you! Please feel free to file issues and things I’ve been twiddling my thumbs waiting for some feed-back outside of myself.