def done(self, smc): res = super().done(smc) if res: assert np.allclose(self.pf_debug_access.logLt, self.logging.compact_particle_history.logLT) # noinspection PyTypeChecker self.logging.resampling_mode.append(None) self.logging.inner_ESS_ratio.append(ut.ESS_ratio(smc.wgts)) return res
def M(self, t: int, xp: np.ndarray, w: rs.Weights) -> typing.Tuple[np.ndarray, rs.Weights]: resampling_needed = ut.ESS_ratio(w) < self.ESSrmin self.logging.punctual_logging[ t] = GenericParticleFilterPunctualLogging() self.logging.punctual_logging[t].ESS_ratio = ut.ESS_ratio(w) self.logging.punctual_logging[t].ESS = w.ESS self.logging.punctual_logging[t].resampled = resampling_needed if resampling_needed: ancestors = rs.resampling(self.resampling_mode, w.W) xp = xp[ancestors] w = rs.Weights(lw=np.zeros(len(xp))) self.logging.compact_particle_history.add(lw=w.lw, ancestor=ancestors, last_particles=xp) x = self.fk_model.M(t, xp) return x, w
def done(self, smc: 'SMCNew') -> bool: res = smc.t > self.fk_model.T if res: assert np.allclose(smc.logLt, self.logging.compact_particle_history.logLT) self.logging.punctual_logging[ smc.t] = GenericParticleFilterPunctualLogging() self.logging.punctual_logging[smc.t].ESS_ratio = ut.ESS_ratio( smc.wgts) self.logging.punctual_logging[smc.t].ESS = smc.wgts.ESS return res
def done(self, smc): res = super().done(smc) if res: assert np.allclose(smc.logLt, self.logging.weight_cumulator.logLT) assert np.allclose(smc.logLt, sum([hist.logLT for hist in self.histories_between_two_outer_resampling])) self.logging.inner_ESS_ratio.append(self._inner_ess_ratio(smc.wgts)) self.logging.outer_ESS_ratio.append(ut.ESS_ratio(MultipleViewWeights(flattened_lw=smc.wgts.lw, M=self.M_resample, M1=self.M1).outer_weights)) self.logging.resampling_mode.append(-1) self.logging.chain_length.append(0) self.logging.thinning.append(0) self.logging.done = True return res
def need_rejuvenate(self, t, xp, w: rs.Weights) -> bool: inner_ess_ratio = self._inner_ess_ratio(w) self.logging.inner_ESS_ratio.append(inner_ess_ratio) self.logging.outer_ESS_ratio.append(ut.ESS_ratio(MultipleViewWeights(flattened_lw=w.lw, M=self.M_resample, M1=self.M1).outer_weights)) res = inner_ess_ratio < self.ESSrmin_inner if not res: self.logging.resampling_mode.append(0) self.logging.weight_cumulator.update_M(new_weights=w, normalize=False) self.logging.chain_length.append(0) self.logging.thinning.append(0) self.last_resampling_mode = 0 return res
def outer_resampling_needed(self) -> bool: outer_ess_ratio = ut.ESS_ratio(self.w.outer_weights) return outer_ess_ratio < self.ESSrmin_outer
def need_rejuvenate(self, t:int, xp, w: rs.Weights) -> bool: self.logging.inner_ESS_ratio.append(ut.ESS_ratio(w)) res = w.ESS < len(xp) * self.ESSrmin self.logging.resampling_mode.append(res) return res
def ESS_ratio(self, t: int) -> typing.Union[float, None]: if t >= len(self._logG): return None return ut.ESS_ratio(rs.Weights(lw=self._logG[t]))