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


C# GeneralMatrix.Multiply方法代码示例

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


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

示例1: CalculateNextHessianApproximation

        protected override GeneralMatrix CalculateNextHessianApproximation(GeneralMatrix previousH, 
			double[]prevX, double[]curX, double[]prevGrad, double[]curGrad)
        {
            GeneralMatrix currentH = new GeneralMatrix(_nDim,_nDim);
            GeneralMatrix cX = new GeneralMatrix(curX,_nDim);
            GeneralMatrix pX = new GeneralMatrix(prevX,_nDim);
            GeneralMatrix cG = new GeneralMatrix(curGrad,_nDim);
            GeneralMatrix pG = new GeneralMatrix(prevGrad,_nDim);

            GeneralMatrix dX = cX.Subtract(pX);
            GeneralMatrix dG = cG.Subtract(pG);

            double aK1 = 1/(dX.Transpose().Multiply(dG).GetElement(0,0));
            GeneralMatrix aK2 = dX.Multiply(dX.Transpose());

            GeneralMatrix aK = aK2.Multiply(aK1);

            double bK1 = -1/(dG.Transpose().Multiply(previousH).Multiply(dG).GetElement(0,0));
            GeneralMatrix bK2 = previousH.Multiply(dG).Multiply(dG.Transpose()).Multiply(previousH.Transpose());

            GeneralMatrix bK =bK2.Multiply(bK1);

            currentH = previousH.Add(aK).Add(bK);

            return currentH;
        }
开发者ID:kriskniaz,项目名称:pCode,代码行数:26,代码来源:DFP.cs

示例2: CholeskyDecomposition2

 public void CholeskyDecomposition2()
 {
     double[][] pvals = {new double[]{1.0, 1.0, 1.0}, new double[]{1.0, 2.0, 3.0}, new double[]{1.0, 3.0, 6.0}};
     GeneralMatrix A = new GeneralMatrix(pvals);
     CholeskyDecomposition chol = A.chol();
     GeneralMatrix X = chol.Solve(GeneralMatrix.Identity(3, 3));
     Assert.IsTrue(GeneralTests.Check(A.Multiply(X), GeneralMatrix.Identity(3, 3)));
 }
开发者ID:kriskniaz,项目名称:pCode,代码行数:8,代码来源:LinearAlgebraTests.cs

示例3: CalculateNextHessianApproximation

        protected override GeneralMatrix CalculateNextHessianApproximation(GeneralMatrix pH, 
			double[]prevX, double[]curX, double[]prevGrad, double[]curGrad)
        {
            GeneralMatrix cH = new GeneralMatrix(_nDim,_nDim);
            GeneralMatrix cX = new GeneralMatrix(curX,_nDim);
            GeneralMatrix pX = new GeneralMatrix(prevX,_nDim);
            GeneralMatrix cG = new GeneralMatrix(curGrad,_nDim);
            GeneralMatrix pG = new GeneralMatrix(prevGrad,_nDim);

            GeneralMatrix sigma = cX.Subtract(pX);
            GeneralMatrix gamma = cG.Subtract(pG);

            double sigmaTGamma = sigma.Transpose().Multiply(gamma).GetElement(0,0);

            GeneralMatrix hGammaSigmaT = pH.Multiply(gamma.Multiply(sigma.Transpose()));
            GeneralMatrix sigmaGammaTH = sigma.Multiply(gamma.Transpose().Multiply(pH));
            double gammaTHGamma = (gamma.Transpose().Multiply(pH.Multiply(gamma))).GetElement(0,0);
            GeneralMatrix sigmaSigmaT  = sigma.Multiply(sigma.Transpose());

            GeneralMatrix term1 = (hGammaSigmaT.Add(sigmaGammaTH)).Multiply(1/sigmaTGamma);
            GeneralMatrix term2 = (sigmaSigmaT.Multiply(1/sigmaTGamma)).Multiply(1+gammaTHGamma/sigmaTGamma);

            return pH.Subtract(term1).Add(term2);
        }
开发者ID:kriskniaz,项目名称:pCode,代码行数:24,代码来源:BFGS.cs

