void Start() { var layer = new PerceptronLayer(2); layer.Add(new Perceptron(2)); layer.Add(new Perceptron(2)); //layer.Add (new Perceptron (2)); var layer2 = new PerceptronLayer(2); layer2.Add(new Perceptron(2)); /* * layer2.Add (new Perceptron (3)); * * var layer3 = new PerceptronLayer (2); * layer3.Add (new Perceptron (2)); */ // 總共3神經元就能訓練xor p.Add(layer); p.Add(layer2); // p.Add (layer3); for (var i = 0; i < pixels.GetLength(0); ++i) { for (var j = 0; j < pixels.GetLength(1); ++j) { pixels [i, j] = Instantiate(pixel, new Vector3(i, j, 0), new Quaternion()) as GameObject; } } }
void Start() { float[] state = TeacherCar.State; float[] action = TeacherCar.Action; bpn = new MultiLayerPerceptron(state.Length); var layer = new PerceptronLayer(state.Length); layer.Add(new Perceptron(state.Length)); layer.Add(new Perceptron(state.Length)); layer.Add(new Perceptron(state.Length)); var layer2 = new PerceptronLayer(3); layer2.Add(new Perceptron(3)); layer2.Add(new Perceptron(3)); var layer3 = new PerceptronLayer(2); for (var i = 0; i < action.Length; ++i) { layer3.Add(new Perceptron(2)); } bpn.Add(layer); bpn.Add(layer2); bpn.Add(layer3); /* * for (var i = 0; i < 1000; ++i) { * bpn.Input = new float[]{ 0, 0, 0 }; * bpn.Feed (); * bpn.Learn (new float[]{ 1, 1 }); * * bpn.Input = new float[]{ 1, 1, 1 }; * bpn.Feed (); * bpn.Learn (new float[]{ 0, 0 }); * * bpn.Input = new float[]{ 1, 0, 1 }; * bpn.Feed (); * bpn.Learn (new float[]{ 0.5f, 0.5f }); * } * * bpn.Input = new float[]{ 0, 0, 0 }; * bpn.Feed (); * var currAction = bpn.Output; * print (currAction[0]+","+currAction[1]); * * bpn.Input = new float[]{ 1, 1, 1 }; * bpn.Feed (); * currAction = bpn.Output; * print (currAction[0]+","+currAction[1]); * * bpn.Input = new float[]{ 1, 0, 1 }; * bpn.Feed (); * currAction = bpn.Output; * print (currAction[0]+","+currAction[1]); */ }