/**
* EGreedyNArmedBanditSim.java
*
* Usage:
* java EGreedyNArmedBanditSim > greedy.csv
* java TrialAverager < greedy.csv > greedyAvg.csv
*
* Created: Thu Jan 16 16:06:48 2003
*
* @author Todd Neller
* @version 1.0
*/
public class EGreedyNArmedBanditSim extends Simulation {
static final int N = 10; // bandit arms
static final int NUM_TRIALS = 3; // number of trials
static final int MAX_STEPS = 3; // max steps per trial
static final int REPORT_FREQ = 1; // trials between reports
/**
* Creates a new EGreedyNArmedBanditSim
instance. As a
* subclass instance of Simulation
, it manages the
* interaction between the EGreedyNArmedBanditAgent & the
* NArmedBanditEnvironment. The Agent and Environment instances
* corresponding to this Simulation instance must be constructed
* prior to constructing a new Simulation instance.
*
* @param agt an Agent
instance
* @param env an Environment
instance */
public EGreedyNArmedBanditSim ( Agent agt, Environment env ){
super(agt, env);
}
/**
* A user-defined method that is called regularly by the steps and
* trials methods of the Simulation instance. User-defined
* specialized methods might accumulate rewards or other data and
* update displays. This is the preferred way to gain access to
* the simulation's behavior.
*
* @param state a State
value. Should not be
* mutated within this method.
* @param act an Action
value. Should not be
* mutated within this method.
* @param nextState a State
value. Should not be
* mutated within this method.
* @param reward a double
value */
public void collectData( State state, Action act,
State nextState, double reward ) {
}
public static void main(String[] args){
// create agent
EGreedyNArmedBanditAgent agt = new EGreedyNArmedBanditAgent(N, 0);
// Uncomment to show average reward information:
//agt.showAvgRewards = true;
// create environment
NArmedBanditEnvironment env = new NArmedBanditEnvironment(N);
/* ensure that the n-armed bandits will always have the same
initial state. */
// Uncomment for common trial problem:
//env.setSeed(2);
// create, initialize and run simulation
Simulation sim = new EGreedyNArmedBanditSim(agt, env);
sim.init(null);
//System.out.println(env);
sim.trials(NUM_TRIALS, MAX_STEPS, REPORT_FREQ);
//System.out.println(agt);
//System.out.println(env);
}
} // EGreedyNArmedBanditSim