Udacity CS212 unit5 赌博问题简单程序

来源:互联网 发布:网络成瘾的症状 编辑:程序博客网 时间:2024/05/31 19:55

选择hold还是gamble,通过这个程序理解utility和quality的概念。


import mathactions = ["hold", "gamble"]def Quality(state, action, U):    if action == "hold":        return U(state + 1e6)    if action == "gamble":        return U(state) * 0.5 + U(state + 3e6) * 0.5    def identical(x):return x        def BestAction(state, actions,U):    def EU(action):        return Quality(state, action, U)    return max(actions, key=EU);print BestAction(1, actions, identical)print BestAction(1e6, actions, identical)print BestAction(10e6, actions, identical)print BestAction(1, actions, math.log10)print BestAction(1e6, actions, math.log10)print BestAction(10e6, actions, math.log10)