def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. measurement = [] predicted_measurement = [] # zt_component => measurement to a specific detected cylinder in the scan from particle p. for zt_component, landmark in assignment: measurement.append(zt_component) predicted_measurement.append(ParticleFilter.h( p, landmark, self.scanner_displacement)) weights.append(self.probability_of_measurement( measurement, predicted_measurement)) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: #print p # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] #print cylinders assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) #print assignment # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. part_wt = 1 for i in assignment: measurement, landmark = i predicted_measurement = self.h(p, landmark, self.scanner_displacement) part_wt *= self.probability_of_measurement( measurement, predicted_measurement) #print p1 weights.append(part_wt) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, return list of weights.""" # --->>> Put the code of a previous solution here. # pass # Remove. weights = [] for p in self.particles: # Loop in particles. # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders( cylinders, p, self.scanner_displacement, landmarks) # Assign once for each particle. # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. # weights.append(1.0) # Replace this. prob = 1.0 for e in assignment: true_measurement, landmark = e predicted_measurement = self.h(p, landmark, scanner_displacement) prob *= self.probability_of_measurement( true_measurement, predicted_measurement) #if prob == 1.0: # prob = 0.0 weights.append(prob) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. measurement = [] predicted_measurement = [] # zt_component => measurement to a specific detected cylinder in the scan from particle p. for zt_component, landmark in assignment: measurement.append(zt_component) predicted_measurement.append( ParticleFilter.h(p, landmark, self.scanner_displacement)) weights.append( self.probability_of_measurement(measurement, predicted_measurement)) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weights.append(1.0) # Replace this. return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weight = 1 for assign in assignment: predicted_measurement = self.h(p, assign[1], self.scanner_displacement) weight *= self.probability_of_measurement(assign[0], predicted_measurement) weights.append(weight) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, return list of weights.""" weights = [] for p in self.particles: weight = 1 # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) for a in assignment: d_,alpha_ = self.h(p,a[1],self.scanner_displacement) weight = weight*self.probability_of_measurement((d_,alpha_),a[0]) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weights.append(weight) # Replace this. return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) wt = 1.0 for z, landmark in assignment: # Get measurement for given landmark z_pred = self.h(p, landmark, self.scanner_displacement) wt *= self.probability_of_measurement(z, z_pred) weights.append(wt) total = sum(weights) return [w / total for w in weights]
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) w = 1. for pair in assignment: predicted_measurement = self.h(p,pair[1],self.scanner_displacement) w = w * self.probability_of_measurement(pair[0],predicted_measurement) weights.append(w) # Replace this. normalizing_factor = 1/sum(weights) weights = [normalizing_factor * w for w in weights] return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) prob = 1. for tupl in assignment: meas_prime = self.h(p, tupl[1], self.scanner_displacement) prob *= self.probability_of_measurement(tupl[0], meas_prime) weights.append(prob) weights = np.array(weights) total = sum(weights) return weights/total
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] Final_prob = 1 assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) for i in range(len((assignment))): predicted_landmarks = self.h(p, assignment[i][1], self.scanner_displacement) Final_prob *= self.probability_of_measurement( assignment[i][0], predicted_landmarks) weights.append(Final_prob) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. w_p = 1 for z, landmark in assignment: z_pred = self.h(p, landmark, self.scanner_displacement) w_p *= self.probability_of_measurement(z, z_pred) # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weights.append(w_p) # Replace this. totalsum = sum(weights) return [w / totalsum for w in weights]
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] Final_prob = 1 assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) for i in range(len((assignment))): predicted_landmarks = self.h(p, assignment[i][1], self.scanner_displacement) Final_prob *= self.probability_of_measurement( assignment[i][0], predicted_landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weights.append(Final_prob) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. total_weight = 1 for pairing in assignment: expected_measurement = [0, 0] expected_measurement[0] = ( (p[0]-pairing[1][0])**2 + (p[1]-pairing[1][1])**2 )**0.5 expected_measurement[1] = atan2( (pairing[1][1] - p[1]), (pairing[1][0] - p[0]) ) - p[2] total_weight *= self.probability_of_measurement(pairing[0], expected_measurement) weights.append(total_weight) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, returns list of weights.""" weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. P= 1 for i in xrange(len(assignment)): p_measurement = self.h(p,assignment[i][1],self.scanner_displacement) po = self.probability_of_measurement(assignment[i][0],p_measurement) P *= po weights.append(P) return weights
def compute_weights(self, cylinders, landmarks): """Computes one weight for each particle, return list of weights.""" # --->>> Put the code of a previous solution here. weights = [] for p in self.particles: # Get list of tuples: # [ ((range_0, bearing_0), (landmark_x, landmark_y)), ... ] assignment = assign_cylinders(cylinders, p, self.scanner_displacement, landmarks) # --->>> Insert code to compute weight for particle p here. # This will require a loop over all (measurement, landmark) # in assignment. Append weight to the list of weights. weight = 1.0 for pair in assignment: measurement, landmark = pair predicted_measurement = self.h(p, landmark, self.scanner_displacement) weight *= self.probability_of_measurement( measurement, predicted_measurement) weights.append(weight) # Replace this. return weights