Пример #1
0
def postprocess(station_nums, ref_num):
    
    filename = 'P_q'+str(station_nums[0]+1)+'_q'+str(station_nums[1]+1)
    if len(station_nums) == 3:
        filename += '_q'+str(station_nums[2]+1)
    filename += '_ref_'+str(ref_num+1)

    data = Q[:, station_nums]
    q_ref = Q_ref[ref_num, station_nums]

    # Create Simple function approximation
    # Save points used to parition D for simple function approximation and the
    # approximation itself (this can be used to make close comparisions...)
    (rho_D_M, d_distr_samples, d_Tree) = sfun.uniform_hyperrectangle(data,
            q_ref, bin_ratio=0.15,
            center_pts_per_edge=np.ones((data.shape[1],)))

    num_l_emulate = 1e6
    lambda_emulate = calcP.emulate_iid_lebesgue(lam_domain, num_l_emulate)
    
    if comm.rank == 0:
        print "Finished emulating lambda samples"
        mdict = dict()
        mdict['rho_D_M'] = rho_D_M
        mdict['d_distr_samples'] = d_distr_samples 
        mdict['num_l_emulate'] = num_l_emulate

    # Calculate P on lambda emulate
    (P0, lem0, io_ptr0, emulate_ptr0) = calcP.prob_emulated(samples, data,
            rho_D_M, d_distr_samples, lambda_emulate, d_Tree)
    if comm.rank == 0:
        print "Calculating prob_emulated"
        mdict['P0'] = P0
        mdict['lem0'] = lem0
        mdict['io_ptr0'] = io_ptr0
        mdict['emulate_ptr0'] = emulate_ptr0

    # Calclate P on the actual samples with assumption that voronoi cells have
    # equal size
    (P1, lam_vol1, io_ptr1) = calcP.prob(samples, data,
            rho_D_M, d_distr_samples, d_Tree)
    if comm.rank == 0:
        print "Calculating prob"
        mdict['P1'] = P1
        mdict['lam_vol1'] = lam_vol1
        mdict['lem1'] = samples
        mdict['io_ptr1'] = io_ptr1

    # Calculate P on the actual samples estimating voronoi cell volume with MC
    # integration
    (P3, lam_vol3, lambda_emulate3, io_ptr3, emulate_ptr3) = calcP.prob_mc(samples,
            data, rho_D_M, d_distr_samples, lambda_emulate, d_Tree)
    if comm.rank == 0:
        print "Calculating prob_mc"
        mdict['P3'] = P3
        mdict['lam_vol3'] = lam_vol3
        mdict['io_ptr3'] = io_ptr3
        mdict['emulate_ptr3'] = emulate_ptr3
        # Export P
        sio.savemat(filename, mdict, do_compression=True)
Пример #2
0
def postprocess(station_nums, ref_num):
    
    filename = 'P_q'+str(station_nums[0]+1)+'_q'
    if len(station_nums) == 3:
        filename += '_q'+str(station_nums[2]+1)
    filename += '_ref_'+str(ref_num+1)

    data = Q[:, station_nums]
    q_ref = Q_ref[ref_num, station_nums]

    # Create Simple function approximation
    # Save points used to parition D for simple function approximation and the
    # approximation itself (this can be used to make close comparisions...)
    (rho_D_M, d_distr_samples, d_Tree) = sfun.uniform_hyperrectangle(data,
            q_ref, bin_ratio=0.15,
            center_pts_per_edge=np.ones((data.shape[1],)))

    num_l_emulate = 1e6
    lambda_emulate = calcP.emulate_iid_lebesgue(lam_domain, num_l_emulate)
    print "Finished emulating lambda samples"

    mdict = dict()
    mdict['rho_D_M'] = rho_D_M
    mdict['d_distr_samples'] = d_distr_samples 
    mdict['num_l_emulate'] = num_l_emulate
    mdict['lambda_emulate'] = lambda_emulate

    # Calculate P on lambda emulate
    (P0, lem0, io_ptr0, emulate_ptr0) = calcP.prob_emulated(samples, data,
            rho_D_M, d_distr_samples, lambda_emulate, d_Tree)
    print "Calculating prob_emulated"
    mdict['P0'] = P0
    mdict['lem0'] = lem0
    mdict['io_ptr0'] = io_ptr0
    mdict['emulate_ptr0'] = emulate_ptr0

    # Calclate P on the actual samples with assumption that voronoi cells have
    # equal size
    (P1, lam_vol1, io_ptr1) = calcP.prob(samples, data,
            rho_D_M, d_distr_samples, d_Tree)
    print "Calculating prob"
    mdict['P1'] = P1
    mdict['lam_vol1'] = lam_vol1
    mdict['lem1'] = samples
    mdict['io_ptr1'] = io_ptr1

    # Calculate P on the actual samples estimating voronoi cell volume with MC
    # integration
    (P3, lam_vol3, lambda_emulate3, io_ptr3, emulate_ptr3) = calcP.prob_mc(samples,
            data, rho_D_M, d_distr_samples, lambda_emulate, d_Tree)
    print "Calculating prob_mc"
    mdict['P3'] = P3
    mdict['lam_vol3'] = lam_vol3
    mdict['io_ptr3'] = io_ptr3
    mdict['emulate_ptr3'] = emulate_ptr3
    # Export P
    sio.savemat(filename, mdict, do_compression=True)
