这个走路急胸疼是怎么回事事求大神在线急!

求大神解析一下这串代码是什么意思!!!急在线等【python吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:139,960贴子:
求大神解析一下这串代码是什么意思!!!急在线等收藏
&&&Run all doctests from modules on the command line.
For eachmodule, if there is a &module.txt& file, run that too.
However,if the module.txt file contains the comment &# demo&,then the remainder of the file has its &&&&& lines executed,but not run through doctest.
The idea is that you can use thisto demo statements that return random or otherwise variable results.Example usage:
python doctests.py *.py&&&import doctest, redef run_tests(modules, verbose=None):
&Run tests f then summarize results.&
for module in modules:
tests, demos = split_extra_tests(module.__name__ + &.txt&)
if '__doc__' not in dir(module):
module.__doc__ = ''
module.__doc__ += '\n' + tests + '\n'
doctest.testmod(module, report=0, verbose=verbose)
for stmt in re.findall(&&&& (.*)&, demos):
exec stmt in module.__dict__
doctest.master.summarize()def split_extra_tests(filename):
&&&Take a filename and, if it exists, return a 2-tuple of
the parts before and after '# demo'.&&&
contents = open(filename).read() + '# demo'
return contents.split(&# demo&, 1)
except IOError:
return ('', '')if __name__ == &__main__&:
import sys
modules = [__import__(name.replace('.py',''))
for name in sys.argv if name != &-v&]
run_tests(modules, (&-v& in sys.argv))
苹果怎么设置铃声?
还有这串。。。我是小白&&&Markov Decision Processes (Chapter 17)First we define an MDP, and the special case of a GridMDP, in whichstates are laid out in a 2-dimensional grid.
We also represent a policyas a dictionary of {state:action} pairs, and a Utility function as adictionary of {state:number} pairs.
We then define the value_iteration and policy_iteration algorithms.&&&from utils import *class MDP:
&&&A Markov Decision Process, defined by an initial state, transition model,
and reward function. We also keep track of a gamma value, for use by
algorithms. The transition model is represented somewhat differently from
Instead of T(s, a, s') being
probability number for each
state/action/state triplet, we instead have T(s, a) return a list of (p, s')
We also keep track of the possible states, terminal states, and
actions for each state. [page 615]&&&
def __init__(self, init, actlist, terminals, gamma=.9):
update(self, init=init, actlist=actlist, terminals=terminals,
gamma=gamma, states=set(), reward={})
def R(self, state):
&Return a numeric reward for this state.&
return self.reward[state]
def T(state, action):
&&&Transition model.
From a state and an action, return a list
of (result-state, probability) pairs.&&&
def actions(self, state):
&&&Set of actions that can be performed in this state.
By default, a
fixed list of actions, except for terminal states. Override this
method if you need to specialize by state.&&&
if state in self.terminals:
return [None]
return self.actlistclass GridMDP(MDP):
&&&A two-dimensional grid MDP, as in [Figure 17.1].
All you have to do is
specify the grid as a list use None for an obstacle
(unreachable state).
Also, you should specify the terminal states.
An action is an (x, y) e.g. (1, 0) means move east.&&&
def __init__(self, grid, terminals, init=(0, 0), gamma=.9):
grid.reverse() ## because we want row 0 on bottom, not on top
MDP.__init__(self, init, actlist=orientations,
terminals=terminals, gamma=gamma)
update(self, grid=grid, rows=len(grid), cols=len(grid[0]))
for x in range(self.cols):
for y in range(self.rows):
self.reward[x, y] = grid[y][x]
if grid[y][x] is not None:
self.states.add((x, y))
def T(self, state, action):
if action == None:
return [(0.0, state)]
return [(0.8, self.go(state, action)),
(0.1, self.go(state, turn_right(action))),
(0.1, self.go(state, turn_left(action)))]
def go(self, state, direction):
&Return the state that results from going in this direction.&
state1 = vector_add(state, direction)
return if_(state1 in self.states, state1, state)
def to_grid(self, mapping):
&&&Convert a mapping from (x, y) to v into a [[..., v, ...]] grid.&&&
return list(reversed([[mapping.get((x,y), None)
for x in range(self.cols)]
for y in range(self.rows)]))
def to_arrows(self, policy):
chars = {(1, 0):'&', (0, 1):'^', (-1, 0):'&', (0, -1):'v', None: '.'}
return self.to_grid(dict([(s, chars[a]) for (s, a) in policy.items()]))#______________________________________________________________________________Fig[17,1] = GridMDP([[-0.04, -0.04, -0.04, +1],
[-0.04, None,
-0.04, -1],
[-0.04, -0.04, -0.04, -0.04]],
terminals=[(3, 2), (3, 1)])#______________________________________________________________________________def value_iteration(mdp, epsilon=0.001):
&Solving an MDP by value iteration. [Fig. 17.4]&
U1 = dict([(s, 0) for s in mdp.states])
R, T, gamma = mdp.R, mdp.T, mdp.gamma
while True:
U = U1.copy()
for s in mdp.states:
U1[s] = R(s) + gamma * max([sum([p * U[s1] for (p, s1) in T(s, a)])
for a in mdp.actions(s)])
delta = max(delta, abs(U1[s] - U[s]))
if delta & epsilon * (1 - gamma) / gamma:
return Udef best_policy(mdp, U):
&&&Given an MDP and a utility function U, determine the best policy,
as a mapping from state to action. (Equation 17.4)&&&
for s in mdp.states:
pi[s] = argmax(mdp.actions(s), lambda a:expected_utility(a, s, U, mdp))
return pidef expected_utility(a, s, U, mdp):
&The expected utility of doing a in state s, according to the MDP and U.&
return sum([p * U[s1] for (p, s1) in mdp.T(s, a)])#______________________________________________________________________________def policy_iteration(mdp):
&Solve an MDP by policy iteration [Fig. 17.7]&
U = dict([(s, 0) for s in mdp.states])
pi = dict([(s, random.choice(mdp.actions(s))) for s in mdp.states])
while True:
U = policy_evaluation(pi, U, mdp)
unchanged = True
for s in mdp.states:
a = argmax(mdp.actions(s), lambda a: expected_utility(a,s,U,mdp))
if a != pi[s]:
unchanged = False
if unchanged:
return pidef policy_evaluation(pi, U, mdp, k=20):
&&&Return an updated utility mapping U from each state in the MDP to its
utility, using an approximation (modified policy iteration).&&&
R, T, gamma = mdp.R, mdp.T, mdp.gamma
for i in range(k):
for s in mdp.states:
U[s] = R(s) + gamma * sum([p * U[s] for (p, s1) in T(s, pi[s])])
这句短的可以吗大概想表达什么就行了&&&Planning (Chapters 11-12)&&&from __future__ import generatorsfrom utils import *import agentsimport math, random, sys, time, bisect, string
求求大神来楼主要交作业了靠谱一点就行让我装下有学过&&&Reinforcement Learning (Chapter 21)&&&from utils import *import agentsclass PassiveADPAgent(agents.Agent):
&&&Passive (non-learning) agent that uses adaptive dynamic programming
on a given MDP and policy. [Fig. 21.2]&&&
NotImplementedErrorclass PassiveTDAgent(agents.Agent):
&&&Passive (non-learning) agent that uses temporal differences to learn
utility estimates. [Fig. 21.4]&&&
NotImplementedError
度娘把缩进都吃了
忘记那个人,不如忘记自己。告诉自己,不是怕他忘记,而是怕他有一天重新把你想起。岁月带走的是记忆,但回忆会越来越清晰。真的有一天,他回过头来告诉你,他一直在惦记你,千万不要相信,因为,他已经不是原来的他,而你,也不再是过去的你。
登录百度帐号推荐应用

我要回帖

更多关于 大神f1急速 的文章

 

随机推荐