-
Notifications
You must be signed in to change notification settings - Fork 0
/
BinClassifier.py
60 lines (44 loc) · 1.54 KB
/
BinClassifier.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
58
59
60
import random as rand
import math
import time
import numpy as np
def bin_classifier(Array2d: list[list[float]]) -> list[tuple[float]]:
start_time = time.time()
# create vars
Rmax = 28.3
Rmin = min([point[0] for point in Array2d])
B = 3
Bins_min = [[-1, -1] for _ in range(3)]
minZ = min(Array2d, key=lambda point: point[2])
# split Array2d into bins
for p in Array2d:
r_val = math.sqrt((p[0] ** 2 + p[1] ** 2))
bin_num = math.floor(B * (r_val / (Rmax + 0.00001)))
if Bins_min[bin_num][0] > 0:
if Bins_min[bin_num][1] > p[2]:
Bins_min[bin_num][0] = r_val
Bins_min[bin_num][1] = p[2]
else:
Bins_min[bin_num][0] = r_val
Bins_min[bin_num][1] = p[2]
end_time = time.time()
elapsed_time = end_time - start_time # Calculate the time difference
ret: list[tuple[float]] = [(bin[0], bin[1]) for bin in Bins_min]
return ret
def bin_point_classifier(points: list[list[float]], num_bins: int):
ranges = np.sqrt(points[:, 0] ** 2 + points[:, 1] ** 2)
pts = []
for i in range(len(ranges)):
pts.append((ranges[i], points[i][2]))
# print("ranges")
# print(ranges)
# Calculate range for each point
# print(segments)
# import pdb; pdb.set_trace()
rmax = np.max(ranges)
rmin = np.min(ranges)
bin_size = (rmax - rmin) / num_bins
rbins = np.arange(rmin, rmax, bin_size)
regments = np.digitize(ranges, rbins) - 1
np.append(rbins, rmax)
return (rbins, pts, regments)