Created on 2016/02/19

@author: takuya-hv2
'''
from pybrain.rl.learners.valuebased.interface import ActionValueNetwork
from pybrainSG.rl.experiments.episodicSG import EpisodicExperimentSG
from pybrainSG.rl.agents.multiAgent import MultiAgent
from pybrainSG.rl.leaners.valuebased.nfqSG import NFQ_SG
from pybrainSG.rl.agents.learningSG import LearningAgentSG
from pybrainSG.rl.examples.tasks.huntinggame import HuntingGame, HuntingGameTask
import numpy as np
import warnings
if __name__ == '__main__':
    warnings.simplefilter("ignore")
    for _ in range(500):
        ma=MultiAgent()
        #
        HuntingGame.numberofAgents=2
        for i in range(HuntingGame.numberofAgents):
            #dimState=# position of each agent in grid world + # position of each niman in grid world + bias
            net=ActionValueNetwork(dimState=(HuntingGame.numberofAgents*2+HuntingGame.numberofAnimals*2+1),
                                   numActions=len(HuntingGame.availableActions))
            learner= NFQ_SG(maxEpochs=100)#hopefully, more than 100.
#             learner._explorer.epsilon=0.1#In one player case, that too small. 
            #print learner.explorer
            agent = LearningAgentSG(net,
                                    num_features=(np.ones(HuntingGame.numberofAgents)*(HuntingGame.numberofAgents*2+HuntingGame.numberofAnimals*2+1)),
                                    num_actions=(np.ones(HuntingGame.numberofAgents)*len(HuntingGame.availableActions)), 
                                    num_agents=HuntingGame.numberofAgents, 
                                    learner=learner,
                                    index=i)
Exemplo n.º 2
0
Created on 2016/02/28

@author: takuya-hv2
'''
from pybrainSG.rl.experiments.episodicSG import EpisodicExperimentSG
from pybrainSG.rl.leaners.valuebased.ceq import *
from pybrainSG.rl.agents.nfceqa import *
from pybrainSG.rl.examples.tasks.huntinggame import HuntingGame, HuntingGameTask
from pybrainSG.rl.agents.multiAgent import MultiAgent

import numpy as np
if __name__ == '__main__':
    warnings.simplefilter("ignore")

    for _ in range(500):
        ma = MultiAgent()
        HuntingGame.numberofAgents = 2
        for i in range(HuntingGame.numberofAgents):
            learner = NFCEQ(num_features=(HuntingGame.numberofAgents * 2 +
                                          HuntingGame.numberofAnimals * 2 + 1),
                            num_actions=np.ones(HuntingGame.numberofAgents,
                                                dtype=np.int8) *
                            len(HuntingGame.availableActions),
                            num_agents=HuntingGame.numberofAgents,
                            max_epochs=100,
                            indexOfAgent=i)
            agent = NFCEQ_Agent(
                learner,
                num_features=np.ones(HuntingGame.numberofAgents, dtype=np.int8)
                * (HuntingGame.numberofAgents * 2 +
                   HuntingGame.numberofAnimals * 2 + 1),
'''
Created on 2016/02/19

@author: takuya-hv2
'''

from pybrainSG.rl.experiments.episodicSG import EpisodicExperimentSG
from pybrainSG.rl.leaners.valuebased.learnerfaSG import Q_LinFA_SG
from pybrainSG.rl.agents.linearfaSG import LinearFA_AgentSG
from pybrainSG.rl.examples.tasks.huntinggame import HuntingGame, HuntingGameTask
from pybrainSG.rl.agents.multiAgent import MultiAgent
import numpy as np
if __name__ == '__main__':
    ma=MultiAgent()
    for i in range(HuntingGame.numberofAgents):
        learner= Q_LinFA_SG(
                            num_features=(HuntingGame.numberofAgents*2+HuntingGame.numberofAnimals*2+1),
                            num_actions=len(HuntingGame.availableActions))
        agent= LinearFA_AgentSG(
                                learner,
                                num_features=np.ones(HuntingGame.numberofAgents)*(HuntingGame.numberofAgents*2+HuntingGame.numberofAnimals*2+1),
                                num_actions=np.ones(HuntingGame.numberofAgents)*len(HuntingGame.availableActions),
                                num_agents=HuntingGame.numberofAgents,
                                index=i)
        ma.addAgent(agent)
    task=HuntingGameTask()
    exp=EpisodicExperimentSG(task,ma)
    rewards=exp.doEpisodes(number=1000)
    print "Given reward for " + str(len(rewards)) + " episodes:"
    print "Reward for Agents"
    for i in range(len(rewards)):
'''
Created on 2016/03/07

@author: takuya-hv2
'''
from pybrainSG.rl.experiments.episodicSG import EpisodicExperimentSG
from pybrainSG.rl.agents.multiAgent import MultiAgent
from pybrainSG.rl.leaners.valuebased.ceq import *
from pybrainSG.rl.agents.ceqa import *
from pybrainSG.rl.examples.tasks.gridgames import GridGameTask, GridGame
import numpy as np
import warnings

if __name__ == '__main__':
    warnings.simplefilter("ignore")
    ma = MultiAgent()
    for i in range(GridGame.numberofAgents):
        learner = CEQ_Lin(
            num_features=(GridGame.numberofAgents * 2),
            num_actions=np.ones(GridGame.numberofAgents, dtype=np.int8) *
            len(GridGame.availableActions),
            num_agents=GridGame.numberofAgents,
            indexOfAgent=i)
        agent = CEQ_Agent(
            learner,
            num_features=np.ones(GridGame.numberofAgents, dtype=np.int8) *
            (GridGame.numberofAgents * 2),
            num_actions=np.ones(GridGame.numberofAgents, dtype=np.int8) *
            len(GridGame.availableActions),
            num_agents=GridGame.numberofAgents,
            index=i)