-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.py
More file actions
44 lines (30 loc) · 1.17 KB
/
kernel.py
File metadata and controls
44 lines (30 loc) · 1.17 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
import numpy as np
# from errors import WrongConstant
class Kernel:
"""Initialisation of the Kernel class
Attributes:
set_x -- the X input that will be kernalised
set_y -- the Y input that represents the classes
"""
def __init__(self, set_x, set_y):
self.set_x = set_x
self.set_y = set_y
"""Returns the kernalised x and y vectors """
def kernalised(self):
self.kernalised_x = self.kernalise(self.set_x)
return self.kernalised_x
def kernalise(self, set_x):
n_rows, n_cols = set_x.shape
kernalised_x = [None]*n_rows
for row_idx in range(n_rows):
kernalised_x[row_idx] = [1]
for col_idx in range(n_cols):
if len(kernalised_x[row_idx]) == 1:
start = 0
else:
start = 1
for i in range(start, len(kernalised_x[row_idx])):
current_multiplication = kernalised_x[row_idx][i]
current_multiplication *= set_x[row_idx][col_idx]
kernalised_x[row_idx].append(current_multiplication)
return kernalised_x