TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Public Member Functions | |
NeuralNetwork ()=default | |
NeuralNetwork (const std::vector< std::pair< int, std::string > > &config) | |
NeuralNetwork (const NeuralNetwork &model)=default | |
~NeuralNetwork ()=default | |
NeuralNetwork & | operator= (const NeuralNetwork &model)=default |
NeuralNetwork (NeuralNetwork &&)=default | |
NeuralNetwork & | operator= (NeuralNetwork &&)=default |
std::pair< std::vector< std::vector< std::valarray< double > > >, std::vector< std::vector< std::valarray< double > > > > | get_XY_from_csv (const std::string &file_name, const bool &last_label, const bool &normalize, const int &slip_lines=1) |
std::vector< std::valarray< double > > | single_predict (const std::vector< std::valarray< double > > &X) |
std::vector< std::vector< std::valarray< double > > > | batch_predict (const std::vector< std::vector< std::valarray< double > > > &X) |
void | fit (const std::vector< std::vector< std::valarray< double > > > &X_, const std::vector< std::vector< std::valarray< double > > > &Y_, const int &epochs=100, const double &learning_rate=0.01, const size_t &batch_size=32, const bool &shuffle=true) |
void | fit_from_csv (const std::string &file_name, const bool &last_label, const int &epochs, const double &learning_rate, const bool &normalize, const int &slip_lines=1, const size_t &batch_size=32, const bool &shuffle=true) |
void | evaluate (const std::vector< std::vector< std::valarray< double > > > &X, const std::vector< std::vector< std::valarray< double > > > &Y) |
void | evaluate_from_csv (const std::string &file_name, const bool &last_label, const bool &normalize, const int &slip_lines=1) |
void | save_model (const std::string &_file_name) |
NeuralNetwork | load_model (const std::string &file_name) |
void | summary () |
Private Member Functions | |
NeuralNetwork (const std::vector< std::pair< int, std::string > > &config, const std::vector< std::vector< std::valarray< double > > > &kernels) | |
std::vector< std::vector< std::valarray< double > > > | __detailed_single_prediction (const std::vector< std::valarray< double > > &X) |
Private Attributes | |
std::vector< neural_network::layers::DenseLayer > | layers |
NeuralNetwork class is implements MLP. This class is used by actual user to create and train networks.
Definition at line 247 of file neural_network.cpp.
|
inlineprivate |
Private Constructor for class NeuralNetwork. This constructor is used internally to load model.
config | vector containing pair (neurons, activation) |
kernels | vector containing all pretrained kernels |
Definition at line 256 of file neural_network.cpp.
|
default |
Default Constructor for class NeuralNetwork. This constructor is used to create empty variable of type NeuralNetwork class.
|
inlineexplicit |
Constructor for class NeuralNetwork. This constructor is used by user.
config | vector containing pair (neurons, activation) |
Definition at line 313 of file neural_network.cpp.
|
default |
Copy Constructor for class NeuralNetwork.
model | instance of class to be copied. |
|
default |
Destructor for class NeuralNetwork.
|
default |
Move constructor for class NeuralNetwork
|
inlineprivate |
Private function to get detailed predictions (i.e. activated neuron values). This function is used in backpropagation, single predict and batch predict.
X | input vector |
Definition at line 289 of file neural_network.cpp.
|
inline |
Function to get prediction of model on batch
X | array of feature vectors |
Definition at line 464 of file neural_network.cpp.
|
inline |
Function to evaluate model on supplied data
X | array of feature vectors (input data) |
Y | array of target values (label) |
Definition at line 606 of file neural_network.cpp.
|
inline |
Function to evaluate model on data stored in csv file
file_name | csv file name |
last_label | flag for whether label is in first or last column |
normalize | flag for whether to normalize data |
slip_lines | number of lines to skip |
Definition at line 638 of file neural_network.cpp.
|
inline |
Function to fit model on supplied data
X | array of feature vectors |
Y | array of target values |
epochs | number of epochs (default = 100) |
learning_rate | learning rate (default = 0.01) |
batch_size | batch size for gradient descent (default = 32) |
shuffle | flag for whether to shuffle data (default = true) |
Definition at line 485 of file neural_network.cpp.
|
inline |
Function to fit model on data stored in csv file
file_name | csv file name |
last_label | flag for whether label is in first or last column |
epochs | number of epochs |
learning_rate | learning rate |
normalize | flag for whether to normalize data |
slip_lines | number of lines to skip |
batch_size | batch size for gradient descent (default = 32) |
shuffle | flag for whether to shuffle data (default = true) |
Definition at line 587 of file neural_network.cpp.
|
inline |
Function to get X and Y from csv file (where X = data, Y = label)
file_name | csv file name |
last_label | flag for whether label is in first or last column |
normalize | flag for whether to normalize data |
slip_lines | number of lines to skip |
Definition at line 382 of file neural_network.cpp.
|
inline |
Function to load earlier saved model.
file_name | file from which model will be loaded (*.model) |
Definition at line 732 of file neural_network.cpp.
|
default |
Copy assignment operator for class NeuralNetwork
|
default |
Move assignment operator for class NeuralNetwork
|
inline |
Function to save current model.
file_name | file name to save model (*.model) |
Format in which model is saved:
total_layers neurons(1st neural_network::layers::DenseLayer) activation_name(1st neural_network::layers::DenseLayer) kernel_shape(1st neural_network::layers::DenseLayer) kernel_values neurons(Nth neural_network::layers::DenseLayer) activation_name(Nth neural_network::layers::DenseLayer) kernel_shape(Nth neural_network::layers::DenseLayer) kernel_value
For Example, pretrained model with 3 layers:
3 4 none 4 4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 6 relu 4 6 -1.88963 -3.61165 1.30757 -0.443906 -2.41039 -2.69653 -0.684753 0.0891452 0.795294 -2.39619 2.73377 0.318202 -2.91451 -4.43249 -0.804187 2.51995 -6.97524 -1.07049 -0.571531 -1.81689 -1.24485 1.92264 -2.81322 1.01741 3 sigmoid 6 3 0.390267 -0.391703 -0.0989607 0.499234 -0.564539 -0.28097 0.553386 -0.153974 -1.92493 -2.01336 -0.0219682 1.44145 1.72853 -0.465264 -0.705373 -0.908409 -0.740547 0.376416
Definition at line 652 of file neural_network.cpp.
|
inline |
Function to get prediction of model on single sample.
X | array of feature vectors |
Definition at line 451 of file neural_network.cpp.
|
inline |
Function to print summary of the network.
Definition at line 773 of file neural_network.cpp.
|
private |
Definition at line 249 of file neural_network.cpp.