Пример #3
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_emulated_1to1, self).setUp()
     (self.P_emulate, self.lambda_emulate, _, _) =\
             calcP.prob_emulated(samples=self.samples, data=self.data,
                     rho_D_M=self.d_distr_prob,
                     d_distr_samples=self.d_distr_samples,
                     lambda_emulate=self.lambda_emulate, d_Tree=self.d_Tree)
     self.P_emulate = util.get_global_values(self.P_emulate)
Пример #4
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_emulated_3to1, self).setUp()
     (self.P_emulate, self.lambda_emulate, _, _) = calcP.prob_emulated(\
             samples=self.samples, data=self.data,
             rho_D_M=self.d_distr_prob,
             d_distr_samples=self.d_distr_samples,
             lambda_emulate=self.lambda_emulate, d_Tree=self.d_Tree)
     self.P_emulate_ref = np.loadtxt(data_path+"/3to1_prob_emulated.txt.gz")
     self.P_emulate = util.get_global_values(self.P_emulate)
Пример #5
0
    def setUp(self):
        """
        Set up problem.
        """
        super(Test_prob_emulated_1to1, self).setUp()

        (self.P_emulate, self.lambda_emulate, _,
         _) = calcP.prob_emulated(samples=self.samples,
                                  data=self.data,
                                  rho_D_M=self.d_distr_prob,
                                  d_distr_samples=self.d_distr_samples,
                                  lambda_emulate=self.lambda_emulate,
                                  d_Tree=self.d_Tree)
        self.P_emulate = util.get_global_values(self.P_emulate)
Пример #6
0
    def generate_results(self):
        """
        Generate the mix of results from
        :meth:~`bet.calculateP.calculateP.prob_emulated`,
        :meth:~`bet.calculateP.calculateP.prob`, and
        :meth:~`bet.calculateP.calculateP.prob_mc` to be used in test
        subclasses
        """

        # RESULTS WHERE SAMPLES = LAMBDA_EMULATE
        # samples are on a regular grid
        # result_wtree, result_wsamples, result_emulated_rg
        self.result_emulated_rg = calcP.prob_emulated(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.r_samples, self.d_Tree)
Пример #7
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_emulated_3to1, self).setUp()
     (self.P_emulate, self.lambda_emulate, _,
      _) = calcP.prob_emulated(samples=self.samples,
                               data=self.data,
                               rho_D_M=self.d_distr_prob,
                               d_distr_samples=self.d_distr_samples,
                               lambda_emulate=self.lambda_emulate,
                               d_Tree=self.d_Tree)
     self.P_emulate_ref = np.loadtxt(data_path +
                                     "/3to1_prob_emulated.txt.gz")
     self.P_emulate = util.get_global_values(self.P_emulate)
Пример #8
0
        Generate the mix of results from
        :meth:~`bet.calculateP.calculateP.prob_emulated`,
        :meth:~`bet.calculateP.calculateP.prob`, and
        :meth:~`bet.calculateP.calculateP.prob_mc` to be used in test
        subclasses
        """

        # RESULTS WHERE SAMPLES = LAMBDA_EMULATE
        # samples are on a regular grid
        # result_wtree, result_wsamples, result_emulated_rg
        self.result_emulated_rg = calcP.prob_emulated(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.r_samples, self.d_Tree)
        self.result_wtree = result_emulated_rg
        self.result_wsamples = result_emulated_rg
        self.result_wotree = calcP.prob_emulated(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.r_samples)
        self.result_wosamples = calcP.prob_emulated(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain)

        self.result_prob_rg = calcP.prob(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.d_Tree)
        self.result_mc_rg = calcP.prob_mc(self.r_samples, self.r_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.r_samples, self.d_Tree)

        # samples are iid
        self.result_emulated_iid = calcP.prob_emulated(self.u_samples, self.u_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
Voronoi cell is assumed to have the same measure. This type of
approximation is more reasonable for large n_samples due to the slow
convergence rate of Monte Carlo (it converges like 1/sqrt(n_samples)).
'''
if random_sample is False:
    lambda_emulate = samples
else:
    lambda_emulate = calculateP.emulate_iid_lebesgue(
        lam_domain=lam_domain, num_l_emulate=1E5)


# calculate probablities
(P, lambda_emulate, io_ptr, emulate_ptr) = \
    calculateP.prob_emulated(samples=samples,
                             data=data,
                             rho_D_M=d_distr_prob,
                             d_distr_samples=d_distr_samples,
                             lambda_emulate=lambda_emulate,
                             d_Tree=d_Tree)

# calculate 2d marginal probs
'''
Suggested changes for user:

At this point, the only thing that should change in the plotP.* inputs
should be either the nbins values or sigma (which influences the kernel
density estimation with smaller values implying a density estimate that
looks more like a histogram and larger values smoothing out the values
more).

There are ways to determine "optimal" smoothing parameters (e.g., see CV, GCV,
and other similar methods), but we have not incorporated these into the code