umontreal.iro.lecuyer.randvar.LognormalGen Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ssj Show documentation
Show all versions of ssj Show documentation
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: LognormalGen
* Description: random variate generator for the lognormal 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
* lognormal distribution. Its density is
*
*
*
* f (x) = (1/((2π)1/2σx)e-(ln(x)-μ)2/(2σ2) for x > 0,
*
* where σ > 0.
*
*
* The (non-static) nextDouble method simply calls inverseF on the
* lognormal distribution object.
* One can also generate a lognormal random variate X via
*
*
*
* X = Math.exp (NormalGen.nextDouble (s, mu, sigma)),
*
* in which
* NormalGen can actually be replaced by any subclass of NormalGen.
*
*/
public class LognormalGen extends RandomVariateGen {
private double mu;
private double sigma = -1.0;
/**
* Creates a lognormal random variate generator with parameters
* μ = mu and σ = sigma, using stream s.
*
*/
public LognormalGen (RandomStream s, double mu, double sigma) {
this (s, new LognormalDist(mu, sigma));
setParams (mu, sigma);
}
/**
* Creates a lognormal random variate generator with parameters
* μ = 0 and
* σ = 1, using stream s.
*
*/
public LognormalGen (RandomStream s) {
this (s, 0.0, 1.0);
}
/**
* Create a random variate generator for the lognormal
* distribution dist and stream s.
*
*/
public LognormalGen (RandomStream s, LognormalDist dist) {
super (s, dist);
if (dist != null)
setParams (dist.getMu(), dist.getSigma());
}
/**
* Generates a new variate from the lognormal
* distribution with parameters μ = mu and
* σ = sigma, using stream s.
*
*/
public static double nextDouble (RandomStream s, double mu, double sigma) {
return LognormalDist.inverseF (mu, sigma, s.nextDouble());
}
/**
* Returns the parameter μ of this object.
*
*/
public double getMu() {
return mu;
}
/**
* Returns the parameter σ of this object.
*
*
*/
public double getSigma() {
return sigma;
}
/**
* Sets the parameters μ and σ of this object.
*
*/
protected void setParams (double mu, double sigma) {
if (sigma <= 0)
throw new IllegalArgumentException ("sigma <= 0");
this.mu = mu;
this.sigma = sigma;
}
}