本文整理汇总了C#中MathNet.Numerics.Distributions.Normal.CumulativeDistribution方法的典型用法代码示例。如果您正苦于以下问题:C# Normal.CumulativeDistribution方法的具体用法?C# Normal.CumulativeDistribution怎么用?C# Normal.CumulativeDistribution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.Distributions.Normal
的用法示例。
在下文中一共展示了Normal.CumulativeDistribution方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Nu
private static double Nu(double x, double tol)
{
double nu;
double lnu0, lnu1, dk, xk;
int i, k;
// fpnorm(x): pnorm(x, 0, 1, lower.tail=TRUE, log.p=FALSE)
// calculates P(X <= x)
var norm = new Normal(); // N(0, 1)
if (x > 0.01)
{
lnu1 = Math.Log(2.0) - 2 * Math.Log(x);
lnu0 = lnu1;
k = 2;
dk = 0;
for (i = 0; i < k; i++)
{
dk = dk + 1;
xk = -x * Math.Sqrt(dk) / 2.0;
lnu1 = lnu1 - 2.0 * norm.CumulativeDistribution(xk) / dk;
}
while (Math.Abs((lnu1 - lnu0) / lnu1) > tol)
{
lnu0 = lnu1;
for (i = 0; i < k; i++)
{
dk = dk + 1;
xk = -x * Math.Sqrt(dk) / 2.0;
lnu1 = lnu1 - 2.0 * norm.CumulativeDistribution(xk) / dk;
}
k *= 2;
}
}
else
{
lnu1 = -0.583 * x;
}
nu = Math.Exp(lnu1);
return nu;
}
示例2: Run
/// <summary>
/// Run example
/// </summary>
/// <a href="http://en.wikipedia.org/wiki/Normal_distribution">Normal distribution</a>
public void Run()
{
// 1. Initialize the new instance of the Normal distribution class with parameters Mean = 0, StdDev = 1
var normal = new Normal(0, 1);
Console.WriteLine(@"1. Initialize the new instance of the Normal distribution class with parameters Mean = {0}, StdDev = {1}", normal.Mean, normal.StdDev);
Console.WriteLine();
// 2. Distributuion properties:
Console.WriteLine(@"2. {0} distributuion properties:", normal);
// Cumulative distribution function
Console.WriteLine(@"{0} - Сumulative distribution at location '0.3'", normal.CumulativeDistribution(0.3).ToString(" #0.00000;-#0.00000"));
// Probability density
Console.WriteLine(@"{0} - Probability density at location '0.3'", normal.Density(0.3).ToString(" #0.00000;-#0.00000"));
// Log probability density
Console.WriteLine(@"{0} - Log probability density at location '0.3'", normal.DensityLn(0.3).ToString(" #0.00000;-#0.00000"));
// Entropy
Console.WriteLine(@"{0} - Entropy", normal.Entropy.ToString(" #0.00000;-#0.00000"));
// Largest element in the domain
Console.WriteLine(@"{0} - Largest element in the domain", normal.Maximum.ToString(" #0.00000;-#0.00000"));
// Smallest element in the domain
Console.WriteLine(@"{0} - Smallest element in the domain", normal.Minimum.ToString(" #0.00000;-#0.00000"));
// Mean
Console.WriteLine(@"{0} - Mean", normal.Mean.ToString(" #0.00000;-#0.00000"));
// Median
Console.WriteLine(@"{0} - Median", normal.Median.ToString(" #0.00000;-#0.00000"));
// Mode
Console.WriteLine(@"{0} - Mode", normal.Mode.ToString(" #0.00000;-#0.00000"));
// Variance
Console.WriteLine(@"{0} - Variance", normal.Variance.ToString(" #0.00000;-#0.00000"));
// Standard deviation
Console.WriteLine(@"{0} - Standard deviation", normal.StdDev.ToString(" #0.00000;-#0.00000"));
// Skewness
Console.WriteLine(@"{0} - Skewness", normal.Skewness.ToString(" #0.00000;-#0.00000"));
Console.WriteLine();
// 3. Generate 10 samples
Console.WriteLine(@"3. Generate 10 samples");
for (var i = 0; i < 10; i++)
{
Console.Write(normal.Sample().ToString("N05") + @" ");
}
Console.WriteLine();
Console.WriteLine();
// 4. Generate 100000 samples of the Normal(0, 1) distribution and display histogram
Console.WriteLine(@"4. Generate 100000 samples of the Normal(0, 1) distribution and display histogram");
var data = new double[100000];
for (var i = 0; i < data.Length; i++)
{
data[i] = normal.Sample();
}
ConsoleHelper.DisplayHistogram(data);
Console.WriteLine();
// 5. Generate 100000 samples of the Normal(-10, 0.2) distribution and display histogram
Console.WriteLine(@"5. Generate 100000 samples of the Normal(-10, 0.01) distribution and display histogram");
normal.Mean = -10;
normal.StdDev = 0.01;
for (var i = 0; i < data.Length; i++)
{
data[i] = normal.Sample();
}
ConsoleHelper.DisplayHistogram(data);
}
示例3: createNormalPlotModel
public PlotModel createNormalPlotModel(VariableDesc oCategVar, VariableDesc oVar)
{
if (oVar == null)
{
return null;
}
var srcData = ComputeVariableCategValues(oCategVar, oVar);
if (srcData == null)
{
return null;
}
List<ValueDesc> sortedData = new List<ValueDesc>();
List<double> oList = new List<double>();
Dictionary<String, ScatterSeries> oDict = new Dictionary<string, ScatterSeries>();
foreach (var s in srcData.Keys)
{
oDict[s] = new ScatterSeries(s) { MarkerType = MarkerType.Circle };
var vals = srcData[s];
foreach (var v in vals)
{
v.StringTag = s;
sortedData.Add(v);
oList.Add(v.DoubleValue);
}
}// s
sortedData.Sort((v1, v2) =>
{
double d1 = v1.DoubleValue;
double d2 = v2.DoubleValue;
int nRet = -1;
if (d1 > d2)
{
nRet = 1;
}
else if (d1 == d2)
{
nRet = 0;
}
return nRet;
});
int n = sortedData.Count;
if (n < 2)
{
return null;
}
DescriptiveStatistics st = new DescriptiveStatistics(oList);
double mean = st.Mean;
double dev = st.StandardDeviation;
if (dev <= 0.0)
{
return null;
}
var dist = new Normal();
var s2 = new LineSeries { Title = "Distribution normale" };
int nTotal = 1;
int i = 0;
double dn = (double)n;
var oAr = sortedData.ToArray();
ValueDesc vCur = null;
while (i < n)
{
vCur = oAr[i];
double xMax = vCur.DoubleValue;
int c = 0;
while ((vCur.DoubleValue <= xMax) && (i < n))
{
double x = vCur.DoubleValue;
double xr = (x - mean) / dev;
double yr = dist.CumulativeDistribution(xr);
s2.Points.Add(new DataPoint(x, yr));
double yc = (double)nTotal / dn;
vCur.DoubleTag = yc;
String scateg = vCur.StringTag;
if ((!String.IsNullOrEmpty(scateg)) && oDict.ContainsKey(scateg))
{
oDict[scateg].Points.Add(new ScatterPoint(x, yc) { Tag = vCur.Index });
}
++i;
++c;
if (i >= n)
{
break;
}
vCur = oAr[i];
}
nTotal += c;
}// i
PlotModel model = new PlotModel(oVar.Name);
foreach (var ss in oDict.Values)
{
model.Series.Add(ss);
}
s2.Smooth = true;
model.Series.Add(s2);
return model;
}
示例4: GetGaussianPixel
/// <summary>
/// Returns a gaussian weighted average of pixels centred on a point
/// </summary>
/// <param name="Source"></param>
/// <param name="Coords"></param>
/// <param name="Radius"></param>
/// <returns></returns>
public static Color GetGaussianPixel(Bitmap Source, ProportionPoint Coords, int Radius)
{
if ((Radius > MaxGausRadius) || (Radius < 0)) throw new ArgumentOutOfRangeException("Radius", "Radius must be >= 0 and < MaxGausRadius");
int diameter = 1 + (2 * Radius);
int centre = Radius + 1;
double sigma = (double)Radius / 2d;
Normal dist = new Normal(Radius, sigma);
// create new bitmap with known PixelFormat
Bitmap bm = new Bitmap(Source.Width, Source.Height, PixelFormat.Format24bppRgb);
using (Graphics gr = Graphics.FromImage(bm))
{
gr.DrawImage(Source, new Rectangle(0, 0, bm.Width, bm.Height));
}
//Source.Dispose();
// Now we know there are 24 bits per pixel. 24 / 8 (bits / byte) = 3 bytes
const int BytesPerPixel = 3;
Color colourPixel;
int x, y;
x = (int)Math.Round((double)(Coords.x * (float)bm.Width));
if (x >= bm.Width) x = bm.Width - 1;
y = (int)Math.Round((double)(Coords.y * (float)bm.Height));
if (y >= bm.Height) y = bm.Height - 1;
int stride;
byte[] rgbValues = GetBytesFromImage(bm, out stride);
bm.Dispose();
int centrePixel = (Math.Abs(stride) * y) + (x * BytesPerPixel);
if (Radius == 0)
{
// get the RGB data from the byte array
colourPixel = Color.FromArgb(0, rgbValues[centrePixel], rgbValues[centrePixel + 1], rgbValues[centrePixel + 2]);
}
else
{
// work out where the origin of our sub-region will be
int TLcorner = centrePixel - (BytesPerPixel * (Radius + (Radius * stride)));
double weightCumulative = 0;
double[] rgbCumulative = new double[3] { 0d, 0d, 0d };
for (int row = 0; row < diameter; row++)
{
for (int col = 0; col < diameter; col++)
{
// find the start of this pixel
int pixelStart = TLcorner + (BytesPerPixel * (col + (row * stride)));
int centrePixelStart = pixelStart - (col - Radius);
int line = (int)Math.Floor((double)centrePixelStart / (double)stride);
// check pixel lies within bound of image
if ((pixelStart >= 0) && (pixelStart < rgbValues.Length))
{
// check pixel hasn't wrapped to different line
int lineOfThisPixel = (int)Math.Floor((double)pixelStart / (double)stride);
if (line == lineOfThisPixel)
{
// work out the distance from the centre of the sub-region
int relX = Math.Abs((col + 1) - centre);
int relY = Math.Abs((row + 1) - centre);
double hyp = Math.Sqrt((double)(Math.Pow(relX, 2)) + (Math.Pow(relY, 2)));
// get a gaussian weight for this distance
double weight = dist.CumulativeDistribution(Radius - hyp);
weightCumulative += weight;
// add the weighted RGB values to the array
for (int p = 0; p < 3; p++)
{
rgbCumulative[p] += rgbValues[pixelStart + p] * weight;
}
}
}
}
}
// compose the resulting color pixel
byte[] rgbFinal = new byte[3];
for (int p = 0; p < 3; p++)
{
int final = (int)Math.Round(rgbCumulative[p] / weightCumulative);
if (final > 255) final = 255;
rgbFinal[p] = (byte)(final & 0xff);
}
return Color.FromArgb(0, rgbFinal[0], rgbFinal[1], rgbFinal[2]);
}
return colourPixel;
//.........这里部分代码省略.........