def f_second(i,pi,attribute_values,df): #-----------------CUDA #Cheetah Variables template = Template(f_source) template.DF = np.array(df[pi], dtype = np.int32) template.nrow = df[pi].shape[0] nfeat = df[pi].shape[1] template.ncol = nfeat template.ll = np.array(df[i], dtype=np.int32) phi_i_ = [attribute_values[item] for item in pi] combinations = np.array(list(itertools.product(*phi_i_)), dtype=np.int32) combinations = np.array(combinations.ravel().tolist(), dtype=np.int32) height = combinations.shape[0] template.H = height f_kernel = nvcc_compile(template, "my_f") ##Threads block_x = np.int(height/nfeat) blocksize = (block_x,1,1) gridsize = (1,1) ##Kernel h_res = np.zeros(height/nfeat,dtype=np.float32) d_combinations = gpu.to_gpu(combinations) d_res = gpu.to_gpu(h_res) f_kernel(d_combinations,d_res,block=blocksize,grid=gridsize) ress = d_res.get() ress = list(ress) return sum(ress)
for i in xrange(n): OKToProceed = False pi = [] pred = node_order[0:i] P_old = f(i,pi,attribute_values,df) if len(pred) > 0: OKToProceed = True while (OKToProceed == True and len(pi) < u): iters = [item for item in pred if item not in pi] if len(iters) > 0: f_to_max = {}; #Cheetah Variables template = Template(f_source) template.nrow = df[pi].shape[0] nfeat = df[pi].shape[1]+1 template.ncol = nfeat f_kernel = nvcc_compile(template, "my_f") for z_hat in iters: f_to_max[z_hat] = f_second(i,pi+[z_hat],attribute_values,df) #print 'i = %i, val = %f'% (i,f_to_max[z_hat]) z = max(f_to_max.iteritems(), key=operator.itemgetter(1))[0] P_new = f_to_max[z] if P_new > P_old: P_old = P_new pi = pi+[z] else: OKToProceed = False else: OKToProceed = False parents.append(pi)