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


C# Double.SparseMatrix类代码示例

本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.SparseMatrix的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix类的具体用法?C# SparseMatrix怎么用?C# SparseMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SparseMatrix类属于MathNet.Numerics.LinearAlgebra.Double命名空间,在下文中一共展示了SparseMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestVelocityOnPlane

        public void TestVelocityOnPlane()
        {
            Frisbee.SimulationState st = new Frisbee.SimulationState
                                             {
                                                 VX = 1,
                                                 VY = 1,
                                                 Theta = Math.PI / 4
                                             };

            Matrix<double> transformation =
                new SparseMatrix(new [,]
                                     {
                                         {st.CosTheta, st.SinTheta*st.SinPhi, -st.SinTheta*st.CosPhi},
                                         {0, st.CosPhi, st.SinPhi},
                                         {st.SinTheta, -st.CosTheta*st.SinPhi, st.CosTheta*st.CosPhi}
                                     });

            SparseVector c3 = new SparseVector(transformation.Row(2));

            SparseVector velocity = new SparseVector(new[] { st.VX, st.VY, st.VZ });
            double velocityMagnitude = velocity.Norm(2);

            double velocityC3 = velocity.DotProduct(c3);

            Vector<double> vp = velocity.Subtract(c3.Multiply(velocityC3));
            double vpMagnitude = vp.Norm(2);
        }
开发者ID:joproulx,项目名称:FrisbeeSimulator,代码行数:27,代码来源:UnitTest1.cs

