Giter Club home page Giter Club logo

neuralnetwork's Introduction

Feed-forward neural network

This is an implementantion in Python of a simple model of a neural network. It uses the sigmoid function as the activation function, stochastic gradient descent for learning, and quadratic cost function (cross-entropy should be available soon). Weights and bias are initialized from a gaussian distribution (when not loaded), and are choosen using a low standart deviation to prevent neurons from being initially saturated.

Usage

Instanciation

You can initialize the network with random weights and biases, and i input neurons, h hidden layers and o output layers like so (any number of hidden layers is allowed):

NN = NeuralNetwork([i, h, o])

You can also initialize the net with a set of previously saved weights and bias by passing a preset name to the constructor (which should be present in the presets folder):

NN = NeuralNetwork("my_cool_preset")

Learning

Learning can be achieved calling the stochastic_gradient_descent method:

NN.stochastic_gradient_descent(training_data, test_data, epochs=10, batch_size=10, learning_rate=3.0)

training_data (and test_data, if needed) should be a list of of tuples (x, y). x should be a numpy column vector with i elements, i being the number of neurons in the input layers, and y should also be a column vector with o elements, where o is the number of neurons in the output layer.

If test_data is provided, at each epoch the method will print the number of itens in test_data that the network got correct.

Output

One can compute the output of the network as easily as

NN.feed_forward(x)

x is the input, and should be a numpy column vector with the same number of entries and the number of input neurons in the input layer.

Misc

It is possible to load the MNIST data using the following methods:

handwritten_digits = MNIST("data/mnist")
training_data = handwritten_digits.load_training()
testing_data = handwritten_digits.load_testing()

You can also save the current set of weights and biases in a external file, in the presets folder:

NN.save_parameters("my_cool_preset")

neuralnetwork's People

Contributors

alansammarone avatar

Stargazers

Guilherme Kingma avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.