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


C# System.Matrix类代码示例

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


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

示例1: LoadContent

        protected override async Task LoadContent()
        {
            await base.LoadContent();

            wireframeState = new RasterizerStateDescription(CullMode.Back) { FillMode = FillMode.Wireframe };

            simpleEffect = new EffectInstance(new Effect(GraphicsDevice, SpriteEffect.Bytecode));

            // TODO GRAPHICS REFACTOR
            simpleEffect.Parameters.Set(TexturingKeys.Texture0, UVTexture);
            simpleEffect.UpdateEffect(GraphicsDevice);

            primitives = new List<GeometricPrimitive>();

            // Creates all primitives
            primitives = new List<GeometricPrimitive>
                             {
                                 GeometricPrimitive.Plane.New(GraphicsDevice),
                                 GeometricPrimitive.Cube.New(GraphicsDevice),
                                 GeometricPrimitive.Sphere.New(GraphicsDevice),
                                 GeometricPrimitive.GeoSphere.New(GraphicsDevice),
                                 GeometricPrimitive.Cylinder.New(GraphicsDevice),
                                 GeometricPrimitive.Torus.New(GraphicsDevice),
                                 GeometricPrimitive.Teapot.New(GraphicsDevice),
                                 GeometricPrimitive.Capsule.New(GraphicsDevice, 0.5f, 0.3f),
                                 GeometricPrimitive.Cone.New(GraphicsDevice)
                             };


            view = Matrix.LookAtRH(new Vector3(0, 0, 5), new Vector3(0, 0, 0), Vector3.UnitY);

            Window.AllowUserResizing = true;
        }
开发者ID:cg123,项目名称:xenko,代码行数:33,代码来源:TestGeometricPrimitives.cs

示例2: FromMatrix

 public void FromMatrix(ref Matrix matrix)
 {
     Position = matrix.Translation;
     Quaternion q;
     Quaternion.CreateFromRotationMatrix(ref matrix, out q);
     Orientation = new HalfVector4(q.ToVector4());
 }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:7,代码来源:CompressedPositionOrientation.cs

示例3: FindNearest

 /// <summary>
 /// For each input vector (which are rows of the matrix <paramref name="samples"/>) the method finds k &lt;= get_max_k() nearest neighbor. In case of regression, the predicted result will be a mean value of the particular vector's neighbor responses. In case of classification the class is determined by voting.
 /// </summary>
 /// <param name="samples">The sample matrix where each row is a sample</param>
 /// <param name="k">The number of nearest neighbor to find</param>
 /// <param name="results">
 /// Can be null if not needed.
 /// If regression, return a mean value of the particular vector's neighbor responses;
 /// If classification, return the class determined by voting.
 /// </param>
 /// <param name="kNearestNeighbors">Should be null if not needed. Setting it to non-null values incures a performance panalty. A matrix of (k * samples.Rows) rows and (samples.Cols) columns that will be filled the data of the K nearest-neighbor for each sample</param>
 /// <param name="neighborResponses">Should be null if not needed. The response of the neighbors. A vector of k*_samples->rows elements.</param>
 /// <param name="dist">Should be null if not needed. The distances from the input vectors to the neighbors. A vector of k*_samples->rows elements.</param>
 /// <returns>In case of regression, the predicted result will be a mean value of the particular vector's neighbor responses. In case of classification the class is determined by voting</returns>
 public float FindNearest(
     Matrix<float> samples,
     int k,
     Matrix<float> results,
     Matrix<float> kNearestNeighbors,
     Matrix<float> neighborResponses,
     Matrix<float> dist)
 {
     IntPtr[] neighbors = null;
      if (kNearestNeighbors != null)
      {
     Debug.Assert(kNearestNeighbors.Rows == k * samples.Rows && kNearestNeighbors.Cols == samples.Cols, "The kNeighbors must have (k*samples.Rows) rows and samples.Cols columns.");
     neighbors = new IntPtr[k * samples.Rows];
      }
      float res = MlInvoke.CvKNearestFindNearest(_ptr, samples.Ptr, k, results, neighbors, neighborResponses, dist);
      if (kNearestNeighbors != null)
      {
     IntPtr data; int step; Size size;
     CvInvoke.cvGetRawData(kNearestNeighbors.Ptr, out data, out step, out size);
     Int64 dataAddress = data.ToInt64();
     int elements = k * samples.Rows;
     int length = samples.Cols * sizeof(float);
     for (int i = 0; i < elements; i++)
     {
        Emgu.Util.Toolbox.memcpy(new IntPtr(dataAddress + i * step), neighbors[i], length);
     }
      }
      return res;
 }
