import numpy as np
from scipy.io.wavfile import read

# Load training and test data
X_train = read('../X_train.wav')[1].reshape(-1, 784)
y_train = (read('../y_train.wav')[1] * 9).astype(int)
X_test = read('../X_test.wav')[1].reshape(-1, 784)
y_test = (read('../y_test.wav')[1] * 9).astype(int)
X20 = X_test[:1000]
yt20 = y_test[:1000]

#yt = np.random.normal(0,1,100)
#w = np.random.rand(100,100)
#x = np.linspace(0,1,100)

"""while True:
    c = np.polyfit(x @ w,yt,deg=2)
    err = yt - np.polyval(c,x@w)
    w -= err
    print(np.sum(err**2))"""


X = X_train[:100]
y = np.random.randn(100,784)
for _ in range(2):
    c = [np.polyfit(X[i],y[i],deg=2) for i in range(100)]
    err = np.stack([np.polyval(c[i],X[i]) - y[i] for i in range(100)])
    y += err
    print(np.sum(err**2))


