This source code shows the minimal set of steps needed to create an Agent and start a loop to update its Observation, reward, and action. Note that several function calls here are user-defined, like initEnvironment, computeContinuousInput0, computeReward, performAction2, and updateEnvironment.

// Define an AgentDescriptor.
verve::AgentDescriptor agentDesc;
agentDesc.addDiscreteSensor(4);  // 4 possible values.
agentDesc.addContinuousSensor();
agentDesc.addContinuousSensor();
agentDesc.setContinuousSensorResolution(10);
agentDesc.setNumOutputs(3); // 3 actions.
 
// Create the Agent and an Observation initialized 
// to fit this Agent.
verve::Agent agent(agentDesc);
verve::Observation obs;
obs.init(agent);
 
// Set the initial state of the world.
initEnvironment();
 
// Loop forever (or until some desired learning 
// performance is achieved).
while (1)
{
	verve::real dt = 0.1;
 
	// Update the Observation based on the current 
	// state of the world.  Each sensor is 
	// accessed via an index.
	obs.setDiscreteValue(0, computeDiscreteInput());
	obs.setContinuousValue(0, computeContinuousInput0());
	obs.setContinuousValue(1, computeContinuousInput1());
 
	verve::real reward = computeReward();
 
	// Update the Agent.
	unsigned int action = agent.update(reward, obs, dt);
 
	// Apply the chosen action to the environment.
	switch(action)
	{
		case 0:
			performAction0();
			break;
		case 1:
			performAction1();
			break;
		case 2:
			performAction2();
			break;
		default:
			break;
	}
 
	// Simulate the environment ahead by 'dt' seconds.
	updateEnvironment(dt);
}
 
sample_code/basic_loop.txt · Last modified: 2008/11/03 04:32