Skip to content

Commit 56f89a1

Browse files
john-halloranJohn Halloranpre-commit-ci[bot]
authored
Initial commit of John refactor of SNMF (#140)
* added my files * [pre-commit.ci] auto fixes from pre-commit hooks * Updated X and Y optimizers, now produces formatted but partially incorrect output * removed duplicate class * Working build (no normalization) --------- Co-authored-by: John Halloran <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 34b6aba commit 56f89a1

File tree

2 files changed

+620
-0
lines changed

2 files changed

+620
-0
lines changed

src/diffpy/snmf/main.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import numpy as np
2+
import snmf_class
3+
4+
X0 = np.loadtxt("input/X0.txt", dtype=float)
5+
MM = np.loadtxt("input/MM.txt", dtype=float)
6+
A0 = np.loadtxt("input/A0.txt", dtype=float)
7+
Y0 = np.loadtxt("input/W0.txt", dtype=float)
8+
N, M = MM.shape
9+
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+
my_model = snmf_class.SNMFOptimizer(MM=MM, Y0=Y0, X0=X0, A=A0, components=2)
25+
print("Done")
26+
# print(f"My final guess for X: {my_model.X}")
27+
# print(f"My final guess for Y: {my_model.Y}")
28+
# print(f"Compare to true X: {X_norm}")
29+
# print(f"Compare to true Y: {Y_norm}")
30+
np.savetxt("my_new_X.txt", my_model.X, fmt="%.6g", delimiter=" ")
31+
np.savetxt("my_new_Y.txt", my_model.Y, fmt="%.6g", delimiter=" ")
32+
np.savetxt("my_new_A.txt", my_model.A, fmt="%.6g", delimiter=" ")

0 commit comments

Comments
 (0)