开发者ID:samuto,项目名称:UnityOpenCV,代码行数:43,代码来源:KNearest.cs

示例4: InverseDeterminant

        public static void InverseDeterminant(Matrix matrix, out Matrix inverse, out double determinant)
        {
            int n = matrix.Rows;

            if (matrix.Columns != n)
            {
                throw new ArgumentException("The matrix isn't a square matrix.");
            }

            double[,] a = matrix.ToArray();

            if (!trfac.spdmatrixcholesky(ref a, n, false))
            {
                throw new ArithmeticException();
            }

            determinant = matdet.spdmatrixcholeskydet(ref a, n);

            int info = 0;
            matinv.matinvreport rep = new matinv.matinvreport();
            matinv.spdmatrixcholeskyinverse(ref a, n, false, ref info, ref rep);

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    a[i, j] = a[j, i];
                }
            }

            inverse = new Matrix(a);
        }
开发者ID:mortenbakkedal,项目名称:SharpMath,代码行数:32,代码来源:CholeskyDecomposition.cs

示例5: UserQR

        /// <summary>
        /// Initializes a new instance of the <see cref="UserQR"/> class. This object will compute the
        /// QR factorization when the constructor is called and cache it's factorization.
        /// </summary>
        /// <param name="matrix">The matrix to factor.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="matrix"/> is <c>null</c>.</exception>
        public UserQR(Matrix matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException("matrix");
            }

            if (matrix.RowCount < matrix.ColumnCount)
            {
                throw new ArgumentException(Resources.ArgumentMatrixDimensions);
            }

            MatrixR = matrix.Clone();
            MatrixQ = matrix.CreateMatrix(matrix.RowCount, matrix.RowCount);

            for (var i = 0; i < matrix.RowCount; i++)
            {
                MatrixQ.At(i, i, 1.0);
            }

            var minmn = Math.Min(matrix.RowCount, matrix.ColumnCount);
            var u = new double[minmn][];
            for (var i = 0; i < minmn; i++)
            {
                u[i] = GenerateColumn(MatrixR, i, matrix.RowCount - 1, i);
                ComputeQR(u[i], MatrixR, i, matrix.RowCount - 1, i + 1, matrix.ColumnCount - 1);
            }

            for (var i = minmn - 1; i >= 0; i--)
            {
                ComputeQR(u[i], MatrixQ, i, matrix.RowCount - 1, i, matrix.RowCount - 1);
            }
        }
开发者ID:rafaortega,项目名称:mathnet-numerics,代码行数:39,代码来源:UserQR.cs

示例6: TestInit

 public void TestInit()
 {
     var matrix = new Matrix<int>(5, 5);
     int[] row = { 2, 2, 2, 2, 2 };
     matrix.Init(2);
     Assert.AreEqual(row, matrix.GetRow(2));
 }
开发者ID:pipifuyj,项目名称:MyMediaLite,代码行数:7,代码来源:MatrixTest.cs

