pyEELSMODEL.fitters package
Submodules
pyEELSMODEL.fitters.linear_fitter module
copyright University of Antwerp 2021 author: Jo Verbeeck and Daen Jannis
- class pyEELSMODEL.fitters.linear_fitter.LinearFitter(spectrum, model, method='ols', use_weights=False)
Bases:
FitterA linear fitter class which uses as input a Spectrum or Multispectrum and Model.
- property A_matrix
- calculate_A_matrix()
Get derivative matrix. This is a matrix which holds for each energy in the spectrum the first derivative of the value at that energy with respect to each free parameter in the model. This A matrix needs to be convolved to include the low loss scattering
- calculate_weights()
- The weights are calculated assuming the data is poisson noise.
W=1/(sigma**2), and sigma**2 = N which is the number of electrons. If the data itself is lower than 1, which could happen due to dark noise, then the value is set to 1. Note that the data itself needs to be expressed in electron (right pppc) for it to make most sense.
Returns
- calculate_y_vector()
Calculates the y vector for the linear least squares fitting. The y vector is the raw data where the excluded regions are not included.
- Returns:
y – The y vector for the linear least squares fitting
- Return type:
numpy array
- convolute_A_matrix()
Convolutes the A matrix with the low loss. This is necessary to take the low loss into account. It does this by first checking which components need to be convolved. The next step is to convolve each row of the A matrix with low loss. This low loss convolution increases the fitting time. Other and faster ways can be exploited to have a faster quantification.
- Returns:
A_matrix_ll – The convolved A matrix with the low loss.
- Return type:
numpy 2d array
- convolute_A_matrix_()
Test convolution using the matrix approach however this seems to be slower than the original which loops over A matrix
- partial_derivative(parameter)
Calculates the partial derivative of the parameter. When the entire model is linear. This is taking the rows (or columns) of the A matrix which needs to be convoluted when low loss is used.
- Parameters:
parameter (Parameter) – The parameter from which the partial derivative will be calculated.
fraction (float) – The fraction of the step the parameter does to calculate the numerical gradient. (default: 0.001)
- Returns:
parial – The partial derivative for the given parameter.
- Return type:
numpy array (1D)
- pearson_correlation_matrix()
Calculates the pearson correlation matrix :returns: correlation_matrix – The pearson correlation matrix :rtype: 2d numpy array
- perform_fit()
Fits the spectrum using the linear least squares method.
- show_pearson_correlation()
- property y_vector
pyEELSMODEL.fitters.lsqfitter module
copyright University of Antwerp 2021 author: Jo Verbeeck and Daen Jannis
- class pyEELSMODEL.fitters.lsqfitter.LSQFitter(spectrum, model, use_bounds=False, method='lm')
Bases:
FitterThe least squares fitter which can be used to solve non-linear problems by optimizing the least squares.
- bounds_lsq()
Boundaries for lsq is different as used for the ml fitter
- property estimator
- property method
- perform_fit()
- residuals(x0, m, s)
- property use_bounds
pyEELSMODEL.fitters.minimizefitter module
copyright University of Antwerp 2021 author: Jo Verbeeck and Daen Jannis
- class pyEELSMODEL.fitters.minimizefitter.MinimizeFitter(spectrum, model, method='nelder-mead', estimator='ML')
Bases:
FitterFitter class which uses the minimization algorithms of scipy for finding the optimal parameters. Mainly for the maximum likelihood estimator but others can also be implemented.
- MLE_function(x0, m, s)
The maximum likelihood estimator :param x0: :param m: :param s: :return:
- property estimator
- property jacobian
return:
- jacobian_LSQ(x0, m, s)
- jacobian_ML(x0, m, s)
- lsq_function(x0, m, s)
Least squares minimization, preferably use LSQFitter
- property method
- perform_fit()
Does the fit on a single spectrum where the starting parameters are given by x0.