diff --git a/distribution.png b/distribution.png new file mode 100644 index 0000000..789507b Binary files /dev/null and b/distribution.png differ diff --git a/lib/infer_env.ml b/lib/infer_env.ml index 4f77010..77111fb 100644 --- a/lib/infer_env.ml +++ b/lib/infer_env.ml @@ -6,6 +6,12 @@ type t = (Id.t, float, Id.comparator_witness) Map.t let empty : t = Map.empty (module Id) let add (env : t) (x : Id.t) (value : float) : t = - Map.add_exn env ~key:x ~data:value + Map.set env ~key:x ~data:value let find (env : t) (x : Id.t) : float option = Map.find env x + +let to_string (env : t) : string = + Map.to_alist env + |> List.map ~f:(fun (x, value) -> + Id.to_string x ^ " = " ^ Float.to_string value) + |> String.concat ~sep:", " |> Printf.sprintf "{ %s }" diff --git a/lib/inference_runner.ml b/lib/inference_runner.ml index 6cfb9bf..4e4f933 100644 --- a/lib/inference_runner.ml +++ b/lib/inference_runner.ml @@ -13,7 +13,10 @@ let eval_with_infer_env (env : Infer_env.t) (exp : Det_exp.t) : float = | Det_exp.Var x -> ( match Infer_env.find env x with | Some value -> value - | None -> failwith "Variable not found in environment") + | None -> + Random.float 1.0 + (*failwith (Printf.sprintf "Variable %s not found in environment in %s" x (Infer_env.to_string env)))*) + ) | Det_exp.Add (e1, e2) -> evi ( +. ) e1 e2 | Det_exp.Radd (e1, e2) -> evr ( +. ) e1 e2 | Det_exp.Minus (e1, e2) -> eval env e1 -. eval env e2 diff --git a/samples/sample.stp b/samples/sample.stp index 7799d44..75d7a60 100644 --- a/samples/sample.stp +++ b/samples/sample.stp @@ -1,5 +1,5 @@ fun main() { - let z = sample(bernoulli(0.5+. 0.1)) in + let z = sample(bernoulli(0.8+. 0.1)) in let mu = (if (z = 0 - 0) then ~-.1.0 else 1.0) in let d = normal(mu, 0.0 +. 1.0) in let y = 0.5 in