package umontreal.iro.lecuyer.randvar;
import umontreal.iro.lecuyer.rng.*;
import umontreal.iro.lecuyer.probdist.*;


/**
 * This class implements methods for generating random variates from the 
 * half-normal distribution with parameters μ and 
 * σ > 0.
 * Its density is
 * 
 * 

*
* f (x) = ((2/π)1/2/σ)e-(x-μ)2/(2σ2),        for x > = μ, *

* */ public class HalfNormalGen extends RandomVariateGen { // Distribution parameters protected double mu; protected double sigma; /** * Creates a new half-normal generator with parameters μ = * mu and σ = sigma, using stream s. * */ public HalfNormalGen (RandomStream s, double mu, double sigma) { super (s, new HalfNormalDist (mu, sigma)); setParams (mu, sigma); } /** * Creates a new generator for the distribution dist, * using stream s. * */ public HalfNormalGen (RandomStream s, HalfNormalDist dist) { super (s, dist); if (dist != null) setParams (dist.getMu(), dist.getSigma()); } /** * Generates a variate from the half-normal distribution with * parameters μ = mu and σ = sigma, * using stream s. * * @param s the random stream * * @param mu the parameter mu * * @param sigma the parameter sigma * * @return Generates a variate from the HalfNormal distribution * */ public static double nextDouble (RandomStream s, double mu, double sigma) { return HalfNormalDist.inverseF (mu, sigma, s.nextDouble()); } /** * Returns the parameter μ of this object. * * @return the parameter mu * */ public double getMu() { return mu; } /** * Returns the parameter σ of this object. * * @return the parameter mu * */ public double getSigma() { return sigma; } protected void setParams (double mu, double sigma) { if (sigma <= 0.0) throw new IllegalArgumentException ("sigma <= 0"); this.mu = mu; this.sigma = sigma; } }

Ads help maintain this website.