30 abr. 2014

NIR spectra mixture simulation of 3 ingredients (with R)

These are the spectra of  Lactose from the previous post, multiplied by a sequence of scalars from 1 to 0.1 steps.
These are the spectra of  Soya  from the previous post, multiplied by a sequence of scalars from 1 to 0.1 steps.

These are the spectra of Lactose from the previous post, multiplied by a sequence of scalars from 1 to 0.1 steps
These spectra were calculated developing a sequence of all possible combinations of these 3 ingredients, let´s call Lactose as A, Soya as B and Gluten as C, so the combinations in this case would be:
A         B        C
1          0         0
0.9       0,1      0
0.9       0         0.1
0.8       0.2      0
0.8       0.1      0.1
0.8       0         0.2
.......     .....      ......
.......     ......    .......
0          0         1

We obtain 66 posible combinations.
The sequence for every product (A, B, and C), multiplied by the spectrum of each product, give us the spectra shown in the previous figures, so now we can sum the 3 matrices to get spectra simulation of these 3 ingredients at different concentrations (from 0 to 100%).
Now we can apply a treatment like SNV to normalize the spectra.

25 abr. 2014

Sum Spectra Simulation (R exercise)

This is a simple exercise:
 I have the spectrum of three different ingredients:  lactose, soya protein concentrate and wheat gluten. I want to simulate in R a mixture of these three ingredients in different concentrations, for example 30% lactose, 20% soya and 50% gluten.


+ ylab="log 1/R",col="blue",main="NIR Spectrum Lactose")

+ ylab="log 1/R",col="blue",main="NIR Spectrum Soya")

+ ylab="log 1/R",col="blue",main="NIR Spectrum Lactose")
Now let´s calculate the percentage spectrum for each component of the mixture:
Now we can add this percentage spectra:
Mixture<- lactose_1 + soya_1 + gluten_1
+ ylab="log 1/R",col="blue",main="Mix Spectrum")
Each spectrum has been treated as a vector

3 abr. 2014

SVD (Now aplying Singular Value Decomposition)

I have the ocasion to ask to Mark Westerhaus what kind of PC algorithms use Win ISI. As always, he replies very quickly:

"WinISI uses SVD everywhere except the PCA regression option in GLOBAL, where it uses NIPALS"

By the way, as you know, Mark Westerhaus has received the EAS Award 2014.
See the post:

I have been writing the lasts post about NIPALS, but now I can continue with some posts doing the same with Singular Value Decomposition, and it would be interesting to make some comparisons with Win ISI.
For the NIPALS, I used a training set of sunflower see acquired in a NIR instrument, the scan goes from 1100 nm to 2500 nm , every 0,5 nm. So we have 1400 . 2 = 2800 data points or wavelength variables,  these means a lot of columns in the X matrix. The number of samples is 107.

So here I write some code to use SVD with my data:


#The output are: "d" "u" "v"
 dim(U)      #Matrix U  (dim= 107.107)


 dim(D)      #Matrix D  (dim= 107.107)


 dim(V)      #Matrix V  (dim= 2800.107)

Now we can calculate the original matrix as

 X<-U %*% D %*% t(V)

  # we can multilpy this: U %*% D  [107.107].[107.107]
  # The result is a [107.107] matrix
  # Finally we have to multiply a [107.107] matrix by a [107.2800]
  # beeing the result a [107.2800] matrix (The X matrix)