Exemple #1
0
 def resample(self):
     if self.parameters.state_parameters["resample_threshold"] < 0:
         return
     # Effective number of particles
     eff_nparticles = 1/np.power(self.weights, 2).sum()
     resample_threshold = (
             eff_nparticles/self.parameters.state_parameters["nparticles"])
     # Check if we have particle depletion
     if (resample_threshold > 
                 self.parameters.state_parameters["resample_threshold"]):
         return
     # Otherwise we need to resample
     max_wt_index = self.weights.argmax()
     max_wt_state = self.states[max_wt_index].copy()
     max_wt_state[4:] = 0
     max_wt_map = self.maps[max_wt_index].copy()
     
     resample_index = misctools.get_resample_index(self.weights, 
                         self.parameters.state_parameters["nparticles"]-1)
     # self.states is a numpy array so the indexing operation forces a copy
     resampled_states = self.states[resample_index]
     resampled_states.resize((resampled_states.shape[0]+1, resampled_states.shape[1]))
     resampled_states[-1] = max_wt_state
     resampled_maps = [self.maps[i].copy() for i in resample_index]
     resampled_maps.append(max_wt_map)
     resampled_weights = (
       np.ones(self.parameters.state_parameters["nparticles"], dtype=float)*
       1/float(self.parameters.state_parameters["nparticles"]))
     
     self.weights = resampled_weights
     self.states = resampled_states
     self.maps = resampled_maps
Exemple #2
0
 def phdResample(self, FORCE_COPY=True):
     sum_weights = [_weights_.sum() for _weights_ in self._weights_]
     nparticles = np.array(sum_weights)*self.parameters.phd_parameters["nparticles"]
     for count in range(len(self._weights_)):
         resample_indices = get_resample_index(self._weights_[count], nparticles[count])
         self._weights_[count] = (1.0/nparticles[count])*np.ones(nparticles[count])
         if FORCE_COPY:
             self._states_[count] = copy.deepcopy([self._states_[count][ridx] for ridx in resample_indices])
         else:
             self._states_[count] = [self._states_[count][ridx] for ridx in resample_indices]
Exemple #3
0
 def resample(self):
     # Effective number of particles
     nparticles = self.vars.nparticles
     eff_nparticles = 1/np.power(self.vehicle.weights, 2).sum()
     resample_threshold = eff_nparticles/nparticles
     # Check if we have particle depletion
     if (resample_threshold > self.vars.resample_threshold):
         return
     # Otherwise we need to resample
     resample_index = misctools.get_resample_index(self.vehicle.weights)
     # self.states is a numpy array so the indexing operation forces a copy
     self.vehicle.weights = np.ones(nparticles, dtype=float)/nparticles
     self.vehicle.states = self.vehicle.states[resample_index]
     self.vehicle.covs = self.vehicle.covs[resample_index]
     self.vehicle.maps = [self.vehicle.maps[i].copy() 
         for i in resample_index]