Search in sources :

Example 6 with DataType

use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.

the class GeneralAlgorithmEditor method refreshTestList.

private void refreshTestList() {
    updatingTestModels = true;
    indTestComboBox.removeAllItems();
    AlgorithmModel algoModel = algorithmList.getSelectedValue();
    if (algoModel != null && algoModel.isRequiredTest()) {
        boolean linear = linearVarChkBox.isSelected();
        boolean gaussian = gaussianVarChkBox.isSelected();
        List<IndependenceTestModel> models = IndependenceTestModels.getInstance().getModels(dataType);
        if (linear && gaussian) {
            models.stream().filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
        } else if (linear) {
            models.stream().filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> !e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
        } else if (gaussian) {
            models.stream().filter(e -> !e.getIndependenceTest().getClazz().isAnnotationPresent(Linear.class)).filter(e -> e.getIndependenceTest().getClazz().isAnnotationPresent(Gaussian.class)).forEach(e -> indTestComboBox.addItem(e));
        } else {
            models.stream().forEach(e -> indTestComboBox.addItem(e));
        }
    }
    updatingTestModels = false;
    if (indTestComboBox.getItemCount() > 0) {
        indTestComboBox.setEnabled(true);
        Map<DataType, IndependenceTestModel> map = defaultIndTestModels.get(algoModel);
        if (map == null) {
            map = new EnumMap<>(DataType.class);
            defaultIndTestModels.put(algoModel, map);
        }
        IndependenceTestModel testModel = map.get(dataType);
        if (testModel == null) {
            testModel = IndependenceTestModels.getInstance().getDefaultModel(dataType);
            if (testModel == null) {
                testModel = indTestComboBox.getItemAt(0);
            }
        }
        indTestComboBox.setSelectedItem(testModel);
    } else {
        indTestComboBox.setEnabled(false);
    }
}
Also used : Enumeration(java.util.Enumeration) JDialog(javax.swing.JDialog) TetradDesktop(edu.cmu.tetradapp.app.TetradDesktop) LoggerFactory(org.slf4j.LoggerFactory) Parameters(edu.cmu.tetrad.util.Parameters) Node(edu.cmu.tetrad.graph.Node) PaddingPanel(edu.cmu.tetradapp.ui.PaddingPanel) StringUtils(org.apache.commons.lang3.StringUtils) Linear(edu.cmu.tetrad.annotation.Linear) AlgorithmModel(edu.cmu.tetradapp.ui.model.AlgorithmModel) Map(java.util.Map) ScoreModel(edu.cmu.tetradapp.ui.model.ScoreModel) ICovarianceMatrix(edu.cmu.tetrad.data.ICovarianceMatrix) HpcJobActivityAction(edu.cmu.tetradapp.app.hpc.action.HpcJobActivityAction) BorderLayout(java.awt.BorderLayout) ButtonModel(javax.swing.ButtonModel) JComboBox(javax.swing.JComboBox) GraphSelectionWrapper(edu.cmu.tetradapp.model.GraphSelectionWrapper) Method(java.lang.reflect.Method) Path(java.nio.file.Path) GeneralAlgorithmRunner(edu.cmu.tetradapp.model.GeneralAlgorithmRunner) BdeuScore(edu.cmu.tetrad.algcomparison.score.BdeuScore) HpcJobManager(edu.cmu.tetradapp.app.hpc.manager.HpcJobManager) Frame(java.awt.Frame) HpcAccountManager(edu.cmu.tetradapp.app.hpc.manager.HpcAccountManager) WatchedProcess(edu.cmu.tetradapp.util.WatchedProcess) EnumMap(java.util.EnumMap) AlgType(edu.cmu.tetrad.annotation.AlgType) HpcParameter(edu.pitt.dbmi.tetrad.db.entity.HpcParameter) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) ComboBoxModel(javax.swing.ComboBoxModel) Gaussian(edu.cmu.tetrad.annotation.Gaussian) Nonexecutable(edu.cmu.tetrad.annotation.Nonexecutable) JsonWebToken(edu.pitt.dbmi.ccd.rest.client.dto.user.JsonWebToken) HpcJobInfo(edu.pitt.dbmi.tetrad.db.entity.HpcJobInfo) JRadioButton(javax.swing.JRadioButton) DataModel(edu.cmu.tetrad.data.DataModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) Box(javax.swing.Box) Dimension(java.awt.Dimension) List(java.util.List) DataSet(edu.cmu.tetrad.data.DataSet) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) MessageDigestHash(edu.pitt.dbmi.ccd.commons.file.MessageDigestHash) JPanel(javax.swing.JPanel) Toolkit(java.awt.Toolkit) CardLayout(java.awt.CardLayout) JOptionUtils(edu.cmu.tetrad.util.JOptionUtils) HashMap(java.util.HashMap) AlgorithmModels(edu.cmu.tetradapp.ui.model.AlgorithmModels) FinalizingEditor(edu.cmu.tetradapp.util.FinalizingEditor) AlgorithmParamRequest(edu.pitt.dbmi.tetrad.db.entity.AlgorithmParamRequest) SwingConstants(javax.swing.SwingConstants) ArrayList(java.util.ArrayList) SingleGraphAlg(edu.cmu.tetrad.algcomparison.algorithm.oracle.pattern.SingleGraphAlg) HashSet(java.util.HashSet) HasKnowledge(edu.cmu.tetrad.algcomparison.utils.HasKnowledge) SemBicScore(edu.cmu.tetrad.algcomparison.score.SemBicScore) DataType(edu.cmu.tetrad.data.DataType) JsonUtils(edu.cmu.tetrad.util.JsonUtils) IndependenceTestModel(edu.cmu.tetradapp.ui.model.IndependenceTestModel) IndependenceTestModels(edu.cmu.tetradapp.ui.model.IndependenceTestModels) TsImages(edu.cmu.tetrad.algcomparison.algorithm.oracle.pag.TsImages) LinkedList(java.util.LinkedList) AlgorithmFactory(edu.cmu.tetrad.algcomparison.algorithm.AlgorithmFactory) Algorithm(edu.cmu.tetrad.algcomparison.algorithm.Algorithm) JButton(javax.swing.JButton) Logger(org.slf4j.Logger) AlgorithmParameter(edu.pitt.dbmi.tetrad.db.entity.AlgorithmParameter) Files(java.nio.file.Files) ButtonGroup(javax.swing.ButtonGroup) TakesInitialGraph(edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph) Window(java.awt.Window) JList(javax.swing.JList) DesktopController(edu.cmu.tetradapp.util.DesktopController) Graph(edu.cmu.tetrad.graph.Graph) HpcAccountUtils(edu.cmu.tetradapp.app.hpc.util.HpcAccountUtils) JvmOptions(edu.pitt.dbmi.tetrad.db.entity.JvmOptions) IOException(java.io.IOException) JOptionPane(javax.swing.JOptionPane) ActionEvent(java.awt.event.ActionEvent) JScrollPane(javax.swing.JScrollPane) LayoutStyle(javax.swing.LayoutStyle) DataModelList(edu.cmu.tetrad.data.DataModelList) ScoreModels(edu.cmu.tetradapp.ui.model.ScoreModels) DefaultListModel(javax.swing.DefaultListModel) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) HpcAccount(edu.pitt.dbmi.tetrad.db.entity.HpcAccount) JTextArea(javax.swing.JTextArea) Knowledge2(edu.cmu.tetrad.data.Knowledge2) IndependenceTestModel(edu.cmu.tetradapp.ui.model.IndependenceTestModel) DataType(edu.cmu.tetrad.data.DataType) AlgorithmModel(edu.cmu.tetradapp.ui.model.AlgorithmModel) Linear(edu.cmu.tetrad.annotation.Linear)

