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


C# Matrix.Transpose方法代码示例

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


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

示例1: Bfgs

        /// <summary>
        /// Computes the BFGS correction formula for inverse hessiana approximation.
        /// </summary>
        /// <param name="func">Function to find it the hessiana approximation.</param>
        /// <param name="b">Current inverse approximation of the hessiana.</param>
        /// <param name="x">Current vector of the minimization Quasi-Newton algorithm.</param>
        /// <param name="x1">Next vector of the minimization Quasi-Newton algorithm.</param>
        /// <returns>Returns a matrix representing the next step in inverse hessiana approximation.s</returns>
        public static Matrix Bfgs(CompiledFunc func, Matrix b, Vector x, Vector x1)
        {
            var sk = new Matrix(x1 - x);
            var yk = new Matrix(func.Differentiate(x1) - func.Differentiate(x));

            var t = b.Dot(sk.Transpose()).Dot(sk).Dot(b)/sk.Dot(b).Dot(sk.Transpose())[0,0];
            var t1 = yk.Transpose().Dot(yk)/yk.Dot(sk.Transpose())[0,0];

            return b - t + t1;
        }
开发者ID:renehernandez,项目名称:SharpOptimization,代码行数:18,代码来源:RangeCorrection.cs

示例2: Transformation

        private Matrix Transformation(Matrix A, Matrix U, Matrix axt, Matrix wxt, Matrix ayt, Matrix wyt)
        {
            var fx_aff = axt * MatrixUtils.RankVertical(Ones(1, A.Rows), A.Transpose());
            var fx_wrp = wxt * U;
            var fx = fx_aff + fx_wrp; //fx=fx_aff+fx_wrp;

            // fy_aff=cy(n_good+1:n_good+3)'*[ones(1,nsamp1); X'];
            var fy_aff = ayt * MatrixUtils.RankVertical(Ones(1, A.Rows), A.Transpose());
            var fy_wrp = wyt * U; // fy_wrp=cy(1:n_good)'*U;
            var fy = fy_aff + fy_wrp; // fy=fy_aff+fy_wrp;

            return MatrixUtils.RankVertical(fx, fy).Transpose();
        }
开发者ID:pakerliu,项目名称:sharp-context,代码行数:13,代码来源:Transformation.cs

示例3: Main

        static void Main()
        {
            int[,] matrix1 = new int[,]
            {
                {1, 2, -3},
                {2, 1, 3},
                {3, 1, 2}
            };

            int[,] matrix2 = new int[,]
            {
                {4, 5, 6},
                {-1, 0, 7},
                {3, 2, 1}
            };

            Matrix<int> m1 = new Matrix<int>(matrix1);
            Matrix<int> m2 = new Matrix<int>(matrix2);

            Console.WriteLine(m1 + m2);
            Console.WriteLine(m1 - m2);
            Console.WriteLine(m1 * m2);
            Console.WriteLine(m1.Transpose());
            Console.WriteLine(m1 * 5);
        }
开发者ID:ekostadinov,项目名称:CoursesProjects,代码行数:25,代码来源:MainProg.cs

示例4: Draw

        public static void Draw(RenderContext11 renderContext, PositionColoredTextured[] points, int count, Matrix mat, bool triangleStrip)
        {
            if (VertexBuffer == null)
            {
                VertexBuffer = new Buffer(renderContext.Device, System.Runtime.InteropServices.Marshal.SizeOf(points[0]) * 2500, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, System.Runtime.InteropServices.Marshal.SizeOf(points[0]));
                VertexBufferBinding = new VertexBufferBinding(VertexBuffer, System.Runtime.InteropServices.Marshal.SizeOf((points[0])), 0);

            }

            renderContext.devContext.InputAssembler.PrimitiveTopology = triangleStrip ? SharpDX.Direct3D.PrimitiveTopology.TriangleStrip : SharpDX.Direct3D.PrimitiveTopology.TriangleList;
            renderContext.BlendMode = BlendMode.Alpha;
            renderContext.setRasterizerState(TriangleCullMode.Off);

            mat.Transpose();

            WarpOutputShader.MatWVP = mat;
            WarpOutputShader.Use(renderContext.devContext, false);

            renderContext.SetVertexBuffer(VertexBufferBinding);

            DataBox box = renderContext.devContext.MapSubresource(VertexBuffer, 0, MapMode.WriteDiscard, MapFlags.None);
            Utilities.Write(box.DataPointer, points, 0, count);

            renderContext.devContext.UnmapSubresource(VertexBuffer, 0);

            renderContext.devContext.PixelShader.SetShaderResource(0, null);

            renderContext.devContext.Draw(count, 0);
        }
