Ejemplo n.º 1
0
    def setUp(self):
        """
        Setup map.
        """
        param_ref = np.array([0.5, 0.5, 0.5])
        Q_ref = linear_model1(param_ref)

        sampler = bsam.sampler(linear_model1)
        input_samples = sample.sample_set(3)
        input_samples.set_domain(np.repeat([[0.0, 1.0]], 3, axis=0))
        input_samples = sampler.random_sample_set('random',
                                                  input_samples,
                                                  num_samples=1E2)
        disc = sampler.compute_QoI_and_create_discretization(input_samples,
                                                             globalize=True)
        simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(
            data_set=disc, Q_ref=Q_ref, rect_scale=0.5)
        num = disc.check_nums()
        disc._output_sample_set.set_error_estimates(0.01 * np.ones((num, 2)))
        jac = np.zeros((num, 2, 3))
        jac[:, :, :] = np.array([[0.506, 0.463], [0.253, 0.918],
                                 [0.085, 0.496]]).transpose()

        disc._input_sample_set.set_jacobians(jac)
        self.sur = surrogates.piecewise_polynomial_surrogate(disc)
Ejemplo n.º 2
0
    def setUp(self):
        """
        Setup map.
        """
        param_ref = np.array([0.5, 0.5, 0.5])
        Q_ref =  linear_model1(param_ref)
        
        sampler = bsam.sampler(linear_model1)
        input_samples = sample.sample_set(3)
        input_samples.set_domain(np.repeat([[0.0, 1.0]], 3, axis=0))
        input_samples = sampler.random_sample_set('random', input_samples, num_samples=1E2)
        disc = sampler.compute_QoI_and_create_discretization(input_samples, 
                                                             globalize=True)
        simpleFunP.regular_partition_uniform_distribution_rectangle_scaled(
        data_set=disc, Q_ref=Q_ref, rect_scale=0.5)
        num = disc.check_nums()
        disc._output_sample_set.set_error_estimates(0.01 * np.ones((num, 2)))
        jac = np.zeros((num,2,3))
        jac[:,:,:] = np.array([[0.506, 0.463],[0.253, 0.918], [0.085, 0.496]]).transpose()

        disc._input_sample_set.set_jacobians(jac)
        self.sur = surrogates.piecewise_polynomial_surrogate(disc)
Ejemplo n.º 3
0
my_disc_exact._output_sample_set._error_estimates_local = np.zeros(my_disc_exact._output_sample_set._error_estimates_local.shape)
my_disc_exact._output_sample_set.local_to_global()
my_disc_exact.set_emulated_input_sample_set(emulated_inputs2)

# Solve stochastic inverse problems
my_disc.set_emulated_input_sample_set(emulated_inputs)
calculateP.prob_with_emulated_volumes(my_disc)
calculateP.prob_with_emulated_volumes(my_disc_exact)

# Set in input space to calculate errors for
s_set = samp.rectangle_sample_set(3)
s_set.setup(maxes=[[0.75, 0.75, 0.75]], mins=[[0.25, 0.25, 0.25]])
s_set.set_region(np.array([0,1]))

# 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)
Ejemplo n.º 4
0
    my_disc_exact._output_sample_set._error_estimates_local.shape)
my_disc_exact._output_sample_set.local_to_global()
my_disc_exact.set_emulated_input_sample_set(emulated_inputs2)

# Solve stochastic inverse problems
my_disc.set_emulated_input_sample_set(emulated_inputs)
calculateP.prob_with_emulated_volumes(my_disc)
calculateP.prob_with_emulated_volumes(my_disc_exact)

# Set in input space to calculate errors for
s_set = samp.rectangle_sample_set(3)
s_set.setup(maxes=[[0.75, 0.75, 0.75]], mins=[[0.25, 0.25, 0.25]])
s_set.set_region(np.array([0, 1]))

# 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,