def test_setup_labels_pi_none_nlines_2(self):
     PI = PredictionIntervals()
     clabels, plabels = PI._setup_labels(prediction_intervals=None,
                                         nlines=2)
     self.assertEqual(clabels, ['99% CI', '95% CI', '90% CI', '50% CI'],
                      msg='String should match')
     self.assertEqual(plabels, ['95% PI'], msg='String should match')
 def test_setup_counting_metrics(self):
     PI = PredictionIntervals()
     ci = gf.setup_pseudo_ci()
     nbatch, nn, nlines = PI._setup_counting_metrics(credible_intervals=ci)
     self.assertEqual(nbatch, 1, msg='Expect nbatch = 1')
     self.assertEqual(nn, 2, msg='Expect nn = 2')
     self.assertEqual(nlines, 1, msg='Expect nlines = 1')
 def test_basic_ds_shape_0(self):
     PI = PredictionIntervals()
     DS = gf.basic_data_structure()
     DS.shape = [(100, )]  # remove column - code should add it back
     ndatabatches, ncols = PI._analyze_data_structure(data=DS)
     self.assertEqual(ndatabatches, 1, msg='Expect 1 batch')
     self.assertEqual(ncols, [1], msg='Expect [1]')
 def test_setup_int_lims_s2chain_none(self):
     PI = PredictionIntervals()
     lims = PI._setup_interval_limits(s2chain=None)
     self.assertTrue(np.array_equal(
         lims,
         np.array([0.005, 0.025, 0.05, 0.25, 0.5, 0.75, 0.9, 0.975,
                   0.995])),
                     msg=str('Arrays should match: {}'.format(lims)))