开发者ID:china-vo,项目名称:wwt-windows-client,代码行数:29,代码来源:Sprite2d.cs

示例5: GradientDescent

        private static Tuple<Vector<double>, double[]> GradientDescent(Matrix<double> x, Vector<double> y, Vector<double> theta, double alpha, int numberOfIterations)
        {
            var m = y.Count;
            var jHistory = new double[numberOfIterations];

            for (int i = 0; i < numberOfIterations; i++)
            {
                theta = theta - (alpha / m) * x.Transpose() * (x * theta - y);
            }

            return Tuple.Create(theta, jHistory);
        }
开发者ID:jgera,项目名称:MachineLearning,代码行数:12,代码来源:Program.cs

示例6: GradientDescent

        /// <summary>
        /// Uses gradient descent to calculate the "theta" vector.
        /// On each iteration gets calculated as per
        /// 
        ///		theta = theta - (alpha/m)*(X*theta - Y)'*X
        /// 
        /// </summary>
        private void GradientDescent(Input input)
        {
            var monitor = new CostFunctionMonitor(input);

            _theta = new DenseMatrix(1, input.FeaturesCount);

            var multiplier = (Settings.LearningRate / input.SamplesCount);
            for (int i = 0; i < Settings.MaxIterations; i++) {
                _theta -= multiplier * ((input.X * _theta.Transpose() - input.Y).Transpose() * input.X);
                if (monitor.IsConverged(_theta)) {
                    break;
                }
            }
        }
开发者ID:andreister,项目名称:NMachine,代码行数:21,代码来源:LinearRegression.cs

示例7: Main

        static void Main(string[] args)
        {
            //test constructor
            var matr = new Matrix<int>(4, 5);
            //test indexer
            matr[3, 4] = 8;
            Console.WriteLine("{0}", matr[3, 4]);
            //test ToString override
            Console.WriteLine(matr);

            double[,] first = { { 0, 2, 3, 8 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 }, { 1, 2, 3, 4 } };
            double[,] second = { { 1, 2, 3, 8 }, { 1, 2, 3, 6 }, { 1, 2, 8, 4 }, { 1, 0, 3, 4 } };
            //test constructor2
            Matrix<double> arrFirst = new Matrix<double>(first);
            Matrix<double> arrSecond = new Matrix<double>(second);
            Console.WriteLine(arrFirst);
            Console.WriteLine(arrSecond);

            //test operator true
            if (arrFirst)
            {
                Console.WriteLine("There is no zero inside");
            }
            else Console.WriteLine("There is at least one zero inside\n");
            Console.WriteLine("Sum of the two matrices");
            //test opretor +
            Console.WriteLine(arrFirst + arrSecond);
            Console.WriteLine("Substraction of the two matrices");
            //test opreator -
            Console.WriteLine(arrFirst - arrSecond);
            Console.WriteLine("Multiplication of the two matrices");
            //test operator *
            Console.WriteLine(arrFirst * arrSecond);

            Console.WriteLine("Transposed matrix:");
            Matrix<double> transposed = arrFirst.Transpose();
            Console.WriteLine(transposed);
        }
开发者ID:denjai,项目名称:TU-Plovdiv,代码行数:38,代码来源:Example.cs

示例8: AdvancedOptimization

        private static Vector<double> AdvancedOptimization(Matrix<double> x, Vector<double> y, Vector<double> theta, double lambda)
        {
            var m = x.RowCount;
            var featureCount = theta.Count;
            var xTranspose = x.Transpose();

            // TODO: convert all of this to use MicrosoftResearch.Infer.Maths instead of MathNet.Numerics
            var solver = new MicrosoftResearch.Infer.Maths.BFGS();
            var minTheta = solver.Run(
                MicrosoftResearch.Infer.Maths.DenseVector.FromList(theta),
                10000,
                (Vector vector, ref Vector dX) =>
                    {
                        var newTheta = DenseVector.Create(featureCount, n => vector[n]);

                        var regTheta = DenseVector.OfVector(newTheta);
                        regTheta[0] = 0;

                        var regThetaSq = DenseVector.OfVector(regTheta);
                        regThetaSq.MapInplace(t => t * t);

                        var h = x * newTheta - y;

                        var cost = ((h * h) / (2D * m)) + ((lambda / (2D * m)) * regThetaSq.Sum());

                        var grad = ((1D / m) * (xTranspose * h)) + ((lambda / m) * regTheta);

                        for (var j = 0; j < grad.Count; j++)
                        {
                            dX[j] = grad[j];
                        }

                        return cost;
                    });

            return DenseVector.Create(theta.Count, i => minTheta[i]);
        }