示例7: Matrix_Conversion_ToXna

        public void Matrix_Conversion_ToXna()
        {
            var matrix = new Matrix(
                11, 12, 13, 14,
                21, 22, 23, 24,
                31, 32, 33, 34,
                41, 42, 43, 44);

            XnaMatrix xnaMatrix = matrix.ToXna();

            Assert.AreEqual(matrix.R1C1, xnaMatrix.M11);
            Assert.AreEqual(matrix.R1C2, xnaMatrix.M12);
            Assert.AreEqual(matrix.R1C3, xnaMatrix.M13);
            Assert.AreEqual(matrix.R1C4, xnaMatrix.M14);

            Assert.AreEqual(matrix.R2C1, xnaMatrix.M21);
            Assert.AreEqual(matrix.R2C2, xnaMatrix.M22);
            Assert.AreEqual(matrix.R2C3, xnaMatrix.M23);
            Assert.AreEqual(matrix.R2C4, xnaMatrix.M24);

            Assert.AreEqual(matrix.R3C1, xnaMatrix.M31);
            Assert.AreEqual(matrix.R3C2, xnaMatrix.M32);
            Assert.AreEqual(matrix.R3C3, xnaMatrix.M33);
            Assert.AreEqual(matrix.R3C4, xnaMatrix.M34);

            Assert.AreEqual(matrix.R4C1, xnaMatrix.M41);
            Assert.AreEqual(matrix.R4C2, xnaMatrix.M42);
            Assert.AreEqual(matrix.R4C3, xnaMatrix.M43);
            Assert.AreEqual(matrix.R4C4, xnaMatrix.M44);
        }
开发者ID:Christof,项目名称:afterglow,代码行数:30,代码来源:Test_XnaExtensions.cs

示例8: CholeskyDecomposition

 /// <summary>
 /// Cholesky algorithm for symmetric and positive definite matrix.
 /// </summary>
 /// <param name="matrix">Square, symmetric matrix.</param>
 public CholeskyDecomposition(Matrix matrix)
 {
     // Initialize.
     double[][] a = matrix.Data;
     n = matrix.Rows;
     l = EngineArray.AllocateDouble2D(n, n);
     isspd = (matrix.Cols == n);
     // Main loop.
     for (int j = 0; j < n; j++)
     {
         double[] lrowj = l[j];
         double d = 0.0;
         for (int k = 0; k < j; k++)
         {
             double[] lrowk = l[k];
             double s = 0.0;
             for (int i = 0; i < k; i++)
             {
                 s += lrowk[i] * lrowj[i];
             }
             s = (a[j][k] - s) / l[k][k];
             lrowj[k] = s;
             d = d + s * s;
             isspd = isspd & (a[k][j] == a[j][k]);
         }
         d = a[j][j] - d;
         isspd = isspd & (d > 0.0);
         l[j][j] = Math.Sqrt(Math.Max(d, 0.0));
         for (int k = j + 1; k < n; k++)
         {
             l[j][k] = 0.0;
         }
     }
 }
开发者ID:kedrzu,项目名称:encog-dotnet-core,代码行数:38,代码来源:CholeskyDecomposition.cs

示例9: Test2

        public static void Test2()
        {
            const uint MARGIN = 1;

            Matrix mA = new Matrix(2 + MARGIN, 3 + MARGIN);
            Matrix mB = new Matrix(3, 2);
            Matrix mC = new Matrix(2, 2);

            mA.SetValue(0 + MARGIN, 0 + MARGIN, 0.11);
            mA.SetValue(0 + MARGIN, 1 + MARGIN, 0.12);
            mA.SetValue(0 + MARGIN, 2 + MARGIN, 0.13);
            mA.SetValue(1 + MARGIN, 0 + MARGIN, 0.21);
            mA.SetValue(1 + MARGIN, 1 + MARGIN, 0.22);
            mA.SetValue(1 + MARGIN, 2 + MARGIN, 0.23);

            mB.SetValue(0, 0, 1011);
            mB.SetValue(0, 1, 1012);
            mB.SetValue(1, 0, 1021);
            mB.SetValue(1, 1, 1022);
            mB.SetValue(2, 0, 1031);
            mB.SetValue(2, 1, 1032);

            MatrixView mViewA = new MatrixView(mA, MARGIN, MARGIN, mA.Columns - MARGIN, mA.Rows - MARGIN);
            MatrixView mViewB = new MatrixView(mB, 0, 0, mB.Columns, mB.Rows);
            MatrixView mViewC = new MatrixView(mC, 0, 0, mC.Columns, mC.Rows);
            Blas.DGemm(Blas.TransposeType.NoTranspose, Blas.TransposeType.NoTranspose, 1.0, mViewA, mViewB, 0.0, ref mViewC);

            Console.WriteLine(mC.GetValue(0, 0) + " , " + mC.GetValue(0, 1));
            Console.WriteLine(mC.GetValue(1, 0) + " , " + mC.GetValue(1, 1));
        }
