Search in sources :

Example 6 with DataReader

use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.

the class TestIndTestGSquare method getDataSet.

private DataSet getDataSet(int i) throws IOException {
    String filename = discreteFiles[i];
    System.out.println("Loading " + filename);
    DataReader reader = new DataReader();
    reader.setMissingValueMarker("-99");
    reader.setMaxIntegralDiscrete(5);
    return reader.parseTabular(new File(filename));
}
Also used : DataReader(edu.cmu.tetrad.data.DataReader) File(java.io.File)

Example 7 with DataReader

use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.

the class KnowledgeBoxEditor method loadKnowledge.

private void loadKnowledge(String fileName) {
    if (fileName == null) {
        throw new IllegalStateException("No data file was specified.");
    }
    try {
        File knowledgeFile = new File(fileName);
        CharArrayWriter writer = new CharArrayWriter();
        FileReader fr = new FileReader(knowledgeFile);
        int i;
        while ((i = fr.read()) != -1) {
            writer.append((char) i);
        }
        DataReader reader = new DataReader();
        char[] chars = writer.toCharArray();
        System.out.println(new String(chars));
        knowledgeBoxModel.setKnowledge(reader.parseKnowledge(chars));
    } catch (Exception e) {
        throw new RuntimeException("Couldn't read knowledge.");
    }
}
Also used : DataReader(edu.cmu.tetrad.data.DataReader) FileReader(java.io.FileReader) File(java.io.File) CharArrayWriter(java.io.CharArrayWriter) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) IOException(java.io.IOException)

Example 8 with DataReader

use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.

the class KnowledgeLoaderWizard method actionPerformed.

/**
 * Performs the action of loading a session from a file.
 */
public void actionPerformed(ActionEvent e) {
    int ret = 1;
    while (ret == 1) {
        JFileChooser chooser = getJFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        Component comp = (this.knowledgeEditable instanceof Component) ? (Component) this.knowledgeEditable : null;
        chooser.showOpenDialog(comp);
        File file = chooser.getSelectedFile();
        if (file != null) {
            Preferences.userRoot().put("fileSaveLocation", file.getParent());
        }
        KnowledgeLoaderWizard wizard = new KnowledgeLoaderWizard(file, knowledgeEditable);
        wizard.setCommentIndicator(commentIndicator);
        ret = JOptionPane.showOptionDialog(null, wizard, "Knowledge Import Wizard", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, new String[] { "Cancel", "Select Another File", "Import Data" }, "Import Data");
        this.delimiters = wizard.getDelimiters();
        this.commentIndicator = wizard.getCommentIndicator();
        // Import...
        if (ret == JOptionPane.OK_OPTION) {
            try {
                DataReader reader = new DataReader();
                IKnowledge knowledge = reader.parseKnowledge(file);
                this.knowledgeEditable.setKnowledge(knowledge);
            } catch (Exception e1) {
                String message = e1.getMessage() == null ? e1.getClass().getName() : e1.getMessage();
                if ("".equals(message)) {
                    message = "Could not load knowledge.";
                }
                JOptionPane.showMessageDialog(JOptionUtils.centeringComp(), message);
            }
        }
    }
}
Also used : IKnowledge(edu.cmu.tetrad.data.IKnowledge) DataReader(edu.cmu.tetrad.data.DataReader) File(java.io.File) IOException(java.io.IOException)

Example 9 with DataReader

use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.

the class LoadContinuousDataAndSingleGraph method createData.

@Override
public void createData(Parameters parameters) {
    this.dataSets = new ArrayList<>();
    File dir = new File(path + "/data_noise");
    if (dir.exists()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            if (!file.getName().endsWith(".txt"))
                continue;
            System.out.println("Loading data from " + file.getAbsolutePath());
            DataReader reader = new DataReader();
            reader.setVariablesSupplied(true);
            try {
                DataSet dataSet = reader.parseTabular(file);
                dataSets.add(dataSet);
            } catch (Exception e) {
                System.out.println("Couldn't parse " + file.getAbsolutePath());
            }
        }
    }
    File dir2 = new File(path + "/graph");
    if (dir2.exists()) {
        File[] files = dir2.listFiles();
        if (files.length != 1) {
            throw new IllegalArgumentException("Expecting exactly one graph file.");
        }
        File file = files[0];
        System.out.println("Loading graph from " + file.getAbsolutePath());
        this.graph = GraphUtils.loadGraphTxt(file);
        // if (!graph.isAdjacentTo(graph.getNode("X3"), graph.getNode("X4"))) {
        // graph.addUndirectedEdge(graph.getNode("X3"), graph.getNode("X4"));
        // }
        GraphUtils.circleLayout(this.graph, 225, 200, 150);
    }
    if (parameters.get("numRuns") != null) {
        parameters.set("numRuns", parameters.get("numRuns"));
    } else {
        parameters.set("numRuns", dataSets.size());
    }
    System.out.println();
}
Also used : DataReader(edu.cmu.tetrad.data.DataReader) DataSet(edu.cmu.tetrad.data.DataSet) File(java.io.File)

Example 10 with DataReader

use of edu.cmu.tetrad.data.DataReader in project tetrad by cmu-phil.

the class YeastPcCcdSearchWrapper method main.

