Spaces:
Sleeping
Sleeping
File size: 670 Bytes
8c348c5 14841f9 8c348c5 |
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 |
from typing import Callable
from nn.nn import NN
import numpy as np
def get_activation(nn: NN) -> Callable:
a = nn.activation
funcs = {
"relu": relu,
"sigmoid": sigmoid,
"tanh": tanh,
}
prime_funcs = {
"sigmoid": sigmoid_prime,
"tanh": tanh_prime,
"relu": relu_prime,
}
nn.set_func(funcs[a])
nn.set_func_prime(prime_funcs[a])
def relu(x):
return np.max(0.0, x)
def relu_prime(x):
return
def sigmoid(x):
return 1.0 / (1.0 + np.exp(-x))
def sigmoid_prime(x):
s = sigmoid(x)
return s / (1.0 - s)
def tanh(x):
return np.tanh(x)
def tanh_prime(x):
return
|