def regress_poly(degree, data, remove_mean=True, axis=(-1)):
 IFLOG.debug((u'Performing polynomial regression on data of shape ' + str(data.shape)))
 datashape = data.shape
 timepoints = datashape[axis]
 data = data.reshape(((-1), timepoints))
 X = np.ones((timepoints, 1))
 for i in range(degree):
  polynomial_func = Legendre.basis((i + 1))
  value_array = np.linspace((-1), 1, timepoints)
  X = np.hstack((X, polynomial_func(value_array)[:, np.newaxis]))
 betas = np.linalg.pinv(X).dot(data.T)
 if remove_mean:
  datahat = X.dot(betas).T
 else:
  datahat = X[:, 1:].dot(betas[1:, ...]).T
 regressed_data = (data - datahat)
 return regressed_data.reshape(datashape)

def regress_poly ( degree , data , remove_mean = True , axis = ( - 1 ) ) : IFLOG . debug ( ( u'Performing polynomial regression on data of shape ' + str ( data . shape ) ) ) datashape = data . shape timepoints = datashape [ axis ] data = data . reshape ( ( ( - 1 ) , timepoints ) ) X = np . ones ( ( timepoints , 1 ) ) for i in range ( degree ) : polynomial_func = Legendre . basis ( ( i + 1 ) ) value_array = np . linspace ( ( - 1 ) , 1 , timepoints ) X = np . hstack ( ( X , polynomial_func ( value_array ) [ : , np . newaxis ] ) ) betas = np . linalg . pinv ( X ) . dot ( data . T ) if remove_mean : datahat = X . dot ( betas ) . T else : datahat = X [ : , 1 : ] . dot ( betas [ 1 : , ... ] ) . T regressed_data = ( data - datahat ) return regressed_data . reshape ( datashape )
returns data with degree polynomial regressed out .