示例4: EigenValueDecomposition2

 public void EigenValueDecomposition2()
 {
     double[][] evals = {new double[]{0.0, 1.0, 0.0, 0.0}, new double[]{1.0, 0.0, 2e-7, 0.0}, new double[]{0.0, - 2e-7, 0.0, 1.0}, new double[]{0.0, 0.0, 1.0, 0.0}};
     GeneralMatrix A = new GeneralMatrix(evals);
     EigenvalueDecomposition Eig = A.Eigen();
     GeneralMatrix D = Eig.D;
     GeneralMatrix V = Eig.GetV();
     Assert.IsTrue(GeneralTests.Check(A.Multiply(V), V.Multiply(D)));
 }
开发者ID:kriskniaz,项目名称:pCode,代码行数:9,代码来源:LinearAlgebraTests.cs

示例5: Main


//.........这里部分代码省略.........
                check(C, O);
                try_success("ArrayRightDivide... ", "");
            }
            catch (System.SystemException e)
            {
                errorCount = try_failure(errorCount, "ArrayRightDivide... ", "(M./M != ones)");
                System.Console.Out.WriteLine(e.Message);
            }
            try
            {
                A.ArrayRightDivideEquals(S);
                errorCount = try_failure(errorCount, "ArrayRightDivideEquals conformance check... ", "nonconformance not raised");
            }
            catch (System.ArgumentException e)
            {
                try_success("ArrayRightDivideEquals conformance check... ", "");
                System.Console.Out.WriteLine(e.Message);
            }
            A.ArrayRightDivideEquals(R);
            try
            {
                check(A, O);
                try_success("ArrayRightDivideEquals... ", "");
            }
            catch (System.SystemException e)
            {
                errorCount = try_failure(errorCount, "ArrayRightDivideEquals... ", "(M./M != ones)");
                System.Console.Out.WriteLine(e.Message);
            }
            A = R.Copy();
            B = GeneralMatrix.Random(A.RowDimension, A.ColumnDimension);
            try
            {
                S = A.ArrayMultiply(S);
                errorCount = try_failure(errorCount, "arrayTimes conformance check... ", "nonconformance not raised");
            }
            catch (System.ArgumentException e)
            {
                try_success("arrayTimes conformance check... ", "");
                System.Console.Out.WriteLine(e.Message);
            }
            C = A.ArrayMultiply(B);
            try
            {
                check(C.ArrayRightDivideEquals(B), A);
                try_success("arrayTimes... ", "");
            }
            catch (System.SystemException e)
            {
                errorCount = try_failure(errorCount, "arrayTimes... ", "(A = R, C = A.*B, but C./B != A)");
                System.Console.Out.WriteLine(e.Message);
            }
            try
            {
                A.ArrayMultiplyEquals(S);
                errorCount = try_failure(errorCount, "ArrayMultiplyEquals conformance check... ", "nonconformance not raised");
            }
            catch (System.ArgumentException e)
            {
                try_success("ArrayMultiplyEquals conformance check... ", "");
                System.Console.Out.WriteLine(e.Message);
            }
            A.ArrayMultiplyEquals(B);
            try
            {
                check(A.ArrayRightDivideEquals(B), R);
开发者ID:eylvisaker,项目名称:tbsuite,代码行数:67,代码来源:TestMatrix.cs

示例6: Encrypt

        //encrypt line of input
        static void Encrypt(string input, GeneralMatrix key, Dictionary<char, int> hillDict, StringBuilder encText)
        {
            string ct = "";
            string[] pt = input.Trim().Split(' ');
            for (int i = 0; i < pt.Length; i += 3)
            {
                //encrypt 3 letters at a time
                double[] temp = new double[3];
                temp[0] = Convert.ToInt32(pt[i]);
                temp[1] = Convert.ToInt32(pt[i + 1]);
                temp[2] = Convert.ToInt32(pt[i + 2]);

                //create plain text matrix, transpose and encrypt it
                GeneralMatrix ptMat = new GeneralMatrix(new double[] { temp[0], temp[1], temp[2] }, 3);
                GeneralMatrix trnasPTMat = ptMat.Transpose();
                GeneralMatrix ctMat = key.Multiply(ptMat);
                for (int x = 0; x < ctMat.RowDimension; x++)
                {
                    for (int y = 0; y < ctMat.ColumnDimension; y++)
                    {
                        var tempElement = Convert.ToInt32(ctMat.GetElement(x, y)) % 31;
                        ctMat.SetElement(x, y, tempElement);
                    }
                }

                for (int x = 0; x < ctMat.RowDimension; x++)
                {
                    for (int y = 0; y < ctMat.ColumnDimension; y++)
                    {
                        ct += hillDict.FirstOrDefault(z => z.Value == ctMat.GetElement(x, y)).Key;
                    }
                }
            }
            //append to string builder
            encText.AppendLine(ct);
        }
开发者ID:b-esf,项目名称:Crypto,代码行数:37,代码来源:Program.cs

示例7: Rotate

        public void Rotate(double sineAngle, double cosineAngle)
        {
            double[][] temp = new double[2][];
            temp[0] = new double[2];
            temp[1] = new double[2];
            temp[0][0] = cosineAngle;
            temp[0][1] = -sineAngle;
            temp[1][0] = sineAngle;
            temp[1][1] = cosineAngle;

            GeneralMatrix rotationMatrix = new GeneralMatrix(temp);
            GeneralMatrix newVector = rotationMatrix.Multiply(this.ToMatrix());
            this.X = newVector.GetElement(0, 0);
            this.Y = newVector.GetElement(1, 0);
        }
开发者ID:TanjaStojanovska,项目名称:VP_Arkanoid_Game,代码行数:15,代码来源:Vector2D.cs

示例8: FCalc

 /// <summary>
 /// multiply normalized priority matrix by sum of average rows 
 /// </summary>
 /// <param name="argMatrix"></param>
 /// <param name="selection"></param>
 /// <returns></returns>
 private GeneralMatrix FCalc(GeneralMatrix argMatrix, GeneralMatrix selection)
 {
     GeneralMatrix matrix = argMatrix.Multiply(selection);
     return (matrix.ArrayRightDivide(selection));
 }
开发者ID:kriskniaz,项目名称:pCode,代码行数:11,代码来源:PrioritiesSelector.cs

示例9: GetFiles_Decompose_WriteToArff


//.........这里部分代码省略.........
                frV = pinv(rV.Transpose());
                fgV = pinv(gV.Transpose());
                fbV = pinv(bV.Transpose());

                // Stores frV, fgV and fbV to file
                WriteToFile();

                Console.WriteLine("SVD finished");
                DisplayMessage("SVD finished, load full dataset for testing");

                Console.WriteLine("Begin filling dataset for testing");

                // fill the 'full' datasets
                dataRed = new GeneralMatrix(galaxyData.Count(), imageScaleSize
                        * imageScaleSize);
                dataGreen = new GeneralMatrix(galaxyData.Count(), imageScaleSize
                        * imageScaleSize);
                dataBlue = new GeneralMatrix(galaxyData.Count(), imageScaleSize
                        * imageScaleSize);

                System.Threading.Tasks.Parallel.For(0, galaxyData.Count(), (int index) => {
                    Bitmap tempImage = getImage(OutputDir + "galaxies/"
                            + galaxyData[index][0] + ".jpg", imageScaleSize);

                    for (int i = 0; i < imageScaleSize; i++) {
                        for (int j = 0; j < imageScaleSize; j++) {
                            int pixelColor = tempImage.GetPixel(i, j).ToArgb();
                            int[] rgb = new int[3];
                            rgb[0] += ((pixelColor & 0x00ff0000) >> 16);
                            rgb[1] += ((pixelColor & 0x0000ff00) >> 8);
                            rgb[2] += (pixelColor & 0x000000ff);

                            dataRed.SetElement(index, i * imageScaleSize + j, rgb[0]);
                            dataGreen.SetElement(index, i * imageScaleSize + j,
                                    rgb[1]);
                            dataBlue.SetElement(index, i * imageScaleSize + j, rgb[2]);
                        }
                    }

                });

                Console.WriteLine("Finished filling dataset for testing");
                DisplayMessage("Finished filling dataset for testing, begin projecting galaxies to U coordinate system");

                Console.WriteLine("Begin projecting galaxies to U coordinate system, writing to ARFF file");

                // Do the coordinate conversion
                rV = dataRed.Multiply(frV);
                gV = dataGreen.Multiply(fgV);
                bV = dataBlue.Multiply(fbV);

                Console.Write("Dim Final rU: " + rV.ColumnDimension
                        + ", " + rV.RowDimension);
                Console.WriteLine("galaxyData.Count(): " + galaxyData.Count());

                // write to the output file here:
                for (int imageIndex = 0; imageIndex < galaxyData.Count(); imageIndex++) {

                    Bitmap tempImage = getImage(OutputDir + "galaxies/"
                            + galaxyData[imageIndex][0] + ".jpg", imageScaleSize);

                    float colorFactor = (GetColor(tempImage)[0] / GetColor(tempImage)[2]);
                    float centralBulgeFactor = getCentralBulge(tempImage);
                    float consistencyFactor = GetConsistency(tempImage);

                    output.Write(galaxyData[imageIndex][1] + ", ");
                    output.Write(colorFactor + ", ");
                    output.Write(centralBulgeFactor + ", ");
                    output.Write(consistencyFactor + ", ");

                    // output data (r,g,b)
                    for (int i = 0; i < rV.ColumnDimension; i++) {
                        output.Write(rV.GetElement(imageIndex, i) + ", ");
                        output.Write(gV.GetElement(imageIndex, i) + ", ");
                        if (i == rV.ColumnDimension - 1) {
                            output.Write(bV.GetElement(imageIndex, i) + "\n");
                        }
                        else {
                            output.Write(bV.GetElement(imageIndex, i) + ", ");
                        }
                    }

                    //if (imageIndex % (galaxyData.Count() / 100) == 0)
                    //    DisplayImage(imageIndex);
                    DisplayMessage("Finished galaxy " + imageIndex.ToString() + " - " + (100 * imageIndex / galaxyData.Count()).ToString() + "%");

                }

                output.Flush();
                output.Close();
                output.Dispose();

                Console.Write("Finished creating arff file...");
                DisplayMessage("Finished creating arff file...");

            }
            catch (Exception ex) {
                Console.Write(ex.ToString());
            }
        }
