本文整理汇总了C#中NormalDistribution.DistributionFunction方法的典型用法代码示例。如果您正苦于以下问题:C# NormalDistribution.DistributionFunction方法的具体用法?C# NormalDistribution.DistributionFunction怎么用?C# NormalDistribution.DistributionFunction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NormalDistribution
的用法示例。
在下文中一共展示了NormalDistribution.DistributionFunction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConstructorTest5
public void ConstructorTest5()
{
var normal = new NormalDistribution(mean: 4, stdDev: 4.2);
double mean = normal.Mean; // 4.0
double median = normal.Median; // 4.0
double mode = normal.Mode; // 4.0
double var = normal.Variance; // 17.64
double cdf = normal.DistributionFunction(x: 1.4); // 0.26794249453351904
double pdf = normal.ProbabilityDensityFunction(x: 1.4); // 0.078423391448155175
double lpdf = normal.LogProbabilityDensityFunction(x: 1.4); // -2.5456330358182586
double ccdf = normal.ComplementaryDistributionFunction(x: 1.4); // 0.732057505466481
double icdf = normal.InverseDistributionFunction(p: cdf); // 1.4
double hf = normal.HazardFunction(x: 1.4); // 0.10712736480747137
double chf = normal.CumulativeHazardFunction(x: 1.4); // 0.31189620872601354
string str = normal.ToString(CultureInfo.InvariantCulture); // N(x; μ = 4, σ² = 17.64)
Assert.AreEqual(4.0, mean);
Assert.AreEqual(4.0, median);
Assert.AreEqual(4.0, mode);
Assert.AreEqual(17.64, var);
Assert.AreEqual(0.31189620872601354, chf);
Assert.AreEqual(0.26794249453351904, cdf);
Assert.AreEqual(0.078423391448155175, pdf);
Assert.AreEqual(-2.5456330358182586, lpdf);
Assert.AreEqual(0.10712736480747137, hf);
Assert.AreEqual(0.732057505466481, ccdf);
Assert.AreEqual(1.4, icdf);
Assert.AreEqual("N(x; μ = 4, σ² = 17.64)", str);
Assert.AreEqual(Accord.Math.Normal.Function(normal.ZScore(4.2)), normal.DistributionFunction(4.2));
Assert.AreEqual(Accord.Math.Normal.Derivative(normal.ZScore(4.2)) / normal.StandardDeviation, normal.ProbabilityDensityFunction(4.2), 1e-16);
Assert.AreEqual(Accord.Math.Normal.LogDerivative(normal.ZScore(4.2)) - Math.Log(normal.StandardDeviation), normal.LogProbabilityDensityFunction(4.2), 1e-15);
var range1 = normal.GetRange(0.95);
var range2 = normal.GetRange(0.99);
var range3 = normal.GetRange(0.01);
Assert.AreEqual(-2.9083852331961833, range1.Min);
Assert.AreEqual(10.908385233196183, range1.Max);
Assert.AreEqual(-5.7706610709715314, range2.Min);
Assert.AreEqual(13.770661070971531, range2.Max);
Assert.AreEqual(-5.7706610709715314, range3.Min);
Assert.AreEqual(13.770661070971531, range3.Max);
}
示例2: ConstructorTest5
public void ConstructorTest5()
{
var normal = new NormalDistribution(mean: 4, stdDev: 4.2);
double mean = normal.Mean; // 4.0
double median = normal.Median; // 4.0
double var = normal.Variance; // 17.64
double cdf = normal.DistributionFunction(x: 1.4); // 0.26794249453351904
double pdf = normal.ProbabilityDensityFunction(x: 1.4); // 0.078423391448155175
double lpdf = normal.LogProbabilityDensityFunction(x: 1.4); // -2.5456330358182586
double ccdf = normal.ComplementaryDistributionFunction(x: 1.4); // 0.732057505466481
double icdf = normal.InverseDistributionFunction(p: cdf); // 1.4
double hf = normal.HazardFunction(x: 1.4); // 0.10712736480747137
double chf = normal.CumulativeHazardFunction(x: 1.4); // 0.31189620872601354
string str = normal.ToString(CultureInfo.InvariantCulture); // N(x; μ = 4, σ² = 17.64)
Assert.AreEqual(4.0, mean);
Assert.AreEqual(4.0, median);
Assert.AreEqual(17.64, var);
Assert.AreEqual(0.31189620872601354, chf);
Assert.AreEqual(0.26794249453351904, cdf);
Assert.AreEqual(0.078423391448155175, pdf);
Assert.AreEqual(-2.5456330358182586, lpdf);
Assert.AreEqual(0.10712736480747137, hf);
Assert.AreEqual(0.732057505466481, ccdf);
Assert.AreEqual(1.4, icdf);
Assert.AreEqual("N(x; μ = 4, σ² = 17.64)", str);
}
示例3: ConstructorTest1
public void ConstructorTest1()
{
NormalDistribution normal = new NormalDistribution(4.2, 1.2);
MultivariateNormalDistribution target = new MultivariateNormalDistribution(new[] { 4.2 }, new[,] { { 1.2 * 1.2 } });
double[] mean = target.Mean;
double[] median = target.Median;
double[] var = target.Variance;
double[,] cov = target.Covariance;
double apdf1 = target.ProbabilityDensityFunction(new double[] { 2 });
double apdf2 = target.ProbabilityDensityFunction(new double[] { 4 });
double apdf3 = target.ProbabilityDensityFunction(new double[] { 3 });
double alpdf = target.LogProbabilityDensityFunction(new double[] { 3 });
double acdf = target.DistributionFunction(new double[] { 3 });
double accdf = target.ComplementaryDistributionFunction(new double[] { 3 });
double epdf1 = normal.ProbabilityDensityFunction(2);
double epdf2 = normal.ProbabilityDensityFunction(4);
double epdf3 = normal.ProbabilityDensityFunction(3);
double elpdf = normal.LogProbabilityDensityFunction(3);
double ecdf = normal.DistributionFunction(3);
double eccdf = normal.ComplementaryDistributionFunction(3);
Assert.AreEqual(normal.Mean, target.Mean[0]);
Assert.AreEqual(normal.Median, target.Median[0]);
Assert.AreEqual(normal.Variance, target.Variance[0]);
Assert.AreEqual(normal.Variance, target.Covariance[0, 0]);
Assert.AreEqual(epdf1, apdf1);
Assert.AreEqual(epdf2, apdf2);
Assert.AreEqual(epdf3, apdf3);
Assert.AreEqual(elpdf, alpdf);
Assert.AreEqual(ecdf, acdf);
Assert.AreEqual(eccdf, accdf);
Assert.AreEqual(1.0 - ecdf, eccdf);
}
示例4: DistributionFunctionTest3
public void DistributionFunctionTest3()
{
double expected, actual;
// Test small variance
NormalDistribution target = new NormalDistribution(1.0, double.Epsilon);
expected = 0;
actual = target.DistributionFunction(0);
Assert.AreEqual(expected, actual);
expected = 0.5;
actual = target.DistributionFunction(1.0);
Assert.AreEqual(expected, actual);
expected = 1.0;
actual = target.DistributionFunction(1.0 + 1e-15);
Assert.AreEqual(expected, actual);
expected = 0.0;
actual = target.DistributionFunction(1.0 - 1e-15);
Assert.AreEqual(expected, actual);
}
示例5: DistributionFunctionTest
public void DistributionFunctionTest()
{
double x = 3;
double mean = 7;
double dev = 5;
NormalDistribution target = new NormalDistribution(mean, dev);
double expected = 0.211855398583397;
double actual = target.DistributionFunction(x);
Assert.IsFalse(double.IsNaN(actual));
Assert.AreEqual(expected, actual, 1e-15);
}
示例6: ConstructorTest3
public void ConstructorTest3()
{
Accord.Math.Tools.SetupGenerator(0);
// Create a normal distribution with mean 2 and sigma 3
var normal = new NormalDistribution(mean: 2, stdDev: 3);
// In a normal distribution, the median and
// the mode coincide with the mean, so
double mean = normal.Mean; // 2
double mode = normal.Mode; // 2
double median = normal.Median; // 2
// The variance is the square of the standard deviation
double variance = normal.Variance; // 3² = 9
// Let's check what is the cumulative probability of
// a value less than 3 occurring in this distribution:
double cdf = normal.DistributionFunction(3); // 0.63055
// Finally, let's generate 1000 samples from this distribution
// and check if they have the specified mean and standard dev.
double[] samples = normal.Generate(1000);
double sampleMean = samples.Mean(); // 1.92
double sampleDev = samples.StandardDeviation(); // 3.00
Assert.AreEqual(2, mean);
Assert.AreEqual(2, mode);
Assert.AreEqual(2, median);
Assert.AreEqual(9, variance);
Assert.AreEqual(1000, samples.Length);
Assert.AreEqual(1.9245, sampleMean, 1e-4);
Assert.AreEqual(3.0008, sampleDev, 1e-4);
}
示例7: DistributionFunctionTest1
public void DistributionFunctionTest1()
{
var target = GeneralizedNormalDistribution.Normal(mean: 0.42, stdDev: 4.2);
var normal = new NormalDistribution(mean: 0.42, stdDev: 4.2);
for (double x = -10; x < 10; x += 0.0001)
{
double actual = target.DistributionFunction(x);
double expected = normal.DistributionFunction(x);
Assert.AreEqual(expected, actual, 1e-10);
Assert.IsFalse(Double.IsNaN(actual));
}
}
示例8: CumulativeFunctionTest
public void CumulativeFunctionTest()
{
var p1 = new NormalDistribution(4.2, 1);
var p2 = new NormalDistribution(7.0, 2);
Independent<NormalDistribution> target = new Independent<NormalDistribution>(p1, p2);
double[] x;
double actual, expected;
x = new double[] { 4.2, 7.0 };
actual = target.DistributionFunction(x);
expected = p1.DistributionFunction(x[0]) * p2.DistributionFunction(x[1]);
Assert.AreEqual(expected, actual);
x = new double[] { 0.0, 0.0 };
actual = target.DistributionFunction(x);
expected = p1.DistributionFunction(x[0]) * p2.DistributionFunction(x[1]);
Assert.AreEqual(expected, actual);
x = new double[] { 7.0, 4.2 };
actual = target.DistributionFunction(x);
expected = p1.DistributionFunction(x[0]) * p2.DistributionFunction(x[1]);
Assert.AreEqual(expected, actual);
}
示例9: CumulativeFunctionTest2
public void CumulativeFunctionTest2()
{
double[] mean = { 4.2 };
double[,] covariance = { { 1.4 } };
var baseline = new NormalDistribution(4.2, System.Math.Sqrt(covariance[0, 0]));
var target = new MultivariateNormalDistribution(mean, covariance);
for (int i = 0; i < 10; i++)
{
double x = (i - 2) / 10.0;
{
double actual = target.ProbabilityDensityFunction(x);
double expected = baseline.ProbabilityDensityFunction(x);
Assert.AreEqual(expected, actual, 1e-10);
}
{
double actual = target.DistributionFunction(x);
double expected = baseline.DistributionFunction(x);
Assert.AreEqual(expected, actual);
}
{
double actual = target.ComplementaryDistributionFunction(x);
double expected = baseline.ComplementaryDistributionFunction(x);
Assert.AreEqual(expected, actual);
}
}
}