Coder Social home page Coder Social logo

basicneuralnet's Introduction

Basic Neural Net

The most basic neural net you can build. Completly from scratch in C++.

This network currently trains and produces results for an XOR.


Building the network

The first thing we do is create the different layers. We specify how many nodes each layer has.

    std::shared_ptr<Layer> input_layer = std::make_shared<Layer>( 2, "Input Layer" );
    std::shared_ptr<Layer> hidden_layer = std::make_shared<Layer>( 3, "Hidden Layer" );
    std::shared_ptr<Layer> output_layer = std::make_shared<Layer>( 1 , "Output Layer" );

image1

The next step is to create the links between the layers and create a network. The function project will connect all the nodes in a layer to the layer passed as an argument.

    input_layer->project( hidden_layer );
    hidden_layer->project( output_layer );

This is how our layers look now.

image2

Finally, to create the network we need pass the input and output layers.

    std::shared_ptr<Network> network = std::make_shared<Network>( input_layer, output_layer );

Using the Network

To use the network we call the function activate. This function will take an std::vector as a parameter that should match in size with the number of nodes in the input layer. The return vector will be the same size as the number of output nodes.

    std::vector<double> output = network->activate( { 0,0 } );

The output values we will get the first times we use the network will be random. In order to train the network we can call propagate after an activate to trains the network. We want to pass in a learning rate and the target results. The learning rate is just a constant defined to 0.5 and the target results must be an std::vector that matches in size with the amount of output nodes. The learning rate can be tweaked to achieve better results.

    network->propagate( learning_rate, { 0 } );

Once this is done a multitude of times with all posible values the results from the activate will start to match the target results.


Building

There is a Visual Studio solution file and xcode project that can be use to build. There is only a small number of files, so building from the command line would be easy too.

License

MIT License

basicneuralnet's People

Contributors

kretash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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