def test_equilibrium_thermochemical_correct_probability(datasets_db): """Integration test for equilibrium thermochemical error.""" dbf = Database(CU_MG_TDB) opt = EmceeOptimizer(dbf) datasets_db.insert(CU_MG_EQ_HMR_LIQUID) ctx = setup_context(dbf, datasets_db, ['VV0017']) ctx.update(opt.get_priors(None, ['VV0017'], [0])) prob = opt.predict(np.array([-31626.6]), **ctx) expected_prob = norm(loc=0, scale=500).logpdf([-31626.6 * 0.5 * 0.5]).sum() assert np.isclose(prob, expected_prob) # change to -40000 prob = opt.predict(np.array([-40000], dtype=np.float_), **ctx) expected_prob = norm(loc=0, scale=500).logpdf([-40000 * 0.5 * 0.5]).sum() assert np.isclose(prob, expected_prob)
def test_equilibrium_thermochemical_context_is_pickleable(datasets_db): """Test that the context for equilibrium thermochemical data is pickleable""" datasets_db.insert(CU_MG_EQ_HMR_LIQUID) dbf = Database(CU_MG_TDB) symbols_to_fit = database_symbols_to_fit(dbf) initial_guess = np.array([unpack_piecewise(dbf.symbols[s]) for s in symbols_to_fit]) prior_dict = EmceeOptimizer.get_priors(None, symbols_to_fit, initial_guess) ctx = setup_context(dbf, datasets_db) ctx.update(prior_dict) ctx_pickle = pickle.dumps(ctx) ctx_unpickled = pickle.loads(ctx_pickle) regular_predict = EmceeOptimizer.predict(initial_guess, **ctx) unpickle_predict = EmceeOptimizer.predict(initial_guess, **ctx_unpickled) assert np.isclose(regular_predict, unpickle_predict)
def test_zpf_context_is_pickleable(datasets_db): """Test that the context for ZPF data is pickleable""" datasets_db.insert(CU_MG_DATASET_ZPF_ZERO_ERROR) dbf = Database(CU_MG_TDB) symbols_to_fit = database_symbols_to_fit(dbf) initial_guess = np.array([unpack_piecewise(dbf.symbols[s]) for s in symbols_to_fit]) prior_dict = EmceeOptimizer.get_priors(None, symbols_to_fit, initial_guess) ctx = setup_context(dbf, datasets_db) ctx.update(prior_dict) ctx_pickle = pickle.dumps(ctx) ctx_unpickled = pickle.loads(ctx_pickle) regular_predict = EmceeOptimizer.predict(initial_guess, **ctx) unpickle_predict = EmceeOptimizer.predict(initial_guess, **ctx_unpickled) assert np.isclose(regular_predict, unpickle_predict)