当前位置: 首页>>代码示例>>Python>>正文


Python agent.Agent类代码示例

本文整理汇总了Python中agent.Agent的典型用法代码示例。如果您正苦于以下问题:Python Agent类的具体用法?Python Agent怎么用?Python Agent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Agent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: solve

    def solve(system,initV = None, gamma = 0.9):
        numNodes = system.network.numNodes
        numTrt = Agent.numTrt(system)
        numValidTrt = Agent.numValidTrt(numNodes,numTrt)

        if initV is None:
            initV = np.zeros((1 << numNodes,))


        it = 0
        maxIt = 1000
        tol = 1e-8
        cont = True

        v0 = initV

        while cont:
            v1 = ValueIteration.operT(system,gamma,v0)

            it += 1

            if np.linalg.norm(v1 - v0,2) < tol or it == maxIt:
                cont = False

            v0 = v1

        if it == maxIt:
            raise ValueError("ValueIteration hit iteration limit")

        return v0
开发者ID:nickjmeyer,项目名称:stdmMf,代码行数:30,代码来源:valueIteration.py

示例2: run

def run(N):
    """ Runs N episodes of a given length and then runs a demo with greedy policy
	"""
    agent = Agent()

    data = read_data('./data/q.dat')
    if data is not None:
        agent.Q = data

    for i in range(N):
        bot = Bot()
        run_episode(bot, agent, None, draw=False, policy='eps_greedy')
    # if bot.center[1] > 7: print "robot moved on: %i steps" % bot.center[1]

    pg.init()
    pg.display.init()
    surf = pg.display.set_mode((800, 600))
    surf.fill((0, 0, 0))
    pg.display.flip()
    print "Surf1:", surf

    bot = Bot()
    bot.info()
    run_episode(bot, agent, surf, draw=True, policy='eps_greedy', episode_len=60)
    print "Robot's moves:\n", bot.path
    print "Robot walked %i m" % bot.center[1]
    print "Last state value=%.1f" % agent.get_state_value(bot.get_state())
    write_data(agent.Q, "data/q.dat")
    write_path(agent.Q_values, "data/path.csv")
开发者ID:snigavig,项目名称:triptripod,代码行数:29,代码来源:run.py

示例3: setUp

 def setUp(self):
     exchange1 = Exchange()
     exchange2 = Exchange()
     self.location1 = Location(exchange1)
     self.location2 = Location(exchange2)
     self.agent1 = Agent(location=self.location1)
     self.agent2 = Agent(location=self.location2)
开发者ID:delbalso,项目名称:MarketSim,代码行数:7,代码来源:testLocation.py

示例4: run

def run(args):
    logging.basicConfig(filename=args.LOG_FILE, level=logging.DEBUG)
    logging.getLogger().addHandler(logging.StreamHandler())

    game_handler = GameStateHandler(random_seed=123, frame_skip=args.FRAME_SKIP, use_sdl=False,
                                    image_processing=lambda x: crop_and_resize(x, args.IMAGE_HEIGHT, args.IMAGE_WIDTH))
    game_handler.loadROM(args.ROM_FILE)

    height, width = game_handler.getScreenDims()
    logging.info('Screen resolution is %dx%d' % (height, width))
    num_actions = game_handler.num_actions

    net = theano_qnetwork.DeepQNetwork(args.IMAGE_HEIGHT, args.IMAGE_WIDTH, num_actions, args.STATE_FRAMES, args.DISCOUNT_FACTOR)

    replay_memory = ReplayMemoryManager(args.IMAGE_HEIGHT, args.IMAGE_WIDTH, args.STATE_FRAMES, args.REPLAY_MEMORY_SIZE)

    monitor = Monitoring(log_train_step_every=100, smooth_episode_scores_over=50)
    agent = Agent(game_handler, net, replay_memory, None, monitor, args.TRAIN_FREQ, batch_size=args.BATCH_SIZE)

    start_epsilon = args.START_EPSILON
    exploring_duration = args.EXPLORING_DURATION

    agent.populate_replay_memory(args.MIN_REPLAY_MEMORY)
    agent.play(train_steps_limit=args.LEARNING_BEYOND_EXPLORING+args.EXPLORING_DURATION, start_eps=start_epsilon,
               final_eps=args.FINAL_EPSILON, exploring_duration=exploring_duration)
开发者ID:adrianoo,项目名称:rl_atari,代码行数:25,代码来源:theano_luncher.py

示例5: Environment

