Coder Social home page Coder Social logo

rusih100 / simple-neural-network Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 1.0 211 KB

🧬 A simple scalable evolutionary neural network in C++

License: MIT License

CMake 2.62% C++ 95.36% C 2.02%
cpp neural-network machine-learning deep-learning neural-networks

simple-neural-network's Introduction

simple_neural_network

🧬 A simple scalable evolutionary neural network in C++

Description

Hi. This is a simple neural network model that is trained by evolution.
The neural network is scalable, that is, the number of input and output neurons is set, as well as the number of hidden layers with the same number of neurons on each layer is set. The sigmoid function is used as the activation function.
A neural network consists of two main classes Network_training and Neuron_network.

Example of creating a neural network

In this example, we will create a neural network that performs the XOR operation.

x y XOR
0 0 0
0 1 1
1 0 1
1 1 0

Let's define datasets and expected results for these datasets.
The neural network takes a vector of values as input and returns the result as a vector.

vector <vector<float>> dataset_input = {
            {0, 0}, {0, 1}, {1, 0}, {1, 1}
    };

vector <vector<float>> dataset_output = {
            {0}, {1}, {1}, {0}
    };

Create an instance of the Neuron_network class with the parameters:
2 hidden layers (hidden_layers_n), 3 neurons on each hidden layer (neurons_per_layer_n), 2 input neurons (inputs_n), 1 output neuron (outputs_n).

Neuron_network XOR(2, 3, 2, 1);

Let's train a neural network with these parameters for 100,000 epochs.
To do this, create an instance of class Network_training and pass it our neural network and datasets.
The method training() will return us a trained neural network

Network_training Training_network(dataset_input, dataset_output, XOR);  
XOR = Training_network.training(100000);

Let's test the work of a neural network on a data set:

cout << "Datasets result: \n";
    for (auto & set : dataset_input) {
        cout << "[ ";
        for (float i : set) {
            cout << i << " ";
        }
        cout << "] - ";
        cout << XOR.run(set)[0] << "\n";
    }

Results:

Datasets result:
[ 0 0 ] - 1.13952e-17
[ 0 1 ] - 1
[ 1 0 ] - 1
[ 1 1 ] - 9.37329e-10

The weights of the neural network can be viewed using the method print_weights():

1) Weights:
-27.697 8.582 -16.824
8.101 -27.766 -15.757

2) Weights:
-7.891 -5.387 6.158
23.374 -7.467 9.219
7.007 14.167 -26.493

3) Weights:
-0.27
-58.941
17.635

simple-neural-network's People

Contributors

rusih100 avatar

Stargazers

 avatar Dasha Petrova avatar Eugenie avatar Heslem avatar

Watchers

 avatar

Forkers

znsoft

simple-neural-network's Issues

Скорее всего утечка пямяти

Я использую твою нейронную сеть в своём проекте, и у меня произошла утечка памяти. Visual Studio указывает на float**, они постоянно создаются, возможно где-то это моя ошибка, но это как задачка для тебя, я буду рад если ты попробуешь исправить это.

EDIT 1: Замечаю что если я не запускаю нейронную сеть утечки нет.
EDIT 2:
for (auto & layer : network_layers) {
temp = layer.run(temp);
}
Утечка происходит здесь.

EDIT 3:

Я отыскал ошибку. Оператор присваивания у матрицы не удалял прошлые данные, из-за этого происходила утечка

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.