Class SimpleDataLoader

java.lang.Object
edu.cmu.tetrad.data.SimpleDataLoader

public class SimpleDataLoader extends Object

SimpleDataLoader class.

Version:
$Id: $Id
Author:
josephramsey
  • Method Details

    • loadContinuousData

      @NotNull public static @NotNull DataSet loadContinuousData(File file, String commentMarker, char quoteCharacter, String missingValueMarker, boolean hasHeader, Delimiter delimiter, boolean excludeFirstColumn) throws IOException
      Loads a continuous dataset from a file.
      Parameters:
      file - The text file to load the data from.
      commentMarker - The comment marker as a string--e.g., "//".
      quoteCharacter - The quote character, e.g., '\"'.
      missingValueMarker - The missing value marker as a string--e.g., "NA".
      hasHeader - True if the first row of the data contains variable names.
      delimiter - One of the options in the Delimiter enum--e.g., Delimiter.TAB.
      excludeFirstColumn - If the first column should be excluded from the data.
      Returns:
      The loaded DataSet.
      Throws:
      IOException - If an error occurred in reading the file.
    • loadDiscreteData

      @NotNull public static @NotNull DataSet loadDiscreteData(File file, String commentMarker, char quoteCharacter, String missingValueMarker, boolean hasHeader, Delimiter delimiter, boolean excludeFirstColumn) throws IOException
      Loads a discrete dataset from a file.
      Parameters:
      file - The text file to load the data from.
      commentMarker - The comment marker as a string--e.g., "//".
      quoteCharacter - The quote character, e.g., '\"'.
      missingValueMarker - The missing value marker as a string--e.g., "NA".
      hasHeader - True if the first row of the data contains variable names.
      delimiter - One of the options in the Delimiter enum--e.g., Delimiter.TAB.
      excludeFirstColumn - If the first columns should be excluded from the data.
      Returns:
      The loaded DataSet.
      Throws:
      IOException - If an error occurred in reading the file.
    • loadMixedData

      @NotNull public static @NotNull DataSet loadMixedData(File file, String commentMarker, char quoteCharacter, String missingValueMarker, boolean hasHeader, int maxNumCategories, Delimiter delimiter, boolean excludeFirstColumn) throws IOException
      Loads a mixed dataset from a file.
      Parameters:
      file - The text file to load the data from.
      commentMarker - The comment marker as a string--e.g., "//".
      quoteCharacter - The quote character, e.g., '\"'.
      missingValueMarker - The missing value marker as a string--e.g., "NA".
      hasHeader - True if the first row of the data contains variable names.
      maxNumCategories - The maximum number of distinct entries in a columns alloed in order for the column to be parsed as discrete.
      delimiter - One of the options in the Delimiter enum--e.g., Delimiter.TAB.
      excludeFirstColumn - If the first columns should be excluded from the data set.
      Returns:
      The loaded DataSet.
      Throws:
      IOException - If an error occurred in reading the file.
    • loadCovarianceMatrix

      public static ICovarianceMatrix loadCovarianceMatrix(char[] chars, String commentMarker, DelimiterType delimiterType, char quoteChar, String missingValueMarker)
      Parses a covariance matrix from a char[] array. The format is as follows.
      /covariance
      100
      X1   X2   X3   X4
      1.4
      3.2  2.3
      2.5  3.2  5.3
      3.2  2.5  3.2  4.2
      
      CovarianceMatrix dataSet = DataLoader.loadCovMatrix(
                                new FileReader(file), " \t", "//");
      
      The initial "/covariance" is optional.
      Parameters:
      chars - an array of objects
      commentMarker - a String object
      delimiterType - a DelimiterType object
      quoteChar - a char
      missingValueMarker - a String object
      Returns:
      a ICovarianceMatrix object
    • loadCovarianceMatrix

      public static ICovarianceMatrix loadCovarianceMatrix(File file, String commentMarker, DelimiterType delimiter, char quoteCharacter, String missingValueMarker) throws IOException
      Parses the given files for a tabular data set, returning a RectangularDataSet if successful.
      Parameters:
      file - The text file to load the data from.
      commentMarker - The comment marker as a string--e.g., "//".
      delimiter - One of the options in the Delimiter enum--e.g., Delimiter.TAB.
      quoteCharacter - The quote character, e.g., '\"'.
      missingValueMarker - The missing value marker as a string--e.g., "NA".
      Returns:
      a ICovarianceMatrix object
      Throws:
      IOException - if the file cannot be read.
    • getDiscreteDataSet

      public static DataSet getDiscreteDataSet(DataModel dataSet)
      Returns the datamodel case to DataSet if it is discrete.
      Parameters:
      dataSet - a DataModel object
      Returns:
      a DataSet object
    • getContinuousDataSet

      public static DataSet getContinuousDataSet(DataModel dataSet)
      Returns the datamodel case to DataSet if it is continuous.
      Parameters:
      dataSet - a DataModel object
      Returns:
      a DataSet object
    • getMixedDataSet

      public static DataSet getMixedDataSet(DataModel dataSet)
      Returns the datamodel case to DataSet if it is mixed.
      Parameters:
      dataSet - a DataModel object
      Returns:
      a DataSet object
    • getCovarianceMatrix

      public static ICovarianceMatrix getCovarianceMatrix(DataModel dataModel, boolean precomputeCovariances)
      Returns the model cast to ICovarianceMatrix if already a covariance matric, or else returns the covariance matrix for a dataset.
      Parameters:
      dataModel - a DataModel object
      precomputeCovariances - a boolean
      Returns:
      a ICovarianceMatrix object
    • getCovarianceMatrix

      @NotNull public static @NotNull ICovarianceMatrix getCovarianceMatrix(DataSet dataSet, boolean precomputeCovariances)

      getCovarianceMatrix.

      Parameters:
      dataSet - a DataSet object
      precomputeCovariances - a boolean
      Returns:
      a ICovarianceMatrix object
    • getCorrelationMatrix

      @NotNull public static @NotNull ICovarianceMatrix getCorrelationMatrix(DataSet dataSet)

      getCorrelationMatrix.

      Parameters:
      dataSet - a DataSet object
      Returns:
      a ICovarianceMatrix object
    • loadKnowledge

      public static Knowledge loadKnowledge(File file, DelimiterType delimiter, String commentMarker) throws IOException
      Loads knowledge from a file. Assumes knowledge is the only thing in the file. No jokes please. :)
      Parameters:
      file - The text file to load the data from.
      delimiter - One of the options in the Delimiter enum--e.g., Delimiter.TAB.
      commentMarker - The comment marker as a string--e.g., "//".
      Returns:
      a Knowledge object
      Throws:
      IOException - if any.
    • loadKnowledge

      public static Knowledge loadKnowledge(Reader reader, DelimiterType delimiter, String commentMarker) throws IOException
      Loads knowledge from an arbitrary character stream, in the same tetrad2 format loadKnowledge(File, DelimiterType, String) reads and DataWriter.saveKnowledge writes. Added 2026-8-13 so that callers holding the specification as text -- in particular the editable "Text" tab of the knowledge editor -- can parse it through exactly the same path as the file loader, rather than round-tripping through a temporary file or reimplementing the parse.
      Parameters:
      reader - the character stream to read the specification from
      delimiter - one of the options in the DelimiterType enum
      commentMarker - the comment marker as a string -- e.g., "//"
      Returns:
      the parsed knowledge
      Throws:
      IOException - if any.