# Path: LinearRegression/leastsquare.py
# def ls(X, Y):
# def augment(data):
# def predict(X, beta):
# def RSS(X, Y, beta):
# def thegama2(yhat, output, p):
# def z_score(beta, theg, data):
#     XT = np.transpose(X)
#     M = XT.dot(X)
#     DT = np.transpose(data)
#     M = np.linalg.inv(DT.dot(data))


import numpy as np
import matplotlib.pyplot as plt
from LinearRegression import leastsquare as ls
    return (item1**3 - item2**3)/kdiff

def N(x, k, knots):
    if k == 1:
        return 1
    elif k == 2:
        return x
    else:
        return d(x, k-2, knots)-d(x, len(knots)-1, knots)

def nscookdata(data, K, knots):
    df = 6
    L = len(data)
    new_matrix = np.zeros((L,df))
    for i in range(L):
        row = []
        for k in range(1,K+1):
            row.append(N(data[i], k, knots))
        new_matrix[i] = np.array(row)
    return new_matrix
    
def draw_natural_spline_pwv(train_in, train_out):
    p = 5
    knots = np.arange(0.1, 0.9, 0.16).tolist()
    knots.append(0.9)
    X = nscookdata(train_in, 6, knots)
    #print H
    #print H.shape
    XT = np.transpose(X)
    

# Path: LinearRegression/leastsquare.py
# def ls(X, Y):
# def augment(data):
# def predict(X, beta):
# def RSS(X, Y, beta):
# def thegama2(yhat, output, p):
# def z_score(beta, theg, data):
#     XT = np.transpose(X)
#     M = XT.dot(X)
#     DT = np.transpose(data)
#     M = np.linalg.inv(DT.dot(data))


# Path: BasisExpansionsRegularization/PointwiseVariance.py
import numpy as np
import matplotlib.pyplot as plt
from LinearRegression import leastsquare as ls

    return (item1**3 - item2**3)/kdiff

def N(x, k, knots):
    if k == 1:
        return 1
    elif k == 2:
        return x
    else:
        return d(x, k-2, knots)-d(x, len(knots)-1, knots)

def nscookdata(data, K, knots):
    df = 6
    L = len(data)
    new_matrix = np.zeros((L,df))
    for i in range(L):
        row = []
        for k in range(1,K+1):
            row.append(N(data[i], k, knots))
        new_matrix[i] = np.array(row)
    return new_matrix
    
def draw_natural_spline_pwv(train_in, train_out):
    p = 5
    knots = np.arange(0.1, 0.9, 0.16).tolist()
    knots.append(0.9)
    X = nscookdata(train_in, 6, knots)
    #print H
    #print H.shape
    XT = np.transpose(X)
    

    beta = ls.ls(X, train_out)