Skip to content

Commit d6b2011

Browse files
john-halloranJohn Halloran
andauthored
docs: clean up and add a real data XRD example (#191)
* refactor: move example data to docs/examples/data * refactor: turn main.py into an example located in docs * docs: add complete XRD example * fix: clean up two more snmf references * chore: add news item * refactor: remove references to unused variable num_updates * refactor: consistently label variables as private or fit-derived * refactor: change remaining data files from underscores to dashes * refactor: name files to sort correctly * docs: add to API explanation of trailing underscores --------- Co-authored-by: John Halloran <jhalloran@oxy.edu>
1 parent c436df0 commit d6b2011

57 files changed

Lines changed: 3632 additions & 293 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AUTHORS.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Contributors
77
------------
88

99
For a list of contributors, visit
10-
https://github.com/diffpy/diffpy.snmf/graphs/contributors
10+
https://github.com/diffpy/diffpy.stretched-nmf/graphs/contributors
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pathlib import Path
2+
3+
import numpy as np
4+
5+
from diffpy.stretched_nmf.snmf_class import SNMFOptimizer
6+
7+
# Input data
8+
DATA_DIR = Path(__file__).resolve().parent / "data/XRD-MgMnO-YCl-real"
9+
source_matrix_file = np.loadtxt(
10+
DATA_DIR / "source-matrix.txt", dtype=float, skiprows=4
11+
)
12+
13+
# Optional starting initialization
14+
# Without it, would need to provide n_components = 2 to get these results
15+
init_components_file = np.loadtxt(
16+
DATA_DIR / "init-components.txt", dtype=float
17+
)
18+
init_stretch_file = np.loadtxt(DATA_DIR / "init-stretch.txt", dtype=float)
19+
init_weights_file = np.loadtxt(DATA_DIR / "init-weights.txt", dtype=float)
20+
21+
my_model = SNMFOptimizer(
22+
show_plots=True,
23+
rho=1e12,
24+
eta=610,
25+
)
26+
# Experimentally found best fit parameters for this data
27+
my_model.fit(
28+
source_matrix=source_matrix_file,
29+
init_weights=init_weights_file,
30+
init_components=init_components_file,
31+
init_stretch=init_stretch_file,
32+
)
33+
34+
print("Done")
35+
np.savetxt(
36+
"my_norm_components.txt", my_model.components_, fmt="%.6g", delimiter=" "
37+
)
38+
np.savetxt("my_norm_weights.txt", my_model.weights_, fmt="%.6g", delimiter=" ")
39+
np.savetxt("my_norm_stretch.txt", my_model.stretch_, fmt="%.6g", delimiter=" ")

0 commit comments

Comments
 (0)