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


Python SwingyMonkey.get_state方法代码示例

本文整理汇总了Python中SwingyMonkey.SwingyMonkey.get_state方法的典型用法代码示例。如果您正苦于以下问题:Python SwingyMonkey.get_state方法的具体用法?Python SwingyMonkey.get_state怎么用?Python SwingyMonkey.get_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SwingyMonkey.SwingyMonkey的用法示例。


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

示例1: evaluate

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
def evaluate(gamma=0.4, iters=100, chatter=True):

    learner = TDValueLearner()
    learner.gamma = gamma

    highscore = 0
    avgscore = 0.0

    for ii in xrange(iters):

        learner.epsilon = 1/(ii+1)

        # Make a new monkey object.
        swing = SwingyMonkey(sound=False,            # Don't play sounds.
                             text="Epoch %d" % (ii), # Display the epoch on screen.
                             tick_length=1,          # Make game ticks super fast.
                             action_callback=learner.action_callback,
                             reward_callback=learner.reward_callback)

        # Loop until you hit something.
        while swing.game_loop():
            pass

        score = swing.get_state()['score']
        highscore = max([highscore, score])
        avgscore = (ii*avgscore+score)/(ii+1)

        if chatter:
            print ii, score, highscore, avgscore

        # Reset the state of the learner.
        learner.reset()

    return -avgscore
开发者ID:caseygrun,项目名称:cs181-practical-4,代码行数:36,代码来源:td_value.py

示例2: run_games

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
def run_games(learner, hist, iters = 100, t_len = 100):
    '''
    Driver function to simulate learning by having the agent play a sequence of games.
    '''

    for ii in range(iters):
        # Make a new monkey object.
        swing = SwingyMonkey(sound=False,                  # Don't play sounds.
                             text="Epoch %d" % (ii),       # Display the epoch on screen.
                             tick_length = t_len,          # Make game ticks super fast.
                             action_callback=learner.action_callback,
                             reward_callback=learner.reward_callback)

        # Loop until you hit something.
        while swing.game_loop():
            learner.last_state = swing.get_state()
            pass

        # Save score history.
        hist.append(swing.score)

        # Reset the state of the learner.
        learner.reset()

    return
开发者ID:mingu600,项目名称:Practical4,代码行数:27,代码来源:stub.py

示例3: testgame

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
def testgame(iters=100,show=True):

    learner = QLearner2()

    highestscore = 0
    avgscore = 0
    record={}
    record['epoch']=[]
    record['highest']=[]
    record['avg']=[]
    record['score']=[]
    record['q']=[]

    for ii in range(iters):

        learner.epsilon = 1/(ii+1)

        # Make a new monkey object.
        swing = SwingyMonkey(sound=False,            # Don't play sounds.
                             text="Epoch %d" % (ii), # Display the epoch on screen.
                             tick_length=1,          # Make game ticks super fast.
                             action_callback=learner.action_callback,
                             reward_callback=learner.reward_callback)

        # Loop until you hit something.
        while swing.game_loop():
            pass

        score = swing.get_state()['score']
        highestscore = max([highestscore, score])
        avgscore = (ii*avgscore+score)/(ii+1)
        q=round(float(np.count_nonzero(learner.Q))*100/learner.Q.size,3)
        
        if show==True:
            print "epoch:",ii, "highest:", highestscore, "current score:", score, "average:", avgscore, "% of Q mx filled:", q 
            
        record['epoch'].append(ii)
        record['highest'].append(highestscore)
        record['avg'].append(avgscore)
        record['score'].append(score)
        record['q'].append(q)
        pickle.dump( record, open( "record12.p", "wb" ) )  
        # Reset the state of the learner.
        learner.reset()
    

    return avgscore,highestscore,score
开发者ID:aannieliu,项目名称:monkeymonkeygogogo,代码行数:49,代码来源:model_Q_2.py

