Exemple #1
0
    def monteCarloIndicator(self, estim_param, estimate, space_dict, assg_map):
        '''
        Calculates indicators from the MC runs
        '''
        start_index = estim_param.tint_eval_start * len(space_dict)
        end_index = (estim_param.tint_eval_start +
                     len(estim_param.tint_eval_dict)) * len(space_dict)

        if estim_param.MC_iterations > 1:
            IndDist = np.zeros((len(estim_param.tint_dict) * len(space_dict),
                                estim_param.MC_iterations))
            for iteration in range(estim_param.MC_iterations):
                IndDist[:, iteration] = np.asarray(
                    DNL.apply_assg(assg_map, estimate.demand_distr[:,
                                                                   iteration]))

            ind_mean = np.mean(IndDist[start_index:end_index, :], axis=1)
            ind_std = np.std(IndDist[start_index:end_index, :], axis=1)
            ind_dist = IndDist[start_index:end_index, :]

        else:
            ind_mean = np.asarray(
                DNL.apply_assg(np.asarray(assg_map),
                               estimate.demand_distr))[start_index:end_index]
            ind_std = None
            ind_dist = ind_mean

        return ind_mean, ind_std, ind_dist
Exemple #2
0
    def __init__(self, estim_param, network):
        '''
        Constructor
        '''
        # create precomputed directory if it does not exist
        if not os.path.exists(estim_param.path_precomp):
            os.makedirs(estim_param.path_precomp)

        '''-----------------------------------------------------------------------------------------------------------------
                            Loads the link flow assignment matrix if is exists, otherwise calculates it
        -----------------------------------------------------------------------------------------------------------------'''
        if os.path.isfile(estim_param.path_precomputed_asg + "_linkFlowAssgn_data.csv") and estim_param.forceRecompAssgnment is False:
            print "Loading pre-computed flow assignment matrix",
            data = np.loadtxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_data.csv", delimiter=",")
            indices = np.loadtxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_indices.csv", dtype='int_', delimiter=",")
            indptr = np.loadtxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_indptr.csv", dtype='int_', delimiter=",")
            self.linkFlowAssgn = sps.csr_matrix((data, indices, indptr)).todense()
        else:
            print "Computing flow assignment matrix",
            self.linkFlowAssgn = np.asmatrix(DNL.compute_assg_mat(network, estim_param))
            linkFlowAssgn_csr = sps.csr_matrix(self.linkFlowAssgn)
            np.savetxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_data.csv", linkFlowAssgn_csr.data, delimiter=",")
            np.savetxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_indices.csv", linkFlowAssgn_csr.indices, fmt='%i', delimiter=",")
            np.savetxt(estim_param.path_precomputed_asg + "_linkFlowAssgn_indptr.csv", linkFlowAssgn_csr.indptr, fmt='%i', delimiter=",")
        
        self.linkFlowAssgn_prime = DNL.build_flow_assg_mat(self.linkFlowAssgn, network, estim_param, network.edges_ASE_dict)
        self.subRouteAssgn_prime = DNL.build_ODflow_assg_mat(self.linkFlowAssgn, network, estim_param, network.subroutes_VS_dict)
        self.accAssgn_prime = DNL.build_flow_assg_mat(self.linkFlowAssgn, network, estim_param, network.edges_TINF_dict)
        estim_param.print_incr_runtime()

        '''-----------------------------------------------------------------------------------------------------------------
                         Loads the occupation flow assignment matrix if is exists, otherwise calculates it
        -----------------------------------------------------------------------------------------------------------------'''
        if os.path.isfile(estim_param.path_precomputed_asg + "_acc_data.csv") and estim_param.forceRecompAssgnment is False:
            print "Loading pre-computed accumulation assignment matrix",
            data = np.loadtxt(estim_param.path_precomputed_asg + "_acc_data.csv", delimiter=",")
            indices = np.loadtxt(estim_param.path_precomputed_asg + "_acc_indices.csv", dtype='int_', delimiter=",")
            indptr = np.loadtxt(estim_param.path_precomputed_asg + "_acc_indptr.csv", dtype='int_', delimiter=",")
            self.acc = sps.csr_matrix((data, indices, indptr)).todense()
            #print "Occupation assignment matrix accumulation loaded."
        else:
            print "Computing accumulation assignment matrix",
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")  # Prevent some annoying numerical warnings from appearing
                self.acc = np.asmatrix(DNL.compute_assg_mat_accumulation(network, estim_param))
            acc_csr = sps.csr_matrix(self.acc)
            np.savetxt(estim_param.path_precomputed_asg + "_acc_data.csv", acc_csr.data, delimiter=",")
            np.savetxt(estim_param.path_precomputed_asg + "_acc_indices.csv", acc_csr.indices, fmt='%i', delimiter=",")
            np.savetxt(estim_param.path_precomputed_asg + "_acc_indptr.csv", acc_csr.indptr, fmt='%i', delimiter=",")
        estim_param.print_incr_runtime()
Exemple #3
0
    def monteCarloIndicator(self, estim_param, estimate, space_dict, assg_map):
        """
        Calculates indicators from the MC runs
        """
        start_index = estim_param.tint_eval_start * len(space_dict)
        end_index = (estim_param.tint_eval_start + len(estim_param.tint_eval_dict)) * len(space_dict)

        if estim_param.MC_iterations > 1:
            IndDist = np.zeros((len(estim_param.tint_dict) * len(space_dict), estim_param.MC_iterations))
            for iteration in range(estim_param.MC_iterations):
                IndDist[:, iteration] = np.asarray(DNL.apply_assg(assg_map, estimate.demand_distr[:, iteration]))

            ind_mean = np.mean(IndDist[start_index:end_index, :], axis=1)
            ind_std = np.std(IndDist[start_index:end_index, :], axis=1)
            ind_dist = IndDist[start_index:end_index, :]

        else:
            ind_mean = np.asarray(DNL.apply_assg(np.asarray(assg_map), estimate.demand_distr))[start_index:end_index]
            ind_std = None
            ind_dist = ind_mean

        return ind_mean, ind_std, ind_dist