def play(self): try: mkdir('examples/connect4/genomes') except OSError: pass players = input('Players: ') if players == 0: output = input('Output: ') for _ in xrange(input('Iterations: ')): processes = [] for i in xrange(20): processes.append(Process(target=self.thread, kwargs={'i': i, 'output': output})) processes[-1].start() for process in processes: process.join() elif players == 1: roll = randint(0, 19) ann = ANN(inputs=49, outputs=3, hidden=49, rows=5) try: ann.genome = load(open('examples/connect4/genomes/genome{0:02d}.p'.format(roll), 'rb')) except IOError: pass if roll < 10: Connect4([ann, None]).play() else: Connect4([None, ann]).play() elif players == 2: Connect4().play()
def setUp(self): self.G=ANN([[None]], sum) self.costs={(0,0):None} # pair: cost dict. self.heads={0:()} self.tails={0:()} self.sources=(0,) self.sinks=(0,) self.order=1 # Should I be returning tuples or lists? self.outputs={(0.1,):{0:0.1},(1,):{0:1},(5,):{0:5}}
class TestANNBase(TestGraphBase): def setUp(self): self.G=ANN([[None]], sum) self.costs={(0,0):None} # pair: cost dict. self.heads={0:()} self.tails={0:()} self.sources=(0,) self.sinks=(0,) self.order=1 # Should I be returning tuples or lists? self.outputs={(0.1,):{0:0.1},(1,):{0:1},(5,):{0:5}} def testFeedforward(self): for inputs, output in self.outputs.items(): self.assertEqual({i:round(o, 6) for i, o in self.G.feedforward(inputs).items()},output)
import numpy as np import pandas as pd filename = 'data_resource_usage_5Minutes_6176858948.csv' f = '5m' foldername = 'data/' # parameters idx = (6336, 6336 + 1584) sliding_windows = [2, 3, 5] pop_sizes = [100, 150, 200] cross_rates = [0.7, 0.8, 0.9] mutate_rates = [0.01, 0.02, 0.03] method_statistic = [0, 1, 2] n_expanded = [2, 3, 4] activations = [3, 2, 1, 0] df = pd.read_csv(foldername + filename, header=None, index_col=False, usecols=[3, 4]) df.dropna(inplace=True) dataset_original = df.values for sliding in sliding_windows: for ms in method_statistic: for activation in activations: p = ANN(dataset_original, idx[0], idx[1], sliding, ms, activation, f) p.train(epochs=1000)