GithubHelp home page GithubHelp logo

neural-network-c's Introduction

Simple Neural Network written in C

Build status (LLVM on macOS, GCC on Linux, MSVC on Windows)

This is a very basic neural network implementation written with simple C.

I really just created this to learn more about the internals of neural networks. I'm making it public in case anyone else finds it helpful or useful.

Features

  • Allows abitrary number of layers, and nodes in each layer (feed-forward only)
  • Processes multiple training examples at a time
  • Good unit test coverage
  • Load and save weight values to file

Improvement Potential

  • Include bias nodes
  • Paralellisation across CPU and/or GPU to increase speed
  • Choice of activation function at different layers

Usage

  1. Create/allocate a new neural network with any number of layers, and any number of nodes in each layer, e.g.

    nn_Network *network = nn_Network_alloc("2, 3, 1");
  2. Randomise weights within the network

    nn_Network_randomiseWeightsBetweenMinAndMax(network, -3.0, 3.0);
  3. Set up training input and output data, e.g.

    nn_Matrix *trainingDataInputs = nn_Matrix_allocWithValues(4, 2,
    	0.0, 0.0,
    	0.0, 1.0,
    	1.0, 0.0,
    	1.0, 1.0
    );
    nn_Matrix *trainingDataOutputs = nn_Matrix_allocWithValues(4, 1,
    	1.0,
    	0.0,
    	0.0,
    	1.0
    );
  4. Complete a training pass (forward, then backward pass with weight updates),

    double error = nn_Network_train(network, trainingDataInputs, trainingDataOutputs, 0.3);

    Complete this step until error is at an acceptable level.

  5. Clean up memory,

    nn_Matrix_free(trainingDataInputs);
    nn_Matrix_free(trainingDataOutputs);
    nn_Network_free(network);
  6. Link in the C math library when building, e.g.

    cc -o example example.c nn_Network.c nn_Matrix.c -lm

neural-network-c's People

Contributors

jdoxey avatar

Watchers

 avatar Kostas Georgiou 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.