use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.
the class MisclassificationUtils method endpointMisclassification.
public static String endpointMisclassification(Graph estGraph, Graph refGraph) {
List<Node> _nodes = refGraph.getNodes();
estGraph = GraphUtils.replaceNodes(estGraph, _nodes);
refGraph = GraphUtils.replaceNodes(refGraph, _nodes);
_nodes = estGraph.getNodes();
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, "NULL");
table2.setToken(1, 0, "-o");
table2.setToken(2, 0, "->");
table2.setToken(3, 0, "--");
table2.setToken(4, 0, "NULL");
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();
}
use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.
the class MisclassificationUtils method edgeMisclassifications.
public static String edgeMisclassifications(Graph estGraph, Graph refGraph) {
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, "null");
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, "null");
int[][] counts = new int[8][6];
for (Edge est1 : estGraph.getEdges()) {
Node x = est1.getNode1();
Node y = est1.getNode2();
Edge true1 = refGraph.getEdge(x, y);
if (true1 == null) {
true1 = new Edge(x, y, Endpoint.NULL, Endpoint.NULL);
}
Edge trueConvert = new Edge(x, y, true1.getProximalEndpoint(x), true1.getProximalEndpoint(y));
int m = getTypeLeft(trueConvert, est1);
int n = getTypeTop(est1);
counts[m][n]++;
}
for (Edge true1 : refGraph.getEdges()) {
Node x = true1.getNode1();
Node y = true1.getNode2();
Edge est1 = estGraph.getEdge(x, y);
if (est1 == null) {
est1 = new Edge(x, y, Endpoint.NULL, Endpoint.NULL);
}
Edge estConvert = new Edge(x, y, est1.getProximalEndpoint(x), est1.getProximalEndpoint(y));
int m = getTypeLeft(true1, estConvert);
int n = getTypeTop(estConvert);
if (n == 5) {
counts[m][n]++;
}
}
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("\n").append(table2.toString());
return builder.toString();
}
use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.
the class TabularComparisonEditor method getTextTable.
private TextTable getTextTable(DataSet dataSet, NumberFormat nf) {
TextTable table = new TextTable(dataSet.getNumRows() + 2, dataSet.getNumColumns() + 1);
table.setTabDelimited(true);
table.setToken(0, 0, "Run");
for (int j = 0; j < dataSet.getNumColumns(); j++) {
table.setToken(0, j + 1, dataSet.getVariable(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 < dataSet.getNumColumns(); j++) {
double d = dataSet.getDouble(i, j);
if (Double.isNaN(d)) {
table.setToken(i + 1, j + 1, "*");
} else {
table.setToken(i + 1, j + 1, nf.format(d));
}
}
}
NumberFormat nf2 = new DecimalFormat("0.00");
for (int j = 0; j < dataSet.getNumColumns(); j++) {
double sum = 0.0;
int count = 0;
for (int i = 0; i < dataSet.getNumRows(); i++) {
double d = dataSet.getDouble(i, j);
if (!Double.isNaN(d)) {
sum += d;
count++;
}
}
double avg = sum / count;
if (Double.isNaN(avg)) {
table.setToken(dataSet.getNumRows() + 2 - 1, j + 1, "*");
} else {
table.setToken(dataSet.getNumRows() + 2 - 1, j + 1, nf2.format(avg));
}
}
table.setToken(dataSet.getNumRows() + 2 - 1, 0, "Avg");
return table;
}
use of edu.cmu.tetrad.util.TextTable in project tetrad by cmu-phil.
the class TestPc method printBestStats.
private void printBestStats(double[][][] allAllRet, String[] algorithms, String[] statLabels, int maxLatents, int jumpLatents, double ofInterestCutoff) {
TextTable table = new TextTable(allAllRet.length + 1, allAllRet[0][0].length + 1);
int latentIndex = -1;
class Pair {
private String algorithm;
private double stat;
public Pair(String algorithm, double stat) {
this.algorithm = algorithm;
this.stat = stat;
}
public String getAlgorithm() {
return algorithm;
}
public double getStat() {
return stat;
}
}
for (int numLatents = 0; numLatents <= maxLatents; numLatents += jumpLatents) {
latentIndex++;
table.setToken(latentIndex + 1, 0, numLatents + "");
for (int statIndex = 0; statIndex < allAllRet[latentIndex][0].length; statIndex++) {
// double maxStat = Double.NaN;
String maxAlg = "-";
List<Pair> algStats = new ArrayList<>();
for (int t = 0; t < algorithms.length; t++) {
double stat = allAllRet[latentIndex][t][statIndex];
if (!Double.isNaN(stat)) {
algStats.add(new Pair(algorithms[t], stat));
}
}
if (algStats.isEmpty()) {
maxAlg = "-";
} else {
Collections.sort(algStats, new Comparator<Pair>() {
@Override
public int compare(Pair o1, Pair o2) {
return -Double.compare(o1.getStat(), o2.getStat());
}
});
double maxStat = algStats.get(0).getStat();
maxAlg = algStats.get(0).getAlgorithm();
double minStat = algStats.get(algStats.size() - 1).getStat();
double diff = maxStat - minStat;
double ofInterest = maxStat - ofInterestCutoff * (diff);
for (int i = 1; i < algStats.size(); i++) {
if (algStats.get(i).getStat() >= ofInterest) {
maxAlg += "," + algStats.get(i).getAlgorithm();
}
}
}
table.setToken(latentIndex + 1, statIndex + 1, maxAlg);
}
}
for (int j = 0; j < statLabels.length; j++) {
table.setToken(0, j + 1, statLabels[j]);
}
System.out.println();
System.out.println(table.toString());
}
Aggregations