开发者ID:Samangan,项目名称:automatic-galaxy-classification-tool,代码行数:101,代码来源:Logic.cs

示例10: ClassifyGroup

        private void ClassifyGroup(string[] images, string filePath, StreamWriter output, int groupNum)
        {
            // fill the 'full' datasets
            dataRed = new GeneralMatrix(images.Count(), imageScaleSize
                    * imageScaleSize);
            dataGreen = new GeneralMatrix(images.Count(), imageScaleSize
                    * imageScaleSize);
            dataBlue = new GeneralMatrix(images.Count(), imageScaleSize
                    * imageScaleSize);

            //create the entire size of the dataset
            System.Threading.Tasks.Parallel.For(0, images.Count(), (int imageIndex) => {
                Bitmap tempImage = getImage(images[imageIndex], imageScaleSize);

                for (int i = 0; i < imageScaleSize; i++) {
                    for (int j = 0; j < imageScaleSize; j++) {
                        int pixelColor = tempImage.GetPixel(i, j).ToArgb();
                        int[] rgb = new int[3];
                        rgb[0] += ((pixelColor & 0x00ff0000) >> 16);
                        rgb[1] += ((pixelColor & 0x0000ff00) >> 8);
                        rgb[2] += (pixelColor & 0x000000ff);

                        dataRed.SetElement(imageIndex, i * imageScaleSize + j, rgb[0]);
                        dataGreen.SetElement(imageIndex, i * imageScaleSize + j,
                                rgb[1]);
                        dataBlue.SetElement(imageIndex, i * imageScaleSize + j, rgb[2]);
                    }
                }
                Console.WriteLine("SDSS Galaxy " + imageIndex + " put in main dataset");
            });

            //then convert the whole dataset to the same coordinate
            // Do the coordinate conversion
            GeneralMatrix rV = dataRed.Multiply(frV);
            GeneralMatrix gV = dataGreen.Multiply(fgV);
            GeneralMatrix bV = dataBlue.Multiply(fbV);

            Console.WriteLine("Dim Final rU: " + rV.ColumnDimension
                    + ", " + rV.RowDimension);
            Console.WriteLine("images.length: " + images.Count());

            // write to the output file here:
            for (int imageIndex = 0; imageIndex < images.Count(); imageIndex++) {

                Bitmap tempImage = getImage(images[imageIndex], imageScaleSize);

                float colorFactor = (GetColor(tempImage)[0] / GetColor(tempImage)[2]);
                float centralBulgeFactor = getCentralBulge(tempImage);
                float consistencyFactor = GetConsistency(tempImage);

                output.Write(-999 + ", ");

                output.Write(colorFactor + ", ");
                output.Write(centralBulgeFactor + ", ");
                output.Write(consistencyFactor + ", ");

                // output data (r,g,b)
                for (int i = 0; i < rV.ColumnDimension; i++) {
                    output.Write(rV.GetElement(imageIndex, i) + ", ");
                    output.Write(gV.GetElement(imageIndex, i) + ", ");
                    if (i == rV.ColumnDimension - 1) {
                        output.Write(bV.GetElement(imageIndex, i) + "\n");
                    }
                    else {
                        output.Write(bV.GetElement(imageIndex, i) + ", ");
                    }
                }

                Console.WriteLine("Creating ARFF classification file - " + (100 * imageIndex / images.Count()).ToString() + "%");
            }
        }