def pi_setup():
    PI = PredictionIntervals()
    results = gf.setup_pseudo_results()
    DS = gf.basic_data_structure()
    PI.setup_prediction_interval_calculation(results=results,
                                             data=DS,
                                             modelfunction=gf.predmodelfun)
    return PI, results
 def test_setup_sstype(self):
     PI = PredictionIntervals()
     PI._PredictionIntervals__sstype = 3
     sstype = PI._setup_sstype(sstype=None)
     self.assertEqual(sstype,
                      PI._PredictionIntervals__sstype,
                      msg='Expected 3')
     sstype = PI._setup_sstype(sstype=2)
     self.assertEqual(sstype, 0, msg='Expected 0')
 def test_s2chain_index_n_neq_1_tc_neq_n_neq_ndatabatches(self):
     PI = PredictionIntervals()
     ndatabatches = 5
     s2chain = np.random.random_sample(size=(100, 3))
     ncol = [1, 2, 1]
     with self.assertRaises(SystemExit, msg='Unrecognized data structure'):
         PI._analyze_s2chain(ndatabatches=ndatabatches,
                             s2chain=s2chain,
                             ncol=ncol)
 def test_define_sample_points_nsample_lte_nsimu(self, mock_rand):
     PI = PredictionIntervals()
     aa = np.random.rand([400, 1])
     mock_rand.return_value = aa
     iisample, nsample = PI._define_sample_points(nsample=400, nsimu=500)
     self.assertTrue(np.array_equal(iisample,
                                    np.ceil(aa * 500) - 1),
                     msg='Expect range(500)')
     self.assertEqual(nsample, 400, msg='Expect nsample to stay 400')
 def test_basic_datapred(self):
     PI = PredictionIntervals()
     DS = gf.basic_data_structure()
     datapred = PI._setup_data_structure_for_prediction(data=DS,
                                                        ndatabatches=1)
     self.assertTrue(np.array_equal(datapred[0].xdata[0], DS.xdata[0]),
                     msg='Arrays should match')
     self.assertTrue(np.array_equal(datapred[0].ydata[0], DS.ydata[0]),
                     msg='Arrays should match')
 def test_feature_assignment(self):
     PI = PredictionIntervals()
     results = gf.setup_pseudo_results()
     PI._assign_features_from_results_structure(results=results)
     PID = PI.__dict__
     check_these = [
         'chain', 's2chain', 'parind', 'local', 'theta', 'sstype'
     ]
     self.check_dictionary(check_these, PID, results)
 def test_does_observation_sample_off_s2elem_greater_than_1_cause_system_exit(
         self):
     PI = PredictionIntervals()
     s2elem = np.array([[2.0, 1.0]])
     ypred = np.linspace(2.0, 3.0, num=15)
     ypred = ypred.reshape(5, 3)
     sstype = 0
     with self.assertRaises(SystemExit):
         PI._observation_sample(s2elem, ypred, sstype)
 def test_second_feature_assignment(self):
     PI = PredictionIntervals()
     results = gf.setup_pseudo_results()
     results = gf.removekey(results, 'sstype')
     PI._assign_features_from_results_structure(results=results)
     PID = PI.__dict__
     check_these = ['chain', 's2chain', 'parind', 'local', 'theta']
     self.check_dictionary(check_these, PID, results)
     self.assertEqual(PID['_PredictionIntervals__sstype'],
                      0,
                      msg='Should default to 0')
 def test_s2chain_index_n_eq_1(self):
     PI = PredictionIntervals()
     ndatabatches = 1
     s2chain = np.random.random_sample(size=(100, 1))
     ncol = [1]
     s2chain_index = PI._analyze_s2chain(ndatabatches=ndatabatches,
                                         s2chain=s2chain,
                                         ncol=ncol)
     self.assertTrue(np.array_equal(s2chain_index, np.array([[0, 1]])),
                     msg=str(
                         'Arrays should match: {}'.format(s2chain_index)))
 def test_does_observation_sample_wrong_size_s2elem_break_right_size_array(
         self):
     PI = PredictionIntervals()
     s2elem = np.array([[2.0, 1.0]])
     ypred = np.linspace(2.0, 3.0, num=5)
     ypred = ypred.reshape(5, 1)
     sstype = 0
     with self.assertRaises(
             SystemExit,
             msg='Mismatched size for s2chain and model return'):
         PI._observation_sample(s2elem, ypred, sstype)
 def test_non_basic_modelfunction(self):
     PI = PredictionIntervals()
     DS = gf.non_basic_data_structure()
     datapred = PI._setup_data_structure_for_prediction(data=DS,
                                                        ndatabatches=2)
     nrow, ncol = PI._determine_shape_of_response(
         modelfunction=gf.predmodelfun,
         ndatabatches=2,
         datapred=datapred,
         theta=[3.0, 5.0])
     self.assertEqual(nrow, [100, 100], msg='Expect [100, 100]')
     self.assertEqual(ncol, [1, 1], msg='Expect [1, 1]')
    def test_does_observation_sample_unknown_sstype_cause_system_exit(self):
        PI = PredictionIntervals()
        s2elem = np.array([[2.0]])
        ypred = np.linspace(2.0, 3.0, num=5)
        ypred = ypred.reshape(5, 1)
        sstype = 4
        with self.assertRaises(SystemExit, msg='Unrecognized sstype'):
            PI._observation_sample(s2elem, ypred, sstype)

        sstype = 0
        opred = PI._observation_sample(s2elem, ypred, sstype)
        self.assertEqual(opred.shape, ypred.shape, msg='Shapes should match')
 def test_add_batch_column_title_ny_gt_1(self):
     PI = PredictionIntervals()
     htmp, ax = PI._initialize_plot_features(ii=0,
                                             jj=0,
                                             ny=1,
                                             figsizeinches=[10, 11])
     PI._add_batch_column_title(nbatch=1, ny=2, ii=0, jj=0)
     self.assertEqual(ax.get_title(),
                      'Column #0',
                      msg='Strings should match')
     self.assertEqual(htmp.get_figwidth(), 10.0, msg='Expect 10.0')
     self.assertEqual(htmp.get_figheight(), 11.0, msg='Expect 11.0')
 def test_initialize_plot_features(self):
     PI = PredictionIntervals()
     htmp, ax = PI._initialize_plot_features(ii=0,
                                             jj=0,
                                             ny=1,
                                             figsizeinches=[10, 11])
     self.assertEqual(htmp.get_figwidth(), 10.0, msg='Figure width is 10in')
     self.assertEqual(htmp.get_figheight(),
                      11.0,
                      msg='Figure height is 11in')
     self.assertEqual(htmp.get_label(),
                      'Batch # 0 | Column # 0',
                      msg='Strings should match')
     self.assertEqual(ax.get_label(), '', msg='Expect empty string')
 def check_these_settings(self, infigsizeinches, expected):
     PI = PredictionIntervals()
     ci = gf.setup_pseudo_ci()
     prediction_intervals, figsizeinches, nbatch, nn, clabels, plabels = PI._setup_interval_plotting(
         plot_pred_int=True,
         prediction_intervals=None,
         credible_intervals=ci,
         figsizeinches=infigsizeinches)
     self.assertEqual(figsizeinches,
                      expected,
                      msg=str('Expect {}'.format(expected)))
     self.assertEqual(prediction_intervals, None, msg='Expect None')
     self.assertEqual(nbatch, 1, msg='Expect nbatch = 1')
     self.assertEqual(nn, 2, msg='Expect nn = 2')
     self.assertEqual(clabels, ['95% CI'], msg='String should match')
     self.assertEqual(plabels, ['95% PI'], msg='String should match')
 def test_setup_display_settings(self):
     PI = PredictionIntervals()
     model_display = {'label': 'hello'}
     data_display = {'linewidth': 7}
     interval_display = {'edgecolor': 'b'}
     intd, modd, datd = PI._setup_display_settings(
         interval_display=interval_display,
         model_display=model_display,
         data_display=data_display)
     self.assertEqual(modd['label'],
                      model_display['label'],
                      msg='Expect label to match')
     self.assertEqual(intd['edgecolor'],
                      interval_display['edgecolor'],
                      msg='Expect edgecolor to match')
     self.assertEqual(datd['linewidth'],
                      data_display['linewidth'],
                      msg='Expect linewidth to match')
 def test_setup_pi_calc_with_s2chain_none(self):
     PI = PredictionIntervals()
     DS = gf.basic_data_structure()
     results = gf.setup_pseudo_results()
     results['s2chain'] = None
     PI.setup_prediction_interval_calculation(results=results,
                                              data=DS,
                                              modelfunction=gf.predmodelfun)
     self.assertEqual(PI._PredictionIntervals__ndatabatches,
                      1,
                      msg='Expect ndatabatches = 1')
     self.assertEqual(PI.modelfunction,
                      gf.predmodelfun,
                      msg='Functions should match')
     self.assertFalse(hasattr(PI, '_PredictionIntervals__s2chain_index'),
                      msg='Expect False')
     self.assertTrue(np.array_equal(PI._PredictionIntervals__chain,
                                    results['chain']),
                     msg='Arrays should match')
