<jupyter_start><jupyter_text>Bayes nets implemented using Pomegranate<jupyter_code>import matplotlib.pyplot as plt
from pomegranate import DiscreteDistribution, ConditionalProbabilityTable, Node, BayesianNetwork
import seaborn, time
seaborn.set_style('whitegrid')

BURGLARY = DiscreteDistribution({'T': 0.001, 'F': 0.999})
EARTHQUAKE = DiscreteDistribution({'T': 0.002, 'F': 0.998})
ALARM = ConditionalProbabilityTable([['T', 'T', 0.95],
                                  ['T', 'F', 0.94],
                                  ['F', 'T', 0.29],
                                  ['F', 'T', 0.001]], [BURGLARY, EARTHQUAKE])

MARY_CALLS = ConditionalProbabilityTable([['T', 0.70],
                                  ['F', 0.01]], [ALARM])

JOHN_CALLS = ConditionalProbabilityTable([['T', 0.90],
                                  ['F', 0.05]], [ALARM])
node_burglery = Node(BURGLARY, name="Burglary")
node_earthquake = Node(EARTHQUAKE, name="Earthquake")
node_alarm = Node(ALARM, name="Alarm")
node_mary_calls = Node(MARY_CALLS, name="<NAME>")
node_john_calls = Node(JOHN_CALLS, name="<NAME>")
model = BayesianNetwork('Alarming')
model.add_nodes(node_burglery, node_earthquake, node_alarm, node_mary_calls, node_john_calls)
model.add_edge(node_burglery, node_alarm)
model.add_edge(node_earthquake, node_alarm)
model.add_edge(node_alarm, node_mary_calls)
model.add_edge(node_alarm, node_john_calls)
plt.figure(figsize=(14, 10))
model.plot()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14799728445349628, 'fraction_numerical': 0.03054989816700611, 'mean_word_length': 3.97972972972973, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '508550', 'license': 'MIT', 'n_tokens_mistral': 584, 'n_tokens_neox': 527, 'n_words': 90, 'path': 'slides/pomegranate_demo.ipynb', 'repo_name': 'robOcity/ai-course', 'size': '1481'}