/SimpleNeuralNetwork

A simple neural network implement in c++

Primary LanguageC++

SimpleNeuralNetwork

This is a C++ implement of simple neural network. It's based on video Neural Net in C++ Tutorial by David Miller.

Test in Ubuntu

1 Gernerate training data to slove XOR problem

    g++ ./makeTrainingSamples.cpp -o makeTrainingSamples
    ./makeTrainingSamples > out.txt

2 Test neural netwrok

    g++ ./neural-net.cpp -o neural-net
    ./neural-net

And you will get the result!

Display results

Let the neural net output its results to a file instead:

    ./neural-net > results.txt

Use python to plot iteration number vs recent average error:

    python3 plot_simulation_results.py

Figure_1

Another usecase: Estimating a surface

Lets say we estimate the surface:

given:

$$ r = \sqrt{x^2 + y^2} $$

then

$$ z = \begin{cases} \frac{\cos(r) + 1}{2} & \text{if } r < \pi \\ 0 & \text{otherwise} \end{cases} $$

Which is basically cylindrically symmetric a cosine-ish function near the origin and flat outside the radius $r&gt;\pi$

cleancosinepiccleanCosCone1

First attempt gave: wrongsurfaceNotrainingset Which was not really that nice.

Although comparing with the training gave quite a good score in terms of error... Lets compare with the training set:

withTrainingSetFaulty

This suggested that the training set was actually wrong! Looking back I found that i used $\frac{\cos(x) + 1}{2}$ instead of $\frac{\cos(r) + 1}{2}$

Correcting the training set gives:

good2

good1