开发者ID:jgera,项目名称:MachineLearning,代码行数:37,代码来源:Program.cs

示例9: Simple

        public void Simple()
        {
            var matrix = new Matrix(3, 3);

            // [ 1,  4,  7 ]
            // [ 2,  5,  8 ]
            // [ 3,  6,  9 ]

            matrix[0, 0] = 1;
            matrix[0, 1] = 4;
            matrix[0, 2] = 7;

            matrix[1, 0] = 0;
            matrix[1, 1] = 5;
            matrix[1, 2] = 8;

            matrix[2, 0] = 0;
            matrix[2, 1] = 0;
            matrix[2, 2] = 0;

            Assert.AreEqual(matrix.IsTriangular, TriangularMatrixType.Upper);
            matrix = matrix.Transpose();
            Assert.AreEqual(matrix.IsTriangular, TriangularMatrixType.Lower);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:24,代码来源:IsTriangular.cs

示例10: Render

        public void Render(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture)
        {
            worldMatrix.Transpose();
            viewMatrix.Transpose();
            projectionMatrix.Transpose();
            // Lock the constant memory buffer so it can be written to.
            DataStream mappedResource;
            deviceContext.MapSubresource(ConstantMatrixBuffer, MapMode.WriteDiscard, SharpDX.Direct3D11.MapFlags.None, out mappedResource);

            // Copy the transposed matrices (because they are stored in column-major order on the GPU by default) into the constant buffer.
            var matrixBuffer = new MatrixBuffer
            {
                world = worldMatrix,
                view = viewMatrix,
                projection = projectionMatrix
            };
            mappedResource.Write(matrixBuffer);

            // Unlock the constant buffer.
            deviceContext.UnmapSubresource(ConstantMatrixBuffer, 0);

            // Set the position of the constant buffer in the vertex shader.
            const int bufferNumber = 0;

            // Finally set the constant buffer in the vertex shader with the updated values.
            deviceContext.VertexShader.SetConstantBuffer(bufferNumber, ConstantMatrixBuffer);

            // Set shader resource in the pixel shader.
            deviceContext.PixelShader.SetShaderResource(0, texture);

            // Set the vertex input layout.
            deviceContext.InputAssembler.InputLayout = Layout;

            // Set the vertex and pixel shaders that will be used to render this triangle.
            deviceContext.VertexShader.Set(VertexShader);
            deviceContext.PixelShader.Set(PixelShader);

            // Set the sampler state in the pixel shader.
            deviceContext.PixelShader.SetSampler(0, SamplerState);

            // Render the triangle.
            deviceContext.DrawIndexed(indexCount, 0, 0);
        }
开发者ID:ndech,项目名称:PlaneSimulator,代码行数:43,代码来源:TextureShader.cs

示例11: TestTransposeFloatMatrix

      public void TestTransposeFloatMatrix()
      {
         using (Matrix<float> mat = new Matrix<float>(1, 3))
         {
            mat.SetRandUniform(new MCvScalar(-1000.0), new MCvScalar(1000.0));

            Matrix<float> matT = mat.Transpose();

            for (int i = 0; i < matT.Rows; i++)
               for (int j = 0; j < matT.Cols; j++)
                  EmguAssert.AreEqual(matT[i, j], mat[j, i]);
         }
      }
开发者ID:neutmute,项目名称:emgucv,代码行数:13,代码来源:AutoTestMatrix.cs

示例12: GetWeights

        public static Vector<double> GetWeights(Matrix<double> data, Vector<double> targetClassification)
        {            
            var features = data.ColumnCount;

            // these are things we are trying to solve for
            Vector<double> weights = DenseVector.Create(features, i => 1.0);

            var alpha = 0.001;

            foreach (var cycle in Enumerable.Range(0, 500))
            {
                #region Sigmoid Explanation

                /*
                 * multiply all the data by the weights, this gives you the estimation of the current function
                 * given the weights. multiplying by the sigmoid moves a point into one class vs the other
                 * if its larger than 0.5 it'll be in class 1, if its smaller than it'll be in class 0.  The closer it is
                 * to 1 means that with the given weights that value is highly probably to be in class 1.
                 * 
                 * it doesn't matter if the instance is the class the sigmoid says it is,
                 * the error will shift the weights gradient so over the iterations of the cycles 
                 * the weights will move the final data point towards its actual expected class
                 * 
                 * for example, if there is a data point with values    
                 * 
                 * [1.0, -0.017612, 14.053064]
                 * 
                 * where value 1 is the initial weight factor, and values 2 and 3 are the x y coordinates
                 *  
                 * and lets say the point is categorized at class 0.
                 * 
                 * Calculating the initial sigma gives you something like 0.9999998
                 * 
                 * which says its class 1, but thats obviously wrong.  However, the error rate here is large
                 * 
                 * meaning that the gradient wants to move towards the expected data.  
                 * 
                 * As you run the ascent this data point will get smaller and smaller and eventually
                 * 
                 * the sigmoid will classify it properly
                 */

                #endregion

                var currentData = DenseVector.OfEnumerable(data.Multiply(weights).Select(Sigmoid));
               
                #region Error Explanation

                // find out how far off we are from the actual expectation. this is
                // like the x2 - x1 part of a derivative

                #endregion

                var error = targetClassification.Subtract(currentData);

                #region Gradient Explanation

                // this gives you the direction of change from the current 
                // set of data.  At this point every point is moving in the direction
                // of the error rate.  A large error means we are far off and trying to move
                // towards the actual data, a low error rate means we are really close
                // to the target data (so the gradient will be smaller, meaning less delta)

                #endregion

                var gradient = data.Transpose() * error;

                #region Weights Update Explanation

                // multiplying by alpha means we'll take a small step in the direction
                // of the gradient and add it to the current weights. An initial weights of 1.0
                // means we're going to start at the current location of where we are.

                #endregion

                weights = weights + alpha * gradient;
            }

            return weights;
        }
开发者ID:Gabo1988,项目名称:Playground,代码行数:80,代码来源:GradientRunner.cs

示例13: SetShaderParameters

        /// <summary>
        /// Binds the shader and world matricies.
        /// </summary>
        /// <param name="context">The context to draw from.</param>
        /// <param name="world">The world <see cref="Matrix"/> to draw from.</param>
        /// <param name="view">The view <see cref="Matrix"/> to use for transforms.</param>
        /// <param name="projection">The projection <see cref="Matrix"/> to use for transforms.</param>
        /// <returns></returns>
        private bool SetShaderParameters(DeviceContext context, Matrix world, Matrix view, Matrix projection)
        {
            try
            {
                world.Transpose();
                view.Transpose();
                projection.Transpose();

                context.VertexShader.Set(vertexShader);
                context.PixelShader.Set(pixelShader);

                DataStream mappedResource;
                context.MapSubresource(matrixBuffer, 0, MapMode.WriteDiscard, MapFlags.None, out mappedResource);

                mappedResource.Write(world);
                mappedResource.Write(view);
                mappedResource.Write(projection);

                context.UnmapSubresource(matrixBuffer, 0);

                context.VertexShader.SetConstantBuffers(0, matrixBuffer);

                context.InputAssembler.InputLayout = layout;

                return true;
            }
            catch(Exception)
            {
                return false;
            }
        }
开发者ID:Earthmark,项目名称:RenderTest,代码行数:39,代码来源:ColorShader.cs

示例14: MatrixTransposeDimensions

        public void MatrixTransposeDimensions()
        {
            var matrix = new Matrix(2, 3);

            var transpose = matrix.Transpose();

            Assert.AreEqual(3, transpose.Rows);
            Assert.AreEqual(2, transpose.Columns);
        }
开发者ID:renehernandez,项目名称:SharpOptimization,代码行数:9,代码来源:MatrixTest.cs

示例15: MatrixTransposeValues

        public void MatrixTransposeValues()
        {
            var matrix = new Matrix(new []{1, 2}, new []{3, 4});

            var transpose = matrix.Transpose();

            Assert.AreEqual(1, transpose[0, 0]);
            Assert.AreEqual(2, transpose[1, 0]);
            Assert.AreEqual(3, transpose[0, 1]);
            Assert.AreEqual(4, transpose[1, 1]);
        }
开发者ID:renehernandez,项目名称:SharpOptimization,代码行数:11,代码来源:MatrixTest.cs


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