/** * 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(); }
/** * {@inheritDoc} * * The mean is {@code scale * Gamma(1 + (1 / shape))}, where {@code Gamma()} * is the Gamma-function. */ public double getNumericalMean() { if (!numericalMeanIsCalculated) { numericalMean = calculateNumericalMean(); numericalMeanIsCalculated = true; } return numericalMean; }
/** * used by {@link #getNumericalVariance()} * * @return the variance of this distribution */ protected double calculateNumericalVariance() { final double sh = getShape(); final double sc = getScale(); final double mn = getNumericalMean(); return (sc * sc) * FastMath.exp(Gamma.logGamma(1 + (2 / sh))) - (mn * mn); }
/** * Instantiates a new Weibull pseudo random number generator. * * @param alpha the alpha * @param beta the beta */ public WeibullDistr(double alpha, double beta) { numGen = new WeibullDistribution(alpha, beta); }
/** * @param param * shape * @param param2 * scale * @return Weibull distribution */ WeibullDistribution getWeibullDistribution(double param, double param2) { if (weibull == null || weibull.getShape() != param || weibull.getScale() != param2) { weibull = new WeibullDistribution(param, param2); } return weibull; }
@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]); 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 e) { throw new IllegalArgumentException("Invalid parameter list for extreme (Weibull) distribution: " + params); } } }
@Override public double sample() { return numGen.sample(); }
/** * {@inheritDoc} * * The variance is {@code scale^2 * Gamma(1 + (2 / shape)) - mean^2} * where {@code Gamma()} is the Gamma-function. */ public double getNumericalVariance() { if (!numericalVarianceIsCalculated) { numericalVariance = calculateNumericalVariance(); numericalVarianceIsCalculated = true; } return numericalVariance; }
/** * Instantiates a new Weibull pseudo random number generator. * * @param seed the seed * @param alpha the alpha * @param beta the beta */ public WeibullDistr(long seed, double alpha, double beta) { super(new WeibullDistribution(alpha, beta), seed); }
/** * used by {@link #getNumericalVariance()} * * @return the variance of this distribution */ protected double calculateNumericalVariance() { final double sh = getShape(); final double sc = getScale(); final double mn = getNumericalMean(); return (sc * sc) * Math.exp(Gamma.logGamma(1 + (2 / sh))) - (mn * mn); }
@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))); return new QuantizedExtremeFactory(min, max, shape, scale, quantas); } catch (Exception e) { throw new IllegalArgumentException("Invalid parameter list for quantized extreme (Weibull) distribution: " + params); } } }
/** * {@inheritDoc} * * The variance is {@code scale^2 * Gamma(1 + (2 / shape)) - mean^2} * where {@code Gamma()} is the Gamma-function. */ public double getNumericalVariance() { if (!numericalVarianceIsCalculated) { numericalVariance = calculateNumericalVariance(); numericalVarianceIsCalculated = true; } return numericalVariance; }
/** * 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(); }
@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()); } }
/** * used by {@link #getNumericalVariance()} * * @return the variance of this distribution */ protected double calculateNumericalVariance() { final double sh = getShape(); final double sc = getScale(); final double mn = getNumericalMean(); return (sc * sc) * FastMath.exp(Gamma.logGamma(1 + (2 / sh))) - (mn * mn); }
/** * {@inheritDoc} * * The mean is {@code scale * Gamma(1 + (1 / shape))}, where {@code Gamma()} * is the Gamma-function. */ public double getNumericalMean() { if (!numericalMeanIsCalculated) { numericalMean = calculateNumericalMean(); numericalMeanIsCalculated = true; } return numericalMean; }
/** * {@inheritDoc} * * The variance is {@code scale^2 * Gamma(1 + (2 / shape)) - mean^2} * where {@code Gamma()} is the Gamma-function. */ public double getNumericalVariance() { if (!numericalVarianceIsCalculated) { numericalVariance = calculateNumericalVariance(); numericalVarianceIsCalculated = true; } return numericalVariance; }
/** * 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(); }