Package teamwork :: Package math :: Module boltzmann
[hide private]
[frames] | no frames]

Source Code for Module teamwork.math.boltzmann

 1  import math 
 2   
3 -def prob(options,beta=1.):
4 for myKey,myVal in options.items(): 5 denominator = 1. 6 for yourKey,yourVal in options.items(): 7 if myKey != yourKey: 8 delta = yourVal['value']-myVal['value'] 9 try: 10 denominator += math.exp(beta*delta) 11 except OverflowError: 12 myVal['probability'] = 0. 13 break 14 else: 15 myVal['probability'] = 1./denominator 16 return options
17 18 if __name__ == '__main__': 19 import sys 20 21 beta = float(sys.argv[1])*1000. 22 options = {'punish':{'value':0.1390}, 23 'wait':{'value':0.1280}} 24 print prob(options,beta) 25