PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/src/tools/pg-search2/pgparameters.cpp

https://gitlab.com/redgis/PhD-SNN-Simulator
C++ | 188 lines | 121 code | 37 blank | 30 comment | 2 complexity | 4d5025c1a1e1ca17a071a07e29b189b5 MD5 | raw file
  1. /*
  2. NNL - Neuron Network Library - This program is a
  3. spiking neuron network simulator.
  4. Copyright (C) 2006-2017 RĂ©gis Martinez - regis.martinez3@gmail.com
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. extern "C" {
  17. #include "lua.hpp"
  18. }
  19. #include <iostream>
  20. #include <fstream>
  21. #include "pgparameters.hpp"
  22. using namespace std;
  23. /*****************************************************************************/
  24. CPGParameters::CPGParameters ()
  25. {
  26. }
  27. /*****************************************************************************/
  28. CPGParameters::~CPGParameters ()
  29. {
  30. }
  31. /*****************************************************************************/
  32. bool CPGParameters::loadFromLuaFile (string InputSettingFile)
  33. {
  34. cout << "Loading PGs settings \"" << InputSettingFile << "\" ... " << flush;
  35. // Create a lua state
  36. //lua_State * pLua = lua_open ();
  37. lua_State * pLua = luaL_newstate ();
  38. // Reset lua stack
  39. lua_settop (pLua, 0);
  40. int hasError;
  41. //load and run the script
  42. hasError = luaL_dofile(pLua, InputSettingFile.c_str ());
  43. if (hasError)
  44. {
  45. cerr << "-- " << lua_tostring(pLua, -1) << endl;
  46. luaL_error (pLua, "An error occured while loading %s", InputSettingFile.c_str());
  47. exit (hasError);
  48. }
  49. lua_getglobal (pLua, "MAX_MEMORY_USE");
  50. MAX_MEMORY_USE = (int) lua_tonumber (pLua, 1);
  51. lua_pop (pLua,1);
  52. lua_getglobal (pLua, "PG_OUTPUT_DIR");
  53. PG_OUTPUT_DIR = lua_tostring (pLua, 1);
  54. lua_pop (pLua,1);
  55. lua_getglobal (pLua, "MIN_PG_TIME");
  56. MIN_PG_TIME = (NNLtime) lua_tonumber (pLua, 1);
  57. lua_pop (pLua,1);
  58. lua_getglobal (pLua, "MAX_PG_TIME");
  59. MAX_PG_TIME = (NNLtime) lua_tonumber (pLua, 1);
  60. lua_pop (pLua,1);
  61. lua_getglobal (pLua, "MIN_PG_SIZE");
  62. MIN_PG_SIZE = (int) lua_tonumber (pLua, 1);
  63. lua_pop (pLua,1);
  64. lua_getglobal (pLua, "MAX_PG_SIZE");
  65. MAX_PG_SIZE = (int) lua_tonumber (pLua, 1);
  66. lua_pop (pLua,1);
  67. lua_getglobal (pLua, "PG_JITTER");
  68. PG_JITTER = (NNLtime) lua_tonumber (pLua, 1);
  69. lua_pop (pLua,1);
  70. lua_getglobal (pLua, "NB_TRIGGER_NEURONS");
  71. NB_TRIGGER_NEURONS = (int) lua_tonumber (pLua, 1);
  72. lua_pop (pLua,1);
  73. lua_getglobal (pLua, "AVOID_CYCLICS");
  74. AVOID_CYCLICS = (bool) lua_toboolean(pLua, 1);
  75. lua_pop (pLua,1);
  76. lua_getglobal (pLua, "SEARCH_BY_NB_PSP");
  77. SEARCH_BY_NB_PSP = (bool) lua_toboolean (pLua, 1);
  78. lua_pop (pLua,1);
  79. lua_getglobal (pLua, "NB_PSP_TO_SPIKE");
  80. NB_PSP_TO_SPIKE = (int) lua_tonumber (pLua, 1);
  81. lua_pop (pLua,1);
  82. lua_getglobal (pLua, "WEIGHT_THRESHOLD");
  83. WEIGHT_THRESHOLD = (NNLweight) lua_tonumber (pLua, 1);
  84. lua_pop (pLua,1);
  85. lua_getglobal (pLua, "SIZE_DISTRIB_BEAN");
  86. SIZE_DISTRIB_BEAN = (int) lua_tonumber (pLua, 1);
  87. lua_pop (pLua,1);
  88. lua_getglobal (pLua, "TIMESPAN_DISTRIB_BEAN");
  89. TIMESPAN_DISTRIB_BEAN = (NNLtime) lua_tonumber (pLua, 1);
  90. lua_pop (pLua,1);
  91. lua_getglobal (pLua, "SAVE_DETAILED_PGS");
  92. SAVE_DETAILED_PGS = (bool) lua_toboolean (pLua, 1);
  93. lua_pop (pLua,1);
  94. lua_getglobal (pLua, "ONLY_TRIGGERS_IN_SUMMARY");
  95. ONLY_TRIGGERS_IN_SUMMARY = (bool) lua_toboolean (pLua, 1);
  96. lua_pop (pLua,1);
  97. // close lua
  98. lua_close (pLua); //Theoretically, no need to close : automatically done by destructor of lua_State (i.e. pLua) class. But we do it anyway.
  99. cout << "done." << endl << flush;
  100. return true;
  101. }
  102. /*****************************************************************************/
  103. bool CPGParameters::saveToLuaFile (string OutputSettingFile)
  104. {
  105. ofstream * OutputSettingsStream = new ofstream (OutputSettingFile.c_str(), ios::out|ios::trunc);
  106. if (!OutputSettingsStream)
  107. {
  108. cerr << "*** Error opening \"" << OutputSettingFile << "\"."<< endl;
  109. return false;
  110. }
  111. (*OutputSettingsStream) << "MAX_MEMORY_USE = \"" << MAX_MEMORY_USE << "\"" << endl;
  112. (*OutputSettingsStream) << "PG_OUTPUT_DIR = " << PG_OUTPUT_DIR << endl;
  113. (*OutputSettingsStream) << "MIN_PG_TIME = " << MIN_PG_TIME << endl;
  114. (*OutputSettingsStream) << "MAX_PG_TIME = " << MAX_PG_TIME << endl;
  115. (*OutputSettingsStream) << "MIN_PG_SIZE = " << MIN_PG_SIZE << endl;
  116. (*OutputSettingsStream) << "MAX_PG_SIZE = " << MAX_PG_SIZE << endl;
  117. (*OutputSettingsStream) << "PG_JITTER = " << PG_JITTER << endl;
  118. (*OutputSettingsStream) << "NB_TRIGGER_NEURONS = " << NB_TRIGGER_NEURONS << endl;
  119. (*OutputSettingsStream) << "AVOID_CYCLICS = " << AVOID_CYCLICS << endl;
  120. (*OutputSettingsStream) << "SEARCH_BY_NB_PSP = " << SEARCH_BY_NB_PSP << endl;
  121. (*OutputSettingsStream) << "NB_PSP_TO_SPIKE = " << NB_PSP_TO_SPIKE << endl;
  122. (*OutputSettingsStream) << "WEIGHT_THRESHOLD = " << WEIGHT_THRESHOLD << endl;
  123. (*OutputSettingsStream) << "SIZE_DISTRIB_BEAN = " << SIZE_DISTRIB_BEAN << endl;
  124. (*OutputSettingsStream) << "TIMESPAN_DISTRIB_BEAN = " << TIMESPAN_DISTRIB_BEAN << endl;
  125. (*OutputSettingsStream) << "SAVE_DETAILED_PGS = " << SAVE_DETAILED_PGS << endl;
  126. (*OutputSettingsStream) << "ONLY_TRIGGERS_IN_SUMMARY = " << ONLY_TRIGGERS_IN_SUMMARY << endl;
  127. OutputSettingsStream->close ();
  128. return true;
  129. }
  130. int CPGParameters::MAX_MEMORY_USE = 1024*1024*1024; //1Go
  131. string CPGParameters::PG_OUTPUT_DIR = "PGs/";
  132. NNLtime CPGParameters::MAX_PG_TIME = 1500; //150*TIMECALE
  133. NNLtime CPGParameters::MIN_PG_TIME = 100; //10*TIMESCALE
  134. int CPGParameters::MIN_PG_SIZE = 5;
  135. int CPGParameters::MAX_PG_SIZE = 1000;
  136. NNLtime CPGParameters::PG_JITTER = 1; // (0.1*TIMESCALE)
  137. int CPGParameters::NB_TRIGGER_NEURONS = 3;
  138. bool CPGParameters::AVOID_CYCLICS = false;
  139. bool CPGParameters::SEARCH_BY_NB_PSP = false;
  140. int CPGParameters::NB_PSP_TO_SPIKE = 3;
  141. NNLweight CPGParameters::WEIGHT_THRESHOLD = 0;
  142. int CPGParameters::SIZE_DISTRIB_BEAN = 10;
  143. NNLtime CPGParameters::TIMESPAN_DISTRIB_BEAN = 10; //1 * TIMESCALE
  144. bool CPGParameters::SAVE_DETAILED_PGS = true;
  145. bool CPGParameters::ONLY_TRIGGERS_IN_SUMMARY = true;