Skip to content

Commit d2f1852

Browse files
committed
test prior fitting
1 parent 7313ca6 commit d2f1852

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/test_fitting.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,35 @@ def test_fit_PVT_data(self):
126126

127127
self.assertArraysAlmostEqual(fitted_eos.pcov[0], zeros)
128128

129+
def test_fit_PVT_data_w_priors(self):
130+
fo = burnman.minerals.HP_2011_ds62.fo()
131+
132+
pressures = np.linspace(1.0e9, 2.0e9, 8)
133+
temperatures = np.ones_like(pressures) * fo.params["T_0"]
134+
135+
PTV = np.empty((len(pressures), 3))
136+
137+
for i in range(len(pressures)):
138+
fo.set_state(pressures[i], temperatures[i])
139+
PTV[i] = [pressures[i], temperatures[i], fo.V]
140+
141+
params = ["V_0", "K_0", "Kprime_0"]
142+
priors = [fo.params["V_0"], fo.params["K_0"], fo.params["Kprime_0"]]
143+
invcov = np.linalg.inv(
144+
np.diag(np.power(np.array([fo.params["V_0"] / 10.0, 1.0e9, 1.0]), 2.0))
145+
)
146+
fitted_eos = burnman.eos_fitting.fit_PTV_data(
147+
fo,
148+
params,
149+
PTV,
150+
param_priors=priors,
151+
param_prior_inv_cov_matrix=invcov,
152+
verbose=False,
153+
)
154+
zeros = np.zeros_like(fitted_eos.pcov[0])
155+
156+
self.assertArraysAlmostEqual(fitted_eos.pcov[0], zeros)
157+
129158
def test_fit_bounded_PVT_data(self):
130159
fo = burnman.minerals.HP_2011_ds62.fo()
131160

@@ -240,7 +269,14 @@ def test_bounded_solution_fitting(self):
240269
flags = np.array(flags)
241270
delta_params = np.array([1.0e-8, 1.0e-8, 1.0e-8])
242271
bounds = np.array([[0, np.inf], [0, np.inf], [-np.inf, np.inf]])
243-
272+
priors = np.array(
273+
[
274+
solution.endmembers[0][0].params["V_0"],
275+
solution.endmembers[1][0].params["V_0"],
276+
0.0,
277+
]
278+
)
279+
invcov = np.linalg.inv(np.diag(np.array([1.0e-7, 1.0e-7, 1.0e-7])))
244280
fitted_eos = fit_XPTp_data(
245281
solution=solution,
246282
flags=flags,
@@ -250,6 +286,8 @@ def test_bounded_solution_fitting(self):
250286
delta_params=delta_params,
251287
bounds=bounds,
252288
param_tolerance=1.0e-5,
289+
param_priors=priors,
290+
param_prior_inv_cov_matrix=invcov,
253291
verbose=False,
254292
)
255293

0 commit comments

Comments
 (0)