Anonymous user
Monte Carlo methods: Difference between revisions
m
→{{header|Futhark}}
(→JS ES6) |
|||
Line 669:
<lang Futhark>
include futlib.numeric
default(f32)
fun dirvcts(): [2][30]
[
[
Line 682 ⟶ 684:
fun grayCode(x:
----------------------------------------
--- Sobol Generator
----------------------------------------
fun testBit(n:
let t = (1 << ind) in (n & t) == t
fun xorInds(n:
let reldv_vals = zipWith (
if testBit(grayCode n,i)
then dv else 0)
Line 697 ⟶ 699:
in reduce (^) 0 reldv_vals
fun sobolIndI (dir_vs: [m][num_bits]
map (xorInds n) dir_vs
fun sobolIndR(dir_vs: [m][num_bits]
let divisor = 2.0 ** f32(num_bits)
let arri = sobolIndI( dir_vs, n )
in map (
fun main(n:
let rand_nums = map (sobolIndR (dirvcts())) (iota n)
let dists = map (
let (x,y) = (xy[0],xy[1]) in
rand_nums
let bs = map (
let inside = reduce (+) 0 bs
|