Neural network creation
The first step in using a neural network is to create it.
As discussed here, a neural network is created by specifying:
- Type of network
- Data input/output
- Network function
An example of a network is shown in IGNORE.
stats++ (header-only)
Creation of a neural network is handled in stats++ though the NeuralNet class, declared in statsxx/machine_learning/NeuralNet.hpp. The create_MLP() subroutine is used for this purpose:
void NeuralNet::create_MLP( int ni, int no, int nl, std::vector<int> nhn, bool fully_connect, bool recurrent, int af_type, bool isClass, const std::vector<double> &w = std::vector<double>() );
Note that the last parameter is optional, defining the weights of the network. If this parameter is undefined, the weights are randomly initialized.
Example code
// STL #include <vector> // std::vector<> // stats++ #include "statsxx/machine_learning/NeuralNet.hpp" // statsxx::data::Preproccessor int main(int argc, char* argv[]) { // type of network bool reccurrent = false; // type of input/output bool is_classif = false; // architecture int ni = 10; int no = 1; int nl = 2; std::vector<int> nhn(nl); nhn[0] = 20; nhn[1] = 5; bool fully_connect = false; int af_type = 0; NeuralNet nn; nn.creat_MLP( ni no, nl, nhn, fully_connect, recurrent, af_type, is_classif ); return 0; }
stats++ (executable)
Creation of a neural network is handled by the [create] block in the input file to the NeuralNet executable.
Example block
The following example defines a non-recurrent, non-classification network with 10 inputs, two layers with 20 and 5 hidden neurons, and one output, with logistic activation functions.
[create] classif = false architecture = 10 architecture = 20 architecture = 5 architecture = 1 af_type = 0
Note that weights are If this parameter is undefined, the weights are randomly initialized.