Class DataWriter
java.lang.Object
edu.cmu.tetrad.data.DataWriter
Provides static methods for saving data to files.
- Version:
- $Id: $Id
- Author:
- josephramsey
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidsaveKnowledge(Knowledge knowledge, Writer out) Saves knowledge in the tetrad2 text format thatSimpleDataLoader.loadKnowledgereads.static voidsaveKnowledge(Knowledge knowledge, Writer out, boolean useCommaDelimiter) Saves knowledge in the tetrad2 text format, choosing the delimiter explicitly.static voidwriteCovMatrixLowerTriangle(ICovarianceMatrix covMatrix, PrintWriter out, NumberFormat nf) Writes the lower triangle of a covariance matrix to file.static voidwriteCovMatrixSquare(ICovarianceMatrix covMatrix, PrintWriter out, NumberFormat nf) Writes the covariance matrix to file as a square matrix.static voidwriteRectangularData(DataSet dataSet, Writer out, char separator) Writes a dataset to file.
-
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 thatoutis not closed by this method, so the close method onoutwill 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- aICovarianceMatrixobjectout- The writer to write the output to.nf- aNumberFormatobject
-
writeCovMatrixSquare
public static void writeCovMatrixSquare(ICovarianceMatrix covMatrix, PrintWriter out, NumberFormat nf) Writes the covariance matrix to file as a square matrix.- Parameters:
covMatrix- aICovarianceMatrixobjectout- The writer to write the output to.nf- aNumberFormatobject
-
saveKnowledge
Saves knowledge in the tetrad2 text format thatSimpleDataLoader.loadKnowledgereads. 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; seesaveKnowledge(Knowledge, Writer, boolean).- Parameters:
knowledge- aKnowledgeobjectout- aWriterobject- 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- aKnowledgeobjectout- aWriterobjectuseCommaDelimiter- true to write the comma-delimited variant- Throws:
IOException- if any.
-