Search in sources :

Example 6 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class PerformanceTests method endpointMisclassification.

public static String endpointMisclassification(List<Node> _nodes, Graph estGraph, Graph refGraph) {
    int[][] counts = new int[4][4];
    for (int i = 0; i < _nodes.size(); i++) {
        for (int j = 0; j < _nodes.size(); j++) {
            if (i == j)
                continue;
            Endpoint endpoint1 = refGraph.getEndpoint(_nodes.get(i), _nodes.get(j));
            Endpoint endpoint2 = estGraph.getEndpoint(_nodes.get(i), _nodes.get(j));
            int index1 = getIndex(endpoint1);
            int index2 = getIndex(endpoint2);
            counts[index1][index2]++;
        }
    }
    TextTable table2 = new TextTable(5, 5);
    table2.setToken(0, 1, "-o");
    table2.setToken(0, 2, "->");
    table2.setToken(0, 3, "--");
    table2.setToken(0, 4, "NO EDGE");
    table2.setToken(1, 0, "-o");
    table2.setToken(2, 0, "->");
    table2.setToken(3, 0, "--");
    table2.setToken(4, 0, "NO EDGE");
    int sum = 0;
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (i == 3 && j == 3)
                continue;
            else
                sum += counts[i][j];
        }
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            if (i == 3 && j == 3)
                table2.setToken(i + 1, j + 1, "");
            else
                table2.setToken(i + 1, j + 1, "" + counts[i][j]);
        }
    }
    return table2.toString();
// println("\n" + name);
// println(table2.toString());
// println("");
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable)

Example 7 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class GraphUtils method edgeMisclassifications.

public static String edgeMisclassifications(int[][] counts) {
    StringBuilder builder = new StringBuilder();
    TextTable table2 = new TextTable(9, 7);
    table2.setToken(1, 0, "---");
    table2.setToken(2, 0, "o-o");
    table2.setToken(3, 0, "o->");
    table2.setToken(4, 0, "<-o");
    table2.setToken(5, 0, "-->");
    table2.setToken(6, 0, "<--");
    table2.setToken(7, 0, "<->");
    table2.setToken(8, 0, "No Edge");
    table2.setToken(0, 1, "---");
    table2.setToken(0, 2, "o-o");
    table2.setToken(0, 3, "o->");
    table2.setToken(0, 4, "-->");
    table2.setToken(0, 5, "<->");
    table2.setToken(0, 6, "No Edge");
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 6; j++) {
            if (i == 7 && j == 5) {
                table2.setToken(i + 1, j + 1, "*");
            } else {
                table2.setToken(i + 1, j + 1, "" + counts[i][j]);
            }
        }
    }
    builder.append(table2.toString());
    int correctEdges = 0;
    int estimatedEdges = 0;
    for (int i = 0; i < counts.length; i++) {
        for (int j = 0; j < counts[0].length - 1; j++) {
            if ((i == 0 && j == 0) || (i == 1 && j == 1) || (i == 2 && j == 2) || (i == 4 && j == 3) || (i == 6 && j == 4)) {
                correctEdges += counts[i][j];
            }
            estimatedEdges += counts[i][j];
        }
    }
    NumberFormat nf2 = new DecimalFormat("0.00");
    builder.append("\nRatio correct edges to estimated edges = ").append(nf2.format((correctEdges / (double) estimatedEdges)));
    return builder.toString();
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 8 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class Comparison2 method getTextTable.

private static TextTable getTextTable(DataSet dataSet, int[] columns, NumberFormat nf) {
    TextTable table = new TextTable(dataSet.getNumRows() + 2, columns.length + 1);
    table.setToken(0, 0, "Run #");
    for (int j = 0; j < columns.length; j++) {
        table.setToken(0, j + 1, dataSet.getVariable(columns[j]).getName());
    }
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        table.setToken(i + 1, 0, Integer.toString(i + 1));
    }
    for (int i = 0; i < dataSet.getNumRows(); i++) {
        for (int j = 0; j < columns.length; j++) {
            table.setToken(i + 1, j + 1, nf.format(dataSet.getDouble(i, columns[j])));
        }
    }
    NumberFormat nf2 = new DecimalFormat("0.00");
    for (int j = 0; j < columns.length; j++) {
        double sum = 0.0;
        for (int i = 0; i < dataSet.getNumRows(); i++) {
            sum += dataSet.getDouble(i, columns[j]);
        }
        double avg = sum / dataSet.getNumRows();
        table.setToken(dataSet.getNumRows() + 2 - 1, j + 1, nf2.format(avg));
    }
    table.setToken(dataSet.getNumRows() + 2 - 1, 0, "Avg");
    return table;
}
Also used : TextTable(edu.cmu.tetrad.util.TextTable) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 9 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class TestFci method testFciAnc.

