edu.ucla.stat.SOCR.core
Class Distribution

java.lang.Object
  extended by edu.ucla.stat.SOCR.core.SOCRValueSettable
      extended by edu.ucla.stat.SOCR.core.Distribution
All Implemented Interfaces:
IValueSettable, Pluginable, java.util.Observer
Direct Known Subclasses:
AndersonDarlingDistribution, ArcSineDistribution, BenfordDistribution, BetaBinomialDistribution, BetaDistribution, BetaGeneralDistribution, BinomialDistribution, BinomialRandomNDistribution, BirthdayDistribution, ChiDistribution, CircleDistribution, ContinuousUniformDistribution, Convolution, CouponDistribution, DiscreteArcsineDistribution, DiscreteUniformDistribution, ErlangDistribution, ErrorDistribution, FiniteDistribution, FiniteOrderStatisticDistribution, FisherDistribution, FisherTippettDistribution, GammaDistribution, GeneralCauchyDistribution, GeneralizedExtremeValueDistribution, GompertzDistribution, GumbelDistribution, HalfNormalDistribution, HyperbolicSecantDistribution, HypergeometricDistribution, InverseGammaDistribution, InverseGaussianDistribution, JohnsonSBDistribution, JohnsonSUDistribution, KolmogorovDistribution, LaplaceDistribution, LocationScaleDistribution, LogarithmicSeriesDistribution, LogisticDistribution, LogisticExponentialDistribution, LogNormalDistribution, LomaxDistribution, MatchDistribution, MaxwellDistribution, MinimaxDistribution, MixtureDistribution, MultiNomialDistribution, MuthDistribution, NegativeBinomialDistribution, NegativeHypergeometricDistribution, NegativeMultiNomialDistribution, NonCentralChiSquareDistribution, NormalDistribution, NormalTruncatedDistribution, OrderStatisticDistribution, ParetoDistribution, PointMassDistribution, PoissonDistribution, PokerDiceDistribution, PowerFunctionDistribution, RayleighDistribution, RiceDistribution, StudentDistribution, TriangleDistribution, TwoSidedPowerDistribution, UQuadraticDistribution, VonMisesDistribution, WalkMaxDistribution, WalkPositionDistribution, WeibullDistribution, ZipfMandelbrotDistribution

public abstract class Distribution
extends SOCRValueSettable
implements Pluginable

Distribution: An abstract implmentation of a real probability distribution. All distributions should subclass this class.

It require a no argument constructor, if it need a handler for client to select values, it should create some valueSetters by calling createsValueSetter() . It is better to invoke createsValueSetter() , in the method initialize() . If you invoke them at constructor, then its subclass will creates these valueSetters too. You also must override valueChanged() to do updates corrosponding any changes in valueSetters. It is an Observer of its value changed, and observable for its value changes


Field Summary
protected  javax.swing.JApplet applet
           
static int CONTINUOUS
           
static int DISCRETE
           
static double MAXMGFXVAL
           
static double MAXMGFYVAL
           
static double MINMGFXVAL
           
static int MIXED
           
protected  java.lang.String name
           
 
Constructor Summary
Distribution()
           
 
Method Summary
 void addObserver(java.util.Observer observer)
           
static double betaCDF(double x, double a, double b)
          The method computes the beta CDF.
static double comb(double n, int k)
          This method computes the number of combinations of k objects chosen from a population of n objects
static double factorial(int k)
          This method computes k!, the number of permutations of k objects.
protected  double findGFRoot(int genFun, double prob, double guess, double xLo, double xHi)
          This method approximates the value of X for which P(x<X)=prob.
protected  double findRoot(double prob, double guess, double xLo, double xHi)
          This method approximates the value of X for which P(x<X)=prob.
static double gamma(double x)
          This method computes the gamma function.
static double gammaCDF(double x, double a)
          This method computes the CDF of the gamma distribution with shape parameter a and scale parameter 1
 double getCDF(double x)
          This method returns a default approximate cumulative distribution function.
abstract  double getDensity(double x)
          The getDensity method is abstract and must be overridden for any specific distribuiton
 java.awt.Container getDisplayPane()
           
 Domain getDomain()
          This method returns the domain of the distribution.
 double getFailureRate(double x)
          This method computes the failure rate function
protected  double getGFDerivative(int genFun, double x)
          This method approximates a derivative for a Generating Function using Newton's Quotient.
protected  double getGFSecondDerivative(int genFun, double x)
          This method approximates the second derivative for a Generating Function using Newton's Quotient.
