MeLOn
Loading...
Searching...
No Matches
AnnParser.h
Go to the documentation of this file.
1/**********************************************************************************
2* Copyright (c) 2020 Process Systems Engineering (AVT.SVT), RWTH Aachen University
3*
4* This program and the accompanying materials are made available under the
5* terms of the Eclipse Public License 2.0 which is available at
6* http://www.eclipse.org/legal/epl-2.0.
7*
8* SPDX-License-Identifier: EPL-2.0
9*
10* @file AnnParser.h
11*
12* @brief File containing declaration of the ann parser classes.
13*
14**********************************************************************************/
15
16#pragma once
17
18#include <string> // std::string
19#include <vector> // std::vector
20#include <memory> // std::shared_ptr, std::unique_ptr
21
22#include "tinyxml2.h"
23#include "AnnProperties.h"
24#include "modelParser.h"
25
26namespace melon {
27
34 class AnnParser: public ModelParser {
35
36 protected:
44 ACTIVATION_FUNCTION _string_to_activation_function(const std::string& activationFunctionName);
45 public:
46
56 virtual std::shared_ptr<ModelData> parse_model(const std::string modelPath, const std::string modelName) = 0;
57 };
58
65 class AnnParserCsv : public AnnParser {
66
67 const int LAYER_INDICATOR_BASE = 900;
68
76 std::vector<std::vector<std::string>> _csv_to_string_matrix(std::string fileName);
77
85 std::vector<std::vector<double>> _csv_to_double_matrix(std::string fileName);
86
92 void _parse_config_file(AnnStructure& structure);
93
103 void _parse_scalers(std::shared_ptr<ScalerData> inputScalerData, std::shared_ptr<ScalerData> outputScalerData, const AnnStructure& structure);
104
112 void _parse_bias_weights(const AnnStructure& structure, AnnWeights& weights);
113
121 void _parse_layer_weights(const AnnStructure& structure, AnnWeights& weights);
122
130 void _parse_input_weights(const AnnStructure& structure, AnnWeights& weights);
131
132
140 bool _check_if_layer_indicator(int number);
141
142
150 int _get_layer_index_from_indicator(int indicator);
151 public:
161 std::shared_ptr<ModelData> parse_model(const std::string modelPath, const std::string modelName);
162 };
163
170 class AnnParserXml : public AnnParser {
182 tinyxml2::XMLError _parse_vector_int(tinyxml2::XMLElement *parentElement, const std::string vectorName, std::vector<int>& vector);
183
195 tinyxml2::XMLError _parse_vector_double(tinyxml2::XMLElement *parentElement, const std::string vectorName, std::vector<double>& vector);
196 public:
197
207 std::shared_ptr<ModelData> parse_model(const std::string modelPath, const std::string modelName);
208 };
209
210
216 public:
217
225 std::unique_ptr<ModelParser> create_model_parser(const MODEL_FILE_TYPE fileType) override;
226 };
227
228}
This class implements an specialization of the AnnParser for csv files.
Definition AnnParser.h:65
const int LAYER_INDICATOR_BASE
Definition AnnParser.h:67
void _parse_bias_weights(const AnnStructure &structure, AnnWeights &weights)
Parses the bias weights.
Definition AnnParserCSV.cpp:177
bool _check_if_layer_indicator(int number)
Checks if passed number is a layer indicator.
Definition AnnParserCSV.cpp:454
std::vector< std::vector< std::string > > _csv_to_string_matrix(std::string fileName)
Parses the content of an csv file into a string matrix.
Definition AnnParserCSV.cpp:419
int _get_layer_index_from_indicator(int indicator)
Extracts layer index from a layer indicator.
Definition AnnParserCSV.cpp:461
void _parse_scalers(std::shared_ptr< ScalerData > inputScalerData, std::shared_ptr< ScalerData > outputScalerData, const AnnStructure &structure)
Parses the input and output scalers.
Definition AnnParserCSV.cpp:131
void _parse_input_weights(const AnnStructure &structure, AnnWeights &weights)
Parses the input weights.
Definition AnnParserCSV.cpp:239
void _parse_config_file(AnnStructure &structure)
Parses the configuration csv file.
Definition AnnParserCSV.cpp:59
std::shared_ptr< ModelData > parse_model(const std::string modelPath, const std::string modelName)
Parsing function which is used to get the ANN data from a csv file.
Definition AnnParserCSV.cpp:33
void _parse_layer_weights(const AnnStructure &structure, AnnWeights &weights)
Parses the layer weights.
Definition AnnParserCSV.cpp:309
std::vector< std::vector< double > > _csv_to_double_matrix(std::string fileName)
Parses the content of an csv file into a double matrix.
Definition AnnParserCSV.cpp:384
This class is a factory class for creating child instances of AnnParser.
Definition AnnParser.h:215
std::unique_ptr< ModelParser > create_model_parser(const MODEL_FILE_TYPE fileType) override
Factory function for creating a instance of an ann parser corresponding to the specified file type.
Definition AnnParser.cpp:25
This class implements an abstract parent class for ANN file parser.
Definition AnnParser.h:34
ACTIVATION_FUNCTION _string_to_activation_function(const std::string &activationFunctionName)
Turns a string containing the name of an activation function in the correct enum representation.
Definition AnnParser.cpp:41
virtual std::shared_ptr< ModelData > parse_model(const std::string modelPath, const std::string modelName)=0
Abstract function for defining the structure of the parsing function which is used to get the ANN dat...
This class implements an specialization of the AnnParser for xml files.
Definition AnnParser.h:170
tinyxml2::XMLError _parse_vector_int(tinyxml2::XMLElement *parentElement, const std::string vectorName, std::vector< int > &vector)
Parses child elements of an xml element into an vector of int.
Definition AnnParserXML.cpp:363
tinyxml2::XMLError _parse_vector_double(tinyxml2::XMLElement *parentElement, const std::string vectorName, std::vector< double > &vector)
Parses child elements of an xml element into an vector of double.
Definition AnnParserXML.cpp:384
std::shared_ptr< ModelData > parse_model(const std::string modelPath, const std::string modelName)
Parsing function which is used to get the ANN data from a xml file.
Definition AnnParserXML.cpp:26
This class is a abstract parent class for model parser factories implemented in the MeLOn library.
Definition modelParser.h:108
This class is a abstract parent class for model parser implemented in the MeLOn library.
Definition modelParser.h:40
Definition tinyxml2.h:1259
Definition kernel.h:21
MODEL_FILE_TYPE
Enum for representing the parsable filetypes.
Definition modelParser.h:30
ACTIVATION_FUNCTION
Enum for representing the available types of scaler parameters.
Definition AnnProperties.h:30
XMLError
Definition tinyxml2.h:522
struct containing all information regarding the structure of a feedforward neural network
Definition AnnProperties.h:42
struct containing the different weights of a feedforward neural network
Definition AnnProperties.h:59