1 package nl.tudelft.simulation.jstats.distributions; 2 3 import org.djutils.exceptions.Throw; 4 5 import nl.tudelft.simulation.jstats.streams.StreamInterface; 6 7 /** 8 * The Weibull distribution with a shape parameter α and a scale parameter β. For more information on this 9 * distribution see <a href="https://mathworld.wolfram.com/WeibullDistribution.html"> 10 * https://mathworld.wolfram.com/WeibullDistribution.html </a> 11 * <p> 12 * Copyright (c) 2002-2024 Delft University of Technology, Jaffalaan 5, 2628 BX Delft, the Netherlands. All rights reserved. See 13 * for project information <a href="https://simulation.tudelft.nl/" target="_blank"> https://simulation.tudelft.nl</a>. The DSOL 14 * project is distributed under a three-clause BSD-style license, which can be found at 15 * <a href="https://https://simulation.tudelft.nl/dsol/docs/latest/license.html" target="_blank"> 16 * https://https://simulation.tudelft.nl/dsol/docs/latest/license.html</a>. 17 * </p> 18 * @author <a href="https://www.linkedin.com/in/peterhmjacobs">Peter Jacobs </a> 19 * @author <a href="https://www.tudelft.nl/averbraeck">Alexander Verbraeck</a> 20 */ 21 public class DistWeibull extends DistContinuous 22 { 23 /** */ 24 private static final long serialVersionUID = 1L; 25 26 /** alpha is the shape parameter α. */ 27 private final double alpha; 28 29 /** beta is the scale parameter β. */ 30 private final double beta; 31 32 /** 33 * constructs a new Weibull distribution. 34 * @param stream StreamInterface; the random number stream 35 * @param alpha double; the shape parameter α 36 * @param beta double; the scale parameter β 37 */ 38 public DistWeibull(final StreamInterface stream, final double alpha, final double beta) 39 { 40 super(stream); 41 Throw.when(alpha <= 0.0 || beta <= 0.0, IllegalArgumentException.class, "Error Weibull - alpha <= 0.0 or beta <= 0.0"); 42 this.alpha = alpha; 43 this.beta = beta; 44 } 45 46 /** {@inheritDoc} */ 47 @Override 48 public double draw() 49 { 50 return this.beta * Math.pow(-Math.log(this.stream.nextDouble()), 1.0d / this.alpha); 51 } 52 53 /** {@inheritDoc} */ 54 @Override 55 public double getProbabilityDensity(final double x) 56 { 57 if (x > 0) 58 { 59 return this.alpha * Math.pow(this.beta, -this.alpha) * Math.pow(x, this.alpha - 1) 60 * Math.exp(-Math.pow(x / this.beta, this.alpha)); 61 } 62 return 0.0; 63 } 64 65 /** 66 * Return the shape parameter α. 67 * @return double; the shape parameter α 68 */ 69 public double getAlpha() 70 { 71 return this.alpha; 72 } 73 74 /** 75 * Return the scale parameter β. 76 * @return double; the scale parameter β 77 */ 78 public double getBeta() 79 { 80 return this.beta; 81 } 82 83 /** {@inheritDoc} */ 84 @Override 85 public String toString() 86 { 87 return "Weibull(" + this.alpha + "," + this.beta + ")"; 88 } 89 }