本文整理汇总了C#中Normal.Sample方法的典型用法代码示例。如果您正苦于以下问题:C# Normal.Sample方法的具体用法?C# Normal.Sample怎么用?C# Normal.Sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Normal
的用法示例。
在下文中一共展示了Normal.Sample方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateRandomDenseMatrix
/// <summary>
/// Creates a <c>DenseMatrix</c> with random values.
/// </summary>
/// <param name="row">The number of rows.</param>
/// <param name="col">The number of columns.</param>
/// <returns>A <c>DenseMatrix</c> with the given dimensions and random values.</returns>
public static Matrix GenerateRandomDenseMatrix(int row, int col)
{
// Fill a matrix with standard random numbers.
var normal = new Normal
{
RandomSource = new MersenneTwister(1)
};
var matrixA = new DenseMatrix(row, col);
for (var i = 0; i < row; i++)
{
for (var j = 0; j < col; j++)
{
matrixA[i, j] = normal.Sample();
}
}
return matrixA;
}
示例2: CanSample
public void CanSample()
{
var n = new Normal();
n.Sample();
}
示例3: GenerateRandomUserDefinedVector
/// <summary>
/// Creates a <c>UserDefinedVector</c> with random values.
/// </summary>
/// <param name="order">The size of the vector.</param>
/// <returns>A <c>UserDefinedVector</c> with the given dimension and random values.</returns>
public static Vector GenerateRandomUserDefinedVector(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal
{
RandomSource = new MersenneTwister(1)
};
var v = new UserDefinedVector(order);
for (var i = 0; i < order; i++)
{
v[i] = new Complex(normal.Sample(), normal.Sample());
}
// Generate a matrix which is positive definite.
return v;
}
示例4: GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix
/// <summary>
/// Creates a positive definite <c>UserDefinedMatrix</c> with random values.
/// </summary>
/// <param name="order">The order of the matrix.</param>
/// <returns>A positive definite <c>UserDefinedMatrix</c> with the given order and random values.</returns>
public static Matrix<Complex> GenerateRandomPositiveDefiniteHermitianUserDefinedMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal
{
RandomSource = new MersenneTwister(1)
};
var matrixA = new UserDefinedMatrix(order);
for (var i = 0; i < order; i++)
{
for (var j = 0; j < order; j++)
{
matrixA[i, j] = new Complex(normal.Sample(), normal.Sample());
}
}
// Generate a Hermitian matrix which is positive definite.
return matrixA.ConjugateTranspose()*matrixA;
}
示例5: GenerateRandomDenseVector
/// <summary>
/// Creates a <c>DenseVector</c> with random values.
/// </summary>
/// <param name="order">The size of the vector.</param>
/// <returns>A <c>DenseVector</c> with the given dimension and random values.</returns>
public static Vector GenerateRandomDenseVector(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal
{
RandomSource = new MersenneTwister(1)
};
var v = new DenseVector(order);
for (var i = 0; i < order; i++)
{
v[i] = new Complex(normal.Sample(), normal.Sample());
}
return v;
}
示例6: GenerateRandomPositiveDefiniteUserDefinedMatrix
/// <summary>
/// Creates a positive definite <c>UserDefinedMatrix</c> with random values.
/// </summary>
/// <param name="order">The order of the matrix.</param>
/// <returns>A positive definite <c>UserDefinedMatrix</c> with the given order and random values.</returns>
public static Matrix<double> GenerateRandomPositiveDefiniteUserDefinedMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal(new MersenneTwister(1));
var matrixA = new UserDefinedMatrix(order);
for (var i = 0; i < order; i++)
{
for (var j = 0; j < order; j++)
{
matrixA[i, j] = normal.Sample();
}
}
// Generate a matrix which is positive definite.
return matrixA.Transpose()*matrixA;
}
示例7: GenerateRandomPositiveDefiniteDenseMatrix
/// <summary>
/// Creates a positive definite <c>DenseMatrix</c> with random values.
/// </summary>
/// <param name="order">The order of the matrix.</param>
/// <returns>A positive definite <c>DenseMatrix</c> with the given order and random values.</returns>
public static Matrix<float> GenerateRandomPositiveDefiniteDenseMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal
{
RandomSource = new MersenneTwister(1)
};
var matrixA = new DenseMatrix(order);
for (var i = 0; i < order; i++)
{
for (var j = 0; j < order; j++)
{
matrixA[i, j] = (float) normal.Sample();
}
}
// Generate a matrix which is positive definite.
return matrixA.Transpose()*matrixA;
}
示例8: GenerateRandomUserDefinedMatrix
/// <summary>
/// Creates a <c>UserDefinedMatrix</c> with random values.
/// </summary>
/// <param name="row">The number of rows.</param>
/// <param name="col">The number of columns.</param>
/// <returns>A <c>UserDefinedMatrix</c> with the given dimensions and random values.</returns>
public static Matrix GenerateRandomUserDefinedMatrix(int row, int col)
{
// Fill a matrix with standard random numbers.
var normal = new Normal(new MersenneTwister(1));
var matrixA = new UserDefinedMatrix(row, col);
for (var i = 0; i < row; i++)
{
for (var j = 0; j < col; j++)
{
matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
}
}
return matrixA;
}
示例9: GenerateRandomPositiveDefiniteHermitianDenseMatrix
/// <summary>
/// Creates a positive definite <c>DenseMatrix</c> with random values.
/// </summary>
/// <param name="order">The order of the matrix.</param>
/// <returns>A positive definite <c>DenseMatrix</c> with the given order and random values.</returns>
public static Matrix<Complex32> GenerateRandomPositiveDefiniteHermitianDenseMatrix(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal(new MersenneTwister(1));
var matrixA = new DenseMatrix(order);
for (var i = 0; i < order; i++)
{
for (var j = 0; j < order; j++)
{
matrixA[i, j] = new Complex32((float) normal.Sample(), (float) normal.Sample());
}
}
// Generate a Hermitian matrix which is positive definite.
return matrixA.ConjugateTranspose()*matrixA;
}
示例10: GenerateRandomDenseVector
/// <summary>
/// Creates a <c>DenseVector</c> with random values.
/// </summary>
/// <param name="order">The size of the vector.</param>
/// <returns>A <c>DenseVector</c> with the given dimension and random values.</returns>
public static Vector GenerateRandomDenseVector(int order)
{
// Fill a matrix with standard random numbers.
var normal = new Normal(new MersenneTwister(1));
var v = new DenseVector(order);
for (var i = 0; i < order; i++)
{
v[i] = (float) normal.Sample();
}
return v;
}
示例11: CreateStartingVectors
/// <summary>
/// Returns an array of starting vectors.
/// </summary>
/// <param name="maximumNumberOfStartingVectors">The maximum number of starting vectors that should be created.</param>
/// <param name="numberOfVariables">The number of variables.</param>
/// <returns>
/// An array with starting vectors. The array will never be larger than the
/// <paramref name="maximumNumberOfStartingVectors"/> but it may be smaller if
/// the <paramref name="numberOfVariables"/> is smaller than
/// the <paramref name="maximumNumberOfStartingVectors"/>.
/// </returns>
private static IList<Vector> CreateStartingVectors(int maximumNumberOfStartingVectors, int numberOfVariables)
{
// Create no more starting vectors than the size of the problem - 1
// Get random values and then orthogonalize them with
// modified Gramm - Schmidt
var count = NumberOfStartingVectorsToCreate(maximumNumberOfStartingVectors, numberOfVariables);
// Get a random set of samples based on the standard normal distribution with
// mean = 0 and sd = 1
var distribution = new Normal();
Matrix matrix = new DenseMatrix(numberOfVariables, count);
for (var i = 0; i < matrix.ColumnCount; i++)
{
var samples = new float[matrix.RowCount];
for (var j = 0; j < matrix.RowCount; j++)
{
samples[j] = (float)distribution.Sample();
}
// Set the column
matrix.SetColumn(i, samples);
}
// Compute the orthogonalization.
var gs = matrix.GramSchmidt();
var orthogonalMatrix = gs.Q;
// Now transfer this to vectors
var result = new List<Vector>();
for (var i = 0; i < orthogonalMatrix.ColumnCount; i++)
{
result.Add((Vector)orthogonalMatrix.Column(i));
// Normalize the result vector
result[i].Multiply(1 / result[i].Norm(2), result[i]);
}
return result;
}