static Distribution getInstance(java.lang.String classname)
           
 java.lang.String getLocalHelp()
          This method returns a general Distribution usage off-line help.
 double getMaxDensity()
          This method returns the largest (finite) value of the getDensity function on the finite set of domain values.
 double getMean()
          This method returns a default approximate mean, based on the finite set of domain values.
 double getMean(double[] distData)
          This method returns the sample mean of a data series
 double getMedian()
          This method computes a default approximate median.
 double getMGF(double t)
          This method returns an approximate moment generating function.
 Domain getMgfDomain()
          This method returns the domain of the mgf for that particular distribution.
 java.lang.String getName()
           
 java.lang.String getOnlineDescription()
          This method returns an online description of this distribution.
 double getPGF(double t)
          This method should be overriden if the PGF is known in closed form
 Domain getPGFDomain()
          This method returns the domain of the pgf for that particular distribution.
 double getQuantile(double p)
          This method computes an approximate getQuantile function.
 double getSampleMoment(int _power, double[] distData)
          This method returns the n-th sample moment of a data series
 double getSD()
          This method returns the standard deviation, as the square root of the variance
 SOCRDistributionFunctors getSOCRDistributionFunctors()
           
 SOCRDistributions getSOCRDistributions()
           
 int getType()
          This method returns the type of the distribution (discrete or continuous)
 double getVariance()
          This method returns a default approximate variance.
 double getVariance(double[] distData)
          This method returns the sample variance of a data series
 void initialize()
          used for some subclass to initialize before being used
 double inverseCDF(double probability)
          Inverse of the cumulative distribution function (CDF) of the specified distribution.
static double logGamma(double x)
          This method computes the log of the gamma function.
 void paramEstimate(double[] distData)
           
static double perm(double n, int k)
          This method computes the number of permuatations of k objects chosen from a population of n objects.
 double sampleMean(double[] array)
           
 double sampleVar(double[] array, double mean)
           
 void setApplet(javax.swing.JApplet applet)
           
protected  void setDomain(Domain d)
          This method sets the domain of the distribution for purposes of data collection and for default computations.
protected  void setDomain(double a, double b, double w, int t)
          This method sets the domain of the distribution for purposes of data collection and for default computations.
protected  void setMGFDomain(Domain d)
          This method sets the moment generating function's domain of the distribution for purposes of data collection and for default computations.
protected  void setMGFDomain(double a, double b, double w)
          This method sets the MGF domain of the distribution for purposes of data collection and for default computations.
 void setMGFParameters()
          This method defines a partition of an interval that acts as a default domain for the moment generating function of the distribution, for purposes of data collection and for default computations.
 void setMGFParameters(double xlo, double xhi)
           
 void setMGFParameters(double xlo, double xhi, double max_slope)
           
 void setMGFParameters(double xlo, double xhi, double max_slope, double initial_guess)
           
 void setParameters(double a, double b, double w, int t)
          This method defines a partition of an interval that acts as a default domain for the distribution, for purposes of data collection and for default computations.
protected  void setPGFDomain(Domain d)
          This method sets the moment generating function's domain of the distribution for purposes of data collection and for default computations.
protected  void setPGFDomain(double a, double b, double w)
          This method sets the PGF domain of the distribution for purposes of data collection and for default computations.
 void setPGFParameters()
          This method defines a partition of an interval that acts as a default domain for the probability generating function of the distribution, for purposes of data collection and for default computations.
 void setPGFParameters(double xlo, double xhi)
           
 void setPGFParameters(double xlo, double xhi, double max_slope)
           
 void setPGFParameters(double xlo, double xhi, double max_slope, double initial_guess)
           
 double simulate()
          This method computes a default simulation of a value from the distribution, as a random getQuantile.
 void update(java.util.Observable o, java.lang.Object arg)
           
 void valueChanged()
           
 void valueChanged(java.util.Observable o, java.lang.Object arg)
           
 
Methods inherited from class edu.ucla.stat.SOCR.core.SOCRValueSettable
createComponentSetter, createValueSetter, createValueSetter, createValueSetter, createValueSetter, getComponentSetter, getComponentSetters, getValueSetter, getValueSetters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DISCRETE

public static final int DISCRETE
See Also:
Constant Field Values

CONTINUOUS

public static final int CONTINUOUS
See Also:
Constant Field Values

MIXED

public static final int MIXED
See Also:
Constant Field Values

MAXMGFYVAL

public static final double MAXMGFYVAL
See Also:
Constant Field Values

MINMGFXVAL

public static final double MINMGFXVAL
See Also:
Constant Field Values

MAXMGFXVAL

public static final double MAXMGFXVAL
See Also:
Constant Field Values

applet

protected javax.swing.JApplet applet

name

protected java.lang.String name
Constructor Detail

Distribution

public Distribution()
Method Detail

getInstance

public static Distribution getInstance(java.lang.String classname)
                                throws java.lang.Exception