开发者ID:Samangan,项目名称:automatic-galaxy-classification-tool,代码行数:71,代码来源:Logic.cs

示例11: CalculateNextPoint

        private double[] CalculateNextPoint(double[] pX, double[] pGrad, GeneralMatrix hessian)
        {
            int i=0;
            double xmin=0;
            double step = _step;
            GeneralMatrix alfaX = new GeneralMatrix(_nDim,1);
            GeneralMatrix prevX = new GeneralMatrix(pX,_nDim);
            GeneralMatrix prevGrad = new GeneralMatrix(pGrad,_nDim);
            double[] intermediate = new double[_nDim];;

            alfaX = hessian.Multiply(prevGrad);

            //doing a line search to minimize alpha
            OneDWrapper wrapper = new OneDWrapper(_f,prevX,alfaX);
            LineSearch search = new LineSearch();
            double[] interval = new double[Constants.BRACKET_POINTS];
            int it1 = search.FindMinInterval(wrapper,_alpha,step,50,ref interval);
            int it2 = search.FindMinimumViaBrent(wrapper,interval[0],interval[1],interval[2],50,_epsilon, ref xmin);

            for (i=0;i<_nDim; i++)
                intermediate[i] = prevX.GetElement(i,0) - xmin*alfaX.GetElement(i,0);

            _alpha = xmin;

            return intermediate;
        }
