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


C# MatrixF.SetColumn方法代码示例

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


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

示例1: PrincipalComponentAnalysisF

        //--------------------------------------------------------------
        /// <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="VectorF.NumberOfElements"/>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="points"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="points"/> is empty.
        /// </exception>
        public PrincipalComponentAnalysisF(IList<VectorF> points)
        {
            if (points == null)
            throw new ArgumentNullException("points");
              if (points.Count == 0)
            throw new ArgumentException("The list of points is empty.");

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

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

              int numberOfElements = evd.RealEigenvalues.NumberOfElements;
              Variances = new VectorF(numberOfElements);
              V = new MatrixF(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] = float.NegativeInfinity;
              }
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:43,代码来源:PrincipalComponentAnalysisF.cs

示例2: SetColumnException2

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

示例3: SetColumn

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

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

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

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

示例4: TestRandomRegularA

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

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

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

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

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

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

示例5: TestRandomRegularA

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

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

            VectorF column2 = new VectorF(3);
            RandomHelper.Random.NextVectorF(column2, 1, 2);

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

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

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

            LUDecompositionF d = new LUDecompositionF(a);

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

            Assert.AreEqual(false, d.IsNumericallySingular);

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

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

示例6: 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++)
              {
            VectorF column1 = new VectorF(4);
            RandomHelper.Random.NextVectorF(column1, 1, 2);
            VectorF column2 = new VectorF(4);
            RandomHelper.Random.NextVectorF(column2, 1, 2);

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

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

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

            MatrixF spdMatrix = a.Transposed * a;

            CholeskyDecompositionF d = new CholeskyDecompositionF(spdMatrix);

            Assert.AreEqual(true, d.IsSymmetricPositiveDefinite);

            MatrixF 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(MatrixF.AreNumericallyEqual(spdMatrix, l * l.Transposed));

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

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

示例7: TestRandomRegularA

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

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

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

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

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

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

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

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

            MatrixF 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,代码行数:42,代码来源:QRDecompositionFTest.cs


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