Minor enhancements
This commit is contained in:
parent
01da434fc3
commit
831d1345c5
|
@ -179,7 +179,7 @@ class LogNormalDistributionBinned extends BaseDistributionBinned {
|
||||||
_set_props() {
|
_set_props() {
|
||||||
this.name = "lognormal";
|
this.name = "lognormal";
|
||||||
this.param_names = ["normal_mean", "normal_std"];
|
this.param_names = ["normal_mean", "normal_std"];
|
||||||
this.n_bounds_samples = 1000;
|
this.n_bounds_samples = 100;
|
||||||
this.n_largest_bound_sample = 10;
|
this.n_largest_bound_sample = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -306,6 +306,12 @@ module Range = {
|
||||||
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
|
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
|
||||||
(nextX -. lastX) *. (lastY +. nextY) /. 2.;
|
(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 =
|
let delta_y_over_delta_x =
|
||||||
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
|
(((lastX, lastY), (nextX, nextY)): zippedRange) =>
|
||||||
(nextY -. lastY) /. (nextX -. lastX);
|
(nextY -. lastY) /. (nextX -. lastX);
|
||||||
|
@ -316,18 +322,18 @@ module Range = {
|
||||||
|> E.R.toOption
|
|> E.R.toOption
|
||||||
|> E.O.fmap(r => r |> Belt.Array.map(_, r => (nextX(r), fn(r))));
|
|> 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 integrateWithTriangles = ({xs, ys}) => {
|
||||||
let length = E.A.length(xs);
|
let length = E.A.length(xs);
|
||||||
let cumulativeY = Belt.Array.make(length, 0.0);
|
let cumulativeY = Belt.Array.make(length, 0.0);
|
||||||
let _ = Belt.Array.set(cumulativeY, 0, 0.0);
|
let _ = Belt.Array.set(cumulativeY, 0, 0.0);
|
||||||
for (x in 0 to E.A.length(xs) - 2) {
|
for (x in 0 to E.A.length(xs) - 2) {
|
||||||
let area =
|
Belt.Array.set(
|
||||||
rangeAreaAssumingTriangles((
|
cumulativeY,
|
||||||
(xs[x], ys[x]),
|
x + 1,
|
||||||
(xs[x + 1], ys[x + 1]),
|
(xs[x + 1] -. xs[x]) *. ((ys[x] +. ys[x + 1]) /. 2.) +. cumulativeY[x],
|
||||||
));
|
);
|
||||||
let cumulative = area +. cumulativeY[x];
|
|
||||||
let _ = Belt.Array.set(cumulativeY, x + 1, cumulative);
|
|
||||||
();
|
();
|
||||||
};
|
};
|
||||||
Some({xs, ys: cumulativeY});
|
Some({xs, ys: cumulativeY});
|
||||||
|
|
|
@ -115,6 +115,7 @@ module FloatFloatMap = {
|
||||||
let fmap = (fn, t: t) => Belt.MutableMap.map(t, fn);
|
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 split = (sortedArray: array(float)) => {
|
||||||
let continuous = [||];
|
let continuous = [||];
|
||||||
let discrete = FloatFloatMap.empty();
|
let discrete = FloatFloatMap.empty();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user