Search in sources :

Example 21 with DiscreteVariable

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

the class Proposition method getCategoryIndex.

public int getCategoryIndex(String nodeName, String category) {
    int index = getVariableSource().getVariableNames().indexOf(nodeName);
    DiscreteVariable variable = (DiscreteVariable) getVariableSource().getVariables().get(index);
    return variable.getCategories().indexOf(category);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable)

Example 22 with DiscreteVariable

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

the class Proposition method toString.

public String toString() {
    StringBuilder buf = new StringBuilder();
    List<Node> variables = getVariableSource().getVariables();
    buf.append("\n");
    for (int i = 0; i < getNumVariables(); i++) {
        DiscreteVariable variable = (DiscreteVariable) variables.get(i);
        String name = variable.getName();
        buf.append(name);
        for (int j = name.length(); j < 5; j++) {
            buf.append(" ");
        }
        buf.append("\t");
    }
    for (int i = 0; i < getMaxNumCategories(); i++) {
        buf.append("\n");
        for (int j = 0; j < getNumVariables(); j++) {
            if (i < getNumCategories(j)) {
                boolean allowed = isAllowed(j, i);
                buf.append(allowed ? "true" : "*   ").append("\t");
            } else {
                buf.append("    \t");
            }
        }
    }
    return buf.toString();
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable) Node(edu.cmu.tetrad.graph.Node)

Example 23 with DiscreteVariable

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

the class BayesPm method getVariableNames.

public List<String> getVariableNames() {
    List<Node> variables = getVariables();
    List<String> names = new ArrayList<>();
    for (Node variable : variables) {
        DiscreteVariable discreteVariable = (DiscreteVariable) variable;
        names.add(discreteVariable.getName());
    }
    return names;
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable)

Example 24 with DiscreteVariable

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

the class BayesPm method toString.

/**
 * Prints out the list of values for each node.
 */
public String toString() {
    StringBuilder buf = new StringBuilder();
    for (Node node1 : nodesToVariables.keySet()) {
        buf.append("\n");
        buf.append((node1));
        buf.append(": ");
        DiscreteVariable variable = nodesToVariables.get((node1));
        for (int j = 0; j < variable.getNumCategories(); j++) {
            buf.append(variable.getCategory(j));
            if (j < variable.getNumCategories() - 1) {
                buf.append(", ");
            }
        }
    }
    return buf.toString();
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable)

Example 25 with DiscreteVariable

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

the class BayesPm method mapNodeToVariable.

private void mapNodeToVariable(Node node, List<String> categories) {
    if (categories.size() != new HashSet<>(categories).size()) {
        throw new IllegalArgumentException("Duplicate variable names.");
    }
    DiscreteVariable variable = new DiscreteVariable(node.getName(), categories);
    variable.setNodeType(node.getNodeType());
    this.nodesToVariables.put(node, variable);
}
Also used : DiscreteVariable(edu.cmu.tetrad.data.DiscreteVariable)

Aggregations

DiscreteVariable (edu.cmu.tetrad.data.DiscreteVariable)56 Node (edu.cmu.tetrad.graph.Node)37 DataSet (edu.cmu.tetrad.data.DataSet)18 ContinuousVariable (edu.cmu.tetrad.data.ContinuousVariable)16 ColtDataSet (edu.cmu.tetrad.data.ColtDataSet)11 LinkedList (java.util.LinkedList)9 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 Dag (edu.cmu.tetrad.graph.Dag)3 NumberFormat (java.text.NumberFormat)3 Element (nu.xom.Element)3 EdgeListGraph (edu.cmu.tetrad.graph.EdgeListGraph)2 Graph (edu.cmu.tetrad.graph.Graph)2 LogisticRegression (edu.cmu.tetrad.regression.LogisticRegression)2 List (java.util.List)2 Elements (nu.xom.Elements)2 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)1 TakesInitialGraph (edu.cmu.tetrad.algcomparison.utils.TakesInitialGraph)1 StoredCellProbs (edu.cmu.tetrad.bayes.StoredCellProbs)1 BoxDataSet (edu.cmu.tetrad.data.BoxDataSet)1