// @Test
public void testFciAnc() {
    int numMeasures = 50;
    double edgeFactor = 2.0;
    int numRuns = 10;
    double alpha = 0.01;
    double penaltyDiscount = 4.0;
    int numVarsToMarginalize = 5;
    int numLatents = 10;
    System.out.println("num measures = " + numMeasures);
    System.out.println("edge factor = " + edgeFactor);
    System.out.println("alpha = " + alpha);
    System.out.println("penaltyDiscount = " + penaltyDiscount);
    System.out.println("num runs = " + numRuns);
    System.out.println("num vars to marginalize = " + numVarsToMarginalize);
    System.out.println("num latents = " + numLatents);
    System.out.println();
    for (int i = 0; i < numRuns; i++) {
        int numEdges = (int) (edgeFactor * (numMeasures + numLatents));
        List<Node> nodes = new ArrayList<>();
        for (int r = 0; r < numMeasures + numLatents; r++) {
            String name = "X" + (r + 1);
            nodes.add(new ContinuousVariable(name));
        }
        Graph dag = GraphUtils.randomGraphRandomForwardEdges(nodes, numLatents, numEdges, 10, 10, 10, false);
        SemPm pm = new SemPm(dag);
        SemIm im = new SemIm(pm);
        DataSet data = im.simulateData(1000, false);
        Graph pag = getPag(alpha, penaltyDiscount, data);
        DataSet marginalData = data.copy();
        List<Node> variables = marginalData.getVariables();
        Collections.shuffle(variables);
        for (int m = 0; m < numVarsToMarginalize; m++) {
            marginalData.removeColumn(marginalData.getColumn(variables.get(m)));
        }
        Graph margPag = getPag(alpha, penaltyDiscount, marginalData);
        int ancAnc = 0;
        int ancNanc = 0;
        int nancAnc = 0;
        int nancNanc = 0;
        int ambAnc = 0;
        int ambNanc = 0;
        int totalAncMarg = 0;
        int totalNancMarg = 0;
        for (Node n1 : marginalData.getVariables()) {
            for (Node n2 : marginalData.getVariables()) {
                if (n1 == n2)
                    continue;
                if (ancestral(n1, n2, margPag)) {
                    if (ancestral(n1, n2, pag)) {
                        ancAnc++;
                    } else if (nonAncestral(n1, n2, pag)) {
                        nancAnc++;
                    } else {
                        ambAnc++;
                    }
                    totalAncMarg++;
                } else if (nonAncestral(n1, n2, margPag)) {
                    if (ancestral(n1, n2, pag)) {
                        ancNanc++;
                    } else if (nonAncestral(n1, n2, pag)) {
                        nancNanc++;
                    } else {
                        ambNanc++;
                    }
                    totalNancMarg++;
                }
            }
        }
        // {
        // TextTable table = new TextTable(5, 3);
        // table.setToken(0, 1, "Ancestral");
        // table.setToken(0, 2, "Nonancestral");
        // table.setToken(1, 0, "Ancestral");
        // table.setToken(2, 0, "Nonancestral");
        // table.setToken(3, 0, "Ambiguous");
        // table.setToken(4, 0, "Total");
        // 
        // table.setToken(1, 1, ancAnc + "");
        // table.setToken(2, 1, nancAnc + "");
        // table.setToken(3, 1, ambAnc + "");
        // table.setToken(1, 2, ancNanc + "");
        // table.setToken(2, 2, nancNanc + "");
        // table.setToken(3, 2, ambNanc + "");
        // table.setToken(4, 1, totalAncMarg + "");
        // table.setToken(4, 2, totalNancMarg + "");
        // 
        // System.out.println(table);
        // }
        {
            TextTable table = new TextTable(5, 3);
            table.setToken(0, 1, "Ancestral");
            table.setToken(0, 2, "Nonancestral");
            table.setToken(1, 0, "Ancestral");
            table.setToken(2, 0, "Nonancestral");
            table.setToken(3, 0, "Ambiguous");
            table.setToken(4, 0, "Total");
            NumberFormat nf = new DecimalFormat("0.00");
            table.setToken(1, 1, nf.format(ancAnc / (double) totalAncMarg) + "");
            table.setToken(2, 1, nf.format(nancAnc / (double) totalAncMarg) + "");
            table.setToken(3, 1, nf.format(ambAnc / (double) totalAncMarg) + "");
            table.setToken(1, 2, nf.format(ancNanc / (double) totalNancMarg) + "");
            table.setToken(2, 2, nf.format(nancNanc / (double) totalNancMarg) + "");
            table.setToken(3, 2, nf.format(ambNanc / (double) totalNancMarg) + "");
            table.setToken(4, 1, totalAncMarg + "");
            table.setToken(4, 2, totalNancMarg + "");
            System.out.println(table);
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) ArrayList(java.util.ArrayList) TextTable(edu.cmu.tetrad.util.TextTable) SemPm(edu.cmu.tetrad.sem.SemPm) SemIm(edu.cmu.tetrad.sem.SemIm) NumberFormat(java.text.NumberFormat)

Example 10 with TextTable

use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.

the class TabularComparisonEditor method getTableDisplay.

private Box getTableDisplay() {
    DataSet dataSet = comparison.getDataSet();
    TextTable table = getTextTable(dataSet, new DecimalFormat("0.00"));
    StringBuilder b0 = new StringBuilder();
    String trueGraphAndTarget = "Target graphs from " + comparison.getTargetName() + "\nTrue graphs from " + comparison.getReferenceName();
    b0.append(trueGraphAndTarget + "\n\n");
    b0.append(table.toString());
    Map<String, String> allParamsSettings = comparison.getAllParamSettings();
    if (allParamsSettings != null) {
        for (String key : allParamsSettings.keySet()) {
            b0.append(key).append(" = ").append(allParamsSettings.get(key)).append("\n");
        }
    }
    JTextArea area = new JTextArea(b0.toString());
    area.setFont(new Font(Font.MONOSPACED, Font.BOLD, 12));
    // area.setPreferredSize(area.getMaximumSize());
    JScrollPane pane = new JScrollPane(area);
    pane.setPreferredSize(new Dimension(700, 400));
    Box b = Box.createVerticalBox();
    Box b1 = Box.createHorizontalBox();
    b1.add(new JLabel("Tabular Comparison\b"));
    b.add(b1);
    b.add(Box.createVerticalStrut(10));
    Box b3 = Box.createHorizontalBox();
    b3.add(pane);
    b.add(b3);
    return b;
}
Also used : DataSet(edu.cmu.tetrad.data.DataSet) TextTable(edu.cmu.tetrad.util.TextTable) DecimalFormat(java.text.DecimalFormat)

Aggregations

TextTable (edu.cmu.tetrad.util.TextTable)19 DecimalFormat (java.text.DecimalFormat)8 NumberFormat (java.text.NumberFormat)8 ArrayList (java.util.ArrayList)2 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 ExternalAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.ExternalAlgorithm)1 MultiDataSetAlgorithm (edu.cmu.tetrad.algcomparison.algorithm.MultiDataSetAlgorithm)1 Simulation (edu.cmu.tetrad.algcomparison.simulation.Simulation)1 Statistic (edu.cmu.tetrad.algcomparison.statistic.Statistic)1 HasParameterValues (edu.cmu.tetrad.algcomparison.utils.HasParameterValues)1 DataSet (edu.cmu.tetrad.data.DataSet)1 SemIm (edu.cmu.tetrad.sem.SemIm)1 SemPm (edu.cmu.tetrad.sem.SemPm)1