Optimize the number of points for t. Provided the number of points to sample in t based on t-1, return values number of sample points.
Type
Details
state
DataFrame
a dataframe with the state of the administrative boundaries
Exported source
class Optimizer:def__init__(self, state:pd.DataFrame # a dataframe with the state of the administrative boundaries ):"Optimize the number of points for t. Provided the number of points to sample in t based on t-1, return values number of sample points."self.state = stateself.matrix = state.to_numpy()return
Determines the rank of the administrative polygon based on the provided states.
Exported source
@patchdef get_rank(self:Optimizer, is_benefit_x:list, w_vector:list, n_method:str=None, c_method:str=None, w_method:str=None, s_method:str=None ):"Determines the rank of the administrative polygon based on the provided states."# normailize the matrix z_matrix, is_benefit_z = normalize(self.matrix, is_benefit_x, n_method)# replace nan values with 0 if cost and & 1 if benefitfor i, is_benefit inenumerate(is_benefit_z):if is_benefit: z_matrix[:, i][np.isnan(z_matrix[:, i])] =1else: z_matrix[:, i][np.isnan(z_matrix[:, i])] =0if w_vector isNone:# Weigh each criterion using the selected methods w_vector = weigh(z_matrix, w_method, c_method)else:pass s_vector, desc_order = score(z_matrix, is_benefit_z, w_vector, s_method) state =self.state.copy() state['value'] = s_vector df = state[['value']]# Get the indices of the sorted scoresif desc_order: df_sorted = df.sort_values(by='value', ascending=False)else: df_sorted = df.sort_values(by='value', ascending=True) df_sorted['rank'] =range(1, len(df_sorted) +1) df_rank = df_sorted[['rank']]return df_rank