-
-
Save favre49/b2062ae84d84be245ea3e638cbc81a9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A Task class that wraps a continuous RL environment. | |
*/ | |
template<class EnvironmentType> | |
class ContinuousRLTask | |
{ | |
ContinuousRLTask(EnvironmentType& environment) : environment(environment) | |
{ /* Nothing to do here */ } | |
double Evaluate(Genome& genome) | |
{ | |
// Set the initial state. | |
EnvironmentType::State state = environment.InitialSample(); | |
genome.Input(state.Data()); | |
double loss = 0; | |
while (!environment.IsTerminal()) | |
{ | |
EnvironmentType::Action action; | |
action.action[0] = genome.Output()[0]; | |
// Use the current action to get the next state. | |
loss += environment.Sample(state, action, state); | |
// Update the state of the genome for the next step. | |
genome.Input(state.Data()); | |
} | |
return loss; | |
} | |
private: | |
EnvironmentType environment; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment