本文整理汇总了C#中MathNet.Numerics.Distributions.Normal类的典型用法代码示例。如果您正苦于以下问题:C# Normal类的具体用法?C# Normal怎么用?C# Normal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Normal类属于MathNet.Numerics.Distributions命名空间,在下文中一共展示了Normal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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>());
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:7,代码来源:MetropolisHastingsSamplerTests.cs
示例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);
}
}
开发者ID:geoparsYoti,项目名称:Sharpkit.Learn,代码行数:35,代码来源:RidgeTest.cs
示例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();
}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:13,代码来源:MatrixExtensions.cs
示例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();
}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:12,代码来源:MatrixExtensions.cs
示例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();
}
开发者ID:bemde,项目名称:MyMediaLite,代码行数:13,代码来源:MatrixExtensions.cs
示例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();
}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:12,代码来源:VectorExtensions.cs
示例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();
}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:13,代码来源:MatrixExtensions.cs
示例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);
}
}
开发者ID:visheratin,项目名称:CDRSim,代码行数:58,代码来源:RegularAgent.cs
示例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;
}
开发者ID:preyen,项目名称:MarketSimulator,代码行数:9,代码来源:RandomLiquidityMaker.cs
示例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();
}
开发者ID:joeynelson,项目名称:mathnet-numerics,代码行数:10,代码来源:MetropolisSamplerTests.cs
示例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);
}
开发者ID:tp-nscan,项目名称:HopAlong,代码行数:10,代码来源:HIst1DVmD.cs
示例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);
}
开发者ID:c0d3m0nky,项目名称:mty,代码行数:11,代码来源:Distribution.cs
示例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;
}
开发者ID:pkhorrami4,项目名称:AvaScholar_Git,代码行数:54,代码来源:Screen_Prob_Map.cs
示例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);
}
开发者ID:joeynelson,项目名称:mathnet-numerics,代码行数:11,代码来源:MetropolisSamplerTests.cs
示例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();
}
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:12,代码来源:MetropolisSamplerTests.cs
示例16: SampleArrayTest
public void SampleArrayTest()
{
var normal = new Normal(0.0, 1.0);
var rnd = new SystemRandomSource(1);
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(rnd, x, 0.1), 10)
{
RandomSource = rnd
};
ms.Sample(5);
}
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:12,代码来源:MetropolisHastingsSamplerTests.cs
示例17: Paths
public static IEnumerable<double> Paths(double S, double sigma, double maturity, double N)
{
double var = sigma*sigma*maturity;
Normal n = new Normal();
for (int i = 0; i < N; i++ )
{
double normalsample = n.Sample();
double Sf = S * Math.Exp(-0.5 * var + Math.Sqrt(var) * normalsample);
yield return Sf;
}
}
开发者ID:joelhoro,项目名称:JHLib,代码行数:12,代码来源:PythonWrapper.cs
示例18: SetupDistributions
public void SetupDistributions()
{
dists = new IDistribution[8];
dists[0] = new Beta(1.0, 1.0);
dists[1] = new ContinuousUniform(0.0, 1.0);
dists[2] = new Gamma(1.0, 1.0);
dists[3] = new Normal(0.0, 1.0);
dists[4] = new Bernoulli(0.6);
dists[5] = new Weibull(1.0, 1.0);
dists[6] = new DiscreteUniform(1, 10);
dists[7] = new LogNormal(1.0, 1.0);
}
开发者ID:DvptUml,项目名称:mathnet-numerics,代码行数:13,代码来源:CommonDistributionTests.cs
示例19: Node
public Node(string ip, int port,int type)
{
this.type = type;
this.ip = ip;
this.port = port;
thread = new Thread(new ThreadStart(beginNode));
end = false;
nextIntimacyDistributionSpeaking = new Normal(4.0, 1.0);
nextIntimacyDistributionListening = new Normal(5.0, 1.0);
intimacyLengthDistribution = new Normal(1.0, 0.2);
tracker = new FaceTrackerProxy(ip,port);
tracker.setWholeBodyOn(false);
}
开发者ID:Wisc-HCI,项目名称:robot-gaze-aversion,代码行数:13,代码来源:node.cs
示例20: MetropolisHastingsConstructor
public void MetropolisHastingsConstructor()
{
var normal = new Normal(0.0, 1.0);
var rnd = new SystemRandomSource(1);
var ms = new MetropolisHastingsSampler<double>(0.2, normal.Density, (x, y) => Normal.PDF(x, 0.1, y), x => Normal.Sample(rnd, x, 0.1), 10)
{
RandomSource = rnd
};
Assert.IsNotNull(ms.RandomSource);
ms.RandomSource = new System.Random(0);
Assert.IsNotNull(ms.RandomSource);
}
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:14,代码来源:MetropolisHastingsSamplerTests.cs
注:本文中的MathNet.Numerics.Distributions.Normal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论