from matplotlib import pyplot as plt import math import numpy as np from icecream import ic def activation_func(x: float) -> float: y = math.log1p(math.exp(-abs(x))) + max(x, 0) ic(x) ic(y) return y w1 = -34.4 w2 = -2.52 w3 = -1.30 w4 = 2.28 b1 = 2.14 b2 = 1.29 b3 = -0.58 def my_neurale_net(x: float) -> float: h1 = x * w1 + b1 h2 = x * w2 + b2 h12 = activation_func(h1) h22 = activation_func(h2) ic(h12) ic(h22) y = h12 * w3 + h22 * w4 + b3 return y def f1(x): return np.sin(x) def f2(x): return 4*x*x + 2*x + 4 def demo(): # vfunc = np.vectorize(my_neurale_net) # vfunc = np.vectorize(f2) vfunc = np.vectorize(activation_func) x = np.linspace(-5, 5, 1000) y = vfunc(x) plt.plot(x, y, color='red') plt.show() def debug(): ic(my_neurale_net(0)) ic(my_neurale_net(0.5)) ic(my_neurale_net(1)) if __name__ == '__main__': debug() demo()