public static void main(String[] args) {
    int[][] yeastReg = { { 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0 }, { 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1 }, { 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1 }, { 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0 }, { 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1 }, { 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }, { 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1 }, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }, { 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1 } };
    List listOfNames = new ArrayList();
    // get the file containing the file names
    DataSet cds = null;
    try {
        DataReader reader = new DataReader();
        cds = reader.parseTabular(new File(args[0]));
    } catch (IOException e) {
        e.printStackTrace();
    }
    String outfileprefix = args[1];
    String outverbosefile = outfileprefix + ".doc";
    String outsummaryfile = outfileprefix + ".xls";
    OutputStream s1 = null;
    OutputStream s2 = null;
    boolean verbose = true;
    try {
        s1 = new FileOutputStream(outverbosefile);
    } catch (IOException e) {
        System.out.println("Cannot open file file " + outverbosefile);
        System.exit(0);
    }
    DataOutputStream d1 = new DataOutputStream(s1);
    try {
        s2 = new FileOutputStream(outsummaryfile);
    } catch (IOException e) {
        System.out.println("Cannot open file file " + outsummaryfile);
        System.exit(0);
    }
    DataOutputStream d2 = new DataOutputStream(s2);
    try {
        // if(!verbose) {
        d2.writeBytes("File\tPC05 FP\tPC05 FN\tPC10 FP\tPC10 FN\tPC15 FP\t");
        d2.writeBytes("PC15 FN\tPC20 FP\tPC20 FN\tPC30 FP\tPC30 FN\t");
        d2.writeBytes("CCD05 FP\tCCD05 FN\tCCD10 FP\tCCD10 FN\tCCD 15 FP\t");
        d2.writeBytes("CCD15 FN\tCCD20 FP\tCCD20 FN\tCCD30 FP\tCCD 30 FN\n");
        // }
        // read in variable name and set up DataSet.
        // RectangularDataSet dataSet = DataLoaders.loadContinuousData(
        // new File(args[0]), DelimiterType.WHITESPACE,
        // "//"
        // );
        // int ngenes = 6;
        int ngenes = Integer.valueOf(args[2]);
        IKnowledge bk = new Knowledge2();
        bk.addToTiersByVarNames(listOfNames);
        // if(verbose) {
        d1.writeBytes("\n \n**Results for data in file yeastTRN**\n \n");
        d1.writeBytes("  Acutal adj matrix: \n");
        printAdjMatrix(yeastReg, listOfNames, d1);
        // }
        int[] PC05Accuracy;
        PC05Accuracy = PCAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] PC10Accuracy;
        PC10Accuracy = PCAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] PC15Accuracy;
        PC15Accuracy = PCAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] PC20Accuracy;
        PC20Accuracy = PCAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] PC30Accuracy;
        PC30Accuracy = PCAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] CCD05Accuracy;
        CCD05Accuracy = CcdAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] CCD10Accuracy;
        CCD10Accuracy = CcdAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] CCD15Accuracy;
        CCD15Accuracy = CcdAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] CCD20Accuracy;
        CCD20Accuracy = CcdAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        int[] CCD30Accuracy;
        CCD30Accuracy = CcdAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);
        /*
            int[] FCI05Accuracy;
            FCI05Accuracy =
              FCIAccuracy(0.05, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);

            int[] FCI10Accuracy;
            FCI10Accuracy =
              FCIAccuracy(0.10, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);

            int[] FCI15Accuracy;
            FCI15Accuracy =
              FCIAccuracy(0.15, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);

            int[] FCI20Accuracy;
            FCI20Accuracy =
              FCIAccuracy(0.20, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);

            int[] FCI30Accuracy;
            FCI30Accuracy =
              FCIAccuracy(0.30, ngenes, cds, bk, yeastReg, listOfNames, d1, verbose);


            */
        // if(!verbose) {
        d2.writeBytes("yeastTRN \t");
        d2.writeBytes(PC05Accuracy[0] + "\t");
        d2.writeBytes(PC05Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(PC10Accuracy[0] + "\t");
        d2.writeBytes(PC10Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(PC15Accuracy[0] + "\t");
        d2.writeBytes(PC15Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(PC20Accuracy[0] + "\t");
        d2.writeBytes(PC20Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(PC30Accuracy[0] + "\t");
        d2.writeBytes(PC30Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(CCD05Accuracy[0] + "\t");
        d2.writeBytes(CCD05Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(CCD10Accuracy[0] + "\t");
        d2.writeBytes(CCD10Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(CCD15Accuracy[0] + "\t");
        d2.writeBytes(CCD15Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(CCD20Accuracy[0] + "\t");
        d2.writeBytes(CCD20Accuracy[1] + "\t");
        // }
        // if(!verbose) {
        d2.writeBytes(CCD30Accuracy[0] + "\t");
        d2.writeBytes(CCD30Accuracy[1] + "\n");
    // }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) ArrayList(java.util.ArrayList) Knowledge2(edu.cmu.tetrad.data.Knowledge2) IKnowledge(edu.cmu.tetrad.data.IKnowledge) DataReader(edu.cmu.tetrad.data.DataReader) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

DataReader (edu.cmu.tetrad.data.DataReader)15 File (java.io.File)14 IOException (java.io.IOException)10 DataSet (edu.cmu.tetrad.data.DataSet)8 IKnowledge (edu.cmu.tetrad.data.IKnowledge)4 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)3 Graph (edu.cmu.tetrad.graph.Graph)2 FileReader (java.io.FileReader)2 JFileChooser (javax.swing.JFileChooser)2 Fask (edu.cmu.tetrad.algcomparison.algorithm.multi.Fask)1 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)1 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)1 DeltaSextadTest (edu.cmu.tetrad.search.DeltaSextadTest)1 IntSextad (edu.cmu.tetrad.search.IntSextad)1 BufferedReader (java.io.BufferedReader)1 CharArrayWriter (java.io.CharArrayWriter)1 FileWriter (java.io.FileWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Box (javax.swing.Box)1