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);
}
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();
}
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;
}
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();
}
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);
}
Aggregations