Package edu.cmu.tetrad.data
Class CovarianceMatrix
java.lang.Object
edu.cmu.tetrad.data.CovarianceMatrix
- All Implemented Interfaces:
DataModel
,ICovarianceMatrix
,KnowledgeTransferable
,VariableSource
,TetradSerializable
,Serializable
- Direct Known Subclasses:
CorrelationMatrix
Stores a covariance matrix together with variable names and sample size, intended as a representation of a data set.
When constructed from a continuous data set, the matrix is not checked for positive definiteness; however, when a
covariance matrix is supplied, its positive definiteness is always checked. If the sample size is less than the
number of variables, the positive definiteness is "spot-checked"--that is, checked for various submatrices.
- Author:
- josephramsey
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCovarianceMatrix
(CovarianceMatrix covMatrix) Copy constructor.CovarianceMatrix
(DataSet dataSet) Constructs a new covariance matrix from the given data set.CovarianceMatrix
(DataSet dataSet, boolean biasCorrected) CovarianceMatrix
(ICovarianceMatrix covMatrix) CovarianceMatrix
(List<Node> variables, double[][] matrix, int sampleSize) CovarianceMatrix
(List<Node> variables, Matrix matrix, int sampleSize) Protected constructor to construct a new covariance matrix using the supplied continuous variables and the the given symmetric, positive definite matrix and sample size. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
copy()
final int
final Knowledge
final Matrix
final String
getName()
Gets the name of the covariance matrix.final int
The size of the sample used to calculated this covariance matrix.getSelection
(int[] rows, int[] cols) final int
getSize()
final ICovarianceMatrix
getSubmatrix
(int[] indices) final CovarianceMatrix
getSubmatrix
(String[] submatrixVarNames) final ICovarianceMatrix
getSubmatrix
(List<String> submatrixVarNames) final double
getValue
(int i, int j) getVariable
(String name) final String
getVariableName
(int index) Returns the variable names associated with this getVariableNames.Returns the list of variables associated with this object.boolean
boolean
boolean
isMixed()
final boolean
isSelected
(Node variable) boolean
void
removeVariables
(List<String> remaining) final void
static ICovarianceMatrix
Generates a simple exemplar of this class to test serialization.final void
setKnowledge
(Knowledge knowledge) Associates knowledge with this data.void
final void
Sets the name of the covariance matrix.final void
setSampleSize
(int sampleSize) void
setValue
(int i, int j, double v) void
setVariables
(List<Node> variables) final String
toString()
Prints out the matrix
-
Constructor Details
-
CovarianceMatrix
Constructs a new covariance matrix from the given data set.- Throws:
IllegalArgumentException
- if this is not a continuous data set.
-
CovarianceMatrix
-
CovarianceMatrix
Protected constructor to construct a new covariance matrix using the supplied continuous variables and the the given symmetric, positive definite matrix and sample size. The number of variables must equal the dimension of the array.- Parameters:
variables
- the list of variables (in order) for the covariance matrix.matrix
- an square array of containing covariances.sampleSize
- the sample size of the data for these covariances.- Throws:
IllegalArgumentException
- if the given matrix is not symmetric (to a tolerance of 1.e-5) and positive definite, if the number of variables does not equal the dimension of m, or if the sample size is not positive.
-
CovarianceMatrix
-
CovarianceMatrix
Copy constructor. -
CovarianceMatrix
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization. -
getVariables
Description copied from interface:VariableSource
Returns the list of variables associated with this object.- Specified by:
getVariables
in interfaceICovarianceMatrix
- Specified by:
getVariables
in interfaceVariableSource
- Returns:
- the list of variables (unmodifiable).
-
setVariables
- Specified by:
setVariables
in interfaceICovarianceMatrix
-
getVariableNames
Description copied from interface:VariableSource
Returns the variable names associated with this getVariableNames.- Specified by:
getVariableNames
in interfaceICovarianceMatrix
- Specified by:
getVariableNames
in interfaceVariableSource
- Returns:
- the variable names, in order.
-
getVariableName
- Specified by:
getVariableName
in interfaceICovarianceMatrix
- Returns:
- the variable name at the given index.
-
getDimension
public final int getDimension()- Specified by:
getDimension
in interfaceICovarianceMatrix
- Returns:
- the dimension of the covariance matrix.
-
getSampleSize
public final int getSampleSize()The size of the sample used to calculated this covariance matrix.- Specified by:
getSampleSize
in interfaceICovarianceMatrix
- Returns:
- The sample size (> 0).
-
setSampleSize
public final void setSampleSize(int sampleSize) - Specified by:
setSampleSize
in interfaceICovarianceMatrix
-
getName
Gets the name of the covariance matrix.- Specified by:
getName
in interfaceDataModel
- Specified by:
getName
in interfaceICovarianceMatrix
- Returns:
- the name of the data model (may be null).
-
setName
Sets the name of the covariance matrix.- Specified by:
setName
in interfaceDataModel
- Specified by:
setName
in interfaceICovarianceMatrix
-
getKnowledge
- Specified by:
getKnowledge
in interfaceICovarianceMatrix
- Specified by:
getKnowledge
in interfaceKnowledgeTransferable
- Returns:
- the knowledge associated with this data.
-
setKnowledge
Associates knowledge with this data.- Specified by:
setKnowledge
in interfaceICovarianceMatrix
- Specified by:
setKnowledge
in interfaceKnowledgeTransferable
-
getSubmatrix
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Returns:
- a submatrix of the covariance matrix with variables in the given order.
-
getSubmatrix
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
-
getSubmatrix
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Returns:
- a submatrix of this matrix, with variables in the given order.
-
getValue
public final double getValue(int i, int j) - Specified by:
getValue
in interfaceICovarianceMatrix
- Returns:
- the value of element (i,j) in the matrix
-
getSize
public final int getSize()- Specified by:
getSize
in interfaceICovarianceMatrix
- Returns:
- the size of the square matrix.
-
getMatrix
- Specified by:
getMatrix
in interfaceICovarianceMatrix
- Returns:
- a the covariance matrix (not a copy).
-
setMatrix
- Specified by:
setMatrix
in interfaceICovarianceMatrix
-
select
- Specified by:
select
in interfaceICovarianceMatrix
-
clearSelection
public final void clearSelection()- Specified by:
clearSelection
in interfaceICovarianceMatrix
-
isSelected
- Specified by:
isSelected
in interfaceICovarianceMatrix
-
getSelectedVariableNames
- Specified by:
getSelectedVariableNames
in interfaceICovarianceMatrix
-
toString
Prints out the matrix -
isContinuous
public boolean isContinuous()- Specified by:
isContinuous
in interfaceDataModel
-
isDiscrete
public boolean isDiscrete()- Specified by:
isDiscrete
in interfaceDataModel
-
isMixed
public boolean isMixed() -
getSelection
- Specified by:
getSelection
in interfaceICovarianceMatrix
-
getVariable
- Specified by:
getVariable
in interfaceDataModel
- Specified by:
getVariable
in interfaceICovarianceMatrix
-
copy
-
setValue
public void setValue(int i, int j, double v) - Specified by:
setValue
in interfaceICovarianceMatrix
-
removeVariables
- Specified by:
removeVariables
in interfaceICovarianceMatrix
-
isSingular
public boolean isSingular()
-