let make mat bg = Array.(
map
(fun p ->
let n = fold ~f:( + ) ~init:0 p in
let r =
mapi p ~f:(fun i x ->
log ((float x +. bg.(i)) /. float n /. bg.(i))
)
in
let n_case =
range p
|> Stream.fold ~f:(fun accu i -> accu +. bg.(i) *. r.(i)) ~init:0. in
append r [| n_case |])
mat
)