From 831d1345c5cab570fc69af3f111532ec984be823 Mon Sep 17 00:00:00 2001 From: Ozzie Gooen Date: Fri, 20 Mar 2020 11:07:27 +0000 Subject: [PATCH] Minor enhancements --- src/components/editor/distribution.js | 2 +- src/distributions/XYShape.re | 20 +++++++++++++------- src/utility/Guesstimator.re | 1 + 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/editor/distribution.js b/src/components/editor/distribution.js index 8c4be312..31908bc6 100644 --- a/src/components/editor/distribution.js +++ b/src/components/editor/distribution.js @@ -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; } diff --git a/src/distributions/XYShape.re b/src/distributions/XYShape.re index 9b43f970..40ebd46f 100644 --- a/src/distributions/XYShape.re +++ b/src/distributions/XYShape.re @@ -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}); diff --git a/src/utility/Guesstimator.re b/src/utility/Guesstimator.re index 4a7ba2bd..3389327c 100644 --- a/src/utility/Guesstimator.re +++ b/src/utility/Guesstimator.re @@ -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();