Skip to content

Commit 708a21d

Browse files
committed
adding unittest
1 parent 5216672 commit 708a21d

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pyomo/contrib/doe/tests/test_doe_FIM_metrics.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
1+
from pyomo.common.dependencies import (
2+
numpy as np,
3+
numpy_available,
4+
pandas as pd,
5+
pandas_available,
6+
)
7+
8+
import pyomo.common.unittest as unittest
9+
from pyomo.contrib.doe import DesignOfExperiments
10+
from pyomo.contrib.doe.doe import compute_FIM_full_factorial, _SMALL_TOLERANCE_IMG
11+
from pyomo.opt import SolverFactory
12+
13+
14+
@unittest.skipIf(not numpy_available, "Numpy is not available")
15+
class TestFullFactrialMetrics(unittest.TestCase):
16+
def test_compute_FIM_full_factorial_metrics(self):
17+
# Create a sample Fisher Information Matrix (FIM)
18+
FIM = np.array([[4, 2], [2, 3]])
19+
20+
21+
# ======================================================================
122
import numpy as np
223

324
# from pyomo.common.dependencies import numpy as np
425
from pyomo.contrib.doe.doe import _SMALL_TOLERANCE_IMG
5-
import pytest
626

727

828
def compute_FIM_metrics(FIM):
@@ -14,7 +34,7 @@ def compute_FIM_metrics(FIM):
1434
E_vals, E_vecs = np.linalg.eig(FIM) # Grab eigenvalues and eigenvectors
1535

1636
E_ind = np.argmin(E_vals.real) # Grab index of minima to check imaginary
17-
IMG_THERESHOLD = 1e-6 # Instead of creating a new constant, use `SMALL_DIFF` by importiing it form `doe.py`
37+
1838
# Warn the user if there is a ``large`` imaginary component (should not be)
1939
if abs(E_vals.imag[E_ind]) > _SMALL_TOLERANCE_IMG:
2040
print(

0 commit comments

Comments
 (0)