Ejemplo n.º 1
0
    def do_spin(self, spin_angle):
        timer = 0
        final_time = math.fabs(spin_angle) / self.spin_speed
        self.twist_cmd.angular.z = utils.sgn(spin_angle) * self.spin_speed

        while timer < final_time:
            self.twist_commander.publish(self.twist_cmd)
            timer += self.sample_dt
            self.loop_timer.sleep()

        self.do_halt()
Ejemplo n.º 2
0
def load_patterns(n_patterns: Optional[int] = None) -> np.ndarray:
    """
    Returns training images from the mnist dataset in hopfield-network form.
    More specifically, 8-bit images from (0, 255) are converted to
    floating point images having values in {-1, 1}.
    """
    mnist = load_mnist()
    out = mnist["images"][:n_patterns]
    out = 2 * (out.astype(np.float32) / 255.0) - 1
    out = sgn(out)
    return out
Ejemplo n.º 3
0
 def learn_aen(self, x, ir):
     b_new = self.B + self.beta * ir * self.x_prev
     c_new = self.C + self.beta * ir * self.y_prev
     a_new = np.zeros_like(self.A)
     for i in range(self.h_aen):
         for j in range(self.input_len + 1):
             a_new[j,
                   i] = self.A[j, i] + self.beta_h * ir * self.y_prev[i] * (
                       1 - self.y_prev[i]) * sgn(self.C[i]) * self.x_prev[j]
     self.A = a_new
     self.B = b_new
     self.C = c_new
Ejemplo n.º 4
0
    def do_move(self, distance):
        timer = 0
        final_time = math.fabs(distance) / self.move_speed
        self.twist_cmd.angular.z = 0
        self.twist_cmd.linear.x = utils.sgn(distance) * self.move_speed

        while timer < final_time:
            self.twist_commander.publish(self.twist_cmd)
            timer += self.sample_dt
            self.loop_timer.sleep()

        self.do_halt()
Ejemplo n.º 5
0
 def learn_asn(self, x, ir, s):
     e_new = self.E + self.rho * ir * s * self.x_prev
     f_new = self.F + self.rho * ir * s * self.z_prev
     d_new = np.zeros_like(self.D)
     for i in range(self.h_asn):
         for j in range(self.input_len + 1):
             d_new[j,
                   i] = self.D[j, i] + self.rho_h * ir * self.z_prev[i] * (
                       1 - self.z_prev[i]) * sgn(
                           self.F[i]) * s * self.x_prev[j]
     self.D = d_new
     self.E = e_new
     self.F = f_new
Ejemplo n.º 6
0
    def derivative(self, y):  # computed yd
        g = 9.81    # gravity constant

        # Compute thetadd by splitting the computation of the numerator and denominator for clarity
        temp_num = g * sin(y[2]) + cos(y[2]) * (
                -self.f - self.m * self.l * y[3] * y[3] * sin(y[2]) + self.mu_c * sgn(y[1])) / (
                           self.mu_c + self.m) - self.mu_p * y[3] / (self.m * self.l)
        temp_denom = self.l * (4 / 3 - (self.m * cos(y[2]) ** 2) / (self.mu_c + self.m))
        thetadd = temp_num / temp_denom

        # Compute xdd by splitting the computation of the numerator and denominator for clarity
        temp_num = self.f + self.m * self.l * (y[3] ** 2 * sin(y[2]) - thetadd * cos(y[2])) - self.mu_c * sgn(y[1])
        temp_denom = self.mu_c + self.m
        xdd = temp_num / temp_denom

        return np.array([y[1], xdd, y[3], thetadd])
Ejemplo n.º 7
0
    def update(self) -> None:

        # Compute synaptic input.
        self._I_syn = np.dot(self._weights, self._state)
        self._state = sgn(self._bias + self._I_syn)
Ejemplo n.º 8
0
def k_func_cart_pole(v, v_prev, p):
    return 1 - p if sgn(v) != sgn(v_prev) else -p
Ejemplo n.º 9
0
 def _choose_determinant_action(self, meadow, directions, all_bees):
     if self.pollen_gathered >= self.max_capacity:
         return (sgn(self.hive_position[0] - self.position[0]), sgn(self.hive_position[1] - self.position[1]))
     else:
         return self._neural_move(meadow, directions, all_bees)