/*******************************************************************************
 * DIANNE  - Framework for distributed artificial neural networks
 * Copyright (C) 2015  iMinds - IBCN - UGent
 *
 * This file is part of DIANNE.
 *
 * DIANNE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     Tim Verbelen, Steven Bohez
 *******************************************************************************/
package be.iminds.iot.dianne.rl.agent.strategy;

import java.util.Map;
import java.util.Random;

import be.iminds.iot.dianne.api.nn.NeuralNetwork;
import be.iminds.iot.dianne.api.rl.agent.ActionStrategy;
import be.iminds.iot.dianne.api.rl.agent.AgentProgress;
import be.iminds.iot.dianne.api.rl.environment.Environment;
import be.iminds.iot.dianne.tensor.Tensor;

/**
 * Select a random discrete action.
 * 
 * @author tverbele
 *
 */
public class RandomActionStrategy implements ActionStrategy {

	private Tensor action;
	private Random r = new Random(System.currentTimeMillis());
	
	@Override
	public void setup(Map<String, String> config, Environment env, NeuralNetwork... nns) throws Exception {
		 action = new Tensor(env.actionDims());
	}

	@Override
	public AgentProgress processIteration(long i, Tensor state) throws Exception {
		action.fill(0f);
		
		int index = r.nextInt(action.size());
		action.set(1.0f, index);
		
		return new AgentProgress(i, action);
	}
	
}

@@ -1094,33 +1094,8 @@
 Map;
-%0Aimport java.util.Random;
 %0A%0Aim
@@ -1315,16 +1315,62 @@
 onment;%0A
+import be.iminds.iot.dianne.tensor.ModuleOps;%0A
 import b
@@ -1567,68 +1567,8 @@
 on;%0A
-%09private Random r = new Random(System.currentTimeMillis());%0A
 %09%0A%09@
@@ -1831,85 +1831,48 @@
 ion.
-fill(0f);%0A%09%09%0A%09%09int index = r.nextInt(action.size());%0A%09%09action.set(1.0f, index
+randn();%0A%09%09ModuleOps.tanh(action, action
 );%0A%09

generate random action values between -1..1 in RandomActionStrategy