예제 #1
0
 def test_eval_sos(self):
     model, options, parameters, data = gf.setup_mcmc()
     SOS = SumOfSquares(model = model, data = data, parameters = parameters)
     theta = np.array([2., 5.])
     ss = SOS.evaluate_sos_function(theta = theta)
     self.assertTrue(isinstance(ss, np.ndarray), msg = 'Expect numpy array return')
     self.assertEqual(ss.size, 1, msg = 'Size of array is 1')
     self.assertTrue(isinstance(ss[0], float), msg = 'Numerical result returned')
     self.assertTrue(np.array_equal(SOS.value[SOS.parind], theta), msg = 'Value(s) updated')
예제 #2
0
 def test_eval_sos_model_cs(self):
     model, options, parameters, data = gf.setup_mcmc()
     model.sos_function = gf.custom_ssfun
     SOS = SumOfSquares(model=model, data=data, parameters=parameters)
     SOS.sos_style = 1
     theta = np.array([2., 5.])
     ss = SOS.evaluate_sos_function(theta)
     self.assertEqual(ss, None, msg='Expect None')
     ss = SOS.evaluate_sos_function(theta, custom=123)
     self.assertEqual(ss, 123, msg='Expect 123')
예제 #3
0
 def setup_dr(self):
     model, options, parameters, data, covariance, __, __, __, __ = gf.setup_mcmc_case_dr(
     )
     RDR = covariance._RDR
     invR = covariance._invR
     old_set = ParameterSet(theta=np.random.rand(2),
                            ss=np.array([10.2]),
                            sigma2=np.array([0.5]),
                            prior=np.array([0.5]))
     new_set = ParameterSet(theta=np.random.rand(2),
                            ss=np.array([8.2]),
                            sigma2=np.array([0.5]),
                            prior=np.array([0.5]))
     priorobj = PriorFunction(
         priorfun=model.prior_function,
         mu=parameters._thetamu[parameters._parind[:]],
         sigma=parameters._thetasigma[parameters._parind[:]])
     sosobj = SumOfSquares(model, data, parameters)
     DR = DelayedRejection()
     DR._initialize_dr_metrics(options=options)
     accept, out_set, outbound = DR.run_delayed_rejection(
         old_set=old_set,
         new_set=new_set,
         RDR=RDR,
         ntry=2,
         parameters=parameters,
         invR=invR,
         sosobj=sosobj,
         priorobj=priorobj)
     return accept, out_set, outbound
예제 #4
0
 def test_init_sos(self):
     model, __, parameters, data = gf.setup_mcmc()
     SOS = SumOfSquares(model = model, data = data, parameters = parameters)
     SOSD = SOS.__dict__
     check = {'nbatch': 1, 'parind': parameters._parind, 'value': parameters._value,
              'local': parameters._local, 'data': data, 'model_function': model.model_function,
              'sos_function': model.sos_function, 'sos_style': 1}
     items = ['nbatch', 'sos_style', 'sos_function', 'model_function', 'data']
     for ii, ai in enumerate(items):
         self.assertEqual(SOSD[ai], check[ai], msg = str('{}: {} != {}'.format(ai, SOSD[ai], check[ai])))
         
     array_items = ['parind', 'value', 'local']
     for ii, ai in enumerate(array_items):
         self.assertTrue(np.array_equal(SOSD[ai], check[ai]), msg = str('{}: {} != {}'.format(ai, SOSD[ai], check[ai])))
예제 #5
0
 def test_init_sos_model_function_is_none(self):
     model, options, parameters, data = gf.setup_mcmc()
     model.sos_function = None
     model.model_function = None
     with self.assertRaises(SystemExit):
         SumOfSquares(model = model, data = data, parameters = parameters)