SNMFOptimizer
- class diffpy.stretched_nmf.snmf_class.SNMFOptimizer(n_components=None, max_iter=500, min_iter=20, tol=5e-07, rho=0, eta=0, random_state=None, show_plots=False, verbose=False)[source]
Bases:
objectAn implementation of stretched NMF, including sparse stretched NMF.
Instantiate the estimator with hyperparameters, then call
fitto optimize model factors. Trailing underscores indicate that an attribute was determined during the fit process.For more information on sNMF, please reference: Gu, R., Rakita, Y., Lan, L. et al. Stretched non-negative matrix factorization. npj Comput Mater 10, 193 (2024) https://doi.org/10.1038/s41524-024-01377-5
- stretch_
The best guess (or while running, the current guess) for the stretching factor matrix.
- Type:
- components_
The best guess (or while running, the current guess) for the matrix of component intensities.
- Type:
- weights_
The best guess (or while running, the current guess) for the matrix of component weights.
- Type:
- rho
The stretching factor that influences the decomposition. Zero corresponds to no stretching present. Relatively insensitive and typically adjusted in powers of 10.
- Type:
- eta
The sparsity factor that influences the decomposition. Should be set to zero for non-sparse data such as PDF. Can be used to improve results for sparse data such as XRD, but due to instability, should be used only after first selecting the best value for rho. Suggested adjustment is by powers of 2.
- Type:
- max_iter
The maximum number of times to update each of stretch, components, and weights before stopping the optimization.
- Type:
- min_iter
The minimum number of times to update each of stretch, components, and weights before terminating the optimization due to low/no improvement.
- Type:
- tol
The convergence threshold. This is the minimum fractional improvement in the objective function to allow without terminating the optimization.
- Type:
- random_state
The seed for the initial guesses at the matrices (stretch, components, and weights) created by the decomposition.
- Type:
- objective_difference_
The change in the objective function value since the last update. A positive value means that the result improved.
- Type:
- __init__(n_components=None, max_iter=500, min_iter=20, tol=5e-07, rho=0, eta=0, random_state=None, show_plots=False, verbose=False)[source]
Initialize an instance of sNMF with estimator hyperparameters.
- Parameters:
n_components (int, optional) – The number of components to extract when
init_weightsis not provided tofit.max_iter (int) – The maximum number of times to update each of A, X, and Y before stopping the optimization. Optional.
min_iter (int) – The minimum number of outer-loop iterations before convergence checks can stop optimization. Optional.
tol (float) – The convergence threshold. This is the minimum fractional improvement in the objective function to allow without terminating the optimization. Note that a minimum of 20 updates are run before this parameter is checked. Optional.
rho (float) – The stretching regularization hyperparameter. Zero corresponds to no stretching.
eta (float) – The sparsity regularization hyperparameter. Turn off for non-sparse data such as PDF.
random_state (int) – The seed for the initial guesses at the matrices (A, X, and Y) created by the decomposition. Optional.
show_plots (bool) – Enables plotting at each step of the decomposition. Optional.
- fit(source_matrix, init_weights=None, init_components=None, init_stretch=None, reset=True)[source]
Run the sNMF optimization on
source_matrix.- Parameters:
source_matrix (ndarray of shape (signal_length, n_signals)) – The source data matrix to decompose.
init_weights (ndarray, optional) – The initial weights matrix of shape
(n_components, n_signals).init_components (ndarray, optional) – Optional initial components matrix of shape
(signal_length, n_components).init_stretch (ndarray, optional) – The initial stretch matrix of shape
(n_components, n_signals).reset (bool) – Whether to reinitialize model factors before fitting. If
False, the previous factor matrices are reused.