Package edu.cmu.tetrad.data
Class CovarianceMatrixOnTheFly
java.lang.Object
edu.cmu.tetrad.data.CovarianceMatrixOnTheFly
- All Implemented Interfaces:
DataModel
,ICovarianceMatrix
,KnowledgeTransferable
,VariableSource
,TetradSerializable
,Serializable
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
ConstructorsConstructorDescriptionCovarianceMatrixOnTheFly
(DataSet dataSet) Constructs a new covariance matrix from the given data set.CovarianceMatrixOnTheFly
(DataSet dataSet, boolean verbose) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
copy()
static void
final int
final Knowledge
final Matrix
final Matrix
getMatrix
(int[] rows) 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) getSelection
(int[] rows, int[] cols, int[] dataRows) final int
getSize()
final ICovarianceMatrix
getSubmatrix
(int[] indices) final ICovarianceMatrix
getSubmatrix
(int[] indices, int[] dataRows) final CovarianceMatrixOnTheFly
getSubmatrix
(String[] submatrixVarNames) final ICovarianceMatrix
getSubmatrix
(List<String> submatrixVarNames) final double
getValue
(int i, int j) final double
getValue
(int i, int j, int[] rows) 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) void
setVerbose
(boolean verbose) final String
toString()
Prints out the matrix
-
Constructor Details
-
CovarianceMatrixOnTheFly
Constructs a new covariance matrix from the given data set. If dataSet is a BoxDataSet with a VerticalDoubleDataBox, the data will be mean-centered by the constructor; is non-mean-centered version of the data is needed, the data should be copied before being send into the constructor.- Throws:
IllegalArgumentException
- if this is not a continuous data set.
-
CovarianceMatrixOnTheFly
-
-
Method Details
-
demean
-
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
-
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
-
getValue
public final double getValue(int i, int j, int[] rows) -
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 copy of the covariance matrix.
-
setMatrix
- Specified by:
setMatrix
in interfaceICovarianceMatrix
-
getMatrix
-
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() -
isVerbose
public boolean isVerbose() -
setVerbose
public void setVerbose(boolean verbose) -
getSelection
- Specified by:
getSelection
in interfaceICovarianceMatrix
-
getSelection
-
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
-