org.apache.commons.math3.distribution.LogNormalDistribution Java Examples

The following examples show how to use org.apache.commons.math3.distribution.LogNormalDistribution. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Random.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@operator (
		value = "lognormal_rnd",
		can_be_const = false,
		category = { IOperatorCategory.RANDOM },
		concept = { IConcept.RANDOM })
@doc (
		value = "returns a random value from a Log-Normal distribution with specified values of the shape (alpha) and scale (beta) parameters. See https://en.wikipedia.org/wiki/Log-normal_distribution for more details. ",
		examples = { @example (
				value = "lognormal_rnd(2,3) ",
				equals = "0.731",
				test = false) },
		see = { "binomial", "gamma_rnd", "gauss_rnd", "poisson", "rnd", "skew_gauss", "truncated_gauss",
				"weibull_rnd", "lognormal_trunc_rnd" })
@no_test (Reason.IMPOSSIBLE_TO_TEST)
public static Double OpLogNormalDist(final IScope scope, final Double shape, final Double scale)
		throws GamaRuntimeException {
	final LogNormalDistribution dist = new LogNormalDistribution(scope.getRandom().getGenerator(), shape, scale);
	return dist.sample();
}
 
Example #2
Source File: Random.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@operator (
		value = "lognormal_density",
		can_be_const = false,
		category = { IOperatorCategory.RANDOM },
		concept = { IConcept.RANDOM })
@doc (
		value = "lognormal_density(x,shape,scale) returns the probability density function (PDF) at the specified point x "
				+ "of the logNormal distribution with the given shape and scale.",
		examples = { @example ( value = "lognormal_density(1,2,3) ", equals = "0.731", test = false) },
		see = { "binomial", "gamma_rnd", "gauss_rnd", "poisson", "rnd", "skew_gauss", "truncated_gauss",
				"weibull_rnd", "weibull_density", "gamma_density" })
@no_test (Reason.IMPOSSIBLE_TO_TEST)
public static Double OpLogNormalDist(final IScope scope, final Double x, final Double shape, final Double scale)
		throws GamaRuntimeException {
	final LogNormalDistribution dist = new LogNormalDistribution(scope.getRandom().getGenerator(), shape, scale);
	return dist.density(x);
}
 
Example #3
Source File: HouseholdBehaviour.java    From housing-model with MIT License 6 votes vote down vote up
/**
 * Initialise behavioural variables for a new household: propensity to save, whether the household will have the BTL
    * investor "gene" (provided its income percentile is above a certain minimum), and whether the household will be a
    * fundamentalist or a trend follower investor (provided it has received the BTL investor gene)
 *
 * @param incomePercentile Fixed income percentile for the household (assumed constant over a lifetime)
    */
HouseholdBehaviour(MersenneTwister prng, double incomePercentile) {
	this.prng = prng;  // initialize the random number generator

       // Set downpayment distributions for both first-time-buyers and owner-occupiers
       downpaymentDistFTB = new LogNormalDistribution(this.prng, config.DOWNPAYMENT_FTB_SCALE, config.DOWNPAYMENT_FTB_SHAPE);
       downpaymentDistOO = new LogNormalDistribution(this.prng, config.DOWNPAYMENT_OO_SCALE, config.DOWNPAYMENT_OO_SHAPE);
    // Compute propensity to save, so that it is constant for a given household
       propensityToSave = config.DESIRED_BANK_BALANCE_EPSILON * prng.nextGaussian();
       // Decide if household is a BTL investor and, if so, its tendency to seek capital gains or rental yields
	BTLCapGainCoefficient = 0.0;
       if(incomePercentile > config.MIN_INVESTOR_PERCENTILE &&
               prng.nextDouble() < config.getPInvestor()/config.MIN_INVESTOR_PERCENTILE) {
           BTLInvestor = true;
           if(prng.nextDouble() < config.P_FUNDAMENTALIST) {
               BTLCapGainCoefficient = config.FUNDAMENTALIST_CAP_GAIN_COEFF;
           } else {
               BTLCapGainCoefficient = config.TREND_CAP_GAIN_COEFF;
           }
       } else {
           BTLInvestor = false;
       }
}
 
