from PygameEnvironment import TwentyFortyEightEnvironment
from pybrain.rl.learners.valuebased import ActionValueNetwork
from pybrain.rl.agents import LearningAgent
from pybrain.rl.learners import NFQ, SARSA
from pybrain.rl.experiments import EpisodicExperiment
from pybrain.rl.environments import Task

#set the learning time
learning_eps = 20

#set the batch size
games_per_ep = 25

# make the environment
environment = TwentyFortyEightEnvironment()
environment.meansize = 1.0/games_per_ep

#the task is the game this time
task = environment

#make the reinforcement learning agent (use a network because inputs are continuous)
controller = ActionValueNetwork(task.nsenses,task.nactions)

#use Q learning for updating the table (NFQ is for networks)
learner = NFQ()

agent = LearningAgent(controller, learner)


示例#2
0
from pybrain.optimization import GA #HillClimber
from pybrain.rl.agents import OptimizationAgent
from pybrain.rl.experiments import EpisodicExperiment
from pybrain.rl.environments import Task

#set the learning time
learning_eps = 150

#set the batch size
games_per_ep = 75

population_size = 150


# make the environment
environment = TwentyFortyEightEnvironment()
environment.meansize = 1.0/(population_size*games_per_ep)

#the task is the game this time
task = environment

#create our network
controller = buildNetwork(task.nsenses, 20, task.nactions)

#use a Genetic Algorithm
#all the commented out lines are options you can play with
learner = GA(populationSize=population_size
            , topProportion=0.05
            , elitism=True
            , eliteProportion=0.5
            , mutationProb=0.05