class Environment():
    def __init__(self):
        env = gym.make(ENV)
        self.env = wrappers.Monitor(env, '/tmp/gym/mountaincar_dqn', force=True)
        self.num_states = self.env.observation_space.shape[0]
        self.num_actions = self.env.action_space.n
        self.agent = Agent(self.num_states, self.num_actions)

    def run(self):
        complete_episodes = 0
        episode_final = False
        output = open('result.log', 'w')

        print(self.num_states, self.num_actions)
        for episode in range(NUM_EPISODE):
            observation = self.env.reset()
            state = torch.from_numpy(observation).type(torch.FloatTensor)
            state = torch.unsqueeze(state, 0)

            for step in range(MAX_STEPS):
                if episode_final:
                    self.env.render(mode='rgb_array')

                action = self.agent.get_action(state, episode)

                observation_next, _, done, _ = self.env.step(action.item())

                state_next = torch.from_numpy(observation_next).type(torch.FloatTensor)
                state_next = torch.unsqueeze(state_next, 0)

                reward = torch.FloatTensor([0.0])
                if done:
                    state_next = None
                    if 199 <= step:
                        reward = torch.FloatTensor([-1.0])
                        complete_episodes = 0
                    else:
                        reward = torch.FloatTensor([1.0])
                        complete_episodes = complete_episodes + 1

                self.agent.memory(state, action, state_next, reward)
                self.agent.update_q_function()

                state = state_next

                if done:
                    message = 'episode: {0}, step: {1}'.format(episode, step)
                    print(message)
                    output.write(message + '\n')
                    break

                if episode_final:
                    break

                if 10 <= complete_episodes:
                    print('success 10 times in sequence')
                    # episode_final = True

        self.env.close()
        output.close()
开发者ID:y-kamiya,项目名称:machine-learning-samples,代码行数:60,代码来源:mountaincar_dqn.py

示例6: test_startup_and_shutdown

def test_startup_and_shutdown():
    # Create an agent that throws an exception when it receives
    # a payload command packet.
    a = Agent()
    a.bind_udp_sockets()
    a.service_handler["Payload Command"] = Agent.raise_exception

    # Run agent.
    t = threading.Thread(target=Agent.run, args=(a,))
    t.daemon = True
    t.start()

    # Send an ACK packet
    p = Packet()
    p.service = Supernova.service_id("Payload Command")
    p.dest_node = Supernova.get_my_id()
    p.ack = 1
    Send.send_to_self(p)   

    # Wait for and then assert that thread has *not* exited.
    t.join(0.01)
    assert t.is_alive()

    # Send a payload command packet -- SHUTDOWN
    p = Packet()
    p.service = Supernova.service_id("Payload Command")
    p.dest_node = Supernova.get_my_id()
    Send.send_to_self(p)   

    # Wait for and then assert that thread has exited.
    t.join(0.01)
    assert not t.is_alive()
开发者ID:SpaceVR-O1,项目名称:OverviewOne,代码行数:32,代码来源:test_agent.py

示例7: test_timeout

def test_timeout():
    # Create an agent that throws an exception when it receives
    # a payload command packet.
    a = Agent()
    a.bind_udp_sockets()
    a.service_handler["Payload Command"] = Agent.raise_exception

    # Set a timeout that is << delay.
    Agent.TIMEOUT = 0.005

    # Run agent.
    t = threading.Thread(target=Agent.run, args=(a,))
    t.daemon = True
    t.start()

    # Delay
    time.sleep(0.02)

    # Send a payload command packet -- SHUTDOWN
    p = Packet()
    p.service = Supernova.service_id("Payload Command")
    p.dest_node = Supernova.get_my_id()
    Send.send_to_self(p)   

    # Wait for and then assert that thread has exited.
    t.join(0.01)
    assert not t.is_alive()
开发者ID:SpaceVR-O1,项目名称:OverviewOne,代码行数:27,代码来源:test_agent.py

示例8: main

def main(game_name, lr, num_agents, update_target_every, model_name, tau):
    assert 'NoFrameskip-v4' in game_name

    if 'soft' in model_name:
        update_target_every = 1

    basename = '{}:lr={}:na={}:ute={}:{}'.format(
        game_name[:-14], lr, num_agents, update_target_every, model_name)

    if 'soft' in model_name:
        basename += ':tau={}'.format(tau)

    env = Agent(num_agents, game_name, basename)
    try:
        estimator = get_estimator(model_name, env.action_n, lr, 0.99, tau=tau)
        base_path = os.path.join(train_path, basename)
        print("start training!!")
        dqn(env,
            estimator,
            base_path,
            batch_size=32,
            epsilon=0.01,
            save_model_every=1000,
            update_target_every=update_target_every,
            learning_starts=200,
            memory_size=100000,
            num_iterations=40000000)
    except KeyboardInterrupt:
        print("\nKeyboard interrupt!!")
    except Exception:
        traceback.print_exc()
    finally:
        env.close()
