com.hankcs.hanlp.dependency.nnparser
类 Matrix

java.lang.Object
  继承者 com.hankcs.hanlp.dependency.nnparser.Matrix
所有已实现的接口:
ICacheAble, Serializable, Cloneable

public class Matrix
extends Object
implements Cloneable, Serializable, ICacheAble

Jama = Java Matrix class.

The Java Matrix Class provides the fundamental operations of numerical linear algebra. Various constructors create Matrices from two dimensional arrays of double precision floating point numbers. Various "gets" and "sets" provide access to submatrices and matrix elements. Several methods implement basic matrix arithmetic, including matrix addition and multiplication, matrix norms, and element-by-element array operations. Methods for reading and printing matrices are also included. All the operations in this version of the Matrix Class involve real matrices. Complex matrices may be handled in a future version.

Five fundamental matrix decompositions, which consist of pairs or triples of matrices, permutation vectors, and the like, produce results in five decomposition classes. These decompositions are accessed by the Matrix class to compute solutions of simultaneous linear equations, determinants, inverses and other matrix functions. The five decompositions are:

Example of use:

Solve a linear system A x = b and compute the residual norm, ||b - A x||.

 double[][] vals = {{1.,2.,3},{4.,5.,6.},{7.,8.,10.}};
 Matrix A = new Matrix(vals);
 Matrix b = Matrix.random(3,1);
 Matrix x = A.solve(b);
 Matrix r = A.times(x).minus(b);
 double rnorm = r.normInf();
 

版本:
5 August 1998
作者:
The MathWorks, Inc. and the National Institute of Standards and Technology.
另请参见:
序列化表格

构造方法摘要
Matrix()
           
Matrix(double[][] A)
          Construct a matrix from a 2-D array.
Matrix(double[][] A, int m, int n)
          Construct a matrix quickly without checking arguments.
Matrix(double[] vals, int m)
          Construct a matrix from a one-dimensional packed array
Matrix(int m, int n)
          Construct an m-by-n matrix of zeros.
Matrix(int m, int n, double s)
          Construct an m-by-n constant matrix.
 
方法摘要
 Matrix arrayLeftDivide(Matrix B)
          Element-by-element left division, C = A.
 Matrix arrayLeftDivideEquals(Matrix B)
          Element-by-element left division in place, A = A.
 Matrix arrayRightDivide(Matrix B)
          Element-by-element right division, C = A.
 Matrix arrayRightDivideEquals(Matrix B)
          Element-by-element right division in place, A = A.
 Matrix arrayTimes(Matrix B)
          Element-by-element multiplication, C = A.
 Matrix arrayTimesEquals(Matrix B)
          Element-by-element multiplication in place, A = A.
 Matrix block(int i, int j, int p, int q)
           
 Object clone()
          Clone the Matrix object.
 Matrix col(int j)
          取出第j列作为一个列向量
 int cols()
           
static Matrix constructWithCopy(double[][] A)
          Construct a matrix from a copy of a 2-D array.
 Matrix copy()
          Make a deep copy of a matrix
 double[][] cube()
          返回矩阵的立方(以数组形式)
 double get(int i, int j)
          Get a single element.
 double[][] getArray()
          Access the internal two-dimensional array.
 double[][] getArrayCopy()
          Copy the internal two-dimensional array.
 int getColumnDimension()
          Get column dimension.
 double[] getColumnPackedCopy()
          Make a one-dimensional column packed copy of the internal array.
 Matrix getMatrix(int[] r, int[] c)
          Get a submatrix.
 Matrix getMatrix(int[] r, int j0, int j1)
          Get a submatrix.
 Matrix getMatrix(int i0, int i1, int[] c)
          Get a submatrix.
 Matrix getMatrix(int i0, int i1, int j0, int j1)
          Get a submatrix.
 int getRowDimension()
          Get row dimension.
 double[] getRowPackedCopy()
          Make a one-dimensional row packed copy of the internal array.
static Matrix identity(int m, int n)
          Generate identity matrix
 boolean load(ByteArray byteArray)
          载入
 Matrix minus(Matrix B)
          C = A - B
 Matrix minusEquals(Matrix B)
          A = A - B
 double norm1()
          One norm
 double normInf()
          Infinity norm
 Matrix plus(Matrix B)
          C = A + B
 Matrix plusEquals(Matrix B)
          A = A + B
 void print(int w, int d)
          Print the matrix to stdout.
 void print(NumberFormat format, int width)
          Print the matrix to stdout.
 void print(PrintWriter output, int w, int d)
          Print the matrix to the output stream.
 void print(PrintWriter output, NumberFormat format, int width)
          Print the matrix to the output stream.
static Matrix random(int m, int n)
          Generate matrix with random elements
