本文整理汇总了Python中vgdl.core.VGDLParser类的典型用法代码示例。如果您正苦于以下问题:Python VGDLParser类的具体用法?Python VGDLParser怎么用?Python VGDLParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VGDLParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test6
def test6():
""" Now with memory!"""
from numpy import ndarray
from examples.gridphysics.mazes import polarmaze_game
from pybrain.optimization import SNES
g = VGDLParser().parseGame(polarmaze_game)
g.buildLevel(cheese_maze)
game_env = GameEnvironment(g)
net = buildNet(game_env.outdim, 10, 4, temperature=0.1, recurrent=True)
algo = SNES(lambda x: someEpisodes(game_env, x, avgOver=6, maxSteps=30, exploretoo=False), net, verbose=True, desiredEvaluation=0.85)
print algo.batchSize
rows, cols = 2,3
episodesPerStep = 5
for i in range(rows*cols):
pylab.subplot(rows, cols, i+1)
algo.learn(episodesPerStep)
if isinstance(algo.bestEvaluable, ndarray):
net._setParameters(algo.bestEvaluable)
else:
net = algo.bestEvaluable
plotBackground(game_env)
plotTrajectories(game_env, net)
pylab.title(str((i+1)*episodesPerStep))
if algo.desiredEvaluation <= algo.bestEvaluation:
break
print
pylab.show()
示例2: plotLSPIValues
def plotLSPIValues(gametype, layout, discountFactor=0.9, useTD=False, showValue=False):
# build the game
g = VGDLParser().parseGame(gametype)
g.buildLevel(layout)
# transform into an MDP and the mapping to observations
C = MDPconverter(g)
Ts, R, fMap = C.convert()
# find the the best least-squares approximation to the policy,
# given only observations, not the state information
if useTD:
# state-based
_, Tlspi = LSTD_PI_policy(fMap, Ts, R, discountFactor=discountFactor)
else:
# state-action-based
_, Tlspi = LSPI_policy(fMap, Ts, R, discountFactor=discountFactor)
# evaluate the policy
Vlspi = trueValues(Tlspi, R, discountFactor=discountFactor)
# plot those values
featurePlot((g.width, g.height), C.states, Vlspi)
if showValue:
# expected discounted reward at initial state
Vinit = Vlspi[C.initIndex()]
pylab.xlabel("V0=%.4f"%Vinit)
示例3: testAugmented
def testAugmented():
from vgdl.core import VGDLParser
from pybrain.rl.experiments.episodic import EpisodicExperiment
from vgdl.mdpmap import MDPconverter
from vgdl.agents import PolicyDrivenAgent
zelda_level2 = """
wwwwwwwwwwwww
wA wwk1ww w
ww ww 1 w
ww wwww+w
wwwww1ww www
wwwww 0 Gww
wwwwwwwwwwwww
"""
from examples.gridphysics.mazes.rigidzelda import rigidzelda_game
g = VGDLParser().parseGame(rigidzelda_game)
g.buildLevel(zelda_level2)
env = GameEnvironment(g, visualize=False,
recordingEnabled=True, actionDelay=150)
C = MDPconverter(g, env=env, verbose=True)
Ts, R, _ = C.convert()
print C.states
print Ts[0]
print R
env.reset()
agent = PolicyDrivenAgent.buildOptimal(env)
env.visualize = True
env.reset()
task = GameTask(env)
exper = EpisodicExperiment(task, agent)
exper.doEpisodes(1)
示例4: test4
def test4():
from numpy import ndarray
from examples.gridphysics.mazes import polarmaze_game
from pybrain.optimization import SNES, WeightGuessing
g = VGDLParser().parseGame(polarmaze_game)
g.buildLevel(labyrinth2)
game_env = GameEnvironment(g)
net = buildNet(game_env.outdim, 5, 4, temperature=0.1, recurrent=False)
algo = SNES(lambda x: someEpisodes(game_env, x, avgOver=3), net, verbose=True, desiredEvaluation=0.75)
#algo = WeightGuessing(lambda x: someEpisodes(game_env, x), net, verbose=True, desiredEvaluation=0.78)
rows, cols = 2,2
episodesPerStep = 4
for i in range(rows*cols):
pylab.subplot(rows, cols, i+1)
algo.learn(episodesPerStep)
if isinstance(algo.bestEvaluable, ndarray):
net._setParameters(algo.bestEvaluable)
else:
net = algo.bestEvaluable
plotBackground(game_env)
plotTrajectories(game_env, net)
pylab.title(str((i+1)*episodesPerStep))
if algo.desiredEvaluation <= algo.bestEvaluation:
break
print
pylab.show()
示例5: testRolloutVideo
def testRolloutVideo(actions=[0, 0, 2, 2, 0, 3] * 2):
from examples.gridphysics.mazes import polarmaze_game, maze_level_1
from vgdl.core import VGDLParser
from vgdl.tools import makeGifVideo
game_str, map_str = polarmaze_game, maze_level_1
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
makeGifVideo(GameEnvironment(g, visualize=True), actions)
示例6: testRollout
def testRollout(actions=[0, 0, 2, 2, 0, 3] * 20):
from examples.gridphysics.mazes import polarmaze_game, maze_level_1
from vgdl.core import VGDLParser
game_str, map_str = polarmaze_game, maze_level_1
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
env = GameEnvironment(g, visualize=True, actionDelay=100)
env.rollOut(actions)
示例7: _createVGDLGame
def _createVGDLGame( gameSpec, levelSpec ):
import uuid
from vgdl.core import VGDLParser
# parse, run and play.
game = VGDLParser().parseGame(gameSpec)
game.buildLevel(levelSpec)
game.uiud = uuid.uuid4()
return game
示例8: test2
def test2():
from examples.gridphysics.mazes import polarmaze_game, maze_level_1
from vgdl.core import VGDLParser
game_str, map_str = polarmaze_game, maze_level_1
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
actions = [1, 0, 0, 3, 0, 2, 0, 2, 0, 0, 0]
env = GameEnvironment(g, visualize=True, actionDelay=100)
env.rollOut(actions)
env.reset()
senv = SubjectiveGame(g, actionDelay=1500)
senv.rollOut(actions)
示例9: testStochMaze
def testStochMaze():
from vgdl.core import VGDLParser
from examples.gridphysics.mazes.stochastic import stoch_game, stoch_level
g = VGDLParser().parseGame(stoch_game)
g.buildLevel(stoch_level)
C = MDPconverter(g, verbose=True)
Ts, R, fMap = C.convert()
print C.states
print R
for T in Ts:
print T
print fMap
示例10: testMaze
def testMaze():
from vgdl.core import VGDLParser
from examples.gridphysics.mazes import polarmaze_game, maze_level_1
game_str, map_str = polarmaze_game, maze_level_1
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
C = MDPconverter(g, verbose=True)
Ts, R, fMap = C.convert()
print C.states
print R
for T in Ts:
print T
print fMap
示例11: test4
def test4():
""" Same thing, but animated. """
from examples.gridphysics.mazes.windy import windy_stoch_game, windy_level
from pybrain.rl.experiments.episodic import EpisodicExperiment
from vgdl.interfaces import GameEnvironment, GameTask
from vgdl.agents import PolicyDrivenAgent
g = VGDLParser().parseGame(windy_stoch_game)
g.buildLevel(windy_level)
env = GameEnvironment(g, visualize=True, actionDelay=100)
task = GameTask(env)
agent = PolicyDrivenAgent.buildOptimal(env)
exper = EpisodicExperiment(task, agent)
res = exper.doEpisodes(5)
print res
示例12: testPolicyAgent
def testPolicyAgent():
from pybrain.rl.experiments.episodic import EpisodicExperiment
from vgdl.core import VGDLParser
from examples.gridphysics.mazes import polarmaze_game, maze_level_2
from vgdl.agents import PolicyDrivenAgent
game_str, map_str = polarmaze_game, maze_level_2
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
env = GameEnvironment(g, visualize=False, actionDelay=100)
task = GameTask(env)
agent = PolicyDrivenAgent.buildOptimal(env)
env.visualize = True
env.reset()
exper = EpisodicExperiment(task, agent)
res = exper.doEpisodes(2)
print res
示例13: test1
def test1():
from examples.gridphysics.mazes import polarmaze_game, maze_level_1
game_str, map_str = polarmaze_game, maze_level_1
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
game_env = GameEnvironment(g)
print 'number of observations:', game_env.outdim
net = buildNet(game_env.outdim, 2, 2)
for i in range(200):
net.randomize()
net.reset()
print someEpisodes(game_env, net),
if i% 20 == 19:
print
示例14: test3
def test3():
from examples.gridphysics.mazes import polarmaze_game
from examples.gridphysics.mazes.simple import maze_level_1b
from vgdl.core import VGDLParser
from pybrain.rl.experiments.episodic import EpisodicExperiment
from vgdl.interfaces import GameTask
from vgdl.agents import InteractiveAgent, UserTiredException
game_str, map_str = polarmaze_game, maze_level_1b
g = VGDLParser().parseGame(game_str)
g.buildLevel(map_str)
senv = SubjectiveGame(g, actionDelay=100, recordingEnabled=True)
#senv = GameEnvironment(g, actionDelay=100, recordingEnabled=True, visualize=True)
task = GameTask(senv)
iagent = InteractiveAgent()
exper = EpisodicExperiment(task, iagent)
try:
exper.doEpisodes(1)
except UserTiredException:
pass
print senv._allEvents
示例15: plotOptimalValues
def plotOptimalValues(gametype, layout, discountFactor=0.9, showValue=False):
# build the game
g = VGDLParser().parseGame(gametype)
g.buildLevel(layout)
# transform into an MDP
C = MDPconverter(g)
Ts, R, _ = C.convert()
# find the optimal policy
_, Topt = policyIteration(Ts, R, discountFactor=discountFactor)
# evaluate the policy
Vopt = trueValues(Topt, R, discountFactor=discountFactor)
# plot those values
featurePlot((g.width, g.height), C.states, Vopt, plotdirections=True)
if showValue:
# expected discounted reward at initial state
Vinit = Vopt[C.initIndex()]
pylab.xlabel("V0=%.4f"%Vinit)