开发者ID:kriskniaz,项目名称:pCode,代码行数:26,代码来源:Optimizer.cs

示例12: calculateR

        private double[][] calculateR()
        {
            sourceCount = sourceASTL.abstractLatticeGraph.VertexCount;
            targetCount = targetASTL.abstractLatticeGraph.VertexCount;

            GeneralMatrix newR = new GeneralMatrix(sourceCount * targetCount, 1);
            GeneralMatrix myA = new GeneralMatrix(A);

            //initial R
            for (int i = 0; i < newR.RowDimension; i++)
            {
                newR.SetElement(i, 0, 1.0 / newR.RowDimension);
            }

            //printMatrix(vector2Matrix(newR.Array, 0));

            //move similarity matrix to a double index vector
            GeneralMatrix newSim = new GeneralMatrix(sourceCount * targetCount, 1);

            for (int i = 0; i < sourceCount; i++)
                for (int j = 0; j < targetCount; j++)
                {
                    newSim.SetElement(targetCount * i + j, 0, simMatrix[i, j]);
                }

            //move structure similarity matrix to a double index vector
            GeneralMatrix newStructSim = new GeneralMatrix(sourceCount * targetCount, 1);

            //for (int i = 0; i < sourceCount; i++)
            //    for (int j = 0; j < targetCount; j++)
            //    {
               //         newStructSim.SetElement(targetCount * i + j, 0, structSimMatrix[i, j]);
            //    }

            //calculate R using power method (eigen vector)
            //==========================================

            int count = 0;
            while (count < 50)
            {
                //R = aAR + (1-2a)E1 + (1-2a)E2 where a = 0.333
                //newR = (((myA.Multiply(newR)).Multiply(0.333)).Add(newStructSim.Multiply(0.333))).Add(newSim.Multiply(0.333));//ommited to have name similarity only 17/4/2012
                newR = (((myA.Multiply(newR)).Multiply(0.5)).Add(newSim.Multiply(0.5)));

                double sum = 0;
                for (int i = 0; i < newR.RowDimension; i++)
                    for (int j = 0; j < newR.ColumnDimension; j++)
                        sum += newR.GetElement(i, j);

                newR = newR.Multiply(1.0 / sum);

                count++;
            }

            return newR.Array;
        }
开发者ID:imanavaz,项目名称:CONVErT,代码行数:56,代码来源:IsoRankSuggester.cs


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