package com.bayesserver.examples;
import com.bayesserver.Network;
import com.bayesserver.Node;
import com.bayesserver.Variable;
import com.bayesserver.data.*;
import com.bayesserver.learning.structure.*;
import java.util.ArrayList;
import java.util.List;
public class StructuralLearningNonTemporal {
public static void main(String[] args) {
Network network = CreateNetworkNoLinks();
PCStructuralLearning learning = new PCStructuralLearning();
DataReaderCommand dataReaderCommand = CreateDataReaderCommand();
List<VariableReference> variableReferences = new ArrayList<VariableReference>();
for (Variable v : network.getVariables()) {
variableReferences.add(new VariableReference(v, ColumnValueType.NAME, v.getName()));
}
EvidenceReaderCommand evidenceReaderCommand = new DefaultEvidenceReaderCommand(
dataReaderCommand,
variableReferences,
new ReaderOptions());
PCStructuralLearningOptions options = new PCStructuralLearningOptions();
PCStructuralLearningOutput output = (PCStructuralLearningOutput) learning.learn(evidenceReaderCommand, network.getNodes(), options);
for (LinkOutput linkOutput : output.getLinkOutputs()) {
System.out.println(
String.format("Link added from %s -> %s",
linkOutput.getLink().getFrom().getName(),
linkOutput.getLink().getTo().getName()));
}
}
private static Network CreateNetworkNoLinks() {
Network network = new Network();
for (String name : new String[]{"A", "B", "C"}) {
Node node = new Node(name, new String[]{"False", "True"});
network.getNodes().add(node);
}
return network;
}
private static DataTableDataReaderCommand CreateDataReaderCommand() {
DataTable data = new DataTable();
DataColumnCollection columns = data.getColumns();
columns.add("A", String.class);
columns.add("B", String.class);
columns.add("C", String.class);
DataRowCollection rows = data.getRows();
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("False", "True", "True");
rows.add("False", "False", "False");
rows.add("False", "True", "True");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("False", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("False", "True", "True");
rows.add("True", "True", "True");
rows.add("False", "True", "True");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("False", "False", "False");
rows.add("False", "False", "False");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("False", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
rows.add("False", "True", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("False", "False", "False");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("False", "False", "False");
rows.add("False", "True", "True");
rows.add("True", "False", "True");
rows.add("True", "False", "True");
rows.add("True", "True", "True");
rows.add("True", "True", "True");
rows.add("False", "True", "True");
rows.add("True", "True", "True");
rows.add("True", "False", "True");
return new DataTableDataReaderCommand(data);
}
}