def __call__(self, rotation): """ Calculate probability of robot being in given position Parameters ---------- rotation : float Angle at which we see other robot. Returns ------- float Probability in given rotation_angle """ d = math.pi - self.mean p1 = gauss_distribution(rotation, self.mean, self.stdev) p2 = gauss_distribution(rotation, -math.pi - d, self.stdev) return max(p1, p2)
def __call__(self, angle): """ Calculate probability of robot being in given position Parameters ---------- angle : float Angle at which we see other robot. Returns ------- float Probability in given rotation_angle """ return gauss_distribution(angle, self.mu, self.sigma)
def rotate(self, rotation_angle): """ Shift function accordingly to input angle and calculate probability Parameters ---------- rotation_angle : float Angle to shift function by. Returns ------- float Probability after rotation. """ self.mu = (self.mu + rotation_angle) % 2 * math.pi self.sigma = self.coef * self.sigma return gauss_distribution(rotation_angle, self.mu, self.sigma)
def shift(self, rotation): """ Shift function accordingly to input angle and calculate probability Parameters ---------- rotation : float Angle to shift function by. Returns ------- float Probability after rotation. """ mean = (self.mean + rotation) % (2 * math.pi) - math.pi if self.mean > math.pi: self.mean = mean - 2 * math.pi else: self.mean = mean self.stdev = self.coef * self.stdev return gauss_distribution(rotation, self.mean, self.stdev)
def test_max_value_location(self, mu, stdev): xs = np.linspace(mu - 3 * stdev, mu + 3 * stdev, 250) ys = [gauss_distribution(x, mu, stdev) for x in xs] self.assertAlmostEqual(ys.index(max(ys)), len(ys) // 2, delta=3)
def _gaussian_normalized(x, mu, sigma): k = 1 / gauss_distribution(mu, mu, sigma) return k * gauss_distribution(x, mu, sigma)