from numpy import *
import numpy as np
import matplotlib.pyplot as plt
from mlp import mlp

x = ones((1, 40)) * linspace(0, 1, 40)
t = sin(2 * pi * x) + cos(2 * pi * x) + np.random.randn(40) * 0.2
x = transpose(x)
t = transpose(t)

n_hidden = 3
eta = 0.25
n_iterations = 101

plt.plot(x, t, '.')
plt.show()

train = x[0::2, :]
test = x[1::4, :]
valid = x[3::4, :]

train_targets = t[0::2, :]
test_targets = t[1::4, :]
valid_targets = t[3::4, :]

net = mlp(train, train_targets, n_hidden, out_type='linear')
net.mlptrain(train, train_targets, eta, n_iterations)

best_err = net.earlystopping(train, train_targets, valid, valid_targets, eta)

[(15, 'matplotlib.pyplot.plot', 'plt.plot', True, 'import matplotlib.pyplot as plt\n'), (16, 'matplotlib.pyplot.show', 'plt.show', True, 'import matplotlib.pyplot as plt\n'), (26, 'mlp.mlp', 'mlp', False, 'from mlp import mlp\n'), (7, 'numpy.random.randn', 'np.random.randn', True, 'import numpy as np\n')]