def regressionPlot(X, Y, M, w, basis_function):
      pl.plot(X.T.tolist()[0],Y.T.tolist()[0], 'gs')

      # You will need to write the designMatrix and regressionFit function

      # constuct the design matrix (Bishop 3.16), the 0th column is just 1s.
      #phi = _phi(X, M, basis_function)
      # compute the weight vector
      #w = max_likelihood_weight(X, Y, phi)

      print 'w', w
      # produce a plot of the values of the function 
      pts = np.array([[p] for p in pl.linspace(min(X), max(X), 100)])
      Yp = pl.dot(w.T, _phi(pts, M, basis_function).T)
      pl.plot(pts, Yp.tolist()[0])
      pl.xlim(min(X), max(X))
      pl.xlabel("X")
      pl.ylabel("Y")
      pl.title("Linear Regression (M={})".format(M))
      pl.show()
def SSE(X, Y, M, Theta, basis_function):
    phi = _phi(X, M, basis_function)

    e = np.dot(phi, Theta) - Y
    return np.dot(e.T, e)
def SSEfcn(X, Y, M, basis_function):
    phi = _phi(X, M, basis_function)
    return lambda Theta: np.linalg.norm(np.dot((np.dot(phi, Theta) - Y).T, np.dot(phi, Theta) - Y))
def SSEgrad(X, Y, M, Theta, basis_function):
    phi = _phi(X, M, basis_function)

    e = np.dot(phi, Theta) - Y
    return 2*np.dot(phi.T, e)