本项目利用Python编程语言及matplotlib等库,旨在可视化多种深度学习中的激活函数曲线,帮助理解与选择合适的激活函数。
以下是修正后的函数定义:
```python
import math, numpy as np
def sigmoid(x):
result = 1 / (1 + math.exp(-x))
return result
def tanh(x):
numerator = math.exp(x) - math.exp(-x)
denominator = math.exp(x) + math.exp(-x)
result = numerator/denominator
return result
def relu(x):
result = np.maximum(0, x)
return result
def elu(x, alpha=1):
a = x[x > 0]
b = alpha * (math.exp(x[x < 0]) - 1)
result = np.concatenate((b,a), axis=0)
return result
def leaky_relu(x):
positive_part = x[x > 0]
negative_part = 0.1 * x[x <= 0]
# Concatenate the results along an appropriate dimension
result = np.zeros_like(x)
result[x > 0] = positive_part
result[x < 0] = negative_part
return result
```
注意:`leaky_relu`函数未完全给出,根据上下文添加了合理的实现方式。