コード例 #1
0
 void OnGUI()
 {
     if (GUI.Button(new Rect(10, 10, 100, 50), "step"))
     {
         errorsum = 0;
         foreach (Vector3 v in data)
         {
             p.Input = new float[] { v.x, v.y };
             p.Feed();
             float output = p.Output[0];
             p.Learn(new float[] { v.z });
             this.output = output;
             print(output);
         }
     }
 }
コード例 #2
0
ファイル: Think.cs プロジェクト: VicYu1983/spaceWar
        void Update()
        {
            if (addCount % 10 == 0)
            {
                float[] state2 = TeacherCar.State;
                float[] action = TeacherCar.Action;
                float[] s      = new float[state2.Length];
                for (var i = 0; i < state2.Length; ++i)
                {
                    s [i] = state2 [i];
                }
                float[] a = new float[action.Length];
                for (var i = 0; i < action.Length; ++i)
                {
                    a [i] = action [i];
                }
                statehistory.Add(s);
                actionhistory.Add(a);

                if (statehistory.Count > 100)
                {
                    statehistory.RemoveAt(0);
                    actionhistory.RemoveAt(0);
                }

                historyCount = statehistory.Count;
            }
            ++addCount;

            if (learn)
            {
                for (var i = 0; i < statehistory.Count; ++i)
                {
                    var s = statehistory [i];
                    var a = actionhistory [i];
                    bpn.Input = s;
                    bpn.Feed();
                    bpn.Learn(a);
                }
            }

            float[] state = MyCar.State;
            bpn.Input = state;
            bpn.Feed();
            float[] currAction = bpn.Output;
            MyCar.PerformAction(currAction, Time.deltaTime);
        }