use of edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper in project tetrad by cmu-phil.
the class AlgorithmFactory method create.
public static Algorithm create(Class<? extends Algorithm> algoClass, IndependenceWrapper test, ScoreWrapper score) throws IllegalAccessException, InstantiationException {
if (algoClass == null) {
throw new IllegalArgumentException("Algorithm class cannot be null.");
}
AlgorithmAnnotations algoAnno = AlgorithmAnnotations.getInstance();
boolean testRequired = algoAnno.requireIndependenceTest(algoClass);
if (testRequired && test == null) {
throw new IllegalArgumentException("Test of independence is required.");
}
boolean scoreRequired = algoAnno.requireScore(algoClass);
if (scoreRequired && score == null) {
throw new IllegalArgumentException("Score is required.");
}
Algorithm algorithm = algoClass.newInstance();
if (testRequired) {
((TakesIndependenceWrapper) algorithm).setIndependenceWrapper(test);
}
if (scoreRequired) {
((UsesScoreWrapper) algorithm).setScoreWrapper(score);
}
return algorithm;
}
Aggregations