/* Indian GPA problem in Picat. From cplint http://cplint.ml.unife.it/example/inference/indian_gpa.pl """ The Indian GPA Problem. From http://www.robots.ox.ac.uk/~fwood/anglican/examples/viewer/?worksheet=indian-gpa "This example was inspired by Stuart Russell...the problem is: if you observe that a student GPA is exactly 4.0 in a model of transcripts of students from the USA (GPA's from 0.0 to 4.0 and India (GPA's from 0.0 to 10.0) what is the probability that the student is from India?... As we know from statistics, given the mixture distribution and given the fact that his/her GPA is exactly 4.0, the probability that the student is American must be 1.0. (i.e. zero probability that the student is from India)." Probabilistic logic program from https://github.com/davidenitti/DC/blob/master/examples/indian-gpa.pl """ Cf my Gamble model gamble_indian_gpa.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. /* * Observe GPA 4.0 var : gpa Probabilities (truncated): 4.0: 0.9794959419051688 3.99933292902975: 0.0004271678769757 3.999222703277703: 0.0004271678769757 3.999128492548656: 0.0004271678769757 ......... 3.991430761288587: 0.0004271678769757 3.990117294709253: 0.0004271678769757 3.99005961790218: 0.0004271678769757 3.990041163745355: 0.0004271678769757 mean = 3.99989 var : nationality Probabilities: usa: 0.9944468175993165 india: 0.0055531824006835 mean = [usa = 0.994447,india = 0.00555318] var : perfect Probabilities: true: 0.9794959419051688 false: 0.0205040580948313 mean = [true = 0.979496,false = 0.0205041] * Observe perfect var : gpa Probabilities: 4.0: 0.6104205236709865 10.0: 0.3895794763290135 mean = 6.33748 var : nationality Probabilities: usa: 0.6104205236709865 india: 0.3895794763290135 mean = [usa = 0.610421,india = 0.389579] var : perfect Probabilities: true: 1.0000000000000000 mean = [true = 1.0] * Observe GPA 3.0 var : gpa Probabilities (truncated): 3.009967493363641: 0.0136986301369863 3.009857760281236: 0.0136986301369863 3.009483848237192: 0.0136986301369863 3.009308582641794: 0.0136986301369863 ......... 2.991065863981408: 0.0136986301369863 2.990856581828956: 0.0136986301369863 2.99071886250317: 0.0136986301369863 2.990261559835757: 0.0136986301369863 mean = 2.99981 var : nationality Probabilities: usa: 0.6849315068493150 india: 0.3150684931506849 mean = [usa = 0.684932,india = 0.315068] var : perfect Probabilities: false: 1.0000000000000000 mean = [false = 1.0] * Observe GPA 4.1 var : gpa Probabilities (truncated): 4.109083606912328: 0.0400000000000000 4.108320150574818: 0.0400000000000000 4.108249672738951: 0.0400000000000000 4.106630577755454: 0.0400000000000000 ......... 4.092139552390267: 0.0400000000000000 4.090959901963807: 0.0400000000000000 4.090655261692896: 0.0400000000000000 4.090297838715044: 0.0400000000000000 mean = 4.10021 var : nationality Probabilities: india: 1.0000000000000000 mean = [india = 1.0] var : perfect Probabilities: false: 1.0000000000000000 mean = [false = 1.0] * Observe nationality = usa var : gpa Probabilities (truncated): 4.0: 0.1568432890123702 3.999496482312445: 0.0000661506912747 3.999053506180203: 0.0000661506912747 3.99875643849315: 0.0000661506912747 ......... 0.001365123317281: 0.0000661506912747 0.001136243343882: 0.0000661506912747 0.001012198627466: 0.0000661506912747 0.000850087032118: 0.0000661506912747 mean = 2.30806 var : nationality Probabilities: usa: 1.0000000000000000 mean = [usa = 1.0] var : perfect Probabilities: false: 0.8431567109876298 true: 0.1568432890123702 mean = [false = 0.843157,true = 0.156843] * Observe nationality = india var : gpa Probabilities (truncated): 10.0: 0.0998320456835741 9.999500494450098: 0.0000671817265704 9.99838771764114: 0.0000671817265704 9.997837655245251: 0.0000671817265704 ......... 0.003043222242521: 0.0000671817265704 0.00295476056773: 0.0000671817265704 0.002480130643807: 0.0000671817265704 0.000008367933337: 0.0000671817265704 mean = 5.48861 var : nationality Probabilities: india: 1.0000000000000000 mean = [india = 1.0] var : perfect Probabilities: false: 0.9001679543164259 true: 0.0998320456835741 mean = [false = 0.900168,true = 0.099832] */ go ?=> reset_store, run_model(30_000,$model,[show_probs_trunc,mean]), nl, % fail, nl. go => true. model() => % Note: In https://probprog.github.io/anglican/examples/viewer/?worksheet=indian-gpa % the proportions are a little different. % Nationality = categorical([0.75,0.25],["india","usa"]), Nationality = categorical([0.5,0.5],["india","usa"]), Perfect = cond(Nationality == "india", flip(0.10), flip(0.15)), GPA = cond(Nationality == "india", condt(Perfect, 10.0, uniform(0,10)), condt(Perfect, 4.0, uniform(0,4))), % Observations: observe((GPA <= 4.0, abs(GPA-4.0) <= 0.01)), % Observe GPA=4.0 % observe(abs(GPA-3.0) <= 0.01), % Observe GPA=3.0 % observe(abs(GPA-4.1) <= 0.01), % Observe GPA=4.1 % observe(Perfect), % observe(not Perfect), % observe(Nationality == "usa"), % observe(Nationality == "india"), if observed_ok then add("nationality",Nationality), add("perfect",Perfect), add("gpa",GPA), end.