Skip to content

Chi Squared strange behavior around x=0 #379

Open
@verybadcat

Description

@verybadcat

I am uncomfortable with the output of the following test. It feels weird that the output is 0 specifically for an input of 0, but not for a negative input. The y2 value should be zero IMO. But certainly it should not be the case that y2=0 and y1 is nonzero.

[Test()]
public void TestMathNetChiSquared() {
  MathNet.Numerics.Distributions.ChiSquared chiSquared = new MathNet.Numerics.Distributions.ChiSquared(2);
  double y1 = chiSquared.Density(-0.01);
  double y2 = chiSquared.Density(0.0);
  double y3 = chiSquared.Density(0.01);
  double y3Error = Math.Abs(y3 - 0.5);
  Assert.Less(y3Error, 0.01); // passes, which is correct behavior from MathNet
  MyCustomLogMethod("y1=", y1, "y2=", y2, "y3=", y3); // prints: y1= 0.502506260429701 y2= 0 y3= 0.497506239596341. 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions