Skip to content
Snippets Groups Projects
Commit 81fdf354 authored by Franck Dary's avatar Franck Dary
Browse files

Added default value for NumericColumnModule

parent 30d8eecd
No related branches found
No related tags found
No related merge requests found
...@@ -13,6 +13,7 @@ class NumericColumnModuleImpl : public Submodule ...@@ -13,6 +13,7 @@ class NumericColumnModuleImpl : public Submodule
private : private :
int outSize; int outSize;
float defaultValue;
std::vector<int> focusedBuffer, focusedStack; std::vector<int> focusedBuffer, focusedStack;
std::shared_ptr<MyModule> myModule{nullptr}; std::shared_ptr<MyModule> myModule{nullptr};
std::string column; std::string column;
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
NumericColumnModuleImpl::NumericColumnModuleImpl(std::string name, const std::string & definition) NumericColumnModuleImpl::NumericColumnModuleImpl(std::string name, const std::string & definition)
{ {
setName(name); setName(name);
std::regex regex("(?:(?:\\s|\\t)*)Column\\{(.*)\\}(?:(?:\\s|\\t)*)Buffer\\{(.*)\\}(?:(?:\\s|\\t)*)Stack\\{(.*)\\}(?:(?:\\s|\\t)*)(\\S+)\\{(.*)\\}(?:(?:\\s|\\t)*)Out\\{(.*)\\}(?:(?:\\s|\\t)*)"); std::regex regex("(?:(?:\\s|\\t)*)Column\\{(.*)\\}(?:(?:\\s|\\t)*)Buffer\\{(.*)\\}(?:(?:\\s|\\t)*)Stack\\{(.*)\\}(?:(?:\\s|\\t)*)(\\S+)\\{(.*)\\}(?:(?:\\s|\\t)*)Out\\{(.*)\\}(?:(?:\\s|\\t)*)DefaultValue\\{(.*)\\}(?:(?:\\s|\\t)*)");
if (!util::doIfNameMatch(regex, definition, [this,&definition](auto sm) if (!util::doIfNameMatch(regex, definition, [this,&definition](auto sm)
{ {
try try
...@@ -28,6 +28,8 @@ NumericColumnModuleImpl::NumericColumnModuleImpl(std::string name, const std::st ...@@ -28,6 +28,8 @@ NumericColumnModuleImpl::NumericColumnModuleImpl(std::string name, const std::st
int outSize = std::stoi(sm.str(6)); int outSize = std::stoi(sm.str(6));
defaultValue = std::stoi(sm.str(7));
if (subModuleType == "LSTM") if (subModuleType == "LSTM")
myModule = register_module("myModule", LSTM(1, outSize, options)); myModule = register_module("myModule", LSTM(1, outSize, options));
else if (subModuleType == "GRU") else if (subModuleType == "GRU")
...@@ -76,7 +78,8 @@ void NumericColumnModuleImpl::addToContext(std::vector<std::vector<long>> & cont ...@@ -76,7 +78,8 @@ void NumericColumnModuleImpl::addToContext(std::vector<std::vector<long>> & cont
{ {
double res = 0.0; double res = 0.0;
if (index >= 0) if (index >= 0)
res = std::stof(config.getAsFeature(column, index).get()); try {res = std::stof(config.getAsFeature(column, index).get());}
catch (std::exception &) {res = defaultValue;}
contextElement.emplace_back(0); contextElement.emplace_back(0);
std::memcpy(&contextElement.back(), &res, sizeof res); std::memcpy(&contextElement.back(), &res, sizeof res);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment