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

The following examples show how to use org.apache.commons.math3.distribution.WeibullDistribution. 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 = "weibull_rnd",
		can_be_const = false,
		category = { IOperatorCategory.RANDOM },
		concept = { IConcept.RANDOM })
@doc (
		value = "returns a random value from a Weibull distribution with specified values of the shape (alpha) and scale (beta) parameters. See https://mathworld.wolfram.com/WeibullDistribution.html for more details (equations 1 and 2). ",
		examples = { @example (
				value = "weibull_rnd(2,3) ",
				equals = "0.731",
				test = false) },
		see = { "binomial", "gamma_rnd", "gauss_rnd", "lognormal_rnd", "poisson", "rnd", "skew_gauss",
				"truncated_gauss", "weibull_trunc_rnd" })
@no_test (Reason.IMPOSSIBLE_TO_TEST)
public static Double OpWeibullDist(final IScope scope, final Double shape, final Double scale)
		throws GamaRuntimeException {
	final WeibullDistribution dist = new WeibullDistribution(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 = "weibull_density",
		can_be_const = false,
		category = { IOperatorCategory.RANDOM },
		concept = { IConcept.RANDOM })
@doc (
		value = "weibull_density(x,shape,scale) returns the probability density function (PDF) at the specified point x "
				+ "of the Weibull distribution with the given shape and scale.",
		examples = { @example ( value = "weibull_rnd(1,2,3) ", equals = "0.731", test = false) },
		see = { "binomial", "gamma_rnd", "gauss_rnd", "lognormal_rnd", "poisson", "rnd", "skew_gauss",
				"lognormal_density", "gamma_density"})
@no_test (Reason.IMPOSSIBLE_TO_TEST)
public static Double OpWeibullDistDensity(final IScope scope, final Double x, final Double shape, final Double scale)
		throws GamaRuntimeException {
	final WeibullDistribution dist = new WeibullDistribution(scope.getRandom().getGenerator(), shape, scale);

	return dist.density(x);
}
 
Example #3
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
public DistributionFactory getFactory(List<String> params)
{
    if (params.size() != 3)
        throw new IllegalArgumentException("Invalid parameter list for quantized extreme (Weibull) distribution: " + params);
    try
    {
        String[] bounds = params.get(0).split("\\.\\.+");
        final long min = parseLong(bounds[0]);
        final long max = parseLong(bounds[1]);
        final double shape = Double.parseDouble(params.get(1));
        final int quantas = Integer.parseInt(params.get(2));
        WeibullDistribution findBounds = new WeibullDistribution(shape, 1d);
        // max probability should be roughly equal to accuracy of (max-min) to ensure all values are visitable,
        // over entire range, but this results in overly skewed distribution, so take sqrt
        final double scale = (max - min) / findBounds.inverseCumulativeProbability(1d - Math.sqrt(1d/(max-min)));
        if (min == max)
            return new FixedFactory(min);
        return new QuantizedExtremeFactory(min, max, shape, scale, quantas);
    } catch (Exception ignore)
    {
        throw new IllegalArgumentException("Invalid parameter list for quantized extreme (Weibull) distribution: " + params);
    }
}
 
Example #4
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
@Override
public DistributionFactory getFactory(List<String> params)
{
    if (params.size() != 2)
        throw new IllegalArgumentException("Invalid parameter list for extreme (Weibull) distribution: " + params);
    try
    {
        String[] bounds = params.get(0).split("\\.\\.+");
        final long min = parseLong(bounds[0]);
        final long max = parseLong(bounds[1]);
        if (min == max)
            return new FixedFactory(min);
        final double shape = Double.parseDouble(params.get(1));
        WeibullDistribution findBounds = new WeibullDistribution(shape, 1d);
        // max probability should be roughly equal to accuracy of (max-min) to ensure all values are visitable,
        // over entire range, but this results in overly skewed distribution, so take sqrt
        final double scale = (max - min) / findBounds.inverseCumulativeProbability(1d - Math.sqrt(1d/(max-min)));
        return new ExtremeFactory(min, max, shape, scale);
    } catch (Exception ignore)
    {
        throw new IllegalArgumentException("Invalid parameter list for extreme (Weibull) distribution: " + params);
    }
}
 
Example #5
Source File: WeibullDistributionEvaluator.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 WeibullDistribution(shape.doubleValue(), scale.doubleValue());
}
 
Example #6
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #7
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #8
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #9
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #10
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #11
Source File: RandomDataTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() throws Exception {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #12
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #13
Source File: RandomDataGeneratorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNextWeibull() {
    double[] quartiles = TestUtils.getDistributionQuartiles(new WeibullDistribution(1.2, 2.1));
    long[] counts = new long[4];
    randomData.reSeed(1000);
    for (int i = 0; i < 1000; i++) {
        double value = randomData.nextWeibull(1.2, 2.1);
        TestUtils.updateCounts(value, counts, quartiles);
    }
    TestUtils.assertChiSquareAccept(expected, counts, 0.001);
}
 
Example #14
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public Distribution get()
{
    return new DistributionQuantized(new DistributionOffsetApache(new WeibullDistribution(new JDKRandomGenerator(), shape, scale, WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY), min, max), quantas);
}
 
Example #15
Source File: OptionDistribution.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public Distribution get()
{
    return new DistributionOffsetApache(new WeibullDistribution(new JDKRandomGenerator(), shape, scale, WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY), min, max);
}
 
Example #16
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRandomGenerator(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #17
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRandomGenerator(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #18
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRandomGenerator(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #19
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 * This implementation uses {@link #nextInversionDeviate(RealDistribution) inversion}
 * to generate random values.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @since 2.2
 */
public double nextWeibull(double shape, double scale) {
    return nextInversionDeviate(new WeibullDistribution(shape, scale));
}
 
Example #20
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRandomGenerator(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #21
Source File: RandomDataImpl.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 * This implementation uses {@link #nextInversionDeviate(RealDistribution) inversion}
 * to generate random values.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @since 2.2
 */
public double nextWeibull(double shape, double scale) {
    return nextInversionDeviate(new WeibullDistribution(shape, scale));
}
 
Example #22
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRan(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}
 
Example #23
Source File: RandomDataGenerator.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Generates a random value from the {@link WeibullDistribution Weibull Distribution}.
 *
 * @param shape the shape parameter of the Weibull distribution
 * @param scale the scale parameter of the Weibull distribution
 * @return random value sampled from the Weibull(shape, size) distribution
 * @throws NotStrictlyPositiveException if {@code shape <= 0} or
 * {@code scale <= 0}.
 */
public double nextWeibull(double shape, double scale) throws NotStrictlyPositiveException {
    return new WeibullDistribution(getRandomGenerator(), shape, scale,
            WeibullDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY).sample();
}