当前位置: 首页>>代码示例>>C#>>正文


C# MatrixD.SetColumn方法代码示例

本文整理汇总了C#中MatrixD.SetColumn方法的典型用法代码示例。如果您正苦于以下问题:C# MatrixD.SetColumn方法的具体用法?C# MatrixD.SetColumn怎么用?C# MatrixD.SetColumn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MatrixD的用法示例。


在下文中一共展示了MatrixD.SetColumn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PrincipalComponentAnalysisD

        //--------------------------------------------------------------
        /// <summary>
        /// Creates the principal component analysis for the given list of points.
        /// </summary>
        /// <param name="points">
        /// The list of data points. All points must have the same 
        /// <see cref="VectorD.NumberOfElements"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="points"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="points"/> is empty.
        /// </exception>
        public PrincipalComponentAnalysisD(IList<VectorD> points)
        {
            if (points == null)
            throw new ArgumentNullException("points");
              if (points.Count == 0)
            throw new ArgumentException("The list of points is empty.");

              // Compute covariance matrix.
              MatrixD covarianceMatrix = StatisticsHelper.ComputeCovarianceMatrix(points);

              // Perform Eigenvalue decomposition.
              EigenvalueDecompositionD evd = new EigenvalueDecompositionD(covarianceMatrix);

              int numberOfElements = evd.RealEigenvalues.NumberOfElements;
              Variances = new VectorD(numberOfElements);
              V = new MatrixD(numberOfElements, numberOfElements);

              // Sort eigenvalues by decreasing value.
              // Since covarianceMatrix is symmetric, we have no imaginary eigenvalues.
              for (int i = 0; i < Variances.NumberOfElements; i++)
              {
            int index = evd.RealEigenvalues.IndexOfLargestElement;

            Variances[i] = evd.RealEigenvalues[index];
            V.SetColumn(i, evd.V.GetColumn(index));

            evd.RealEigenvalues[index] = double.NegativeInfinity;
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:43,代码来源:PrincipalComponentAnalysisD.cs

示例2: TestRandomRegularA

        public void TestRandomRegularA()
        {
            RandomHelper.Random = new Random(1);

              for (int i = 0; i < 100; i++)
              {
            VectorD column1 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column1, 1, 2);

            VectorD column2 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column2, 1, 2);

            // Make linearly independent.
            if (column1 / column1[0] == column2 / column2[0])
              column2[0]++;

            // Create linearly independent third column.
            VectorD column3 = column1 + column2;
            column3[1]++;

            // Create A.
            MatrixD a = new MatrixD(3, 3);
            a.SetColumn(0, column1);
            a.SetColumn(1, column2);
            a.SetColumn(2, column3);

            LUDecompositionD d = new LUDecompositionD(a);

            MatrixD aPermuted = d.L * d.U;
            Assert.IsTrue(MatrixD.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));
            aPermuted = d.L * d.U; // Repeat with to test cached values.
            Assert.IsTrue(MatrixD.AreNumericallyEqual(aPermuted, a.GetSubmatrix(d.PivotPermutationVector, 0, 2)));

            Assert.AreEqual(false, d.IsNumericallySingular);

            // Check solving of linear equations.
            MatrixD b = new MatrixD(3, 2);
            RandomHelper.Random.NextMatrixD(b, 0, 1);

            MatrixD x = d.SolveLinearEquations(b);
            MatrixD b2 = a * x;
            Assert.IsTrue(MatrixD.AreNumericallyEqual(b, b2, 0.01f));
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:44,代码来源:LUDecompositionDTest.cs

示例3: TestRandomRegularA

        public void TestRandomRegularA()
        {
            RandomHelper.Random = new Random(1);

              for (int i = 0; i < 100; i++)
              {
            VectorD column1 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column1, 1, 2);

            VectorD column2 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column2, 1, 2);

            // Make linearly independent.
            if (column1 / column1[0] == column2 / column2[0])
              column2[0]++;

            // Create linearly independent third column.
            VectorD column3 = column1 + column2;
            column3[1]++;

            // Create A.
            MatrixD a = new MatrixD(3, 3);
            a.SetColumn(0, column1);
            a.SetColumn(1, column2);
            a.SetColumn(2, column3);

            QRDecompositionD d = new QRDecompositionD(a);
            Assert.IsTrue(MatrixD.AreNumericallyEqual(a, d.Q * d.R));
            Assert.IsTrue(MatrixD.AreNumericallyEqual(a, d.Q * d.R)); // Second time with the cached values.
            Assert.AreEqual(true, d.HasNumericallyFullRank);

            // Check solving of linear equations.
            MatrixD b = new MatrixD(3, 2);
            RandomHelper.Random.NextMatrixD(b, 0, 1);

            MatrixD x = d.SolveLinearEquations(b);
            MatrixD b2 = a * x;
            Assert.IsTrue(MatrixD.AreNumericallyEqual(b, b2, 0.01f));

            MatrixD h = d.H;  // Just call this one to see if it runs through.
            h = d.H; // Call it secont time to cover code with internal caching.
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:43,代码来源:QRDecompositionDTest.cs

示例4: TestRandomSpdA

        public void TestRandomSpdA()
        {
            RandomHelper.Random = new Random(1);

              // Every transpose(A) * A is SPD if A has full column rank and m>n.
              for (int i = 0; i < 100; i++)
              {
            VectorD column1 = new VectorD(4);
            RandomHelper.Random.NextVectorD(column1, 1, 2);
            VectorD column2 = new VectorD(4);
            RandomHelper.Random.NextVectorD(column2, 1, 2);

            // Make linearly independent.
            if (column1 / column1[0] == column2 / column2[0])
              column2[0]++;

            // Create linearly independent third column.
            VectorD column3 = column1 + column2;
            column3[1]++;

            // Create A.
            MatrixD a = new MatrixD(4, 3);
            a.SetColumn(0, column1);
            a.SetColumn(1, column2);
            a.SetColumn(2, column3);

            MatrixD spdMatrix = a.Transposed * a;

            CholeskyDecompositionD d = new CholeskyDecompositionD(spdMatrix);

            Assert.AreEqual(true, d.IsSymmetricPositiveDefinite);

            MatrixD l = d.L;

            // Test if L is a lower triangular matrix.
            for (int j = 0; j < l.NumberOfRows; j++)
              for (int k = 0; k < l.NumberOfColumns; k++)
            if (j < k)
              Assert.AreEqual(0, l[j, k]);

            Assert.IsTrue(MatrixD.AreNumericallyEqual(spdMatrix, l * l.Transposed));

            // Check solving of linear equations.
            MatrixD b = new MatrixD(3, 2);
            RandomHelper.Random.NextMatrixD(b, 0, 1);

            MatrixD x = d.SolveLinearEquations(b);
            MatrixD b2 = spdMatrix * x;
            Assert.IsTrue(MatrixD.AreNumericallyEqual(b, b2, 0.01f));
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:51,代码来源:CholeskyDecompositionDTest.cs

示例5: SetColumnException2

 public void SetColumnException2()
 {
     MatrixD m = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor);
       m.SetColumn(4, new VectorD(3));
 }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:5,代码来源:MatrixDTest.cs

示例6: SetColumn

        public void SetColumn()
        {
            MatrixD m = new MatrixD(3, 4, rowMajor, MatrixOrder.RowMajor);
              m.SetColumn(0, new VectorD(new double[]{ 0.1, 0.2, 0.3 }));
              Assert.AreEqual(new VectorD(new double[]{ 0.1, 0.2, 0.3 }), m.GetColumn(0));
              Assert.AreEqual(new VectorD(new double[]{ 2.0, 6.0, 10.0 }), m.GetColumn(1));
              Assert.AreEqual(new VectorD(new double[]{ 3.0, 7.0, 11.0 }), m.GetColumn(2));
              Assert.AreEqual(new VectorD(new double[]{ 4.0, 8.0, 12.0 }), m.GetColumn(3));

              m.SetColumn(1, new VectorD(new double[] { 0.4, 0.5, 0.6 }));
              Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0));
              Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1));
              Assert.AreEqual(new VectorD(new double[] { 3.0, 7.0, 11.0 }), m.GetColumn(2));
              Assert.AreEqual(new VectorD(new double[] { 4.0, 8.0, 12.0 }), m.GetColumn(3));

              m.SetColumn(2, new VectorD(new double[] { 0.7, 0.8, 0.9 }));
              Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0));
              Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1));
              Assert.AreEqual(new VectorD(new double[] { 0.7, 0.8, 0.9 }), m.GetColumn(2));
              Assert.AreEqual(new VectorD(new double[] { 4.0, 8.0, 12.0 }), m.GetColumn(3));

              m.SetColumn(3, new VectorD(new double[] { 1.1, 1.8, 1.9 }));
              Assert.AreEqual(new VectorD(new double[] { 0.1, 0.2, 0.3 }), m.GetColumn(0));
              Assert.AreEqual(new VectorD(new double[] { 0.4, 0.5, 0.6 }), m.GetColumn(1));
              Assert.AreEqual(new VectorD(new double[] { 0.7, 0.8, 0.9 }), m.GetColumn(2));
              Assert.AreEqual(new VectorD(new double[] { 1.1, 1.8, 1.9 }), m.GetColumn(3));
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:27,代码来源:MatrixDTest.cs

示例7: TestRandomRegularA

        public void TestRandomRegularA()
        {
            RandomHelper.Random = new Random(1);

              for (int i = 0; i < 100; i++)
              {
            VectorD column1 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column1, 1, 2);
            VectorD column2 = new VectorD(3);
            RandomHelper.Random.NextVectorD(column2, 1, 2);

            // Make linearly independent.
            if (column1 / column1[0] == column2 / column2[0])
              column2[0]++;

            // Create linearly independent third column.
            VectorD column3 = column1 + column2;
            column3[1]++;

            // Create A.
            MatrixD a = new MatrixD(3, 3);
            a.SetColumn(0, column1);
            a.SetColumn(1, column2);
            a.SetColumn(2, column3);

            SingularValueDecompositionD svd = new SingularValueDecompositionD(a);
            Assert.AreEqual(3, svd.NumericalRank);
            Assert.IsTrue(MatrixD.AreNumericallyEqual(a, svd.U * svd.S * svd.V.Transposed));
            Assert.AreEqual(svd.SingularValues[0], svd.Norm2);
            double condNumber = svd.ConditionNumber;
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:32,代码来源:SingularValueDecompositionDTest.cs


注:本文中的MatrixD.SetColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。