-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkcc.py
More file actions
26 lines (20 loc) · 743 Bytes
/
kcc.py
File metadata and controls
26 lines (20 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import numpy as np
import matplotlib.pyplot as plt
class Function(object):
def forward(self, *args):
return self._forward(*args)
class PiecewiseLinear2D(Function):
def __init__(self, 2d_points):
assert isinstance(2d_points, np.ndarray), \
"invalid type of 2d_points: {}".format(type(2d_points))
shp = 2d_points.shape
assert len(shp) == 2 and shp[1] == 2, \
"invalid shape of 2d_points: {}".format(shp)
for i in range(shp[0]-1):
assert 2d_points[i][0] < 2d_points[i+1][0], \
"unsorted data: {}".format(2d_points)
# if __name__ == "__main__":
# plt.figure()
# plt.plot(x, y, 'o')
# plt.plot(x_hat, y_hat, '-')
# plt.show()