本文整理汇总了Python中agents.Agent方法的典型用法代码示例。如果您正苦于以下问题:Python agents.Agent方法的具体用法?Python agents.Agent怎么用?Python agents.Agent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类agents
的用法示例。
在下文中一共展示了agents.Agent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def __init__(self):
Agent.__init__(self)
state = []
seq = []
def program(percept):
state = self.update_state(state, percept)
if not seq:
goal = self.formulate_goal(state)
problem = self.formulate_problem(state, goal)
seq = self.search(problem)
action = seq[0]
seq[0:1] = []
return action
self.program = program
#______________________________________________________________________________
## Uninformed Search algorithms
示例2: WalkSAT
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def WalkSAT(clauses, p=0.5, max_flips=10000):
## model is a random assignment of true/false to the symbols in clauses
## See ~/aima1e/print1/manual/knowledge+logic-answers.tex ???
model = dict([(s, random.choice([True, False]))
for s in prop_symbols(clauses)])
for i in range(max_flips):
satisfied, unsatisfied = [], []
for clause in clauses:
if_(pl_true(clause, model), satisfied, unsatisfied).append(clause)
if not unsatisfied: ## if model satisfies all the clauses
return model
clause = random.choice(unsatisfied)
if probability(p):
sym = random.choice(prop_symbols(clause))
else:
## Flip the symbol in clause that miximizes number of sat. clauses
raise NotImplementedError
model[sym] = not model[sym]
# PL-Wumpus-Agent [Fig. 7.19]
示例3: get_action
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def get_action(self, state, legal_moves=None):
"""Agent method, called by the game to pick a move."""
if legal_moves is None:
legal_moves = self.reversi.legal_moves(state)
if not legal_moves:
# no actions available
return None
else:
move = None
if self.epsilon > random.random():
move = random.choice(legal_moves)
else:
move = self.policy(state, legal_moves)
if self.learning_enabled:
self.train(state, legal_moves)
self.prev_move = move
self.prev_state = state
return move
示例4: __init__
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def __init__(self, belief_state):
agents.Agent.__init__(self)
def program(percept):
belief_state.observe(action, percept)
program.action = argmax(belief_state.actions(),
belief_state.expected_outcome_utility)
return program.action
program.action = None
self.program = program
#______________________________________________________________________________
示例5: __init__
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def __init__(self,location,shape,plot):
self.location = location
self.shape = shape
self.plot = plot
self.env = Environment(self.shape)
self.agent = Agent()
self.child = Child(self.env.state)
示例6: create_agents
# 需要导入模块: import agents [as 别名]
# 或者: from agents import Agent [as 别名]
def create_agents(self):
agents = []
for _ in range(self.config.num_threads):
memory = ReplayMemory(self.config)
agent = Agent(self.policy_network(), memory, self.summary, self.config)
agents.append(agent)
return agents