-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.py
49 lines (41 loc) · 1.26 KB
/
node.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
class Node:
def __init__(self, depth, D, K,
parent, left, right,):
self.depth = depth
self.D = D
self.K = K
self.parent = parent
self.left = left
self.right = right
def set_children(self, left, right):
self.left = left
self.right = right
def set_parent(self, node):
self.parent = node
class StandardNode(Node):
def __init__(self, depth, D, K,
parent, left, right,
w, b,):
super().__init__(depth, D, K, parent, left, right)
self.w = w
self.b = b
@property
def is_leaf(self):
return False
def copy(self):
return StandardNode(self.depth, self.D, self.K,
self.parent, self.left, self.right,
self.w, self.b)
class LeafNode(Node):
def __init__(self, depth, D, K,
parent,
label,):
super().__init__(depth=depth, D=D, K=K, parent=parent, left=None, right=None)
self.label = label
@property
def is_leaf(self):
return True
def copy(self):
return LeafNode(self.depth, self.D, self.K,
self.parent,
self.label)