/* Sally and the vending machine (1) in Picat. From https://probmods.org/chapters/social-cognition (WebPPL model) """ For instance, imagine that Sally walks up to a vending machine wishing to have a cookie. Imagine also that we know the mapping between buttons (potential actions) and foods (outcomes). We can then predict Sally’s action: We see, unsurprisingly, that if Sally wants a cookie, she will always press button b. """ Cf my Gamble model gamble_vending_machine1.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. import util. main => go. /* var : v Probabilities: b: 1.0000000000000000 mean = [b = 1.0] */ go ?=> reset_store, run_model(10_000,$model,[show_probs_trunc,mean]), nl, % show_store_lengths,nl, % fail, nl. go => true. vending_machine(State,Action) = Res => Res = case(Action, [[a,bagel], [b,cookie], [true,nothing]]). choose_action(GoalState,Transition,ActionPrior) = choose_action(GoalState, Transition, ActionPrior, undefined). choose_action(GoalState, Transition, ActionPrior, State1) = Res => State = cond(State1 == undefined,start,state1), Action = ActionPrior, observe(GoalState == apply(Transition,State,Action)), Res = Action. model() => ActionPrior = categorical([0.5,0.5],[a,b]), V = choose_action(cookie,vending_machine,ActionPrior), if observed_ok then add("v",V), end.