import numpy as np
from scipy.io.wavfile import read
from scipy.signal import find_peaks
from numpy.fft import fft, ifft
from numpy.linalg import pinv

# 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]

w1 = 0.1 * np.random.randn(784,80)
w2 = 0.1 * np.random.randn(10,80)
w3 = 0.1 * np.random.randn(784,60)
w4 = 0.1 * np.random.randn(10,60)


i=0
while True:
    idx = np.random.randint(0,60000,100)
    X = X_train[idx]
    yt = y_train[idx]
    M = w1 @ pinv(w2) + w3 @ pinv(w4)
    y = X @ M
    err = np.eye(10)[yt] - y
    
    break
