# Path: LinearClassification/Logistic.py
# def augment(data):
# def cp(x, beta):
# def W(X, beta):
# def Z(X, Y, W, beta):
# def logistic(X, Y):
# def predict(x, beta):
# def zscore(X, Y, beta):
#     P = np.zeros(len(X))
#     XT = np.transpose(X)
#     M = np.transpose(X).dot(w).dot(X)
#     M = np.linalg.inv(M)
#     X = augment(inputs)[:,np.array([0,2,3,4,7])]


import numpy as np
import matplotlib.pyplot as plt
from LinearClassification import Logistic as lg
def transform(H, train_in, M):
    ln = len(train_in)
    HT = np.transpose(H)
    XS = np.zeros((ln, M))
    for i in range(ln):
        XS[i] = HT.dot(train_in[i])
    return XS

def plot(x):
    plt.plot([i for i in range(1,257)], x)
    plt.show()    

if __name__ == '__main__':
    M = 12
    train_in, train_out, test_in, test_out = loaddata()
    #plot(train_in[101])
    print train_in.shape
    #print outputs.shape
    knots = createknots(1,256)
    print knots
    p = len(train_in[0])
    H = basismatrix(knots, p, M)
    XS = transform(H, train_in, M)
    print XS.shape
    print np.linalg.matrix_rank(XS)
    beta = lg.logistic(XS, train_out)
    print beta
    error = 0
    TXS = transform(H, test_in, M)
    for i in range(len(TXS)):

# Path: LinearClassification/Logistic.py
# def augment(data):
# def cp(x, beta):
# def W(X, beta):
# def Z(X, Y, W, beta):
# def logistic(X, Y):
# def predict(x, beta):
# def zscore(X, Y, beta):
#     P = np.zeros(len(X))
#     XT = np.transpose(X)
#     M = np.transpose(X).dot(w).dot(X)
#     M = np.linalg.inv(M)
#     X = augment(inputs)[:,np.array([0,2,3,4,7])]


# Path: BasisExpansionsRegularization/PhonemeLogistic.py
import numpy as np
import matplotlib.pyplot as plt
from LinearClassification import Logistic as lg

def transform(H, train_in, M):
    ln = len(train_in)
    HT = np.transpose(H)
    XS = np.zeros((ln, M))
    for i in range(ln):
        XS[i] = HT.dot(train_in[i])
    return XS

def plot(x):
    plt.plot([i for i in range(1,257)], x)
    plt.show()    

if __name__ == '__main__':
    M = 12
    train_in, train_out, test_in, test_out = loaddata()
    #plot(train_in[101])
    print train_in.shape
    #print outputs.shape
    knots = createknots(1,256)
    print knots
    p = len(train_in[0])
    H = basismatrix(knots, p, M)
    XS = transform(H, train_in, M)
    print XS.shape
    print np.linalg.matrix_rank(XS)
    beta = lg.logistic(XS, train_out)
    print beta
    error = 0
    TXS = transform(H, test_in, M)
    for i in range(len(TXS)):

        res = lg.predict(TXS[i], beta)