25package umontreal.ssj.probdist;
27import umontreal.ssj.functions.MathFunctionUtil;
28import umontreal.ssj.functions.MathFunction;
49 public static int NUMINTERVALS = 500;
58 private double approxMean;
59 private double approxVariance;
60 private double approxStandardDeviation;
71 if ((x < a) || (x > b))
73 return dist0.density(x) / fbfa;
76 public double cdf(
double x) {
82 return (dist0.cdf(x) - fa) / fbfa;
85 public double barF(
double x) {
91 return (dist0.barF(x) - barfb) / fbfa;
99 return dist0.inverseF(fa + fbfa * u);
110 if (Double.isNaN(approxMean))
111 throw new UnsupportedOperationException(
"Undefined mean");
123 if (Double.isNaN(approxVariance))
124 throw new UnsupportedOperationException(
"Unknown variance");
125 return approxVariance;
135 if (Double.isNaN(approxStandardDeviation))
136 throw new UnsupportedOperationException(
"Unknown standard deviation");
137 return approxStandardDeviation;
182 throw new IllegalArgumentException(
"a must be smaller than b.");
188 supportA = this.a = a;
189 supportB = this.b = b;
193 barfb = dist.
barF(b);
196 || ((a == Double.NEGATIVE_INFINITY) && (b == Double.POSITIVE_INFINITY))) {
203 MomentFunction func1 =
new MomentFunction(dist, 1);
207 MomentFunction func2 =
new MomentFunction(dist, 2, approxMean);
210 approxStandardDeviation = Math.sqrt(approxVariance);
220 double[] retour = { a, b, fa, fb, fbfa };
228 return getClass().getSimpleName() +
" : a = " + a +
", b = " + b +
", F(a) = " + fa +
", F(b) = " + fb
229 +
", F(b)-F(a) = " + fbfa;
232 private static class MomentFunction
implements MathFunction {
235 private double offset;
239 this.moment = moment;
243 public MomentFunction(ContinuousDistribution dist,
int moment,
double offset) {
245 this.offset = offset;
248 public double evaluate(
double x) {
250 final double offsetX = x - offset;
251 for (
int i = 0; i < moment; i++)
Provides utility methods for computing derivatives and integrals of functions.
static double simpsonIntegral(MathFunction func, double a, double b, int numIntervals)
Computes and returns an approximation of the integral of func over , using the Simpson’s method wit...
Classes implementing continuous distributions should inherit from this base class.
double getStandardDeviation()
Returns the standard deviation.
double getXinf()
Returns such that the probability density is 0 everywhere outside the interval .
double getMean()
Returns the mean.
double getXsup()
Returns such that the probability density is 0 everywhere outside the interval .
abstract double density(double x)
Returns , the density evaluated at .
double getVariance()
Returns the variance.
double barF(double x)
Returns the complementary distribution function.
double getStandardDeviation()
Returns the square root of the approximate variance.
double density(double x)
Returns , the density evaluated at .
double getB()
Returns the value of .
double barF(double x)
Returns the complementary distribution function.
String toString()
Returns a String containing information about the current distribution.
void setParams(ContinuousDistribution dist, double a, double b)
Sets the parameters dist, and for this object.
double getMean()
Returns an approximation of the mean computed with the Simpson.
TruncatedDist(ContinuousDistribution dist, double a, double b)
Constructs a new distribution by truncating distribution dist to the interval .
double getArea()
Returns the value of , the area under the truncated density function.
double getVariance()
Returns an approximation of the variance computed with the Simpson.
double inverseF(double u)
Returns the inverse distribution function .
double[] getParams()
Return a table containing the parameters of the current distribution.
double getFa()
Returns the value of .
double cdf(double x)
Returns the distribution function .
double getA()
Returns the value of .
double getFb()
Returns the value of .
This interface should be implemented by classes which represent univariate mathematical functions.
double cdf(double x)
Returns the distribution function .