Skip to content

Commit 3d7c8b6

Browse files
author
John Halloran
committed
components->n_components
1 parent ae45726 commit 3d7c8b6

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/diffpy/snmf/main.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,8 @@
77
Y0 = np.loadtxt("input/W0.txt", dtype=float)
88
N, M = MM.shape
99

10-
# Convert to DataFrames for display
11-
# df_X = pd.DataFrame(X, columns=[f"Comp_{i+1}" for i in range(X.shape[1])])
12-
# df_Y = pd.DataFrame(Y, columns=[f"Sample_{i+1}" for i in range(Y.shape[1])])
13-
# df_MM = pd.DataFrame(MM, columns=[f"Sample_{i+1}" for i in range(MM.shape[1])])
14-
# df_Y0 = pd.DataFrame(Y0, columns=[f"Sample_{i+1}" for i in range(Y0.shape[1])])
15-
16-
# Print the matrices
17-
"""
18-
print("Feature Matrix (X):\n", df_X, "\n")
19-
print("Coefficient Matrix (Y):\n", df_Y, "\n")
20-
print("Data Matrix (MM):\n", df_MM, "\n")
21-
print("Initial Guess (Y0):\n", df_Y0, "\n")
22-
"""
23-
24-
25-
my_model = snmf_class.SNMFOptimizer(MM=MM, Y0=Y0, X0=X0, A=A0, components=2)
10+
my_model = snmf_class.SNMFOptimizer(MM=MM, Y0=Y0, X0=X0, A=A0, n_components=2)
2611
print("Done")
27-
# print(f"My final guess for X: {my_model.X}")
28-
# print(f"My final guess for Y: {my_model.Y}")
29-
# print(f"Compare to true X: {X_norm}")
30-
# print(f"Compare to true Y: {Y_norm}")
3112
np.savetxt("my_norm_X.txt", my_model.X, fmt="%.6g", delimiter=" ")
3213
np.savetxt("my_norm_Y.txt", my_model.Y, fmt="%.6g", delimiter=" ")
3314
np.savetxt("my_norm_A.txt", my_model.A, fmt="%.6g", delimiter=" ")

src/diffpy/snmf/snmf_class.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(
1414
eta=610,
1515
max_iter=500,
1616
tol=5e-7,
17-
components=None,
17+
n_components=None,
1818
random_state=None,
1919
):
2020
"""Run sNMF based on an ndarray, parameters, and either a number
@@ -38,8 +38,9 @@ def __init__(
3838
A numpy array containing initial guesses for the component weights
3939
at each stretching condition, with number of rows equal to the assumed
4040
number of components and number of columns equal to the number of
41-
conditions (same number of columns as MM). Must be provided if components
42-
is not provided. Will override components if both are provided.
41+
conditions (same number of columns as MM). Must be provided if
42+
n_components is not provided. Will override n_components if both are
43+
provided.
4344
X0: ndarray
4445
A numpy array containing initial guesses for the intensities of each
4546
component per row/sample/angle. Has rows equal to the rows of MM and
@@ -65,7 +66,7 @@ def __init__(
6566
The minimum fractional improvement in the objective function to allow
6667
without terminating the optimization. Note that a minimum of 20 updates
6768
are run before this parameter is checked.
68-
components: int
69+
n_components: int
6970
The number of components to attempt to extract from MM. Note that this will
7071
be overridden by Y0 if that is provided, but must be provided if no Y0 is
7172
provided.
@@ -88,10 +89,10 @@ def __init__(
8889
self.rng = np.random.default_rng(random_state)
8990

9091
if Y0 is None:
91-
if components is None:
92-
raise ValueError("Must provide either Y0 or a number of components.")
92+
if n_components is None:
93+
raise ValueError("Must provide either Y0 or n_components.")
9394
else:
94-
self.K = components
95+
self.K = n_components
9596
self.Y0 = self.rng.beta(a=2.5, b=1.5, size=(self.K, self.M))
9697
else:
9798
self.K = Y0.shape[0]

0 commit comments

Comments
 (0)