fn learn(&mut self, new_vector: [f64; 2], dt: f64) {
        use vecmath::vec2_add as add;
        use vecmath::vec2_scale as scale;

        let eps = [
            0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error(),
            0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error()
        ];

        let error_middle = self.error(new_vector, dt);
        let pred = self.get_prediction();
        self.set_prediction(add(pred, eps));
        let error_up = self.error(new_vector, dt);
        let pred = self.get_prediction();
        self.set_prediction(add(pred, scale(eps, -2.0)));
        let error_down = self.error(new_vector, dt);
        if error_middle < error_up && error_middle < error_down {
            // Change back.
            let pred = self.get_prediction();
            self.set_prediction(add(pred, eps));
        } else if error_up < error_down {
            // Go up.
            let pred = self.get_prediction();
            self.set_prediction(add(pred, scale(eps, 2.0)));
        }

        // Clamp prediction.
        let pred = self.get_prediction();
        self.set_prediction([
            pred[0].min(10.0).max(-10.0),
            pred[1].min(10.0).max(-10.0),
        ]);

        let eps = 0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error();

        let error_middle = self.error(new_vector, dt);
        let err = self.get_error();
        self.set_error(err + eps);
        let error_up = self.error(new_vector, dt);
        let err = self.get_error();
        self.set_error(err - 2.0 * eps);
        let error_down = self.error(new_vector, dt);
        if error_middle < error_up && error_middle < error_down {
            let err = self.get_error();
            self.set_error(err + eps);
        }  else if error_up < error_down {
            let err = self.get_error();
            self.set_error(err + 2.0 * eps);
        }

        // Clamp the error.
        let err = self.get_error();
        self.set_error(err.min(20.0).max(0.0));

        self.set_old_vector(new_vector);
    }
/// Learns when moving to a new distance.
/// The control value might have changed in the mean time.
Learns when moving to a new distance.
The control value might have changed in the mean time.
Learns when moving to a new distance . The control value might have changed in the mean time .
fn learn(&mut self, new_vector: [f64; 2], dt: f64) {
        use vecmath::vec2_add as add;
        use vecmath::vec2_scale as scale;
        let eps = [
            0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error(),
            0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error()
        ];
        let error_middle = self.error(new_vector, dt);
        let pred = self.get_prediction();
        self.set_prediction(add(pred, eps));
        let error_up = self.error(new_vector, dt);
        let pred = self.get_prediction();
        self.set_prediction(add(pred, scale(eps, -2.0)));
        let error_down = self.error(new_vector, dt);
        if error_middle < error_up && error_middle < error_down {
            // Change back.
            let pred = self.get_prediction();
            self.set_prediction(add(pred, eps));
        } else if error_up < error_down {
            // Go up.
            let pred = self.get_prediction();
            self.set_prediction(add(pred, scale(eps, 2.0)));
        }
        // Clamp prediction.
        let pred = self.get_prediction();
        self.set_prediction([
            pred[0].min(10.0).max(-10.0),
            pred[1].min(10.0).max(-10.0),
        ]);
        let eps = 0.0000000000001 + rand::random::<f64>() * self.get_tune() * self.get_error();
        let error_middle = self.error(new_vector, dt);
        let err = self.get_error();
        self.set_error(err + eps);
        let error_up = self.error(new_vector, dt);
        let err = self.get_error();
        self.set_error(err - 2.0 * eps);
        let error_down = self.error(new_vector, dt);
        if error_middle < error_up && error_middle < error_down {
            let err = self.get_error();
            self.set_error(err + eps);
        }  else if error_up < error_down {
            let err = self.get_error();
            self.set_error(err + 2.0 * eps);
        }
        // Clamp the error.
        let err = self.get_error();
        self.set_error(err.min(20.0).max(0.0));
        self.set_old_vector(new_vector);
    }
fn learn ( & mut self , new_vector : [ f64 ; 2 ] , dt : f64 ) { use vecmath :: vec2_add as add ; use vecmath :: vec2_scale as scale ; let eps = [ 0.0000000000001 + rand :: random :: < f64 > ( ) * self . get_tune ( ) * self . get_error ( ) , 0.0000000000001 + rand :: random :: < f64 > ( ) * self . get_tune ( ) * self . get_error ( ) ] ; let error_middle = self . error ( new_vector , dt ) ; let pred = self . get_prediction ( ) ; self . set_prediction ( add ( pred , eps ) ) ; let error_up = self . error ( new_vector , dt ) ; let pred = self . get_prediction ( ) ; self . set_prediction ( add ( pred , scale ( eps , - 2.0 ) ) ) ; let error_down = self . error ( new_vector , dt ) ; if error_middle < error_up && error_middle < error_down { // Change back. let pred = self . get_prediction ( ) ; self . set_prediction ( add ( pred , eps ) ) ; } else if error_up < error_down { // Go up. let pred = self . get_prediction ( ) ; self . set_prediction ( add ( pred , scale ( eps , 2.0 ) ) ) ; } // Clamp prediction. let pred = self . get_prediction ( ) ; self . set_prediction ( [ pred [ 0 ] . min ( 10.0 ) . max ( - 10.0 ) , pred [ 1 ] . min ( 10.0 ) . max ( - 10.0 ) , ] ) ; let eps = 0.0000000000001 + rand :: random :: < f64 > ( ) * self . get_tune ( ) * self . get_error ( ) ; let error_middle = self . error ( new_vector , dt ) ; let err = self . get_error ( ) ; self . set_error ( err + eps ) ; let error_up = self . error ( new_vector , dt ) ; let err = self . get_error ( ) ; self . set_error ( err - 2.0 * eps ) ; let error_down = self . error ( new_vector , dt ) ; if error_middle < error_up && error_middle < error_down { let err = self . get_error ( ) ; self . set_error ( err + eps ) ; } else if error_up < error_down { let err = self . get_error ( ) ; self . set_error ( err + 2.0 * eps ) ; } // Clamp the error. let err = self . get_error ( ) ; self . set_error ( err . min ( 20.0 ) . max ( 0.0 ) ) ; self . set_old_vector ( new_vector ) ; }
Learns when moving to a new distance.
Learns when moving to a new distance .
&mut self
new_vector
[f64; 2]
dt
f64
&mut self
new_vector
[f64; 2]
dt
f64