Throws:
java.lang.Exception

setApplet

public void setApplet(javax.swing.JApplet applet)
Specified by:
setApplet in interface Pluginable

getSOCRDistributions

public SOCRDistributions getSOCRDistributions()

getSOCRDistributionFunctors

public SOCRDistributionFunctors getSOCRDistributionFunctors()

addObserver

public void addObserver(java.util.Observer observer)

initialize

public void initialize()
used for some subclass to initialize before being used


update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

valueChanged

public void valueChanged()

valueChanged

public void valueChanged(java.util.Observable o,
                         java.lang.Object arg)

getName

public java.lang.String getName()
Specified by:
getName in interface Pluginable

getDensity

public abstract double getDensity(double x)
The getDensity method is abstract and must be overridden for any specific distribuiton


setParameters

public void setParameters(double a,
                          double b,
                          double w,
                          int t)
This method defines a partition of an interval that acts as a default domain for the distribution, for purposes of data collection and for default computations. For a discrete distribution, the specified parameters define the midpoints of the partition (these are typically the values on which the distribution is defined, although truncated if the true set of values is infinite). For a continuous distribution, the parameters define the boundary points of the interval on which the distribuiton is defined (truncated if the true interval is infinite)


setMGFParameters

public void setMGFParameters()
This method defines a partition of an interval that acts as a default domain for the moment generating function of the distribution, for purposes of data collection and for default computations. The parameters define the boundary points of the interval on which the moment generating function is defined (truncated if the true interval is infinite)


setMGFParameters

public void setMGFParameters(double xlo,
                             double xhi)

setMGFParameters

public void setMGFParameters(double xlo,
                             double xhi,
                             double max_slope)

setMGFParameters

public void setMGFParameters(double xlo,
                             double xhi,
                             double max_slope,
                             double initial_guess)

setPGFParameters

public void setPGFParameters()
This method defines a partition of an interval that acts as a default domain for the probability generating function of the distribution, for purposes of data collection and for default computations. The parameters define the boundary points of the interval on which the probability generating function is defined (truncated if the true interval is infinite)


setPGFParameters

public void setPGFParameters(double xlo,
                             double xhi)

setPGFParameters

public void setPGFParameters(double xlo,
                             double xhi,
                             double max_slope)

setPGFParameters

public void setPGFParameters(double xlo,
                             double xhi,
                             double max_slope,
                             double initial_guess)

setDomain

protected void setDomain(Domain d)
This method sets the domain of the distribution for purposes of data collection and for default computations. For a discrete distribution, the domain specifies the values on which the distribution is defined (although truncated if the true set of values is infinite). For a continuous distribution, domain defines the interval on which the distribuiton is defined (truncated if the true interval is infinite).

Parameters:
d - the domain

setMGFDomain

protected void setMGFDomain(Domain d)
This method sets the moment generating function's domain of the distribution for purposes of data collection and for default computations. For a discrete distribution, the domain specifies the values on which the distribution is defined (although truncated if the true set of values is infinite). For a continuous distribution, domain defines the interval on which the distribution is defined (truncated if the true interval is infinite).

Parameters:
d - the domain

setPGFDomain

protected void setPGFDomain(Domain d)
This method sets the moment generating function's domain of the distribution for purposes of data collection and for default computations. For a discrete distribution, the domain specifies the values on which the distribution is defined (although truncated if the true set of values is infinite). For a continuous distribution, domain defines the interval on which the distribution is defined (truncated if the true interval is infinite).

Parameters:
d - the domain

setDomain

protected void setDomain(double a,
                         double b,
                         double w,
                         int t)
This method sets the domain of the distribution for purposes of data collection and for default computations.

Parameters:
a - lower value or bound of the domain
b - the upper value or bound of the domain
w - the width (step size) of the domain
t - the type of domain (DISCRETE or CONTINUOUS)

setMGFDomain

protected void setMGFDomain(double a,
                            double b,
                            double w)
This method sets the MGF domain of the distribution for purposes of data collection and for default computations.

Parameters:
a - lower value or bound of the MGF domain
b - the upper value or bound of the MGF domain
w - the width (step size) of the MGF domain
t - the type of domain (DISCRETE or CONTINUOUS)

setPGFDomain

protected void setPGFDomain(double a,
                            double b,
                            double w)
This method sets the PGF domain of the distribution for purposes of data collection and for default computations.

Parameters:
a - lower value or bound of the MGF domain
b - the upper value or bound of the MGF domain
w - the width (step size) of the MGF domain
t - the type of domain (DISCRETE or CONTINUOUS)

getDomain

public Domain getDomain()
This method returns the domain of the distribution.


getMgfDomain

public Domain getMgfDomain()
This method returns the domain of the mgf for that particular distribution.


