Package edu.cmu.tetrad.util
Class Matrix
java.lang.Object
edu.cmu.tetrad.util.Matrix
- All Implemented Interfaces:
TetradSerializable,Serializable
Wraps the Apache math3 linear algebra library for most uses in Tetrad. Specialized uses will still have to use the
library directly. One issue is that we need to be able to represent empty matrices gracefully; this case is handled
separately and incorporated into the class.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassign.voidassignColumn(int col, Vector doubles) assignColumn.voidassignRow.copy()copy.doubledet()det.diag()diag.booleanequals.doubleget(int i, int j) get.org.apache.commons.math3.linear.RealMatrixGetter for the fieldapacheData.getColumn(int j) getColumn.intgetNumColumns.intgetNumRows.getPart(int i, int j, int k, int l) getPart.getRow(int i) getRow.getSelection(int[] rows, int[] cols) getSelection.static Matrixidentity(int rows) identity.inverse()Returns the inverse of the matrix.booleanisSquare()isSquare.booleanisSymmetric(double tolerance) isSymmetric.like()like.minus.doublenorm1()norm1.plus.Returns the Moore-Penrose pseudoinverse of the matrix.intrank()rank.scalarMult(double scalar) scalarMult.static MatrixGenerates a simple exemplar of this class to test serialization.voidset(int i, int j, double v) set.static MatrixsparseMatrix(int m, int n) sparseMatrix.sqrt()sqrt.sum(int direction) sum.times.times.double[][]toArray()toArray.toString()toString.doubletrace()trace.transpose.doublezSum()zSum.
-
Constructor Details
-
Matrix
public Matrix(double[][] data) Constructor for Matrix.
- Parameters:
data- an array of objects
-
Matrix
public Matrix(org.apache.commons.math3.linear.RealMatrix data) Constructor for Matrix.
- Parameters:
data- aRealMatrixobject
-
Matrix
public Matrix(int m, int n) Constructor for Matrix.
- Parameters:
m- a intn- a int
-
Matrix
-
-
Method Details
-
identity
-
sparseMatrix
-
serializableInstance
-
assign
-
getNumColumns
public int getNumColumns()getNumColumns.
- Returns:
- a int
-
diag
-
getSelection
-
copy
-
getColumn
-
times
-
times
-
toArray
public double[][] toArray()toArray.
- Returns:
- an array of objects
-
getApacheData
public org.apache.commons.math3.linear.RealMatrix getApacheData()Getter for the field
apacheData.- Returns:
- a
RealMatrixobject
-
get
public double get(int i, int j) get.
- Parameters:
i- a intj- a int- Returns:
- a double
-
like
-
set
public void set(int i, int j, double v) set.
- Parameters:
i- a intj- a intv- a double
-
getRow
-
getPart
-
inverse
Returns the inverse of the matrix. If the matrix is not square, an exception is thrown. If the matrix is singular, an exception is thrown.- Returns:
- a
Matrixobject - Throws:
org.apache.commons.math3.linear.SingularMatrixException- if any.
-
pseudoinverse
-
assignRow
-
assignColumn
-
trace
public double trace()trace.
- Returns:
- a double
-
det
public double det()det.
- Returns:
- a double
-
transpose
-
equals
-
isSquare
public boolean isSquare()isSquare.
- Returns:
- a boolean
-
isSymmetric
public boolean isSymmetric(double tolerance) isSymmetric.
- Parameters:
tolerance- a double- Returns:
- a boolean
-
minus
-
norm1
public double norm1()norm1.
- Returns:
- a double
-
plus
-
rank
public int rank()rank.
- Returns:
- a int
-
getNumRows
public int getNumRows()getNumRows.
- Returns:
- a int
-
scalarMult
-
sqrt
-
sum
-
zSum
public double zSum()zSum.
- Returns:
- a double
-
toString
-