Search in sources :

Example 1 with TakesInitialGraph

use of edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph in project tetrad by cmu-phil.

the class GeneralAlgorithmEditor method getAlgorithmFromInterface.

/**
 * Initialize algorithm
 *
 * @param algoModel
 * @param indTestModel
 * @param scoreModel
 * @return Algorithm
 */
public Algorithm getAlgorithmFromInterface(AlgorithmModel algoModel, IndependenceTestModel indTestModel, ScoreModel scoreModel) {
    Class algoClass = algoModel.getAlgorithm().getClazz();
    Class indTestClass = (indTestModel == null) ? null : indTestModel.getIndependenceTest().getClazz();
    Class scoreClass = (scoreModel == null) ? null : scoreModel.getScore().getClazz();
    Algorithm algorithm = null;
    try {
        algorithm = AlgorithmFactory.create(algoClass, indTestClass, scoreClass);
    } catch (IllegalAccessException | InstantiationException exception) {
        LOGGER.error("", exception);
    }
    // Those pairwise algos (R1, R2,..) require source graph to initialize - Zhou
    if (algorithm != null && algorithm instanceof TakesInitialGraph && runner.getSourceGraph() != null && !runner.getDataModelList().isEmpty()) {
        Algorithm initialGraph = new SingleGraphAlg(runner.getSourceGraph());
        ((TakesInitialGraph) algorithm).setInitialGraph(initialGraph);
    }
    return algorithm;
}
Also used : SingleGraphAlg(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.SingleGraphAlg) TakesInitialGraph(edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm)

Aggregations

Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)1 SingleGraphAlg (edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.SingleGraphAlg)1 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)1