Class DataWriter

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

public final class DataWriter extends Object
Provides static methods for saving data to files.
Version:
$Id: $Id
Author:
josephramsey
  • Method Details

    • writeRectangularData

      public static void writeRectangularData(DataSet dataSet, Writer out, char separator) throws IOException
      Writes a dataset to file. The dataset may have continuous and/or discrete columns. Note that out is not closed by this method, so the close method on out will need to be called externally.
      Parameters:
      dataSet - The data set to save.
      out - The writer to write the output to.
      separator - The character separating fields, usually '\t' or ','.
      Throws:
      IOException - If there is some problem dealing with the writer.
    • writeCovMatrixLowerTriangle

      public static void writeCovMatrixLowerTriangle(ICovarianceMatrix covMatrix, PrintWriter out, NumberFormat nf)
      Writes the lower triangle of a covariance matrix to file.
      Parameters:
      covMatrix - a ICovarianceMatrix object
      out - The writer to write the output to.
      nf - a NumberFormat object
    • writeCovMatrixSquare

      public static void writeCovMatrixSquare(ICovarianceMatrix covMatrix, PrintWriter out, NumberFormat nf)
      Writes the covariance matrix to file as a square matrix.
      Parameters:
      covMatrix - a ICovarianceMatrix object
      out - The writer to write the output to.
      nf - a NumberFormat object
    • saveKnowledge

      public static void saveKnowledge(Knowledge knowledge, Writer out) throws IOException
      Saves knowledge in the tetrad2 text format that SimpleDataLoader.loadKnowledge reads. If every variable name mentioned by the knowledge is free of whitespace and commas, the format is the original whitespace-delimited one, unchanged. If some mentioned name contains whitespace -- which the whitespace-delimited format cannot represent -- the comma-delimited variant is written instead; see saveKnowledge(Knowledge, Writer, boolean).
      Parameters:
      knowledge - a Knowledge object
      out - a Writer object
      Throws:
      IOException - if any.
    • saveKnowledge

      public static void saveKnowledge(Knowledge knowledge, Writer out, boolean useCommaDelimiter) throws IOException
      Saves knowledge in the tetrad2 text format, choosing the delimiter explicitly. In the comma-delimited variant the header line is /knowledge comma, which the loader reads as an instruction to split names on commas rather than whitespace, so names containing spaces survive the round trip; in tier and group lines the names are separated by commas, and in forbiddirect and requiredirect lines the from- and to-names are separated by a comma. A name containing a comma is written in double quotes. Names may not contain the double-quote character in either variant.
      Parameters:
      knowledge - a Knowledge object
      out - a Writer object
      useCommaDelimiter - true to write the comma-delimited variant
      Throws:
      IOException - if any.