# 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: LinearClassification/SAHeart_data.py
# def convertfunc(x):
# def loaddata():


import numpy as np
from LinearClassification import Logistic as lg
from LinearClassification import SAHeart_data as hd
    df = 1 + (K-1)*(len(data[0])-1) + 1
    L = len(data)
    new_matrix = np.zeros((L,df))
    for i in range(L):
        row = [1]
        for j in range(len(data[0])):
            seg = []
            if j == 3:
                seg.append(data[i,j])
                row = row + seg
                continue
            for k in range(0,K):
                seg.append(N(data[i,j], k, knots[j]))
            row = row + seg[1:]
        new_matrix[i] = np.array(row)
    return new_matrix

if __name__ == '__main__':
    K = 5
    X, Y = hd.loaddata()
    knots = split(X, K)
    print knots
    H = cookdata(X, K, knots)
    np.savetxt('H.dat', H, delimiter=',')
    print H.shape
    print np.linalg.matrix_rank(H)
    beta = lg.logistic(H, Y)
    print beta
    error = 0
    for i in range(len(H)):

# 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: LinearClassification/SAHeart_data.py
# def convertfunc(x):
# def loaddata():


# Path: BasisExpansionsRegularization/NaturalCubicSplines.py
import numpy as np
from LinearClassification import Logistic as lg
from LinearClassification import SAHeart_data as hd

    df = 1 + (K-1)*(len(data[0])-1) + 1
    L = len(data)
    new_matrix = np.zeros((L,df))
    for i in range(L):
        row = [1]
        for j in range(len(data[0])):
            seg = []
            if j == 3:
                seg.append(data[i,j])
                row = row + seg
                continue
            for k in range(0,K):
                seg.append(N(data[i,j], k, knots[j]))
            row = row + seg[1:]
        new_matrix[i] = np.array(row)
    return new_matrix

if __name__ == '__main__':
    K = 5
    X, Y = hd.loaddata()
    knots = split(X, K)
    print knots
    H = cookdata(X, K, knots)
    np.savetxt('H.dat', H, delimiter=',')
    print H.shape
    print np.linalg.matrix_rank(H)
    beta = lg.logistic(H, Y)
    print beta
    error = 0
    for i in range(len(H)):

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