Skip to content

Latest commit

 

History

History
54 lines (47 loc) · 2.02 KB

README.md

File metadata and controls

54 lines (47 loc) · 2.02 KB

NNCPP

Simple Self-Contained Neural Network toolkit written on C++ (usefull as sample or tutorial)

Example

Create network

// Create NN.Layers
auto IN  = new NN::Layer(28*28, NN::TheNeuronFactory<NN::InputNeuron>()); IN->addNeurons(1,NN::TheNeuronFactory<NN::BiasNeuron>());
auto L1  = new NN::Layer(28*28, NN::TheNeuronFactory<NN::ProcNeuronTrainee>()); L1->addNeurons(1,NN::TheNeuronFactory<NN::BiasNeuron>());
auto OUT = new NN::Layer(10, NN::TheNeuronFactory<NN::ProcNeuronTrainee>()); // Outputs: 0="0", 1="1", 2="2", ...
// Connect layers
L1->addInputAll(IN);
OUT->addInputAll(L1);
// Create NN.Network by NN.Layers
NN::Network NET;
NET.addLayer(IN); NET.addLayer(L1); NET.addLayer(OUT);

Train

// NN::doTrain(NET, DATAS, TARGS) // run training session
//std::vector<std::vector<double>> DATAS = [ [...], ... ]; // source data (each sample holds values for inputs)
//std::vector<std::vector<double>> TARGS = [ [...], ... ]; // expected results (each result holds expected outputs)
cout << "Training, please wait ...";
if (!NN::doTrain(NET, DATAS, TARGS))
{
  cout << "Training failed!";
}
cout << "Training complete";

Run inference

// NN::doProc(NET, DATA) // run single inference calculation
// std::vector<double> DATA Input (must have same count as number of inputs)
// Returns result std::vector<double> (will have same count as number of outputs)
auto CALC = NN::doProc(NET, DATA);

Cousin JavaScript project: NNJS

There is a NN engine implementation on JavaScript with (almost) the same API:

https://github.com/openlab-vn-ua/NNJS

Useful links (and thanks to!)