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 this fixes is that a BlockRealMatrix cannot represent a matrix with zero rows; this uses
an Array2DRowRealMatrix to represent that case.
- 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.ginverse()
ginverse.static Matrix
identity
(int rows) identity.inverse()
inverse.boolean
isSquare()
isSquare.boolean
isSymmetric
(double tolerance) isSymmetric.like()
like.minus.double
norm1()
norm1.plus.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.symmetricInverse.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 ofdouble
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
Constructor for Matrix.
- Parameters:
m
- aMatrix
object
-
-
Method Details
-
identity
identity.
- Parameters:
rows
- a int- Returns:
- a
Matrix
object
-
sparseMatrix
sparseMatrix.
- Parameters:
m
- a intn
- a int- Returns:
- a
Matrix
object
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
Matrix
object
-
assign
assign.
- Parameters:
matrix
- aMatrix
object
-
getNumColumns
public int getNumColumns()getNumColumns.
- Returns:
- a int
-
diag
diag.
- Returns:
- a
Vector
object
-
getSelection
getSelection.
- Parameters:
rows
- an array ofint
objectscols
- an array ofint
objects- Returns:
- a
Matrix
object
-
copy
copy.
- Returns:
- a
Matrix
object
-
getColumn
getColumn.
- Parameters:
j
- a int- Returns:
- a
Vector
object
-
times
times.
-
times
times.
-
toArray
public double[][] toArray()toArray.
- Returns:
- an array of
double
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
like.
- Returns:
- a
Matrix
object
-
set
public void set(int i, int j, double v) set.
- Parameters:
i
- a intj
- a intv
- a double
-
getRow
getRow.
- Parameters:
i
- a int- Returns:
- a
Vector
object
-
getPart
getPart.
- Parameters:
i
- a intj
- a intk
- a intl
- a int- Returns:
- a
Matrix
object
-
inverse
inverse.
- Returns:
- a
Matrix
object - Throws:
org.apache.commons.math3.linear.SingularMatrixException
- if any.
-
symmetricInverse
symmetricInverse.
- Returns:
- a
Matrix
object
-
ginverse
ginverse.
- Returns:
- a
Matrix
object
-
assignRow
assignRow.
- Parameters:
row
- a intdoubles
- aVector
object
-
assignColumn
assignColumn.
- Parameters:
col
- a intdoubles
- aVector
object
-
trace
public double trace()trace.
- Returns:
- a double
-
det
public double det()det.
- Returns:
- a double
-
transpose
transpose.
- Returns:
- a
Matrix
object
-
equals
equals.
- Parameters:
m
- aMatrix
objecttolerance
- a double- Returns:
- a boolean
-
isSquare
public boolean isSquare()isSquare.
- Returns:
- a boolean
-
isSymmetric
public boolean isSymmetric(double tolerance) isSymmetric.
- Parameters:
tolerance
- a double- Returns:
- a boolean
-
minus
minus.
-
norm1
public double norm1()norm1.
- Returns:
- a double
-
plus
plus.
-
rank
public int rank()rank.
- Returns:
- a int
-
getNumRows
public int getNumRows()getNumRows.
- Returns:
- a int
-
scalarMult
scalarMult.
- Parameters:
scalar
- a double- Returns:
- a
Matrix
object
-
sqrt
sqrt.
- Returns:
- a
Matrix
object
-
sum
sum.
- Parameters:
direction
- a int- Returns:
- a
Vector
object
-
zSum
public double zSum()zSum.
- Returns:
- a double
-
toString
toString.
-