def spectrum(peptide):#peptide being a list of integers # if peptide == "": # return [0] # subs = subpeptides(peptide) # spct = [0]+ [sum([im_table[a] for a in ppd]) for ppd in subs]+[sum([im_table[a] for a in peptide])] # return sorted(spct); spec=set() for i in range(0,len(peptide)): combis = itertools.combinations(peptide,i) spec = spec.union({sum(c) for c in combis}) return sorted(spec)
def create_super_key(FD, Attribute_list, size, Super_key_list): combination = itertools.combinations(Attribute_list, size) Super_keys = Super_key_list for comb in combination: result = helper.computeClosure(list(comb), FD) if (sorted(result) == Attribute_list): if (list(comb) not in Super_keys): Super_keys.append(list(comb)) return Super_keys return create_super_key(FD, Attribute_list, size + 1, Super_keys)
def exaustive_search(exons): full_array = [] highest_score = 0.0 best_combination = [] for exon in exons: full_array.append(exon.id) for i in range(len(full_array)): all_combinations = itertools.combinations(full_array, len(full_array) - i) for comb in all_combinations: if isSorted(comb): score = calculate_total_score(comb, exons) if score > highest_score: highest_score = score best_combination = comb if highest_score > 0.0: return best_combination
def Extraneous_attributes(FD_element, FD): FD_Left_side = FD_element[0] FD_Right_side = FD_element[1] Right_side_str = ''.join(FD_element[1]) Left_side_combination = itertools.combinations(FD_Left_side, len(FD_Left_side) - 1) #If our FD is just a single one EX: A --> D then its not redundant if (len(FD_Left_side) == 1): return FD #However if our FD is more than one on the LHS EX: ABC --> D then we check every possible combination to see which is redundant else: for single_element_combination in Left_side_combination: single_element_combination = list(single_element_combination) closure_of_single_element_combination = helper.computeClosure( single_element_combination, FD) #Now to see if redundant we check if our Right hand side is in our new closure of the new posibility if (Right_side_str in closure_of_single_element_combination): FD.remove(FD_element) FD.append([single_element_combination, FD_Right_side]) Extraneous_attributes( [single_element_combination, FD_element[1]], FD) return FD return FD
def _find_best_orderred_subset(alignment_exons, reference_exons): ''' Finds the best alignment exons subset with respect to the score (which corresponds to the sum of fitness' of the exons in the set ''' full_array = [] highest_score = 0. best_combination = [] ordered_alignment_exons = alignment_exons.get_ordered_exons() # add all the exon ordinals to a list of all ordinals for exon in ordered_alignment_exons: # if exon is already marked as not viable, just discard it if hasattr(exon, "viability"): if not exon.viability: continue full_array.append ((exon.ordinal, exon.alignment_ordinal)) for i in range (len(full_array)): # find all combinations of ordinals of all possible lengths # ranging from 1 to number of exons all_combinations = itertools.combinations(full_array, len(full_array)-i) for comb in all_combinations: if _is_sorted (comb, alignment_exons): score = _calculate_total_score(comb, ordered_alignment_exons) if score > highest_score: highest_score = score best_combination = comb if highest_score > 0.: return best_combination
def show_structure(self, xyz, super_cell_size=[1, 1, 1]): # self.setCameraPosition(distance=55, azimuth=-90) # self.setCameraPosition(azimuth=0) # self.setProjection() ii = 0 xyz_values = [] el_list = [] if len(self.items) != 0: self.clear() self.get_super_cell_grids_new(super_cell_size, color=[1, 0, 0, 0.8]) for each_line in self.grids: v1, v2, color = each_line self.addItem( self.draw_line_between_two_points(v1, v2, color, width=1)) for each in xyz: e, x, y, z = each #apply translation symmetry to consider super cell x, y, z = self.RealRM.dot([x, y, z]) xyz_trans = np.array( list( itertools.product(np.arange(0, super_cell_size[0]), np.arange(0, super_cell_size[1]), np.arange(0, super_cell_size[-1])))) xyz_trans = np.dot( self.RealRM, np.array(xyz_trans).transpose()).transpose().tolist() for each_xyz_trans in xyz_trans: md = gl.MeshData.sphere(rows=10, cols=20) m1 = gl.GLMeshItem(meshdata=md, smooth=True, color=color_to_rgb(color_lib[e.upper()]), shader='shaded', glOptions='opaque') # print(dir(m1.metaObject())) dx, dy, dz = each_xyz_trans m1.translate(x + dx, y + dy, z + dz) m1.scale(0.6, 0.6, 0.6) self.addItem(m1) xyz_values.append([x + dx, y + dy, z + dz]) el_list.append(e) dist_container = pdist(np.array(xyz_values), 'euclidean') index_all = list(itertools.combinations(range(len(xyz_values)), 2)) index_dist_all = np.where(dist_container < 3)[0] bond_index_all = [ index_all[each] for each in np.where(dist_container < 3)[0] ] bond_index = [] for i in range(len(bond_index_all)): each = bond_index_all[i] if el_list[each[0]] != el_list[each[1]]: try: bond_length = covalent_bond_length[(el_list[each[0]], el_list[each[1]])] if dist_container[index_dist_all[i]] < bond_length: bond_index.append(each) except: pass self.bond_index = bond_index if self.bond_index != None: for each_bond_index in self.bond_index: v1 = np.array(xyz_values[each_bond_index[0]]) v2 = np.array(xyz_values[each_bond_index[1]]) color1 = color_to_rgb( color_lib[el_list[each_bond_index[0]].upper()]) color2 = color_to_rgb( color_lib[el_list[each_bond_index[1]].upper()]) items = self.draw_two_chemical_bonds(v1, v2, [color1, color2]) [self.addItem(item) for item in items] self.setProjection()
def _saveResults(timestamp, balancesFName, n_trader_types, n_trials_per_ratio, iterativelyShow=False): traders_offset = 2 traders_fields = 4 traders_numberOfRobots = 2 trader_balancePerTrader_offset = 3 traderTypesCols = [] averageProfitCols = [] numberOfTradersCols = [] for i in xrange(n_trader_types): averageProfitCols.append(traders_offset + traders_fields*i + trader_balancePerTrader_offset) traderTypesCols.append(traders_offset + traders_fields*i) numberOfTradersCols.append(traders_offset + traders_fields*i + traders_numberOfRobots) allAvgProfits = np.loadtxt(balancesFName, delimiter=',', usecols=averageProfitCols, unpack = True) allTraderTypes = np.loadtxt(balancesFName, delimiter=',', usecols=traderTypesCols, unpack = True, dtype = np.str) allNumOfTraders= np.loadtxt(balancesFName, delimiter=',', usecols=numberOfTradersCols, unpack = True, dtype = np.str) if n_trader_types == 1: # If we have only one type of traders np.loadtxt will give us a simple # array instead of an array of arrays allAvgProfits = [allAvgProfits] allTraderTypes = [allTraderTypes] allNumOfTraders = [allNumOfTraders] # compute the list of traders types traders_types = [] for i in xrange(len(allTraderTypes)): traders_types.append(allTraderTypes[i][0]) # we only need the first one resultsFileName = '{}_results.txt'.format(timestamp) resultsFile=open(resultsFileName,'w') # compute means, of each ratio and total groupAvgProfitMeans = [] totalAvgProfitMeans = [] for i in xrange(len(allAvgProfits)): # For each trader type balancePerTraders = allAvgProfits[i] nTraders = allNumOfTraders[i] totalAvgProfitMeans.append(np.mean(balancePerTraders)) resultsFile.write("{0}:\nTotal mean: {1}\n".format(traders_types[i], totalAvgProfitMeans[i])) groupAvgProfitMeans.append([]) for j in xrange(0, len(balancePerTraders), n_trials_per_ratio): # For each experiment group groupAvgProfits = balancePerTraders[j:j+n_trials_per_ratio] numberOfRobots= nTraders[j:j+n_trials_per_ratio][0] mean = np.mean(groupAvgProfits) sd = np.std(groupAvgProfits) resultsFile.write("{0} robots: mean = {1}, stdev = {2} \n".format(numberOfRobots, mean, sd)) groupAvgProfitMeans[i].append(mean) # We configure the plot plt.clf() # We clear the plot plt.cla() ax = plt.subplot(111) xMin = 1 xMax = len(groupAvgProfitMeans[0]) + 1 xAxis = xrange(xMin,xMax) xTicks = [] step = round(len(xAxis) / 7) # 7 ticks for i in xAxis: if (i % step == 0): xTicks.append('G{}'.format(i)) else: xTicks.append('') plt.xticks(xAxis, xTicks) for i in xrange(len(groupAvgProfitMeans)): array = groupAvgProfitMeans[i] plot, = plt.plot(xAxis, array, label=traders_types[i]) plt.plot(xAxis, np.repeat(totalAvgProfitMeans[i], len(array)), color=plot.get_color(), label='Mean: {0:.2f}'.format(totalAvgProfitMeans[i]), linestyle='dashed') plt.title('Average profit per experiment group') plt.xlabel("Experiment Groups") plt.ylabel("Average Profit") # resize and set the legnd box = ax.get_position() ax.set_position([box.x0, box.y0, box.width * 0.75, box.height]) ax.legend(loc='center left', bbox_to_anchor=(1, 0.5)) plt.savefig("{}_plot_a.pdf".format(timestamp)) #resultsFile.write("All data Mann-Whitney U-test:\n"); #for subset in itertools.combinations(xrange(0, len(allAvgProfits)), 2): # i, j = subset # u, p_value = mannwhitneyu(allAvgProfits[i], allAvgProfits[j]) # resultsFile.write("{0} - {1} : u = {2}, p-value={3}\n".format(traders_types[i], traders_types[j], u, p_value)) resultsFile.write("Experiment group means Mann-Whitney U-test:\n"); for subset in itertools.combinations(xrange(0, len(groupAvgProfitMeans)), 2): i, j = subset u, p_value = mannwhitneyu(groupAvgProfitMeans[i], groupAvgProfitMeans[j]) resultsFile.write("{0} - {1} : u = {2}, p-value={3}\n".format(traders_types[i], traders_types[j], u, p_value)) #resultsFile.write("Wilcoxon test:\n"); #for subset in itertools.combinations(xrange(0, len(allAvgProfits)), 2): # i, j = subset # t, p_value = wilcoxon(allAvgProfits[i], list(reversed(allAvgProfits[j]))) # resultsFile.write("{0} - {1} : t = {2}, p-value={3}\n".format(traders_types[i], traders_types[j], t, p_value)) resultsFile.close() if iterativelyShow : plt.show()
def get_attributes_combinations(): list = [i for i in range(8)] i = itertools.combinations(list, 3) combinations = [item for item in i] return combinations