Class CovarianceMatrixOnTheFly

java.lang.Object
edu.cmu.tetrad.data.CovarianceMatrixOnTheFly
All Implemented Interfaces:
DataModel, ICovarianceMatrix, KnowledgeTransferable, VariableSource, TetradSerializable, Serializable

public class CovarianceMatrixOnTheFly extends Object implements ICovarianceMatrix
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 Details

    • CovarianceMatrixOnTheFly

      public CovarianceMatrixOnTheFly(DataSet dataSet)
      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.
      Parameters:
      dataSet - a DataSet object
      Throws:
      IllegalArgumentException - if this is not a continuous data set.
    • CovarianceMatrixOnTheFly

      public CovarianceMatrixOnTheFly(DataSet dataSet, boolean verbose)

      Constructor for CovarianceMatrixOnTheFly.

      Parameters:
      dataSet - a DataSet object
      verbose - a boolean
  • Method Details

    • demean

      public static void demean(double[][] data, Vector means)

      demean.

      Parameters:
      data - an array of double objects
      means - a Vector object
    • serializableInstance

      public static ICovarianceMatrix serializableInstance()
      Generates a simple exemplar of this class to test serialization.
      Returns:
      a ICovarianceMatrix object
    • getVariables

      public final List<Node> getVariables()

      Getter for the field variables.

      Specified by:
      getVariables in interface ICovarianceMatrix
      Specified by:
      getVariables in interface VariableSource
      Returns:
      the list of variables (unmodifiable).
    • setVariables

      public void setVariables(List<Node> variables)

      setVariables.

      Specified by:
      setVariables in interface ICovarianceMatrix
      Parameters:
      variables - a List object
    • getVariableNames

      public final List<String> getVariableNames()

      getVariableNames.

      Specified by:
      getVariableNames in interface ICovarianceMatrix
      Specified by:
      getVariableNames in interface VariableSource
      Returns:
      the variable names, in order.
    • getVariableName

      public final String getVariableName(int index)

      getVariableName.

      Specified by:
      getVariableName in interface ICovarianceMatrix
      Parameters:
      index - a int
      Returns:
      a String object
    • getDimension

      public final int getDimension()

      getDimension.

      Specified by:
      getDimension in interface ICovarianceMatrix
      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 interface ICovarianceMatrix
      Returns:
      The sample size (> 0).
    • setSampleSize

      public final void setSampleSize(int sampleSize)

      setSampleSize.

      Specified by:
      setSampleSize in interface ICovarianceMatrix
      Parameters:
      sampleSize - a int
    • getName

      public final String getName()
      Gets the name of the covariance matrix.
      Specified by:
      getName in interface DataModel
      Specified by:
      getName in interface ICovarianceMatrix
      Returns:
      a String object
    • setName

      public final void setName(String name)
      Sets the name of the data model (may be null).

      Sets the name of the covariance matrix.

      Specified by:
      setName in interface DataModel
      Specified by:
      setName in interface ICovarianceMatrix
      Parameters:
      name - the name to set
    • getKnowledge

      public final Knowledge getKnowledge()

      Getter for the field knowledge.

      Specified by:
      getKnowledge in interface ICovarianceMatrix
      Specified by:
      getKnowledge in interface KnowledgeTransferable
      Returns:
      the knowledge associated with this data.
    • setKnowledge

      public final void setKnowledge(Knowledge knowledge)
      Sets knowledge to a copy of the given object.

      Associates knowledge with this data.

      Specified by:
      setKnowledge in interface ICovarianceMatrix
      Specified by:
      setKnowledge in interface KnowledgeTransferable
      Parameters:
      knowledge - the knowledge to set
    • getSubmatrix

      public final ICovarianceMatrix getSubmatrix(int[] indices)

      getSubmatrix.

      Specified by:
      getSubmatrix in interface ICovarianceMatrix
      Parameters:
      indices - an array of int objects
      Returns:
      a submatrix of the covariance matrix with variables in the given order.
    • getSubmatrix

      public final ICovarianceMatrix getSubmatrix(int[] indices, int[] dataRows)

      getSubmatrix.

      Parameters:
      indices - an array of int objects
      dataRows - an array of int objects
      Returns:
      a ICovarianceMatrix object
    • getSubmatrix

      public final ICovarianceMatrix getSubmatrix(List<String> submatrixVarNames)

      getSubmatrix.

      Specified by:
      getSubmatrix in interface ICovarianceMatrix
      Parameters:
      submatrixVarNames - a List object
      Returns:
      a ICovarianceMatrix object
    • getSubmatrix

      public final CovarianceMatrixOnTheFly getSubmatrix(String[] submatrixVarNames)

      getSubmatrix.

      Specified by:
      getSubmatrix in interface ICovarianceMatrix
      Parameters:
      submatrixVarNames - an array of String 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 interface ICovarianceMatrix
      Parameters:
      i - a int
      j - a int
      Returns:
      a double
    • getValue

      public final double getValue(int i, int j, int[] rows)

      getValue.

      Parameters:
      i - a int
      j - a int
      rows - an array of int objects
      Returns:
      a double
    • getSize

      public final int getSize()

      getSize.

      Specified by:
      getSize in interface ICovarianceMatrix
      Returns:
      the size of the square matrix.
    • getMatrix

      public final Matrix getMatrix()

      Getter for the field matrix.

      Specified by:
      getMatrix in interface ICovarianceMatrix
      Returns:
      a copy of the covariance matrix.
    • setMatrix

      public void setMatrix(Matrix matrix)

      setMatrix.

      Specified by:
      setMatrix in interface ICovarianceMatrix
      Parameters:
      matrix - a Matrix object
    • getMatrix

      public final Matrix getMatrix(int[] rows)

      Getter for the field matrix.

      Parameters:
      rows - an array of int objects
      Returns:
      a Matrix object
    • select

      public final void select(Node variable)

      select.

      Specified by:
      select in interface ICovarianceMatrix
      Parameters:
      variable - a Node object
    • clearSelection

      public final void clearSelection()

      clearSelection.

      Specified by:
      clearSelection in interface ICovarianceMatrix
    • isSelected

      public final boolean isSelected(Node variable)

      isSelected.

      Specified by:
      isSelected in interface ICovarianceMatrix
      Parameters:
      variable - a Node object
      Returns:
      a boolean
    • getSelectedVariableNames

      public final List<String> getSelectedVariableNames()

      getSelectedVariableNames.

      Specified by:
      getSelectedVariableNames in interface ICovarianceMatrix
      Returns:
      a List object
    • toString

      public final String toString()
      Prints out the matrix
      Specified by:
      toString in interface DataModel
      Specified by:
      toString in interface ICovarianceMatrix
      Overrides:
      toString in class Object
      Returns:
      a String object
    • isContinuous

      public boolean isContinuous()

      isContinuous.

      Specified by:
      isContinuous in interface DataModel
      Returns:
      true if the data model is continuous, false otherwise.
    • isDiscrete

      public boolean isDiscrete()

      isDiscrete.

      Specified by:
      isDiscrete in interface DataModel
      Returns:
      true if the data model is discrete, false otherwise.
    • isMixed

      public boolean isMixed()

      isMixed.

      Specified by:
      isMixed in interface DataModel
      Returns:
      true if the data model is mixed continuous/discrete, false otherwise.
    • isVerbose

      public boolean isVerbose()

      isVerbose.

      Returns:
      a boolean
    • setVerbose

      public void setVerbose(boolean verbose)

      Setter for the field verbose.

      Parameters:
      verbose - a boolean
    • getSelection

      public Matrix getSelection(int[] rows, int[] cols)

      getSelection.

      Specified by:
      getSelection in interface ICovarianceMatrix
      Parameters:
      rows - an array of int objects
      cols - an array of int objects
      Returns:
      a Matrix object
    • getSelection

      public Matrix getSelection(int[] rows, int[] cols, int[] dataRows)

      getSelection.

      Parameters:
      rows - an array of int objects
      cols - an array of int objects
      dataRows - an array of int objects
      Returns:
      a Matrix object
    • getVariable

      public Node getVariable(String name)

      getVariable.

      Specified by:
      getVariable in interface DataModel
      Specified by:
      getVariable in interface ICovarianceMatrix
      Parameters:
      name - a String object
      Returns:
      the variable with the given name, or null if no such variable exists.
    • copy

      public DataModel copy()

      copy.

      Specified by:
      copy in interface DataModel
      Returns:
      a copy of the data model.
    • setValue

      public void setValue(int i, int j, double v)

      setValue.

      Specified by:
      setValue in interface ICovarianceMatrix
      Parameters:
      i - a int
      j - a int
      v - a double
    • removeVariables

      public void removeVariables(List<String> remaining)

      removeVariables.

      Specified by:
      removeVariables in interface ICovarianceMatrix
      Parameters:
      remaining - a List object