feat: add the actual model
This commit is contained in:
parent
76968afc79
commit
da9a10791f
|
@ -1,2 +1,11 @@
|
||||||
|
SHELL := /bin/bash
|
||||||
|
|
||||||
build: samples.nim
|
build: samples.nim
|
||||||
nim c --verbosity:0 samples.nim
|
nim c --verbosity:0 samples.nim
|
||||||
|
|
||||||
|
run: samples
|
||||||
|
./samples --verbosity:0
|
||||||
|
|
||||||
|
examine: samples
|
||||||
|
# nim c --verbosity:0 --opt:speed -d:release -d:danger --checks:off samples.nim && time ./samples --verbosity:0 --checks:off
|
||||||
|
nim c -d:release samples.nim && time ./samples
|
||||||
|
|
BIN
wip/nim/samples
BIN
wip/nim/samples
Binary file not shown.
|
@ -126,3 +126,20 @@ proc mixture(sxs: seq[seq[float]], ps: seq[float], n: int): seq[float] =
|
||||||
|
|
||||||
return toSeq(1..n).map(_ => get_mixture_sample())
|
return toSeq(1..n).map(_ => get_mixture_sample())
|
||||||
|
|
||||||
|
## Actual model
|
||||||
|
|
||||||
|
let n = 1000000
|
||||||
|
|
||||||
|
let p_a = 0.8
|
||||||
|
let p_b = 0.5
|
||||||
|
let p_c = p_a * p_b
|
||||||
|
|
||||||
|
let weights = @[ 1.0 - p_c, p_c/2.0, p_c/4.0, p_c/4.0 ]
|
||||||
|
|
||||||
|
let fs = [ () => 0.0, () => 1.0, () => to(1.0, 3.0), () => to(2.0, 10.0) ]
|
||||||
|
let dists = fs.map(f => make_samples(f, n))
|
||||||
|
let result = mixture(dists, weights, n)
|
||||||
|
let mean_result = foldl(result, a + b, 0.0) / float(result.len)
|
||||||
|
|
||||||
|
# echo result
|
||||||
|
echo mean_result
|
||||||
|
|
Loading…
Reference in New Issue
Block a user