开发者ID:mastobaev,项目名称:gsldotnet,代码行数:30,代码来源:BlasTester.cs

示例10: Test

        public static void Test()
        {
            Matrix mA = new Matrix(2, 3);
            Matrix mB = new Matrix(3, 2);
            Matrix mC = new Matrix(2, 2);

            mA.SetValue(0, 0, 0.11);
            mA.SetValue(0, 1, 0.12);
            mA.SetValue(0, 2, 0.13);
            mA.SetValue(1, 0, 0.21);
            mA.SetValue(1, 1, 0.22);
            mA.SetValue(1, 2, 0.23);

            mB.SetValue(0, 0, 1011);
            mB.SetValue(0, 1, 1012);
            mB.SetValue(1, 0, 1021);
            mB.SetValue(1, 1, 1022);
            mB.SetValue(2, 0, 1031);
            mB.SetValue(2, 1, 1032);

            Blas.DGemm(Blas.TransposeType.NoTranspose, Blas.TransposeType.NoTranspose, 1.0, mA, mB, 0.0, ref mC);

            Console.WriteLine(mC.GetValue(0, 0) + " , " + mC.GetValue(0, 1));
            Console.WriteLine(mC.GetValue(1, 0) + " , " + mC.GetValue(1, 1));
        }
开发者ID:mastobaev,项目名称:gsldotnet,代码行数:25,代码来源:BlasTester.cs

示例11: Classify

        /// <summary>
        /// Given an input feature, a feature space and its associated labels, and a positive integer 'k',
        /// Determines the 'k' nearest neighbor label for the input feature. The 'k' value corresponds
        /// to the number of nearest neighbors to use in the voting process.
        /// 
        /// <remarks> 
        /// "When I have this grid of data points, and I provide one additional example row, find the 'k' number
        /// of rows that are most similar, count up the number of occurrences of each label for each row (1 to 'k'), 
        /// and choose the label with the highest occurrence."
        /// </remarks> 
        /// <see href="http://en.wikipedia.org/wiki/K-nearest_neighbor_algorithm" />
        /// </summary>
        /// <param name="distanceType">The type of equation to use when measuring the distance between each data point</param>
        /// <param name="input">The matrix row to input; must have the same number of columns as the feature space</param>
        /// <param name="featureSpace">The feature space matrix; everything we know</param>
        /// <param name="labels">The results for each feature space row; what we call each collection of data points</param>
        /// <param name="k">The number of nearest neighbors to include in the voting; the label with the most occurrences in 'k' neighbors wins</param>
        /// <returns></returns>
        public static string Classify(DistanceType distanceType, Number[] input, Matrix featureSpace, IList<string> labels, int k)
        {
            if (labels.Count() != featureSpace.Rows)
            {
                throw new ArgumentException("The number of labels must match the number of rows of data in the feature space", "labels");
            }

            var distances = CalculateDistances(distanceType, featureSpace, input);

            var nearestNeighbors = distances.OrderByDescending(d => d.Value).Take(k);

            var votes = new Dictionary<string, int>(k);

            foreach (var label in nearestNeighbors.Select(neighbor => labels[neighbor.Key]))
            {
                if (votes.ContainsKey(label))
                {
                    votes[label]++;
                }
                else
                {
                    votes.Add(label, 1);
                }
            }

            var nearest = votes.OrderByDescending(v => v.Value).First().Key;

            return nearest;
        }
开发者ID:modulexcite,项目名称:graveyard,代码行数:47,代码来源:KNearestNeighbor.cs

