Minor enhancements

This commit is contained in:
Ozzie Gooen 2020-03-20 11:07:27 +00:00
parent 01da434fc3
commit 831d1345c5
3 changed files with 15 additions and 8 deletions

View File

@ -179,7 +179,7 @@ class LogNormalDistributionBinned extends BaseDistributionBinned {
_set_props() {
this.name = "lognormal";
this.param_names = ["normal_mean", "normal_std"];
this.n_bounds_samples = 1000;
this.n_bounds_samples = 100;
this.n_largest_bound_sample = 10;
}

View File

@ -306,6 +306,12 @@ module Range = {
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
(nextX -. lastX) *. (lastY +. nextY) /. 2.;
//Todo: figure out how to without making new array.
let rangeAreaAssumingTrapezoids =
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
(nextX -. lastX)
*. (Js.Math.min_float(lastY, nextY) +. (lastY +. nextY) /. 2.);
let delta_y_over_delta_x =
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
(nextY -. lastY) /. (nextX -. lastX);
@ -316,18 +322,18 @@ module Range = {
|> E.R.toOption
|> E.O.fmap(r => r |> Belt.Array.map(_, r => (nextX(r), fn(r))));
// This code is messy, in part because I'm trying to make things easy on garbage collection here.
// It's using triangles instead of trapezoids right now.
let integrateWithTriangles = ({xs, ys}) => {
let length = E.A.length(xs);
let cumulativeY = Belt.Array.make(length, 0.0);
let _ = Belt.Array.set(cumulativeY, 0, 0.0);
for (x in 0 to E.A.length(xs) - 2) {
let area =
rangeAreaAssumingTriangles((
(xs[x], ys[x]),
(xs[x + 1], ys[x + 1]),
));
let cumulative = area +. cumulativeY[x];
let _ = Belt.Array.set(cumulativeY, x + 1, cumulative);
Belt.Array.set(
cumulativeY,
x + 1,
(xs[x + 1] -. xs[x]) *. ((ys[x] +. ys[x + 1]) /. 2.) +. cumulativeY[x],
);
();
};
Some({xs, ys: cumulativeY});

View File

@ -115,6 +115,7 @@ module FloatFloatMap = {
let fmap = (fn, t: t) => Belt.MutableMap.map(t, fn);
};
// todo: Figure out some way of doing this without creating a new array.
let split = (sortedArray: array(float)) => {
let continuous = [||];
let discrete = FloatFloatMap.empty();