diff --git a/README.md b/README.md index f5523bc..1175606 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,9 @@ Here's an example program and its components: ```ocaml # student.stp fun determine_grade(difficult, smart) { - if difficult = 1 & smart = 1 then 0.8 - else if difficult = 1 & smart = 0 then 0.3 - else if difficult = 0 & smart = 1 then 0.95 + if difficult & smart then 0.8 + else if difficult & !smart then 0.3 + else if !difficult & smart then 0.95 else 0.5 } @@ -37,11 +37,11 @@ let difficult = sample(bernoulli(0.4)) in let smart = sample(bernoulli(0.3)) in let grade = bernoulli(determine_grade(difficult, smart)) in let sat = bernoulli( - if smart = 1 then 0.95 + if smart then 0.94 +. 0.01 # partial evaluate to 0.95 else 0.2 ) in -observe(grade, 0); -observe(sat, 1); +observe(grade, false); +observe(sat, true); smart ``` @@ -51,21 +51,19 @@ smart ((funs (((name determine_grade) (params (difficult smart)) (body - (If (And (Eq (Var difficult) (Int 1)) (Eq (Var smart) (Int 1))) - (Real 0.8) - (If (And (Eq (Var difficult) (Int 1)) (Eq (Var smart) (Int 0))) - (Real 0.3) - (If (And (Eq (Var difficult) (Int 0)) (Eq (Var smart) (Int 1))) - (Real 0.95) (Real 0.5)))))))) + (If (And (Var difficult) (Var smart)) (Real 0.8) + (If (And (Var difficult) (Not (Var smart))) (Real 0.3) + (If (And (Not (Var difficult)) (Var smart)) (Real 0.95) (Real 0.5)))))))) (exp (Assign difficult (Sample (Call bernoulli ((Real 0.4)))) (Assign smart (Sample (Call bernoulli ((Real 0.3)))) (Assign grade (Call bernoulli ((Call determine_grade ((Var difficult) (Var smart))))) (Assign sat - (Call bernoulli ((If (Eq (Var smart) (Int 1)) (Real 0.95) (Real 0.2)))) - (Seq (Observe (Var grade) (Int 0)) - (Seq (Observe (Var sat) (Int 1)) (Var smart))))))))) + (Call bernoulli + ((If (Var smart) (Radd (Real 0.94) (Real 0.01)) (Real 0.2)))) + (Seq (Observe (Var grade) (Bool false)) + (Seq (Observe (Var sat) (Bool true)) (Var smart))))))))) ``` #### Graph Mode (-graph) @@ -73,23 +71,28 @@ smart ```scheme ((vertices (X1 X2 X3 X4)) (arcs ((X1 X3) (X2 X3) (X2 X4))) (pmdf_map - ((X1 (Dist_obj (dist bernoulli) (var X1) (args ((Real 0.4))))) - (X2 (Dist_obj (dist bernoulli) (var X2) (args ((Real 0.3))))) + ((X1 (Call bernoulli ((Value 0.4)))) (X2 (Call bernoulli ((Value 0.3)))) (X3 - (If_pred Empty - (Dist_obj (dist bernoulli) (var X3) - (args - ((If (And (Eq (Var X1) (Int 1)) (Eq (Var X2) (Int 1))) (Real 0.8) - (If (And (Eq (Var X1) (Int 1)) (Eq (Var X2) (Int 0))) (Real 0.3) - (If (And (Eq (Var X1) (Int 0)) (Eq (Var X2) (Int 1))) (Real 0.95) - (Real 0.5))))))) - One)) + (If (Value true) + (Call bernoulli + ((If (Bop && (Value true) (Bop && (Var X1) (Var X2))) (Value 0.8) + (If + (Bop && (Bop && (Value true) (Uop not (Bop && (Var X1) (Var X2)))) + (Bop && (Var X1) (Uop ! (Var X2)))) + (Value 0.3) + (If + (Bop && + (Bop && (Bop && (Value true) (Uop not (Bop && (Var X1) (Var X2)))) + (Uop not (Bop && (Var X1) (Uop ! (Var X2))))) + (Bop && (Uop ! (Var X1)) (Var X2))) + (Value 0.95) (Value 0.5)))))) + (Value 1))) (X4 - (If_pred Empty - (Dist_obj (dist bernoulli) (var X4) - (args ((If (Eq (Var X2) (Int 1)) (Real 0.95) (Real 0.2))))) - One)))) - (obs_map ((X3 (Int 0)) (X4 (Int 1))))) + (If (Value true) + (Call bernoulli + ((If (Bop && (Value true) (Var X2)) (Value 0.95) (Value 0.2)))) + (Value 1))))) + (obs_map ((X3 (Value false)) (X4 (Value true))))) ``` #### Inference Mode @@ -99,4 +102,3 @@ smart ## License STAPPL is available under the MIT license. See the [LICENSE](LICENSE) file for more info. - diff --git a/lib/typed_tree.ml b/lib/typed_tree.ml index 702165e..f59ed03 100644 --- a/lib/typed_tree.ml +++ b/lib/typed_tree.ml @@ -242,8 +242,7 @@ module Erased = struct | arg :: args -> of_exp arg :: of_args args and of_pred : pred -> exp = function - | Empty -> Value "" - | True -> Value "true" + | Empty | True -> Value "true" | False -> Value "false" | And (pred, exp) -> Bop ("&&", of_pred pred, of_exp exp) | And_not (pred, exp) -> Bop ("&&", of_pred pred, Uop ("not", of_exp exp)) diff --git a/samples/student.png b/samples/student.png index b612fdc..c665afc 100644 Binary files a/samples/student.png and b/samples/student.png differ