All Projects → kretash → BasicNeuralNet

kretash / BasicNeuralNet

Licence: other
Trying to understand neural nets by building a simple one from scratch

Programming Languages

C++
36643 projects - #6 most used programming language

Projects that are alternatives of or similar to BasicNeuralNet

Optimizers-for-Tensorflow
Adam, NAdam and AAdam optimizers
Stars: ✭ 20 (-41.18%)
Mutual labels:  neural-nets
Deepdetect
Deep Learning API and Server in C++14 support for Caffe, Caffe2, PyTorch,TensorRT, Dlib, NCNN, Tensorflow, XGBoost and TSNE
Stars: ✭ 2,306 (+6682.35%)
Mutual labels:  neural-nets
Deeplearning4j
Suite of tools for deploying and training deep learning models using the JVM. Highlights include model import for keras, tensorflow, and onnx/pytorch, a modular and tiny c++ library for running math code and a java based math library on top of the core c++ library. Also includes samediff: a pytorch/tensorflow like library for running deep learni…
Stars: ✭ 12,277 (+36008.82%)
Mutual labels:  neural-nets
Faceswap
Deepfakes Software For All
Stars: ✭ 39,911 (+117285.29%)
Mutual labels:  neural-nets
Deepfacelab
DeepFaceLab is the leading software for creating deepfakes.
Stars: ✭ 30,308 (+89041.18%)
Mutual labels:  neural-nets
Pytorch Deep Learning
Deep Learning (with PyTorch)
Stars: ✭ 5,574 (+16294.12%)
Mutual labels:  neural-nets
sparse-som
Efficient Self-Organizing Map for Sparse Data
Stars: ✭ 17 (-50%)
Mutual labels:  neural-nets
joliGAN
Semantic Image-to-Image Translation for Domain Adaptation
Stars: ✭ 36 (+5.88%)
Mutual labels:  neural-nets
classifying-cancer
A Python-Tensorflow neural network for classifying cancer data
Stars: ✭ 30 (-11.76%)
Mutual labels:  neural-nets
Blur-and-Clear-Classification
Classifying the Blur and Clear Images
Stars: ✭ 88 (+158.82%)
Mutual labels:  neural-nets

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].