def residualize(X, ps): numObs = X.shape[0] resHat = np.zeros((numObs,1)) hOptimal = LLR.optimalBandwidthSelection(X, ps) # for each observations, get prediction for iObs in range(numObs): xFit = LLR.polynomialFit(X,ps, ps[iObs], hOptimal) resHat[iObs] = X[iObs] - xFit[0] return resHat
def residualize(X, ps): numObs = X.shape[0] resHat = np.zeros((numObs, 1)) hOptimal = LLR.optimalBandwidthSelection(X, ps) # for each observations, get prediction for iObs in range(numObs): xFit = LLR.polynomialFit(X, ps, ps[iObs], hOptimal) resHat[iObs] = X[iObs] - xFit[0] return resHat
def LLRKpLIVOptimalBandwidth(yTilda, ps): hOptimal = LLR.optimalBandwidthSelection(yTilda, ps) return hOptimal
import localLinearRegression as LLR import numpy as np dataList = [] f = open('D:/gitRepo/grmEstimatorToolbox/mteApproach/data/testData.csv','rb') import csv readed = csv.reader(f) for row in readed: dataList.append(row) ''' array - the list ''' data = np.array(dataList, dtype = float) Y = data[:,0:1]**(1./3.) X = data[:,1:2] ''' for unit test purpose, specify the hVec ''' hVec = np.arange(20,100,1) hOptimal = LLR.optimalBandwidthSelection(Y, X, hVec) assert abs(hOptimal - 93)<1 hOptimal = LLR.optimalBandwidthSelection(Y, X) assert abs(hOptimal - 84)<1 print('localLinearRegression passes unit test')
#print test1, test2 #from mpi4py import MPI #import numpy #comm = MPI.COMM_WORLD #rank = comm.Get_rank() #if rank == 0: # data = numpy.arange(1000, dtype = 'i') # comm.Send([data, MPI.INT], dest = 1, tag = 77) #elif rank == 1: # data = numpy.empty(1000, dtype = 'i') # comm.Recv([data, MPI.INT], source = 0, tag = 77) import sampleSimulation as ss import localLinearRegression as LLR import numpy Y,D,X,Z = ss.underiv_data(500) h = numpy.arange(0.05,2,0.05) LLR.optimalBandwidthSelection(Y, X[:,0:1], h) # Retrieves the result calculated by job1 # The value of job1() is the same as sum_primes(100) # If the job has not been finished yet, execution will wait here until result is available