Skip to content

Commit

Permalink
test: uncertainty
Browse files Browse the repository at this point in the history
  • Loading branch information
dfm88 committed Jan 24, 2025
1 parent d15fa0d commit 654cf68
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 113 deletions.
4 changes: 2 additions & 2 deletions Examples/Example3.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -431,7 +431,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion docs/Example2 - Real dataset.rst
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ We can now plot some of the results:
.. code:: python
# plot frequecy-damping clusters for SSI
ssicov.plot_cluster(freqlim=(0,5))
ssicov.plot_freqvsdamp(freqlim=(0,5))
.. figure:: /img/Ex2-Fig9.png
Expand Down
6 changes: 3 additions & 3 deletions docs/Example3 - Multisetup PoSER.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ remains the same as described in the example for the single setup.
.. code:: python
# Initialise the algorithms for setup 1
ssicov1 = SSIcov(name="SSIcov1", method="cov_mm", br=50, ordmax=80)
ssicov1 = SSIcov(name="SSIcov1", method="cov", br=50, ordmax=80)
# Add algorithms to the class
ss1.add_algorithms(ssicov1)
ss1.run_all()
# Initialise the algorithms for setup 2
ssicov2 = SSIcov(name="SSIcov2", method="cov_mm", br=50, ordmax=80)
ssicov2 = SSIcov(name="SSIcov2", method="cov", br=50, ordmax=80)
ss2.add_algorithms(ssicov2)
ss2.run_all()
# Initialise the algorithms for setup 2
ssicov3 = SSIcov(name="SSIcov3", method="cov_mm", br=50, ordmax=80)
ssicov3 = SSIcov(name="SSIcov3", method="cov", br=50, ordmax=80)
ss3.add_algorithms(ssicov3)
ss3.run_all()
Expand Down
1 change: 0 additions & 1 deletion src/pyoma2/algorithms/plscf.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ def run(self) -> pLSCFResult:
)

# Apply HARD CRITERIA
# hc_conj = hc["conj"]
hc_xi_max = hc["xi_max"]
hc_mpc_lim = hc["mpc_lim"]
hc_mpd_lim = hc["mpd_lim"]
Expand Down
19 changes: 11 additions & 8 deletions src/pyoma2/functions/ssi.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,14 @@ def build_hank(
Hvec0 = Hank.reshape(-1, 1, order="f") # vectorialised hankel

for j in range(1, nb + 1):
Ri = np.array(
[
1 / (Nb) * np.dot(Y[:, : j * Nb - k], Yref[:, k : j * Nb].T)
for k in range(p + q)
]
)
print(j, nb)
Ri = np.array([])
for k in range(p + q):
print(f"{k=}, {p=}, {q=}")
res = np.array(
[1 / (Nb) * np.dot(Y[:, : j * Nb - k], Yref[:, k : j * Nb].T)]
)
Ri = np.vstack([Ri, res])
Hcov_j = np.vstack(
[np.hstack([Ri[i + j, :, :] for j in range(p + 1)]) for i in range(q)]
)
Expand Down Expand Up @@ -196,7 +198,7 @@ def build_hank(
# Legacy
def SSI(
H: np.ndarray, br: int, ordmax: int, step: int = 1
) -> typing.Tuple[typing.List[np.ndarray], typing.List[np.ndarray]]:
) -> typing.Tuple[np.ndarray, typing.List[np.ndarray], typing.List[np.ndarray]]:
"""
Perform System Identification using the Stochastic Subspace Identification (SSI) method.
Expand Down Expand Up @@ -953,7 +955,8 @@ def SSI_mpe(
# OPZIONE 3 order = list[int]
# -----------------------------------------------------------------------------
elif isinstance(order, list):
order = int(order / step)
# Convert each element in the order list to model orders
order = [int(o / step) for o in order]
order_out = np.array(order)
for ii, fj in enumerate(tqdm(freq_ref)):
sel = np.nanargmin(np.abs(Fn_pol[:, order[ii]] - fj))
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,36 +155,36 @@ def multi_setup_poser_fixture(
ss3.decimate_data(q=2)

# Initialise the algorithms for setup 1
ssicov1 = SSIcov(name="SSIcov1", method="cov_mm", br=50, ordmax=80)
ssicov1 = SSIcov(name="SSIcov1", method="cov", br=50, ordmax=80)
# Add algorithms to the class
ss1.add_algorithms(ssicov1)
ss1.run_all()

# Initialise the algorithms for setup 2
ssicov2 = SSIcov(name="SSIcov2", method="cov_mm", br=50, ordmax=80)
ssicov2 = SSIcov(name="SSIcov2", method="cov", br=50, ordmax=80)
ss2.add_algorithms(ssicov2)
ss2.run_all()

# Initialise the algorithms for setup 2
ssicov3 = SSIcov(name="SSIcov3", method="cov_mm", br=50, ordmax=80)
ssicov3 = SSIcov(name="SSIcov3", method="cov", br=50, ordmax=80)
ss3.add_algorithms(ssicov3)
ss3.run_all()

# run mpe
ss1.mpe(
"SSIcov1",
sel_freq=[2.63, 2.69, 3.43, 8.29, 8.42, 10.62, 14.00, 14.09, 17.57],
order=50,
order_in=50,
)
ss2.mpe(
"SSIcov2",
sel_freq=[2.63, 2.69, 3.43, 8.29, 8.42, 10.62, 14.00, 14.09, 17.57],
order=40,
order_in=40,
)
ss3.mpe(
"SSIcov3",
sel_freq=[2.63, 2.69, 3.43, 8.29, 8.42, 10.62, 14.00, 14.09, 17.57],
order=40,
order_in=40,
)
# reference indices
ref_ind = [[0, 1, 2], [0, 1, 2], [0, 1, 2]]
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/setup/test_single_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ def test_run(ss: SingleSetup) -> None:

# plot FREQUECY-DAMPING CLUSTERS for SSI
try:
fig4, ax4 = ssicov.plot_cluster(freqlim=(1, 4))
fig4, ax4 = ssicov.plot_freqvsdamp(freqlim=(1, 4))
except Exception as e:
assert False, f"plot_cluster raised an exception {e}"
assert False, f"plot_freqvsdamp raised an exception {e}"

# run mpe_from_plot for algorithms
try:
Expand All @@ -461,7 +461,7 @@ def test_run(ss: SingleSetup) -> None:

# run mpe for algorithms
try:
ss.mpe("SSIcov", sel_freq=[1.88, 2.42, 2.68], order=40)
ss.mpe("SSIcov", sel_freq=[1.88, 2.42, 2.68], order_in=40)
except Exception as e:
assert False, f"mpe raised an exception {e} for SSIcov"

Expand Down
Loading

0 comments on commit 654cf68

Please sign in to comment.