Accord.Statistics.Distributions.Univariate.TrapezoidalDistribution.TrapezoidalDistribution C# (CSharp) Method

TrapezoidalDistribution() public method

Creates a new trapezoidal distribution.
public TrapezoidalDistribution ( [ a, [ b, [ c, [ d, [ n1, [ n3 ) : System
a [ The minimum value a.
b [ The beginning of the stability region b.
c [ The end of the stability region c.
d [ The maximum value d.
n1 [ The growth slope between points and .
n3 [ The growth slope between points and .
return System
        public TrapezoidalDistribution(
            [Real, DefaultValue(0)] double a, [Real, DefaultValue(1)] double b,
            [Real, DefaultValue(2)] double c, [Real, DefaultValue(3)] double d, 
            [Positive] double n1, [Positive] double n3)
        {
            // boundary validation
            if (a > b)
                throw new ArgumentOutOfRangeException("b", "Argument b must be higher than a.");

            if (b > c)
                throw new ArgumentOutOfRangeException("c", "Argument c must be higher than b.");

            if (d < c)
                throw new ArgumentOutOfRangeException("d", "Argument d must be higher than c.");

            if (d <= a)
                throw new ArgumentOutOfRangeException("d", "The maximum value d must be higher than the minimum value a");

            if (n1 <= 0)
                throw new ArgumentOutOfRangeException("n1", "Slope n1 must be positive.");

            if (n3 <= 0)
                throw new ArgumentOutOfRangeException("n3", "Slope n3 must be positive.");

            this.a = a;
            this.b = b;
            this.c = c;
            this.d = d;
            this.n1 = n1;
            this.n3 = n3;

            double num = 2 * n1 * n3;
            double den = 2 * alpha * (b - a) * n3
                + (alpha + 1) * (c - b) * n1 * n3
                + 2 * (d - c) * n1;

            this.constant = num / den;
        }