static Matrix read(BufferedReader input)
          Read a matrix from a stream.
 Matrix row(int i)
          取出第i行作为一个行向量
 int rows()
           
 void save(DataOutputStream out)
          写入
 void set(int i, int j, double s)
          Set a single element.
 void setMatrix(int[] r, int[] c, Matrix X)
          Set a submatrix.
 void setMatrix(int[] r, int j0, int j1, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int[] c, Matrix X)
          Set a submatrix.
 void setMatrix(int i0, int i1, int j0, int j1, Matrix X)
          Set a submatrix.
 void setZero()
           
 Matrix times(double s)
          Multiply a matrix by a scalar, C = s*A
 Matrix times(Matrix B)
          Linear algebraic matrix multiplication, A * B
 Matrix timesEquals(double s)
          Multiply a matrix by a scalar in place, A = s*A
 double trace()
          Matrix trace.
 Matrix transpose()
          Matrix transpose.
 Matrix uminus()
          Unary minus
static Matrix zero(int m, int n)
           
 
从类 java.lang.Object 继承的方法
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

Matrix

public Matrix(int m,
              int n)
Construct an m-by-n matrix of zeros.

参数:
m - Number of rows.
n - Number of colums.

Matrix

public Matrix(int m,
              int n,
              double s)
Construct an m-by-n constant matrix.

参数:
m - Number of rows.
n - Number of colums.
s - Fill the matrix with this scalar value.

Matrix

public Matrix(double[][] A)
Construct a matrix from a 2-D array.

参数:
A - Two-dimensional array of doubles.
抛出:
IllegalArgumentException - All rows must have the same length
另请参见:
constructWithCopy(double[][])

Matrix

public Matrix(double[][] A,
              int m,
              int n)
Construct a matrix quickly without checking arguments.

参数:
A - Two-dimensional array of doubles.
m - Number of rows.
n - Number of colums.

Matrix

public Matrix(double[] vals,
              int m)
Construct a matrix from a one-dimensional packed array

参数:
vals - One-dimensional array of doubles, packed by columns (ala Fortran).
m - Number of rows.
抛出:
IllegalArgumentException - Array length must be a multiple of m.

Matrix

public Matrix()
方法详细信息

constructWithCopy

public static Matrix constructWithCopy(double[][] A)
Construct a matrix from a copy of a 2-D array.

参数:
A - Two-dimensional array of doubles.
抛出:
IllegalArgumentException - All rows must have the same length

copy

public Matrix copy()
Make a deep copy of a matrix


clone

public Object clone()
Clone the Matrix object.

覆盖:
Object 中的 clone

getArray

public double[][] getArray()
Access the internal two-dimensional array.

返回:
Pointer to the two-dimensional array of matrix elements.

getArrayCopy

public double[][] getArrayCopy()
Copy the internal two-dimensional array.

返回:
Two-dimensional array copy of matrix elements.

getColumnPackedCopy

public double[] getColumnPackedCopy()
Make a one-dimensional column packed copy of the internal array.

返回:
Matrix elements packed in a one-dimensional array by columns.

getRowPackedCopy

public double[] getRowPackedCopy()
Make a one-dimensional row packed copy of the internal array.

返回:
Matrix elements packed in a one-dimensional array by rows.

getRowDimension

public int getRowDimension()
Get row dimension.

返回:
m, the number of rows.

getColumnDimension

public int getColumnDimension()
Get column dimension.

返回:
n, the number of columns.

get

public double get(int i,
                  int j)
Get a single element.

参数:
i - Row index.
j - Column index.
返回:
A(i, j)
抛出:
ArrayIndexOutOfBoundsException

getMatrix

public Matrix getMatrix(int i0,
                        int i1,
                        int j0,
                        int j1)
Get a submatrix.

参数:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
返回:
A(i0:i1, j0:j1)
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int[] r,
                        int[] c)
Get a submatrix.

参数:
r - Array of row indices.
c - Array of column indices.
返回:
A(r(:), c(:))
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int i0,
                        int i1,
                        int[] c)
Get a submatrix.

参数:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
返回:
A(i0:i1, c(:))
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

getMatrix

public Matrix getMatrix(int[] r,
                        int j0,
                        int j1)
Get a submatrix.

参数:
r - Array of row indices.
j0 - Initial column index
j1 - Final column index
返回:
A(r(:), j0:j1)
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

set

public void set(int i,
                int j,
                double s)
Set a single element.

参数:
i - Row index.
j - Column index.
s - A(i,j).
抛出:
ArrayIndexOutOfBoundsException

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int j0,
                      int j1,
                      Matrix X)
Set a submatrix.

参数:
i0 - Initial row index
i1 - Final row index
j0 - Initial column index
j1 - Final column index
X - A(i0:i1,j0:j1)
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int[] c,
                      Matrix X)
Set a submatrix.

参数:
r - Array of row indices.
c - Array of column indices.
X - A(r(:),c(:))
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int[] r,
                      int j0,
                      int j1,
                      Matrix X)
Set a submatrix.

参数:
r - Array of row indices.
j0 - Initial column index
j1 - Final column index
X - A(r(:),j0:j1)
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

setMatrix

public void setMatrix(int i0,
                      int i1,
                      int[] c,
                      Matrix X)
Set a submatrix.

参数:
i0 - Initial row index
i1 - Final row index
c - Array of column indices.
X - A(i0:i1,c(:))
抛出:
ArrayIndexOutOfBoundsException - Submatrix indices

