-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFunction.py
40 lines (33 loc) · 885 Bytes
/
Function.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
"""
One can defince any sort of mathemathecal function by following
the same patterns as the already defined functions (Sigmoid, Relu, MeanSquare)
"""
import numpy as np
class Sigmoid:
def __init__(self):
pass
def activate(self, x):
self.x = x
return 1/(1 + np.exp(-x))
def differentiate(self):
return self.activate(self.x) * (1 - self.activate(self.x))
class Relu:
def __init(self):
pass
def activate(self, x):
self.x = x
return np.maximum(x, 0)
def differentiate(self):
x = self.x
x[x <= 0] = 0
x[x > 0] = 1
return x
class MeanSquare:
def __init__(self):
pass
def activate(self, y_hat, y):
self.y_hat = y_hat
self.y = y
return ((y - y_hat)**2)/2
def differentiate(self):
return (self.y - self.y_hat) * -1