Example 7 with DataType

use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.

the class IndependenceTestModels method initModelMap.

private void initModelMap() {
    // initialize enum map
    DataType[] dataTypes = DataType.values();
    for (DataType dataType : dataTypes) {
        modelMap.put(dataType, new LinkedList<>());
    }
    // group by datatype
    models.stream().forEach(e -> {
        DataType[] types = e.getIndependenceTest().getAnnotation().dataType();
        for (DataType dataType : types) {
            modelMap.get(dataType).add(e);
        }
    });
    // merge continuous datatype with mixed datatype
    List<IndependenceTestModel> mergedModels = Stream.concat(modelMap.get(DataType.Continuous).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
    modelMap.put(DataType.Continuous, mergedModels);
    // merge discrete datatype with mixed datatype
    mergedModels = Stream.concat(modelMap.get(DataType.Discrete).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
    modelMap.put(DataType.Discrete, mergedModels);
    // make map values unmodifiable
    modelMap.forEach((k, v) -> modelMap.put(k, Collections.unmodifiableList(v)));
}
Also used : DataType(edu.cmu.tetrad.data.DataType)

Example 8 with DataType

use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.

the class ScoreModels method initDefaultModelMap.

private void initDefaultModelMap() {
    DataType[] dataTypes = DataType.values();
    for (DataType dataType : dataTypes) {
        List<ScoreModel> list = getModels(dataType);
        if (!list.isEmpty()) {
            String property = getProperty(dataType);
            if (property == null) {
                defaultModelMap.put(dataType, list.get(0));
            } else {
                String value = TetradProperties.getInstance().getValue(property);
                if (value == null) {
                    defaultModelMap.put(dataType, list.get(0));
                } else {
                    Optional<ScoreModel> result = list.stream().filter(e -> e.getScore().getClazz().getName().equals(value)).findFirst();
                    defaultModelMap.put(dataType, result.isPresent() ? result.get() : list.get(0));
                }
            }
        }
    }
}
Also used : List(java.util.List) DataType(edu.cmu.tetrad.data.DataType) Stream(java.util.stream.Stream) EnumMap(java.util.EnumMap) Map(java.util.Map) TetradProperties(edu.cmu.tetrad.util.TetradProperties) Optional(java.util.Optional) ScoreAnnotations(edu.cmu.tetrad.annotation.ScoreAnnotations) LinkedList(java.util.LinkedList) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) DataType(edu.cmu.tetrad.data.DataType)

Example 9 with DataType

use of edu.cmu.tetrad.data.DataType in project tetrad by cmu-phil.

the class ScoreModels method initModelMap.

private void initModelMap() {
    // initialize enum map
    DataType[] dataTypes = DataType.values();
    for (DataType dataType : dataTypes) {
        modelMap.put(dataType, new LinkedList<>());
    }
    // group by datatype
    models.stream().forEach(e -> {
        DataType[] types = e.getScore().getAnnotation().dataType();
        for (DataType dataType : types) {
            modelMap.get(dataType).add(e);
        }
    });
    // merge continuous datatype with mixed datatype
    List<ScoreModel> mergedModels = Stream.concat(modelMap.get(DataType.Continuous).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
    modelMap.put(DataType.Continuous, mergedModels);
    // merge discrete datatype with mixed datatype
    mergedModels = Stream.concat(modelMap.get(DataType.Discrete).stream(), modelMap.get(DataType.Mixed).stream()).sorted().collect(Collectors.toList());
    modelMap.put(DataType.Discrete, mergedModels);
    // make map values unmodifiable
    modelMap.forEach((k, v) -> modelMap.put(k, Collections.unmodifiableList(v)));
}
Also used : DataType(edu.cmu.tetrad.data.DataType)

Aggregations

DataType (edu.cmu.tetrad.data.DataType)9 List (java.util.List)5 Map (java.util.Map)5 Algorithm (edu.cmu.tetrad.algcomparison.algorithm.Algorithm)4 EnumMap (java.util.EnumMap)4 LinkedList (java.util.LinkedList)4 Optional (java.util.Optional)4 BdeuScore (edu.cmu.tetrad.algcomparison.score.BdeuScore)3 HasKnowledge (edu.cmu.tetrad.algcomparison.utils.HasKnowledge)3 DataModel (edu.cmu.tetrad.data.DataModel)3 DataModelList (edu.cmu.tetrad.data.DataModelList)3 DataSet (edu.cmu.tetrad.data.DataSet)3 ICovarianceMatrix (edu.cmu.tetrad.data.ICovarianceMatrix)3 Knowledge2 (edu.cmu.tetrad.data.Knowledge2)3 Graph (edu.cmu.tetrad.graph.Graph)3 Node (edu.cmu.tetrad.graph.Node)3 Parameters (edu.cmu.tetrad.util.Parameters)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 AlgorithmFactory (edu.cmu.tetrad.algcomparison.algorithm.AlgorithmFactory)2