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


C# SparseMatrix类代码示例

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


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


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