本文整理汇总了C#中MathNet.Numerics.Distributions.Normal类的典型用法代码示例。如果您正苦于以下问题:C# Normal类的具体用法?C# Normal怎么用?C# Normal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Normal类属于MathNet.Numerics.Distributions命名空间,在下文中一共展示了Normal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NullRandomNumberGenerator
public void NullRandomNumberGenerator()
{
var random = MersenneTwister.Default;
var normal = new Normal(0.0, 1.0, random);
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(random, x, 0.1), 10);
Assert.That(() => ms.RandomSource = null, Throws.TypeOf<ArgumentNullException>());
}
示例2: TestRidge
public void TestRidge()
{
var rng = new Random(0);
const double alpha = 1.0;
foreach (var solver in new[] { RidgeSolver.Svd, RidgeSolver.DenseCholesky, RidgeSolver.Lsqr })
{
// With more samples than features
int nSamples = 6;
int nFeatures = 5;
var normal = new Normal { RandomSource = rng };
Vector y = DenseVector.CreateRandom(nSamples, normal);
Matrix x = DenseMatrix.CreateRandom(nSamples, nFeatures, normal);
var ridge = new RidgeRegression(alpha: alpha, solver: solver);
ridge.Fit(x, y);
Assert.AreEqual(ridge.Coef.Row(0).Count, x.ColumnCount);
Assert.IsTrue(ridge.Score(x, y) > 0.47);
ridge.Fit(x, y, sampleWeight: DenseVector.Create(nSamples, i => 1.0));
Assert.IsTrue(ridge.Score(x, y) > 0.47);
// With more features than samples
nSamples = 5;
nFeatures = 10;
y = DenseVector.CreateRandom(nSamples, normal);
x = DenseMatrix.CreateRandom(nSamples, nFeatures, normal);
ridge = new RidgeRegression(alpha: alpha, solver: solver);
ridge.Fit(x, y);
Assert.IsTrue(ridge.Score(x, y) > 0.9);
ridge.Fit(x, y, sampleWeight: DenseVector.Create(nSamples, i => 1.0));
Assert.IsTrue(ridge.Score(x, y) > 0.9);
}
}
示例3: RowInitNormal
/// <summary>Initializes one row of a float matrix with normal distributed (Gaussian) noise</summary>
/// <param name="matrix">the matrix to initialize</param>
/// <param name="row">the row to be initialized</param>
/// <param name="mean">the mean of the normal distribution drawn from</param>
/// <param name="stddev">the standard deviation of the normal distribution</param>
static public void RowInitNormal(this Matrix<float> matrix, int row, double mean, double stddev)
{
var nd = new Normal(mean, stddev);
nd.RandomSource = MyMediaLite.Random.GetInstance();
for (int j = 0; j < matrix.dim2; j++)
matrix[row, j] = (float) nd.Sample();
}
示例4: InitNormal
/// <summary>Initializes a float matrix with normal distributed (Gaussian) noise</summary>
/// <param name="matrix">the matrix to initialize</param>
/// <param name="mean">the mean of the normal distribution drawn from</param>
/// <param name="stddev">the standard deviation of the normal distribution</param>
static public void InitNormal(this Matrix<float> matrix, double mean, double stddev)
{
var nd = new Normal(mean, stddev);
nd.RandomSource = MyMediaLite.Random.GetInstance();
for (int i = 0; i < matrix.data.Length; i++)
matrix.data[i] = (float) nd.Sample();
}
示例5: ColumnInitNormal
/// <summary>Initializes one column of a double matrix with normal distributed (Gaussian) noise</summary>
/// <param name="matrix">the matrix to initialize</param>
/// <param name="mean">the mean of the normal distribution drawn from</param>
/// <param name="stddev">the standard deviation of the normal distribution</param>
/// <param name="column">the column to be initialized</param>
public static void ColumnInitNormal(this Matrix<double> matrix, int column, double mean, double stddev)
{
var nd = new Normal(mean, stddev);
nd.RandomSource = Util.Random.GetInstance();
for (int i = 0; i < matrix.dim1; i++)
matrix[i, column] = nd.Sample();
}
示例6: InitNormal
/// <summary>Initialize a collection of floats with values from a normal distribution</summary>
/// <param name="vector">the vector to initialize</param>
/// <param name="mean">the mean of the normal distribution</param>
/// <param name="stddev">the standard deviation of the normal distribution</param>
static public void InitNormal(this IList<float> vector, double mean, double stddev)
{
var nd = new Normal(mean, stddev);
nd.RandomSource = MyMediaLite.Random.GetInstance();
for (int i = 0; i < vector.Count; i++)
vector[i] = (float) nd.Sample();
}
示例7: ColumnInitNormal
/// <summary>Initializes one column of a float matrix with normal distributed (Gaussian) noise</summary>
/// <param name="matrix">the matrix to initialize</param>
/// <param name="mean">the mean of the normal distribution drawn from</param>
/// <param name="stddev">the standard deviation of the normal distribution</param>
/// <param name="column">the column to be initialized</param>
static public void ColumnInitNormal(this Matrix<float> matrix, int column, double mean, double stddev)
{
var nd = new Normal(mean, stddev);
nd.RandomSource = MyMediaLite.Random.GetInstance();
for (int i = 0; i < matrix.dim1; i++)
matrix[i, column] = (float) nd.Sample();
}
示例8: Initialize
public override void Initialize(List<Agent> agents)
{
var appSettings = ConfigurationManager.AppSettings;
var activityMean = int.Parse(appSettings["RegularAgentActivityMean"]);
var activityStd = int.Parse(appSettings["RegularAgentActivityStd"]);
var distribution = new Normal(activityMean, activityStd);
var interval = distribution.Sample();
ActivityInterval = (int)interval;
var contactsMean = int.Parse(appSettings["RegularAgentContactsMean"]);
var contactsStd = int.Parse(appSettings["RegularAgentContactsStd"]);
distribution = new Normal(contactsMean, contactsStd);
var contactsNumber = 0;
while (contactsNumber == 0)
{
contactsNumber = (int)distribution.Sample();
}
var strongConnectionsMean = int.Parse(appSettings["RegularAgentStrongConnectionsMean"]);
var strongConnectionsStd = int.Parse(appSettings["RegularAgentStrongConnectionsStd"]);
distribution = new Normal(strongConnectionsMean, strongConnectionsStd);
var strongConnectionsNumber = (int)distribution.Sample();
var strongConnectionsInterval = 0.75 / strongConnectionsNumber;
var strongConnectionsIntervalMin = 0.8 * strongConnectionsInterval;
var strongConnectionsIntervalDiff = strongConnectionsInterval - strongConnectionsIntervalMin;
var random = new Random();
var total = 1.0;
var usedIndices = new List<int>();
for (int i = 0; i < contactsNumber; i++)
{
var currentAgentIndex = random.Next(agents.Count);
if (usedIndices.Contains(currentAgentIndex))
{
i--;
continue;
}
usedIndices.Add(currentAgentIndex);
var currentAgent = agents.ElementAt(currentAgentIndex);
var probability = 0.0;
if (i < strongConnectionsNumber)
{
probability = strongConnectionsIntervalMin + random.NextDouble() * strongConnectionsIntervalDiff;
}
else
{
if(i == contactsNumber - 1)
{
probability = total;
}
else
{
probability = 0.2 * total;
}
}
total -= probability;
Contacts.Add(currentAgent, probability);
}
}
示例9: RandomLiquidityMaker
public RandomLiquidityMaker(IRandomNumberGenerator randomNumberGenerator, double maxOrderSize, double maxPriceDifferential, double doNothingProbability, Normal normalDist,int decimals)
{
_rng = randomNumberGenerator;
_maxOrderSize = maxOrderSize;
_maxPriceDifferential = maxPriceDifferential;
_doNothingProbability = doNothingProbability;
_normal = normalDist;
_decimals = decimals;
}
示例10: SampleTest
public void SampleTest()
{
var normal = new Normal(0.0, 1.0);
var rnd = new MersenneTwister();
var ms = new MetropolisSampler<double>(0.2, normal.Density, x => Normal.Sample(rnd, x, 0.1), 10);
ms.RandomSource = rnd;
double sample = ms.Sample();
}
示例11: TestData
public static IEnumerable<float> TestData()
{
var g = new Normal(0.0, 1.0);
var randy = new MersenneTwister();
g.RandomSource = randy;
var dbls = new double[100000];
g.Samples(dbls);
return dbls.Select(d => (float) d);
}
示例12: CreateNormalFromString
private void CreateNormalFromString(string distributionString)
{
var regex = new Regex(@"Normal\(\s*(\d+)\s*,\s*(\d+)\s*\)", RegexOptions.IgnoreCase);
var match = regex.Match(distributionString);
var mean = double.Parse(match.Groups[1].Value);
var stddev = double.Parse(match.Groups[2].Value);
_normal = new Normal(mean, stddev);
}
示例13: build_prob_map
public void build_prob_map()
{
Normal N_x = new Normal(X / 2, STD_X);
Normal N_y = new Normal(Y / 2, STD_Y);
DenseMatrix M_x = new DenseMatrix(Y, X, 0.0);
DenseMatrix M_y = new DenseMatrix(Y, X, 0.0);
DenseVector V_x = new DenseVector(X);
for (int i = 0; i < X; i++)
{
V_x[i] = N_x.Density(i);
}
for (int j = 0; j < Y; j++)
{
M_x.SetRow(j, V_x);
}
DenseVector V_y = new DenseVector(Y);
for (int i = 0; i < Y; i++)
{
V_y[i] = N_y.Density(i);
}
for (int j = 0; j < X; j++)
{
M_y.SetColumn(j, V_y);
}
DenseMatrix MULT = (DenseMatrix)M_x.PointwiseMultiply(M_y);
double s = MULT.Data.Sum();
MULT = (DenseMatrix)MULT.PointwiseDivide(new DenseMatrix(Y, X, s));
//this.dataGridView1.DataSource = MULT;
//Console.WriteLine(MULT.Data.Sum());
PROB_MAP_ORIG = MULT;
s = MULT[Y / 2, X / 2];
MULT = (DenseMatrix)MULT.PointwiseDivide(new DenseMatrix(Y, X, s));
/*
for (int i = 0; i < Y; i++)
{
Console.Write(i + " - ");
for (int j = 0; j < X; j++)
{
Console.Write(MULT[i, j] + " ");
}
Console.WriteLine();
Console.WriteLine();
}
*/
PROB_MAP = MULT;
}
示例14: MetropolisConstructor
public void MetropolisConstructor()
{
var normal = new Normal(0.0, 1.0);
var rnd = new MersenneTwister();
var ms = new MetropolisSampler<double>(0.2, normal.Density, x => Normal.Sample(rnd, x, 0.1), 10);
Assert.IsNotNull(ms.RandomSource);
ms.RandomSource = rnd;
Assert.IsNotNull(ms.RandomSource);
}
示例15: SampleTest
public void SampleTest()
{
var normal = new Normal(0.0, 1.0);
var rnd = new SystemRandomSource(1);
var ms = new MetropolisSampler<double>(0.2, normal.Density, x => Normal.Sample(rnd, x, 0.1), 10)
{
RandomSource = rnd
};
ms.Sample();
}