def main(): batch_size = 100 mnist_train = datasets.MNIST("/hdd/Data/MNIST/", train=True, transform=transforms.ToTensor(), download=True) mnist_test = datasets.MNIST("/hdd/Data/MNIST/", train=False, transform=transforms.ToTensor(), download=True) data_feeder = DataFeeder(mnist_train, preprocess_workers=1, cuda_workers=1, cpu_size=10, cuda_size=10, batch_size=batch_size, use_cuda=True, volatile=False) data_feeder.start_queue_threads() cnn = ModelStruct(CNN().cuda(), 0.001) fcc = ModelStruct(FCC().cuda(), 0.001) test_data = make_batch(len(mnist_test), 0, mnist_test, use_cuda=True) for i in range(100001): images, labels = data_feeder.get_batch() train(cnn, images, labels, i) train(fcc, images, labels, i) if i % 100 == 0: evaluate_acc(cnn, test_data, i) evaluate_acc(fcc, test_data, i) if i in [33333, 66666]: decrease_lr(cnn) decrease_lr(fcc) if i % 20000 == 0: torch.save(cnn.model, "savedir/cnn_it" + str(i // 1000) + "k.pt") torch.save(fcc.model, "savedir/fcc_it" + str(i // 1000) + "k.pt") print(max(cnn.acc)) print(max(fcc.acc)) graph(fcc, cnn) cnn.losses = losses_to_ewma(cnn.losses) cnn.val_losses = losses_to_ewma(cnn.val_losses, alpha=0.3) cnn.acc = losses_to_ewma(cnn.acc) fcc.losses = losses_to_ewma(fcc.losses) fcc.val_losses = losses_to_ewma(fcc.val_losses, alpha=0.3) fcc.acc = losses_to_ewma(fcc.acc) graph(fcc, cnn) data_feeder.kill_queue_threads()
def get(self, *args, **kwargs): ''' Retrieve objects from remote server ''' extra_fields = kwargs.pop('extra_fields', {}) # extra_fields['fetched'] = datetime.now() response = graph(self.resource_path % args[0], **kwargs) return self.parse_response(response.toDict(), extra_fields)
import utils print(utils.graph(3, 5))
def traverse(tree): machines = [] if not tree: return r = traverse(tree.right) l = traverse(tree.left) machines.append(r) if r else None machines.append(l) if l else None if tree.data in operations: result = create(machines, tree.data) print(result.start.transitions, 'Transitions') else: result = create(tree.data, None) return result if __name__ == "__main__": inp = input('Regex: ') symbols = set(inp) - set(operations) - set(EPSILON) - set('()') Tree, pos = evaluate(inp, 0) print2D(Tree) nfa = traverse(Tree) t = getTransitionTable(nfa, symbols) graph(t) while 1: match = input('String: ') print(t[0].matches(match, []))
Tree, pos = evaluate(inp, 0) DFATree, pos1 = evaluate(inp + '.#', 0) print2D(Tree) follow = {} for p in range(pos1): follow[p + 1] = set() nfa = traverse(Tree) nfa_table, accepting, _s = nfa.transition_table() dfaFromNFA = getTransitionTable(nfa, symbols) dfaFromRegex = build(DFATree, symbols.union(set('#')), follow) graph(dfaFromNFA, inp + 'fromNFA') graph(dfaFromRegex, inp + 'fromRegex') graphNFA(nfa_table, accepting, inp + 'NFA') match = True while match: match = input('String: ') start = time.time() print(dfaFromNFA[0].matches(match, [])) end = time.time() print('DFA from NFA took', end - start, 'seconds') start = time.time() print(dfaFromRegex[0].matches(match, [])) end = time.time()
def draw_graph(self): if not self.graphing and self.game_state != GAMEOVER: self.level_scores.append(self.score) self.graphing = True if graph(self.level_scores, self): self.game_state = GAMEOVER