本文整理汇总了C#中DoubleMatrix.SetMatrixElements方法的典型用法代码示例。如果您正苦于以下问题:C# DoubleMatrix.SetMatrixElements方法的具体用法?C# DoubleMatrix.SetMatrixElements怎么用?C# DoubleMatrix.SetMatrixElements使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoubleMatrix
的用法示例。
在下文中一共展示了DoubleMatrix.SetMatrixElements方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TikhonovNMF3
/// <summary>
/// Factorize a nonnegative matrix A into two nonnegative matrices B and C so that A is nearly equal to B*C.
/// Tikhonovs the nm f3.
/// </summary>
/// <param name="A">Matrix to factorize.</param>
/// <param name="r">The number of factors.</param>
/// <param name="B0">Original B matrix. Can be null.</param>
/// <param name="C0">Original C matrix. Can be null.</param>
/// <param name="oldalpha">The oldalpha.</param>
/// <param name="oldbeta">The oldbeta.</param>
/// <param name="gammaB">The gamma b.</param>
/// <param name="gammaC">The gamma c.</param>
/// <param name="maxiter">The maxiter.</param>
/// <param name="tol">The tol.</param>
public static void TikhonovNMF3(
IMatrix A,
int r,
IMatrix B0,
IMatrix C0,
IVector oldalpha,
IVector oldbeta,
IMatrix gammaB,
IMatrix gammaC,
int maxiter,
double tol)
{
// The converged version of the algorithm
// Use complementary slackness as stopping criterion
// format long;
// Check the input matrix
if (null == A)
throw new ArgumentNullException(nameof(A));
if (MatrixMath.Min(A) < 0)
throw new ArgumentException("Input matrix must not contain negative elements", nameof(A));
int m = A.Rows;
int n = A.Columns;
// Check input arguments
//if ˜exist(’r’)
if (null == B0)
{
B0 = DoubleMatrix.Random(m, r);
}
if (null == C0)
{
C0 = DoubleMatrix.Random(r, n);
}
if (null == oldalpha)
{
oldalpha = new DoubleVector(n);
}
if (null == oldbeta)
{
oldbeta = new DoubleVector(m);
}
if (null == gammaB)
{
gammaB = new DoubleMatrix(m, 1);
gammaB.SetMatrixElements(0.1); // small values lead to better convergence property
}
if (null == gammaC)
{
gammaC = new DoubleMatrix(n, 1);
gammaC.SetMatrixElements(0.1); // small values lead to better convergence property
}
if (0 == maxiter)
maxiter = 1000;
if (double.IsNaN(tol) || tol <= 0)
tol = 1.0e-9;
var B = B0; B0 = null;
var C = C0; C0 = null;
var newalpha = oldalpha;
var newbeta = oldbeta;
var AtA = new DoubleMatrix(n, n);
MatrixMath.MultiplyFirstTransposed(A, A, AtA);
double trAtA = MatrixMath.Trace(AtA);
var olderror = new DoubleVector(maxiter + 1);
var BtA = new DoubleMatrix(r, n);
MatrixMath.MultiplyFirstTransposed(B, A, BtA);
var CtBtA = new DoubleMatrix(n, n);
MatrixMath.MultiplyFirstTransposed(C, BtA, CtBtA);
var BtB = new DoubleMatrix(r, r);
MatrixMath.MultiplyFirstTransposed(B, B, BtB);
//.........这里部分代码省略.........