-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeafLevelCreator.py
36 lines (30 loc) · 1.13 KB
/
LeafLevelCreator.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
# System import
import math
# user import
import Partition
import PartitionNode
import Const
# Implements the formulas of section 3
class LeafLevelCreator:
def __init__(self, size, max_leaves):
# Store parameters
self.size = size
self.max_leaves = max_leaves
# Create all leaves for the tree
def create_leaves_and_nodes(self):
# Compute desired fill factors
features_per_partition = int(Const.PARTITION_SIZE * Const.UTILIZATION)
partitions_per_node = int(self.max_leaves * Const.UTILIZATION)
# Compute number of partitions and nodes
partitions = int(math.ceil(self.size / features_per_partition))
# Create all the partitions and partition nodes
nodes = []
leaves = []
for i in range(0, partitions):
if i % partitions_per_node == 0:
node = PartitionNode.PartitionNode()
nodes.append(node)
leaf = Partition.Partition(i, features_per_partition, 1.0, node)
node.add_partition(leaf)
leaves.append(leaf)
return leaves, nodes