I've written a function that generates a sum of N-many RelU functions, with random slopes and activation points.
I was expecting these resulting functions to be arbitrary, random curves, but for some reason they all look like a quadratic. Why is that?
Here's my code and an example plot
# Write a function that returns N-Many RelUs
def n_relu(*args, x):
return sum(F.relu(a*(x+b) + c) for a, b, c in args)
Intantiate a n_relu function with N random parameter pairs
def instantiate_n_relu(N):
# Generate N random parameter pairs
random_parameters = [(random.uniform(-100, 100), random.uniform(-100, 100), random.uniform(-100, 100)) for _ in range(N)]
# Create and return the n_relu function with the random parameters
return lambda x: n_relu(*random_parameters, x=x)
Example usage:
N = 100 # Set the desired number of ReLUs
Instantiate n_relu function with N random parameter pairs
random_n_relu = instantiate_n_relu(N)
def plot_n_relu(f):
x_values = torch.linspace(-100, 100, 100)
y_values = f(x_values)
plt.figure(figsize=(8, 6))
plt.scatter(x_values, y_values, label='N ReLUs')
plt.title('n_relu Function with N Random Parameter Pairs')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plot_n_relu(random_n_relu)
