예제 #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 setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_mc_1to1, self).setUp()
     (self.P, self.lam_vol, _, _, _) = calcP.prob_mc(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)
예제 #3
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)
예제 #4
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_mc_3to1, self).setUp()
     (self.P, self.lam_vol, _, _, _) = calcP.prob_mc(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_ref = np.loadtxt(data_path + "/3to1_prob_mc.txt.gz")
예제 #5
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_mc_1to1, self).setUp()
     (self.P, self.lam_vol, _, _,
      _) = calcP.prob_mc(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)
예제 #6
0
 def setUp(self):
     """
     Set up problem.
     """
     super(Test_prob_mc_3to1, self).setUp()
     (self.P, self.lam_vol, _, _,
      _) = calcP.prob_mc(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_ref = np.loadtxt(data_path + "/3to1_prob_mc.txt.gz")
예제 #7
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 += '_truth_'+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"

    # 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, lam_domain, lambda_emulate, d_Tree)
    print "Calculating prob_mc"
    mdict = dict()
    mdict['rho_D_M'] = rho_D_M
    mdict['d_distr_samples'] = d_distr_samples 
    mdict['lambda_emulate'] = util.get_global_values(lambda_emulate)   
    mdict['num_l_emulate'] = mdict['lambda_emulate'].shape[1]
    mdict['P3'] = util.get_global_values(P3)
    mdict['lam_vol3'] = util.get_global_values(lam_vol3)
    mdict['io_ptr3'] = util.get_global_values(io_ptr3)
    mdict['emulate_ptr3'] = emulate_ptr3
        
    if rank == 0:
        # Export P and compare to MATLAB solution visually
        sio.savemat(filename, mdict, do_compression=True)
예제 #8
0
        # 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,
                self.u_samples, self.d_Tree)
        self.result_prob_iid = calcP.prob(self.u_samples, self.u_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.d_Tree)
        self.result_mc_iid = calcP.prob_mc(self.u_samples, self.u_data,
                self.rho_D_M, self.d_distr_samples, self.lam_domain,
                self.u_samples, self.d_Tree)

        # RESULTS WHERE SAMPLES != LAMBDA_EMULATE