From 3c95ebe36715616a533be1c6f3dbd59c7fc27501 Mon Sep 17 00:00:00 2001 From: imstatlab Date: Mon, 17 Oct 2016 13:52:22 +0200 Subject: [PATCH] Added RandPoissonFlow and RandBinomialFlow --- js/EquationEditor.js | 2 ++ js/SimulationEngine/calc/functions.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/js/EquationEditor.js b/js/EquationEditor.js index 8cb919aa..4abdc1ab 100755 --- a/js/EquationEditor.js +++ b/js/EquationEditor.js @@ -182,8 +182,10 @@ function EquationWindow(config) { ["Lognormal Distribution", "RandLognormal(##Mean$$, ##Standard Deviation$$)", "Generates a log-normally distributed random number with a mean and a standard deviation."], ["Binary Distribution", "RandBoolean(##Probability$$)", "Returns 1 with the specified probability, otherwise 0. The probability is optional and defaults to 0.5: a coin flip.", ["RandBoolean(0.1)", "False"]], ["Binomial Distribution", "RandBinomial(##Count$$, ##Probability$$)", "Generates a binomially distributed random number. The number of successes in Count random events each with Probability of success."], + ["Binomial Distribution Flow", "RandBinomialFlow(##Count$$, ##Probability$$)", "Generates a binomially distribution adapted to simulation Timestep."], ["Negative Binomial", "RandNegativeBinomial(##Successes$$, ##Probability$$)", "Generates a negative binomially distributed random number. The number of random events each with Probability of success required to generate the specified Successes."], ["Poisson Distribution", "RandPoisson(##Lambda$$)", "Generates a Poisson distributed random number."], + ["Poisson Distribution Flow", "RandPoissonFlow(##Lambda$$)", "Generates a Poisson distribution adapted to simulation Timestep."], ["Triangular Distribution", "RandTriangular(##Minimum$$, ##Maximum$$, ##Peak$$)", "Generates a triangularly distributed random number."], ["Exponential Distribution", "RandExp(##Lambda$$)", "Generates an exponentially distributed random number with the specified rate parameter."], ["Gamma Distribution", "RandGamma(##Alpha$$, ##Beta$$)", "Generates a Gamma distributed random number."], diff --git a/js/SimulationEngine/calc/functions.js b/js/SimulationEngine/calc/functions.js index 00ad632a..3dd3e754 100755 --- a/js/SimulationEngine/calc/functions.js +++ b/js/SimulationEngine/calc/functions.js @@ -76,12 +76,20 @@ defineFunction("RandBinomial", {params: [{name:"Count", noUnits:true, noVector:t defineFunction("RandNegativeBinomial", {params: [{name:"Successes", noUnits:true, noVector:true}, {name:"Probability", noUnits:true, noVector:true}]}, function(x){ return new Material(RandNegativeBinomial(x[0].toNum().value, x[1].toNum().value)); }); +defineFunction("RandBinomialFlow", {params: [{name:"Count", noUnits:true, noVector:true}, {name:"Probability", noUnits:true, noVector:true}]}, function(x){ + var dt=simulate.timeStep.toNum().value; + return new Material(RandBinomial(x[0].toNum().value, dt*x[1].toNum().value)/dt); +}); defineFunction("RandGamma", {params:[{name:"Alpha", noUnits:true, noVector:true}, {name:"Beta", noUnits:true, noVector:true}]}, function(x){ return new Material(RandGamma(x[0].toNum().value, x[1].toNum().value)); }); defineFunction("RandPoisson", {params:[{name:"Rate", noUnits:true, noVector:true}]}, function(x){ return new Material(RandPoisson(x[0].toNum().value)); }); +defineFunction("RandPoissonFlow", {params:[{name:"Rate", noUnits:true, noVector:true}]}, function(x){ + var dt=simulate.timeStep.toNum().value; + return new Material(RandPoisson(dt*x[0].toNum().value)/dt); +}); defineFunction("RandTriangular", {params:[{name:"Minimum", noUnits:true, noVector:true}, {name:"Maximum", noUnits:true, noVector:true}, {name:"Peak", noUnits:true, noVector:true}]}, function(x){ return new Material(RandTriangular(x[0].toNum().value, x[1].toNum().value, x[2].toNum().value)); });