rs_1 = AbstractLayer (ReshapeLayer, [16], [1, 16]) fc_1 = AbstractLayer (FCLayer, [1, 16], [1, 256]) l_1 = AbstractLayer (LogisticLayer, [1, 256], [1, 256]) fc_2 = AbstractLayer (FCLayer, [1, 256], [1, 4]) rs_2 = AbstractLayer (ReshapeLayer, [1, 4], [4]) sftm = AbstractLayer (SoftmaxLayer, [4], [4]) argmax = AbstractLayer (ArgmaxLayer, [4], [1]) net = Netlist ([rs_1, fc_1, l_1, fc_2, rs_2, sftm, argmax]) g, v = net.build_graph () ga = GeneticAlgorithm (0.7, 0.05, 200, net, Phenotype2048) scores = [] for a in range (100): scores += [math.sqrt (ga.get_best ().fitness)] if a % 2 == 0: ga.stats () ga.generation () ga.stats () plt.plot (scores)
rs_1 = AbstractLayer (ReshapeLayer, [2], [1, 2]) fc_1 = AbstractLayer (FCLayer, [1, 2], [1, 4]) l_1 = AbstractLayer (LogisticLayer, [1, 4], [1, 4]) fc_2 = AbstractLayer (FCLayer, [1, 4], [1, 2]) rs_2 = AbstractLayer (ReshapeLayer, [1, 2], [2]) sftm = AbstractLayer (SoftmaxLayer, [2], [2]) argmax = AbstractLayer (ArgmaxLayer, [2], [1]) net = Netlist ([rs_1, fc_1, l_1, fc_2, rs_2, sftm, argmax]) g, v = net.build_graph () ga = GeneticAlgorithm (0.7, 0.05, 200, net, PhenotypeXOR) a = 0 while (ga.get_best ().evaluate () != 16): if a % 20 == 0: ga.stats () ga.generation () a += 1 ga.stats () g = ga.get_best ().graph print '[0, 0] -> ', g.evaluate (np.array ([0, 0])) print '[0, 1] -> ', g.evaluate (np.array ([0, 1])) print '[1, 0] -> ', g.evaluate (np.array ([1, 0]))