-
Notifications
You must be signed in to change notification settings - Fork 2
/
PC.py
44 lines (34 loc) · 1.62 KB
/
PC.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
import numpy as np
import DATASET
def compute_positions(data, df_name, section_array):
# Use a copy of the dataframe to avoid changing the original data
df_copy = df_name.copy()
for index, is_inverted in enumerate(data.attribute_inversions):
if is_inverted:
df_copy.iloc[:, index] = 1 - df_copy.iloc[:, index]
x_coord = np.tile(section_array, reps=len(df_copy.index))
y_coord = df_copy.to_numpy().ravel()
pos_array = np.column_stack((x_coord, y_coord))
return pos_array
def compute_axis_positions(data, section_array):
axis_vertex_array = [[0, 0], [0, 1]]
for idx in range(1, data.vertex_count):
axis_vertex_array.append([section_array[idx], 1])
axis_vertex_array.append([section_array[idx], 0])
return axis_vertex_array
class PC:
def __init__(self, data: DATASET.Dataset):
# Normalization using the DATASET class function
data.dataframe = data.normalize_data(our_range=(0, 1))
# Create section_array based on vertex_count
section_array = np.linspace(start=0, stop=1, num=data.vertex_count)
# Compute positions for each class and store in data.positions
data.positions = []
for class_name in data.class_names:
df_name = data.dataframe[data.dataframe['class'] == class_name]
df_name = df_name.drop(columns='class', axis=1)
pos_array = compute_positions(data, df_name, section_array)
data.positions.append(pos_array)
# Compute axis positions
data.axis_positions = compute_axis_positions(data, section_array)
data.axis_count = data.vertex_count