-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivations.py
47 lines (30 loc) · 1.03 KB
/
Activations.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
45
46
47
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 24 16:32:44 2022
@author: ASUS
"""
import numpy as np
from Activation import Activation
from Layer import Layer
class Tanh(Activation):
def __init__(self):
def tanh(x):
return np.tanh(x)
def tanh_prime(x):
return 1 - np.tanh(x) ** 2
super().__init__(tanh, tanh_prime)
class Sigmoid(Activation):
def __init__(self):
def sigmoid(x):
return ( 1 / (1 + np.exp(-x)) )
def sigmoid_prime(x):
s = sigmoid(x)
return s * (1-s)
class Softmax(Layer):
def forward(self, input) :
input_expo = np.exp(input)
self.output = input_expo / np.sum(input_expo)
return self.output
def backward(self, output_gradient, learning_rate):
n = np.size(self.output)
return np.dot((np.identity(n) - self.output.T) * self.output, output_gradient)