@PublicationReference(author="Wikipedia", title="Algebra of random variables", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Algebra_of_random_variables") public class UnivariateRandomVariable extends AbstractRandomVariable<java.lang.Number> implements UnivariateDistribution<java.lang.Number>
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_NUM_SAMPLES
Default number of samples to draw from a distribution to perform the
empirical algebra approximation, 10000.
|
| Constructor and Description |
|---|
UnivariateRandomVariable(UnivariateDistribution<? extends java.lang.Number> distribution,
java.util.Random random)
Creates a new instance of UnivariateRandomVariable
|
UnivariateRandomVariable(UnivariateDistribution<? extends java.lang.Number> distribution,
java.util.Random random,
int numSamples)
Creates a new instance of UnivariateRandomVariable
|
| Modifier and Type | Method and Description |
|---|---|
UnivariateRandomVariable |
clone()
This makes public the clone method on the
Object class and
removes the exception that it throws. |
void |
dotTimesEquals(RandomVariable<java.lang.Number> other)
Inline element-wise multiplication of
this and
other |
boolean |
equals(java.lang.Object obj)
Determines if two RingType objects are equal
|
boolean |
equals(RandomVariable<java.lang.Number> other,
double effectiveZero)
Determines if two RingType objects are effectively equal
|
CumulativeDistributionFunction<java.lang.Number> |
getCDF()
Gets the CDF of a scalar distribution.
|
UnivariateDistribution<? extends java.lang.Number> |
getDistribution()
Getter for distribution
|
java.lang.Double |
getMaxSupport()
Gets the minimum support (domain or input) of the distribution.
|
java.lang.Number |
getMean()
Gets the arithmetic mean, or "first central moment" or "expectation",
of the distribution.
|
double |
getMeanAsDouble()
Gets the mean of the distribution as a double.
|
java.lang.Double |
getMinSupport()
Gets the minimum support (domain or input) of the distribution.
|
int |
getNumSamples()
Getter for numSamples
|
java.util.Random |
getRandom()
Gets the random number generator used by this object.
|
ConfidenceInterval |
getSamplingError(double confidence)
Gets the 95% confidence interval estimated sampling error associated
with this empirical random variable.
|
double |
getVariance()
Gets the variance of the distribution.
|
int |
hashCode()
Warning: The hashCode of this class is just the default hashCode,
but equality uses a statistical test to see if two random variables
are equal.
|
boolean |
isZero(double effectiveZero)
Determines if this ring is equal to zero using the element-wise effective
zero value.
|
void |
minusEquals(RandomVariable<java.lang.Number> other)
Inline arithmetic subtraction of
other from
this |
void |
plusEquals(RandomVariable<java.lang.Number> other)
Inline arithmetic addition of
this and other |
java.lang.Number |
sample(java.util.Random random)
Draws a single random sample from the distribution.
|
java.util.ArrayList<java.lang.Number> |
sample(java.util.Random random,
int numSamples)
Draws multiple random samples from the distribution.
|
void |
sampleInto(java.util.Random random,
int sampleCount,
java.util.Collection<? super java.lang.Number> output)
Draws multiple random samples from the distribution and puts the result
into the given collection.
|
void |
scaledPlusEquals(double scaleFactor,
RandomVariable<java.lang.Number> other)
Inline arithmetic addition of
this and other after
element-wise scaling of other by scaleFactor. |
void |
scaleEquals(double scaleFactor)
Inline element-wise scaling of
this by
scaleFactor |
void |
setDistribution(UnivariateDistribution<? extends java.lang.Number> distribution)
Setter for distribution
|
void |
setNumSamples(int numSamples)
Setter for numSamples
|
void |
setRandom(java.util.Random random)
Sets the random number generator used by this object.
|
dotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zerofinalize, getClass, notify, notifyAll, toString, wait, wait, waitdotTimes, isZero, minus, negative, negativeEquals, plus, scale, scaledMinus, scaledMinusEquals, scaledPlus, zeropublic static final int DEFAULT_NUM_SAMPLES
public UnivariateRandomVariable(UnivariateDistribution<? extends java.lang.Number> distribution, java.util.Random random)
distribution - Scalar distribution that backs the random variable, from which samples
will be drawn to approximate the distribution during algebra.random - Random number generator used to sample the distributionpublic UnivariateRandomVariable(UnivariateDistribution<? extends java.lang.Number> distribution, java.util.Random random, int numSamples)
distribution - Scalar distribution that backs the random variable, from which samples
will be drawn to approximate the distribution during algebra.random - Random number generator used to sample the distributionnumSamples - public UnivariateRandomVariable clone()
AbstractCloneableSerializableObject class and
removes the exception that it throws. Its default behavior is to
automatically create a clone of the exact type of object that the
clone is called on and to copy all primitives but to keep all references,
which means it is a shallow copy.
Extensions of this class may want to override this method (but call
super.clone() to implement a "smart copy". That is, to target
the most common use case for creating a copy of the object. Because of
the default behavior being a shallow copy, extending classes only need
to handle fields that need to have a deeper copy (or those that need to
be reset). Some of the methods in ObjectUtil may be helpful in
implementing a custom clone method.
Note: The contract of this method is that you must use
super.clone() as the basis for your implementation.clone in interface Ring<RandomVariable<java.lang.Number>>clone in interface CloneableSerializableclone in class AbstractRing<RandomVariable<java.lang.Number>>public boolean equals(java.lang.Object obj)
Ringequals in interface Ring<RandomVariable<java.lang.Number>>equals in class java.lang.Objectobj - RingType to compare against thispublic boolean equals(RandomVariable<java.lang.Number> other, double effectiveZero)
Ringequals in interface Ring<RandomVariable<java.lang.Number>>other - RingType to compare against thiseffectiveZero - tolerance threshold for element-wise equalitypublic int hashCode()
hashCode in class java.lang.Objectpublic void plusEquals(RandomVariable<java.lang.Number> other)
Ringthis and otherplusEquals in interface Ring<RandomVariable<java.lang.Number>>other - object to add to thispublic void minusEquals(RandomVariable<java.lang.Number> other)
Ringother from
thisminusEquals in interface Ring<RandomVariable<java.lang.Number>>other - object to subtract from thispublic void dotTimesEquals(RandomVariable<java.lang.Number> other)
Ringthis and
otherdotTimesEquals in interface Ring<RandomVariable<java.lang.Number>>other - elements of other will be multiplied to the corresponding
elements of thispublic void scaleEquals(double scaleFactor)
Ringthis by
scaleFactorscaleEquals in interface Ring<RandomVariable<java.lang.Number>>scaleFactor - amount to scale the elements of thispublic void scaledPlusEquals(double scaleFactor,
RandomVariable<java.lang.Number> other)
Ringthis and other after
element-wise scaling of other by scaleFactor.
If this is x, other is y, and scaleFactor is a, then this method is
equivalent to x += a * y. It is typically a more efficient way of doing
this.plusEquals(other.scale(scaleFactor)) since it can avoid
intermediate object creation.scaledPlusEquals in interface Ring<RandomVariable<java.lang.Number>>scaleFactor - The scale factor to multiply by the elements of other before
adding to the elements of this.other - Object to scale and then add to this.public boolean isZero(double effectiveZero)
RingisZero in interface Ring<RandomVariable<java.lang.Number>>effectiveZero - Tolerance threshold for element-wise equalitypublic java.lang.Number sample(java.util.Random random)
Distributionsample in interface Distribution<java.lang.Number>sample in class AbstractRandomVariable<java.lang.Number>random - Random-number generator to use in order to generate random numbers.public java.util.ArrayList<java.lang.Number> sample(java.util.Random random,
int numSamples)
Distributionsample in interface Distribution<java.lang.Number>random - Random-number generator to use in order to generate random numbers.numSamples - Number of samples to draw from the distribution.public void sampleInto(java.util.Random random,
int sampleCount,
java.util.Collection<? super java.lang.Number> output)
DistributionsampleInto in interface Distribution<java.lang.Number>random - Random number generator to use.sampleCount - The number of samples to draw. Cannot be negative.output - The collection to add the samples into.public int getNumSamples()
public void setNumSamples(int numSamples)
numSamples - Number of samples to draw from the distribution to perform the
empirical algebra approximation.public java.util.Random getRandom()
RandomizedgetRandom in interface Randomizedpublic void setRandom(java.util.Random random)
RandomizedsetRandom in interface Randomizedrandom - The random number generator for this object to use.public UnivariateDistribution<? extends java.lang.Number> getDistribution()
public void setDistribution(UnivariateDistribution<? extends java.lang.Number> distribution)
distribution - Scalar distribution that backs the random variable, from which samples
will be drawn to approximate the distribution during algebra.public java.lang.Number getMean()
DistributionWithMeangetMean in interface DistributionWithMean<java.lang.Number>public double getMeanAsDouble()
UnivariateDistributiongetMeanAsDouble in interface UnivariateDistribution<java.lang.Number>public double getVariance()
UnivariateDistributiongetVariance in interface UnivariateDistribution<java.lang.Number>public java.lang.Double getMinSupport()
UnivariateDistributiongetMinSupport in interface UnivariateDistribution<java.lang.Number>public java.lang.Double getMaxSupport()
UnivariateDistributiongetMaxSupport in interface UnivariateDistribution<java.lang.Number>@PublicationReference(author="Wikipedia", title="Standard error (statistics)", type=WebPage, year=2009, url="http://en.wikipedia.org/wiki/Standard_error_(statistics)") public ConfidenceInterval getSamplingError(double confidence)
confidence - Confidence required. If you want 95% confidence, which is the standard
in social science, then use 0.95.public CumulativeDistributionFunction<java.lang.Number> getCDF()
UnivariateDistributiongetCDF in interface UnivariateDistribution<java.lang.Number>