<commit_before>#exact inference

The following code snippet shows how to create nodes, define parents of nodes, create the conditional probability tables (CPTs), create a graph (a graph in this case equates to a Bayesian Belief Network), and perform exact inference on the graph.

To create a BBN, you can create a directed acylic graph (DAG) with the associated conditional probabilities as follows. You should also define the edges. This fluent style of creating a BBN should make it easy to create one. Of course, you may create the nodes first then insert them into the DAG and then define the directed edges. Please note that this BBN is taken from <NAME> and <NAME>, "Inference in Belief Networks: A Procedural Guide," in International Journal of Approximate Reasoning, vol. 15, pp. 225--263, 1999.    

```
Dag dag = new Dag()
    .addNode(Node.builder()
        .id("a")
        .name("a")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.5d, 0.5d))
        .build())
    .addNode(Node.builder()
        .id("b")
        .name("b")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.5d, 0.5d, 0.4d, 0.6d))
        .build())
    .addNode(Node.builder()
        .id("c")
        .name("c")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.7d, 0.3d, 0.2d, 0.8d))
        .build())
    .addNode(Node.builder()
        .id("d")
        .name("d")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.9d, 0.1d, 0.5d, 0.5d))
        .build())
    .addNode(Node.builder()
        .id("e")
        .name("e")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.3d, 0.7d, 0.6d, 0.4d))
        .build())
    .addNode(Node.builder()
        .id("f")
        .name("f")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.01d, 0.99d, 0.01d, 0.99d, 0.01d, 0.99d, 0.99d, 0.01d))
        .build())
    .addNode(Node.builder()
        .id("g")
        .name("g")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.8d, 0.2d, 0.1d, 0.9d))
        .build())
     .addNode(Node.builder()
        .id("h")
        .name("h")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.05d, 0.95d, 0.95d, 0.05d, 0.95d, 0.05d, 0.95d, 0.05d))
        .build())
    .addEdge("a", "b")
    .addEdge("a", "c")
    .addEdge("b", "d")
    .addEdge("c", "e")
    .addEdge("d", "f")
    .addEdge("e", "f")
    .addEdge("c", "g")
    .addEdge("e", "h")
    .addEdge("g", "h");

//assigns the conditional probabilities into potentials
dag.initializePotentials();

//creates a join tree from the BBN
JoinTree joinTree = InferenceControl.apply(getDag());

//print out the probabilities for each node
joinTree.nodes().forEach(node -> {
    Potential potential = joinTree.getPotential(node);
    System.out.println(node);
    System.out.println(potential);
    System.out.println("---------------");
});
    
//insert observation
joinTree.updateEvidence(Evidence.newBuilder()
    .node(joinTree.node("a"))
    .value("on", 1.0)
    .type(Evidence.Type.Observation)
    .build());

//insert multiple observations
joinTree.updateEvidence(Arrays.asList(
    Evidence.newBuilder().node(joinTree.node("a")).value("on", 1.0d).build(),
    Evidence.newBuilder().node(joinTree.node("f")).value("on", 1.0d).build()
));<commit_msg>fix example<commit_after>#exact inference

The following code snippet shows how to create nodes, define parents of nodes, create the conditional probability tables (CPTs), create a graph (a graph in this case equates to a Bayesian Belief Network), and perform exact inference on the graph.

To create a BBN, you can create a directed acylic graph (DAG) with the associated conditional probabilities as follows. You should also define the edges. This fluent style of creating a BBN should make it easy to create one. Of course, you may create the nodes first then insert them into the DAG and then define the directed edges. Please note that this BBN is taken from <NAME> and <NAME>, "Inference in Belief Networks: A Procedural Guide," in International Journal of Approximate Reasoning, vol. 15, pp. 225--263, 1999.    

```
Dag dag = new Dag()
    .addNode(Node.builder()
        .id("a")
        .name("a")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.5d, 0.5d))
        .build())
    .addNode(Node.builder()
        .id("b")
        .name("b")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.5d, 0.5d, 0.4d, 0.6d))
        .build())
    .addNode(Node.builder()
        .id("c")
        .name("c")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.7d, 0.3d, 0.2d, 0.8d))
        .build())
    .addNode(Node.builder()
        .id("d")
        .name("d")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.9d, 0.1d, 0.5d, 0.5d))
        .build())
    .addNode(Node.builder()
        .id("e")
        .name("e")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.3d, 0.7d, 0.6d, 0.4d))
        .build())
    .addNode(Node.builder()
        .id("f")
        .name("f")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.01d, 0.99d, 0.01d, 0.99d, 0.01d, 0.99d, 0.99d, 0.01d))
        .build())
    .addNode(Node.builder()
        .id("g")
        .name("g")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.8d, 0.2d, 0.1d, 0.9d))
        .build())
     .addNode(Node.builder()
        .id("h")
        .name("h")
        .value("on")
        .value("off")
        .probs(Arrays.asList(0.05d, 0.95d, 0.95d, 0.05d, 0.95d, 0.05d, 0.95d, 0.05d))
        .build())
    .addEdge("a", "b")
    .addEdge("a", "c")
    .addEdge("b", "d")
    .addEdge("c", "e")
    .addEdge("d", "f")
    .addEdge("e", "f")
    .addEdge("c", "g")
    .addEdge("e", "h")
    .addEdge("g", "h");

//assigns the conditional probabilities into potentials
dag.initializePotentials();

//creates a join tree from the BBN
JoinTree joinTree = InferenceControl.apply(dag);

//print out the probabilities for each node
joinTree.nodes().forEach(node -> {
    Potential potential = joinTree.getPotential(node);
    System.out.println(node);
    System.out.println(potential);
    System.out.println("---------------");
});
    
//insert observation
joinTree.updateEvidence(Evidence.newBuilder()
    .node(joinTree.node("a"))
    .value("on", 1.0)
    .type(Evidence.Type.Observation)
    .build());

//insert multiple observations
joinTree.updateEvidence(Arrays.asList(
    Evidence.newBuilder().node(joinTree.node("a")).value("on", 1.0d).build(),
    Evidence.newBuilder().node(joinTree.node("f")).value("on", 1.0d).build()
));
{'fraction_non_alphanumeric': 0.18230483271375464, 'fraction_numerical': 0.03271375464684015, 'mean_word_length': 2.3901209677419355, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3172067', 'n_tokens_mistral': 2510, 'n_tokens_neox': 2353, 'n_words': 571}