edu.cmu.tetrad.algcomparison.statistic.AncestorRecall Maven / Gradle / Ivy
package edu.cmu.tetrad.algcomparison.statistic;
import edu.cmu.tetrad.data.DataModel;
import edu.cmu.tetrad.graph.Graph;
import edu.cmu.tetrad.graph.Node;
import java.io.Serial;
import java.util.List;
/**
* Ancestor recall.
*
* @author josephramsey
* @version $Id: $Id
*/
public class AncestorRecall implements Statistic {
@Serial
private static final long serialVersionUID = 23L;
/**
* Constructs the statistic.
*/
public AncestorRecall() {
}
/**
* {@inheritDoc}
*
* Returns the name of the statistic.
*/
@Override
public String getAbbreviation() {
return "Anc-Rec";
}
/**
* {@inheritDoc}
*
* Returns the description of the statistic.
*/
@Override
public String getDescription() {
return "Proportion of X~~>Y in the true graph for which also X~~>Y in estimated graph";
}
/**
* {@inheritDoc}
*
* Calculates the statistic.
*/
@Override
public double getValue(Graph trueGraph, Graph estGraph, DataModel dataModel) {
int tp = 0;
int fn = 0;
List nodes = estGraph.getNodes();
for (Node x : nodes) {
for (Node y : nodes) {
// if (x == y) continue;
if (trueGraph.paths().isAncestorOf(x, y)) {
if (estGraph.paths().isAncestorOf(x, y)) {
tp++;
} else {
fn++;
}
}
}
}
return tp / (double) (tp + fn);
}
/**
* {@inheritDoc}
*
* Returns the norm value of the statistic.
*/
@Override
public double getNormValue(double value) {
return value;
}
}