import numpy as np
from sklearn.linear_model import LinearRegression
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]

f = LinearRegression(fit_intercept=False)

def score(x,yt,c):
    f.coef_ = c
    return np.mean(f.predict(x).argmax(1)==yt)


C = []
i = 0
while True:
    idx = np.random.randint(0,60000,100)
    X = X_train[idx]
    yt = y_train[idx]
    f.fit(X,np.eye(10)[yt])
    C.append(f.coef_)
    if i==100:break    
    i+=1

c = np.stack(C)
#degree of variabe (np.var())
v = np.var(c,0)
print(score(X,yt,c.mean(0)))

# high deg of variance should form a constant weight matrix
map_ = np.sqrt(v[yt])

v01 = np.var([X_train[y_train==0][:100],X_train[y_train==1][:100]],0).mean(0)



