/* Tug of war in Picat. From Hakaru example documentation/tugofwar_rejection.hk $ hakaru tugofwar_rejection.hk | head -100000 | collect 1.0 true: 69223 1.0 false: 30777 In this model we observe that Alice wins of Bob. This is a port of my Gamble model gamble_tug_of_war3.rkt. This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import ppl_distributions, ppl_utils. main => go. /* var : match1 mean = [alice = 1.0] Probabilities: Probabilities: alice: 1.00000000000000000 (1 / 1) var : match2 mean = [carol = 0.675987,bob = 0.324013] Probabilities: Probabilities: carol: 0.67598651596272064 (3409 / 5043) bob: 0.32401348403727942 (1634 / 5043) var : match3 mean = [alice = 0.654967,carol = 0.345033] Probabilities: Probabilities: alice: 0.65496728138013083 (1101 / 1681) carol: 0.34503271861986912 (580 / 1681) var : strength alice mean = 0.926202 Probabilities (truncated): 3.926296048892903: 0.00019829466587349 (1 / 5043) 3.814918957298187: 0.00019829466587349 (1 / 5043) 3.756409292296722: 0.00019829466587349 (1 / 5043) 3.586995465768223: 0.00019829466587349 (1 / 5043) 3.58477511925162: 0.00019829466587349 (1 / 5043) ......... 0.001056742929101: 0.00019829466587349 (1 / 5043) 0.000648192265858: 0.00019829466587349 (1 / 5043) 0.000573474206892: 0.00019829466587349 (1 / 5043) 0.000280188191874: 0.00019829466587349 (1 / 5043) 0.000052394800002: 0.00019829466587349 (1 / 5043) var : strength bob mean = 0.657199 Probabilities (truncated): 3.040586572182948: 0.00019829466587349 (1 / 5043) 2.88355263074314: 0.00019829466587349 (1 / 5043) 2.861466190334316: 0.00019829466587349 (1 / 5043) 2.787325168975777: 0.00019829466587349 (1 / 5043) 2.783159592013704: 0.00019829466587349 (1 / 5043) ......... 0.001583370791069: 0.00019829466587349 (1 / 5043) 0.00113930090667: 0.00019829466587349 (1 / 5043) 0.000961877452675: 0.00019829466587349 (1 / 5043) 0.00087867150733: 0.00019829466587349 (1 / 5043) 0.000102015539829: 0.00019829466587349 (1 / 5043) var : strength carol mean = 0.789783 Probabilities (truncated): 4.0741016897302: 0.00019829466587349 (1 / 5043) 3.482268483523745: 0.00019829466587349 (1 / 5043) 3.302073659342756: 0.00019829466587349 (1 / 5043) 3.245158884284827: 0.00019829466587349 (1 / 5043) 3.085044528888897: 0.00019829466587349 (1 / 5043) ......... 0.000824997528792: 0.00019829466587349 (1 / 5043) 0.000766496095747: 0.00019829466587349 (1 / 5043) 0.000181480639208: 0.00019829466587349 (1 / 5043) 0.000164103879448: 0.00019829466587349 (1 / 5043) 0.000013565272156: 0.00019829466587349 (1 / 5043) var : pulls alice mean = 1.58928 Probabilities (truncated): 5.597369437736634: 0.00019829466587349 (1 / 5043) 5.421232790485462: 0.00019829466587349 (1 / 5043) 5.131874004385718: 0.00019829466587349 (1 / 5043) 5.048577786378422: 0.00019829466587349 (1 / 5043) 5.037140718487107: 0.00019829466587349 (1 / 5043) ......... 0.051208555055472: 0.00019829466587349 (1 / 5043) 0.048228795409385: 0.00019829466587349 (1 / 5043) 0.045408469191927: 0.00019829466587349 (1 / 5043) 0.03708151175543: 0.00019829466587349 (1 / 5043) 0.027291174263397: 0.00019829466587349 (1 / 5043) var : pulls bob mean = 0.664278 Probabilities (truncated): 3.770481212237693: 0.00019829466587349 (1 / 5043) 3.510507522769754: 0.00019829466587349 (1 / 5043) 3.330499732396831: 0.00019829466587349 (1 / 5043) 3.296319706673931: 0.00019829466587349 (1 / 5043) 3.246099613001593: 0.00019829466587349 (1 / 5043) ......... 0.000826343223272: 0.00019829466587349 (1 / 5043) 0.000774201855797: 0.00019829466587349 (1 / 5043) 0.000764936121971: 0.00019829466587349 (1 / 5043) 0.000679155188567: 0.00019829466587349 (1 / 5043) 0.000410844123178: 0.00019829466587349 (1 / 5043) var : pulls carol mean = 1.14123 Probabilities (truncated): 6.100363602428722: 0.00019829466587349 (1 / 5043) 5.201296550063526: 0.00019829466587349 (1 / 5043) 4.714558199873927: 0.00019829466587349 (1 / 5043) 4.504175184788844: 0.00019829466587349 (1 / 5043) 4.386651172102522: 0.00019829466587349 (1 / 5043) ......... 0.002658116390014: 0.00019829466587349 (1 / 5043) 0.002213740089024: 0.00019829466587349 (1 / 5043) 0.001354507434717: 0.00019829466587349 (1 / 5043) 0.001011699446403: 0.00019829466587349 (1 / 5043) 0.000899694872041: 0.00019829466587349 (1 / 5043) */ go ?=> reset_store, Obs = [team1,team2,team1,team1,team1,team1,team1,team1], % Note team2 won match 2 run_model(10_000,$model(Obs),[mean,show_probs_rat_trunc,truncate_size=5]), fail, nl. go => true. winner(A,B,Pulls) = cond(Pulls[A] > Pulls[B],A,B). model(Obs) => Alice = 1, Bob = 2, Carol = 3, People = [Alice,Bob,Carol], PeopleMap = new_map([Alice=alice,Bob=bob,Carol=carol]), % We caches the Strengths and Pulls Strengths = [abs(normal_dist(0,1)) : P in People], Pulls = [abs(normal_dist(Strengths[P],1)) : P in People], % The matches Match1 = winner(Alice,Bob,Pulls), Match2 = winner(Bob,Carol,Pulls), Match3 = winner(Alice,Carol,Pulls), observe(Match1 == Alice), if observed_ok then add_all([ ["match1",PeopleMap.get(Match1)], ["match2",PeopleMap.get(Match2)], ["match3",PeopleMap.get(Match3)], ["strength alice",Strengths[Alice]], ["strength bob",Strengths[Bob]], ["strength carol",Strengths[Carol]], ["pulls alice",Pulls[Alice]], ["pulls bob",Pulls[Bob]], ["pulls carol",Pulls[Carol]]]) end.