def setup_param_group(self, group): frame = tk.Frame(self.param_tabs) self.param_tabs.add(frame, text=group.title) i = 0 for p1, p2 in pairs(group.params): self.setup_param(frame, p1, i, 0) if p2: self.setup_param(frame, p2, i, 1) i += 1
def get_sequence(self): # NEW APPROACH if len(self.assembly) >= 2: for contig1,contig2 in util.pairs(self.assembly): uniq1 = contig1.get_unique_sequence() uniq2 = contig2.get_unique_sequence() overlap = contig1.get_overlap_sequence(contig2) if uniq1 not in self.sequence: self.sequence.append(uniq1) self.sequence.append(overlap) self.sequence.append(uniq2) # cleanup steps self.sequence = "".join(self.sequence) self.length = len(self.sequence) else: self.sequence = self.assembly[0].sequence
def recover_token(oracle): token = oracle.create_token() ans = bytearray() for c1, c2 in util.pairs(util.blocks(token, 16)): p2 = bytearray(16) for i in reversed(range(16)): padding = pad(bytes(i), 16) for guess in range(256): p2[i] = guess iv = xor(c1, p2, padding) if i == 15: # Ugly hack; prevent creating new valid padding. iv[:14] = bytearray(14) if oracle.is_padding_ok(bytes(iv + c2)): break ans += p2 return bytes(unpad(ans, 16))
def mappings(x, y, getTransformations=True, repeats=False): tempy = y if len(y) < len(x): tempy.extend([None] * (len(x) - len(y))) mappings = util.pairs(x, tempy) if len(x) < len(y): mappings = util.extended_pairs(x, y) # Mappings defined as follows: Given x=[1], y=[1,2], we want queue = PriorityQueue() for mapping in mappings: ftf = FigureTransformation() for objectMap in mapping: name = objectMap[0].getName() otf = ObjectTransformation(objectMap, ftf, transform=getTransformations, try_repeats=repeats) ftf.add(name, otf) yield ftf
def heuristic(ks): pairs = util.pairs(util.blocks(ct, ks)) return sum(hamming(x, y) for x, y in pairs if len(x) == len(y))
spy = price['SPY'].copy() price = price.drop('SPY', 1) delta = pd.DataFrame(index=price.index, columns=price.columns) for c in price.columns: delta[c] = price[c].pct_change() days = delta.shape[0] symbols = delta.shape[1] i = 0 corr_tab = np.empty(shape=[days, symbols**2]) for c1 in delta.columns: for c2 in delta.columns: corr_tab[:,i] = delta[c1].rolling(window=w).corr(delta[c2]) i += 1 avg_corr = pd.DataFrame(index=delta.index, columns=['Correlation']) avg_corr['Correlation'] = 100 * (corr_tab.sum(axis=1) - symbols) / 2 / u.pairs(symbols) avg_corr['SPY'] = spy avg_corr['Date'] = pd.to_datetime(avg_corr.index) avg_corr['Smooth SPY'] = avg_corr['SPY'].rolling(window=s).mean() avg_corr['Smooth Corr'] = avg_corr['Correlation'].rolling(window=s).mean() avg_corr = avg_corr.iloc[w+s:,:] #truncate the wasted w+s days avg_corr.loc[avg_corr['Correlation'] <= lo, 'Low'] = True box = avg_corr.loc[:,['Date', 'Low']] box = box[box['Low'] == True] top = avg_corr['SPY'].max() bottom = avg_corr['SPY'].min() box['Top'] = top box['Bottom'] = bottom box['Right'] = box['Date'] + pd.DateOffset(2)