def update( self, transitions: List[Transition], model_weights: np.ndarray, t: int = None, ): test_X = [trans.X for trans in transitions] test_w = [trans.w for trans in transitions] reference_nr_part = self.nr_particles target_cv = self.mean_cv cv_estimate = predict_population_size( reference_nr_part, target_cv, lambda nr_particles: calc_cv( nr_particles, model_weights, self.n_bootstrap, test_w, transitions, test_X, )[0], ) if not np.isnan(cv_estimate.n_estimated): self.nr_particles = max( min(int(cv_estimate.n_estimated), self.max_population_size), self.min_population_size, ) logger.info("Change nr particles {} -> {}".format( reference_nr_part, self.nr_particles))
def adapt_population_size(self, transitions: List[Transition], model_weights: np.ndarray): test_X = [trans.X for trans in transitions] test_w = [trans.w for trans in transitions] N_BOOTSTR = 5 reference_nr_part = self.nr_particles target_cv = self.mean_cv cv_estimate = predict_population_size( reference_nr_part, target_cv, lambda nr_particles: calc_cv( nr_particles, model_weights, N_BOOTSTR, test_w, transitions, test_X)[0]) if not np.isnan(cv_estimate.n_estimated): self.nr_particles = max( min(int(cv_estimate.n_estimated), self.max_population_size), self.min_population_size) adaptation_logger.info("Change nr particles {} -> {}".format( reference_nr_part, self.nr_particles))