All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umontreal.iro.lecuyer.randvar.FoldedNormalGen Maven / Gradle / Ivy

Go to download

SSJ is a Java library for stochastic simulation, developed under the direction of Pierre L'Ecuyer, in the Département d'Informatique et de Recherche Opérationnelle (DIRO), at the Université de Montréal. It provides facilities for generating uniform and nonuniform random variates, computing different measures related to probability distributions, performing goodness-of-fit tests, applying quasi-Monte Carlo methods, collecting (elementary) statistics, and programming discrete-event simulations with both events and processes.

The newest version!


/*
 * Class:        FoldedNormalGen
 * Description:  generator of random variates from the folded normal distribution
 * Environment:  Java
 * Software:     SSJ 
 * Copyright (C) 2001  Pierre L'Ecuyer and Université de Montréal
 * Organization: DIRO, Université de Montréal
 * @author       
 * @since

 * SSJ is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License (GPL) as published by the
 * Free Software Foundation, either version 3 of the License, or
 * any later version.

 * SSJ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * A copy of the GNU General Public License is available at
   GPL licence site.
 */

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 
 * folded normal distribution  with
 * parameters μ >=  0 and 
 * σ > 0.
 * The density is
 * 
 * 

*
* f (x) = φ((x - μ/)σ) + φ((- x - μ)/σ)        for x >= 0, *

* where φ denotes the density function of a standard normal distribution. * */ public class FoldedNormalGen extends RandomVariateGen { // Distribution parameters protected double mu; protected double sigma; /** * Creates a new folded normal generator with parameters μ = * mu and σ = sigma, using stream s. * */ public FoldedNormalGen (RandomStream s, double mu, double sigma) { super (s, new FoldedNormalDist (mu, sigma)); setParams (mu, sigma); } /** * Creates a new generator for the distribution dist, * using stream s. * */ public FoldedNormalGen (RandomStream s, FoldedNormalDist dist) { super (s, dist); if (dist != null) setParams (dist.getMu(), dist.getSigma()); } /** * Generates a variate from the folded 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 FoldedNormal distribution * */ public static double nextDouble (RandomStream s, double mu, double sigma) { return FoldedNormalDist.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"); if (mu < 0.0) throw new IllegalArgumentException ("mu < 0"); this.mu = mu; this.sigma = sigma; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy