import numpy as np, matplotlib.pyplot as plt
rng = np.random.default_rng(0)
x = np.linspace(-3, 3, 200); target = np.sin(1.5*x) + 0.3*x
M = 40 # hidden ReLU units with random weights
W = rng.normal(0, 1.5, M); b = rng.normal(0, 3, M)
H = np.maximum(0, np.outer(x, W) + b) # hidden features z = ReLU(Wx+b)
v = np.linalg.lstsq(H, target, rcond=None)[0] # learn only the output weights
plt.figure(figsize=(6, 2.4))
plt.plot(x, target, "g", lw=3, label="target")
plt.plot(x, H @ v, "r--", lw=2, label="net: 40 ReLU units")
plt.legend(fontsize=8); plt.tight_layout(); plt.show()