# ChemometricsTools.jl usage

**URL:** <https://discourse.julialang.org/t/chemometricstools-jl-usage/26770>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [July 25, 2019, 2:23am UTC](https://discourse.julialang.org/t/chemometricstools-jl-usage/26770 "2019-07-25T02:23:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![lnacquaroli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lnacquaroli/32/20467_2.png) [@lnacquaroli](https://discourse.julialang.org/u/lnacquaroli)\
**Post date:** [July 25, 2019, 2:23am UTC](https://discourse.julialang.org/t/chemometricstools-jl-usage/26770/1 "2019-07-25T02:23:01Z")

</div>

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:

```julia
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
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 @anon92994695? Thanks! (I also posted an issue, but I don’t think it is.)

---

<div class="post-metadata">

**Author:** ![lnacquaroli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lnacquaroli/32/20467_2.png) [@lnacquaroli](https://discourse.julialang.org/u/lnacquaroli)\
**Post date:** [July 25, 2019, 2:36pm UTC](https://discourse.julialang.org/t/chemometricstools-jl-usage/26770/2 "2019-07-25T14:36:26Z")

</div>

Playing around with the `norm` settings actually helps.

---

<div class="post-metadata">

**Author:** ![anon92994695](https://avatars.discourse-cdn.com/v4/letter/a/ce7236/32.png) [@anon92994695](https://discourse.julialang.org/u/anon92994695)\
**Post date:** [July 29, 2019, 1:11am UTC](https://discourse.julialang.org/t/chemometricstools-jl-usage/26770/3 "2019-07-29T01:11:42Z")

</div>

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.
