Exemplo n.º 1
0
    network.draw()
    take_still("neural_network_before.png")

    # Generate a video of the neural network learning
    print "Generating a video of the neural network learning."
    print "There will be " + str(
        len(examples) * len(parameters.show_iterations)) + " frames."
    print "This may take a long time. Please wait..."
    with writer.saving(fig, parameters.video_file_name, 100):
        for i in range(1, parameters.training_iterations + 1):
            cumulative_error = 0
            for e, example in enumerate(examples):
                cumulative_error += network.train(example)
                if i in parameters.show_iterations:
                    network.draw()
                    annotate_frame(i, e, average_error, example)
                    writer.grab_frame()
            average_error = calculate_average_error(cumulative_error,
                                                    len(examples))
    print "Success! Open the file " + parameters.video_file_name + " to view the video."

    # Generate an image of the neural network after training
    print "Generating an image of the neural network after"
    network.do_not_think()
    network.draw()
    take_still("neural_network_after.png")

    # Consider a new situation
    new_situation = [1, 1, 0]
    print "Considering a new situation " + str(new_situation) + "?"
    print network.think(new_situation)
Exemplo n.º 2
0
                TrainingExample([-27.97045,-42.6892,-62.42385,-72.11889,22,13,13,2,-138.0798,-37.23659,-52.0332,-47.41673,-59.97505,29,13,15,4,-147.1644],1.0),
                TrainingExample([-37.23659,-52.0332,-47.41673,-59.97505,29,13,15,4,-147.1644,-27.97045,-42.6892,-62.42385,-72.11889,22,13,13,2,-138.0798],0.0),
                TrainingExample([-42.23076,-57.38282,-80.06391,-91.61021,24,15,19,6,-146.6433,-45.00954,-46.97235,-108.6906,-114.4459,18,19,20,3,-133.4822],1.0),
                TrainingExample([-45.00954,-46.97235,-108.6906,-114.4459,18,19,20,3,-133.4822,-42.23076,-57.38282,-80.06391,-91.61021,24,15,19,6,-146.6433],0.0)]

    # Create a video and image writer
    fig, writer = generate_writer()


    print "Generating an image of the neural network loaded"
    network.load("dnn.10.__AllNodes__.txt")
    network.draw()
    take_still("neural_network_before.png")

    # Generate a video of the neural network learning
    print "Generating a video of the neural network learning."


    with writer.saving(fig, parameters.video_file_name, 100):
        for e, example in enumerate(examples):
            print e, example
            network.think(example.inputs)
            network.draw()
            annotate_frame(example)
            writer.grab_frame()
        print "Success! Open the file " + parameters.video_file_name + " to view the video."




Exemplo n.º 3
0
    network.do_not_think()
    network.draw()
    take_still("results/new_neural_network.png")

    # Generate a video of the neural network learning
    print "Generating a video of the neural network learning."
    print "There will be " + str(len(examples) * len(parameters.show_iterations)) + " frames."
    print "This may take a long time. Please wait..."
    with writer.saving(fig, parameters.video_file_name, 100):
        for i in range(1, parameters.training_iterations + 1):
            cumulative_error = 0
            for e, example in enumerate(examples):
                cumulative_error += network.train(example)
                if i in parameters.show_iterations:
                    network.draw()
                    annotate_frame(i, e, average_error, example)
                    writer.grab_frame()
            average_error = calculate_average_error(cumulative_error, len(examples))
    print "Success! Open the file " + parameters.video_file_name + " to view the video."

    # Generate an image of the neural network after training
    print "Generating an image of a trained neural network"
    network.do_not_think()
    network.draw()
    take_still("results/trained_neural_network.png")

    # Consider a new situation
    while True:
        print "Enter new input sequence"
        new_input = raw_input()
        new_input_list = [int(i) for i in new_input]