-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-nomh.church
40 lines (31 loc) · 1.09 KB
/
test-nomh.church
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
(define my-pi 3.14159265358979323)
(define (glp mean ssq smp)
(let ([diff (- smp mean)])
(- (- (/ (* diff diff) (* 2.0 ssq)))
(* 0.5 (+ (log 2) (log my-pi) (log ssq))))))
(define (randint l h) (+ l (sample-integer (+ 1 (- h l)))))
(define (index-in x xs)
(define (loop x k rst)
(if (is_null rst) k
(if (equal? (first rst) x) k
(loop x (+ k 1) (rest rst)))))
(loop x 0 xs))
(define (my-length xs)
(if (is_null xs) 0
(+ 1 (my-length (rest xs)))))
(define (data-loop n)
(if (= n 51) '()
(pair (list n n)
(data-loop (+ n 1)))))
(define data (data-loop 0))
(define xbar (/ (sum (map first data)) (my-length data)))
(define (make-sample)
(define alpha (gaussian 0.0 1e4))
(define beta (gaussian 0.0 1e4))
(define tau (abs (gaussian 0.0 1e4)))
(define (gauss-factor m v x) (factor (glp m v x)))
(define y-constrs (map (lambda (xy) (gauss-factor (+ alpha (* beta (- (first xy) xbar))) (/ 1.0 tau) (second xy)))
data))
(define sample (list alpha beta (/ 1.0 (expt tau 0.5)) tau))
sample)
(define sample (make-sample))