public class CauchyDistribution : ContinuousDistribution
{
private double scale;
public override double Mean => double.NaN;
public override double Variance => double.PositiveInfinity;
public override double Skewness => double.NaN;
public override double Kurtosis => double.NaN;
public double ScaleParameter => this.scale;
private void Initialize(double scale)
{
this.scale = scale;
}
public static double GetRandomVariate(System.Random random, double scale)
{
if (random == null)
{
ThrowException.ArgumentNull("random");
}
if (scale <= 0.0)
{
ThrowException.ArgumentOutOfRange("scale");
}
return new CauchyDistribution(scale).GetRandomVariate(random);
}
public CauchyDistribution(double scale)
{
if (scale <= 0.0)
{
ThrowException.ArgumentOutOfRange("scale");
}
this.Initialize(scale);
}
public override double DistributionFunction(double x)
{
return Math.Atan(x / this.scale) / Math.PI + 0.5;
}
public override double ProbabilityDensityFunction(double x)
{
x /= this.scale;
return 1.0 / (this.scale * Math.PI) / (1.0 + x * x);
}
public override double MomentFunction(int order, double x)
{
if (order < 0)
{
ThrowException.ArgumentOutOfRange("order");
}
if (order == 0)
{
return this.DistributionFunction(x) - this.DistributionFunction(0.0);
}
return double.NaN;
}
public override double InverseDistributionFunction(double probability)
{
if (probability < 0.0 || probability > 1.0)
{
ThrowException.ArgumentOutOfRange("probability");
}
if (probability == 0.0)
{
return double.NegativeInfinity;
}
if (probability == 1.0)
{
return double.PositiveInfinity;
}
return this.scale * Math.Tan(Math.PI * (probability - 0.5));
}
public override double GetRandomVariate(System.Random random)
{
if (random == null)
{
ThrowException.ArgumentNull("random");
}
double num;
do
{
num = random.NextDouble();
}
while (num == 0.5);
return this.scale * Math.Tan(Math.PI * num);
}
}
如果对您有帮忙,非常感谢您支持一下创造者的付出!
感谢支持技术分享,请扫码点赞支持:
技术合作交流qq:2401315930