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


C# Matrix.SetColumn方法代码示例

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


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

示例1: TestAreEqual

		public void TestAreEqual()
		{
			var m1 = new Matrix(3, 3);
			m1.SetColumn(0, 1, 4, 7);
			m1.SetColumn(1, 2, 5, 8);
			m1.SetColumn(2, 3, 6, 9);

			var m2 = new Matrix(3, 3);
			m2.SetRow(0, 1, 2, 3);
			m2.SetRow(1, 4, 5, 6);
			m2.SetRow(2, 7, 8, 9);

			Assert.IsTrue(Matrix.AreEqual(m1, m2));

			m2[1, 1] = 0;
			Assert.IsFalse(Matrix.AreEqual(m1, m2));
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:17,代码来源:MatrixTests.cs

示例2: TestGetSetColumn

 public void TestGetSetColumn()
 {
     var matrix = new Matrix<int>(5, 5);
     int[] column = { 1, 2, 3, 4, 5 };
     matrix.SetColumn(3, column);
     Assert.AreEqual(column, matrix.GetColumn(3));
     Assert.AreEqual(0, matrix[0, 0]);
     Assert.AreEqual(1, matrix[0, 3]);
 }
开发者ID:pipifuyj,项目名称:MyMediaLite,代码行数:9,代码来源:MatrixTest.cs

示例3: TestSubtract

		public void TestSubtract()
		{
			Matrix m1 = new Matrix(3, 3);
			m1.SetColumn(0, 2.2F, -6.1F, -7.6F);
			m1.SetColumn(1, -3.4F, 7.2F, 8.7F);
			m1.SetColumn(2, 1.6F, 5.5F, -9.8F);

			Matrix m2 = new Matrix(3, 3);
			m2.SetRow(0, -1.1F, 2.6F, -7.1F);
			m2.SetRow(1, 4.6F, -3.7F, 9.1F);
			m2.SetRow(2, 4.1F, -3.1F, 7.7F);

			Matrix result = new Matrix(3, 3);
			result.SetRow(0, 3.3F, -6F, 8.7F);
			result.SetRow(1, -10.7F, 10.9F, -3.6F);
			result.SetRow(2, -11.7F, 11.8F, -17.5F);

			Assert.IsTrue(Matrix.AreEqual(m1 - m2, result));
		}
开发者ID:nhannd,项目名称:Xian,代码行数:19,代码来源:MatrixTests.cs

示例4: TestAdd

		public void TestAdd()
		{
			Matrix m1 = new Matrix(3, 3);
			m1.SetColumn(0, 2.2F, -6.1F, -7.6F);
			m1.SetColumn(1, -3.4F, 7.2F, 8.7F);
			m1.SetColumn(2, 1.6F, 5.5F, -9.8F);

			Matrix m2 = new Matrix(3, 3);
			m2.SetRow(0, -1.1F, 2.6F, -7.1F);
			m2.SetRow(1, 4.6F, -3.7F, 9.1F);
			m2.SetRow(2, 4.1F, -3.1F, 7.7F);

			Matrix result = new Matrix(3, 3);
			result.SetRow(0, 1.1F, -0.8F, -5.5F);
			result.SetRow(1, -1.5F, 3.5F, 14.6F);
			result.SetRow(2, -3.5F, 5.6F, -2.1F);

			Assert.IsTrue(Matrix.AreEqual(m1 + m2, result));
		}
开发者ID:nhannd,项目名称:Xian,代码行数:19,代码来源:MatrixTests.cs

示例5: TestConstructor

		public void TestConstructor()
		{
			var m = new Matrix(3, 3);
			m.SetColumn(0, 0, 0, 0);
			m.SetColumn(1, 0, 0, 0);
			m.SetColumn(2, 0, 0, 0);
			Assert.IsTrue(Matrix.AreEqual(m, new Matrix(3, 3)));

			m.SetRow(0, 1, 2, 3);
			m.SetRow(1, 4, 5, 6);
			m.SetRow(2, 7, 8, 9);
			Assert.IsTrue(Matrix.AreEqual(m, new Matrix(new float[,] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}})));
			Assert.IsTrue(Matrix.AreEqual(m, new Matrix(new Matrix(new float[,] {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}))));

			try
			{
				new Matrix(0, 0);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}

			try
			{
				new Matrix(new Matrix(4, -5));
				Assert.Fail("Expected an exception");
			}
            catch (ArgumentException) { }

			try
			{
				new Matrix((Matrix) null);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentNullException) {}

			try
			{
				new Matrix((float[,]) null);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentNullException) {}
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:42,代码来源:MatrixTests.cs

示例6: Transpose

 public Matrix Transpose()
 {
     Matrix m = new Matrix(this.Length, 1);
     m.SetColumn(1, this.m_data);
     return m;
 }
开发者ID:pirzada,项目名称:sinapse,代码行数:6,代码来源:Vector.cs

示例7: TestColumnSetter

		public void TestColumnSetter()
		{
			Matrix m = new Matrix(3, 1);
			m.SetColumn(0, 1F, 2F, 3F);

			//too many.
			m.SetColumn(0, 1F, 2F, 3F, 4F);
		}
开发者ID:nhannd,项目名称:Xian,代码行数:8,代码来源:MatrixTests.cs

示例8: TestTranspose

		public void TestTranspose()
		{
			Matrix m = new Matrix(2, 3);
			m.SetRow(0, -1.1F, 2.6F, -7.1F);
			m.SetRow(1, 4.6F, -3.7F, 9.1F);

			Matrix result = new Matrix(3, 2);
			result.SetColumn(0, -1.1F, 2.6F, -7.1F);
			result.SetColumn(1, 4.6F, -3.7F, 9.1F);

			Assert.IsTrue(Matrix.AreEqual(m.Transpose(), result));
		}
