コード例 #1
0
 //BRAIN HELPERS
 void simple_train()
 {
     //Nothing infront -> Don't do much.
     NeuralNet.Matrix zeroin = new NeuralNet.Matrix(1, Eye_script.ret_size(), false);
     NeuralNet.Matrix zerout = new NeuralNet.Matrix(1, 5, false);
     zerout[0, 0] = 0.5;
     for (int i = 0; i < 10; i++)
     {
         mind.Forward(zeroin);
         mind.Backward(zerout);
     }
 }
コード例 #2
0
    //this one is a prototype
    void brain()
    {
        NeuralNet.Matrix input = eye.gameObject.GetComponent <Eye_script> ().look(); //Dirty hack to get the input from the eye... isn't great..

        //NeuralNet.Matrix input2 = NeuralNet.Matrix.AddBias (NeuralNet.Matrix.AddBias (input));

        /*
         * NeuralNet.Matrix input2 = new NeuralNet.Matrix(1,input.Columns+4);
         * for (int i = 0; i < input.Columns; i++) { //Only 1 row.
         * input2.Elements [0,i] = input.Elements[0,i];
         * }*/
        //input2 [0,0] = 0;
        //input2 [0,1] = 1;
        NeuralNet.Matrix brainRet = mind.Forward(input);

        if (getLastBrainStr)
        {
            lastBrainStr = brainRet.ToString();
        }
        //Hardcoding ret to test:
        //ret[0,0] = input[0,0] / Mathf.PI + 0.5 ;

        //Abstract the values out of the NN.
        double rotate_value = ((brainRet[0, 0] - 0.5) * 180.0) / 10.0;
        double accel_value  = (brainRet[0, 1] - 0.5) * 1;


        //ROTATION//
        transform.rotation = Quaternion.AngleAxis((float)rotate_value, Vector3.up) * transform.rotation;

        //VELOCITY//
        body.velocity  = body.velocity * 0.9f; //Dampen vel
        body.velocity += ( float)accel_value * body.transform.forward;


        //Velocity = (brainoutput 1*45)*Velocity + accel

        //Rotates the velocity and applies the body/etc
        //body.velocity = Quaternion.AngleAxis((float)((ret[0,0]-0.5)*180.0/100), Vector3.up)*body.velocity + (body.transform.forward * (float)ret[0,1] * 0);   //The rotation is based off the result.
        //food -= (float)(ret[0,1]);  //Accel costs.

        //Rotate
        //  transform.rotation = Quaternion.AngleAxis((float)((ret[0,1]-ret[0,2])*10),  Vector3.up)*transform.rotation ;

        //transform.rotation = Quaternion.AngleAxis((float)((input[0,0])),  Vector3.up)*transform.rotation ; //TRY IT RAW!

        //transform.rotation = new Quaternion (((float)(ret [0, 1]+ret [0, 2]-ret [0, 3]-ret [0, 4])*2)  , Vector3.up[0],Vector3.up[1],Vector3.up[2]);
        //transform.rotation = new Quaternion (((float)(ret [0, 1]-ret [0, 2]))  , Vector3.up[0],Vector3.up[1],Vector3.up[2]);

        //Move
//    if(ret[0,0] > 0)
//          body.velocity = (float)(ret[0,0]-0.3)*5f*body.transform.forward;


        //if (body.velocity.magnitude < 0.1) {
        //food+=2;
        //  train_bad();
        //}

        //food -= (float)(ret[0,0]);

        /*
         * if (Random.Range(0, 100) < 10)
         * {
         *  body.velocity =  Quaternion.AngleAxis(Random.Range(-45,45), Vector3.up)*body.velocity;
         * // body.velocity = new Vector3(0,0,10);
         * }
         * //Face velocity dir.
         * if (body.velocity != new Vector3 (0, 0, 0)) {
         * transform.rotation = Quaternion.LookRotation (body.velocity);
         * }//*/
    }