Actually use cache when needed
This commit is contained in:
		
							parent
							
								
									6c536183d4
								
							
						
					
					
						commit
						67ee34d821
					
				|  | @ -3,7 +3,7 @@ | ||||||
| 
 | 
 | ||||||
| let timeDist = | let timeDist = | ||||||
|   DistPlusIngredients.make( |   DistPlusIngredients.make( | ||||||
|     ~guesstimatorString="mm(floor(10 to 15), 10 to 11, [.9,.1])", |     ~guesstimatorString="(floor(10 to 15))", | ||||||
|     ~domain=Complete, |     ~domain=Complete, | ||||||
|     ~unit= |     ~unit= | ||||||
|       DistTypes.TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), |       DistTypes.TimeDistribution({zero: MomentRe.momentNow(), unit: `years}), | ||||||
|  | @ -12,7 +12,11 @@ let timeDist = | ||||||
| 
 | 
 | ||||||
| let setup = dist => | let setup = dist => | ||||||
|   dist |   dist | ||||||
|   |> DistPlusIngredients.toDistPlus(~sampleCount=5000, ~outputXYPoints=1000); |   |> DistPlusIngredients.toDistPlus( | ||||||
|  |        ~sampleCount=10000, | ||||||
|  |        ~outputXYPoints=2000, | ||||||
|  |        ~truncateTo=Some(1000), | ||||||
|  |      ); | ||||||
| 
 | 
 | ||||||
| let distributions = () => | let distributions = () => | ||||||
|   <div> |   <div> | ||||||
|  | @ -20,7 +24,7 @@ let distributions = () => | ||||||
|       <h2> {"Single-Discrete" |> ReasonReact.string} </h2> |       <h2> {"Single-Discrete" |> ReasonReact.string} </h2> | ||||||
|       {setup( |       {setup( | ||||||
|          DistPlusIngredients.make( |          DistPlusIngredients.make( | ||||||
|            ~guesstimatorString="8 to 12, [.5,.5])", |            ~guesstimatorString="mm(5 to 20, floor(normal(20,2)), [.5, .05])", | ||||||
|            ~domain=Complete, |            ~domain=Complete, | ||||||
|            (), |            (), | ||||||
|          ), |          ), | ||||||
|  |  | ||||||
|  | @ -37,7 +37,6 @@ module IntegralChart = { | ||||||
|     let minX = integral |> Distributions.Continuous.T.minX; |     let minX = integral |> Distributions.Continuous.T.minX; | ||||||
|     let maxX = integral |> Distributions.Continuous.T.maxX; |     let maxX = integral |> Distributions.Continuous.T.maxX; | ||||||
|     let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; |     let timeScale = distPlus.unit |> DistTypes.DistributionUnit.toJson; | ||||||
|     Js.log3("HIHI", continuous, distPlus); |  | ||||||
|     <DistributionPlot |     <DistributionPlot | ||||||
|       minX |       minX | ||||||
|       maxX |       maxX | ||||||
|  |  | ||||||
|  | @ -9,13 +9,19 @@ let make = | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| let toDistPlus = | let toDistPlus = | ||||||
|     (~sampleCount=1000, ~outputXYPoints=1000, t: distPlusIngredients) |     ( | ||||||
|  |       ~sampleCount=2000, | ||||||
|  |       ~outputXYPoints=2000, | ||||||
|  |       ~truncateTo=Some(100), | ||||||
|  |       t: distPlusIngredients, | ||||||
|  |     ) | ||||||
|     : option(distPlus) => { |     : option(distPlus) => { | ||||||
|   let shape = |   let shape = | ||||||
|     Guesstimator.stringToMixedShape( |     Guesstimator.stringToMixedShape( | ||||||
|       ~string=t.guesstimatorString, |       ~string=t.guesstimatorString, | ||||||
|       ~sampleCount, |       ~sampleCount, | ||||||
|       ~outputXYPoints, |       ~outputXYPoints, | ||||||
|  |       ~truncateTo, | ||||||
|       (), |       (), | ||||||
|     ); |     ); | ||||||
|   let distPlus = |   let distPlus = | ||||||
|  |  | ||||||
|  | @ -127,14 +127,15 @@ module Continuous = { | ||||||
|       // }; |       // }; | ||||||
| 
 | 
 | ||||||
|       let integral = (~cache, t) => |       let integral = (~cache, t) => | ||||||
|         cache |         switch (cache) { | ||||||
|         |> E.O.default( |         | Some(cache) => cache | ||||||
|              t |         | None => | ||||||
|              |> xyShape |           t | ||||||
|              |> XYShape.Range.integrateWithTriangles |           |> xyShape | ||||||
|              |> E.O.toExt("This should not have happened") |           |> XYShape.Range.integrateWithTriangles | ||||||
|              |> fromShape, |           |> E.O.toExt("This should not have happened") | ||||||
|            ); |           |> fromShape | ||||||
|  |         }; | ||||||
|       let integralEndY = (~cache, t) => t |> integral(~cache) |> lastY; |       let integralEndY = (~cache, t) => t |> integral(~cache) |> lastY; | ||||||
|       let integralXtoY = (~cache, f, t) => |       let integralXtoY = (~cache, f, t) => | ||||||
|         t |> integral(~cache) |> shapeFn(CdfLibrary.Distribution.findY(f)); |         t |> integral(~cache) |> shapeFn(CdfLibrary.Distribution.findY(f)); | ||||||
|  | @ -151,8 +152,10 @@ module Discrete = { | ||||||
|       type t = DistTypes.discreteShape; |       type t = DistTypes.discreteShape; | ||||||
|       type integral = DistTypes.continuousShape; |       type integral = DistTypes.continuousShape; | ||||||
|       let integral = (~cache, t) => |       let integral = (~cache, t) => | ||||||
|         cache |         switch (cache) { | ||||||
|         |> E.O.default(Continuous.make(XYShape.accumulateYs(t), `Stepwise)); |         | Some(c) => c | ||||||
|  |         | None => Continuous.make(XYShape.accumulateYs(t), `Stepwise) | ||||||
|  |         }; | ||||||
|       let integralEndY = (~cache, t) => |       let integralEndY = (~cache, t) => | ||||||
|         t |> integral(~cache) |> Continuous.lastY; |         t |> integral(~cache) |> Continuous.lastY; | ||||||
|       let minX = XYShape.minX; |       let minX = XYShape.minX; | ||||||
|  | @ -253,32 +256,27 @@ module Mixed = { | ||||||
|             ~cache, |             ~cache, | ||||||
|             {continuous, discrete, discreteProbabilityMassFraction} as t: t, |             {continuous, discrete, discreteProbabilityMassFraction} as t: t, | ||||||
|           ) => { |           ) => { | ||||||
|         cache |         switch (cache) { | ||||||
|         |> E.O.default( |         | Some(cache) => cache | ||||||
|              { |         | None => | ||||||
|                let cont = |           let cont = | ||||||
|                  continuous |             continuous | ||||||
|                  |> Continuous.T.Integral.get(~cache=None) |             |> Continuous.T.Integral.get(~cache=None) | ||||||
|                  |> scaleContinuous(t); |             |> scaleContinuous(t); | ||||||
|                let dist = |           let dist = | ||||||
|                  discrete |             discrete | ||||||
|                  |> Discrete.T.Integral.get(~cache=None) |             |> Discrete.T.Integral.get(~cache=None) | ||||||
|                  |> Continuous.toLinear |             |> Continuous.toLinear | ||||||
|                  |> E.O.toExn("") |             |> E.O.toExn("") | ||||||
|                  |> Continuous.T.scaleBy( |             |> Continuous.T.scaleBy(~scale=discreteProbabilityMassFraction); | ||||||
|                       ~scale=discreteProbabilityMassFraction, |           Continuous.make( | ||||||
|                     ); |             XYShape.Combine.combineLinear( | ||||||
|                Continuous.make( |               Continuous.getShape(cont), Continuous.getShape(dist), (a, b) => | ||||||
|                  XYShape.Combine.combineLinear( |               a +. b | ||||||
|                    Continuous.getShape(cont), |             ), | ||||||
|                    Continuous.getShape(dist), |             `Linear, | ||||||
|                    (a, b) => |           ); | ||||||
|                    a +. b |         }; | ||||||
|                  ), |  | ||||||
|                  `Linear, |  | ||||||
|                ); |  | ||||||
|              }, |  | ||||||
|            ); |  | ||||||
|       }; |       }; | ||||||
| 
 | 
 | ||||||
|       let integralEndY = (~cache, t: t) => { |       let integralEndY = (~cache, t: t) => { | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| let guesstimatorString = "floor(10 to 20)"; | let guesstimatorString = "normal(40,10)"; | ||||||
| 
 | 
 | ||||||
| let makeI = (currentDateTime: MomentRe.Moment.t) => { | let makeI = (currentDateTime: MomentRe.Moment.t) => { | ||||||
|   DistPlusIngredients.make( |   DistPlusIngredients.make( | ||||||
|  |  | ||||||
|  | @ -29,9 +29,15 @@ module Internals = { | ||||||
|   external toCombinedFormat: (string, int, int) => combined = "run"; |   external toCombinedFormat: (string, int, int) => combined = "run"; | ||||||
| 
 | 
 | ||||||
|   // todo: Format to correct mass, also normalize the pdf. |   // todo: Format to correct mass, also normalize the pdf. | ||||||
|   let toMixedShape = (r: combined): option(DistTypes.shape) => { |   let toMixedShape = | ||||||
|  |       (~truncateTo=Some(500), r: combined): option(DistTypes.shape) => { | ||||||
|  |     let continuous = toContinous(r); | ||||||
|     let continuous = |     let continuous = | ||||||
|       toContinous(r) |> Distributions.Continuous.convertToNewLength(100); |       switch (truncateTo) { | ||||||
|  |       | Some(t) => | ||||||
|  |         continuous |> Distributions.Continuous.convertToNewLength(t) | ||||||
|  |       | None => continuous | ||||||
|  |       }; | ||||||
|     let discrete = toDiscrete(r); |     let discrete = toDiscrete(r); | ||||||
|     // let continuousProb = |     // let continuousProb = | ||||||
|     //   cont |> Distributions.Continuous.T.Integral.sum(~cache=None); |     //   cont |> Distributions.Continuous.T.Integral.sum(~cache=None); | ||||||
|  | @ -44,6 +50,12 @@ module Internals = { | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| let stringToMixedShape = | let stringToMixedShape = | ||||||
|     (~string, ~sampleCount=1000, ~outputXYPoints=1000, ()) => |     ( | ||||||
|  |       ~string, | ||||||
|  |       ~sampleCount=1000, | ||||||
|  |       ~outputXYPoints=1000, | ||||||
|  |       ~truncateTo=Some(500), | ||||||
|  |       (), | ||||||
|  |     ) => | ||||||
|   Internals.toCombinedFormat(string, sampleCount, outputXYPoints) |   Internals.toCombinedFormat(string, sampleCount, outputXYPoints) | ||||||
|   |> Internals.toMixedShape; |   |> Internals.toMixedShape(~truncateTo); | ||||||
|  | @ -42,7 +42,7 @@ const toPdf = (values, outputResolutionCount, min, max) => { | ||||||
| 
 | 
 | ||||||
|   let discrete = {xs: frequencies.map(f => f.value), ys: frequencies.map(f => f.percentage)}; |   let discrete = {xs: frequencies.map(f => f.value), ys: frequencies.map(f => f.percentage)}; | ||||||
|   let continuous = {ys: [], xs: []}; |   let continuous = {ys: [], xs: []}; | ||||||
|   if (continuousSamples.length > 1){ |   if (continuousSamples.length > 20){ | ||||||
|     const samples = new Samples(continuousSamples); |     const samples = new Samples(continuousSamples); | ||||||
| 
 | 
 | ||||||
|     const ratioSize$ = ratioSize(samples); |     const ratioSize$ = ratioSize(samples); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user