override public void Init(NeuralNetwork p_network = null) { NeuralNetwork network = null; Optimizer optimizer = null; if (p_network == null) { network = new NeuralNetwork(); network.AddLayer("input", new InputLayer(GetParam(STATE_DIM)), BaseLayer.TYPE.INPUT); network.AddLayer("hidden0", new CoreLayer(SolverConfig.GetInstance().hidden_layer, ACTIVATION.RELU, BaseLayer.TYPE.HIDDEN), BaseLayer.TYPE.HIDDEN); network.AddLayer("output", new CoreLayer(GetParam(ACTION_DIM) + 1, ACTIVATION.TANH, BaseLayer.TYPE.OUTPUT), BaseLayer.TYPE.OUTPUT); // feed-forward connections network.AddConnection("input", "hidden0", Connection.INIT.GLOROT_UNIFORM); network.AddConnection("hidden0", "output", Connection.INIT.GLOROT_UNIFORM); } else { network = p_network; } optimizer = new ADAM(network); //optimizer.InitAsynchMode(true); //optimizer = new RMSProp(network); //optimizer = new BackProp(network, 1e-5f, 0.99f, true); //_actorCritic = new A3C(optimizer, network, 0.99f, SolverConfig.GetInstance().async_update); _actorCritic = new ActorCritic(optimizer, network, 0.99f); _actorCritic.SetAlpha(SolverConfig.GetInstance().learning_rate); }
static void AbsoluteMazeProblem() { //Declare random MyRandom.RandomPool.Declare("action",(int)DateTime.Now.Ticks); //環境 MazeEnvironment mazeEnv = new MazeEnvironment(); mazeEnv.Map = new MazeMap(new int[,]{ { 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 3 }, { 0, 0, 3, 0, 2 }, }) ; //エージェントを宣言 var mazeAgent = new QLearningAgent<MazeEnvironment,PositionState,MoveAction>(); //= new ActorCritic<MazeEnvironment,PositionState,MoveAction>(); //エージェントに環境をセット mazeAgent.Environment = mazeEnv; //環境にエージェントをセット mazeEnv.AddAgent(mazeAgent); mazeAgent.Id = 1; //エージェントを宣言 var mazeAgent2 //= new QLearningAgent<MazeEnvironment,PositionState,FourDirectionAction>(); = new ActorCritic<MazeEnvironment,PositionState,MoveAction>(); //エージェントに環境をセット mazeAgent2.Environment = mazeEnv; //環境にエージェントをセット mazeEnv.AddAgent(mazeAgent2); mazeAgent2.Id = 2; //初期状態をセット mazeAgent2.CurrentState = mazeEnv.StartState; //初期状態をセット mazeAgent.CurrentState = mazeEnv.StartState; //View のセット MazeView mazeView = new MazeView(); mazeView.Maze = mazeEnv; while(true) { mazeAgent.Act(); mazeAgent2.Act(); mazeView.show(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); mazeAgent.Show(); Console.WriteLine(); mazeAgent2.Show(); string command = Console.ReadLine(); //を、キーをおすたびにやる。 if (command.Equals("init")) { mazeAgent.Init(); mazeAgent2.Init(); } else if (command.Equals("q")) { mazeAgent.Show (); continue; } try //数字としてパースしてみて { //パースできたらその回数ステップ進める int num = int.Parse(command); foreach (int j in Enumerable.Range(0, num)) { mazeAgent.Act(); mazeAgent2.Act(); } } catch (Exception) { } } }