Giter Club home page Giter Club logo

neuralnet's Introduction

neuralnet

A Python utility for using feed-forward artificial neural networks


Command Line Usage

The utility can be run from the command line as follows:

python neuralnet.py [-h] {new,train,eval} ...

There are three different commands that can be used to create new networks, train them, and use them to evaluate data.

Creating a new network:

python neuralnet.py new /path/to/save/network.txt 2 3 1

The above command will create a new network with 3 layers consisting of 2 neurons, 3 neurons, and 1 neuron, respectively, and save it to the designated path.

Training a network:

python neuralnet.py train /path/to/saved/network.txt trainingInput.txt trainingOutput.txt

The above command will load the network saved at the designated path and train it on the provided input and output data. The input and output data should consist of values separated by a single space with each line representing a different set of training data. The first line of the input data should correspond to the first line of the output data, and so on.

An optional parameter can be specified with -e MAXERROR where MAXERROR is the desired accuracy of the network (no error exceeds the provided value).

The trained network will be saved to the path from which the network was originally loaded.

Evaluating data on the network:
Data can be evaluated on the network in two ways:

python neuralnet.py eval -i 1 0 /path/to/network.txt

Will evaluate the dataset 1 0 on the neural net and report the output.

python neyralnet.py eval -l input.txt /path/to/network.txt

Will evaluate all datasets contained in the input file and report the output.

NeuralNet Class Reference

A fully-functional NeuralNet class is also included that can be imported into Python projects.

Initializing the class:
The neural network can be initialized with random weights and biases as follows:

neurons = [2, 3, 1]
nn = NeuralNetwork(neurons)

Alternatively, if you have a list of weights and biases, the neural network can be initialized as follows:

nn = NeuralNetwork(neurons, weights, biases)

The weights array is a two-dimensional list. weights[i][j] corresponds to the weight between the neuron i and the j'th neuron in the previous layer.

The biases array is simply a list of biases for each neuron.

Saving a network:
A neural network can be saved using the save function:

nn.save('/path/to/save.txt')

Will save the neural network to the provided path.

Loading a network:
A neural network can be loaded using the load function:

nn = NeuralNetwork.load('/path/to/load.txt')

Training the network:
The network can be trained on a set of data as follows:

input = [[0, 0],[0,1],[1,0],[1,1]]
output = [[0],[1],[1],[0]]
maxError = 0.01
nn.simulate(input, output, maxError)

Evaluating data on a network:
To evaluate a set of data on the network, use the eval function:

input = [1,0]
output = nn.eval(input)

Note that when training the network, a list of data sets is expected while one one data set is expected when evaluating data


Developed by William Ganucheau. Released under the MIT License.

neuralnet's People

Contributors

williamg avatar

Watchers

Y. Zhai 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.