truth_count = 0
	for p in row:
		if p :
			truth_count += 1
	return 1 * (truth_count == 1)

def truthtable (n):
	if n < 1:
		return [[]]
	subtable = truthtable(n-1)
	return [ row + [v] for row in subtable for v in [0,1] ]

def interpret(v):
	if v[0] > v[1]:
		return 1
	else:
		return 0

a = neuralnetwork.makeNNet(3, 3, 3, act.relu, act.relu)
b = neuralnetwork.makeNNet(3, 2, 1, act.relu, act.relu)

deepnet = neuralnetwork.DeepNet([a, b])

inputs = truthtable(3)
targets = [xor(x) for x in inputs]
for i in range(3000):
	for x, t in zip(inputs, targets):
		deepnet.learn(x, t, 0.01)

for x, t in zip(inputs, targets):
	print t, x, deepnet.feedForward(x)
Beispiel #2
0
	max_index = 0
	for i, n in enumerate(numbers):
		if n > numbers[max_index]:
			max_index = i
	return max_index

path = "/home/lance/git/nnetevolution/src/data"
# Images are 28x28 pixels. Reshapen, they are 784x1
training = [(mux(label), image.reshape(784)/255.0) for label, image in mnist.read(path=path, dataset="training")]
testing = [(mux(label), image.reshape(784)/255.0) for label, image in mnist.read(path=path, dataset="testing")]


a = neuralnetwork.makeSquareConvolution(2, 14)
# pudb.set_trace()
b = neuralnetwork.makeSquareConvolution(2, 7)
nnet = neuralnetwork.makeNNet(49, 10, 10, act.sigmoid, act.relu)
deepnet = neuralnetwork.DeepNet([a, b, nnet])

l = len(training)
k = 1
p = printing.printer(1)
for t, x in training:
	deepnet.learn(x, t)
	p.reprint("iteration: " + str(k) + "/" + str(l))
	k += 1
print
print "finished..."

count = 0
for t, x in testing:
	y = demux(deepnet.feedForward(x))
Beispiel #3
0
import neuralnetwork
from evolution import getAncestor, getDescendant, addNode, splitArc, copy
import networkx as nx
import matplotlib.pyplot as plt
import pylab

import pudb

def makeTuple(arc):
	return (str(arc.parent.innovation_number), str(arc.child.innovation_number))

nnet = neuralnetwork.makeNNet(2, 2, 1)

for i in range(1):
	n = addNode(nnet.input_layer + nnet.hidden_layer + nnet.output_layer)
	nnet.hidden_layer.append(n)
# 	n = splitArc(nnet.input_layer + nnet.hidden_layer + nnet.output_layer)
# 	nnet.hidden_layer.append(n)

G = nx.DiGraph()

arcs = []
for n in nnet.nodes:
	for a in n.incoming:
		arcs.append(makeTuple(a))
G.add_edges_from(arcs)

pos = nx.spring_layout(G)
nx.draw(G, pos)
nx.draw_networkx_labels(G, pos)
plt.show()