示例4: xrange

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
for ii in xrange(iters):
    learning_rate=(learning_rate_start+.5)/(iters/100)

    # Make a new monkey object.
    swing = SwingyMonkey(sound=False,            # Don't play sounds.
                         text="Epoch %d" % (ii), # Display the epoch on screen.
                         tick_length=1,          # Make game ticks super fast.
                         action_callback=learner.action_callback,
                         reward_callback=learner.reward_callback)

    # Loop until you hit something.
    while swing.game_loop():
        pass

    #store all values for mins and max  calcs -- only need to run once to get values for the find_state_bounds function which saves these values    
    scorelist.append(swing.get_state()['score'])

    #print swing.get_state()
    # Reset the state of the learner.
    learner.reset()

#calculate avg score for this approach
print numpy.average(scorelist)



# the function below finds the min/max values for each variable to deterime bin ranges
#def find_state_bounds():

    # print scorelist
    # seq_tree = [x['tree'] for x in scorelist]
开发者ID:ZXspectrumZ80,项目名称:cs181-spring2014,代码行数:33,代码来源:stub_v4.py

示例5: Learner

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
iters = 10000
learner = Learner()
reward = []
score = []
score_cur = 0
ii = 0

#for ii in xrange(iters):

while score_cur < 100:
    ii += 1
    # Make a new monkey object.
    swing = SwingyMonkey(sound=False,            # Don't play sounds.
                         text="Epoch %d" % (ii), # Display the epoch on screen.
                         tick_length=0,          # Make game ticks super fast.
                         action_callback=learner.action_callback,
                         reward_callback=learner.reward_callback)

    # Loop until you hit something.
    while swing.game_loop():
        pass
    reward.append(learner.last_reward)
    score_cur = swing.get_state()["score"]
    score.append(swing.get_state()["score"])

    print "################### Score = " + \
          str(swing.get_state()["score"]) + " ########################"
    # Reset the state of the learner.
    learner.reset()

开发者ID:amckh,项目名称:Swingy-Monkey-AI,代码行数:31,代码来源:3var.py

示例6: SwingyMonkey

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
while ii < 1e5:
    ii += 1
    # Make a new monkey object.
    swing = SwingyMonkey(
        sound=False,  # Don't play sounds.
        text="Epoch %d" % (ii),  # Display the epoch on screen.
        tick_length=0,  # Make game ticks super fast.
        action_callback=learner.action_callback,
        reward_callback=learner.reward_callback,
    )

    # Loop until you hit something.
    while swing.game_loop():
        pass
    reward.append(learner.last_reward)
    score_cur = swing.get_state()["score"]
    veloc_cur = swing.get_state()["monkey"]["vel"]
    result_cur = learner.result_callback()
    qnorm = np.linalg.norm(learner.Q)
    score.append(score_cur)
    state_grid.append(learner.state_grid)
    state_num.append(learner.state_num)

    result.append(result_cur)
    Qnorm.append(qnorm)

    State = np.sum(learner.Q != 0)
    totalState = np.sum(learner.Q > -np.inf)

    if ii > 0 and ii % 50 == 0:
        np.save(data_dir + "Qmat_backup.npy", learner.Q)
开发者ID:jereliu,项目名称:Archive,代码行数:33,代码来源:learner.py

示例7: reward_callback

# 需要导入模块: from SwingyMonkey import SwingyMonkey [as 别名]
# 或者: from SwingyMonkey.SwingyMonkey import get_state [as 别名]
        return self.last_action

    def reward_callback(self, reward):
        self.last_reward = reward

iters = 100
nvars = 3
nstates = 10
alpha = 0.2
gamma = 0.9
epsil = 0.1
learner = Learner(nvars, nstates, alpha, gamma, epsil)

for ii in xrange(iters):

    # Make a new monkey object.
    swing = SwingyMonkey(sound=False,            # Don't play sounds.
                         text="Epoch %d" % (ii), # Display the epoch on screen.
                         tick_length=1,          # Make game ticks super fast.
                         action_callback=learner.action_callback,
                         reward_callback=learner.reward_callback)

    # Loop until you hit something.
    while swing.game_loop():
        print swing.get_state()
        pass

    # Reset the state of the learner.
    learner.reset()
    
开发者ID:bob-slate-notebooks,项目名称:cs181-qlearning,代码行数:31,代码来源:td_value.py


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