-
Notifications
You must be signed in to change notification settings - Fork 1
/
gene_application
48 lines (45 loc) · 1.78 KB
/
gene_application
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
from clique import Clique
import numpy as np
from graph import Graph
from model import Model
from clique import Clique
if __name__ == '__main__':
node_nb = 9
node_list = ['x1', 'x2', 'x3', 'x4', 'x5', 'x6', 'x7', 'x8', 'x9']
edge_u = ['x9', 'x9', 'x8', 'x8', 'x6', 'x6', 'x7', 'x7']
edge_v = ['x5', 'x8', 'x7', 'x6', 'x1', 'x2', 'x3', 'x4']
ns = 4 * np.ones(node_nb)
# evidence = ['G', 'C', 'A', 'T', 'T', None, None, None, None, None]
evidence = [3, 1, 0, 2, 2, None, None, None, None, None]
root_idx = 8
gene_graph = Graph(node_list, ns, edge_u, edge_v, evidence, root_idx)
gene_graph.print_adj_matrix()
#define cliques (b,i)
m1 = 8
m2 = 3
m3 = 2
m4 = 1
M1 = np.array([[m1, m4, m2, m3], [m4, m1, m3, m2], [m2, m3, m1, m4], [m3, m2, m4, m1]])
M2 = np.array([[m1, 3*m4, 4*m2, 3*m3], [3*m4, m1, 3*m3, 4*m2], [4*m2, 3*m3, m1, 3*m4], [3*m3, 4*m2, 3*m4, m1]])
phi_9 = np.array([8, 9, 9, 8])
#leaf nodes 1, 2, 3, 4, 5
phi_one = np.array([1, 1, 1, 1])
# all single nodes and all pairs of nodes connected by edge
clique_nodes = [[0], [1], [2], [3], [4], [5], [6], [7], [8], [4, 8], [8, 7], [6, 7], [7, 5], [0, 5], [1, 5], [2, 6], [3, 6]]
cliques = []
for i in range(0, 8):
cliques.append(Clique(i, clique_nodes[i], np.array([4]), phi_one))
i = i+1
cliques.append(Clique(i, clique_nodes[i], np.array([4]), phi_9))
i = i+1
cliques.append(Clique(i, clique_nodes[i], np.array([4, 4]), M2))
for i in range(i+1, len(clique_nodes)):
cliques.append(Clique(i, clique_nodes[i], np.array([4, 4]), M1))
assert len(cliques)==17
#model
gene_model = Model(gene_graph, cliques, evidence)
gene_model.print_model()
assert gene_model.graph.neighbor(0) == [5]
#""Execute sum_product algorithm""
gene_model.sum_product()
print gene_model.nodeMarginal['x9']