forked from wbaek/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
linear.py
31 lines (26 loc) · 786 Bytes
/
linear.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
import numpy as np
class Linear(object):
def __init__(self):
pass
@staticmethod
def function(x):
return x
@staticmethod
def derivative(x):
return np.ones(x.shape)
def __test(self):
'''
>>> x = np.array( [[-1, 3, -1, 1, 2], [1, -1, 0.5, -1, -2]] )
>>> f = Linear.function
>>> y = f( x )
>>> [['%.1f'%_ for _ in v] for v in y]
[['-1.0', '3.0', '-1.0', '1.0', '2.0'], ['1.0', '-1.0', '0.5', '-1.0', '-2.0']]
>>> d = Linear.derivative
>>> y = d( x )
>>> [['%.1f'%_ for _ in v] for v in y]
[['1.0', '1.0', '1.0', '1.0', '1.0'], ['1.0', '1.0', '1.0', '1.0', '1.0']]
'''
pass
if __name__ == "__main__":
import doctest
doctest.testmod()