本文整理汇总了C#中Matrix.Cholesky方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.Cholesky方法的具体用法?C# Matrix.Cholesky怎么用?C# Matrix.Cholesky使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Matrix
的用法示例。
在下文中一共展示了Matrix.Cholesky方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InverseWishart
/// <summary>
/// Initializes a new instance of the <see cref="InverseWishart"/> class.
/// </summary>
/// <param name="degreesOfFreedom">The degree of freedom (ν) for the inverse Wishart distribution.</param>
/// <param name="scale">The scale matrix (Ψ) for the inverse Wishart distribution.</param>
public InverseWishart(double degreesOfFreedom, Matrix<double> scale)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
_random = SystemRandomSource.Default;
_freedom = degreesOfFreedom;
_scale = scale;
_chol = _scale.Cholesky();
}
示例2: SampleVectorNormal
/// <summary>
/// Samples a vector normal distributed random variable.
/// </summary>
/// <param name="rnd">The random number generator to use.</param>
/// <param name="mean">The mean of the vector normal distribution.</param>
/// <param name="covariance">The covariance matrix of the vector normal distribution.</param>
/// <returns>a sequence of samples from defined distribution.</returns>
static Vector<double> SampleVectorNormal(System.Random rnd, Vector<double> mean, Matrix<double> covariance)
{
var chol = covariance.Cholesky();
// Sample a standard normal variable.
var v = Vector<double>.Build.Random(mean.Count, new Normal(rnd));
// Return the transformed variable.
return mean + (chol.Factor*v);
}
示例3: SetParameters
/// <summary>
/// Sets the parameters of the distribution after checking their validity.
/// </summary>
/// <param name="degreesOfFreedom">The degree of freedom (ν) for the inverse Wishart distribution.</param>
/// <param name="scale">The scale matrix (Ψ) for the inverse Wishart distribution.</param>
/// <exception cref="ArgumentOutOfRangeException">When the parameters are out of range.</exception>
void SetParameters(double degreesOfFreedom, Matrix<double> scale)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))
{
throw new ArgumentOutOfRangeException(Resources.InvalidDistributionParameters);
}
_freedom = degreesOfFreedom;
_scale = scale;
_chol = _scale.Cholesky();
}
示例4: Density
/// <summary>
/// Evaluates the probability density function for the inverse Wishart distribution.
/// </summary>
/// <param name="x">The matrix at which to evaluate the density at.</param>
/// <exception cref="ArgumentOutOfRangeException">If the argument does not have the same dimensions as the scale matrix.</exception>
/// <returns>the density at <paramref name="x"/>.</returns>
public double Density(Matrix<double> x)
{
var p = _scale.RowCount;
if (x.RowCount != p || x.ColumnCount != p)
{
throw new ArgumentOutOfRangeException("x", Resources.ArgumentMatrixDimensions);
}
var chol = x.Cholesky();
var dX = chol.Determinant;
var sXi = chol.Solve(Scale);
// Compute the multivariate Gamma function.
var gp = Math.Pow(Constants.Pi, p*(p - 1.0)/4.0);
for (var j = 1; j <= p; j++)
{
gp *= SpecialFunctions.Gamma((_freedom + 1.0 - j)/2.0);
}
return Math.Pow(dX, -(_freedom + p + 1.0)/2.0)
*Math.Exp(-0.5*sXi.Trace())
*Math.Pow(_chol.Determinant, _freedom/2.0)
/Math.Pow(2.0, _freedom*p/2.0)
/gp;
}
示例5: Sample
/// <summary>
/// Samples a Wishart distributed random variable using the method
/// Algorithm AS 53: Wishart Variate Generator
/// W. B. Smith and R. R. Hocking
/// Applied Statistics, Vol. 21, No. 3 (1972), pp. 341-345
/// </summary>
/// <param name="rnd">The random number generator to use.</param>
/// <param name="degreesOfFreedom">The degrees of freedom (n) for the Wishart distribution.</param>
/// <param name="scale">The scale matrix (V) for the Wishart distribution.</param>
/// <returns>a sequence of samples from the distribution.</returns>
public static Matrix<double> Sample(System.Random rnd, double degreesOfFreedom, Matrix<double> scale)
{
if (Control.CheckDistributionParameters && !IsValidParameterSet(degreesOfFreedom, scale))
{
throw new ArgumentException(Resources.InvalidDistributionParameters);
}
return DoSample(rnd, degreesOfFreedom, scale, scale.Cholesky());
}