def draw_polynomial_pwv(train_in, train_out): p = 3 X = polynomial(train_in) XT = np.transpose(X) beta = ls.ls(X, train_out) Yhat = ls.predict(X, beta) thegsq = ls.thegama2(Yhat, train_out, p) beta_var = np.linalg.inv(XT.dot(X))*thegsq print beta_var PWV = [] for i in range(len(X)): PWV.append(np.transpose(X[i]).dot(beta_var).dot(X[i])) #print PWV plt.plot(train_in, PWV)
def draw_cubic_spline_pwv(train_in, train_out): p = 5 X = cubic(train_in) #print X.shape XT = np.transpose(X) #print X beta = ls.ls(X, train_out) Yhat = ls.predict(X, beta) thegsq = ls.thegama2(Yhat, train_out, p) beta_var = np.linalg.inv(XT.dot(X))*thegsq print beta_var PWV = [] for i in range(len(X)): PWV.append(np.transpose(X[i]).dot(beta_var).dot(X[i])) #print PWV plt.plot(train_in, PWV)
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) Yhat = ls.predict(X, beta) thegsq = ls.thegama2(Yhat, train_out, p) beta_var = np.linalg.inv(XT.dot(X))*thegsq print beta_var PWV = [] for i in range(len(X)): PWV.append(np.transpose(X[i]).dot(beta_var).dot(X[i])) #print PWV plt.plot(train_in, PWV)