-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDBN.py
More file actions
72 lines (57 loc) · 1.99 KB
/
Copy pathDBN.py
File metadata and controls
72 lines (57 loc) · 1.99 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!usr/bin/env python
#coding:utf-8
'''
Author: Haidong Zhang
E-mail: [email protected]
Date: 2016.1.31
'''
from graphviz import Graph, Digraph
from network import Network
class DBN(Network):
def __init__(self, numList, direction = 'TB'):
'''
numList: the number of hidden units;
direction: the direction
LR: from left to right;
RL: from right to left;
TB: from top to bottom;
BT: from bottom to top;
'''
self.numList = numList
self.direction = direction
def plot(self):
g = Digraph(format='png')
# g.graph_attr['rankdir'] = self.direction
# g.graph_attr['splines'] = 'line'
vLayer = Digraph('cluster_0')
self.add_nodes(vLayer, ['v1', 'v2',])
vLayer.body.append('label="Visible Units"')
h1Layer = Digraph('cluster_1')
self.add_nodes(h1Layer, ['h11', 'h12', ])
h1Layer.body.append('label="Visible Units"')
h2Layer = Digraph('cluster_2')
self.add_nodes(h2Layer, ['h21', 'h22',])
h2Layer.body.append('label="Visible Units"')
h3Layer = Digraph('cluster_3')
self.add_nodes(h3Layer, ['h31', 'h32',])
h3Layer.body.append('label="Visible Units"')
g.subgraph(vLayer)
g.subgraph(h1Layer)
g.subgraph(h2Layer)
g.subgraph(h3Layer)
self.add_edges(g, [('h11', 'v1'), ('h11', 'v2'), ('h12', 'v1'), ('h12', 'v2'),
('h21', 'h11'), ('h21', 'h12'), ('h22', 'h11'), ('h22', 'h12'),
])
styles = {
'edge':{
'dir': 'none'
}
}
# self.add_styles(g, styles)
self.add_edges(g, [(('h31', 'h21'), {'dir': 'none'}), (('h31', 'h22'), {'dir': 'none'}),
(('h32', 'h21'), {'dir': 'none'}), (('h32', 'h22'), {'dir': 'none'}),])
print(g.source)
g.view()
if __name__ == '__main__':
dbn = DBN(3, 4)
dbn.plot()