Ejemplo n.º 1
0
## read in the digits_train.csv file
training_line = []
for line in islice(f, 1, None):
    training_line.append(line.replace('\r\n', '').split(','))

## parse each line in the data, convert expected to binary list
## and normalizes pixel value from 0 to 1
for line in training_line:
    line[0] = create_out(int(line[0]))
    for i, item in enumerate(line[1:]):
        line[i + 1] = float(item) / 255.0
print("done")

## create the network and connect the nodes
n = NeuralNetwork(784, 50, 10)
n.connect_nodes()
print("connected")
print("training...")

## train the network with first 10000 digit values
i = 1
for line in islice(training_line, 10000):
    n.forward_prop(line[1:])
    n.back_prop(line[0], 1)
    print i
    i += 1
print("done training")

## test the network on the rest of the digit values
correct = 0
incorrect = 0
Ejemplo n.º 2
0
## read in the digits_train.csv file
training_line = []
for line in islice(f, 1, None):
    training_line.append(line.replace("\r\n", "").split(","))

## parse each line in the data, convert expected to binary list
## and normalizes pixel value from 0 to 1
for line in training_line:
    line[0] = create_out(int(line[0]))
    for i, item in enumerate(line[1:]):
        line[i + 1] = float(item) / 255.0
print ("done")

## create the network and connect the nodes
n = NeuralNetwork(784, 50, 10)
n.connect_nodes()
print ("connected")
print ("training...")

## train the network with first 10000 digit values
i = 1
for line in islice(training_line, 10000):
    n.forward_prop(line[1:])
    n.back_prop(line[0], 1)
    print i
    i += 1
print ("done training")


## test the network on the rest of the digit values
correct = 0
Ejemplo n.º 3
0
#! /usr/local/bin/python2.7

from n_network import NeuralNetwork, InputNode, HiddenNode, OutputNode

n = NeuralNetwork(2,3,1)
n.connect_nodes(False)
n.forward_prop([1,2])

for o_node in n.output_nodes:
  print o_node.output

n.back_prop([0],10)
n.print_net()

"""example of how the Node sub-classes work
without using the class NeuralNetwork"""
def build_n_network():
  i1 = InputNode(1)
  i2 = InputNode(2)
  h3 = HiddenNode(3)
  h4 = HiddenNode(4)
  h5 = HiddenNode(5)
  out1 = OutputNode(6)

  i1.connect(h3,-3)
  i1.connect(h4,2)
  i1.connect(h5,4)
  i2.connect(h3,2)
  i2.connect(h4,-3)
  i2.connect(h5,0.5)