示例2: Learn

        /// <summary>
        /// Learn the current input.
        /// </summary>
        /// <param name="input"></param>
        /// <exception cref="HtmRuleException"></exception>
        public override void Learn(SparseMatrix input)
        {
            // Limitation due to HTM v1.x design (cannot learn after inference without modifying ouput vector structure)
            if (!IsLearning)
                // TODOlater allow learning after training when using FixedMaxSize nodes
                throw new HtmRuleException("Cannot learn after any other mode than learning", this);

            // Ignore blank input
            //TODOlater? treat any input with identical values for *all* components as blank?
            //TODOlater use DetectBlanks/DetectBlanksMode properties
            if (input.NonZerosCount == 0)
            { return; }

            // Check matrix size
            if (CoincidencesFrequencies.Count > 0 &&
                (CoincidencesFrequencies.Keys.First().RowCount != input.RowCount || CoincidencesFrequencies.Keys.First().ColumnCount != input.ColumnCount))
                throw new HtmRuleException("Cannot learn varying sized inputs", this);

            SparseMatrix existingCoincidence = FindClosestCoincidence(input);

            if (existingCoincidence != null)
                CoincidencesFrequencies[existingCoincidence] += 1;
            else
                if (CoincidencesFrequencies.Count < MaxOutputSize)
                    CoincidencesFrequencies[input] = 1;
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:31,代码来源:SpatialNode2DGaussian.cs

示例3: ErrorWhenLearningAfterInferenceMode

        public void ErrorWhenLearningAfterInferenceMode()
        {
            var node = new SpatialNode2DGaussian();
            var mat = new SparseMatrix(4, 4, 4.0);
            var learnAfterInferFails = false;
            var learnAfterTBInferFails = false;
            node.Learn(mat);

            node.Infer(mat);
            try
            {
                node.Learn(mat);
            }
            catch (HtmRuleException e)
            {
                learnAfterInferFails = true;
                Debug.WriteLine(e.Message);
            }

            node.TimeInfer(mat);
            try
            {
                node.Learn(mat);
            }
            catch (HtmRuleException e)
            {
                learnAfterTBInferFails = true;
                Debug.WriteLine(e.Message);
            }

            Assert.IsTrue(learnAfterInferFails);
            Assert.IsTrue(learnAfterTBInferFails);
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:33,代码来源:SpatialNodeGaussianTests.cs

示例4: SparseMatrixSubMatrixMethodWorks

        public void SparseMatrixSubMatrixMethodWorks()
        {
            var matrix = new SparseMatrix(10, 10, 1.0);
            var sub = matrix.SubMatrix(8, 2, 0, 2);

            Assert.AreEqual(2, sub.RowCount);
            Assert.AreEqual(2, sub.ColumnCount);
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:8,代码来源:ThirdPartyComponentsTests.cs

示例5: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            var input = new DenseVector(3);

            var solver = new GpBiCg();
            Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:GpBiCgTest.cs

示例6: SolveLongMatrixThrowsArgumentException

        public void SolveLongMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(3, 2);
            var input = new DenseVector(3);

            var solver = new MlkBiCgStab();
            Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源:MlkBiCgStabTest.cs

示例7: SolveWideMatrixThrowsArgumentException

        public void SolveWideMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(2, 3);
            var input = new DenseVector(2);

            var solver = new TFQMR();
            Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
        }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:8,代码来源:TFQMRTest.cs

示例8: SolveWideMatrixThrowsArgumentException

        public void SolveWideMatrixThrowsArgumentException()
        {
            var matrix = new SparseMatrix(2, 3);
            var input = new DenseVector(2);

            var solver = new MlkBiCgStab();
            Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
        }
开发者ID:EricGT,项目名称:mathnet-numerics,代码行数:8,代码来源:MlkBiCgStabTest.cs

示例9: CreateUnitMatrix

 /// <summary>
 /// Create unit matrix.
 /// </summary>
 /// <param name="size">Matrix size.</param>
 /// <returns>New unit matrix.</returns>
 internal SparseMatrix CreateUnitMatrix(int size)
 {
     var matrix = new SparseMatrix(size);
     for (var i = 0; i < size; i++)
     {
         matrix[i, i] = 2;
     }
     return matrix;
 }
开发者ID:larzw,项目名称:mathnet-numerics,代码行数:14,代码来源:PreConditionerTest.cs

示例10: CheckResult

        /// <summary>
        /// Check the result.
        /// </summary>
        /// <param name="preconditioner">Specific preconditioner.</param>
        /// <param name="matrix">Source matrix.</param>
        /// <param name="vector">Initial vector.</param>
        /// <param name="result">Result vector.</param>
        protected override void CheckResult(IPreconditioner<double> preconditioner, SparseMatrix matrix, Vector<double> vector, Vector<double> result)
        {
            Assert.AreEqual(typeof (UnitPreconditioner<double>), preconditioner.GetType(), "#01");

            // Unit preconditioner is doing nothing. Vector and result should be equal
            for (var i = 0; i < vector.Count; i++)
            {
                Assert.IsTrue(vector[i] == result[i], "#02-" + i);
            }
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:17,代码来源:UnitPreconditionerTest.cs

示例11: SparseMatrixAddsCorrectlyToZeroComponents

        public void SparseMatrixAddsCorrectlyToZeroComponents()
        {
            var m1 = new SparseMatrix(1, 3);
            var m2 = new SparseMatrix(new double[,] { { 0, 1, 1 } });

            var sum1 = m1 + m2;
            var sum2 = m2 + m1;

            Assert.AreEqual(m2, sum2);
            Assert.AreEqual(m2, sum1);
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:11,代码来源:ThirdPartyComponentsTests.cs

示例12: SparseMatrixSubtractsCorrectlyFromZeroComponents

        public void SparseMatrixSubtractsCorrectlyFromZeroComponents()
        {
            var m1 = new SparseMatrix(new double[,] { { 1, 0, 0, 1 }, { 1, 1, 0, 1 } });
            var m2 = new SparseMatrix(new double[,] { { 1, 1, 1, 0 }, { 1, 0, 0, 1 } });

            var diff1 = new SparseMatrix(new double[,] { { 0, -1, -1, 1 }, { 0, 1, 0, 0 } });
            var diff2 = new SparseMatrix(new double[,] { { 0, 1, 1, -1 }, { 0, -1, 0, 0 } });

            Assert.AreEqual(diff2, m2 - m1);
            Assert.AreEqual(diff1, m1 - m2);
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:11,代码来源:ThirdPartyComponentsTests.cs

示例13: CheckResult

        /// <summary>
        /// Check the result.
        /// </summary>
        /// <param name="preconditioner">Specific preconditioner.</param>
        /// <param name="matrix">Source matrix.</param>
        /// <param name="vector">Initial vector.</param>
        /// <param name="result">Result vector.</param>
        protected override void CheckResult(IPreconditioner<double> preconditioner, SparseMatrix matrix, Vector<double> vector, Vector<double> result)
        {
            Assert.AreEqual(typeof (DiagonalPreconditioner), preconditioner.GetType(), "#01");

            // Compute M * result = product
            // compare vector and product. Should be equal
            var product = new DenseVector(result.Count);
            matrix.Multiply(result, product);
            for (var i = 0; i < product.Count; i++)
            {
                Assert.IsTrue(vector[i].AlmostEqualNumbersBetween(product[i], -Epsilon.Magnitude()), "#02-" + i);
            }
        }
开发者ID:skair39,项目名称:mathnet-numerics,代码行数:20,代码来源:DiagonalTest.cs

示例14: Extract

        public static SparseMatrix Extract(this SparseMatrix matrix, int[] rows, int[] columns)
        {
            var extractedMatrix = new SparseMatrix(rows.Length, columns.Length);

            for (int c = 0; c < columns.Length; c++)
            {
                for (int r = 0; r < rows.Length; r++)
                {
                    extractedMatrix[r, c] = matrix[rows[r], columns[c]];
                }
            }

            return extractedMatrix;
        }
开发者ID:Mistrall,项目名称:Solvation,代码行数:14,代码来源:SparseMatrixExtensions.cs

示例15: Infer

        /// <summary>
        /// Do Flash inference for the given input
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public override Vector Infer(SparseMatrix input)
        {
            State = NodeState.FlashInference;

            if (LearnedCoincidences.Length == 0)
            {
                return new SparseVector(1);
            }

            var output = new DenseVector(LearnedCoincidences.Length);
            for (int i = 0; i < LearnedCoincidences.Length; ++i)
            {
                var diff = LearnedCoincidences[i] - input;
                var norm = diff.FrobeniusNorm();

                output[i] = Math.Exp(-(norm * norm)  / (2 * SquaredSigma));
            }

            return output;
        }
开发者ID:neural5torm,项目名称:OCodeHtm,代码行数:25,代码来源:SpatialNode2DGaussian.cs


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