def comb_base_and_GPU(self, top_comb_cur, top_terms, top_res, num_evals, poly_builder, ref_hws=None): """ Base skeleton for generating all AND combinations from top_terms to degree top_comb_cur with help of GPU. For documentation see @comb_base """ #print("AND COMB BASE GPU") polynoms = [] expps = [] exp_cnts = [] for idx, places in enumerate(common.term_generator(top_comb_cur, len(top_terms) - 1, self.prob_comb)): poly = poly_builder(places, top_terms) expp = self.term_eval.expp_poly(poly) exp_cnt = num_evals * expp polynoms.append(poly) expps.append(expp) exp_cnts.append(exp_cnt) #print(len(polynoms),len(expps),len(exp_cnts),polynoms[0]) #print(polynoms) #print("jedno vlakno bere",len(polynoms[0])," *",len(polynoms[0][0])," prvkov, celkovo bude",len(polynoms),"vlakien a prvkov", len(polynoms) * len(polynoms[0][0])) #metadata needed because we are flattening the array for faster access termLen = np.int32(len(polynoms[0][0])) #how many indices have term polyLen = np.int32(len(polynoms[0])) #how many terms are there in one polynom numPolys = np.int32(len(polynoms)) #number of all polynoms #print("pocet indexov termu",termLen,"termov v polynome",polyLen,"pocetpoly",numPolys,"pocetTerm",numPolys*polyLen) #for i in range(0,numPolys): # print(polynoms[i]) obs_cnts = self.term_eval.calculate_and_obs_counts(top_comb_cur,len(top_terms),polynoms,termLen,polyLen,numPolys) #for i in range(0,numPolys): # print("poly",polynoms[i],"count",obs_cnts[i]) #skontrolovat lebo len som to prepisal aby to sedelo na idx for idx,places in enumerate(common.term_generator(top_comb_cur, len(top_terms) - 1, self.prob_comb)): if exp_cnts[idx] == 0: continue zscore = common.zscore(obs_cnts[idx], exp_cnts[idx], num_evals) comb = None if ref_hws is None: comb = Combined(polynoms[idx], expps[idx], exp_cnts[idx], obs_cnts[idx], zscore) else: ref_obs_cnt = self.ref_term_eval.hw( self.ref_term_eval.eval_poly(polynoms[idx], res=self.comb_res, subres=self.comb_subres)) zscore_ref = common.zscore(ref_obs_cnt, exp_cnts[idx], num_evals) comb = Combined(poly, expps[idx], exp_cnts[idx], obs_cnts[idx], zscore - zscore_ref) self.comb_add_result(comb, top_res)
def independence_test(self, term_eval, ddeg=3, vvar=10): """ Experimental verification of term independence. :param term_eval: :param ddeg: :param vvar: :return: """ tterms = common.comb(vvar, ddeg) print('Independence test C(%d, %d) = %s' % (vvar, ddeg, tterms)) ones = [0] * common.comb(vvar, ddeg, True) for val in common.pos_generator(dim=vvar, maxelem=1): for idx, term in enumerate(common.term_generator(ddeg, vvar - 1)): ones[idx] += term_eval.eval_term_raw_single(term, val) print('Done') print(ones)
def comb_base(self, top_comb_cur, top_terms, top_res, num_evals, poly_builder, ref_hws=None): """ Base skeleton for generating all combinations from top_terms up to degree top_comb_cur :param top_comb_cur: current degree of the combination :param top_terms: top terms buffer to choose terms out of :param top_res: top results accumulator to put :param num_evals: number of evaluations in this round - zscore computation :param poly_builder: function of (places, top_terms) returns a new polynomial :param ref_hws: reference results :return: """ for idx, places in enumerate( common.term_generator(top_comb_cur, len(top_terms) - 1, self.prob_comb)): poly = poly_builder(places, top_terms) expp = self.term_eval.expp_poly(poly) exp_cnt = num_evals * expp if exp_cnt == 0: continue obs_cnt = self.term_eval.hw( self.term_eval.eval_poly(poly, res=self.comb_res, subres=self.comb_subres)) zscore = common.zscore(obs_cnt, exp_cnt, num_evals) comb = None if ref_hws is None: comb = Combined(poly, expp, exp_cnt, obs_cnt, zscore) else: ref_obs_cnt = self.ref_term_eval.hw( self.ref_term_eval.eval_poly(poly, res=self.comb_res, subres=self.comb_subres)) zscore_ref = common.zscore(ref_obs_cnt, exp_cnt, num_evals) comb = Combined(poly, expp, exp_cnt, obs_cnt, zscore - zscore_ref) self.comb_add_result(comb, top_res)