开发者ID:nhannd,项目名称:Xian,代码行数:12,代码来源:MatrixTests.cs

示例9: LearnUserAttributeToFactorMapping

        void LearnUserAttributeToFactorMapping()
        {
            // no mapping of no user attributes present
            if (user_attributes.NumberOfEntries == 0)
                return;

            // create attribute-to-factor weight matrix
            this.user_attribute_to_factor = new Matrix<float>(NumUserAttributes + 1, num_factors);
            Console.Error.WriteLine("num_user_attributes=" + NumUserAttributes);
            // store the results of the different runs in the following array
            var old_user_attribute_to_factor = new Matrix<float>[num_init_mapping];

            Console.Error.WriteLine("Will use {0} examples ...", num_iter_mapping * MaxUserID);

            var old_rmse_per_factor = new double[num_init_mapping][];

            for (int h = 0; h < num_init_mapping; h++)
            {
                user_attribute_to_factor.InitNormal(InitMean, InitStdDev);
                Console.Error.WriteLine("----");

                for (int i = 0; i < num_iter_mapping * MaxUserID; i++)
                    UpdateUserMapping();
                ComputeUserMappingFit();

                old_user_attribute_to_factor[h] = new Matrix<float>(user_attribute_to_factor);
                old_rmse_per_factor[h] = ComputeUserMappingFit();
            }

            var min_rmse_per_factor = new double[num_factors];
            for (int i = 0; i < num_factors; i++)
                min_rmse_per_factor[i] = double.MaxValue;
            var best_factor_init = new int[num_factors];

            // find best factor mappings:
            for (int i = 0; i < num_init_mapping; i++)
            {
                for (int j = 0; j < num_factors; j++)
                {
                    if (old_rmse_per_factor[i][j] < min_rmse_per_factor[j])
                    {
                        min_rmse_per_factor[j] = old_rmse_per_factor[i][j];
                        best_factor_init[j]    = i;
                    }
                }
            }

            // set the best weight combinations for each factor mapping
            for (int i = 0; i < num_factors; i++)
            {
                Console.Error.WriteLine("Factor {0}, pick {1}", i, best_factor_init[i]);
                user_attribute_to_factor.SetColumn(i, old_user_attribute_to_factor[best_factor_init[i]].GetColumn(i));
            }

            Console.Error.WriteLine("----");
            ComputeUserMappingFit();

            ComputeFactorsForNewUsers();
        }
开发者ID:wendelad,项目名称:RecSys,代码行数:59,代码来源:BPRMF_Mapping.cs

示例10: Hminired

        private Matrix Hminired(Matrix A)
        {
            //function A=hminired(A)
            //%HMINIRED Initial reduction of cost matrix for the Hungarian method.
            //%
            //%B=assredin(A)
            //%A - the unreduced cost matris.
            //%B - the reduced cost matrix with linked zeros in each row.

            //% v1.0  96-06-13. Niclas Borlin, [email protected]

            //[m,n]=size(A);
            int m = A.Rows, n = A.Columns;

            //% Subtract column-minimum values from each column.
            //colMin=min(A);
            var colMin = new DenseVector(A.GetColumns().Select(col => col.Min()).ToArray());
            //A=A-colMin(ones(n,1),:);
            for (int i = 0; i < A.Rows; ++i) {
                A.SetRow(i, A.GetRow(i) - colMin);
            }

            //% Subtract row-minimum values from each row.
            //rowMin=min(A')';
            var rowMin = new DenseVector(A.GetRows().Select(row => row.Min()).ToArray());
            //A=A-rowMin(:,ones(1,n));
            for (int j = 0; j < A.Rows; ++j) {
                A.SetColumn(j, A.GetColumn(j) - rowMin);
            }

            //% Get positions of all zeros.
            //[i,j]=find(A==0);
            List<int> ilist = new List<int>();
            List<int> jlist = new List<int>();
            A.EachT((v, i, j) => {
                if (v == 0) {
                    ilist.Add(i);
                    jlist.Add(j);
                }
            });

            //% Extend A to give room for row zero list header column.
            //A(1,n+1)=0;
            Matrix tmp = Zeros(n, n + 1);
            tmp.SetSubMatrix(0, n, 0, n, A);
            //for k=1:n
            for (int k = 0; k < n; ++k) {
                //    % Get all column in this row.
                //    cols=j(k==i)';
                var cols = new List<int>();
                cols.Add(n);
                for (int i = 0; i < ilist.Count; ++i) {
                    if (ilist[i] == k) {
                        cols.Add(jlist[i]);
                    }
                }
                cols.Add(-1);

                //    % Insert pointers in matrix.
                //    A(k,[n+1 cols])=[-cols 0];
                for (int i = 0; i < cols.Count - 1; ++i) {
                    tmp[k, cols[i]] = -(cols[i + 1]) - 1;
                } // TODO 不知道对不对了
                //result[k, cols[cols.Count - 1]] = 0;
                //end
            }
            var result = tmp.Each(v => {
                if (v < 0) return v + 1;
                else if (v == 0) return NoMatch;
                else return v;
            });

            return result;
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:74,代码来源:Hungarian.cs

示例11: TestColumnSetter

		public void TestColumnSetter()
		{
			Matrix m = new Matrix(3, 1);
			m.SetColumn(0, 1F, 2F, 3F);

			try
			{
				//too many.
				m.SetColumn(0, 1F, 2F, 3F, 4F);
				Assert.Fail("Expected an exception");
			}
			catch (ArgumentException) {}
		}
开发者ID:UIKit0,项目名称:ClearCanvas,代码行数:13,代码来源:MatrixTests.cs


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