-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
57 lines (49 loc) · 1.67 KB
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from pomegranate.distributions import Categorical
from pomegranate.distributions import ConditionalCategorical
from pomegranate.bayesian_network import BayesianNetwork
# Crear distribuciones de probabilidad
# Creamos los nodos de la red
# e indicamos la distribucion de probabilidad de cada uno.
# Rain node no tiene padres
rain_distribution = Categorical([[
0.7,
0.2,
0.1
]])
# Track maintenance node esta condicionado por rain
maintenance_distribution = ConditionalCategorical([[
[0.4, 0.6],
[0.2, 0.8],
[0.1, 0.9]
]], [rain_distribution])
# Train node esta condicionado por rain y maintenance
train_distribution = ConditionalCategorical([[
[
[0.8, 0.2],
[0.9, 0.1],
],
[
[0.6, 0.4],
[0.7, 0.3],
],
[
[0.4, 0.6],
[0.5, 0.5],
]
]], [rain_distribution, maintenance_distribution])
# Appointment node esta condicionado por train
appointment_distribution = ConditionalCategorical([[
[0.9, 0.1],
[0.6, 0.4],
]], [train_distribution])
# Creamos el modelo y añadimos las distribuciones de probabilidad
model = BayesianNetwork()
model.add_distributions([rain_distribution,
maintenance_distribution,
train_distribution,
appointment_distribution])
# Añadimos las aristas entre nodos para indicar dependencia condicional
model.add_edge(rain_distribution, maintenance_distribution)
model.add_edge(rain_distribution, train_distribution)
model.add_edge(maintenance_distribution, train_distribution)
model.add_edge(train_distribution, appointment_distribution)