Search in sources :

Example 6 with ContinuousTabularDataFileReader

use of edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader in project tetrad by cmu-phil.

the class GdistanceRandomApply method main.

public static void main(String... args) {
    // thresholds are the barriers between histogram buckets.
    double[] thresholds;
    thresholds = new double[5];
    thresholds[0] = 0;
    thresholds[1] = 2;
    thresholds[2] = 4;
    thresholds[3] = 6;
    thresholds[4] = 8;
    // load the location map
    String workingDirectory = System.getProperty("user.dir");
    System.out.println(workingDirectory);
    Path mapPath = Paths.get("erich_coordinates.txt");
    System.out.println(mapPath);
    TabularDataReader dataReaderMap = new ContinuousTabularDataFileReader(mapPath.toFile(), Delimiter.COMMA);
    try {
        DataSet locationMap = (DataSet) DataConvertUtils.toDataModel(dataReaderMap.readInData());
        System.out.println("locationMap loaded");
        GdistanceRandom simRandGdistances = new GdistanceRandom(locationMap);
        System.out.println("GdistanceRandom constructed");
        simRandGdistances.setNumEdges1(300);
        simRandGdistances.setNumEdges2(300);
        simRandGdistances.setVerbose(false);
        System.out.println("Edge parameters set, starting simulations");
        List<List<Double>> GdistanceLists = simRandGdistances.randomSimulation(2);
        System.out.println("Simulations done, calculating histograms");
        for (List<Double> gdist : GdistanceLists) {
            double[] histogram = GdistanceUtils.histogram(gdist, thresholds);
            // making the string to print out histogram values
            String histString = " ";
            for (int i = 0; i < Array.getLength(histogram); i++) {
                histString = histString + " " + histogram[i];
            }
            System.out.println(histString);
        }
    } catch (Exception IOException) {
        IOException.printStackTrace();
    }
}
Also used : Path(java.nio.file.Path) TabularDataReader(edu.pitt.dbmi.data.reader.tabular.TabularDataReader) DataSet(edu.cmu.tetrad.data.DataSet) ContinuousTabularDataFileReader(edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader) List(java.util.List)

Example 7 with ContinuousTabularDataFileReader

use of edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader in project tetrad by cmu-phil.

the class TestDM method readAndSearchData.

// Reads in data and runs search. Note: Assumes variable names are of the form X0, X1, etc.
// Both input and output integer arrays are the indexes of their respective variables.
public DMSearch readAndSearchData(String fileLocation, int[] inputs, int[] outputs, boolean useGES, int[] trueInputs) {
    File file = new File(fileLocation);
    DataSet data = null;
    try {
        TabularDataReader dataReader = new ContinuousTabularDataFileReader(file, Delimiter.SPACE);
        data = (DataSet) DataConvertUtils.toDataModel(dataReader.readInData());
    } catch (IOException e) {
        print("Failed to read in data.");
        e.printStackTrace();
    }
    print("Read Data");
    DMSearch search = new DMSearch();
    search.setInputs(inputs);
    search.setOutputs(outputs);
    if (useGES == false) {
        search.setAlphaPC(.05);
        search.setUseFges(useGES);
        search.setData(data);
        search.setTrueInputs(trueInputs);
        search.search();
    } else {
        search.setData(data);
        search.setTrueInputs(trueInputs);
        search.search();
    // search.search(data, trueInputs);
    }
    return (search);
}
Also used : TabularDataReader(edu.pitt.dbmi.data.reader.tabular.TabularDataReader) DataSet(edu.cmu.tetrad.data.DataSet) ContinuousTabularDataFileReader(edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader) IOException(java.io.IOException) File(java.io.File) DMSearch(edu.cmu.tetrad.search.DMSearch)

Aggregations

ContinuousTabularDataFileReader (edu.pitt.dbmi.data.reader.tabular.ContinuousTabularDataFileReader)7 TabularDataReader (edu.pitt.dbmi.data.reader.tabular.TabularDataReader)7 DataSet (edu.cmu.tetrad.data.DataSet)5 Path (java.nio.file.Path)5 Graph (edu.cmu.tetrad.graph.Graph)4 File (java.io.File)3 PrintWriter (java.io.PrintWriter)3 Node (edu.cmu.tetrad.graph.Node)2 Delimiter (edu.pitt.dbmi.data.Delimiter)2 VerticalDiscreteTabularDataReader (edu.pitt.dbmi.data.reader.tabular.VerticalDiscreteTabularDataReader)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BayesPm (edu.cmu.tetrad.bayes.BayesPm)1 MlBayesIm (edu.cmu.tetrad.bayes.MlBayesIm)1 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)1 CovarianceMatrixOnTheFly (edu.cmu.tetrad.data.CovarianceMatrixOnTheFly)1 DataModel (edu.cmu.tetrad.data.DataModel)1 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)1 Dag (edu.cmu.tetrad.graph.Dag)1 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)1