usnistgov / pyMCR

pyMCR: Multivariate Curve Resolution for Python
https://pages.nist.gov/pyMCR
Other
80 stars 27 forks source link

Use of constraints #43

Open GhostDeini opened 1 year ago

GhostDeini commented 1 year ago

Hi, is it possible to add a constraint for the MCR ALS method such that the first value of one of the concentration profiles must be equal to 1?

CCampJr commented 1 year ago

@GhostDeini Yes it is, thanks for asking!

The easiest way is to provide an initial guess of concentration numbers in the fit method -- setting the first entry to 1.0 -- then use the c_fix=[0] to fix the first concentration profile.

Example:

# D is your data of the shape (M,N)

M, N = D.shape
N_chemicals = 5  # I think or know there are 5 chemical species
# C_init is your concentration matrix of size (M, N_chemicals)
C_init = np.random.rand(M, N_chemical)
C_init[:,0] = 1.0

mcrar = McrAr()
mcrar.fit(D, C=C_init, c_fix=[0])

Does that answer your questions, and anything else I can help you with?

GhostDeini commented 1 year ago

I keep getting this error when I give initial estimates for the concentration profiles:

Error increased above fractionalctol_increase (C iter). Exiting

Is it possible to give initial estimates for the spectra and also the mentioned constraint for the concentrations?

Thank you.

CCampJr commented 1 year ago

You have a few options. You can increase the tol_increase in the instantiation of McrAr: mcrar = McrAr(tol_increase=10.) # 1000% increase in err metric allowed

You can absolutely input an S=S_init and C=C_init and you probably have to select c_first=True or False in the fit method. There are a few other solutions I can think of, but maybe if I understand your use-case a little more, I can come up with a solution. Feel free to post more here or send me an email to charles.camp@nist.gov