Search in sources :

Example 1 with AlgorithmAnnotations

use of edu.cmu.tetrad.annotation.AlgorithmAnnotations 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;
}
Also used : UsesScoreWrapper(edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper) AlgorithmAnnotations(edu.cmu.tetrad.annotation.AlgorithmAnnotations) TakesIndependenceWrapper(edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper)

Aggregations

TakesIndependenceWrapper (edu.cmu.tetrad.algcomparison.utils.TakesIndependenceWrapper)1 UsesScoreWrapper (edu.cmu.tetrad.algcomparison.utils.UsesScoreWrapper)1 AlgorithmAnnotations (edu.cmu.tetrad.annotation.AlgorithmAnnotations)1