def test_inequality(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 50))) S.setTM(bl.tm.Static()) S.fit() S2 = bl.Study() S2.loadData(np.array([1, 2, 3, 4, 5])) S2.setOM(bl.om.Poisson('rate2', bl.oint(0, 6, 50))) S2.setTM(bl.tm.GaussianRandomWalk('sigma', 0.2, target='rate2')) S2.fit() P = bl.Parser(S, S2) P('log(rate2*2*1.2) + 4 + rate^2 > 20', t=3) np.testing.assert_almost_equal( P('log(rate2@1*2*1.2) + 4 + rate@2^2 > 20'), 0.162262091093, decimal=5, err_msg='Erroneous parsing result for inequality.') np.testing.assert_almost_equal( P('log(rate2*2*1.2) + 4 + rate^2 > 20', t=3), 0.163699467863, decimal=5, err_msg= 'Erroneous parsing result for inequality with fixed timestamp.')
def test_scaledar1(self): S = bl.Study() S.loadData(np.array([1, 0, 1, 0, 0])) L = bl.om.ScaledAR1('rho', bl.oint(-1, 1, 100), 'sigma', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -4.4178639067800738, decimal=5, err_msg='Erroneous log-evidence value.')
def test_gaussian(self): S = bl.Study() S.loadData(np.array([1, 0, 1, 0, 0])) L = bl.om.Gaussian('mu', bl.oint(0, 1, 100), 'std', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -12.430583625665736, decimal=5, err_msg='Erroneous log-evidence value.')
def test_bivariaterandomwalk(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) L = bl.om.Gaussian('mu', bl.oint(0, 6, 20), 'sigma', bl.oint(0, 2, 20)) T = bl.tm.BivariateRandomWalk('sigma1', 1., 'sigma2', 0.1, 'rho', 0.5) S.set(L, T) S.fit() # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -7.330706514472251, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_array(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20), prior=np.ones((20, 20)))) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='mean')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.04317995, 0.04296549, 0.04275526, 0.04262151, 0.04262491], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [2.66415455, 2.66519273, 2.66664847, 2.66788051, 2.66828383], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -10.9827282104, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_sympy(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian( 'mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20), prior=[stats.Uniform('u', 0, 6), stats.Exponential('e', 2.)])) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='mean')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.00909976, 0.0089861, 0.00887967, 0.00881235, 0.00880499], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [2.9942575, 2.99646768, 3., 3.00353232, 3.0057425], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -12.4324853153, decimal=5, err_msg='Erroneous log-evidence value.')
def test_optimize(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM(bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) T = bl.tm.CombinedTransitionModel(bl.tm.GaussianRandomWalk('sigma', 1.07, target='mean'), bl.tm.RegimeSwitch('log10pMin', -3.90)) S.setTM(T) S.optimize() # test parameter distributions np.testing.assert_allclose(S.getParameterDistributions('mean', density=False)[1][:, 5], [4.52572851e-04, 1.67790320e-03, 2.94525791e-07, 1.49841548e-08, 1.10238422e-09], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose(S.getParameterMeanValues('mean'), [0.95899404, 1.93816557, 2.99999968, 4.06183394, 5.04100612], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -8.01030368139, decimal=5, err_msg='Erroneous log-evidence value.') # test optimized hyper-parameter values np.testing.assert_almost_equal(S.getHyperParameterValue('sigma'), 1.06576569677, decimal=5, err_msg='Erroneous log-evidence value.') np.testing.assert_almost_equal(S.getHyperParameterValue('log10pMin'), -4.04001476542, decimal=5, err_msg='Erroneous log-evidence value.')
def test_optimize(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 1000), prior=stats.Exponential('expon', 1.))) T = bl.tm.CombinedTransitionModel(bl.tm.GaussianRandomWalk('sigma', 2.1, target='rate'), bl.tm.RegimeSwitch('log10pMin', -3)) S.setTM(T) S.optimize() # test parameter distributions np.testing.assert_allclose(S.getParameterDistributions('rate', density=False)[1][:, 250], [0.00181567, 0.00213315, 0.00091028, 0.00041154, 0.00090885], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose(S.getParameterMeanValues('rate'), [1.01204314, 2.25763551, 3.24176817, 3.74634864, 3.12632199], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -9.47362827569, decimal=5, err_msg='Erroneous log-evidence value.') # test optimized hyper-parameter values np.testing.assert_almost_equal(S.getHyperParameterValue('sigma'), 2.11216289063, decimal=5, err_msg='Erroneous log-evidence value.') np.testing.assert_almost_equal(S.getHyperParameterValue('log10pMin'), -3.0, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_0hp(self): # carry out fit (this test is designed to fall back on the fit method of the Study class) S = bl.HyperStudy() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20), prior=lambda m, s: 1 / s**3)) S.setTM(bl.tm.Static()) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean', density=False)[1][:, 5], [0.00707902, 0.00707902, 0.00707902, 0.00707902, 0.00707902], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose(S.getParameterMeanValues('mean'), [3., 3., 3., 3., 3.], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -16.1946904707, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_2hp(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) T = bl.tm.CombinedTransitionModel( bl.tm.GaussianRandomWalk('sigma', 0.1, target='mean'), bl.tm.RegimeSwitch('log10pMin', -3)) S.setTM(T) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.02976422, 0.15404218, 0.10859567, 0.02553673, 0.00054109], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [1.08288559, 2.24388932, 2.38033179, 2.98934128, 4.64547841], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -14.3305753098, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_function(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20), prior=lambda m, s: 1. / s)) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='mean')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.01591204, 0.01579036, 0.01567361, 0.01559665, 0.01558591], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [2.99576496, 2.99741879, 3., 3.00258121, 3.00423504], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -11.9842221343, decimal=5, err_msg='Erroneous log-evidence value.')
def test_step_set1TM_0hp(self): # carry out fit S = bl.OnlineStudy(storeHistory=True) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) S.setTM(bl.tm.Static()) data = np.array([1, 2, 3, 4, 5]) for d in data: S.step(d) # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.0053811, 0.38690331, 0.16329865, 0.04887604, 0.01334921], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [0.96310103, 1.5065597, 2.00218465, 2.500366, 3.], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -16.1946904707, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_function(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Poisson('rate', bl.oint(0, 6, 1000), prior=lambda x: 1. / x)) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='rate')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('rate')[1][:, 250], [0.0007529, 0.00070742, 0.00066273, 0.00063262, 0.00062968], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('rate'), [2.77252114, 2.78251864, 2.79475018, 2.80541289, 2.81072838], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -11.3966589329, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_array(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 1000), prior=np.ones(1000))) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='rate')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('rate')[1][:, 250], [0.00048679, 0.00045124, 0.00041767, 0.00039717, 0.00039976], rtol=1e-04, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('rate'), [2.81716591, 2.82337653, 2.83204058, 2.83944083, 2.84187612], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -10.0866227472, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_prior_sympy(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Poisson('rate', bl.oint(0, 6, 1000), prior=stats.Exponential('expon', 1.))) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='rate')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('rate')[1][:, 250], [0.0020607, 0.0019692, 0.00187339, 0.0018053, 0.00179584], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('rate'), [2.25427356, 2.26949283, 2.28527551, 2.29704214, 2.30024139], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -11.1819034242, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_0hp(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) S.setTM(bl.tm.Static()) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.00707902, 0.00707902, 0.00707902, 0.00707902, 0.00707902], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose(S.getParameterMeanValues('mean'), [3., 3., 3., 3., 3.], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -16.1946904707, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_1hp(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) S.setTM(bl.tm.GaussianRandomWalk('sigma', 0.1, target='mean')) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean')[1][:, 5], [0.00722368, 0.00712209, 0.00702789, 0.00696926, 0.00696322], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [2.99313985, 2.99573566, 3., 3.00426434, 3.00686015], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -16.1865343702, decimal=5, err_msg='Erroneous log-evidence value.')
def test_fit_2hp(self): # carry out fit S = bl.HyperStudy() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) T = bl.tm.CombinedTransitionModel( bl.tm.GaussianRandomWalk('sigma', bl.cint(0, 0.2, 2), target='mean'), bl.tm.RegimeSwitch('log10pMin', [-3, -1])) S.setTM(T) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean', density=False)[1][:, 5], [ 5.80970506e-03, 1.12927905e-01, 4.44501254e-02, 1.00250119e-02, 1.72751309e-05 ], rtol=1e-05, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [0.96492471, 2.09944204, 2.82451616, 3.72702495, 5.0219119], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -10.7601875492, decimal=5, err_msg='Erroneous log-evidence value.') # test hyper-parameter distribution x, p = S.getHyperParameterDistribution('sigma') np.testing.assert_allclose( np.array([x, p]), [[0., 0.2], [0.48943645, 0.51056355]], rtol=1e-05, err_msg='Erroneous values in hyper-parameter distribution.') # test joint hyper-parameter distribution x, y, p = S.getJointHyperParameterDistribution(['log10pMin', 'sigma']) np.testing.assert_allclose( np.array([x, y]), [[-3., -1.], [0., 0.2]], rtol=1e-05, err_msg='Erroneous parameter values in joint hyper-parameter ' 'distribution.') np.testing.assert_allclose( p, [[0.00701834, 0.0075608], [0.48241812, 0.50300274]], rtol=1e-05, err_msg='Erroneous probability values in joint hyper-parameter ' 'distribution.')
def test_fit_1cp_1bp_2hp(self): # carry out fit S = bl.ChangepointStudy() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20), prior=lambda m, s: 1 / s**3)) T = bl.tm.SerialTransitionModel( bl.tm.Static(), bl.tm.ChangePoint('ChangePoint', [0, 1]), bl.tm.CombinedTransitionModel( bl.tm.GaussianRandomWalk('sigma', bl.cint(0, 0.2, 2), target='mean'), bl.tm.RegimeSwitch('log10pMin', [-3, -1])), bl.tm.BreakPoint('BreakPoint', 'all'), bl.tm.Static()) S.setTM(T) S.fit() # test parameter distributions np.testing.assert_allclose( S.getParameterDistributions('mean', density=False)[1][:, 5], [0.01243717, 0.03016095, 0.016939, 0.00024909, 0.00024909], rtol=1e-04, err_msg='Erroneous posterior distribution values.') # test parameter mean values np.testing.assert_allclose( S.getParameterMeanValues('mean'), [0.96802204, 1.95705078, 3.47078681, 4.22225665, 4.22225665], rtol=1e-05, err_msg='Erroneous posterior mean values.') # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -15.072007461556161, decimal=5, err_msg='Erroneous log-evidence value.') # test hyper-parameter distribution x, p = S.getHyperParameterDistribution('sigma') np.testing.assert_allclose( np.array([x, p]), [[0., 0.2], [0.4963324, 0.5036676]], rtol=1e-05, err_msg='Erroneous values in hyper-parameter distribution.') # test duration distribution d, p = S.getDurationDistribution(['ChangePoint', 'BreakPoint']) np.testing.assert_allclose( np.array([d, p]), [[1., 2., 3.], [0.01039273, 0.49395867, 0.49564861]], rtol=1e-05, err_msg='Erroneous values in duration distribution.')
def test_distribution(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 50))) S.setTM(bl.tm.Static()) S.fit() S2 = bl.Study() S2.loadData(np.array([1, 2, 3, 4, 5])) S2.setOM(bl.om.Poisson('rate2', bl.oint(0, 6, 50))) S2.setTM(bl.tm.GaussianRandomWalk('sigma', 0.2, target='rate2')) S2.fit() P = bl.Parser(S, S2) x, p = P('log(rate2@1*2*1.2)+ 4 + rate@2^2') np.testing.assert_allclose(p[100:105], [0.00643873, 0.00618468, 0.00466452, 0.00314371, 0.00365816], rtol=1e-05, err_msg='Erroneous derived probability distribution.')
def test_poisson(self): S = bl.Study() S.loadData(np.array([1, 0, 1, 0, 0])) L = bl.om.Poisson('rate', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -4.433708287229158, decimal=5, err_msg='Erroneous log-evidence value.')
def test_scipy_2p(self): # carry out fit S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) def likelihood(data, mu, std): x = data pdf = np.exp((x - mu) ** 2. / (2 * std ** 2.)) / np.sqrt(2 * np.pi * std ** 2.) return pdf L = bl.om.NumPy(likelihood, 'mu', bl.oint(0, 7, 100), 'std', bl.oint(1, 2, 100)) S.setOM(L) S.setTM(bl.tm.Static()) S.fit() # test model evidence value np.testing.assert_almost_equal(S.logEvidence, 29.792823521784587, decimal=5, err_msg='Erroneous log-evidence value.')
def test_save_load(self): S = bl.HyperStudy() S.loadData(np.array([1, 2, 3, 4, 5])) S.setOM( bl.om.Gaussian('mean', bl.cint(0, 6, 20), 'sigma', bl.oint(0, 2, 20))) S.setTM(bl.tm.Static()) S.fit() bl.save('study.bl', S) S = bl.load('study.bl')
def test_bernoulli(self): S = bl.Study() S.loadData(np.array([1, 0, 1, 0, 0])) L = bl.om.Bernoulli('p', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -4.3494298741972859, decimal=5, err_msg='Erroneous log-evidence value.')
def test_gaussianmean(self): S = bl.Study() S.loadData(np.array([[1, 0.5], [0, 0.4], [1, 0.3], [0, 0.2], [0, 0.1]])) L = bl.om.GaussianMean('mu', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -6.3333705075036226, decimal=5, err_msg='Erroneous log-evidence value.')
def test_whitenoise(self): S = bl.Study() S.loadData(np.array([1, 0, 1, 0, 0])) L = bl.om.WhiteNoise('std', bl.oint(0, 1, 100)) T = bl.tm.Static() S.set(L, T) S.fit() np.testing.assert_almost_equal(S.logEvidence, -6.8161638661444073, decimal=5, err_msg='Erroneous log-evidence value.')
def test_dynamichyperparameter(self): S = bl.OnlineStudy(storeHistory=True) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 50))) S.add( 'gradual', bl.tm.GaussianRandomWalk('sigma', bl.cint(0, 0.2, 5), target='rate')) S.add('static', bl.tm.Static()) for d in np.arange(5): S.step(d) p = S.eval('exp(0.99*log(sigma@2))+1 > 1.1') np.testing.assert_almost_equal( p, 0.61228433813735061, decimal=5, err_msg='Erroneous parsing result for inequality.') S = bl.OnlineStudy(storeHistory=False) S.setOM(bl.om.Poisson('rate', bl.oint(0, 6, 50))) S.add( 'gradual', bl.tm.GaussianRandomWalk('sigma', bl.cint(0, 0.2, 5), target='rate')) S.add('static', bl.tm.Static()) for d in np.arange(3): S.step(d) p = S.eval('exp(0.99*log(sigma))+1 > 1.1') np.testing.assert_almost_equal( p, 0.61228433813735061, decimal=5, err_msg='Erroneous parsing result for inequality.')
def test_static(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) L = bl.om.Poisson('rate', bl.oint(0, 6, 100)) T = bl.tm.Static() S.set(L, T) S.fit() # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -10.372209708143769, decimal=5, err_msg='Erroneous log-evidence value.')
def test_regimeswitch(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) L = bl.om.Poisson('rate', bl.oint(0, 6, 100)) T = bl.tm.RegimeSwitch('p_min', -3) S.set(L, T) S.fit() # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -10.372866559561402, decimal=5, err_msg='Erroneous log-evidence value.')
def test_independent(self): S = bl.Study() S.loadData(np.array([1, 2, 3, 4, 5])) L = bl.om.Poisson('rate', bl.oint(0, 6, 100)) T = bl.tm.Independent() S.set(L, T) S.fit() # test model evidence value np.testing.assert_almost_equal(S.logEvidence, -11.087360077190617, decimal=5, err_msg='Erroneous log-evidence value.')