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.
- Version:
- $Id: $Id
- 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) Constructor for CovarianceMatrix.CovarianceMatrix
(ICovarianceMatrix covMatrix) Constructor for CovarianceMatrix.CovarianceMatrix
(List<Node> variables, double[][] matrix, int sampleSize) Constructor for CovarianceMatrix.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
clearSelection.copy()
copy.final int
getDimension.final Knowledge
Getter for the fieldknowledge
.final Matrix
getMatrix.final String
getName()
Gets the name of the covariance matrix.final int
The size of the sample used to calculated this covariance matrix.getSelectedVariableNames.getSelection
(int[] rows, int[] cols) getSelection.final int
getSize()
getSize.final ICovarianceMatrix
getSubmatrix
(int[] indices) getSubmatrix.final CovarianceMatrix
getSubmatrix
(String[] submatrixVarNames) getSubmatrix.final ICovarianceMatrix
getSubmatrix
(List<String> submatrixVarNames) getSubmatrix.final double
getValue
(int i, int j) getValue.getVariable
(String name) getVariable.final String
getVariableName
(int index) getVariableName.getVariableNames.Getter for the fieldvariables
.boolean
isContinuous.boolean
isDiscrete.boolean
isMixed()
isMixed.final boolean
isSelected
(Node variable) isSelected.boolean
isSingular.void
removeVariables
(List<String> remaining) removeVariables.final void
select.static ICovarianceMatrix
Generates a simple exemplar of this class to test serialization.final void
setKnowledge
(Knowledge knowledge) Sets knowledge to a copy of the given object.void
setMatrix.final void
Sets the name of the data model (may be null).final void
setSampleSize
(int sampleSize) setSampleSize.void
setValue
(int i, int j, double v) setValue.void
setVariables
(List<Node> variables) setVariables.final String
toString()
Prints out the matrix
-
Constructor Details
-
CovarianceMatrix
Constructs a new covariance matrix from the given data set.- Parameters:
dataSet
- aDataSet
object- Throws:
IllegalArgumentException
- if this is not a continuous data set.
-
CovarianceMatrix
Constructor for CovarianceMatrix.
- Parameters:
dataSet
- aDataSet
objectbiasCorrected
- a boolean
-
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
Constructor for CovarianceMatrix.
- Parameters:
variables
- aList
objectmatrix
- an array ofdouble
objectssampleSize
- a int
-
CovarianceMatrix
Copy constructor.- Parameters:
covMatrix
- aCovarianceMatrix
object
-
CovarianceMatrix
Constructor for CovarianceMatrix.
- Parameters:
covMatrix
- aICovarianceMatrix
object
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
ICovarianceMatrix
object
-
getVariables
Getter for the field
variables
.- Specified by:
getVariables
in interfaceICovarianceMatrix
- Specified by:
getVariables
in interfaceVariableSource
- Returns:
- the list of variables (unmodifiable).
-
setVariables
setVariables.
- Specified by:
setVariables
in interfaceICovarianceMatrix
- Parameters:
variables
- aList
object
-
getVariableNames
getVariableNames.
- Specified by:
getVariableNames
in interfaceICovarianceMatrix
- Specified by:
getVariableNames
in interfaceVariableSource
- Returns:
- the variable names, in order.
-
getVariableName
getVariableName.
- Specified by:
getVariableName
in interfaceICovarianceMatrix
- Parameters:
index
- a int- Returns:
- a
String
object
-
getDimension
public final int getDimension()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) setSampleSize.
- Specified by:
setSampleSize
in interfaceICovarianceMatrix
- Parameters:
sampleSize
- a int
-
getName
Gets the name of the covariance matrix.- Specified by:
getName
in interfaceDataModel
- Specified by:
getName
in interfaceICovarianceMatrix
- Returns:
- a
String
object
-
setName
Sets the name of the data model (may be null).Sets the name of the covariance matrix.
- Specified by:
setName
in interfaceDataModel
- Specified by:
setName
in interfaceICovarianceMatrix
- Parameters:
name
- the name to set
-
getKnowledge
Getter for the field
knowledge
.- Specified by:
getKnowledge
in interfaceICovarianceMatrix
- Specified by:
getKnowledge
in interfaceKnowledgeTransferable
- Returns:
- the knowledge associated with this data.
-
setKnowledge
Sets knowledge to a copy of the given object.Associates knowledge with this data.
- Specified by:
setKnowledge
in interfaceICovarianceMatrix
- Specified by:
setKnowledge
in interfaceKnowledgeTransferable
- Parameters:
knowledge
- the knowledge to set
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
indices
- an array ofint
objects- Returns:
- a submatrix of the covariance matrix with variables in the given order.
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
submatrixVarNames
- aList
object- Returns:
- a
ICovarianceMatrix
object
-
getSubmatrix
getSubmatrix.
- Specified by:
getSubmatrix
in interfaceICovarianceMatrix
- Parameters:
submatrixVarNames
- an array ofString
objects- Returns:
- a submatrix of this matrix, with variables in the given order.
-
getValue
public final double getValue(int i, int j) getValue.
- Specified by:
getValue
in interfaceICovarianceMatrix
- Parameters:
i
- a intj
- a int- Returns:
- a double
-
getSize
public final int getSize()getSize.
- Specified by:
getSize
in interfaceICovarianceMatrix
- Returns:
- the size of the square matrix.
-
getMatrix
getMatrix.
- Specified by:
getMatrix
in interfaceICovarianceMatrix
- Returns:
- a the covariance matrix (not a copy).
-
setMatrix
setMatrix.
- Specified by:
setMatrix
in interfaceICovarianceMatrix
- Parameters:
matrix
- aMatrix
object
-
select
select.
- Specified by:
select
in interfaceICovarianceMatrix
- Parameters:
variable
- aNode
object
-
clearSelection
public final void clearSelection()clearSelection.
- Specified by:
clearSelection
in interfaceICovarianceMatrix
-
isSelected
isSelected.
- Specified by:
isSelected
in interfaceICovarianceMatrix
- Parameters:
variable
- aNode
object- Returns:
- a boolean
-
getSelectedVariableNames
getSelectedVariableNames.
- Specified by:
getSelectedVariableNames
in interfaceICovarianceMatrix
- Returns:
- a
List
object
-
toString
Prints out the matrix -
isContinuous
public boolean isContinuous()isContinuous.
- Specified by:
isContinuous
in interfaceDataModel
- Returns:
- true if the data model is continuous, false otherwise.
-
isDiscrete
public boolean isDiscrete()isDiscrete.
- Specified by:
isDiscrete
in interfaceDataModel
- Returns:
- true if the data model is discrete, false otherwise.
-
isMixed
public boolean isMixed()isMixed.
-
getSelection
getSelection.
- Specified by:
getSelection
in interfaceICovarianceMatrix
- Parameters:
rows
- an array ofint
objectscols
- an array ofint
objects- Returns:
- a
Matrix
object
-
getVariable
getVariable.
- Specified by:
getVariable
in interfaceDataModel
- Specified by:
getVariable
in interfaceICovarianceMatrix
- Parameters:
name
- aString
object- Returns:
- the variable with the given name, or null if no such variable exists.
-
copy
copy.
-
setValue
public void setValue(int i, int j, double v) setValue.
- Specified by:
setValue
in interfaceICovarianceMatrix
- Parameters:
i
- a intj
- a intv
- a double
-
removeVariables
removeVariables.
- Specified by:
removeVariables
in interfaceICovarianceMatrix
- Parameters:
remaining
- aList
object
-
isSingular
public boolean isSingular()isSingular.
- Returns:
- a boolean
-