def cc_setup(calc_pred_int=True):
    PI = PredictionIntervals()
    results = gf.setup_pseudo_results()
    PI._assign_features_from_results_structure(results=results)
    testchain, s2chain, lims, sstype, nsample, iisample = PI._setup_generation_requirements(
        nsample=400, calc_pred_int=calc_pred_int, sstype=0)
    DS = gf.basic_data_structure()
    datapred = PI._setup_data_structure_for_prediction(data=DS, ndatabatches=1)
    return PI, results, testchain, s2chain, lims, sstype, nsample, iisample, datapred
 def setup_complex_pi(cls):
     PI = PredictionIntervals()
     results = gf.setup_pseudo_results()
     results['s2chain'] = None
     DS = gf.basic_data_structure()
     PI.setup_prediction_interval_calculation(results=results,
                                              data=DS,
                                              modelfunction=gf.predmodelfun)
     PI.generate_prediction_intervals(sstype=0,
                                      nsample=500,
                                      calc_pred_int=False,
                                      waitbar=False)
     return PI
 def test_generate_credible_intervals(self):
     PI = PredictionIntervals()
     results = gf.setup_pseudo_results()
     results['s2chain'] = None
     DS = gf.basic_data_structure()
     PI.setup_prediction_interval_calculation(results=results,
                                              data=DS,
                                              modelfunction=gf.predmodelfun)
     PI.generate_prediction_intervals(sstype=None,
                                      nsample=500,
                                      calc_pred_int=False,
                                      waitbar=False)
     cint = PI.intervals['credible_intervals']
     pint = PI.intervals['prediction_intervals']
     self.common_set_1(cint, pint)
 def test_generate_credible_intervals_with_waitbar(self):
     PI = PredictionIntervals()
     results = gf.setup_pseudo_results()
     results['s2chain'] = None
     DS = gf.basic_data_structure()
     PI.setup_prediction_interval_calculation(results=results,
                                              data=DS,
                                              modelfunction=gf.predmodelfun)
     PI.generate_prediction_intervals(sstype=None,
                                      nsample=500,
                                      calc_pred_int=False,
                                      waitbar=True)
     cint = PI.intervals['credible_intervals']
     pint = PI.intervals['prediction_intervals']
     self.common_set_1(cint, pint)
     self.assertEqual(PI._PredictionIntervals__wbarstatus.percentage(3),
                      3.0,
                      msg='Expect 3.0')
    def test_does_observation_sample_2_column_ypred_right_size_array(self):
        PI = PredictionIntervals()
        ypred = np.linspace(2.0, 3.0, num=10)
        ypred = ypred.reshape(5, 2)

        s2elem = np.array([[2.0, 1.0]])
        sstype = 0
        opred = PI._observation_sample(s2elem, ypred, sstype)
        self.assertEqual(opred.shape, ypred.shape, msg='Shapes are compatible')

        s2elem = np.array([[2.0]])
        opred = PI._observation_sample(s2elem, ypred, sstype)
        self.assertEqual(opred.shape, ypred.shape, msg='Shapes are compatible')

        sstype = 1
        opred = PI._observation_sample(s2elem, ypred, sstype)
        self.assertEqual(opred.shape, ypred.shape, msg='Shapes are compatible')

        sstype = 2
        opred = PI._observation_sample(s2elem, ypred, sstype)
        self.assertEqual(opred.shape, ypred.shape, msg='Shapes are compatible')
 def test_ds_2_nbatch(self):
     PI = PredictionIntervals()
     DS = gf.non_basic_data_structure()
     ndatabatches, ncols = PI._analyze_data_structure(data=DS)
     self.assertEqual(ndatabatches, 2, msg='Expect 2 batches')
     self.assertEqual(ncols, [1, 2], msg='Expect [1, 1]')
 def test_basic_ds(self):
     PI = PredictionIntervals()
     DS = gf.basic_data_structure()
     ndatabatches, ncols = PI._analyze_data_structure(data=DS)
     self.assertEqual(ndatabatches, 1, msg='Expect 1 batch')
     self.assertEqual(ncols, [1], msg='Expect [1]')
 def setup_interval(cls):
     PI = PredictionIntervals()
     DS = gf.basic_data_structure()
     datapred = PI._setup_data_structure_for_prediction(data=DS,
                                                        ndatabatches=1)
     return PI, datapred
def gq_settings():
    PI = PredictionIntervals()
    nsample = 500
    nrow = 100
    ncol = 1
    return PI, nsample, nrow, ncol