示例12: AddChildShape

		public void AddChildShape(ref Matrix localTransform, CollisionShape shape)
		{
			m_updateRevision++;
			//m_childTransforms.push_back(localTransform);
			//m_childShapes.push_back(shape);
			CompoundShapeChild child = new CompoundShapeChild();
			child.m_transform = localTransform;
			child.m_childShape = shape;
			child.m_childShapeType = shape.ShapeType;
			child.m_childMargin = shape.Margin;

			//extend the local aabbMin/aabbMax
			Vector3 localAabbMin = new Vector3();
			Vector3 localAabbMax = new Vector3();
			shape.GetAabb(ref localTransform, ref localAabbMin, ref localAabbMax);
			MathUtil.VectorMin(ref localAabbMin, ref m_localAabbMin);
			MathUtil.VectorMax(ref localAabbMax, ref m_localAabbMax);

			if (m_dynamicAabbTree != null)
			{
				DbvtAabbMm bounds = DbvtAabbMm.FromMM(ref localAabbMin, ref localAabbMax);
				int index = m_children.Count;
				child.m_treeNode = m_dynamicAabbTree.Insert(ref bounds, (Object)index);
			}

			m_children.Add(child);
		}
开发者ID:HaKDMoDz,项目名称:InVision,代码行数:27,代码来源:CompoundShape.cs

示例13: HingeConstraint

		public HingeConstraint(RigidBody rigidBodyA, Matrix rigidBodyAFrame, bool useReferenceFrameA = false)
			: base(btHingeConstraint_new8(rigidBodyA._native, ref rigidBodyAFrame,
				useReferenceFrameA))
		{
			_rigidBodyA = rigidBodyA;
            _rigidBodyB = GetFixedBody();
		}
开发者ID:rhynodegreat,项目名称:BulletSharpPInvoke,代码行数:7,代码来源:HingeConstraint.cs

示例14: ComputeEnvLightsTiles

		/// <summary>
		/// 
		/// </summary>
		void ComputeEnvLightsTiles ( Matrix view, Matrix proj, LightSet lightSet )
		{
			var vp = Game.GraphicsDevice.DisplayBounds;

			envLightData = Enumerable
					.Range(0,RenderSystem.MaxEnvLights)
					.Select( i => new EnvLightGPU(){ Position = Vector4.Zero, Intensity = Vector4.Zero })
					.ToArray();

			int index = 0;

			foreach ( var light in lightSet.EnvLights ) {

				Vector4 min, max;

				var visible = GetSphereExtent( view, proj, light.Position, vp, light.RadiusOuter, out min, out max );

				/*if (!visible) {
					continue;
				} */

				envLightData[index].Position		=	new Vector4( light.Position, light.RadiusOuter );
				envLightData[index].Intensity		=	new Vector4( light.Intensity.ToVector3(), 1.0f / light.RadiusOuter / light.RadiusOuter );
				envLightData[index].ExtentMax		=	max;
				envLightData[index].ExtentMin		=	min;
				envLightData[index].InnerOuterRadius=	new Vector4( light.RadiusInner, light.RadiusOuter, 0, 0 );

				index++;
			}

			envLightBuffer.SetData( envLightData );
		}
开发者ID:demiurghg,项目名称:FusionEngine,代码行数:35,代码来源:LightRenderer.Tiles.cs

示例15: Main

        static void Main()
        {
            var myMatrix = new Matrix<double>(3, 3);

            helper.PrintColorText("Filling Matrix:\n\n", "cyan");

            for (int i = 0; i < myMatrix.Rows; i++)
            {
                for (int j = 0; j < myMatrix.Cols; j++)
                {
                    myMatrix[i, j] = (i + 1) * (j + 1);
                    helper.PrintColorText(myMatrix[i, j].ToString() + "\n", "green");
                }
            }

            Console.WriteLine();

            IIterator iterator = myMatrix.GetIterator();

            helper.PrintColorText("Iterationg Matrix in reverse:\n\n", "cyan");

            while (!iterator.IsDone())
            {
                helper.PrintColorText(iterator.CurrentItem().ToString() + "\n", "green");
                iterator.Next();
            }

            Console.WriteLine();
        }
开发者ID:kidroca,项目名称:high-quality-code-2015-homeworks,代码行数:29,代码来源:IteratorTests.cs


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