#!/usr/bin/env python3
"""Auto-generated by AGI Loop cycle #1197
Task: ,

Write a Python function that simulates a basic neural network with one hidden layer, using only numpy, to approximate a given 2D curve defined by a list of (x, y) points.
Generated: 2026-02-12T23:49:06.421275
"""

import numpy as np

def neural_network_approximator(points, epochs=1000, learning_rate=0.01):
    # Unpack points into x and y
    x = np.array([point[0] for point in points], dtype=np.float32).reshape(-1, 1)
    y = np.array([point[1] for point in points], dtype=np.float32).reshape(-1, 1)

    # Network parameters
    input_size = 1
    hidden_size = 4
    output_size = 1

    # Initialize weights
    np.random.seed(42)
    W1 = np.random.randn(input_size, hidden_size)
    W2 = np.random.randn(hidden_size, output_size)

    for epoch in range(epochs):
        # Forward pass
        Z1 = np.dot(x, W1)
        A1 = np.tanh(Z1)
        Z2 = np.dot(A1, W2)
        A2 = Z2

        # Compute loss
        loss = np.mean(0.5 * (y - A2)**2)
        if epoch % 100 == 0:
            print(f"Epoch {epoch}, Loss: {loss:.4f}")

        # Backward pass
        dZ2 = A2 - y
        dW2 = np.dot(A1.T, dZ2) * learning_rate
        dA1 = np.dot(dZ2, W2.T)
        dZ1 = dA1 * (1 - np.tanh(Z1)**2)
        dW1 = np.dot(x.T, dZ1) * learning_rate

        # Update weights
        W1 -= dW1
        W2 -= dW2

    # Final prediction
    Z1 = np.dot(x, W1)
    A1 = np.tanh(Z1)
    final_pred = np.dot(A1, W2)
    return final_pred

if __name__ == '__main__':
    # Example curve: y = x^2, sampled at x in [-1, 1]
    points = [(x, x**2) for x in np.linspace(-1, 1, 10)]
    approximated_y = neural_network_approximator(points)
    print("Approximated y values:")
    print(approximated_y)