Skip to content

Commit d3f31e9

Browse files
author
John Halloran
committed
feat: use reset for sequential refinements
1 parent 1bee9c6 commit d3f31e9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/diffpy/snmf/snmf_class.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,17 @@ def __init__(
155155
self.components_ = np.maximum(0, self.components_)
156156
self.weights_ = np.maximum(0, self.weights_)
157157

158+
# Store the initial components, weights, and stretch
159+
self.init_components = self.components_
160+
self.init_weights = self.weights_
161+
self.init_stretch = self.stretch_
162+
158163
# Second-order spline: Tridiagonal (-2 on diagonal, 1 on sub/superdiagonals)
159164
self._spline_smooth_operator = 0.25 * diags(
160165
[1, -2, 1], offsets=[0, 1, 2], shape=(self.n_signals - 2, self.n_signals)
161166
)
162167

163-
def fit(self, rho=0, eta=0):
168+
def fit(self, rho=0, eta=0, reset=True):
164169
"""Run the sNMF optimization with the given parameters, using the setup from __init__.
165170
166171
Parameters
@@ -173,8 +178,17 @@ def fit(self, rho=0, eta=0):
173178
non-sparse data such as PDF. Can be used to improve results for sparse data such
174179
as XRD, but due to instability, should be used only after first selecting the
175180
best value for rho. Suggested adjustment is by powers of 2.
181+
reset : boolean Optional Default = True
182+
Whether to return to the initial set of components_, weights_, and stretch_ before
183+
running the optimization. When set to False, sequential calls to fit() will use the
184+
output of the previous fit() as their input.
176185
"""
177186

187+
if reset:
188+
self.components_ = self.init_components
189+
self.weights_ = self.init_weights
190+
self.stretch_ = self.init_stretch
191+
178192
self.rho = rho
179193
self.eta = eta
180194

0 commit comments

Comments
 (0)