Example #4
Source File: LogNormalDistributionEvaluator.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Override
public Object doWork(Object first, Object second) throws IOException{
  if(null == first){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the first value",toExpression(constructingFactory)));
  }
  if(null == second){
    throw new IOException(String.format(Locale.ROOT,"Invalid expression %s - null found for the second value",toExpression(constructingFactory)));
  }

  Number shape = (Number)first;
  Number scale = (Number)second;

  return new LogNormalDistribution(scale.doubleValue(), shape.doubleValue());
}
 
Example #5
Source File: PSquarePercentileTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test Various Dist
 */
@Test
public void testDistribution() {
    doDistributionTest(new NormalDistribution(randomGenerator, 4000, 50));
    doDistributionTest(new LogNormalDistribution(randomGenerator,4000, 50));
    // doDistributionTest((new ExponentialDistribution(4000));
    // doDistributionTest(new GammaDistribution(5d,1d),0.1);
}
 
Example #6
Source File: PSquarePercentileTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test Various Dist
 */
@Test
public void testDistribution() {
    doDistributionTest(new NormalDistribution(randomGenerator, 4000, 50));
    doDistributionTest(new LogNormalDistribution(randomGenerator,4000, 50));
    // doDistributionTest((new ExponentialDistribution(4000));
    // doDistributionTest(new GammaDistribution(5d,1d),0.1);
}
 
Example #7
Source File: PatternSpikeGenerator.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
private static AbstractRealDistribution makeDist(DistributionType type, double mean, double sigma, int seed) {
    switch (type) {
        case LOGNORMAL:
            return new LogNormalDistribution(new Well19937c(seed), mean, sigma, 1.0E-9D);
        case EXPONENTIAL:
            return new ExponentialDistribution(new Well19937c(seed), mean, 1.0E-9D);
        case UNIFORM:
            return new UniformRealDistribution(new Well19937c(seed), mean - sigma, mean + sigma);
        case FIXED:
            return new UniformRealDistribution(new Well19937c(seed), mean, mean + 1.0E-9D);
        default:
            throw new IllegalArgumentException(String.format("Unsupported distribution type '%s", type));
    }
}
 
Example #8
Source File: TestJson.java    From deeplearning4j with Apache License 2.0 5 votes vote down vote up
@Test
public void testParameterSpaceJson() throws Exception {

    List<ParameterSpace<?>> l = new ArrayList<>();
    l.add(new FixedValue<>(1.0));
    l.add(new FixedValue<>(1));
    l.add(new FixedValue<>("string"));
    l.add(new ContinuousParameterSpace(-1, 1));
    l.add(new ContinuousParameterSpace(new LogNormalDistribution(1, 1)));
    l.add(new ContinuousParameterSpace(new NormalDistribution(2, 0.01)));
    l.add(new DiscreteParameterSpace<>(1, 5, 7));
    l.add(new DiscreteParameterSpace<>("first", "second", "third"));
    l.add(new IntegerParameterSpace(0, 10));
    l.add(new IntegerParameterSpace(new UniformIntegerDistribution(0, 50)));
    l.add(new BooleanSpace());

    for (ParameterSpace<?> ps : l) {
        String strJson = jsonMapper.writeValueAsString(ps);
        String strYaml = yamlMapper.writeValueAsString(ps);

        ParameterSpace<?> fromJson = jsonMapper.readValue(strJson, ParameterSpace.class);
        ParameterSpace<?> fromYaml = yamlMapper.readValue(strYaml, ParameterSpace.class);

        assertEquals(ps, fromJson);
        assertEquals(ps, fromYaml);
    }
}
 
Example #9
Source File: TestServer.java    From concurrency-limits with Apache License 2.0 4 votes vote down vote up
public Builder lognormal(long mean, long duration, TimeUnit units) {
    final LogNormalDistribution distribution = new LogNormalDistribution(3.0,1.0);
    final double distmean = distribution.getNumericalMean();
    return add("lognormal(" + mean + ")", () -> (long)(distribution.sample() * mean / distmean), duration, units);
}