getPGFDomain

public Domain getPGFDomain()
This method returns the domain of the pgf for that particular distribution.


getType

public final int getType()
This method returns the type of the distribution (discrete or continuous)


paramEstimate

public void paramEstimate(double[] distData)

getMaxDensity

public double getMaxDensity()
This method returns the largest (finite) value of the getDensity function on the finite set of domain values. This method should be overridden if the maximum value is known in closed form


getMean

public double getMean()
This method returns a default approximate mean, based on the finite set of domain values. This method should be overriden if the mean is known in closed form


getMean

public double getMean(double[] distData)
This method returns the sample mean of a data series


getVariance

public double getVariance()
This method returns a default approximate variance. This method should be overriden if the variance is known in closed form


getVariance

public double getVariance(double[] distData)
This method returns the sample variance of a data series


getSampleMoment

public double getSampleMoment(int _power,
                              double[] distData)
This method returns the n-th sample moment of a data series


getSD

public double getSD()
This method returns the standard deviation, as the square root of the variance


getMGF

public double getMGF(double t)
              throws NoMGFException
This method returns an approximate moment generating function. This should be overriden if the MGF is known in closed form

Throws:
NoMGFException

getPGF

public double getPGF(double t)
This method should be overriden if the PGF is known in closed form


getCDF

public double getCDF(double x)
This method returns a default approximate cumulative distribution function. This should be overriden if the CDF is known in closed form


getQuantile

public double getQuantile(double p)
This method computes an approximate getQuantile function. This should be overriden if the getQuantile function is known in closed form


simulate

public double simulate()
This method computes a default simulation of a value from the distribution, as a random getQuantile. This method should be overridden if a better method of simulation is known.


sampleMean

public double sampleMean(double[] array)

sampleVar

public double sampleVar(double[] array,
                        double mean)

getOnlineDescription

public java.lang.String getOnlineDescription()
This method returns an online description of this distribution. This method should be overwritten for each specific distribution.


getLocalHelp

public java.lang.String getLocalHelp()
This method returns a general Distribution usage off-line help. This method should be common for all distributions.


getMedian

public double getMedian()
This method computes a default approximate median. This method should be overriden when there is a closed form expression for the median.


getFailureRate

public double getFailureRate(double x)
This method computes the failure rate function


perm

public static double perm(double n,
                          int k)
This method computes the number of permuatations of k objects chosen from a population of n objects.


factorial

public static double factorial(int k)
This method computes k!, the number of permutations of k objects.


comb

public static double comb(double n,
                          int k)
This method computes the number of combinations of k objects chosen from a population of n objects


logGamma

public static double logGamma(double x)
This method computes the log of the gamma function.


gamma

public static double gamma(double x)
This method computes the gamma function.


gammaCDF

public static double gammaCDF(double x,
                              double a)
This method computes the CDF of the gamma distribution with shape parameter a and scale parameter 1


betaCDF

public static double betaCDF(double x,
                             double a,
                             double b)
The method computes the beta CDF.


inverseCDF

public double inverseCDF(double probability)
Inverse of the cumulative distribution function (CDF) of the specified distribution.

Parameters:
probability - - a probability value in [0, 1]
Returns:
the value X for which P(X)==P(x < X) = probability.

findRoot

protected double findRoot(double prob,
                          double guess,
                          double xLo,
                          double xHi)
This method approximates the value of X for which P(x<X)=prob. It applies a combination of a Newton-Raphson procedure and bisection method with the value guess as a starting point. Furthermore, to ensure convergency and stability, one should supply an inverval [xLo,xHi] in which the probalility distribution reaches the value prob.


findGFRoot

protected double findGFRoot(int genFun,
                            double prob,
                            double guess,
                            double xLo,
                            double xHi)
This method approximates the value of X for which P(x<X)=prob. It applies a combination of a Newton-Raphson procedure and bisection method with the value guess as a starting point. Furthermore, to ensure convergency and stability, one should supply an inverval [xLo,xHi] in which the probalility distribution reaches the value prob.


getGFDerivative

protected double getGFDerivative(int genFun,
                                 double x)
This method approximates a derivative for a Generating Function using Newton's Quotient. f(x+h)-f(x)/h Parameters genFun if genFun == 0 use moment generating function if genFun == 1 use probabilty generating function


getGFSecondDerivative

protected double getGFSecondDerivative(int genFun,
                                       double x)
This method approximates the second derivative for a Generating Function using Newton's Quotient. f(x+h)-f(x)/h Parameters genFun if genFun == 0 use moment generating function if genFun == 1 use probabilty generating function


getDisplayPane

public java.awt.Container getDisplayPane()
Specified by:
getDisplayPane in interface Pluginable