1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# 1 "src/owl/ppl/owl_ppl.ml"
(** Experimental: Probabilistic Programming *)
open Owl_types
open Owl_graph
module Make (A : Stats_Dist) = struct
include Owl_distribution.Make (A)
include Owl_lazy.Make (A)
let uniform ~a ~b =
let draw_samples args =
let a = to_arr args.(0) in
let b = to_arr args.(1) in
let n = 0 in
let t = Uniform.make ~a ~b in
of_arr (Uniform.sample t n)
in
let shape_holder = variable () in
map ~name:"uniform" draw_samples [|a;b;shape_holder|]
let gaussian ~mu ~sigma =
let draw_samples args =
let mu = to_arr args.(0) in
let sigma = to_arr args.(1) in
let n = 0 in
let t = Gaussian.make ~mu ~sigma in
of_arr (Gaussian.sample t n)
in
let shape_holder = variable () in
map ~name:"gaussian" draw_samples [|mu;sigma;shape_holder|]
let sample x s =
invalidate x;
Array.iter (fun n ->
assign_arr n (A.empty s)
) (get_by_name x "variable");
eval x;
x
let infer x = ()
end