Minimum of samples to be collected per area of interest
policy
str
Weighted
policy used form mapping ranks to number of samples
Returns
ndarray
Number of samples per area of interest to be collected in the same order as ranks
Exported source
def rank_to_sample(ranks:np.ndarray, # Ranks sorted by `loc_id`s budget:int, # Total data collection budget availablemin:int=0, # Minimum of samples to be collected per area of interest policy:str="Weighted"# policy used form mapping ranks to number of samples ) -> np.ndarray: # Number of samples per area of interest to be collected in the same order as ranks"Map ranks to number of samples to be collected"if policy =="Weighted": weights =1/ranks normalized_weights = np.array(weights) / np.sum(weights) allocation = np.round(budget * normalized_weights).astype(int)return np.where(allocation <min, min, allocation)elif policy =="quantiles":# 4. Sampling policy (based on 4 quantiles of rank) n_quantile =len(ranks)/4 sampling_policy = [int(budget*0.5/n_quantile), int(budget*0.3/n_quantile), int(budget*0.20/n_quantile), 0]# Calculate quantiles thresholds quantiles_thresholds = np.quantile(ranks, [0.25, 0.5, 0.75, 1.0])# Assign each rank to a quantile quantile_indices = np.digitize(ranks, quantiles_thresholds, right=True)# Map each quantile to its corresponding value in sampling_policy samples_per_quantile = np.array([sampling_policy[i] for i in quantile_indices])# Ensure minimum samples collected per area samples_per_quantile = np.where(samples_per_quantile <min, min, samples_per_quantile)return samples_per_quantileelse:raiseValueError(f'Policy {policy} not implemented.')