开发者ID:liber145,项目名称:oh-my-q-learning,代码行数:33,代码来源:train.py

示例9: process

  def process(self):
    Agent.process(self)

    postponed = self._postponed_messages[:]
    self._postponed_messages = list()
    for m in postponed:
      self._process_message(m)
开发者ID:maxim-borisyak,项目名称:dummy-agent,代码行数:7,代码来源:richagent.py

示例10: __init__

	def __init__(self, player_id, own_dice_list):
		Agent.__init__(self, player_id, own_dice_list)
		self.num_each_fv = {1: 0, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0}
		for fv in self.own_dice_list:
			self.num_each_fv[fv] += 1
		self.pg = ProbGenerator((NUM_PLAYERS-1)*NUM_DICE)
		self.pg.calc()
开发者ID:yf225,项目名称:CS4701-Intro-to-AI-LiarsDice,代码行数:7,代码来源:agent2.py

示例11: main

def main():
	"""
	来源和目标的默认设置,可以自己修改。
	"""

	agent=Agent()

	#从新闻网站获取新闻的SimpleWebSource:
	url='http://news.163.com/'
	sourcename='网易'
	starttag='<!-- 头条区 -->'
	endtag='<div class="ns-wnews ns-recommand mb30" id="nsRecForYou"></div>'
	subtag='target="_blank"'
	titlePattern=r'<a(.*?)href="(http://.*?\.163\.com.*?)">(.*?)</a>'
	contentPattern=r'''
	<h1 id="h1title" class="ep-h1">(.*?)</h1>
	[\s\S]*?
	<div class="ep-time-soure cDGray">(.*?) 来源
	[\s\S]*?
	<div id="endText" class="end-text">
	([\s\S]*?)
	本文来源:(.*?)</span>
	'''
	netease=NeteaseSource(url,sourcename,starttag,
			endtag,subtag,titlePattern,contentPattern)
	#增加纯文本目标和HTML目标
	agent.addSource(netease)

	#发布新闻项目
	agent.distribute()
开发者ID:Time1ess,项目名称:MyCodes,代码行数:30,代码来源:websource.py

示例12: __init__

 def __init__(self, aid, booksList):
     Agent.__init__(self, aid)
     
     self.booksList = booksList
     
     comportamento = ComportamentoAgenteLivraria(self)
     self.behaviours.append(comportamento)
开发者ID:ArnoldJunior,项目名称:Pade,代码行数:7,代码来源:script_2_revisado.py

示例13: __init__

	def __init__(self, name, fg, ms, opt):
		Agent.__init__(self, name, fg, ms, opt)

		self.f = self.fg.functions[self.name]
		self.neighbors = self.f.variables
		self.domains = {v:self.fg.variables[v].domain for v in self.neighbors}
		self.q = {v:{value:0 for value in self.domains[v]} for v in self.neighbors}
		self.terminated_neighbors = {v:False for v in self.neighbors}
开发者ID:amirhj,项目名称:max-sum,代码行数:8,代码来源:functionagent.py

示例14: react

    def react(self, message):
        Agent.react(self, message)
        display_message(self.aid.name, 'Uma mensagem recebida')

        if 'agente_teste_participante' in self.aid.name:
            resposta = message.create_reply()
            resposta.set_content('Ola tambem agente!')
            self.send(resposta)
开发者ID:ArnoldJunior,项目名称:Pade,代码行数:8,代码来源:test_agent.py

示例15: __init__

	def __init__(self, name, fg, ms, opt):
		Agent.__init__(self, name, fg, ms, opt)

		self.v = self.fg.variables[self.name]
		self.neighbors = self.v.functions
		self.domain = self.v.domain
		self.z = {value:0 for value in self.domain}
		self.r = {f:{value:0 for value in self.domain} for f in self.neighbors}
		self.z_queue = []
开发者ID:amirhj,项目名称:max-sum,代码行数:9,代码来源:variableagent.py


注:本文中的agent.Agent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。