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 TypeMethodDescriptionvoid
assign.void
assignColumn
(int col, Vector doubles) assignColumn.void
assignRow.copy()
copy.double
det()
det.diag()
diag.boolean
equals.double
get
(int i, int j) get.org.apache.commons.math3.linear.RealMatrix
Getter for the fieldapacheData
.getColumn
(int j) getColumn.int
getNumColumns.int
getNumRows.getPart
(int i, int j, int k, int l) getPart.getRow
(int i) getRow.getSelection
(int[] rows, int[] cols) getSelection.static Matrix
identity
(int rows) identity.inverse()
Returns the inverse of the matrix.boolean
isSquare()
isSquare.boolean
isSymmetric
(double tolerance) isSymmetric.like()
like.minus.double
norm1()
norm1.plus.Returns the Moore-Penrose pseudoinverse of the matrix.int
rank()
rank.scalarMult
(double scalar) scalarMult.static Matrix
Generates a simple exemplar of this class to test serialization.void
set
(int i, int j, double v) set.static Matrix
sparseMatrix
(int m, int n) sparseMatrix.sqrt()
sqrt.sum
(int direction) sum.times.times.double[][]
toArray()
toArray.toString()
toString.double
trace()
trace.transpose.double
zSum()
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
- aRealMatrix
object
-
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
RealMatrix
object
-
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
Matrix
object - 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
-