Mathematics features can be found in various libraries embedded in Java and Capsis including:
The Apache commons math package can be used in Capsis, it proposes a set of standard distributions. Two versions are available in Capsis:
PoissonDistributionImpl poisson = new PoissonDistributionImpl (mu); int i = poisson.sample ();
Additional distributions are available in capsis.lib.math.distribution
:
Apache v3: it is possible to draw numbers directly from the Distribution object with the sample () method
// Create a BetaDistribution double alpha = 1.69291 - 0.02622 * k; double beta = 20.00094 * (1 - Math.exp(-0.02544 * k)) - 0.32242 * k; BetaDistribution dist = new BetaDistribution(alpha, beta); // Draw a random number in the distribution double zr = dist.sample();
Apache v2: If sample () is not available in the distribution, data can be generated with a RandomGenerator class:
ContinuousRandomGenerator
: for continuous distributions (Normal, Gamma, …)IntegerRandomGenerator
: for discrete distributions (ie Binomial, Poisson, …)import org.apache.commons.math.MathException; import capsis.lib.math.data.ContinuousRandomGenerator; import capsis.lib.math.distribution.TNormalDistributionImpl; /* * Return an array of values from a Truncated normal distribution */ public double[] generate_data() throws MathException { //example mu=15, sigma=2, low=10, high=20 TNormalDistributionImpl dist = new TNormalDistributionImpl(15., 2., 10., 20.); ContinuousRandomGenerator gen = new ContinuousRandomGenerator(dist); return gen.getValues(1000); }
import org.apache.commons.math.MathException; import capsis.lib.math.data.ContinuousRandomGenerator; import capsis.lib.math.distribution.TNormalDistributionImpl; /* * Return one single value from a Truncated normal distribution */ public double getValueInTrucatedNormalDistribution () throws MathException { //example mu=15, sigma=2, low=10, high=20 double mu = 15; double sigma = 2; double low = 10; double high = 20; TNormalDistributionImpl dist = new TNormalDistributionImpl(mu, sigma, low, high); ContinuousRandomGenerator gen = new ContinuousRandomGenerator(dist); return gen.nextDouble (); }