• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SparseMatrix类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: CCSMatrix

        public CCSMatrix(SparseMatrix matrix, bool transponse)
        {
            // get number of non-zero elements
            m = matrix.ColumnSize;
            n = matrix.RowSize;
            int nnz = 0;
            foreach (List<SparseMatrix.Element> col in matrix.Columns) nnz += col.Count;

            // create temp arrays
            rowIndex = new int[nnz];
            colIndex = new int[n + 1];
            values = new double[nnz];

            // copy values to arrays
            int index = 0;
            int index2 = 0;
            colIndex[0] = 0;
            foreach (List<SparseMatrix.Element> row in matrix.Rows)
            {
                foreach (SparseMatrix.Element e in row)
                {
                    rowIndex[index] = e.j;
                    values[index] = e.value;
                    index++;
                }
                colIndex[++index2] = index;
            }
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:28,代码来源:CCSMatrix.cs


示例2: ComputeProbabilities

		void ComputeProbabilities(IList<int> users)
		{
			foreach (int user_id in users)
			{
				// initialize counter variables
				var user_class_counts = new int[ratings.Scale.Levels.Count];
				var user_attribute_given_class_counts = new SparseMatrix<int>(ratings.Scale.Levels.Count, ItemAttributes.NumberOfColumns);

				// count
				foreach (int index in ratings.ByUser[user_id])
				{
					int item_id = ratings.Items[index];
					int level_id = ratings.Scale.LevelID[ratings[index]];

					user_class_counts[level_id]++;
					foreach (int attribute_id in item_attributes.GetEntriesByRow(item_id))
						user_attribute_given_class_counts[attribute_id, level_id]++;
				}

				// compute probabilities
				float denominator = user_class_counts.Sum() + ClassSmoothing;

				foreach (int level_id in ratings.Scale.LevelID.Values)
				{
					user_class_probabilities[user_id, level_id] = (user_class_counts[level_id] + ClassSmoothing) / denominator;

					// TODO sparsify?
					for (int attribute_id = 0; attribute_id < NumItemAttributes; attribute_id++)
						user_attribute_given_class_probabilities[user_id][attribute_id, level_id]
							= (user_attribute_given_class_counts[attribute_id, level_id] + AttributeSmoothing) / (NumItemAttributes + AttributeSmoothing);
				}
			}
		}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:33,代码来源:NaiveBayes.cs


示例3: BuildLaplaceCot

 public SparseMatrix BuildLaplaceCot(TriMesh mesh)
 {
     int n = mesh.Vertices.Count;
     SparseMatrix L = new SparseMatrix(n, n);
     for (int i = 0; i < mesh.Faces.Count; i++)
     {
         int c1 = mesh.Faces[i].GetVertex(0).Index;
         int c2 = mesh.Faces[i].GetVertex(1).Index;
         int c3 = mesh.Faces[i].GetVertex(2).Index;
         Vector3D v1 = mesh.Faces[i].GetVertex(0).Traits.Position;
         Vector3D v2 = mesh.Faces[i].GetVertex(1).Traits.Position;
         Vector3D v3 = mesh.Faces[i].GetVertex(2).Traits.Position;
         double cot1 = (v2 - v1).Dot(v3 - v1) / (v2 - v1).Cross(v3 - v1).Length();
         double cot2 = (v3 - v2).Dot(v1 - v2) / (v3 - v2).Cross(v1 - v2).Length();
         double cot3 = (v1 - v3).Dot(v2 - v3) / (v1 - v3).Cross(v2 - v3).Length();
         L.AddValueTo(c1, c2, -cot3 / 2); L.AddValueTo(c2, c1, -cot3 / 2);
         L.AddValueTo(c2, c3, -cot1 / 2); L.AddValueTo(c3, c2, -cot1 / 2);
         L.AddValueTo(c3, c1, -cot2 / 2); L.AddValueTo(c1, c3, -cot2 / 2);
     }
     for (int i = 0; i < n; i++)
     {
         double sum = 0;
         foreach (SparseMatrix.Element e in L.Rows[i])
         {
             sum += e.value;
         }
         L.AddValueTo(i, i, -sum);
     }
     L.SortElement();
     return L; 
 }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:31,代码来源:LaplaceMatrix.cs


示例4: WriteMatrix

        public void WriteMatrix(ref SparseMatrix sparseMatrix, string modelName)
        {
            string fileName = Path.GetFileNameWithoutExtension(modelName);
            string path = GetPath() + fileName + ".matrix";

            WriteMatrix(sparseMatrix, path);
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:7,代码来源:IOHuizhao.cs


示例5: TestFrobeniusNorm

 public void TestFrobeniusNorm()
 {
     var matrix = new SparseMatrix<double>(5, 5);
     Assert.AreEqual(0, matrix.FrobeniusNorm());
     matrix[1, 1] = 5;
     Assert.AreEqual(Math.Sqrt(25), matrix.FrobeniusNorm());
 }
开发者ID:kinyue,项目名称:MyMediaLite,代码行数:7,代码来源:SparseMatrixExtensionsTest.cs


示例6: WriteSparseMatrix

		/// <summary>Write a sparse matrix of integers to a StreamWriter object</summary>
		/// <param name="writer">a <see cref="StreamWriter"/></param>
		/// <param name="matrix">the matrix of doubles to write out</param>
		static public void WriteSparseMatrix(this TextWriter writer, SparseMatrix<int> matrix)
		{
			writer.WriteLine(matrix.NumberOfRows + " " + matrix.NumberOfColumns);
			foreach (var index_pair in matrix.NonEmptyEntryIDs)
				writer.WriteLine(index_pair.Item1 + " " + index_pair.Item2 + " " + matrix[index_pair.Item1, index_pair.Item2].ToString());
			writer.WriteLine();
		}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:10,代码来源:MatrixExtensions.cs


示例7: TestFrobeniusNorm

		[Test()] public void TestFrobeniusNorm()
		{
			var float_matrix = new SparseMatrix<float>(5, 5);
			Assert.AreEqual(0, float_matrix.FrobeniusNorm());
			float_matrix[1, 1] = 5;
			Assert.AreEqual(Math.Sqrt(25), float_matrix.FrobeniusNorm());
		}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:7,代码来源:SparseMatrixExtensionsTest.cs


示例8: Factorization

        public void Factorization(SparseMatrix A)
        {
            TripletArraryData data = ConvertToTripletArrayData(A);

            int rowCount = A.Rows.Count;
            int columnCount = A.Columns.Count;
            int nnz = data.nnz;
            
            fixed (int* ri = data.rowIndex, ci = data.colIndex)
            fixed (double* val = data.values)
            {
                switch (SolverType)
                {
                    
                    case EnumSolver.UmfpackLU:
                        solver = CreateSolverLUUMFPACK(rowCount,  nnz, ri, ci, val);
                        break;
                    case EnumSolver.SuperLULU:
                        solver = CreateSolverLUSuperLU(rowCount, rowCount,  nnz, ri, ci, val);
                        break;
                    case EnumSolver.CholmodCholesky:
                        solver = CreateSolverCholeskyCHOLMOD(rowCount, rowCount,  nnz, nnz, ri, ci, val);
                        break;
                    case EnumSolver.SPQRLeastNormal:
                        solver = CreateSolverQRSuiteSparseQR(rowCount, columnCount,  nnz,  nnz, ri, ci, val);
                        break;
                    case EnumSolver.SPQRLeastSqure:
                        solver = CreateSolverQRSuiteSparseQR(rowCount, columnCount,  nnz,  nnz, ri, ci, val);
                        break;
                }

            }
            if (solver == null) throw new Exception("Create Solver Fail");
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:34,代码来源:LinearSystemLib.cs


示例9: LinerEquations

 /// <summary>
 /// 連立線形方程式を作成する
 /// </summary>
 /// <param name="count">未知数の数</param>
 /// <param name="maxNonZeroCount">0でない要素の最大数</param>
 public LinerEquations(int count, int maxNonZeroCount)
 {
     // 係数行列・未知数・右辺ベクトルを初期化
     this.A = new SparseMatrix(count, maxNonZeroCount);
     this.x = new double[count];
     this.b = new double[count];
 }
开发者ID:aokomoriuta,项目名称:ConjugateGradient,代码行数:12,代码来源:LinerEquations.cs


示例10: SolveLongMatrixThrowsArgumentException

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

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


示例11: TestIsSymmetric

		[Test()] public void TestIsSymmetric()
		{
			var matrix1 = new SparseMatrix<double>(3, 5);
			Assert.IsFalse(matrix1.IsSymmetric);

			var matrix2 = new SparseMatrix<double>(5, 5);
			Assert.IsFalse(matrix2.IsSymmetric);
		}
开发者ID:WisonHuang,项目名称:MyMediaLite,代码行数:8,代码来源:SparseMatrixTest.cs


示例12: SolveWideMatrixThrowsArgumentException

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

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


示例13: MultiplyByMatlab

        public SparseMatrix MultiplyByMatlab(SparseMatrix A, SparseMatrix B)
        {
            IOHuiZhao.Instance.WriteMatrix(ref A, "abf_A.matrix");
            IOHuiZhao.Instance.WriteMatrix(ref B, "abf_B.matrix");

            SparseMatrix C = IOHuiZhao.Instance.ReadMatrix("AB.matrix");

            return C;
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:9,代码来源:LinearSystemByMatlab.cs


示例14: 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 preconditioner, SparseMatrix matrix, Vector vector, Vector result)
 {
     Assert.AreEqual(typeof(UnitPreconditioner), 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:XiBeichuan,项目名称:hydronumerics,代码行数:16,代码来源:UnitPreconditionerTest.cs


示例15: ComputeEigensByLib

        public Eigen ComputeEigensByLib(SparseMatrix sparse, int count)
        {
            SparseMatrixDouble ds = new SparseMatrixDouble(sparse);
             

            Eigen eigen = ComputeEigensByLib(ds, 0.0, count);

            return eigen;
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:9,代码来源:LinearEigenVector.cs


示例16: TestNonEmptyRows

        public void TestNonEmptyRows()
        {
            var matrix  = new SparseMatrix<double>(3, 5);
            Assert.AreEqual(0, matrix .NonEmptyRows.Count);

            matrix [3, 1] = 1.0;
            Assert.AreEqual(1, matrix.NonEmptyRows.Count);
            Assert.AreEqual(3, matrix .NonEmptyRows[0].Key);
        }
开发者ID:zenogantner,项目名称:MML-KDD,代码行数:9,代码来源:SparseMatrixTest.cs


示例17: BuildLaplaceMatrixDual

        public SparseMatrix BuildLaplaceMatrixDual()
        {
            // build dual Laplacian weight matrix L

            int vn = this.Vertices.Count;
            int fn = this.Faces.Count;
            SparseMatrix L = new SparseMatrix(fn, vn, 6);

            for (int i = 0; i < fn; i++)
            {
                int f1 = this.Faces[i].GetFace(0).Index;
                int f2 = this.Faces[i].GetFace(1).Index;
                int f3 = this.Faces[i].GetFace(2).Index;

                Vector3D dv =  this.DualGetVertexPosition(i);
                Vector3D dv1 = this.DualGetVertexPosition(f1);
                Vector3D dv2 = this.DualGetVertexPosition(f2);
                Vector3D dv3 = this.DualGetVertexPosition(f3);
                Vector3D u = dv - dv3;
                Vector3D v1 = dv1 - dv3;
                Vector3D v2 = dv2 - dv3;
                Vector3D normal = (v1.Cross(v2)).Normalize();
                Matrix3D M = new Matrix3D(v1, v2, normal);
                Vector3D coord = M.Inverse() * u;
                double alpha;

                alpha = 1.0 / 3.0;

                L.AddValueTo(i, this.Faces[i].GetVertex(0).Index, alpha);
                L.AddValueTo(i, this.Faces[i].GetVertex(1).Index, alpha);
                L.AddValueTo(i, this.Faces[i].GetVertex(2).Index, alpha);

                alpha = coord[0] / 3.0;

                L.AddValueTo(i, this.Faces[f1].GetVertex(0).Index, -alpha);
                L.AddValueTo(i, this.Faces[f1].GetVertex(1).Index, -alpha);
                L.AddValueTo(i, this.Faces[f1].GetVertex(2).Index, -alpha);

                alpha = coord[1] / 3.0;

                L.AddValueTo(i, this.Faces[f2].GetVertex(0).Index, -alpha);
                L.AddValueTo(i, this.Faces[f2].GetVertex(1).Index, -alpha);
                L.AddValueTo(i, this.Faces[f2].GetVertex(2).Index, -alpha);

                alpha = (1.0 - coord[0] - coord[1]) / 3.0;

                L.AddValueTo(i, this.Faces[f3].GetVertex(0).Index, -alpha);
                L.AddValueTo(i, this.Faces[f3].GetVertex(1).Index, -alpha);
                L.AddValueTo(i, this.Faces[f3].GetVertex(2).Index, -alpha);


            }

            L.SortElement();
            return L;
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:56,代码来源:TriMeshDual.cs


示例18: 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:XiBeichuan,项目名称:hydronumerics,代码行数:15,代码来源:PreConditionerTest.cs


示例19: ComputeEigensByMatLab

        public Eigen ComputeEigensByMatLab(SparseMatrix sparse, int count, string modelName)
        {


            IOHuiZhao.Instance.WriteMatrix(ref sparse, modelName);

            Eigen eigen = IOHuiZhao.Instance.ReadEigen(modelName);

            return eigen;
        }
开发者ID:meshdgp,项目名称:MeshDGP,代码行数:10,代码来源:LinearSystemByMatlab.cs


示例20: RapportManager

        public RapportManager(ConversationManager parent, DM_TYPE type = DM_TYPE.RULE_BASED)
        {
            _parent = parent;
            _type = type;
            _dialoguePolicy = new SparseMatrix<DialogueState, DialogueAction>();
            _dialogueState = new DialogueState();
            _agentID = parent.getAgentID();

            _parent.DSUpdated += new DSUpdatedEventHandler(DSUpdated);
        }
开发者ID:hanshan3290,项目名称:AndroidStudioApp,代码行数:10,代码来源:RapportManager.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SparseStream类代码示例发布时间:2022-05-24
下一篇:
C# SparseCompressedRowMatrixStorage类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap