0

I have been experiencing an Exception error (surprisingly) while performing some parallel statistical tests with Math.Net Numerics, and I'd like to know the rationale.

using MathNet.Numerics.Distributions;
....
var stable = new Stable(1.7, -0.7, 0.0087, 0.9103);
        double b = stable.Density(3.2);
        double a = stable.Density(5.1);
        Console.WriteLine(b);
        Console.WriteLine(a);

Error: An unhandled exception of type System.NotSupportedException occured in MathNet.Numerics.dll

I was expecting to get b = 2.2484e-06, a = 4.3977e-07.

Ps: Other classical distributions such as Gamma work without problem (e.g Probability Distributions ), ruling out de facto any installation problem with the package

Best,

EDIT: From Github repository I've added Stable.cs in my project that includes all the properties and methods.

Factually, the properties are working fine. See below illustration from Program.cs:

   Stable st = new Stable(1.7, -0.7, 0.0087, 0.9103); // correct instantiation

   Console.WriteLine(string.Format(" Characteristic exponent: {0}\n 
   Skewness: {1}\n Scale: {2}\n Location: {3}" ,st.Alpha, st.Beta,  
   st.Scale,st.Location));

However there is nothing illogical, as far as I am concerned, in calling the Density method based on the object: st.Density(3.2) which is supposed to return:

PDF(_alpha, _beta, _scale, _location, x); 

Thus it's tempting to conclude a method definition problem, unless people object this opinion with valid illustration.

Moreover, on special values of the stable parameters (e.g _alpha = 2.0, etc.) the defined PDF is returning 0 (weird)

dark.vador
  • 619
  • 1
  • 6
  • 25

1 Answers1

0

The answer sits in the Math.NET GitHub repository.

Your example is not fulfilling the Density formula conditions.

public double Density(double x)
{
    return PDF(_alpha, _beta, _scale, _location, x);
}

/// <summary>
/// Computes the probability density of the distribution (PDF) at x, i.e. ∂P(X ≤ x)/∂x.
/// </summary>
/// <param name="alpha">The stability (α) of the distribution. Range: 2 ≥ α > 0.</param>
/// <param name="beta">The skewness (β) of the distribution. Range: 1 ≥ β ≥ -1.</param>
/// <param name="scale">The scale (c) of the distribution. Range: c > 0.</param>
/// <param name="location">The location (μ) of the distribution.</param>
/// <param name="x">The location at which to compute the density.</param>
/// <returns>the density at <paramref name="x"/>.</returns>
/// <seealso cref="Density"/>
public static double PDF(double alpha, double beta, double scale, double location, double x)
{
    if (alpha <= 0.0 || alpha > 2.0 || beta < -1.0 || beta > 1.0 || scale <= 0.0)
    {
        throw new ArgumentException(Resources.InvalidDistributionParameters);
    }

    if (alpha == 2d)
    {
        return Normal.PDF(location, Constants.Sqrt2*scale, x);
    }

    if (alpha == 1d && beta == 0d)
    {
        return Cauchy.PDF(location, scale, x);
    }

    if (alpha == 0.5d && beta == 1d && x >= location)
    {
        return (Math.Sqrt(scale/Constants.Pi2)*Math.Exp(-scale/(2*(x - location))))/Math.Pow(x - location, 1.5);
    }

    throw new NotSupportedException();
}
Piotr Leniartek
  • 1,177
  • 2
  • 14
  • 33