⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.java,v

📁 包含了模式识别中常用的一些分类器设计算法
💻 JAVA,V
📖 第 1 页 / 共 3 页
字号:
	    }	}    }        /**     * this routine computes the inverse of a matrix     *     * @@param    A inverse matrix     */    public void invertMatrix(Matrix A)     {	if ((A == null) || (row != col)) 	{	    return;	}	// declare a unit matrix	//	Matrix T = new Matrix();	T.Elem = new double[row][row];	T.row = T.col = row;	T.identityMatrix();	// allocate memory	//	A.row = A.col = row;	A.Elem = new double[row][row];	// make a local copy of the matrix	//	A.copyMatrix(this);	// find the inverse of the matrix	//	gaussj(A.Elem, row, T.Elem, row);	    }    /**     * This routine takes a matrix as an argument and copies it to the     * the matrix object that invoked it     *     */    public void resetMatrix()     {	for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] = 0.0;	    }	}    }    /**     *  This routine adds two matrices     *     * @@param    A matrix to be added to object evoked     *     */    public void addMatrix(Matrix A)     {	if (A == null)         {	    return;	}	if( (row != A.row) || (col != A.col) ) 	{	    return;	}	else 	{	   	    for(int i = 0; i < row; i++ ) 	    {		for(int j = 0; j < col; j++) 		{		    Elem[i][j] += A.Elem[i][j];		}	    }	}    }    /**     *  This routine subtracts two matrices     *     * @@param     A input matrix     * @@param     B difference matrix     */    public void subtractMatrix(Matrix A, Matrix B)     {	if(A == null || B == null) 	{	    return;	}	if( (row != A.row) || (col != A.col) ) 	{	    return;	}	else         {	    B.row = row;	    B.col = col;	    B.Elem = new double[row][col];	    for(int i = 0; i < row; i++ ) 	    {		for(int j = 0; j < col; j++) 		{		    B.Elem[i][j] = Elem[i][j] - A.Elem[i][j];		}	    }	}    }        /**     * This routine multiplys a matrix with a scalar     *     * @@param    scalar matrix double scalar value     *     */    public void scalarMultMatrix(double scalar)     {		for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] *= scalar;	    }	}    }    /**     * This routine takes the square root of the matrix object     *     */    public void normMatrix()     {		for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] = Math.sqrt(Elem[i][j]);	    }	}    }    /**     * This routine takes every element to its exponent with Math.exp()     *     */    public void expMatrix()     {		for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] = Math.exp(Elem[i][j]);	    }	}    }        /**     * This routine inverses every element of the matrix     *     */    public void inverseMatrixElements()     {		for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] = 1/Elem[i][j];	    }	}    }    /**     * This routine adds a double value to every element in a matrix     *     * @@param    val_a double value to be added to every element     */    public void addMatrixElements(double val_a)     {		for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		Elem[i][j] += val_a;	    }	}    }    /**     *  This routine multiplys two matrices     *     * @@param    A input matrix     * @@param    B product matrix     */    public void multMatrix(Matrix A, Matrix B)     {	if(A == null || B == null) 	{	    // System.out.println(" A == null || B == null");	    Exception e = new Exception();	    e.printStackTrace();	    return;	}	if(col != A.row ) 	{	    // System.out.println(" col != A.row ");	    Exception e = new Exception();	    e.printStackTrace();	    return;	}	else         {	    B.row = row;	    B.col = A.col;	    B.Elem = new double[row][A.col];	    for(int i = 0; i < B.row; i++ ) 	    {		for(int j = 0; j < B.col; j++) 		{		    		    B.Elem[i][j] = 0.0;		    for(int k = 0; k < col; k++ ) 		    {			B.Elem[i][j] += Elem[i][k] * A.Elem[k][j];		    }		}	    }	}    }        /**     * This routine performs the transpose of a matrix     *     * @@param    B matrix transpose     *     */    public void transposeMatrix(Matrix B)     {	if(B == null) 	{	    return;	}	B.row = col;	B.col = row;	B.Elem = new double[col][row];	for(int i = 0; i < row; i++ ) 	{	    for(int j = 0; j < col; j++) 	    {		B.Elem[j][i] = Elem[i][j];	    }	}    }    /**     * Prints the matrix contents to STDOUT     *     */    public void printMatrix()     {	for(int i = 0; i < row; i++) 	{	    for(int j = 0; j < col; j++) 	    {		// System.out.print(Elem[i][j] + " " );	    }	    // System.out.print("\n");	}	// System.out.print("\n");    }    /**     * Puts the DoubleVector contents in a vector and calls printMatrix()     *     * @@param vec_a Vector to be printed     */    public static void printDoubleVector(Vector<Double> vec_a)     {	Matrix temp_M = new Matrix();	temp_M.initMatrix(vec_a);	temp_M.printMatrix();    }}@1.5log@Fixed javadoc comments.@text@d7 1d207 1a207 1    public void initMatrix(Vector vec_a) d230 1a230 1    public void initDiagonalMatrix(Vector vec_a) d249 1a249 1    public void getDiagonalVector(Vector vec_a) d266 1a266 1    public void toDoubleVector(Vector vec_a) d393 1a393 1     * @@param  in_vec input vector of matrix typea679 6     * method: invertMatrix     *     * @@param    Matrix A: inverse matrix     *     * @@return   none     *d682 1d971 1a971 1    public static void printDoubleVector(Vector vec_a) @1.4log@comments changed to Java Documentation Style.@text@d4 1a16 2 * class: Matrix *d55 1a55 9     * method: getNumRows     *     * @@param    double value_a: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   none     *     * this function initialize the matrixd57 1d65 1a65 7     * method: getNumColumns     *     * @@param    double value_a: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   noned67 1a67 1     * this function initialize the matrixa75 6     * method: copyLowerMatrix     *     * @@param    Matrix A: inverse matrix     *     * @@return   none     *d78 1d100 1a100 1     * method: getColSumSquared102 1a102 1     * @@param    Matrix A: inverse matrixd104 1a104 3     * @@return   none     *     * this routine computes the inverse of a matrixd123 1a123 1     * method: setValued125 3a127 7     * @@param    double value_a: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   none     *     * this function initialize the matrixd136 1a136 1     * method: getValued138 2a139 7     * @@param    double value_a: input get of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   none     *     * this function initialize the matrixd141 1d149 2a150 5     * method: initMatrix     *     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrixd152 4a155 1     * @@return   nonea156 1     * this function initialize the matrixd177 1a177 9     * method: initMatrix     *     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   none     *     * this function initialize the matrixd179 3d201 1a201 1     * method: initMatrixd203 1a203 7     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   none     *     * this function initialize the matrixd224 1a224 7     * method: intDiagonalMatrix     *     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   noned226 1a226 1     * this function initialize the matrixd243 1a243 7     * method: getDiagonalVector     *     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   noned245 1a245 1     * this function initialize the matrixd260 1a260 7     * method: toVector     *     * @@param    double initVal: input set of points     * @@param    int r: number of rows in the matrix     * @@param    int c: number of columns in the matrix     *     * @@return   noned262 1a262 1     * this function initialize the matrixd300 1a300 7     * method: copyMatrix     *     * @@param    Matrix A: matrix copy     *     * @@return   none     *     * this routine takes a matrix as an argument and copies it to thed303 1d323 7a329 9     * method: copyMatrix     *     * @@param    Matrix A: matrix copy     *     * @@return   none     *     * this routine takes a matrix as an argument and copies it to the     * the matrix object that invoked it     *d362 1a362 6     * method: identityMatrix     *     * @@param    none     * @@return   none     *     * this routine creates a identity matrixd387 2a388 7     * method: choleskySolve     *     * @@param   MVector<TScalar, TIntegral>& out_vec: (output) output vector     * @@param   const MMatrix<TScalar, TIntegral>& l: (input) lower triangular     *                                            cholesky decomposition matrix     * @@param   const MVector<TScalar, TIntegral>& in_vec: (output)      *                                             input vectord390 3a392 4     * @@return  a boolean value indicating status     *     * this method solves the linear equation l * l' * x = b, where L is the     * cholesky decomposition matrix and b is an input vector.d394 1a453 7     * method: decompositionCholesky     *     * @@param  const MMatrix<TScalar, TIntegral>& this: (input) input matrix     * @@param  MMatrix<TScalar, TIntegral>& l: (output) lower triangular matrix     *     * @@return a boolean value indicating status     *d463 3d571 1a571 10     *  method: gaussj     *     * @@param    double a: input matrix     * @@param    int n: number of rows and columns in the input matrix     * @@param    double b: output matrix     * @@param    int m:  number of rows and columns in the output matrix     *     * @@return   none     *      * this routine computes the inverse matrix using the gauss jordan methodd575 4d718 1a718 6     * method: resetMatrix     *     * @@param    none     * @@return   none     *     * this routine takes a matrix as an argument and copies it to thed735 1a735 1     * method: addMatrixd737 1a737 5     * @@param    Matrix A: sum matrix     *     * @@return   none     *     *  this routine adding two matricesd765 1a765 8     * method: subtractMatrix     *     * @@param     Matrix A: input matrix     * @@param     Matrix B: difference matrix     *     * @@return   none     *     *  thid routine subtracts two matricesd767 2d799 1a799 1     * method: scalarMultMatrixd801 1a801 6     * @@param      * @@param    double scalar: matrix scalar value     *     * @@return   none     *     * this routine multiplys a matrix with a scalard817 1a817 7     * method: normMatrix     *     * @@param     double scalar: matrix scalar value     *     * @@return   none     *     * this routine multiplys a matrix with a scalard833 1a833 7     * method: expMatrix     *     * @@param    double scalar: matrix scalar value     *     * @@return   none     *     * this routine multiplys a matrix with a scalard849 1a849 7     * method: inverseMatrixElement     *     * @@param    double scalar: matrix scalar value     *     * @@return   none     *     * this routine multiplys a matrix with a scalard865 1a865 7     * method: addMatrixElement     *     * @@param    double scalar: matrix scalar value     *     * @@return   none     *     * this routine multiplys a matrix with a scalard867 1d882 1a882 8     * method: multMatrix     *     * @@param    Matrix A: input matrix     * @@param    Matrix B: product matrix     *     * @@return   none     *     *  this routine multiplys two matricesd884 2d926 1a926 5     * method: transposeMatrix     *     * @@param    Matrix B: matrix transpose     *     * @@return   noned928 1a928 1     * this routine performs the transpose of a matrixd953 1a953 6     * method: printMatrix     *     * @@param    none     * @@return   none     *     * print the matrix contemts to STDOUTd971 1a971 6     * method: printDoubleVector     *     * @@param    none     * @@return   none     *     * print the DoubleVector contemts to STDOUTd973 1@1.3log@All the system print commands have been commented. There was a mistakeat line 987, which was unknowingly commented.The line related to closing of method printMatrix was uncommented.@text@d1 5a5 2// file: Matrix.java//d15 9a23 7// class: Matrix//// this class represents a matrix object and performs matrix operations // that are needed to compute the eigenvectors and eigenvalues//public class Matrix {d55 14a68 13    // method: getNumRows    //    // arguments:     //    double value_a: input set of points    //    int r: number of rows in the matrix    //    int c: number of columns in the matrix    //    // returns  : none    //    // this function initialize the matrix    //    public int getNumRows() {	a69 1	d72 14a85 13    // method: getNumColumns    //    // arguments:     //    double value_a: input set of points    //    int r: number of rows in the matrix

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -