Exemplo n.º 1
0
    def Test_sampling_error(self):
        """
        Testing :meth:`bet.calculateP.calculateError.sampling_error`
        """
        num = self.disc.check_nums()
        neiList = calculateError.cell_connectivity_exact(self.disc)
        for i in range(num):
            self.assertGreater(len(neiList[i]), 0)
        (B_N, C_N) = calculateError.boundary_sets(self.disc, neiList)
        s_error = calculateError.sampling_error(self.disc, exact=True)
        (upper, lower) = s_error.calculate_for_contour_events()
        for x in upper:
            if not np.isnan(x):
                self.assertGreaterEqual(x, 0.0)

        for x in lower:
            if not np.isnan(x):
                self.assertLessEqual(x, 0.0)

        s_set = self.disc._input_sample_set.copy()
        regions_local = np.equal(self.disc._io_ptr_local, 0)
        s_set.set_region_local(regions_local)
        s_set.local_to_global()
        (up, low) = s_error.calculate_for_sample_set_region(s_set,
                                                            1)
        if not np.isnan(up):
            self.assertAlmostEqual(up, upper[0])
        else:
            self.assertTrue(np.isnan(upper[0]))
        if not np.isnan(low):
            self.assertAlmostEqual(low, lower[0])
        else:
            self.assertTrue(np.isnan(lower[0]))

        (up, low) = s_error.calculate_for_sample_set_region(s_set,
                                                            1,
                                                            emulated_set=self.disc._input_sample_set)
        if np.isnan(up):
            self.assertEqual(np.isnan(upper[0]), True)
        else:
            self.assertAlmostEqual(up, upper[0])

        if np.isnan(low):
            self.assertEqual(np.isnan(lower[0]), True)
        else:
            self.assertAlmostEqual(low, lower[0])

        self.disc.set_emulated_input_sample_set(self.disc._input_sample_set)
        (up, low) = s_error.calculate_for_sample_set_region(s_set,
                                                            1)
        if np.isnan(up):
            self.assertEqual(np.isnan(upper[0]), True)
        else:
            self.assertAlmostEqual(up, upper[0])

        if np.isnan(low):
            self.assertEqual(np.isnan(lower[0]), True)
        else:
            self.assertAlmostEqual(low, lower[0])
Exemplo n.º 2
0
    def Test_sampling_error(self):
        """
        Testing :meth:`bet.calculateP.calculateError.sampling_error`
        """
        num = self.disc.check_nums()
        neiList = calculateError.cell_connectivity_exact(self.disc)
        for i in range(num):
            self.assertGreater(len(neiList[i]), 0)
        (B_N, C_N) = calculateError.boundary_sets(self.disc, neiList)
        s_error = calculateError.sampling_error(self.disc, exact=True)
        (upper, lower) = s_error.calculate_for_contour_events()
        for x in upper:
            if not np.isnan(x):
                self.assertGreaterEqual(x, 0.0)

        for x in lower:
            if not np.isnan(x):
                self.assertLessEqual(x, 0.0)

        s_set = self.disc._input_sample_set.copy()
        regions_local = np.equal(self.disc._io_ptr_local, 0)
        s_set.set_region_local(regions_local)
        s_set.local_to_global()
        (up, low) = s_error.calculate_for_sample_set_region(s_set, 1)
        if not np.isnan(up):
            self.assertAlmostEqual(up, upper[0])
        else:
            self.assertTrue(np.isnan(upper[0]))
        if not np.isnan(low):
            self.assertAlmostEqual(low, lower[0])
        else:
            self.assertTrue(np.isnan(lower[0]))

        (up, low) = s_error.calculate_for_sample_set_region(
            s_set, 1, emulated_set=self.disc._input_sample_set)
        if np.isnan(up):
            self.assertEqual(isnan(upper[0]), True)
        else:
            self.assertAlmostEqual(up, upper[0])

        if np.isnan(low):
            self.assertEqual(isnan(lower[0]), True)
        else:
            self.assertAlmostEqual(low, lower[0])

        self.disc.set_emulated_input_sample_set(self.disc._input_sample_set)
        (up, low) = s_error.calculate_for_sample_set_region(s_set, 1)
        if np.isnan(up):
            self.assertEqual(isnan(upper[0]), True)
        else:
            self.assertAlmostEqual(up, upper[0])

        if np.isnan(low):
            self.assertEqual(isnan(lower[0]), True)
        else:
            self.assertAlmostEqual(low, lower[0])
Exemplo n.º 3
0
sur = surrogates.piecewise_polynomial_surrogate(my_disc_exact)
sur_disc_lin = sur.generate_for_input_set(emulated_inputs, order=1)
(Pt, _) = sur.calculate_prob_for_sample_set_region(s_set, 
                                                         regions=[0])
P_true = Pt[0]
if comm.rank == 0:
    print "True probability: ",  P_true

# Approximate probabilty
P_approx  = calculateP.prob_from_sample_set(my_disc._input_sample_set,
                                             s_set)[0]
if comm.rank == 0:
    print "Approximate probability: ",  P_approx

# Calculate sampling error
samp_er = calculateError.sampling_error(my_disc)
(up, low) = samp_er.calculate_for_sample_set_region(s_set, 
                                                    region=0, emulated_set=emulated_inputs)
if comm.rank == 0:
    print "Sampling error upper bound: ", up
    print "Sampling error lower bound: ", low


# Calculate modeling error
mod_er = calculateError.model_error(my_disc)
er_est = mod_er.calculate_for_sample_set_region(s_set, 
                    region=0, emulated_set=emulated_inputs)
if comm.rank == 0:
    print "Modeling error estimate: ", er_est

# Make piecewise constant surrogate of discretization
Exemplo n.º 4
0
# Calculate true probabilty using linear surrogate on true data
sur = surrogates.piecewise_polynomial_surrogate(my_disc_exact)
sur_disc_lin = sur.generate_for_input_set(emulated_inputs, order=1)
(Pt, _) = sur.calculate_prob_for_sample_set_region(s_set, regions=[0])
P_true = Pt[0]
if comm.rank == 0:
    print "True probability: ", P_true

# Approximate probabilty
P_approx = calculateP.prob_from_sample_set(my_disc._input_sample_set, s_set)[0]
if comm.rank == 0:
    print "Approximate probability: ", P_approx

# Calculate sampling error
samp_er = calculateError.sampling_error(my_disc)
(up,
 low) = samp_er.calculate_for_sample_set_region(s_set,
                                                region=0,
                                                emulated_set=emulated_inputs)
if comm.rank == 0:
    print "Sampling error upper bound: ", up
    print "Sampling error lower bound: ", low

# Calculate modeling error
mod_er = calculateError.model_error(my_disc)
er_est = mod_er.calculate_for_sample_set_region(s_set,
                                                region=0,
                                                emulated_set=emulated_inputs)
if comm.rank == 0:
    print "Modeling error estimate: ", er_est