transpose

public Matrix transpose()
Matrix transpose.

返回:
A'

norm1

public double norm1()
One norm

返回:
maximum column sum.

normInf

public double normInf()
Infinity norm

返回:
maximum row sum.

uminus

public Matrix uminus()
Unary minus

返回:
-A

plus

public Matrix plus(Matrix B)
C = A + B

参数:
B - another matrix
返回:
A + B

plusEquals

public Matrix plusEquals(Matrix B)
A = A + B

参数:
B - another matrix
返回:
A + B

minus

public Matrix minus(Matrix B)
C = A - B

参数:
B - another matrix
返回:
A - B

minusEquals

public Matrix minusEquals(Matrix B)
A = A - B

参数:
B - another matrix
返回:
A - B

arrayTimes

public Matrix arrayTimes(Matrix B)
Element-by-element multiplication, C = A.*B

参数:
B - another matrix
返回:
A.*B

arrayTimesEquals

public Matrix arrayTimesEquals(Matrix B)
Element-by-element multiplication in place, A = A.*B

参数:
B - another matrix
返回:
A.*B

arrayRightDivide

public Matrix arrayRightDivide(Matrix B)
Element-by-element right division, C = A./B

参数:
B - another matrix
返回:
A./B

arrayRightDivideEquals

public Matrix arrayRightDivideEquals(Matrix B)
Element-by-element right division in place, A = A./B

参数:
B - another matrix
返回:
A./B

arrayLeftDivide

public Matrix arrayLeftDivide(Matrix B)
Element-by-element left division, C = A.\B

参数:
B - another matrix
返回:
A.\B

arrayLeftDivideEquals

public Matrix arrayLeftDivideEquals(Matrix B)
Element-by-element left division in place, A = A.\B

参数:
B - another matrix
返回:
A.\B

times

public Matrix times(double s)
Multiply a matrix by a scalar, C = s*A

参数:
s - scalar
返回:
s*A

timesEquals

public Matrix timesEquals(double s)
Multiply a matrix by a scalar in place, A = s*A

参数:
s - scalar
返回:
replace A by s*A

times

public Matrix times(Matrix B)
Linear algebraic matrix multiplication, A * B

参数:
B - another matrix
返回:
Matrix product, A * B
抛出:
IllegalArgumentException - Matrix inner dimensions must agree.

trace

public double trace()
Matrix trace.

返回:
sum of the diagonal elements.

random

public static Matrix random(int m,
                            int n)
Generate matrix with random elements

参数:
m - Number of rows.
n - Number of colums.
返回:
An m-by-n matrix with uniformly distributed random elements.

identity

public static Matrix identity(int m,
                              int n)
Generate identity matrix

参数:
m - Number of rows.
n - Number of colums.
返回:
An m-by-n matrix with ones on the diagonal and zeros elsewhere.

print

public void print(int w,
                  int d)
Print the matrix to stdout. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

参数:
w - Column width.
d - Number of digits after the decimal.

print

public void print(PrintWriter output,
                  int w,
                  int d)
Print the matrix to the output stream. Line the elements up in columns with a Fortran-like 'Fw.d' style format.

参数:
output - Output stream.
w - Column width.
d - Number of digits after the decimal.

print

public void print(NumberFormat format,
                  int width)
Print the matrix to stdout. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.

参数:
format - A Formatting object for individual elements.
width - Field width for each column.
另请参见:
DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)

print

public void print(PrintWriter output,
                  NumberFormat format,
                  int width)
Print the matrix to the output stream. Line the elements up in columns. Use the format object, and right justify within columns of width characters. Note that is the matrix is to be read back in, you probably will want to use a NumberFormat that is set to US Locale.

参数:
output - the output stream.
format - A formatting object to format the matrix elements
width - Column width.
另请参见:
DecimalFormat.setDecimalFormatSymbols(java.text.DecimalFormatSymbols)

read

public static Matrix read(BufferedReader input)
                   throws IOException
Read a matrix from a stream. The format is the same the print method, so printed matrices can be read back in (provided they were printed using US Locale). Elements are separated by whitespace, all the elements for each row appear on a single line, the last row is followed by a blank line.

参数:
input - the input stream.
抛出:
IOException

zero

public static Matrix zero(int m,
                          int n)

rows

public int rows()

cols

public int cols()

col

public Matrix col(int j)
取出第j列作为一个列向量

参数:
j -
返回:

row

public Matrix row(int i)
取出第i行作为一个行向量

参数:
i -
返回:

block

public Matrix block(int i,
                    int j,
                    int p,
                    int q)

cube

public double[][] cube()
返回矩阵的立方(以数组形式)

返回:

setZero

public void setZero()

save

public void save(DataOutputStream out)
          throws Exception
从接口 ICacheAble 复制的描述
写入

指定者:
接口 ICacheAble 中的 save
抛出:
Exception

load

public boolean load(ByteArray byteArray)
从接口 ICacheAble 复制的描述
载入

指定者:
接口 ICacheAble 中的 load
返回:


Copyright © 2014–2015 鐮佸啘鍦�/a>. All rights reserved.