Removed sferes folder and add a script for fetching sferes

pull/451/head
Anh Nguyen 9 years ago
parent 72372a7808
commit 61cd2e6023
  1. 20
      modules/dnns_easily_fooled/download_sferes.sh
  2. 210
      modules/dnns_easily_fooled/sferes/.cproject
  3. 6
      modules/dnns_easily_fooled/sferes/.gitignore
  4. 33
      modules/dnns_easily_fooled/sferes/.project
  5. 506
      modules/dnns_easily_fooled/sferes/COPYING
  6. 107
      modules/dnns_easily_fooled/sferes/README.md
  7. 55
      modules/dnns_easily_fooled/sferes/build.sh
  8. 3
      modules/dnns_easily_fooled/sferes/contributors.txt
  9. 39
      modules/dnns_easily_fooled/sferes/eigen3.py
  10. 121
      modules/dnns_easily_fooled/sferes/examples/ex_ea.cpp
  11. 11
      modules/dnns_easily_fooled/sferes/examples/ex_ea.json
  12. 93
      modules/dnns_easily_fooled/sferes/examples/ex_ea_mpi.cpp
  13. 91
      modules/dnns_easily_fooled/sferes/examples/ex_eps_moea.cpp
  14. 87
      modules/dnns_easily_fooled/sferes/examples/ex_nsga2.cpp
  15. 8
      modules/dnns_easily_fooled/sferes/examples/qsub.json
  16. 34
      modules/dnns_easily_fooled/sferes/examples/wscript
  17. 88
      modules/dnns_easily_fooled/sferes/exp/example/example.cpp
  18. 10
      modules/dnns_easily_fooled/sferes/exp/example/wscript
  19. 22
      modules/dnns_easily_fooled/sferes/exp/images/build_wscript.sh
  20. 88
      modules/dnns_easily_fooled/sferes/exp/images/continue_run/continue_run.hpp
  21. 120
      modules/dnns_easily_fooled/sferes/exp/images/continue_run/global_options.hpp
  22. 32
      modules/dnns_easily_fooled/sferes/exp/images/dl_images.hpp
  23. 232
      modules/dnns_easily_fooled/sferes/exp/images/dl_map_elites_images.cpp
  24. 197
      modules/dnns_easily_fooled/sferes/exp/images/dl_map_elites_images_imagenet_direct_encoding.cpp
  25. 241
      modules/dnns_easily_fooled/sferes/exp/images/dl_map_elites_images_mnist.cpp
  26. 202
      modules/dnns_easily_fooled/sferes/exp/images/dl_map_elites_images_mnist_direct_encoding.cpp
  27. 237
      modules/dnns_easily_fooled/sferes/exp/images/dl_map_elites_images_test.cpp
  28. 127
      modules/dnns_easily_fooled/sferes/exp/images/ea/ea_custom.hpp
  29. 167
      modules/dnns_easily_fooled/sferes/exp/images/ea/rank_simple.hpp
  30. 238
      modules/dnns_easily_fooled/sferes/exp/images/eval/batch_mpi_parallel.hpp
  31. 238
      modules/dnns_easily_fooled/sferes/exp/images/eval/batch_mpi_tbb_parallel.hpp
  32. 272
      modules/dnns_easily_fooled/sferes/exp/images/eval/cuda_parallel.hpp
  33. 196
      modules/dnns_easily_fooled/sferes/exp/images/eval/mpi_parallel.hpp
  34. 87
      modules/dnns_easily_fooled/sferes/exp/images/eval/tbb_parallel.hpp
  35. 66
      modules/dnns_easily_fooled/sferes/exp/images/eval/tbb_parallel_develop.hpp
  36. 154
      modules/dnns_easily_fooled/sferes/exp/images/eval/tbb_parallel_eval.hpp
  37. 296
      modules/dnns_easily_fooled/sferes/exp/images/fit/fit_deep_learning.hpp
  38. 238
      modules/dnns_easily_fooled/sferes/exp/images/fit/fit_map_deep_learning.hpp
  39. 245
      modules/dnns_easily_fooled/sferes/exp/images/gen/evo_float_image.hpp
  40. BIN
      modules/dnns_easily_fooled/sferes/exp/images/imagenet/hen_256.png
  41. 1
      modules/dnns_easily_fooled/sferes/exp/images/imagenet/image_list.txt
  42. 254
      modules/dnns_easily_fooled/sferes/exp/images/imagenet/imagenet_deploy_image_memory_data.prototxt
  43. 64
      modules/dnns_easily_fooled/sferes/exp/images/phen/cvmat_serialization.h
  44. 265
      modules/dnns_easily_fooled/sferes/exp/images/phen/phen_color_image.hpp
  45. 233
      modules/dnns_easily_fooled/sferes/exp/images/phen/phen_grayscale_image.hpp
  46. 183
      modules/dnns_easily_fooled/sferes/exp/images/phen/phen_grayscale_image_direct.hpp
  47. 119
      modules/dnns_easily_fooled/sferes/exp/images/phen/phen_image.hpp
  48. 210
      modules/dnns_easily_fooled/sferes/exp/images/phen/phen_image_direct.hpp
  49. 17
      modules/dnns_easily_fooled/sferes/exp/images/settings.h
  50. 171
      modules/dnns_easily_fooled/sferes/exp/images/stat/best_fit_image.hpp
  51. 162
      modules/dnns_easily_fooled/sferes/exp/images/stat/best_fit_map_image.hpp
  52. 70
      modules/dnns_easily_fooled/sferes/exp/images/stat/image_stat.hpp
  53. 208
      modules/dnns_easily_fooled/sferes/exp/images/stat/stat_map_image.hpp
  54. 80
      modules/dnns_easily_fooled/sferes/exp/images/util/median.hpp
  55. 14
      modules/dnns_easily_fooled/sferes/exp/images/wscript
  56. 21
      modules/dnns_easily_fooled/sferes/install_caffe.sh
  57. 3
      modules/dnns_easily_fooled/sferes/modules.conf
  58. 0
      modules/dnns_easily_fooled/sferes/modules/.placeholder
  59. 62
      modules/dnns_easily_fooled/sferes/modules/map_elite/fit_map.hpp
  60. 284
      modules/dnns_easily_fooled/sferes/modules/map_elite/map_elite.hpp
  61. 85
      modules/dnns_easily_fooled/sferes/modules/map_elite/plot_map.py
  62. 127
      modules/dnns_easily_fooled/sferes/modules/map_elite/stat_map.hpp
  63. 124
      modules/dnns_easily_fooled/sferes/modules/map_elite/test_map_elite.cpp
  64. 51
      modules/dnns_easily_fooled/sferes/modules/map_elite/wscript
  65. 34
      modules/dnns_easily_fooled/sferes/modules/nn2/README.md
  66. 127
      modules/dnns_easily_fooled/sferes/modules/nn2/af.hpp
  67. 121
      modules/dnns_easily_fooled/sferes/modules/nn2/af_cppn.hpp
  68. 70
      modules/dnns_easily_fooled/sferes/modules/nn2/bench_nn.cpp
  69. 55
      modules/dnns_easily_fooled/sferes/modules/nn2/connection.hpp
  70. 135
      modules/dnns_easily_fooled/sferes/modules/nn2/elman.hpp
  71. 421
      modules/dnns_easily_fooled/sferes/modules/nn2/gen_dnn.hpp
  72. 211
      modules/dnns_easily_fooled/sferes/modules/nn2/gen_dnn_ff.hpp
  73. 83
      modules/dnns_easily_fooled/sferes/modules/nn2/gen_hyper_nn.hpp
  74. 111
      modules/dnns_easily_fooled/sferes/modules/nn2/io_trait.hpp
  75. 100
      modules/dnns_easily_fooled/sferes/modules/nn2/mlp.hpp
  76. 157
      modules/dnns_easily_fooled/sferes/modules/nn2/neuron.hpp
  77. 627
      modules/dnns_easily_fooled/sferes/modules/nn2/nn.hpp
  78. 93
      modules/dnns_easily_fooled/sferes/modules/nn2/params.hpp
  79. 168
      modules/dnns_easily_fooled/sferes/modules/nn2/pf.hpp
  80. 79
      modules/dnns_easily_fooled/sferes/modules/nn2/phen_dnn.hpp
  81. 308
      modules/dnns_easily_fooled/sferes/modules/nn2/phen_hyper_nn.hpp
  82. 219
      modules/dnns_easily_fooled/sferes/modules/nn2/test_dnn.cpp
  83. 145
      modules/dnns_easily_fooled/sferes/modules/nn2/test_dnn_ff.cpp
  84. 240
      modules/dnns_easily_fooled/sferes/modules/nn2/test_hyper_nn.cpp
  85. 263
      modules/dnns_easily_fooled/sferes/modules/nn2/test_hyper_nn_anh.cpp
  86. 62
      modules/dnns_easily_fooled/sferes/modules/nn2/test_mlp.cpp
  87. 138
      modules/dnns_easily_fooled/sferes/modules/nn2/test_nn.cpp
  88. 93
      modules/dnns_easily_fooled/sferes/modules/nn2/test_osc.cpp
  89. 127
      modules/dnns_easily_fooled/sferes/modules/nn2/trait.hpp
  90. 114
      modules/dnns_easily_fooled/sferes/modules/nn2/wscript
  91. 43
      modules/dnns_easily_fooled/sferes/mpi.py
  92. 32
      modules/dnns_easily_fooled/sferes/ode.py
  93. 17
      modules/dnns_easily_fooled/sferes/scripts/add_license.sh
  94. 72
      modules/dnns_easily_fooled/sferes/scripts/error_parser.rb
  95. 34
      modules/dnns_easily_fooled/sferes/scripts/license_cpp.txt
  96. 35
      modules/dnns_easily_fooled/sferes/scripts/license_py.txt
  97. 11
      modules/dnns_easily_fooled/sferes/setup.sh
  98. 390
      modules/dnns_easily_fooled/sferes/sferes.py
  99. 1279
      modules/dnns_easily_fooled/sferes/sferes/dbg/dbg.cpp
  100. 2040
      modules/dnns_easily_fooled/sferes/sferes/dbg/dbg.hpp
  101. Some files were not shown because too many files have changed in this diff Show More

@ -0,0 +1,20 @@
#!/bin/bash
path="./sferes"
if [ -d "${path}" ]; then
echo "Please remove the existing [${path}] folder and re-run this script."
exit 1
fi
# Download the version of Caffe that can be used for generating fooling images via EAs.
echo "Downloading Caffe ..."
wget https://github.com/Evolving-AI-Lab/fooling/archive/master.zip
echo "Extracting into ${path}"
unzip master.zip
mv ./fooling-master/sferes ./
# Clean up
rm -rf fooling-master master.zip
echo "Done."

@ -1,210 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="0.1343441670">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1343441670" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.1343441670" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.1343441670." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.518853527" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.518853527.997723115" name=""/>
<builder autoBuildTarget="build" command="${workspace_loc:/sferes}/waf" enableAutoBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.885439477" incrementalBuildTarget="build" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="false" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.1898543690" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs">
<option id="org.eclipse.cdt.build.core.settings.holder.libpaths.1496481375" name="Library Paths" superClass="org.eclipse.cdt.build.core.settings.holder.libpaths" valueType="libPaths">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/lib"/>
</option>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1966164497" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1498010890" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.2056689194" name="UPC" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1466240126" languageId="org.eclipse.cdt.core.parser.upc.upc" languageName="UPC" sourceContentType="org.eclipse.cdt.core.parser.upc.upcSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1570040244" name="LLVM bytecode assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.224345825" languageId="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssembly" languageName="LLVM bytecode assembly" sourceContentType="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssemblySource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.952010017" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1837838446" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/include"/>
<listOptionValue builtIn="false" value="/usr/include"/>
<listOptionValue builtIn="false" value="/usr/local/include"/>
<listOptionValue builtIn="false" value="/usr/include/x86_64-linux-gnu"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include-fixed"/>
<listOptionValue builtIn="false" value="/usr/include/c++/4.6.3"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.440284380" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.2013027633" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1006456833" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="0.1343441670.1092562839">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1343441670.1092562839" moduleId="org.eclipse.cdt.core.settings" name="Test">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="Test experiment" id="0.1343441670.1092562839" name="Test" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.1343441670.1092562839." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.255415555" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.255415555.2019559593" name=""/>
<builder arguments="--exp" autoBuildTarget="test" command="${workspace_loc:/sferes}/waf" enableAutoBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.1037270282" incrementalBuildTarget="test" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="false" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.975546489" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs">
<option id="org.eclipse.cdt.build.core.settings.holder.libpaths.294179390" name="Library Paths" superClass="org.eclipse.cdt.build.core.settings.holder.libpaths" valueType="libPaths">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/lib"/>
</option>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1156952792" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.226262325" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1542316641" name="UPC" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1020628569" languageId="org.eclipse.cdt.core.parser.upc.upc" languageName="UPC" sourceContentType="org.eclipse.cdt.core.parser.upc.upcSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1001828621" name="LLVM bytecode assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.858615463" languageId="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssembly" languageName="LLVM bytecode assembly" sourceContentType="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssemblySource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.869820616" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1798516912" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/include"/>
<listOptionValue builtIn="false" value="/usr/include"/>
<listOptionValue builtIn="false" value="/usr/local/include"/>
<listOptionValue builtIn="false" value="/usr/include/x86_64-linux-gnu"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include-fixed"/>
<listOptionValue builtIn="false" value="/usr/include/c++/4.6.3"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1149097019" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.581158442" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1214336311" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="0.1343441670.1092562839.1549678658">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1343441670.1092562839.1549678658" moduleId="org.eclipse.cdt.core.settings" name="Images">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" description="Experiment evolving images" id="0.1343441670.1092562839.1549678658" name="Images" parent="org.eclipse.cdt.build.core.prefbase.cfg">
<folderInfo id="0.1343441670.1092562839.1549678658." name="/" resourcePath="">
<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1638023515" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1638023515.1487774424" name=""/>
<builder arguments="-j4 --exp" autoBuildTarget="images" command="${workspace_loc:/sferes}/waf" enableAutoBuild="true" enabledIncrementalBuild="true" id="org.eclipse.cdt.build.core.settings.default.builder.134993261" incrementalBuildTarget="images" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" parallelBuildOn="false" superClass="org.eclipse.cdt.build.core.settings.default.builder">
<outputEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="outputPath" name=""/>
</outputEntries>
</builder>
<tool id="org.eclipse.cdt.build.core.settings.holder.libs.823583310" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs">
<option id="org.eclipse.cdt.build.core.settings.holder.libpaths.644207186" name="Library Paths" superClass="org.eclipse.cdt.build.core.settings.holder.libpaths" valueType="libPaths">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/lib"/>
</option>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.182239317" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1585610966" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.975510256" name="UPC" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1105125374" languageId="org.eclipse.cdt.core.parser.upc.upc" languageName="UPC" sourceContentType="org.eclipse.cdt.core.parser.upc.upcSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.1324142077" name="LLVM bytecode assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.617461107" languageId="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssembly" languageName="LLVM bytecode assembly" sourceContentType="org.eclipse.cdt.managedbuilder.llvm.ui.llvmAssemblySource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.345303749" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1439046553" name="Include Paths" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
<listOptionValue builtIn="false" value="/home/anh/src/sferes/include"/>
<listOptionValue builtIn="false" value="/usr/include"/>
<listOptionValue builtIn="false" value="/usr/local/include"/>
<listOptionValue builtIn="false" value="/usr/include/x86_64-linux-gnu"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include"/>
<listOptionValue builtIn="false" value="/usr/lib/gcc/x86_64-linux-gnu/4.6.3/include-fixed"/>
<listOptionValue builtIn="false" value="/usr/include/c++/4.6.3"/>
</option>
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.820226213" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
<tool id="org.eclipse.cdt.build.core.settings.holder.393533101" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.139990286" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="sferes.null.743032128" name="sferes"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
<storageModule moduleId="refreshScope" versionNumber="2">
<configuration configurationName="Default">
<resource resourceType="PROJECT" workspacePath="/sferes"/>
</configuration>
<configuration configurationName="Test"/>
<configuration configurationName="Example">
<resource resourceType="PROJECT" workspacePath="/sferes"/>
</configuration>
<configuration configurationName="RankSimple">
<resource resourceType="PROJECT" workspacePath="/sferes"/>
</configuration>
<configuration configurationName="Images"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="0.1343441670">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1343441670.1092562839.1549678658">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="0.1343441670.1092562839">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets">
<buildTargets>
<target name="configure" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>/home/anh/workspace/sferes/waf</buildCommand>
<buildArguments/>
<buildTarget>configure --boost-include=/home/anh/src/sferes/include --boost-lib=/home/anh/src/sferes/lib --eigen3=/home/anh/src/sferes/include --mpi=/home/anh/openmpi</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>

@ -1,6 +0,0 @@
*.pyc
build/
.waf-1.5.14*/
.Totti-*/
Totti-*/
.lock-wscript

@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>sferes</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>src</name>
<type>2</type>
<location>/home/anh/src/caffe/src</location>
</link>
</linkedResources>
</projectDescription>

@ -1,506 +0,0 @@
CeCILL FREE SOFTWARE LICENSE AGREEMENT
Notice
This Agreement is a Free Software license agreement that is the result
of discussions between its authors in order to ensure compliance with
the two main principles guiding its drafting:
* firstly, compliance with the principles governing the distribution
of Free Software: access to source code, broad rights granted to
users,
* secondly, the election of a governing law, French law, with which
it is conformant, both as regards the law of torts and
intellectual property law, and the protection that it offers to
both authors and holders of the economic rights over software.
The authors of the CeCILL (for Ce[a] C[nrs] I[nria] L[ogiciel] L[ibre])
license are:
Commissariat à l'Energie Atomique - CEA, a public scientific, technical
and industrial research establishment, having its principal place of
business at 25 rue Leblanc, immeuble Le Ponant D, 75015 Paris, France.
Centre National de la Recherche Scientifique - CNRS, a public scientific
and technological establishment, having its principal place of business
at 3 rue Michel-Ange, 75794 Paris cedex 16, France.
Institut National de Recherche en Informatique et en Automatique -
INRIA, a public scientific and technological establishment, having its
principal place of business at Domaine de Voluceau, Rocquencourt, BP
105, 78153 Le Chesnay cedex, France.
Preamble
The purpose of this Free Software license agreement is to grant users
the right to modify and redistribute the software governed by this
license within the framework of an open source distribution model.
The exercising of these rights is conditional upon certain obligations
for users so as to preserve this status for all subsequent redistributions.
In consideration of access to the source code and the rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors only have limited liability.
In this respect, the risks associated with loading, using, modifying
and/or developing or reproducing the software by the user are brought to
the user's attention, given its Free Software status, which may make it
complicated to use, with the result that its use is reserved for
developers and experienced professionals having in-depth computer
knowledge. Users are therefore encouraged to load and test the
suitability of the software as regards their requirements in conditions
enabling the security of their systems and/or data to be ensured and,
more generally, to use and operate it in the same conditions of
security. This Agreement may be freely reproduced and published,
provided it is not altered, and that no provisions are either added or
removed herefrom.
This Agreement may apply to any or all software for which the holder of
the economic rights decides to submit the use thereof to its provisions.
Article 1 - DEFINITIONS
For the purpose of this Agreement, when the following expressions
commence with a capital letter, they shall have the following meaning:
Agreement: means this license agreement, and its possible subsequent
versions and annexes.
Software: means the software in its Object Code and/or Source Code form
and, where applicable, its documentation, "as is" when the Licensee
accepts the Agreement.
Initial Software: means the Software in its Source Code and possibly its
Object Code form and, where applicable, its documentation, "as is" when
it is first distributed under the terms and conditions of the Agreement.
Modified Software: means the Software modified by at least one
Contribution.
Source Code: means all the Software's instructions and program lines to
which access is required so as to modify the Software.
Object Code: means the binary files originating from the compilation of
the Source Code.
Holder: means the holder(s) of the economic rights over the Initial
Software.
Licensee: means the Software user(s) having accepted the Agreement.
Contributor: means a Licensee having made at least one Contribution.
Licensor: means the Holder, or any other individual or legal entity, who
distributes the Software under the Agreement.
Contribution: means any or all modifications, corrections, translations,
adaptations and/or new functions integrated into the Software by any or
all Contributors, as well as any or all Internal Modules.
Module: means a set of sources files including their documentation that
enables supplementary functions or services in addition to those offered
by the Software.
External Module: means any or all Modules, not derived from the
Software, so that this Module and the Software run in separate address
spaces, with one calling the other when they are run.
Internal Module: means any or all Module, connected to the Software so
that they both execute in the same address space.
GNU GPL: means the GNU General Public License version 2 or any
subsequent version, as published by the Free Software Foundation Inc.
Parties: mean both the Licensee and the Licensor.
These expressions may be used both in singular and plural form.
Article 2 - PURPOSE
The purpose of the Agreement is the grant by the Licensor to the
Licensee of a non-exclusive, transferable and worldwide license for the
Software as set forth in Article 5 hereinafter for the whole term of the
protection granted by the rights over said Software.
Article 3 - ACCEPTANCE
3.1 The Licensee shall be deemed as having accepted the terms and
conditions of this Agreement upon the occurrence of the first of the
following events:
* (i) loading the Software by any or all means, notably, by
downloading from a remote server, or by loading from a physical
medium;
* (ii) the first time the Licensee exercises any of the rights
granted hereunder.
3.2 One copy of the Agreement, containing a notice relating to the
characteristics of the Software, to the limited warranty, and to the
fact that its use is restricted to experienced users has been provided
to the Licensee prior to its acceptance as set forth in Article 3.1
hereinabove, and the Licensee hereby acknowledges that it has read and
understood it.
Article 4 - EFFECTIVE DATE AND TERM
4.1 EFFECTIVE DATE
The Agreement shall become effective on the date when it is accepted by
the Licensee as set forth in Article 3.1.
4.2 TERM
The Agreement shall remain in force for the entire legal term of
protection of the economic rights over the Software.
Article 5 - SCOPE OF RIGHTS GRANTED
The Licensor hereby grants to the Licensee, who accepts, the following
rights over the Software for any or all use, and for the term of the
Agreement, on the basis of the terms and conditions set forth hereinafter.
Besides, if the Licensor owns or comes to own one or more patents
protecting all or part of the functions of the Software or of its
components, the Licensor undertakes not to enforce the rights granted by
these patents against successive Licensees using, exploiting or
modifying the Software. If these patents are transferred, the Licensor
undertakes to have the transferees subscribe to the obligations set
forth in this paragraph.
5.1 RIGHT OF USE
The Licensee is authorized to use the Software, without any limitation
as to its fields of application, with it being hereinafter specified
that this comprises:
1. permanent or temporary reproduction of all or part of the Software
by any or all means and in any or all form.
2. loading, displaying, running, or storing the Software on any or
all medium.
3. entitlement to observe, study or test its operation so as to
determine the ideas and principles behind any or all constituent
elements of said Software. This shall apply when the Licensee
carries out any or all loading, displaying, running, transmission
or storage operation as regards the Software, that it is entitled
to carry out hereunder.
5.2 ENTITLEMENT TO MAKE CONTRIBUTIONS
The right to make Contributions includes the right to translate, adapt,
arrange, or make any or all modifications to the Software, and the right
to reproduce the resulting software.
The Licensee is authorized to make any or all Contributions to the
Software provided that it includes an explicit notice that it is the
author of said Contribution and indicates the date of the creation thereof.
5.3 RIGHT OF DISTRIBUTION
In particular, the right of distribution includes the right to publish,
transmit and communicate the Software to the general public on any or
all medium, and by any or all means, and the right to market, either in
consideration of a fee, or free of charge, one or more copies of the
Software by any means.
The Licensee is further authorized to distribute copies of the modified
or unmodified Software to third parties according to the terms and
conditions set forth hereinafter.
5.3.1 DISTRIBUTION OF SOFTWARE WITHOUT MODIFICATION
The Licensee is authorized to distribute true copies of the Software in
Source Code or Object Code form, provided that said distribution
complies with all the provisions of the Agreement and is accompanied by:
1. a copy of the Agreement,
2. a notice relating to the limitation of both the Licensor's
warranty and liability as set forth in Articles 8 and 9,
and that, in the event that only the Object Code of the Software is
redistributed, the Licensee allows future Licensees unhindered access to
the full Source Code of the Software by indicating how to access it, it
being understood that the additional cost of acquiring the Source Code
shall not exceed the cost of transferring the data.
5.3.2 DISTRIBUTION OF MODIFIED SOFTWARE
When the Licensee makes a Contribution to the Software, the terms and
conditions for the distribution of the resulting Modified Software
become subject to all the provisions of this Agreement.
The Licensee is authorized to distribute the Modified Software, in
source code or object code form, provided that said distribution
complies with all the provisions of the Agreement and is accompanied by:
1. a copy of the Agreement,
2. a notice relating to the limitation of both the Licensor's
warranty and liability as set forth in Articles 8 and 9,
and that, in the event that only the object code of the Modified
Software is redistributed, the Licensee allows future Licensees
unhindered access to the full source code of the Modified Software by
indicating how to access it, it being understood that the additional
cost of acquiring the source code shall not exceed the cost of
transferring the data.
5.3.3 DISTRIBUTION OF EXTERNAL MODULES
When the Licensee has developed an External Module, the terms and
conditions of this Agreement do not apply to said External Module, that
may be distributed under a separate license agreement.
5.3.4 COMPATIBILITY WITH THE GNU GPL
The Licensee can include a code that is subject to the provisions of one
of the versions of the GNU GPL in the Modified or unmodified Software,
and distribute that entire code under the terms of the same version of
the GNU GPL.
The Licensee can include the Modified or unmodified Software in a code
that is subject to the provisions of one of the versions of the GNU GPL,
and distribute that entire code under the terms of the same version of
the GNU GPL.
Article 6 - INTELLECTUAL PROPERTY
6.1 OVER THE INITIAL SOFTWARE
The Holder owns the economic rights over the Initial Software. Any or
all use of the Initial Software is subject to compliance with the terms
and conditions under which the Holder has elected to distribute its work
and no one shall be entitled to modify the terms and conditions for the
distribution of said Initial Software.
The Holder undertakes that the Initial Software will remain ruled at
least by this Agreement, for the duration set forth in Article 4.2.
6.2 OVER THE CONTRIBUTIONS
The Licensee who develops a Contribution is the owner of the
intellectual property rights over this Contribution as defined by
applicable law.
6.3 OVER THE EXTERNAL MODULES
The Licensee who develops an External Module is the owner of the
intellectual property rights over this External Module as defined by
applicable law and is free to choose the type of agreement that shall
govern its distribution.
6.4 JOINT PROVISIONS
The Licensee expressly undertakes:
1. not to remove, or modify, in any manner, the intellectual property
notices attached to the Software;
2. to reproduce said notices, in an identical manner, in the copies
of the Software modified or not.
The Licensee undertakes not to directly or indirectly infringe the
intellectual property rights of the Holder and/or Contributors on the
Software and to take, where applicable, vis-à-vis its staff, any and all
measures required to ensure respect of said intellectual property rights
of the Holder and/or Contributors.
Article 7 - RELATED SERVICES
7.1 Under no circumstances shall the Agreement oblige the Licensor to
provide technical assistance or maintenance services for the Software.
However, the Licensor is entitled to offer this type of services. The
terms and conditions of such technical assistance, and/or such
maintenance, shall be set forth in a separate instrument. Only the
Licensor offering said maintenance and/or technical assistance services
shall incur liability therefor.
7.2 Similarly, any Licensor is entitled to offer to its licensees, under
its sole responsibility, a warranty, that shall only be binding upon
itself, for the redistribution of the Software and/or the Modified
Software, under terms and conditions that it is free to decide. Said
warranty, and the financial terms and conditions of its application,
shall be subject of a separate instrument executed between the Licensor
and the Licensee.
Article 8 - LIABILITY
8.1 Subject to the provisions of Article 8.2, the Licensee shall be
entitled to claim compensation for any direct loss it may have suffered
from the Software as a result of a fault on the part of the relevant
Licensor, subject to providing evidence thereof.
8.2 The Licensor's liability is limited to the commitments made under
this Agreement and shall not be incurred as a result of in particular:
(i) loss due the Licensee's total or partial failure to fulfill its
obligations, (ii) direct or consequential loss that is suffered by the
Licensee due to the use or performance of the Software, and (iii) more
generally, any consequential loss. In particular the Parties expressly
agree that any or all pecuniary or business loss (i.e. loss of data,
loss of profits, operating loss, loss of customers or orders,
opportunity cost, any disturbance to business activities) or any or all
legal proceedings instituted against the Licensee by a third party,
shall constitute consequential loss and shall not provide entitlement to
any or all compensation from the Licensor.
Article 9 - WARRANTY
9.1 The Licensee acknowledges that the scientific and technical
state-of-the-art when the Software was distributed did not enable all
possible uses to be tested and verified, nor for the presence of
possible defects to be detected. In this respect, the Licensee's
attention has been drawn to the risks associated with loading, using,
modifying and/or developing and reproducing the Software which are
reserved for experienced users.
The Licensee shall be responsible for verifying, by any or all means,
the suitability of the product for its requirements, its good working
order, and for ensuring that it shall not cause damage to either persons
or properties.
9.2 The Licensor hereby represents, in good faith, that it is entitled
to grant all the rights over the Software (including in particular the
rights set forth in Article 5).
9.3 The Licensee acknowledges that the Software is supplied "as is" by
the Licensor without any other express or tacit warranty, other than
that provided for in Article 9.2 and, in particular, without any warranty
as to its commercial value, its secured, safe, innovative or relevant
nature.
Specifically, the Licensor does not warrant that the Software is free
from any error, that it will operate without interruption, that it will
be compatible with the Licensee's own equipment and software
configuration, nor that it will meet the Licensee's requirements.
9.4 The Licensor does not either expressly or tacitly warrant that the
Software does not infringe any third party intellectual property right
relating to a patent, software or any other property right. Therefore,
the Licensor disclaims any and all liability towards the Licensee
arising out of any or all proceedings for infringement that may be
instituted in respect of the use, modification and redistribution of the
Software. Nevertheless, should such proceedings be instituted against
the Licensee, the Licensor shall provide it with technical and legal
assistance for its defense. Such technical and legal assistance shall be
decided on a case-by-case basis between the relevant Licensor and the
Licensee pursuant to a memorandum of understanding. The Licensor
disclaims any and all liability as regards the Licensee's use of the
name of the Software. No warranty is given as regards the existence of
prior rights over the name of the Software or as regards the existence
of a trademark.
Article 10 - TERMINATION
10.1 In the event of a breach by the Licensee of its obligations
hereunder, the Licensor may automatically terminate this Agreement
thirty (30) days after notice has been sent to the Licensee and has
remained ineffective.
10.2 A Licensee whose Agreement is terminated shall no longer be
authorized to use, modify or distribute the Software. However, any
licenses that it may have granted prior to termination of the Agreement
shall remain valid subject to their having been granted in compliance
with the terms and conditions hereof.
Article 11 - MISCELLANEOUS
11.1 EXCUSABLE EVENTS
Neither Party shall be liable for any or all delay, or failure to
perform the Agreement, that may be attributable to an event of force
majeure, an act of God or an outside cause, such as defective
functioning or interruptions of the electricity or telecommunications
networks, network paralysis following a virus attack, intervention by
government authorities, natural disasters, water damage, earthquakes,
fire, explosions, strikes and labor unrest, war, etc.
11.2 Any failure by either Party, on one or more occasions, to invoke
one or more of the provisions hereof, shall under no circumstances be
interpreted as being a waiver by the interested Party of its right to
invoke said provision(s) subsequently.
11.3 The Agreement cancels and replaces any or all previous agreements,
whether written or oral, between the Parties and having the same
purpose, and constitutes the entirety of the agreement between said
Parties concerning said purpose. No supplement or modification to the
terms and conditions hereof shall be effective as between the Parties
unless it is made in writing and signed by their duly authorized
representatives.
11.4 In the event that one or more of the provisions hereof were to
conflict with a current or future applicable act or legislative text,
said act or legislative text shall prevail, and the Parties shall make
the necessary amendments so as to comply with said act or legislative
text. All other provisions shall remain effective. Similarly, invalidity
of a provision of the Agreement, for any reason whatsoever, shall not
cause the Agreement as a whole to be invalid.
11.5 LANGUAGE
The Agreement is drafted in both French and English and both versions
are deemed authentic.
Article 12 - NEW VERSIONS OF THE AGREEMENT
12.1 Any person is authorized to duplicate and distribute copies of this
Agreement.
12.2 So as to ensure coherence, the wording of this Agreement is
protected and may only be modified by the authors of the License, who
reserve the right to periodically publish updates or new versions of the
Agreement, each with a separate number. These subsequent versions may
address new issues encountered by Free Software.
12.3 Any Software distributed under a given version of the Agreement may
only be subsequently distributed under the same version of the Agreement
or a subsequent version, subject to the provisions of Article 5.3.4.
Article 13 - GOVERNING LAW AND JURISDICTION
13.1 The Agreement is governed by French law. The Parties agree to
endeavor to seek an amicable solution to any disagreements or disputes
that may arise during the performance of the Agreement.
13.2 Failing an amicable solution within two (2) months as from their
occurrence, and unless emergency proceedings are necessary, the
disagreements or disputes shall be referred to the Paris Courts having
jurisdiction, by the more diligent Party.
Version 2.0 dated 2006-09-05.

@ -1,107 +0,0 @@
You can access this repo with SSH or with HTTPS.
sferes2
=======
Sferes2 is a high-performance, lightweight, generic C++ framework for evolutionary computation.
**If you use this software in an academic article, please cite:**
Mouret, J.-B. and Doncieux, S. (2010). SFERESv2: Evolvin' in the Multi-Core World. _Proc. of Congress on Evolutionary Computation (CEC)_ Pages 4079--4086.
The article is available here: http://www.isir.upmc.fr/files/2010ACTI1524.pdf
@INPROCEEDINGS{Mouret2010,
AUTHOR = {Mouret, J.-B. and Doncieux, S.},
TITLE = {{SFERES}v2: Evolvin' in the Multi-Core World},
YEAR = {2010},
BOOKTITLE = {Proc. of Congress on Evolutionary Computation (CEC)},
PAGES = {4079--4086}
}
Documentation (including instruction for compilation)
-------------
We are in the process of porting the documentation to the github wiki: https://github.com/jbmouret/sferes2/wiki
Optional modules
---------------
- evolvable neural networks: https://github.com/jbmouret/nn2
- khepera-like simulator: https://github.com/jbmouret/fastsim
Design
-----
The following choices were made in the initial design:
- use of modern c++ techniques (template-based programming) to employ object-oriented programming without the cost of virtual functions;
- use of Intel TBB to take full advantages of multicore and SMP systems;
- use of boost libraries when it's useful (shared_ptr, serialization, filesystem, test,...);
- use of MPI to distribute the computational cost on clusters;
- a full set of unit tests;
- no configuration file: a fully optimized executable is built for each particular experiment.
Sferes2 is extended via modules and experiments.
Sferes2 work on most Unix systems (in particular, GNU/Linux and OSX). It successfully compiles with gcc, clang and icc.
Authors
-------
- Jean-Baptiste Mouret mouret@isir.upmc.frfr: main author and maintainer
- Stephane Doncieux doncieux@isir.upmc.fr
- Paul Tonellitonelli@isir.upmc.fr (documentation)
- Many members of ISIR (http://isir.upmc.fr)
Academic papers that used Sferes2:
-----------------------------------
*If you used Sferes2 in an academic paper, please send us an e-mail (mouret@isir.upmc.fr) so that we can add it here!*
(you can find a pdf for most of these publications on http://scholar.google.com).
### 2014
- Lesaint, F., Sigaud, O., Clark, J. J., Flagel, S. B., & Khamassi, M. (2014). Experimental predictions drawn from a computational model of sign-trackers and goal-trackers. Journal of Physiology-Paris.
- Lesaint, F., Sigaud, O., Flagel, S. B., Robinson, T. E., & Khamassi, M. (2014). Modelling Individual Differences in the Form of Pavlovian Conditioned Approach Responses: A Dual Learning Systems Approach with Factored Representations. PLoS computational biology, 10(2), e1003466.
- Shrouf, F., Ordieres-Meré, J., García-Sánchez, A., & Ortega-Mier, M. (2014). Optimizing the production scheduling of a single machine to minimize total energy consumption costs. Journal of Cleaner Production, 67, 197-207.
- Huizinga, J., Mouret, J. B., & Clune, J. (2014). Evolving Neural Networks That Are Both Modular and Regular: HyperNeat Plus the Connection Cost Technique. In Proceedings of GECCO (pp. 1-8).
- Li, J., Storie, J., & Clune, J. (2014). Encouraging Creative Thinking in Robots Improves Their Ability to Solve Challenging Problems. Proceedings of GECCO (pp 1-8)
- Tarapore, D. and Mouret, J.-B. (2014). Comparing the evolvability of generative encoding schemes.
Artificial Life 14: Proceedings of the Fourteenth International Conference on the Synthesis and Simulation of Living Systems, MIT Press, publisher. Pages 1-8.
### 2013
- Koos, S. and Cully, A. and Mouret, J.-B. (2013). Fast Damage Recovery in Robotics with the T-Resilience Algorithm. International Journal of Robotics Research. Vol 32 No 14 Pages 1700-1723.
- Tonelli, P. and Mouret, J.-B. (2013). On the Relationships between Generative Encodings, Regularity, and Learning Abilities when Evolving Plastic Artificial Neural Networks. PLoS One. Vol 8 No 11 Pages e79138
- Clune*, J. and Mouret, J.-B. and Lipson, H. (2013). The evolutionary origins of modularity. Proceedings of the Royal Society B. Vol 280 (J. Clune and J.-B. Mouret contributed equally to this work) Pages 20122863
- Koos, S. and Mouret, J.-B. and Doncieux, S. (2013). The Transferability Approach: Crossing the Reality Gap in Evolutionary Robotics. IEEE Transactions on Evolutionary Computation. Vol 17 No 1 Pages 122 - 145
- Doncieux, S. and Mouret, J.B. (2013). Behavioral Diversity with Multiple Behavioral Distances. Proc. of IEEE Congress on Evolutionary Computation, 2013 (CEC 2013). Pages 1-8
- Cully, A. and Mouret, J.-B. (2013). Behavioral Repertoire Learning in Robotics. Genetic and Evolutionary Computation Conference (GECCO). Pages 175-182.
- Doncieux, S. (2013). Transfer Learning for Direct Policy Search: A Reward Shaping Approach. Proceedings of ICDL-EpiRob conference. Pages 1-6.
### 2012
- Mouret, J.-B. and Doncieux, S. (2012). Encouraging Behavioral Diversity in Evolutionary Robotics: an Empirical Study. Evolutionary Computation. Vol 20 No 1 Pages 91-133.
- Ollion, Charles and Doncieux, Stéphane (2012). Towards Behavioral Consistency in Neuroevolution. From Animals to Animats: Proceedings of the 12th International Conference on Adaptive Behaviour (SAB 2012), Springer, publisher. Pages 1-10.
- Ollion, C. and Pinville, T. and Doncieux, S. (2012). With a little help from selection pressures: evolution of memory in robot controllers. Proc. Alife XIII. Pages 1-8.
### 2011
- Rubrecht, S. and Singla, E. and Padois, V. and Bidaud, P. and de Broissia, M. (2011). Evolutionary design of a robotic manipulator for a highly constrained environment. Studies in Computational Intelligence, New Horizons in Evolutionary Robotics, Springer, publisher. Vol 341 Pages 109-121.
- Doncieux, S. and Hamdaoui, M. (2011). Evolutionary Algorithms to Analyse and Design a Controller for a Flapping Wings Aircraft. New Horizons in Evolutionary Robotics Extended Contributions from the 2009 EvoDeRob Workshop, Springer, publisher. Pages 67--83.
- Mouret, J.-B. (2011). Novelty-based Multiobjectivization. New Horizons in Evolutionary Robotics: Extended Contributions from the 2009 EvoDeRob Workshop, Springer, publisher. Pages 139--154.
- Pinville, T. and Koos, S. and Mouret, J-B. and Doncieux, S. (2011). How to Promote Generalisation in Evolutionary Robotics: the ProGAb Approach. GECCO'11: Proceedings of the 13th annual conference on Genetic and evolutionary computation ACM, publisher . Pages 259--266.
- Koos, S. and Mouret, J-B. (2011). Online Discovery of Locomotion Modes for Wheel-Legged Hybrid Robots: a Transferability-based Approach. Proceedings of CLAWAR, World Scientific Publishing Co., publisher. Pages 70-77.
- Tonelli, P. and Mouret, J.-B. (2011). On the Relationships between Synaptic Plasticity and Generative Systems. Proceedings of the 13th Annual Conference on Genetic and Evolutionary Computation. Pages 1531--1538. (Best paper of the Generative and Developmental Systems (GDS) track).
- Terekhov, A.V. and Mouret, J.-B. and Grand, C. (2011). Stochastic optimization of a chain sliding mode controller for the mobile robot maneuvering. Proceedings of IEEE / IROS Int. Conf. on Robots and Intelligents Systems. Pages 4360 - 4365
### 2010
- Mouret, J.-B. and Doncieux, S. and Girard, B. (2010). Importing the Computational Neuroscience Toolbox into Neuro-Evolution---Application to Basal Ganglia. GECCO'10: Proceedings of the 12th annual conference on Genetic and evolutionary computation ACM, publisher . Pages 587--594.
- Koos, S. and Mouret, J.-B. and Doncieux, S. (2010). Crossing the Reality Gap in Evolutionary Robotics by Promoting Transferable Controllers. GECCO'10: Proceedings of the 12th annual conference on Genetic and evolutionary computation ACM, publisher . Pages 119--126.
- Doncieux, S. and Mouret, J.-B. (2010). Behavioral diversity measures for Evolutionary Robotics. WCCI 2010 IEEE World Congress on Computational Intelligence, Congress on Evolutionary Computation (CEC). Pages 1303--1310.
- Terekhov, A.V. and Mouret, J.-B. and Grand, C. (2010). Stochastic optimization of a neural network-based controller for aggressive maneuvers on loose surfaces. Proceedings of IEEE / IROS Int. Conf. on Robots and Intelligents Systems. Pages 4782 - 4787
- Terekhov, A.V and Mouret, J.-B. and Grand, C (2010). Stochastic multi-objective optimization for aggressive maneuver trajectory planning on loose surface.
Proceedings of IFAC: the 7th Symposium on Intelligent Autonomous Vehicles. Pages 1-6
- Liénard, J. and Guillot, A. and Girard, B. (2010). Multi-Objective Evolutionary Algorithms to Investigate Neurocomputational Issues : The Case Study of Basal Ganglia Models. From animals to animats 11, Springer, publisher. Vol 6226 Pages 597--606
### 2009
- Koos, S. and Mouret, J.-B. and Doncieux, S. (2009). Automatic system identification based on coevolution of models and tests. IEEE Congress on Evolutionary Computation, 2009 (CEC 2009). Pages 560--567
- Mouret, J.-B. and Doncieux, S. (2009). Evolving modular neural-networks through exaptation. IEEE Congress on Evolutionary Computation, 2009 (CEC 2009). Pages 1570--1577. (Best student paper award)
- Mouret, J.-B. and Doncieux, S. (2009). Overcoming the bootstrap problem in evolutionary robotics using behavioral diversity. IEEE Congress on Evolutionary Computation, 2009 (CEC 2009). Pages 1161 - 1168
- Mouret, J.-B. and Doncieux, S. (2009). Using Behavioral Exploration Objectives to Solve Deceptive Problems in Neuro-evolution. GECCO'09: Proceedings of the 11th annual conference on Genetic and evolutionary computation , ACM, publisher. Pages 627--634.

@ -1,55 +0,0 @@
#!/bin/bash
home=$(echo ~)
quit=0
# Remove the build folder
rm -rf ./build
echo "Build folder removed."
# Check the building folder, either on local or Moran
if [ "$home" == "/home/anh" ]
then
echo "Configuring sferes for local.."
echo "..."
./waf clean
./waf distclean
#./waf configure --boost-include=/home/anh/src/sferes/include --boost-lib=/home/anh/src/sferes/lib --eigen3=/home/anh/src/sferes/include --mpi=/home/anh/openmpi
./waf configure --boost-include=/home/anh/src/sferes/include --boost-lib=/home/anh/src/sferes/lib --eigen3=/home/anh/src/sferes/include
quit=1
else
if [ "$home" == "/home/anguyen8" ]
then
echo "Configuring sferes for Moran.."
echo "..."
./waf clean
./waf distclean
# TBB
# ./waf configure --boost-include=/project/RIISVis/anguyen8/sferes/include/ --boost-libs=/project/RIISVis/anguyen8/sferes/lib/ --eigen3=/home/anguyen8/local/include --mpi=/apps/OPENMPI/gnu/4.8.2/1.6.5 --tbb=/home/anguyen8/sferes --libs=/home/anguyen8/local/lib
# MPI (No TBB)
./waf configure --boost-include=/project/RIISVis/anguyen8/sferes/include/ --boost-libs=/project/RIISVis/anguyen8/sferes/lib/ --eigen3=/home/anguyen8/local/include --mpi=/apps/OPENMPI/gnu/4.8.2/1.6.5 --libs=/home/anguyen8/local/lib
quit=1
else
echo "Unknown environment. Building stopped."
fi
fi
if [ "$quit" -eq "1" ]
then
echo "Building sferes.."
echo "..."
echo "..."
./waf build
echo "Building exp/images.."
echo "..."
echo "..."
./waf --exp images
fi

@ -1,39 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# JB Mouret - 2009
"""
Quick n dirty eigen3 detection
"""
import os, glob, types
import Options, Configure
def detect_eigen3(conf):
env = conf.env
opt = Options.options
conf.env['LIB_EIGEN3'] = ''
conf.env['EIGEN3_FOUND'] = False
if Options.options.no_eigen3:
return 0
if Options.options.eigen3:
conf.env['CPPPATH_EIGEN3'] = [Options.options.eigen3]
conf.env['LIBPATH_EIGEN3'] = [Options.options.eigen3]
else:
conf.env['CPPPATH_EIGEN3'] = ['/usr/include/eigen3', '/usr/local/include/eigen3', '/usr/include', '/usr/local/include']
conf.env['LIBPATH_EIGEN3'] = ['/usr/lib', '/usr/local/lib']
res = Configure.find_file('Eigen/Core', conf.env['CPPPATH_EIGEN3'])
conf.check_message('header','Eigen/Core', (res != '') , res)
if (res == '') :
return 0
conf.env['EIGEN3_FOUND'] = True
return 1
def detect(conf):
return detect_eigen3(conf)
def set_options(opt):
opt.add_option('--eigen3', type='string', help='path to eigen3', dest='eigen3')
opt.add_option('--no-eigen3', type='string', help='disable eigen3', dest='no_eigen3')

@ -1,121 +0,0 @@
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/ea/rank_simple.hpp>
#include <sferes/eval/eval.hpp>
#include <sferes/stat/best_fit.hpp>
#include <sferes/stat/mean_fit.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
using namespace sferes;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
SFERES_CONST float mutation_rate = 0.1f;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
// size of the population
SFERES_CONST unsigned size = 200;
// number of generations
SFERES_CONST unsigned nb_gen = 2000;
// how often should the result file be written (here, each 5
// generation)
SFERES_CONST int dump_period = 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
};
SFERES_FITNESS(FitTest, sferes::fit::Fitness)
{
public:
// indiv will have the type defined in the main (phen_t)
template<typename Indiv>
void eval(const Indiv& ind)
{
float v = 0;
for (unsigned i = 0; i < ind.size(); ++i)
{
float p = ind.data(i);
v += p * p * p * p;
}
this->_value = -v;
}
};
int main(int argc, char **argv)
{
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef FitTest<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
typedef gen::EvoFloat<10, Params> gen_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::Parameters<gen_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
typedef eval::Eval<Params> eval_t;
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the comannd line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
run_ea(argc, argv, ea);
//
return 0;
}

@ -1,11 +0,0 @@
{
"machines" :
{
"localhost" : 3,
"fortaleza" : 2
},
"nb_runs": 3,
"exp" : "examples/ex_ea",
"dir" : "res/ex1",
"debug" : 0
}

@ -1,93 +0,0 @@
#include <iostream>
#ifdef MPI_ENABLED
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/ea/rank_simple.hpp>
#include <sferes/eval/eval.hpp>
#include <sferes/stat/best_fit.hpp>
#include <sferes/stat/mean_fit.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
#include <boost/program_options.hpp>
#include <sferes/eval/mpi.hpp>
using namespace sferes;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
SFERES_CONST float cross_rate = 0.5f;
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 10.0f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
};
struct pop
{
SFERES_CONST unsigned size = 200;
SFERES_CONST unsigned nb_gen = 40;
SFERES_CONST int dump_period = 5;
SFERES_CONST int initial_aleat = 1;
SFERES_CONST float coeff = 1.1f;
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
SFERES_CONST float min = -10.0f;
SFERES_CONST float max = 10.0f;
};
};
SFERES_FITNESS(FitTest, sferes::fit::Fitness)
{
public:
FitTest()
{}
template<typename Indiv>
void eval(const Indiv& ind)
{
float v = 0;
for (unsigned i = 0; i < ind.size(); ++i)
{
float p = ind.data(i);
v += p * p * p * p;
}
// slow down to simulate a slow fitness
usleep(1e4);
this->_value = -v;
}
};
int main(int argc, char **argv)
{
dbg::out(dbg::info)<<"running ex_ea ... try --help for options (verbose)"<<std::endl;
std::cout << "To run this example, you need to use mpirun" << std::endl;
std::cout << "mpirun -x LD_LIBRARY_PATH=/home/creadapt/lib -np 50 -machinefile machines.pinfo build/debug/examples/ex_ea_mpi" << std::endl;
typedef gen::EvoFloat<10, Params> gen_t;
typedef phen::Parameters<gen_t, FitTest<Params>, Params> phen_t;
typedef eval::Mpi<Params> eval_t;
typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef modif::Dummy<> modifier_t;
typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
ea_t ea;
run_ea(argc, argv, ea);
std::cout<<"==> best fitness ="<<ea.stat<0>().best()->fit().value()<<std::endl;
// std::cout<<"==> mean fitness ="<<ea.stat<1>().mean()<<std::endl;
return 0;
}
#else
#warning MPI is disabled, ex_ea_mpi is not compiled
int main()
{
std::cerr<<"MPI is disabled"<<std::endl;
return 0;
}
#endif

@ -1,91 +0,0 @@
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/ea/eps_moea.hpp>
#include <sferes/eval/eval.hpp>
#include <sferes/stat/pareto_front.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
#include <boost/program_options.hpp>
using namespace sferes;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.5f;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 10.0f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
};
struct pop
{
SFERES_CONST unsigned size = 200;
SFERES_CONST int dump_period = 50;
SFERES_ARRAY(float, eps, 0.0075f, 0.0075f);
SFERES_ARRAY(float, min_fit, 0.0f, 0.0f);
SFERES_CONST size_t grain = size / 4;
SFERES_CONST unsigned nb_gen = 2000;
};
struct parameters
{
SFERES_CONST float min = 0.0f;
SFERES_CONST float max = 1.0f;
};
};
template<typename Indiv>
float _g(const Indiv &ind)
{
float g = 0.0f;
assert(ind.size() == 30);
for (size_t i = 1; i < 30; ++i)
g += ind.data(i);
g = 9.0f * g / 29.0f;
g += 1.0f;
return g;
}
SFERES_FITNESS(FitZDT2, sferes::fit::Fitness)
{
public:
FitZDT2() {}
template<typename Indiv>
void eval(Indiv& ind)
{
this->_objs.resize(2);
float f1 = ind.data(0);
float g = _g(ind);
float h = 1.0f - pow((f1 / g), 2.0);
float f2 = g * h;
this->_objs[0] = -f1;
this->_objs[1] = -f2;
}
};
int main(int argc, char **argv)
{
std::cout<<"running "<<argv[0]<<" ... try --help for options (verbose)"<<std::endl;
typedef gen::EvoFloat<30, Params> gen_t;
typedef phen::Parameters<gen_t, FitZDT2<Params>, Params> phen_t;
typedef eval::Eval<Params> eval_t;
typedef boost::fusion::vector<stat::ParetoFront<phen_t, Params> > stat_t;
typedef modif::Dummy<> modifier_t;
typedef ea::EpsMOEA<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
ea_t ea;
run_ea(argc, argv, ea);
return 0;
}

@ -1,87 +0,0 @@
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/ea/nsga2.hpp>
#include <sferes/eval/eval.hpp>
#include <sferes/stat/pareto_front.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
#include <boost/program_options.hpp>
using namespace sferes;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
SFERES_CONST float cross_rate = 0.5f;
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 10.0f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
};
struct pop
{
SFERES_CONST unsigned size = 300;
SFERES_CONST unsigned nb_gen = 500;
SFERES_CONST int dump_period = 50;
SFERES_CONST int initial_aleat = 1;
};
struct parameters
{
SFERES_CONST float min = 0.0f;
SFERES_CONST float max = 1.0f;
};
};
template<typename Indiv>
float _g(const Indiv &ind)
{
float g = 0.0f;
assert(ind.size() == 30);
for (size_t i = 1; i < 30; ++i)
g += ind.data(i);
g = 9.0f * g / 29.0f;
g += 1.0f;
return g;
}
SFERES_FITNESS(FitZDT2, sferes::fit::Fitness)
{
public:
FitZDT2() {}
template<typename Indiv>
void eval(Indiv& ind)
{
this->_objs.resize(2);
float f1 = ind.data(0);
float g = _g(ind);
float h = 1.0f - pow((f1 / g), 2.0);
float f2 = g * h;
this->_objs[0] = -f1;
this->_objs[1] = -f2;
}
};
int main(int argc, char **argv)
{
std::cout<<"running "<<argv[0]<<" ... try --help for options (verbose)"<<std::endl;
typedef gen::EvoFloat<30, Params> gen_t;
typedef phen::Parameters<gen_t, FitZDT2<Params>, Params> phen_t;
typedef eval::Eval<Params> eval_t;
typedef boost::fusion::vector<stat::ParetoFront<phen_t, Params> > stat_t;
typedef modif::Dummy<> modifier_t;
typedef ea::Nsga2<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
ea_t ea;
run_ea(argc, argv, ea);
return 0;
}

@ -1,8 +0,0 @@
{
"email" : "mouret@isir.upmc.fr",
"wall_time" : "24:00:00",
"nb_runs": 3,
"bin_dir": "/home/mouret/svn/sferes2/trunk/build/default/examples/",
"res_dir": "/home/mouret/svn/sferes2/trunk/res/",
"exps" : ["ex_ea"]
}

@ -1,34 +0,0 @@
#! /usr/bin/env python
def build(bld):
return None
# ex_ea
#obj = bld.new_task_gen('cxx', 'program')
#obj.source = 'ex_ea.cpp'
#obj.includes = '../'
#obj.target = 'ex_ea'
#obj.uselib_local = 'sferes2'
#obj.uselib = 'TBB BOOST BOOST_UNIT_TEST_FRAMEWORK EIGEN3'
## ex_ea
#obj = bld.new_task_gen('cxx', 'program')
#obj.source = 'ex_ea_mpi.cpp'
#obj.includes = '../'
#obj.target = 'ex_ea_mpi'
#obj.uselib_local = 'sferes2'
#obj.uselib = 'TBB BOOST BOOST_UNIT_TEST_FRAMEWORK EIGEN3'
## ex_nsga2
#obj = bld.new_task_gen('cxx', 'program')
#obj.source = 'ex_nsga2.cpp'
#obj.includes = '../'
#obj.target = 'ex_nsga2'
#obj.uselib_local = 'sferes2'
#obj.uselib = 'TBB BOOST BOOST_UNIT_TEST_FRAMEWORK EIGEN3'
## ex_eps_moea
#obj = bld.new_task_gen('cxx', 'program')
#obj.source = 'ex_eps_moea.cpp'
#obj.includes = '../'
#obj.target = 'ex_eps_moea'
#obj.uselib_local = 'sferes2'
#obj.uselib = 'TBB BOOST BOOST_UNIT_TEST_FRAMEWORK EIGEN3'

@ -1,88 +0,0 @@
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/ea/nsga2.hpp>
#include <sferes/eval/eval.hpp>
#include <sferes/stat/pareto_front.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
#include <boost/program_options.hpp>
using namespace sferes;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 10.0f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
};
struct pop
{
SFERES_CONST unsigned size = 300;
SFERES_CONST unsigned nb_gen = 500;
SFERES_CONST int dump_period = 50;
SFERES_CONST int initial_aleat = 1;
};
struct parameters
{
SFERES_CONST float min = 0.0f;
SFERES_CONST float max = 1.0f;
};
};
template<typename Indiv>
float _g(const Indiv &ind)
{
float g = 0.0f;
assert(ind.size() == 30);
for (size_t i = 1; i < 30; ++i)
g += ind.data(i);
g = 9.0f * g / 29.0f;
g += 1.0f;
return g;
}
SFERES_FITNESS(FitZDT2, sferes::fit::Fitness)
{
public:
FitZDT2() {}
template<typename Indiv>
void eval(Indiv& ind)
{
this->_objs.resize(2);
float f1 = ind.data(0);
float g = _g(ind);
float h = 1.0f - pow((f1 / g), 2.0);
float f2 = g * h;
this->_objs[0] = -f1;
this->_objs[1] = -f2;
}
};
int main(int argc, char **argv)
{
std::cout<<"running "<<argv[0]<<" ... try --help for options (verbose)"<<std::endl;
typedef gen::EvoFloat<30, Params> gen_t;
typedef phen::Parameters<gen_t, FitZDT2<Params>, Params> phen_t;
typedef eval::Eval<Params> eval_t;
typedef boost::fusion::vector<stat::ParetoFront<phen_t, Params> > stat_t;
typedef modif::Dummy<> modifier_t;
typedef ea::Nsga2<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
ea_t ea;
run_ea(argc, argv, ea);
return 0;
}

@ -1,10 +0,0 @@
#! /usr/bin/env python
def build(bld):
obj = bld.new_task_gen('cxx', 'program')
obj.source = 'example.cpp'
obj.includes = '. ../../'
obj.uselib_local = 'sferes2'
obj.uselib = ''
obj.target = 'example'
obj.uselib_local = 'sferes2'

@ -1,22 +0,0 @@
#!/bin/bash
home=$(echo ~)
echo "You are building from: $home"
# Check the building folder, either on local or Moran
if [ "$home" == "/home/anh" ]
then
echo "Enabled local settings.."
cp ./wscript.local ./wscript
else
if [ "$home" == "/home/anguyen8" ]
then
echo "Enabled Moran settings.."
cp ./wscript.moran ./wscript
else
echo "Unknown environment. Building stopped."
fi
fi

@ -1,88 +0,0 @@
/*
* continue_run.hpp
*
* Created on: Aug 14, 2014
* Author: joost
*/
#ifndef CONTINUE_RUN_HPP_
#define CONTINUE_RUN_HPP_
#include <boost/fusion/container.hpp>
#include <boost/fusion/include/vector.hpp>
#include <sferes/dbg/dbg.hpp>
#include "global_options.hpp"
#include <exp/images/stat/stat_map_image.hpp>
namespace sferes
{
namespace cont
{
template<typename EAType, typename Params>
class Continuator
{
public:
typedef std::vector<typename EAType::indiv_t> pop_t;
bool enabled()
{
return options::vm.count("continue");
}
pop_t getPopulationFromFile(EAType& ea)
{
ea.load(options::vm["continue"].as<std::string>());
return boost::fusion::at_c<Params::cont::getPopIndex>(ea.stat()).getPopulation();
}
pop_t getPopulationFromFile(EAType& ea, const std::string& path_gen_file)
{
ea.load(path_gen_file);
return boost::fusion::at_c<Params::cont::getPopIndex>(ea.stat()).getPopulation();
}
void run_with_current_population(EAType& ea, const std::string filename)
{
// Read the number of generation from gen file. Ex: gen_450
int start = 0;
std::string gen_prefix("gen_");
std::size_t pos = filename.rfind(gen_prefix) + gen_prefix.size();
std::string gen_number = filename.substr(pos);
std::istringstream ss(gen_number);
ss >> start;
start++;
dbg::out(dbg::info, "continue") << "File name: " << filename << " number start: " << pos << " gen number: " << gen_number << " result: " << start << std::endl;
// Similar to the run() function in <sferes/ea/ea.hpp>
for (int _gen = start; _gen < Params::pop::nb_gen; ++_gen)
{
ea.setGen(_gen);
ea.epoch();
ea.update_stats();
if (_gen % Params::pop::dump_period == 0)
{
ea.write();
}
}
std::cout << "Finished all the runs.\n";
exit(0);
}
void run_with_current_population(EAType& ea)
{
const std::string filename = options::vm["continue"].as<std::string>();
run_with_current_population(ea, filename);
}
};
}
}
#endif /* CONTINUE_RUN_HPP_ */

@ -1,120 +0,0 @@
/*
* global_options.hpp
*
* Created on: Aug 14, 2014
* Author: Joost Huizinga
*
* Header file created to allow for custom command-line options to be added to an experiment.
* Requires you to replace run_ea with options::run_ea to works.
* Options can be added by:
* options::add()("option_name","description");
*/
#ifndef GLOBAL_OPTIONS_HPP_
#define GLOBAL_OPTIONS_HPP_
#include <boost/program_options.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/foreach.hpp>
#include <sferes/eval/parallel.hpp>
//#include <sferes/dbg/dbg.hpp>
namespace sferes
{
namespace options
{
boost::program_options::variables_map vm;
template<typename Ea>
static void run_ea ( int argc, char **argv, Ea& ea,
const boost::program_options::options_description& add_opts =
boost::program_options::options_description(),
bool init_rand = true )
{
namespace po = boost::program_options;
std::cout << "sferes2 version: " << VERSION << std::endl;
if (init_rand)
{
time_t t = time(0) + ::getpid();
std::cout << "seed: " << t << std::endl;
srand(t);
}
po::options_description desc("Allowed sferes2 options");
desc.add(add_opts);
desc.add_options()("help,h", "produce help message")("stat,s",
po::value<int>(), "statistic number")("out,o",
po::value<std::string>(), "output file")("number,n", po::value<int>(),
"number in stat")("load,l", po::value<std::string>(),
"load a result file")("verbose,v",
po::value<std::vector<std::string> >()->multitoken(),
"verbose output, available default streams : all, ea, fit, phen, trace");
// po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
if (vm.count("help"))
{
std::cout << desc << std::endl;
return;
}
if (vm.count("verbose"))
{
dbg::init();
std::vector < std::string > streams = vm["verbose"].as<
std::vector<std::string> >();
attach_ostream(dbg::warning, std::cout);
attach_ostream(dbg::error, std::cerr);
attach_ostream(dbg::info, std::cout);
bool all = std::find(streams.begin(), streams.end(), "all")
!= streams.end();
bool trace = std::find(streams.begin(), streams.end(), "trace")
!= streams.end();
if (all)
{
streams.push_back("ea");
streams.push_back("fit");
streams.push_back("phen");
streams.push_back("eval");
}
BOOST_FOREACH(const std::string& s, streams){
dbg::enable(dbg::all, s.c_str(), true);
dbg::attach_ostream(dbg::info, s.c_str(), std::cout);
if (trace)
dbg::attach_ostream(dbg::tracing, s.c_str(), std::cout);
}
if (trace)
attach_ostream(dbg::tracing, std::cout);
}
parallel::init();
if (vm.count("load"))
{
ea.load(vm["load"].as<std::string>());
if (!vm.count("out"))
{
std::cerr << "You must specifiy an out file" << std::endl;
return;
}
else
{
int stat = 0;
int n = 0;
if (vm.count("stat"))
stat = vm["stat"].as<int>();
if (vm.count("number"))
n = vm["number"].as<int>();
std::ofstream ofs(vm["out"].as<std::string>().c_str());
ea.show_stat(stat, ofs, n);
}
}
else
ea.run();
}
}
}
#endif /* GLOBAL_OPTIONS_HPP_ */

@ -1,32 +0,0 @@
#ifndef DEEP_LEARNING_IMAGES_HPP
#define DEEP_LEARNING_IMAGES_HPP
#include "settings.h"
#include <sferes/phen/parameters.hpp>
using namespace sferes;
// Parameters required by Caffe separated from those introduced by Sferes
struct ParamsCaffe
{
struct image
{
// Size of the square image 256x256
SFERES_CONST int size = 256;
SFERES_CONST int crop_size = 227;
SFERES_CONST bool use_crops = true;
SFERES_CONST bool color = true; // true: color, false: grayscale images
// GPU configurations
SFERES_CONST bool use_gpu = false;
// GPU on Moran can only handle max of 512 images in a batch at a time.
SFERES_CONST int batch = 1;
SFERES_CONST int num_categories = 1000; // ILSVR2012 ImageNet has 1000 categories
static int category_id;
SFERES_CONST bool record_lineage = false; // Flag to save the parent's assigned class
};
};
#endif /* DEEP_LEARNING_IMAGES_HPP */

@ -1,232 +0,0 @@
#include "dl_images.hpp"
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/eval/eval.hpp>
#include "stat/best_fit_map_image.hpp"
#include "stat/stat_map_image.hpp"
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
// Evolutionary algorithms --------------------------------
#include "fit/fit_map_deep_learning.hpp"
#include <modules/nn2/gen_dnn.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
#include "phen/phen_color_image.hpp"
#include <glog/logging.h>
// Caffe -------------------------------------------------
#include <modules/map_elite/map_elite.hpp>
#include "eval/mpi_parallel.hpp" // MPI
#include "continue_run/continue_run.hpp" // MPI
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params
{
struct cont
{
static const int getPopIndex = 0;
};
struct log
{
SFERES_CONST bool best_image = false;
};
struct ea
{
SFERES_CONST size_t res_x = 1; // 256;
SFERES_CONST size_t res_y = 1000; // 256;
};
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 3; // Red, Green, Blue
SFERES_CONST float m_rate_add_conn = 0.5f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 0.5f;
SFERES_CONST float m_rate_add_neuron = 0.5f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
SFERES_CONST float mutation_rate = 0.1f;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
//number of initial random points
static const size_t init_size = 400; // 1000
// size of the population
SFERES_CONST unsigned size = 400; //200;
// number of generations
SFERES_CONST unsigned nb_gen = 5001; //10,000;
// how often should the result file be written (here, each 5
// generation)
static int dump_period;// 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, nn::cppn::sine, nn::cppn::sigmoid, nn::cppn::gaussian, nn::cppn::linear);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
// Specific settings for MNIST database of grayscale
struct image : ParamsCaffe::image
{
static const std::string model_definition;
static const std::string pretrained_model;
};
};
// Initialize the parameter files for Caffe network.
#ifdef LOCAL_RUN
const std::string Params::image::model_definition = "/home/anh/src/model/imagenet_deploy_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/home/anh/src/model/caffe_reference_imagenet_model";
#else
const std::string Params::image::model_definition = "/project/EvolvingAI/anguyen8/model/imagenet_deploy_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/project/EvolvingAI/anguyen8/model/caffe_reference_imagenet_model";
#endif
int Params::pop::dump_period = 1000;
int main(int argc, char **argv)
{
// Disable GLOG output from experiment and also Caffe
// Comment out for debugging
google::InitGoogleLogging("");
google::SetStderrLogging(3);
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef sferes::fit::FitMapDeepLearning<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
//typedef gen::EvoFloat<10, Params> gen_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef gen::HyperNn<weight_t, Params> cppn_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::ColorImage<cppn_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
// typedef eval::Eval<Params> eval_t;
typedef eval::MpiParallel<Params> eval_t; // TBB
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
// typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef boost::fusion::vector<stat::MapImage<phen_t, Params>, stat::BestFitMapImage<phen_t, Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
// typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the command line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
if (argc > 1) // if a number is provided on the command line
{
int randomSeed = atoi(argv[1]);
printf("randomSeed:%i\n", randomSeed);
srand(randomSeed); //set it as the random seed
boost::program_options::options_description add_opts =
boost::program_options::options_description();
shared_ptr<boost::program_options::option_description> opt (new boost::program_options::option_description(
"continue,t", boost::program_options::value<std::string>(),
"continue from the loaded file starting from the generation provided"
));
add_opts.add(opt);
options::run_ea(argc, argv, ea, add_opts, false);
}
else
{
run_ea(argc, argv, ea);
}
return 0;
}

@ -1,197 +0,0 @@
#include "dl_images.hpp"
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include "gen/evo_float_image.hpp"
#include <sferes/eval/eval.hpp>
#include "stat/best_fit_map_image.hpp"
#include "stat/stat_map_image.hpp"
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
// Evolutionary algorithms --------------------------------
#include "fit/fit_map_deep_learning.hpp"
#include <modules/nn2/gen_dnn.hpp>
#include <modules/nn2/phen_dnn.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
#include "phen/phen_image_direct.hpp"
#include <glog/logging.h>
// Caffe -------------------------------------------------
#include <modules/map_elite/map_elite.hpp>
#include "eval/mpi_parallel.hpp" // MPI
#include "continue_run/continue_run.hpp" // MPI
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float_image;
struct Params
{
struct cont
{
static const int getPopIndex = 0;
};
struct log
{
SFERES_CONST bool best_image = false;
};
struct ea
{
SFERES_CONST size_t res_x = 1; // 256;
SFERES_CONST size_t res_y = 1000; // 256;
};
struct evo_float_image
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
static float mutation_rate;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
//number of initial random points
SFERES_CONST size_t init_size = 200; // 1000
// size of the population
SFERES_CONST unsigned size = 200; //200;
// number of generations
SFERES_CONST unsigned nb_gen = 5010; //10,000;
// how often should the result file be written (here, each 5
// generation)
static int dump_period;// 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
// Specific settings for MNIST database of grayscale
struct image : ParamsCaffe::image
{
static const std::string model_definition;
static const std::string pretrained_model;
};
};
// Initialize the parameter files for Caffe network.
#ifdef LOCAL_RUN
const std::string Params::image::model_definition = "/home/anh/src/model/imagenet_deploy_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/home/anh/src/model/caffe_reference_imagenet_model";
#else
const std::string Params::image::model_definition = "/project/EvolvingAI/anguyen8/model/imagenet_deploy_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/project/EvolvingAI/anguyen8/model/caffe_reference_imagenet_model";
#endif
int Params::pop::dump_period = 1000;
float Params::evo_float_image::mutation_rate = 0.1f;
int main(int argc, char **argv)
{
// Disable GLOG output from experiment and also Caffe
// Comment out for debugging
google::InitGoogleLogging("");
google::SetStderrLogging(3);
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef sferes::fit::FitMapDeepLearning<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
typedef gen::EvoFloatImage<Params::image::size * Params::image::size * 3, Params> gen_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::ImageDirect<gen_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
// typedef eval::Eval<Params> eval_t;
typedef eval::MpiParallel<Params> eval_t; // TBB
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
// typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef boost::fusion::vector<stat::MapImage<phen_t, Params>, stat::BestFitMapImage<phen_t, Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
// typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the command line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
if (argc > 1) // if a number is provided on the command line
{
int randomSeed = atoi(argv[1]);
printf("randomSeed:%i\n", randomSeed);
srand(randomSeed); //set it as the random seed
boost::program_options::options_description add_opts =
boost::program_options::options_description();
shared_ptr<boost::program_options::option_description> opt (new boost::program_options::option_description(
"continue,t", boost::program_options::value<std::string>(),
"continue from the loaded file starting from the generation provided"
));
add_opts.add(opt);
options::run_ea(argc, argv, ea, add_opts, false);
}
else
{
run_ea(argc, argv, ea);
}
return 0;
}

@ -1,241 +0,0 @@
#include "dl_images.hpp"
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/eval/eval.hpp>
#include "stat/best_fit_map_image.hpp"
#include "stat/stat_map_image.hpp"
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
// Evolutionary algorithms --------------------------------
#include "fit/fit_map_deep_learning.hpp"
#include <modules/nn2/gen_dnn.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
#include "phen/phen_grayscale_image.hpp"
#include <glog/logging.h>
// Caffe -------------------------------------------------
#include <modules/map_elite/map_elite.hpp>
#include "eval/mpi_parallel.hpp" // MPI
#include "continue_run/continue_run.hpp" // MPI
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params
{
struct cont
{
static const int getPopIndex = 0;
};
struct log
{
SFERES_CONST bool best_image = false;
};
struct ea
{
SFERES_CONST size_t res_x = 1; // 256;
SFERES_CONST size_t res_y = 10; // 256;
};
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 1; // Red, Green, Blue
SFERES_CONST float m_rate_add_conn = 0.5f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 0.5f;
SFERES_CONST float m_rate_add_neuron = 0.5f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
SFERES_CONST float mutation_rate = 0.1f;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
//number of initial random points
static const size_t init_size = 200; // 1000
// size of the population
SFERES_CONST unsigned size = 200; //200;
// number of generations
SFERES_CONST unsigned nb_gen = 1001; //10,000;
// how often should the result file be written (here, each 5
// generation)
static int dump_period;// 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, nn::cppn::sine, nn::cppn::sigmoid, nn::cppn::gaussian, nn::cppn::linear);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
// Specific settings for MNIST database of grayscale
struct image : ParamsCaffe::image
{
// Size of the square image 256x256
SFERES_CONST int size = 28;
SFERES_CONST bool use_crops = false;
SFERES_CONST bool color = false; // Grayscale
SFERES_CONST int num_categories = 10; // MNIST has 10 categories
static const std::string model_definition;
static const std::string pretrained_model;
SFERES_CONST bool record_lineage = true;
};
};
// Initialize the parameter files for Caffe network.
#ifdef LOCAL_RUN
const std::string Params::image::model_definition = "/home/anh/src/model/lenet_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/home/anh/src/model/lenet_iter_10000";
#else
const std::string Params::image::model_definition = "/project/EvolvingAI/anguyen8/model/lenet_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/project/EvolvingAI/anguyen8/model/lenet_iter_10000";
#endif
int Params::pop::dump_period = 100;
int main(int argc, char **argv)
{
// Disable GLOG output from experiment and also Caffe
// Comment out for debugging
google::InitGoogleLogging("");
google::SetStderrLogging(3);
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef sferes::fit::FitMapDeepLearning<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
//typedef gen::EvoFloat<10, Params> gen_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef gen::HyperNn<weight_t, Params> cppn_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::GrayscaleImage<cppn_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
// typedef eval::Eval<Params> eval_t;
typedef eval::MpiParallel<Params> eval_t; // TBB
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
// typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef boost::fusion::vector<stat::MapImage<phen_t, Params>, stat::BestFitMapImage<phen_t, Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
// typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the command line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
if (argc > 1) // if a number is provided on the command line
{
int randomSeed = atoi(argv[1]);
printf("randomSeed:%i\n", randomSeed);
srand(randomSeed); //set it as the random seed
boost::program_options::options_description add_opts =
boost::program_options::options_description();
shared_ptr<boost::program_options::option_description> opt (new boost::program_options::option_description(
"continue,t", boost::program_options::value<std::string>(),
"continue from the loaded file starting from the generation provided"
));
add_opts.add(opt);
options::run_ea(argc, argv, ea, add_opts, false);
}
else
{
run_ea(argc, argv, ea);
}
return 0;
}

@ -1,202 +0,0 @@
#include "dl_images.hpp"
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include "gen/evo_float_image.hpp"
#include <sferes/eval/eval.hpp>
#include "stat/best_fit_map_image.hpp"
#include "stat/stat_map_image.hpp"
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
// Evolutionary algorithms --------------------------------
#include "fit/fit_map_deep_learning.hpp"
#include <modules/nn2/gen_dnn.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
#include "phen/phen_grayscale_image_direct.hpp"
#include <glog/logging.h>
// Caffe -------------------------------------------------
#include <modules/map_elite/map_elite.hpp>
#include "eval/mpi_parallel.hpp" // MPI
#include "continue_run/continue_run.hpp" // MPI
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float_image;
struct Params
{
struct cont
{
static const int getPopIndex = 0;
};
struct log
{
SFERES_CONST bool best_image = false;
};
struct ea
{
SFERES_CONST size_t res_x = 1; // 256;
SFERES_CONST size_t res_y = 10; // 256;
};
struct evo_float_image
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
SFERES_CONST float mutation_rate = 0.1f;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
//number of initial random points
static const size_t init_size = 200; // 1000
// size of the population
SFERES_CONST unsigned size = 200; //200;
// number of generations
SFERES_CONST unsigned nb_gen = 1010; //10,000;
// how often should the result file be written (here, each 5
// generation)
static int dump_period;// 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
// Specific settings for MNIST database of grayscale
struct image : ParamsCaffe::image
{
// Size of the square image 256x256
SFERES_CONST int size = 28;
SFERES_CONST bool use_crops = false;
SFERES_CONST bool color = false; // Grayscale
SFERES_CONST int num_categories = 10; // MNIST has 10 categories
static const std::string model_definition;
static const std::string pretrained_model;
};
};
// Initialize the parameter files for Caffe network.
#ifdef LOCAL_RUN
const std::string Params::image::model_definition = "/home/anh/src/model/lenet_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/home/anh/src/model/lenet_iter_10000";
#else
const std::string Params::image::model_definition = "/project/EvolvingAI/anguyen8/model/lenet_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/project/EvolvingAI/anguyen8/model/lenet_iter_10000";
#endif
int Params::pop::dump_period = 10;
int main(int argc, char **argv)
{
// Disable GLOG output from experiment and also Caffe
// Comment out for debugging
google::InitGoogleLogging("");
google::SetStderrLogging(3);
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef sferes::fit::FitMapDeepLearning<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
typedef gen::EvoFloatImage<Params::image::size * Params::image::size, Params> gen_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::GrayscaleImageDirect<gen_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
// typedef eval::Eval<Params> eval_t;
typedef eval::MpiParallel<Params> eval_t; // TBB
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
// typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef boost::fusion::vector<stat::MapImage<phen_t, Params>, stat::BestFitMapImage<phen_t, Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
// typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the command line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
if (argc > 1) // if a number is provided on the command line
{
int randomSeed = atoi(argv[1]);
printf("randomSeed:%i\n", randomSeed);
srand(randomSeed); //set it as the random seed
boost::program_options::options_description add_opts =
boost::program_options::options_description();
shared_ptr<boost::program_options::option_description> opt (new boost::program_options::option_description(
"continue,t", boost::program_options::value<std::string>(),
"continue from the loaded file starting from the generation provided"
));
add_opts.add(opt);
options::run_ea(argc, argv, ea, add_opts, false);
}
else
{
run_ea(argc, argv, ea);
}
return 0;
}

@ -1,237 +0,0 @@
#include "dl_images.hpp"
#include <iostream>
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/eval/eval.hpp>
#include "stat/best_fit_map_image.hpp"
#include "stat/stat_map_image.hpp"
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
// Evolutionary algorithms --------------------------------
#include "fit/fit_map_deep_learning.hpp"
#include <modules/nn2/gen_dnn.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
#include "phen/phen_color_image.hpp"
#include <glog/logging.h>
// Caffe -------------------------------------------------
#include <modules/map_elite/map_elite.hpp>
#include "eval/mpi_parallel.hpp" // MPI
#include "continue_run/continue_run.hpp" // MPI
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params
{
struct cont
{
static const int getPopIndex = 0;
};
struct log
{
SFERES_CONST bool best_image = false;
};
struct ea
{
SFERES_CONST size_t res_x = 1; // 256;
SFERES_CONST size_t res_y = 10; // 256;
};
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 3; // Red, Green, Blue
SFERES_CONST float m_rate_add_conn = 0.5f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 0.5f;
SFERES_CONST float m_rate_add_neuron = 0.5f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
// we choose the polynomial mutation type
SFERES_CONST mutation_t mutation_type = polynomial;
// we choose the polynomial cross-over type
SFERES_CONST cross_over_t cross_over_type = sbx;
// the mutation rate of the real-valued vector
SFERES_CONST float mutation_rate = 0.1f;
// the cross rate of the real-valued vector
SFERES_CONST float cross_rate = 0.5f;
// a parameter of the polynomial mutation
SFERES_CONST float eta_m = 15.0f;
// a parameter of the polynomial cross-over
SFERES_CONST float eta_c = 10.0f;
};
struct pop
{
//number of initial random points
static const size_t init_size = 10; // 1000
// size of the population
SFERES_CONST unsigned size = 10; //200;
// number of generations
SFERES_CONST unsigned nb_gen = 10; //10,000;
// how often should the result file be written (here, each 5
// generation)
static int dump_period;// 5;
// how many individuals should be created during the random
// generation process?
SFERES_CONST int initial_aleat = 1;
// used by RankSimple to select the pressure
SFERES_CONST float coeff = 1.1f;
// the number of individuals that are kept from on generation to
// another (elitism)
SFERES_CONST float keep_rate = 0.6f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -10.0f;
// minimum value
SFERES_CONST float max = 10.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, nn::cppn::sine, nn::cppn::sigmoid, nn::cppn::gaussian, nn::cppn::linear);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
// Specific settings for MNIST database of grayscale
struct image : ParamsCaffe::image
{
static const std::string model_definition;
static const std::string pretrained_model;
SFERES_CONST bool record_lineage = false;
SFERES_CONST int size = 28;
SFERES_CONST bool use_crops = false;
SFERES_CONST int num_categories = 10; // ILSVR2012 ImageNet has 1000 categories
};
};
// Initialize the parameter files for Caffe network.
#ifdef LOCAL_RUN
const std::string Params::image::model_definition = "/home/anh/src/model/imagenet_deploy_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/home/anh/src/model/caffe_reference_imagenet_model";
#else
const std::string Params::image::model_definition = "/project/EvolvingAI/anguyen8/model/imagenet_deploy_image_memory_data.prototxt";
const std::string Params::image::pretrained_model = "/project/EvolvingAI/anguyen8/model/caffe_reference_imagenet_model";
#endif
int Params::pop::dump_period = 1;
int main(int argc, char **argv)
{
// Disable GLOG output from experiment and also Caffe
// Comment out for debugging
google::InitGoogleLogging("");
google::SetStderrLogging(3);
// Our fitness is the class FitTest (see above), that we will call
// fit_t. Params is the set of parameters (struct Params) defined in
// this file.
typedef sferes::fit::FitMapDeepLearning<Params> fit_t;
// We define the genotype. Here we choose EvoFloat (real
// numbers). We evolve 10 real numbers, with the params defined in
// Params (cf the beginning of this file)
//typedef gen::EvoFloat<10, Params> gen_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef gen::HyperNn<weight_t, Params> cppn_t;
// This genotype should be simply transformed into a vector of
// parameters (phen::Parameters). The genotype could also have been
// transformed into a shape, a neural network... The phenotype need
// to know which fitness to use; we pass fit_t.
typedef phen::ColorImage<cppn_t, fit_t, Params> phen_t;
// The evaluator is in charge of distributing the evaluation of the
// population. It can be simple eval::Eval (nothing special),
// parallel (for multicore machines, eval::Parallel) or distributed
// (for clusters, eval::Mpi).
// typedef eval::Eval<Params> eval_t;
typedef eval::MpiParallel<Params> eval_t; // TBB
// Statistics gather data about the evolutionary process (mean
// fitness, Pareto front, ...). Since they can also stores the best
// individuals, they are the container of our results. We can add as
// many statistics as required thanks to the boost::fusion::vector.
// typedef boost::fusion::vector<stat::BestFit<phen_t, Params>, stat::MeanFit<Params> > stat_t;
typedef boost::fusion::vector<stat::MapImage<phen_t, Params>, stat::BestFitMapImage<phen_t, Params> > stat_t;
// Modifiers are functors that are run once all individuals have
// been evalutated. Their typical use is to add some evolutionary
// pressures towards diversity (e.g. fitness sharing). Here we don't
// use this feature. As a consequence we use a "dummy" modifier that
// does nothing.
typedef modif::Dummy<> modifier_t;
// We can finally put everything together. RankSimple is the
// evolutianary algorithm. It is parametrized by the phenotype, the
// evaluator, the statistics list, the modifier and the general params.
// typedef ea::RankSimple<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
// We now have a special class for our experiment: ea_t. The next
// line instantiate an object of this class
ea_t ea;
// we can now process the command line options an run the
// evolutionary algorithm (if a --load argument is passed, the file
// is loaded; otherwise, the algorithm is launched).
if (argc > 1) // if a number is provided on the command line
{
int randomSeed = atoi(argv[1]);
printf("randomSeed:%i\n", randomSeed);
srand(randomSeed); //set it as the random seed
boost::program_options::options_description add_opts =
boost::program_options::options_description();
shared_ptr<boost::program_options::option_description> opt (new boost::program_options::option_description(
"continue,t", boost::program_options::value<std::string>(),
"continue from the loaded file starting from the generation provided"
));
add_opts.add(opt);
options::run_ea(argc, argv, ea, add_opts, false);
}
else
{
run_ea(argc, argv, ea);
}
return 0;
}

@ -1,127 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EA_CUSTOM_HPP_
#define EA_CUSTOM_HPP_
#include <iostream>
#include <vector>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <sferes/ea/ea.hpp>
namespace sferes {
namespace ea {
SFERES_EA(EaCustom, Ea) {
protected:
std::string _gen_file_path;
public:
EaCustom () : _gen_file_path("")
{
this->_make_res_dir();
}
void _make_res_dir()
{
if (Params::pop::dump_period == -1)
{
return;
}
// Delete the unused folder by Ea
std::string to_delete = misc::hostname() + "_" + misc::date() + "_" + misc::getpid();
if (boost::filesystem::is_directory(to_delete) && boost::filesystem::is_empty(to_delete))
{
boost::filesystem::remove(to_delete);
}
// Check if such a folder already exists
this->_res_dir = "mmm"; // Only one folder regardless which platform the program is running on
boost::filesystem::path my_path(this->_res_dir);
// Create a new folder if it doesn't exist
if (!boost::filesystem::exists(boost::filesystem::status(my_path)))
{
// Create a new folder if it does not exist
boost::filesystem::create_directory(my_path);
}
// Run experiment from that folder
else
{
std::vector<std::string> gens;
// The file to find
int max = 0;
// Find a gen file
for(boost::filesystem::directory_entry& entry : boost::make_iterator_range(boost::filesystem::directory_iterator(my_path), {}))
{
// Find out if '/gen_' exists in the filename
std::string e = entry.path().string();
std::string prefix = this->_res_dir + "/gen_";
size_t found = e.find(prefix);
if (found != std::string::npos)
{
// Extract out the generation number
std::string number = std::string(e).replace(found, prefix.length(), "");
// Remove double quotes
// number = boost::replace_all_copy(number, "\"", "");.string()
int gen = boost::lexical_cast<int>(number);
if (gen > max)
{
max = gen;
_gen_file_path = e;
}
} // end if
} // end for-loop
// Start run from that gen file
// _continue_run = boost::filesystem::current_path().string() + "/" + _continue_run;
std::cout << "[A]: " << _gen_file_path << "\n";
}
}
};
}
}
#endif

@ -1,167 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef RANK_SIMPLE_HPP_
#define RANK_SIMPLE_HPP_
#include <algorithm>
#include <boost/foreach.hpp>
#include <sferes/stc.hpp>
#include "ea_custom.hpp"
#include <sferes/fit/fitness.hpp>
#include <exp/images/continue_run/continue_run.hpp>
namespace sferes {
namespace ea {
SFERES_EA(RankSimple, EaCustom) {
public:
typedef boost::shared_ptr<Phen> indiv_t;
typedef std::vector<indiv_t> raw_pop_t;
typedef typename std::vector<indiv_t> pop_t;
typedef RankSimple<Phen, Eval, Stat, FitModifier, Params, Exact> this_t;
SFERES_CONST unsigned nb_keep = (unsigned)(Params::pop::keep_rate * Params::pop::size);
void random_pop()
{
sferes::cont::Continuator<this_t, Params> continuator;
// Continuing a run manually from command line or continuing a run automatically if the job was pre-empted
bool continue_run = continuator.enabled() || this->_gen_file_path != "";
if(continue_run)
{
// Load the population file
raw_pop_t raw_pop;
if (this->_gen_file_path == "")
{
raw_pop = continuator.getPopulationFromFile(*this);
}
else
{
raw_pop = continuator.getPopulationFromFile(*this, this->_gen_file_path);
}
// Get the number of population to continue with
const size_t init_size = raw_pop.size();
// Resize the current population archive
this->_pop.resize(init_size);
// Add loaded individuals to the new population
int i = 0;
BOOST_FOREACH(boost::shared_ptr<Phen>&indiv, this->_pop)
{
indiv = boost::shared_ptr<Phen>(new Phen(*raw_pop[i]));
++i;
}
}
else
{
// Original Map-Elites code
// Intialize a random population
this->_pop.resize(Params::pop::size * Params::pop::initial_aleat);
BOOST_FOREACH(boost::shared_ptr<Phen>& indiv, this->_pop)
{
indiv = boost::shared_ptr<Phen>(new Phen());
indiv->random();
}
}
// Evaluate the initialized population
this->_eval.eval(this->_pop, 0, this->_pop.size());
this->apply_modifier();
std::partial_sort(this->_pop.begin(), this->_pop.begin() + Params::pop::size,
this->_pop.end(), fit::compare());
this->_pop.resize(Params::pop::size);
// Continue a run from a specific generation
if(continue_run)
{
if (this->_gen_file_path == "")
{
continuator.run_with_current_population(*this);
}
else
{
continuator.run_with_current_population(*this, this->_gen_file_path);
}
}
}
//ADDED
void setGen(size_t gen)
{
this->_gen = gen;
}
//ADDED END
void epoch()
{
assert(this->_pop.size());
for (unsigned i = nb_keep; i < this->_pop.size(); i += 2) {
unsigned r1 = _random_rank();
unsigned r2 = _random_rank();
boost::shared_ptr<Phen> i1, i2;
this->_pop[r1]->cross(this->_pop[r2], i1, i2);
i1->mutate();
i2->mutate();
this->_pop[i] = i1;
this->_pop[i + 1] = i2;
}
#ifndef EA_EVAL_ALL
this->_eval.eval(this->_pop, nb_keep, Params::pop::size);
#else
this->_eval.eval(this->_pop, 0, Params::pop::size);
#endif
this->apply_modifier();
std::partial_sort(this->_pop.begin(), this->_pop.begin() + nb_keep,
this->_pop.end(), fit::compare());
dbg::out(dbg::info, "ea")<<"best fitness: " << this->_pop[0]->fit().value() << std::endl;
}
protected:
unsigned _random_rank() {
static float kappa = pow(Params::pop::coeff, nb_keep + 1.0f) - 1.0f;
static float facteur = nb_keep / ::log(kappa + 1);
return (unsigned) (this->_pop.size() - facteur * log(misc::rand<float>(1) * kappa + 1));
}
};
}
}
#endif

@ -1,238 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef BATCH_EVAL_MPI_PARALLEL_HPP_
#define BATCH_EVAL_MPI_PARALLEL_HPP_
#include <sferes/parallel.hpp>
#include <boost/mpi.hpp>
#include "tbb_parallel_eval.hpp"
#include <cmath>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
//#ifndef BOOST_MPI_HAS_NOARG_INITIALIZATION
//#error MPI need arguments (we require a full MPI2 implementation)
//#endif
#define MPI_INFO dbg::out(dbg::info, "mpi")<<"["<<_world->rank()<<"] "
namespace sferes {
namespace eval {
SFERES_CLASS(BatchMpiTBBParallel) {
public:
BatchMpiTBBParallel()
{
static char* argv[] = {(char*)"sferes2", 0x0};
char** argv2 = (char**) malloc(sizeof(char*) * 2);
int argc = 1;
argv2[0] = argv[0];
argv2[1] = argv[1];
using namespace boost;
dbg::out(dbg::info, "mpi")<<"Initializing MPI..."<<std::endl;
_env = shared_ptr<mpi::environment>(new mpi::environment(argc, argv2, true));
dbg::out(dbg::info, "mpi")<<"MPI initialized"<<std::endl;
_world = shared_ptr<mpi::communicator>(new mpi::communicator());
MPI_INFO << "communicator initialized"<<std::endl;
// Disable dumping out results for slave processes.
if (_world->rank() > 0)
{
Params::pop::dump_period = -1;
}
}
template<typename Phen>
void eval(std::vector<boost::shared_ptr<Phen> >& pop,
size_t begin, size_t end) {
dbg::trace("mpi", DBG_HERE);
// Develop phenotypes in parallel
// Each MPI process develops one phenotype
if (_world->rank() == 0)
_master_develop(pop, begin, end);
else
_slave_develop<Phen>();
// Make sure the processes have finished developing phenotypes
// Evaluate phenotypes in parallel but in batches of 256.
// Caffe GPU supports max of 512.
// There is no limit for CPU but we try to find out what batch size works best.
if (_world->rank() == 0)
{
_master_eval(pop, begin, end);
}
}
~BatchMpiTBBParallel()
{
MPI_INFO << "Finalizing MPI..."<<std::endl;
std::string s("bye");
if (_world->rank() == 0)
for (size_t i = 1; i < _world->size(); ++i)
_world->send(i, _env->max_tag(), s);
_finalize();
}
protected:
void _finalize()
{
_world = boost::shared_ptr<boost::mpi::communicator>();
dbg::out(dbg::info, "mpi")<<"MPI world destroyed"<<std::endl;
_env = boost::shared_ptr<boost::mpi::environment>();
dbg::out(dbg::info, "mpi")<<"environment destroyed"<<std::endl;
}
template<typename Phen>
void _master_develop(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace("mpi", DBG_HERE);
size_t current = begin;
std::vector<bool> developed(pop.size());
std::fill(developed.begin(), developed.end(), false);
// first round
for (size_t i = 1; i < _world->size() && current < end; ++i) {
MPI_INFO << "[master] [send-init...] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
_world->send(i, current, pop[current]->gen());
MPI_INFO << "[master] [send-init ok] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
// send a new indiv each time we received a fitness
while (current < end) {
boost::mpi::status s = _recv(developed, pop);
MPI_INFO << "[master] [send...] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
_world->send(s.source(), current, pop[current]->gen());
MPI_INFO << "[master] [send ok] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
//join
bool done = true;
do {
dbg::out(dbg::info, "mpi")<<"joining..."<<std::endl;
done = true;
for (size_t i = begin; i < end; ++i)
if (!developed[i]) {
_recv(developed, pop);
done = false;
}
} while (!done);
}
template<typename Phen>
boost::mpi::status _recv(std::vector<bool>& developed,
std::vector<boost::shared_ptr<Phen> >& pop)
{
dbg::trace("mpi", DBG_HERE);
using namespace boost::mpi;
status s = _world->probe();
MPI_INFO << "[rcv...]" << getpid() << " tag=" << s.tag() << std::endl;
//_world->recv(s.source(), s.tag(), pop[s.tag()]->fit());
// Receive the whole developed phenotype from slave processes
Phen p;
_world->recv(s.source(), s.tag(), p);
// Assign the developed phenotype back to the current population for further evaluation
pop[s.tag()]->image() = p.image();
MPI_INFO << "[rcv ok]" << " tag=" << s.tag() << std::endl;
developed[s.tag()] = true;
return s;
}
template<typename Phen>
void _slave_develop()
{
dbg::trace("mpi", DBG_HERE);
while(true) {
Phen p;
boost::mpi::status s = _world->probe();
if (s.tag() == _env->max_tag()) {
MPI_INFO << "[slave] Quit requested" << std::endl;
MPI_Finalize();
exit(0);
} else {
MPI_INFO <<"[slave] [rcv...] [" << getpid()<< "]" << std::endl;
_world->recv(0, s.tag(), p.gen());
MPI_INFO <<"[slave] [rcv ok] " << " tag="<<s.tag()<<std::endl;
p.develop();
MPI_INFO <<"[slave] [send...]"<<" tag=" << s.tag()<<std::endl;
//_world->send(0, s.tag(), p.fit()); // Send only the fitness back to master process
// Send the whole phenotype back to master process
_world->send(0, s.tag(), p);
MPI_INFO <<"[slave] [send ok]"<<" tag=" << s.tag()<<std::endl;
}
}
}
// ----------------------------------------------------------------------------------
template<typename Phen>
void _master_eval(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace trace("eval", DBG_HERE);
assert(pop.size());
assert(begin < pop.size());
assert(end <= pop.size());
// Number of eval iterations
const size_t count = end - begin;
LOG(INFO) << "Total: " << count << " | Batch: " << Params::image::batch << "\n";
// Evaluate phenotypes in parallel using TBB.
parallel::init();
parallel::p_for(
parallel::range_t(begin, end, Params::image::batch),
sferes::eval::parallel_tbb_eval<Phen>(pop, Params::image::model_definition, Params::image::pretrained_model));
// The barrier is implicitly set here after the for-loop in TBB.
}
boost::shared_ptr<boost::mpi::environment> _env;
boost::shared_ptr<boost::mpi::communicator> _world;
};
}
}
#endif

@ -1,238 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef BATCH_EVAL_MPI_TBB_PARALLEL_HPP_
#define BATCH_EVAL_MPI_TBB_PARALLEL_HPP_
#include <sferes/parallel.hpp>
#include <boost/mpi.hpp>
#include "tbb_parallel_eval.hpp"
#include <cmath>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
//#ifndef BOOST_MPI_HAS_NOARG_INITIALIZATION
//#error MPI need arguments (we require a full MPI2 implementation)
//#endif
#define MPI_INFO dbg::out(dbg::info, "mpi")<<"["<<_world->rank()<<"] "
namespace sferes {
namespace eval {
SFERES_CLASS(BatchMpiParallel) {
public:
BatchMpiParallel()
{
static char* argv[] = {(char*)"sferes2", 0x0};
char** argv2 = (char**) malloc(sizeof(char*) * 2);
int argc = 1;
argv2[0] = argv[0];
argv2[1] = argv[1];
using namespace boost;
dbg::out(dbg::info, "mpi")<<"Initializing MPI..."<<std::endl;
_env = shared_ptr<mpi::environment>(new mpi::environment(argc, argv2, true));
dbg::out(dbg::info, "mpi")<<"MPI initialized"<<std::endl;
_world = shared_ptr<mpi::communicator>(new mpi::communicator());
MPI_INFO << "communicator initialized"<<std::endl;
// Disable dumping out results for slave processes.
if (_world->rank() > 0)
{
Params::pop::dump_period = -1;
}
}
template<typename Phen>
void eval(std::vector<boost::shared_ptr<Phen> >& pop,
size_t begin, size_t end) {
dbg::trace("mpi", DBG_HERE);
// Develop phenotypes in parallel
// Each MPI process develops one phenotype
if (_world->rank() == 0)
_master_develop(pop, begin, end);
else
_slave_develop<Phen>();
// Make sure the processes have finished developing phenotypes
// Evaluate phenotypes in parallel but in batches of 256.
// Caffe GPU supports max of 512.
// There is no limit for CPU but we try to find out what batch size works best.
if (_world->rank() == 0)
{
_master_eval(pop, begin, end);
}
}
~BatchMpiParallel()
{
MPI_INFO << "Finalizing MPI..."<<std::endl;
std::string s("bye");
if (_world->rank() == 0)
for (size_t i = 1; i < _world->size(); ++i)
_world->send(i, _env->max_tag(), s);
_finalize();
}
protected:
void _finalize()
{
_world = boost::shared_ptr<boost::mpi::communicator>();
dbg::out(dbg::info, "mpi")<<"MPI world destroyed"<<std::endl;
_env = boost::shared_ptr<boost::mpi::environment>();
dbg::out(dbg::info, "mpi")<<"environment destroyed"<<std::endl;
}
template<typename Phen>
void _master_develop(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace("mpi", DBG_HERE);
size_t current = begin;
std::vector<bool> developed(pop.size());
std::fill(developed.begin(), developed.end(), false);
// first round
for (size_t i = 1; i < _world->size() && current < end; ++i) {
MPI_INFO << "[master] [send-init...] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
_world->send(i, current, pop[current]->gen());
MPI_INFO << "[master] [send-init ok] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
// send a new indiv each time we received a fitness
while (current < end) {
boost::mpi::status s = _recv(developed, pop);
MPI_INFO << "[master] [send...] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
_world->send(s.source(), current, pop[current]->gen());
MPI_INFO << "[master] [send ok] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
//join
bool done = true;
do {
dbg::out(dbg::info, "mpi")<<"joining..."<<std::endl;
done = true;
for (size_t i = begin; i < end; ++i)
if (!developed[i]) {
_recv(developed, pop);
done = false;
}
} while (!done);
}
template<typename Phen>
boost::mpi::status _recv(std::vector<bool>& developed,
std::vector<boost::shared_ptr<Phen> >& pop)
{
dbg::trace("mpi", DBG_HERE);
using namespace boost::mpi;
status s = _world->probe();
MPI_INFO << "[rcv...]" << getpid() << " tag=" << s.tag() << std::endl;
//_world->recv(s.source(), s.tag(), pop[s.tag()]->fit());
// Receive the whole developed phenotype from slave processes
Phen p;
_world->recv(s.source(), s.tag(), p);
// Assign the developed phenotype back to the current population for further evaluation
pop[s.tag()]->image() = p.image();
MPI_INFO << "[rcv ok]" << " tag=" << s.tag() << std::endl;
developed[s.tag()] = true;
return s;
}
template<typename Phen>
void _slave_develop()
{
dbg::trace("mpi", DBG_HERE);
while(true) {
Phen p;
boost::mpi::status s = _world->probe();
if (s.tag() == _env->max_tag()) {
MPI_INFO << "[slave] Quit requested" << std::endl;
MPI_Finalize();
exit(0);
} else {
MPI_INFO <<"[slave] [rcv...] [" << getpid()<< "]" << std::endl;
_world->recv(0, s.tag(), p.gen());
MPI_INFO <<"[slave] [rcv ok] " << " tag="<<s.tag()<<std::endl;
p.develop();
MPI_INFO <<"[slave] [send...]"<<" tag=" << s.tag()<<std::endl;
//_world->send(0, s.tag(), p.fit()); // Send only the fitness back to master process
// Send the whole phenotype back to master process
_world->send(0, s.tag(), p);
MPI_INFO <<"[slave] [send ok]"<<" tag=" << s.tag()<<std::endl;
}
}
}
// ----------------------------------------------------------------------------------
template<typename Phen>
void _master_eval(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace trace("eval", DBG_HERE);
assert(pop.size());
assert(begin < pop.size());
assert(end <= pop.size());
// Number of eval iterations
const size_t count = end - begin;
LOG(INFO) << "Total: " << count << " | Batch: " << Params::image::batch << "\n";
// Evaluate phenotypes in parallel using TBB.
parallel::init();
parallel::p_for(
parallel::range_t(begin, end, Params::image::batch),
sferes::eval::parallel_tbb_eval<Phen>(pop, Params::image::model_definition, Params::image::pretrained_model));
// The barrier is implicitly set here after the for-loop in TBB.
}
boost::shared_ptr<boost::mpi::environment> _env;
boost::shared_ptr<boost::mpi::communicator> _world;
};
}
}
#endif

@ -1,272 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EVAL_CUDA_PARALLEL_HPP_
#define EVAL_CUDA_PARALLEL_HPP_
#include <sferes/parallel.hpp>
#include <cmath>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <stdexcept>
namespace sferes {
namespace caffe
{
/**
* Using a shared_ptr to hold a pointer to a statically allocated object.
* http://www.boost.org/doc/libs/1_55_0/libs/smart_ptr/sp_techniques.html#static
*/
struct null_deleter
{
void operator()(void const *) const
{
}
};
class CaffeFactory
{
private:
static bool initialized;
static Net<float>* _net_1;
static Net<float>* _net_2;
static int _status;
public:
static shared_ptr<Net<float> > getCaffe(const std::string model_definition, const std::string pretrained_model)
{
if (!initialized)
{
// Initialize Caffe net 1
_net_1 = new Net<float>(model_definition);
// Get the trained model
_net_1->CopyTrainedLayersFrom(pretrained_model);
// Initialize Caffe net 2
_net_2 = new Net<float>(model_definition);
// Get the trained model
_net_2->CopyTrainedLayersFrom(pretrained_model);
initialized = true;
}
if (_status == 1)
{
_status = 2;
shared_ptr<Net<float> > c(_net_1, null_deleter());
return c;
}
else
{
_status = 1;
shared_ptr<Net<float> > c(_net_2, null_deleter());
return c;
}
}
CaffeFactory()
{
initialized = false;
_status = 1;
}
};
}
namespace eval {
/**
* Develop phenotypes in parallel using TBB.
*/
template<typename Phen>
struct _parallel_develop {
typedef std::vector<boost::shared_ptr<Phen> > pop_t;
pop_t _pop;
~_parallel_develop() { }
_parallel_develop(pop_t& pop) : _pop(pop) {}
_parallel_develop(const _parallel_develop& ev) : _pop(ev._pop) {}
void operator() (const parallel::range_t& r) const {
for (size_t i = r.begin(); i != r.end(); ++i) {
assert(i < _pop.size());
_pop[i]->develop();
}
}
};
SFERES_CLASS(CudaParallel)
{
private:
/**
* Develop phenotypes in parallel using TBB.
*/
template<typename Phen>
struct _parallel_cuda_eval {
typedef std::vector<boost::shared_ptr<Phen> > pop_t;
pop_t _pop;
~_parallel_cuda_eval() { }
_parallel_cuda_eval(pop_t& pop) : _pop(pop) {}
_parallel_cuda_eval(const _parallel_cuda_eval& ev) : _pop(ev._pop) {}
void operator() (const parallel::range_t& r) const
{
size_t begin = r.begin();
size_t end = r.end();
LOG(INFO) << "Begin: " << begin << " --> " << end << "\n";
dbg::trace trace("eval_cuda", DBG_HERE);
assert(_pop.size());
assert(begin < _pop.size());
assert(end <= _pop.size());
// Algorithm works as follow:
// Send the individuals to Caffe first
// Get back a list of results
// Assign the results to individuals
// Construct a list of images to be in the batch
std::vector<cv::Mat> images(0);
for (size_t i = begin; i < end; ++i)
{
cv::Mat output;
_pop[i]->imageBGR(output);
images.push_back( output ); // Add to a list of images
}
// Initialize Caffe net
shared_ptr<Net<float> > caffe_test_net = sferes::caffe::CaffeFactory::getCaffe(
Params::image::model_definition,
Params::image::pretrained_model
);
// shared_ptr<Net<float> > caffe_test_net =
// boost::shared_ptr<Net<float> >(new Net<float>(Params::image::model_definition));
//
// // Get the trained model
// caffe_test_net->CopyTrainedLayersFrom(Params::image::pretrained_model);
// Run ForwardPrefilled
float loss; // const vector<Blob<float>*>& result = caffe_test_net.ForwardPrefilled(&loss);
// Number of eval iterations
const size_t num_images = end - begin;
// Add images and labels manually to the ImageDataLayer
// vector<cv::Mat> images(num_images, image);
vector<int> labels(num_images, 0);
const shared_ptr<ImageDataLayer<float> > image_data_layer =
boost::static_pointer_cast<ImageDataLayer<float> >(
caffe_test_net->layer_by_name("data"));
image_data_layer->AddImagesAndLabels(images, labels);
// Classify this batch of 512 images
const vector<Blob<float>*>& result = caffe_test_net->ForwardPrefilled(&loss);
// Get the highest layer of Softmax
const float* argmaxs = result[1]->cpu_data();
// Get back a list of results
LOG(INFO) << "Number of results: " << result[1]->num() << "\n";
// Assign the results to individuals
for(int i = 0; i < num_images * 2; i += 2)
{
LOG(INFO)<< " Image: "<< i/2 + 1 << " class:" << argmaxs[i] << " : " << argmaxs[i+1] << "\n";
int pop_index = begin + i/2; // Index of individual in the batch
// Set the fitness of this individual
_pop[pop_index]->fit().setFitness((float) argmaxs[i+1]);
// For Map-Elite, set the cell description
_pop[pop_index]->fit().set_desc(0, argmaxs[i]);
}
}
};
public:
template<typename Phen>
void eval(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace trace("eval", DBG_HERE);
assert(pop.size());
assert(begin < pop.size());
assert(end <= pop.size());
// Develop phenotypes in parallel using TBB.
// The barrier is implicitly set here after the for-loop in TBB.
//parallel::init();
// We have only 2 GPUs per node
//tbb::task_scheduler_init init1(4);
parallel::p_for(parallel::range_t(begin, end),
_parallel_develop<Phen>(pop));
// Number of eval iterations
const size_t count = end - begin;
LOG(INFO) << "Size: " << count << " vs " << Params::image::batch << "\n";
// Load balancing
// We have only 2 GPUs per node
//tbb::task_scheduler_init init2(2);
parallel::p_for(
parallel::range_t(begin, end, Params::image::batch),
_parallel_cuda_eval<Phen>(pop));
}
};
}
}
bool sferes::caffe::CaffeFactory::initialized;
int sferes::caffe::CaffeFactory::_status;
Net<float>* sferes::caffe::CaffeFactory::_net_1;
Net<float>* sferes::caffe::CaffeFactory::_net_2;
#endif

@ -1,196 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EVAL_MPI_PARALLEL_HPP_
#define EVAL_MPI_PARALLEL_HPP_
#include <sferes/parallel.hpp>
#include <boost/mpi.hpp>
//#ifndef BOOST_MPI_HAS_NOARG_INITIALIZATION
//#error MPI need arguments (we require a full MPI2 implementation)
//#endif
#define MPI_INFO dbg::out(dbg::info, "mpi")<<"["<<_world->rank()<<"] "
namespace sferes {
namespace eval {
SFERES_CLASS(MpiParallel) {
public:
MpiParallel() {
static char* argv[] = {(char*)"sferes2", 0x0};
char** argv2 = (char**) malloc(sizeof(char*) * 2);
int argc = 1;
argv2[0] = argv[0];
argv2[1] = argv[1];
using namespace boost;
dbg::out(dbg::info, "mpi")<<"Initializing MPI..."<<std::endl;
_env = shared_ptr<mpi::environment>(new mpi::environment(argc, argv2, true));
dbg::out(dbg::info, "mpi")<<"MPI initialized"<<std::endl;
_world = shared_ptr<mpi::communicator>(new mpi::communicator());
MPI_INFO << "communicator initialized"<<std::endl;
// Disable dumping out results for slave processes.
if (_world->rank() > 0)
{
Params::pop::dump_period = -1;
}
}
template<typename Phen>
void eval(std::vector<boost::shared_ptr<Phen> >& pop,
size_t begin, size_t end) {
dbg::trace("mpi", DBG_HERE);
if (_world->rank() == 0)
_master_loop(pop, begin, end);
else
_slave_loop<Phen>();
}
~MpiParallel()
{
MPI_INFO << "Finalizing MPI..."<<std::endl;
std::string s("bye");
if (_world->rank() == 0)
for (size_t i = 1; i < _world->size(); ++i)
_world->send(i, _env->max_tag(), s);
_finalize();
}
protected:
void _finalize()
{
_world = boost::shared_ptr<boost::mpi::communicator>();
dbg::out(dbg::info, "mpi")<<"MPI world destroyed"<<std::endl;
_env = boost::shared_ptr<boost::mpi::environment>();
dbg::out(dbg::info, "mpi")<<"environment destroyed"<<std::endl;
}
template<typename Phen>
void _master_loop(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace("mpi", DBG_HERE);
size_t current = begin;
std::vector<bool> evaluated(pop.size());
std::fill(evaluated.begin(), evaluated.end(), false);
// first round
for (size_t i = 1; i < _world->size() && current < end; ++i) {
MPI_INFO << "[master] [send-init...] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
_world->send(i, current, pop[current]->gen());
MPI_INFO << "[master] [send-init ok] ->" <<i<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
// send a new indiv each time we received a fitness
while (current < end) {
boost::mpi::status s = _recv(evaluated, pop);
MPI_INFO << "[master] [send...] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
_world->send(s.source(), current, pop[current]->gen());
MPI_INFO << "[master] [send ok] ->" <<s.source()<<" [indiv="<<current<<"]"<<std::endl;
++current;
}
//join
bool done = true;
do {
dbg::out(dbg::info, "mpi")<<"joining..."<<std::endl;
done = true;
for (size_t i = begin; i < end; ++i)
if (!evaluated[i]) {
_recv(evaluated, pop);
done = false;
}
} while (!done);
}
template<typename Phen>
boost::mpi::status _recv(std::vector<bool>& evaluated,
std::vector<boost::shared_ptr<Phen> >& pop)
{
dbg::trace("mpi", DBG_HERE);
using namespace boost::mpi;
status s = _world->probe();
MPI_INFO << "[rcv...]" << getpid() << " tag=" << s.tag() << std::endl;
//_world->recv(s.source(), s.tag(), pop[s.tag()]->fit());
// Receive the whole developed phenotype from slave processes
Phen p;
_world->recv(s.source(), s.tag(), p);
// Assign the developed data back to the current population for further evaluation
pop[s.tag()]->fit() = p.fit();
pop[s.tag()]->image() = p.image();
MPI_INFO << "[rcv ok]" << " tag=" << s.tag() << std::endl;
evaluated[s.tag()] = true;
return s;
}
template<typename Phen>
void _slave_loop()
{
dbg::trace("mpi", DBG_HERE);
while(true) {
Phen p;
boost::mpi::status s = _world->probe();
if (s.tag() == _env->max_tag()) {
MPI_INFO << "[slave] Quit requested" << std::endl;
MPI_Finalize();
exit(0);
} else {
MPI_INFO <<"[slave] [rcv...] [" << getpid()<< "]" << std::endl;
_world->recv(0, s.tag(), p.gen());
MPI_INFO <<"[slave] [rcv ok] " << " tag="<<s.tag()<<std::endl;
p.develop();
p.fit().eval(p);
MPI_INFO <<"[slave] [send...]"<<" tag=" << s.tag()<<std::endl;
//_world->send(0, s.tag(), p.fit()); // Send only the fitness back to master process
// Send the whole phenotype back to master process
_world->send(0, s.tag(), p);
MPI_INFO <<"[slave] [send ok]"<<" tag=" << s.tag()<<std::endl;
}
}
}
boost::shared_ptr<boost::mpi::environment> _env;
boost::shared_ptr<boost::mpi::communicator> _world;
};
}
}
#endif

@ -1,87 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EVAL_TBB_PARALLEL_HPP_
#define EVAL_TBB_PARALLEL_HPP_
#include <sferes/parallel.hpp>
#include <cmath>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "tbb_parallel_develop.hpp"
#include "tbb_parallel_eval.hpp"
#include <stdexcept>
namespace sferes {
namespace eval {
SFERES_CLASS(TBBParallel)
{
public:
template<typename Phen>
void eval(std::vector<boost::shared_ptr<Phen> >& pop, size_t begin, size_t end)
{
dbg::trace trace("eval", DBG_HERE);
assert(pop.size());
assert(begin < pop.size());
assert(end <= pop.size());
// Develop phenotypes in parallel using TBB.
// The barrier is implicitly set here after the for-loop in TBB.
parallel::init();
parallel::p_for(parallel::range_t(begin, end),
sferes::eval::parallel_develop<Phen>(pop));
// Number of eval iterations
const size_t count = end - begin;
LOG(INFO) << "Size: " << count << " vs " << Params::image::batch << "\n";
// Evaluate phenotypes in parallel using TBB.
parallel::p_for(
parallel::range_t(begin, end, Params::image::batch),
sferes::eval::parallel_tbb_eval<Phen>(pop, Params::image::model_definition, Params::image::pretrained_model));
}
};
}
}
#endif

@ -1,66 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef TBB_PARALLEL_DEVELOP_HPP_
#define TBB_PARALLEL_DEVELOP_HPP_
#include <sferes/parallel.hpp>
namespace sferes {
namespace eval {
/**
* Develop phenotypes in parallel using TBB.
*/
template<typename Phen>
struct parallel_develop {
typedef std::vector<boost::shared_ptr<Phen> > pop_t;
pop_t _pop;
~parallel_develop() { }
parallel_develop(pop_t& pop) : _pop(pop) {}
parallel_develop(const parallel_develop& ev) : _pop(ev._pop) {}
void operator() (const parallel::range_t& r) const {
for (size_t i = r.begin(); i != r.end(); ++i) {
assert(i < _pop.size());
_pop[i]->develop();
}
}
};
}
}
#endif

@ -1,154 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EVAL_TBB_PARALLEL_EVAL_HPP_
#define EVAL_TBB_PARALLEL_EVAL_HPP_
#include <sferes/parallel.hpp>
#include <cmath>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "tbb_parallel_develop.hpp"
#include <stdexcept>
namespace sferes {
namespace eval {
/**
* Develop phenotypes in parallel using TBB.
*/
template<typename Phen>
struct parallel_tbb_eval {
typedef std::vector<boost::shared_ptr<Phen> > pop_t;
pop_t _pop;
std::string _model_definition;
std::string _pretrained_model;
~parallel_tbb_eval() { }
parallel_tbb_eval(pop_t& pop, const std::string model_definition, const std::string pretrained_model) :
_pop(pop),
_model_definition(model_definition),
_pretrained_model(pretrained_model)
{
}
parallel_tbb_eval(const parallel_tbb_eval& ev) :
_pop(ev._pop),
_model_definition(_model_definition),
_pretrained_model(_pretrained_model)
{
}
void operator() (const parallel::range_t& r) const
{
size_t begin = r.begin();
size_t end = r.end();
LOG(INFO) << "Begin: " << begin << " --> " << end << "\n";
dbg::trace trace("eval_cuda", DBG_HERE);
assert(_pop.size());
assert(begin < _pop.size());
assert(end <= _pop.size());
// Algorithm works as follow:
// Send the individuals to Caffe first
// Get back a list of results
// Assign the results to individuals
// Construct a list of images to be in the batch
std::vector<cv::Mat> images(0);
for (size_t i = begin; i < end; ++i)
{
cv::Mat output;
_pop[i]->imageBGR(output);
images.push_back( output ); // Add to a list of images
}
// Initialize Caffe net
shared_ptr<Net<float> > caffe_test_net =
boost::shared_ptr<Net<float> >(new Net<float>(_model_definition));
// Get the trained model
caffe_test_net->CopyTrainedLayersFrom(_pretrained_model);
// Run ForwardPrefilled
float loss; // const vector<Blob<float>*>& result = caffe_test_net.ForwardPrefilled(&loss);
// Number of eval iterations
const size_t num_images = end - begin;
// Add images and labels manually to the ImageDataLayer
// vector<cv::Mat> images(num_images, image);
vector<int> labels(num_images, 0);
const shared_ptr<ImageDataLayer<float> > image_data_layer =
boost::static_pointer_cast<ImageDataLayer<float> >(
caffe_test_net->layer_by_name("data"));
image_data_layer->AddImagesAndLabels(images, labels);
// Classify this batch of 512 images
const vector<Blob<float>*>& result = caffe_test_net->ForwardPrefilled(&loss);
// Get the highest layer of Softmax
const float* argmaxs = result[1]->cpu_data();
// Get back a list of results
LOG(INFO) << "Number of results: " << result[1]->num() << "\n";
// Assign the results to individuals
for(int i = 0; i < num_images * 2; i += 2)
{
LOG(INFO)<< " Image: "<< i/2 + 1 << " class:" << argmaxs[i] << " : " << argmaxs[i+1] << "\n";
int pop_index = begin + i/2; // Index of individual in the batch
// Set the fitness of this individual
_pop[pop_index]->fit().setFitness((float) argmaxs[i+1]);
// For Map-Elite, set the cell description
_pop[pop_index]->fit().set_desc(0, argmaxs[i]);
}
}
};
}
}
#endif

@ -1,296 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef FIT_DEEP_LEARNING_HPP
#define FIT_DEEP_LEARNING_HPP
#include <sferes/fit/fitness.hpp>
// Caffe -------------------------------------------------
#include <cuda_runtime.h>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <stdio.h>
#include <caffe/caffe.hpp>
#include <caffe/vision_layers.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
// Caffe -------------------------------------------------
using namespace caffe;
#define FIT_DEEP_LEARNING(Name) SFERES_FITNESS(Name, sferes::fit::Fitness)
namespace sferes
{
namespace fit
{
SFERES_FITNESS(FitDeepLearning, sferes::fit::Fitness)
{
protected:
/**
* Crop an image based on the coordinates and the size of the crop.
*/
static cv::Mat crop(const cv::Mat& image,
const size_t x, const size_t y, const size_t width, const size_t height, const size_t offset, const bool flip = false)
{
// Setup a rectangle to define your region of interest
// int x, int y, int width, int height
cv::Rect myROI(x, y, width, height); // top-left
// Crop the full image to that image contained by the rectangle myROI
// Note that this doesn't copy the data
cv::Mat croppedImage = image(myROI);
// Create a background image of size 256x256
cv::Mat background (Params::image::size, Params::image::size, CV_8UC3, cv::Scalar(255, 255, 255));
// Because we are using crop size of 227x227 which is odd, when the image size is even 256x256
// This adjustment helps aligning the crop.
int left = offset/2;
if (flip)
{
left++;
}
// Because Caffe requires 256x256 images, we paste the crop back to a dummy background.
croppedImage.copyTo(background(cv::Rect(left, offset/2, width, height)));
return background;
}
/**
* Create ten crops (4 corners, 1 center, and x2 for mirrors).
* Following Alex 2012 paper.
* The 10 crops are added back to the list.
*/
static void _createTenCrops(const cv::Mat& image, vector<cv::Mat>& list)
{
// Offset
const int crop_size = Params::image::crop_size;
const int offset = Params::image::size - crop_size;
// 1. Top-left
{
cv::Mat cropped = crop(image, 0, 0, crop_size, crop_size, offset);
// Add a crop to list
list.push_back(cropped);
cv::Mat flipped;
cv::flip(crop(image, 0, 0, crop_size, crop_size, offset, true), flipped, 1);
// Add a flipped crop to list
list.push_back(flipped);
}
// 2. Top-Right
{
cv::Mat cropped = crop(image, offset, 0, crop_size, crop_size, offset);
// Add a crop to list
list.push_back(cropped);
cv::Mat flipped;
cv::flip(crop(image, offset, 0, crop_size, crop_size, offset, true), flipped, 1);
// Add a flipped crop to list
list.push_back(flipped);
}
// 3. Bottom-left
{
cv::Mat cropped = crop(image, 0, offset, crop_size, crop_size, offset);
// Add a crop to list
list.push_back(cropped);
cv::Mat flipped;
cv::flip(crop(image, 0, offset, crop_size, crop_size, offset, true), flipped, 1);
// Add a flipped crop to list
list.push_back(flipped);
}
// 4. Bottom-right
{
cv::Mat cropped = crop(image, offset, offset, crop_size, crop_size, offset);
// Add a crop to list
list.push_back(cropped);
cv::Mat flipped;
cv::flip(crop(image, offset, offset, crop_size, crop_size, offset, true), flipped, 1);
// Add a flipped crop to list
list.push_back(flipped);
}
// 5. Center and its mirror
{
cv::Mat cropped = crop(image, offset/2, offset/2, crop_size, crop_size, offset);
// Add a crop to list
list.push_back(cropped);
cv::Mat flipped;
cv::flip(crop(image, offset/2, offset/2, crop_size, crop_size, offset, true), flipped, 1);
// Add a flipped crop to list
list.push_back(flipped);
}
}
private:
/**
* Evaluate the given image to see its probability in the given category.
*/
float _getProbability(const cv::Mat& image, const int category)
{
this->initCaffeNet(); //Initialize caffe
// Initialize test network
shared_ptr<Net<float> > caffe_test_net = shared_ptr<Net<float> >( new Net<float>(Params::image::model_definition));
// Get the trained model
caffe_test_net->CopyTrainedLayersFrom(Params::image::pretrained_model);
// Run ForwardPrefilled
float loss;
// Add images and labels manually to the ImageDataLayer
vector<int> labels(10, 0);
vector<cv::Mat> images;
// Add images to the list
if (Params::image::use_crops)
{
// Ten crops have been stored in the vector
_createTenCrops(image, images);
}
else
{
images.push_back(image);
}
// Classify images
const shared_ptr<ImageDataLayer<float> > image_data_layer =
boost::static_pointer_cast<ImageDataLayer<float> >(
caffe_test_net->layer_by_name("data"));
image_data_layer->AddImagesAndLabels(images, labels);
const vector<Blob<float>*>& result = caffe_test_net->ForwardPrefilled(&loss);
// Get the highest layer of Softmax
const float* softmax = result[1]->cpu_data();
// If use 10 crops, we have to average the predictions of 10 crops
if (Params::image::use_crops)
{
vector<double> values;
// Average the predictions of evaluating 10 crops
for(int i = 0; i < Params::image::num_categories; ++i)
{
boost::accumulators::accumulator_set<double, boost::accumulators::stats<boost::accumulators::tag::mean> > avg;
for(int j = 0; j < 10 * Params::image::num_categories; j += Params::image::num_categories)
{
avg(softmax[i + j]);
}
double mean = boost::accumulators::mean(avg);
values.push_back(mean);
}
return values[category];
}
// If use only 1 crop
else
{
return softmax[category];
}
}
public:
// Indiv will have the type defined in the main (phen_t)
template<typename Indiv>
void eval(const Indiv& ind)
{
// Convert image to BGR before evaluating
cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(ind.image(), output, CV_HLS2BGR);
// Evolve images to be categorized as a soccer ball
this->_value = _getProbability(output, Params::image::category_id);
}
// Indiv will have the type defined in the main (phen_t)
void setFitness(float value)
{
this->_value = value;
}
void initCaffeNet()
{
// Set test phase
Caffe::set_phase(Caffe::TEST);
if (Params::image::use_gpu)
{
// Set GPU mode
Caffe::set_mode(Caffe::GPU);
}
else
{
// Set CPU mode
Caffe::set_mode(Caffe::CPU);
}
}
};
}
}
#endif

@ -1,238 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef FIT_MAP_DEEP_LEARNING_HPP
#define FIT_MAP_DEEP_LEARNING_HPP
#include "fit_deep_learning.hpp"
#include <modules/map_elite/fit_map.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
// Headers specifics to the computations we need
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/max.hpp>
#define FIT_MAP_DEEP_LEARNING(Name) SFERES_FITNESS(Name, sferes::fit::FitDeepLearning)
namespace sferes
{
namespace fit
{
SFERES_FITNESS(FitMapDeepLearning, sferes::fit::FitDeepLearning)
{
/*
private:
struct ArgMax
{
unsigned int category;
float probability;
};
ArgMax getMaxProbability(const cv::Mat& image)
{
this->initCaffeNet(); //Initialize caffe
// Initialize test network
shared_ptr<Net<float> > caffe_test_net = shared_ptr<Net<float> >( new Net<float>(Params::image::model_definition));
// Get the trained model
caffe_test_net->CopyTrainedLayersFrom(Params::image::pretrained_model);
// Run ForwardPrefilled
float loss; // const vector<Blob<float>*>& result = caffe_test_net.ForwardPrefilled(&loss);
// Add images and labels manually to the ImageDataLayer
vector<cv::Mat> images(1, image);
vector<int> labels(1, 0);
const shared_ptr<ImageDataLayer<float> > image_data_layer =
boost::static_pointer_cast<ImageDataLayer<float> >(
caffe_test_net->layer_by_name("data"));
image_data_layer->AddImagesAndLabels(images, labels);
vector<Blob<float>* > dummy_bottom_vec;
const vector<Blob<float>*>& result = caffe_test_net->Forward(dummy_bottom_vec, &loss);
// Get the highest layer of Softmax
const float* argmax = result[1]->cpu_data();
ArgMax m;
m.category = (int) argmax[0]; // Category
m.probability = (float) argmax[1]; // Probability
return m;
}
*/
private:
void _setProbabilityList(const cv::Mat& image)
{
this->initCaffeNet(); //Initialize caffe
// Initialize test network
shared_ptr<Net<float> > caffe_test_net = shared_ptr<Net<float> >( new Net<float>(Params::image::model_definition));
// Get the trained model
caffe_test_net->CopyTrainedLayersFrom(Params::image::pretrained_model);
// Run ForwardPrefilled
float loss;
// Add images and labels manually to the ImageDataLayer
vector<int> labels(10, 0);
vector<cv::Mat> images;
// Add images to the list
if (Params::image::use_crops)
{
// Ten crops have been stored in the vector
this->_createTenCrops(image, images);
}
else
{
images.push_back(image);
}
// Classify images
const shared_ptr<ImageDataLayer<float> > image_data_layer =
boost::static_pointer_cast<ImageDataLayer<float> >(
caffe_test_net->layer_by_name("data"));
image_data_layer->AddImagesAndLabels(images, labels);
const vector<Blob<float>*>& result = caffe_test_net->ForwardPrefilled(&loss);
// Get the highest layer of Softmax
const float* softmax = result[1]->cpu_data();
vector<double> values;
boost::accumulators::accumulator_set<double, boost::accumulators::stats<boost::accumulators::tag::max> > max;
// Clear the probability in case it is called twice
_prob.clear();
// If use 10 crops, we have to average the predictions of 10 crops
if (Params::image::use_crops)
{
// Average the predictions of evaluating 10 crops
for(int i = 0; i < Params::image::num_categories; ++i)
{
boost::accumulators::accumulator_set<double, boost::accumulators::stats<boost::accumulators::tag::mean> > avg;
for(int j = 0; j < 10 * Params::image::num_categories; j += Params::image::num_categories)
{
avg(softmax[i + j]);
}
double mean = boost::accumulators::mean(avg);
// Push 1000 probabilities in the list
_prob.push_back(mean);
max(mean); // Add this mean to a list for computing the max later
}
}
else
{
for(int i = 0; i < Params::image::num_categories; ++i)
{
float v = softmax[i];
// Push 1000 probabilities in the list
_prob.push_back(v);
max(v); // Add this mean to a list for computing the max later
}
}
float max_prob = boost::accumulators::max(max);
// Set the fitness
this->_value = max_prob;
}
public:
FitMapDeepLearning() : _prob(Params::image::num_categories) { }
const std::vector<float>& desc() const { return _prob; }
// Indiv will have the type defined in the main (phen_t)
template<typename Indiv>
void eval(const Indiv& ind)
{
if (Params::image::color)
{
// Convert image to BGR before evaluating
cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(ind.image(), output, CV_HLS2BGR);
// Create an empty list to store get 1000 probabilities
_setProbabilityList(output);
}
else // Grayscale
{
// Create an empty list to store get 1000 probabilities
_setProbabilityList(ind.image());
}
}
float value(int category) const
{
assert(category < _prob.size());
return _prob[category];
}
float value() const
{
return this->_value;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
sferes::fit::Fitness<Params, typename stc::FindExact<FitMapDeepLearning<Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & BOOST_SERIALIZATION_NVP(_prob);
}
protected:
std::vector<float> _prob; // List of probabilities
};
}
}
#endif

@ -1,245 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef EVO_FLOAT_IMAGE_HPP_
#define EVO_FLOAT_IMAGE_HPP_
#include <vector>
#include <limits>
#include <boost/foreach.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/nvp.hpp>
#include <sferes/stc.hpp>
#include <sferes/misc.hpp>
#include <sferes/dbg/dbg.hpp>
#include <sferes/gen/float.hpp>
#include <iostream>
#include <cmath>
namespace sferes {
namespace gen {
namespace evo_float_image {
enum mutation_t { polynomial = 0, gaussian, uniform };
enum cross_over_t { recombination = 0, sbx, no_cross_over };
template<typename Ev, unsigned long int T>
struct Mutation_f {
void operator()(Ev& ev, size_t i) {
assert(0);
}
};
template<typename Ev, unsigned long int T>
struct CrossOver_f {
void operator()(const Ev& f1, const Ev& f2, Ev &c1, Ev &c2) {
assert(0);
}
};
}
/// in range [0;1]
template<unsigned long int Size, typename Params, typename Exact = stc::Itself>
class EvoFloatImage :
public Float<Size, Params,
typename stc::FindExact<Float<Size, Params, Exact>, Exact>::ret> {
public:
typedef Params params_t;
typedef EvoFloatImage<Size, Params, Exact> this_t;
EvoFloatImage() {}
//@{
void mutate() {
for (size_t i = 0; i < Size; i++)
if (misc::rand<float>() < Params::evo_float_image::mutation_rate)
_mutation_op(*this, i);
_check_invariant();
}
void cross(const EvoFloatImage& o, EvoFloatImage& c1, EvoFloatImage& c2) {
if (Params::evo_float_image::cross_over_type != evo_float_image::no_cross_over &&
misc::rand<float>() < Params::evo_float_image::cross_rate)
_cross_over_op(*this, o, c1, c2);
else if (misc::flip_coin()) {
c1 = *this;
c2 = o;
} else {
c1 = o;
c2 = *this;
}
_check_invariant();
}
void random() {
BOOST_FOREACH(float &v, this->_data) v = misc::rand<float>();
_check_invariant();
}
//@}
protected:
evo_float_image::Mutation_f<this_t, Params::evo_float_image::mutation_type> _mutation_op;
evo_float_image::CrossOver_f<this_t, Params::evo_float_image::cross_over_type> _cross_over_op;
void _check_invariant() const {
#ifdef DBG_ENABLED
BOOST_FOREACH(float p, this->_data) {
assert(!std::isnan(p));
assert(!std::isinf(p));
assert(p >= 0 && p <= 1);
}
#endif
}
};
// partial specialization for operators
namespace evo_float_image {
// polynomial mutation. Cf Deb 2001, p 124 ; param: eta_m
// perturbation of the order O(1/eta_m)
template<typename Ev>
struct Mutation_f<Ev, polynomial> {
void operator()(Ev& ev, size_t i) {
SFERES_CONST float eta_m = Ev::params_t::evo_float_image::eta_m;
assert(eta_m != -1.0f);
float ri = misc::rand<float>();
float delta_i = ri < 0.5 ?
pow(2.0 * ri, 1.0 / (eta_m + 1.0)) - 1.0 :
1 - pow(2.0 * (1.0 - ri), 1.0 / (eta_m + 1.0));
assert(!std::isnan(delta_i));
assert(!std::isinf(delta_i));
float f = ev.data(i) + delta_i;
ev.data(i, misc::put_in_range(f, 0.0f, 1.0f));
}
};
// gaussian mutation
template<typename Ev>
struct Mutation_f<Ev, gaussian> {
void operator()(Ev& ev, size_t i) {
SFERES_CONST float sigma = Ev::params_t::evo_float_image::sigma;
float f = ev.data(i)
+ misc::gaussian_rand<float>(0, sigma * sigma);
ev.data(i, misc::put_in_range(f, 0.0f, 1.0f));
}
};
// uniform mutation
template<typename Ev>
struct Mutation_f<Ev, uniform> {
void operator()(Ev& ev, size_t i) {
SFERES_CONST float max = Ev::params_t::evo_float_image::max;
float f = ev.data(i)
+ misc::rand<float>(max) - max / 2.0f;
ev.data(i, misc::put_in_range(f, 0.0f, 1.0f));
}
};
// recombination
template<typename Ev>
struct CrossOver_f<Ev, recombination> {
void operator()(const Ev& f1, const Ev& f2, Ev &c1, Ev &c2) {
size_t k = misc::rand<unsigned long int>(f1.size());
for (size_t i = 0; i < k; ++i) {
c1.data(i, f1.data(i));
c2.data(i, f2.data(i));
}
for (size_t i = k; i < f1.size(); ++i) {
c1.data(i, f2.data(i));
c2.data(i, f1.data(i));
}
}
};
// no cross-over
template<typename Ev>
struct CrossOver_f<Ev, no_cross_over> {
void operator()(const Ev& f1, const Ev& f2, Ev &c1, Ev &c2) {
}
};
// SBX (cf Deb 2001, p 113) Simulated Binary Crossover
// suggested eta : 15
/// WARNING : this code is from deb's code (different from the
// article ...)
// A large value ef eta gives a higher probablitity for
// creating a `near-parent' solutions and a small value allows
// distant solutions to be selected as offspring.
template<typename Ev>
struct CrossOver_f<Ev, sbx> {
void operator()(const Ev& f1, const Ev& f2, Ev &child1, Ev &child2) {
SFERES_CONST float eta_c = Ev::params_t::evo_float_image::eta_c;
assert(eta_c != -1);
for (unsigned long int i = 0; i < f1.size(); i++) {
float y1 = std::min(f1.data(i), f2.data(i));
float y2 = std::max(f1.data(i), f2.data(i));
SFERES_CONST float yl = 0.0;
SFERES_CONST float yu = 1.0;
if (fabs(y1 - y2) > std::numeric_limits<float>::epsilon()) {
float rand = misc::rand<float>();
float beta = 1.0 + (2.0 * (y1 - yl) / (y2 - y1));
float alpha = 2.0 - pow(beta, -(eta_c + 1.0));
float betaq = 0;
if (rand <= (1.0 / alpha))
betaq = pow((rand * alpha), (1.0 / (eta_c + 1.0)));
else
betaq = pow ((1.0 / (2.0 - rand * alpha)) , (1.0 / (eta_c + 1.0)));
float c1 = 0.5 * ((y1 + y2) - betaq * (y2 - y1));
beta = 1.0 + (2.0 * (yu - y2) / (y2 - y1));
alpha = 2.0 - pow(beta, -(eta_c + 1.0));
if (rand <= (1.0 / alpha))
betaq = pow ((rand * alpha), (1.0 / (eta_c + 1.0)));
else
betaq = pow ((1.0/(2.0 - rand * alpha)), (1.0 / (eta_c + 1.0)));
float c2 = 0.5 * ((y1 + y2) + betaq * (y2 - y1));
c1 = misc::put_in_range(c1, yl, yu);
c2 = misc::put_in_range(c2, yl, yu);
assert(!std::isnan(c1));
assert(!std::isnan(c2));
if (misc::flip_coin()) {
child1.data(i, c1);
child2.data(i, c2);
} else {
child1.data(i, c2);
child2.data(i, c1);
}
}
}
}
};
} //evo_float_image
} // gen
} // sferes
#endif

Binary file not shown.

Before

Width:  |  Height:  |  Size: 109 KiB

@ -1 +0,0 @@
/home/anh/workspace/sferes/exp/images/imagenet/hen_256.png 1

@ -1,254 +0,0 @@
name: "CaffeNet"
layers {
name: "data"
type: IMAGE_DATA
top: "data"
top: "label"
image_data_param {
source: "/home/anh/workspace/sferes/exp/images/imagenet/image_list.txt"
mean_file: "/home/anh/src/caffe/data/ilsvrc12/imagenet_mean.binaryproto"
batch_size: 1
crop_size: 227
mirror: false
new_height: 256
new_width: 256
}
}
layers {
name: "conv1"
type: CONVOLUTION
bottom: "data"
top: "conv1"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 96
kernel_size: 11
stride: 4
}
}
layers {
name: "relu1"
type: RELU
bottom: "conv1"
top: "conv1"
}
layers {
name: "pool1"
type: POOLING
bottom: "conv1"
top: "pool1"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layers {
name: "norm1"
type: LRN
bottom: "pool1"
top: "norm1"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layers {
name: "conv2"
type: CONVOLUTION
bottom: "norm1"
top: "conv2"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 256
pad: 2
kernel_size: 5
group: 2
}
}
layers {
name: "relu2"
type: RELU
bottom: "conv2"
top: "conv2"
}
layers {
name: "pool2"
type: POOLING
bottom: "conv2"
top: "pool2"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layers {
name: "norm2"
type: LRN
bottom: "pool2"
top: "norm2"
lrn_param {
local_size: 5
alpha: 0.0001
beta: 0.75
}
}
layers {
name: "conv3"
type: CONVOLUTION
bottom: "norm2"
top: "conv3"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
}
}
layers {
name: "relu3"
type: RELU
bottom: "conv3"
top: "conv3"
}
layers {
name: "conv4"
type: CONVOLUTION
bottom: "conv3"
top: "conv4"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 384
pad: 1
kernel_size: 3
group: 2
}
}
layers {
name: "relu4"
type: RELU
bottom: "conv4"
top: "conv4"
}
layers {
name: "conv5"
type: CONVOLUTION
bottom: "conv4"
top: "conv5"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
convolution_param {
num_output: 256
pad: 1
kernel_size: 3
group: 2
}
}
layers {
name: "relu5"
type: RELU
bottom: "conv5"
top: "conv5"
}
layers {
name: "pool5"
type: POOLING
bottom: "conv5"
top: "pool5"
pooling_param {
pool: MAX
kernel_size: 3
stride: 2
}
}
layers {
name: "fc6"
type: INNER_PRODUCT
bottom: "pool5"
top: "fc6"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
inner_product_param {
num_output: 4096
}
}
layers {
name: "relu6"
type: RELU
bottom: "fc6"
top: "fc6"
}
layers {
name: "drop6"
type: DROPOUT
bottom: "fc6"
top: "fc6"
dropout_param {
dropout_ratio: 0.5
}
}
layers {
name: "fc7"
type: INNER_PRODUCT
bottom: "fc6"
top: "fc7"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
inner_product_param {
num_output: 4096
}
}
layers {
name: "relu7"
type: RELU
bottom: "fc7"
top: "fc7"
}
layers {
name: "drop7"
type: DROPOUT
bottom: "fc7"
top: "fc7"
dropout_param {
dropout_ratio: 0.5
}
}
layers {
name: "fc8"
type: INNER_PRODUCT
bottom: "fc7"
top: "fc8"
blobs_lr: 1
blobs_lr: 2
weight_decay: 1
weight_decay: 0
inner_product_param {
num_output: 1000
}
}
layers {
name: "prob"
type: SOFTMAX
bottom: "fc8"
top: "prob"
}

@ -1,64 +0,0 @@
/*
* cvmat_serialization.h
*
* Created on: Jul 11, 2014
* Author: anh
*/
#ifndef CVMAT_SERIALIZATION_H_
#define CVMAT_SERIALIZATION_H_
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/vector.hpp>
BOOST_SERIALIZATION_SPLIT_FREE(cv::Mat)
namespace boost {
namespace serialization {
/** Serialization support for cv::Mat */
template<class Archive>
void save(Archive & ar, const cv::Mat& m, const unsigned int version)
{
size_t elem_size = m.elemSize();
size_t elem_type = m.type();
int cols = m.cols;
int rows = m.rows;
ar & BOOST_SERIALIZATION_NVP(cols);
ar & BOOST_SERIALIZATION_NVP(rows);
ar & BOOST_SERIALIZATION_NVP(elem_size);
ar & BOOST_SERIALIZATION_NVP(elem_type);
const size_t data_size = cols * rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
/** Serialization support for cv::Mat */
template<class Archive>
void load(Archive & ar, cv::Mat& m, const unsigned int version)
{
int cols, rows;
size_t elem_size, elem_type;
ar & BOOST_SERIALIZATION_NVP(cols);
ar & BOOST_SERIALIZATION_NVP(rows);
ar & BOOST_SERIALIZATION_NVP(elem_size);
ar & BOOST_SERIALIZATION_NVP(elem_type);
m.create(rows, cols, elem_type);
size_t data_size = m.cols * m.rows * elem_size;
ar & boost::serialization::make_array(m.ptr(), data_size);
}
}
}
#endif /* CVMAT_SERIALIZATION_H_ */

@ -1,265 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_COLOR_IMAGE_HPP
#define PHEN_COLOR_IMAGE_HPP
#include <map>
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
// New stuff added ------------------------------------------
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/join.hpp>
#include <string>
#include "cvmat_serialization.h" // Serialize cv::Mat
#include <glog/logging.h> // Google Logging
#include "phen_image.hpp" // Base Image class
// New stuff added ------------------------------------------
namespace sferes
{
namespace phen
{
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(ColorImage, Image)
{
public:
typedef Gen gen_t;
typedef typename gen_t::nn_t gen_nn_t;
SFERES_CONST size_t nb_cppn_inputs = 2 + 2;
SFERES_CONST size_t nb_cppn_outputs = 3; // Red, Green, Blue
ColorImage():_developed(false)
{
}
void develop()
{
// Check if phenotype has not been developed
if (!_developed)
{
// Initialize the image to be a white background image
reset_image();
this->gen().init();
// develop the parameters
BGL_FORALL_VERTICES_T(v, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
{
this->gen().get_graph()[v].get_afparams().develop();
this->gen().get_graph()[v].get_pfparams().develop();
}
BGL_FORALL_EDGES_T(e, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
this->gen().get_graph()[e].get_weight().develop();
assert(nb_cppn_inputs == this->gen().get_nb_inputs());
assert(nb_cppn_outputs == this->gen().get_nb_outputs());
// Change specific color of every pixel in the image
for (int x = 0; x < _image.cols; ++x)
{
for (int y = 0; y < _image.rows; ++y)
{
std::vector<float> output = cppn_value(x, y); // HLS array
cv::Vec3b color = _image.at<cv::Vec3b>(cv::Point(x,y));
color[0] = this->convert_to_color_scale(255, output[0]); // H
color[1] = this->convert_to_color_scale(255, output[1]); // L
color[2] = this->convert_to_color_scale(255, output[2]); // S
_image.at<cv::Vec3b>(cv::Point(x,y)) = color;
}
}
_developed = true; // Raise the flag that this phenotype has been developed.
}
}
/**
* Programmatically put the patterns in here.
*/
void reset_image()
{
// Paint background : white
_image = cv::Mat(Params::image::size, Params::image::size, CV_8UC3, cv::Scalar(255,255,255));
}
double normalize_map_xy_to_grid(const int & r_xyVal, const int & r_numVoxelsXorY)
{
// turn the xth or yth node into its coordinates on a grid from -1 to 1, e.g. x values (1,2,3,4,5) become (-1, -.5 , 0, .5, 1)
// this works with even numbers, and for x or y grids only 1 wide/tall, which was not the case for the original
// e.g. see findCluster for the orignal versions where it was not a funciton and did not work with odd or 1 tall/wide #s
double coord;
if (r_numVoxelsXorY==1) coord = 0;
else coord = -1 + ( r_xyVal * 2.0/(r_numVoxelsXorY-1) );
return(coord);
}
std::vector<float> cppn_value(size_t i, size_t j)
{
// Euclidean distance from center
const float xNormalized = normalize_map_xy_to_grid(i, Params::image::size);
const float yNormalized = normalize_map_xy_to_grid(j, Params::image::size);
const float distanceFromCenter = sqrt(pow(double(xNormalized),2.0)+pow(double(yNormalized),2.0));
// CPPN inputs
std::vector<float> in(nb_cppn_inputs);
this->gen().init();
in[0] = i; // x
in[1] = j; // y
in[2] = distanceFromCenter; // distance from center
in[3] = 1.0; // bias
for (size_t k = 0; k < this->gen().get_depth(); ++k)
this->gen().step(in);
// Get the CPPN output
std::vector<float> out(nb_cppn_outputs);
out[0] = this->gen().get_outf(0); // Hue
out[1] = this->gen().get_outf(1); // Lightness
out[2] = this->gen().get_outf(2); // Saturation
return out;
}
/**
* Convert [-1, 1] range to a color scale
* [0, 255] for Saturation / Brightness or
* [0, 180] for Hue
*/
static int convert_to_color_scale(const int scale, const float value)
{
int color = value * scale;
if (value < 0)
{
color *= -1;
}
return color;
}
void write_png_image(const std::string fileName, const cv::Mat& map)
{
// Read the target bitmap
try
{
cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(map, output, CV_HLS2BGR);
// // DEBUGGING
// // Convert to 256x256
// cv::Size size(256, 256);
// resize(output, output, size);
// Parameters for cv::imwrite
std::vector<int> write_params;
write_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
write_params.push_back(0); // Fastest writing without compression
// Write to a file
imwrite(fileName, output, write_params);
}
catch (std::runtime_error& ex)
{
std::cout << "Failed to write image: " << fileName << std::endl;
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
void log_best_image_fitness(const std::string title)
{
std::vector < std::string > list;
list.push_back (title);
list.push_back (".png");
const std::string fileName = boost::algorithm::join (list, "");
write_png_image(fileName, _image);
std::cout << "Written to " << title << std::endl;
}
cv::Mat& image() {
return _image;
}
const cv::Mat& image() const {
return _image;
}
/**
* Returns image in BGR color space.
*/
void imageBGR(cv::Mat& output) {
// Convert image to BGR before evaluating
// cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(_image, output, CV_HLS2BGR);
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
dbg::trace trace("phen", DBG_HERE);
sferes::phen::Indiv<Gen, Fit, Params, typename stc::FindExact<ColorImage<Gen, Fit, Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & BOOST_SERIALIZATION_NVP(_image);
ar & BOOST_SERIALIZATION_NVP(_developed);
}
protected:
cv::Mat _image;
bool _developed;
};
}
}
#endif

@ -1,233 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_GRAYSCALE_IMAGE_HPP
#define PHEN_GRAYSCALE_IMAGE_HPP
#include <map>
#include "phen_image.hpp"
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
// New stuff added ------------------------------------------
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/join.hpp>
#include <string>
#include "cvmat_serialization.h" // Serialize cv::Mat
#include <glog/logging.h> // Google Logging
// New stuff added ------------------------------------------
namespace sferes
{
namespace phen
{
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(GrayscaleImage, Image)
{
public:
typedef Gen gen_t;
typedef typename gen_t::nn_t gen_nn_t;
SFERES_CONST size_t nb_cppn_inputs = Params::dnn::nb_inputs;
SFERES_CONST size_t nb_cppn_outputs = Params::dnn::nb_outputs; // Red, Green, Blue
GrayscaleImage():_developed(false)
{
}
void develop()
{
// Check if phenotype has not been developed
if (!_developed)
{
// Initialize the image to be a white background image
reset_image();
this->gen().init();
// develop the parameters
BGL_FORALL_VERTICES_T(v, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
{
this->gen().get_graph()[v].get_afparams().develop();
this->gen().get_graph()[v].get_pfparams().develop();
}
BGL_FORALL_EDGES_T(e, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
this->gen().get_graph()[e].get_weight().develop();
assert(nb_cppn_inputs == this->gen().get_nb_inputs());
assert(nb_cppn_outputs == this->gen().get_nb_outputs());
// Change specific color of every pixel in the image
for (int x = 0; x < _image.cols; ++x)
{
for (int y = 0; y < _image.rows; ++y)
{
float output = cppn_value(x, y); // Single grayscale value (intensity)
// Change pixel intensity of grayscale images
// Ref: http://docs.opencv.org/doc/user_guide/ug_mat.html
_image.at<uchar>(cv::Point(x,y)) = convert_to_color_scale(255, output);
}
}
_developed = true; // Raise the flag that this phenotype has been developed.
}
}
/**
* Programmatically put the patterns in here.
*/
void reset_image()
{
// Paint background : black
_image = cv::Mat(Params::image::size, Params::image::size, CV_8UC1, cv::Scalar(0, 0, 0));
}
double normalize_map_xy_to_grid(const int & r_xyVal, const int & r_numVoxelsXorY)
{
// turn the xth or yth node into its coordinates on a grid from -1 to 1, e.g. x values (1,2,3,4,5) become (-1, -.5 , 0, .5, 1)
// this works with even numbers, and for x or y grids only 1 wide/tall, which was not the case for the original
// e.g. see findCluster for the orignal versions where it was not a funciton and did not work with odd or 1 tall/wide #s
double coord;
if (r_numVoxelsXorY==1) coord = 0;
else coord = -1 + ( r_xyVal * 2.0/(r_numVoxelsXorY-1) );
return(coord);
}
float cppn_value(size_t i, size_t j)
{
// Euclidean distance from center
const float xNormalized = normalize_map_xy_to_grid(i, Params::image::size);
const float yNormalized = normalize_map_xy_to_grid(j, Params::image::size);
const float distanceFromCenter = sqrt(pow(double(xNormalized),2.0)+pow(double(yNormalized),2.0));
// CPPN inputs
std::vector<float> in(nb_cppn_inputs);
this->gen().init();
in[0] = i; // x
in[1] = j; // y
in[2] = distanceFromCenter; // distance from center
in[3] = 1.0; // bias
for (size_t k = 0; k < this->gen().get_depth(); ++k)
this->gen().step(in);
// Get the CPPN output
return this->gen().get_outf(0); // Grayscale value
}
/**
* Convert [-1, 1] range to a color scale
* [0, 255] for Saturation / Brightness or
* [0, 180] for Hue
*/
static int convert_to_color_scale(const int scale, const float value)
{
int color = value * scale;
if (value < 0)
{
color *= -1;
}
return color;
}
void write_png_image(const std::string fileName, const cv::Mat& map)
{
// Read the target bitmap
try
{
// Parameters for cv::imwrite
std::vector<int> write_params;
write_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
write_params.push_back(0); // Fastest writing without compression
// Write to a file
imwrite(fileName, map, write_params);
}
catch (std::runtime_error& ex)
{
std::cout << "Failed to write image: " << fileName << std::endl;
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
void log_best_image_fitness(const std::string title)
{
std::vector < std::string > list;
list.push_back (title);
list.push_back (".png");
const std::string fileName = boost::algorithm::join (list, "");
write_png_image(fileName, _image);
std::cout << "Written to " << title << std::endl;
}
cv::Mat& image() {
return _image;
}
const cv::Mat& image() const {
return _image;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
dbg::trace trace("phen", DBG_HERE);
sferes::phen::Image<Gen, Fit, Params, typename stc::FindExact<GrayscaleImage<Gen, Fit, Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & BOOST_SERIALIZATION_NVP(_image);
ar & BOOST_SERIALIZATION_NVP(_developed);
}
protected:
cv::Mat _image;
bool _developed;
};
}
}
#endif

@ -1,183 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_GRAYSCALE_IMAGE_DIRECT_HPP
#define PHEN_GRAYSCALE_IMAGE_DIRECT_HPP
#include <map>
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
// New stuff added ------------------------------------------
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/join.hpp>
#include <string>
#include "cvmat_serialization.h" // Serialize cv::Mat
#include <glog/logging.h> // Google Logging
#include "phen_image.hpp" // Base Image class
// New stuff added ------------------------------------------
namespace sferes
{
namespace phen
{
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(GrayscaleImageDirect, Image)
{
public:
GrayscaleImageDirect():_developed(false)
{
}
void develop()
{
// Check if phenotype has not been developed
if (!_developed)
{
// Initialize the image to be a white background image
reset_image();
unsigned i = 0; // Index to access genome
// Change specific color of every pixel in the image
for (int x = 0; x < _image.cols; ++x)
{
for (int y = 0; y < _image.rows; ++y)
{
float output = this->_gen.data(i);
// Change pixel intensity of grayscale images
// Ref: http://docs.opencv.org/doc/user_guide/ug_mat.html
_image.at<uchar>(cv::Point(x,y)) = convert_to_color_scale(255, output);
++i; // Move to the next pixel location in genome
}
}
_developed = true; // Raise the flag that this phenotype has been developed.
}
}
/**
* Programmatically put the patterns in here.
*/
void reset_image()
{
// Paint background : black
_image = cv::Mat(Params::image::size, Params::image::size, CV_8UC1, cv::Scalar(0, 0, 0));
}
/**
* Convert [-1, 1] range to a color scale
* [0, 255] for Saturation / Brightness or
* [0, 180] for Hue
*/
static int convert_to_color_scale(const int scale, const float value)
{
int color = value * scale;
if (value < 0)
{
color *= -1;
}
return color;
}
void write_png_image(const std::string fileName, const cv::Mat& map)
{
// Read the target bitmap
try
{
// Parameters for cv::imwrite
std::vector<int> write_params;
write_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
write_params.push_back(0); // Fastest writing without compression
// Write to a file
imwrite(fileName, map, write_params);
}
catch (std::runtime_error& ex)
{
std::cout << "Failed to write image: " << fileName << std::endl;
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
void log_best_image_fitness(const std::string title)
{
std::vector < std::string > list;
list.push_back (title);
list.push_back (".png");
const std::string fileName = boost::algorithm::join (list, "");
write_png_image(fileName, _image);
std::cout << "Written to " << title << std::endl;
}
cv::Mat& image() {
return _image;
}
const cv::Mat& image() const {
return _image;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
dbg::trace trace("phen", DBG_HERE);
sferes::phen::Indiv<Gen, Fit, Params, typename stc::FindExact<GrayscaleImageDirect<Gen, Fit, Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & BOOST_SERIALIZATION_NVP(_image);
ar & BOOST_SERIALIZATION_NVP(_developed);
}
protected:
cv::Mat _image;
bool _developed;
};
}
}
#endif

@ -1,119 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_IMAGE_HPP
#define PHEN_IMAGE_HPP
#include <map>
#include <sferes/phen/indiv.hpp>
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
// New stuff added ------------------------------------------
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/join.hpp>
#include <string>
#include "cvmat_serialization.h" // Serialize cv::Mat
#include <glog/logging.h> // Google Logging
//#include <boost/uuid/uuid.hpp> // uuid class
#include <boost/uuid/uuid_generators.hpp> // generators
#include <boost/uuid/uuid_io.hpp> // streaming operators etc.
#include <boost/uuid/uuid_serialize.hpp> // serialization
// New stuff added ------------------------------------------
namespace sferes
{
namespace phen
{
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(Image, Indiv)
{
public:
Image(): _created_gen(0)
{
boost::uuids::uuid uuid = boost::uuids::random_generator()();
_id = uuid;
}
/*
* Get the ID of this organism.
*/
boost::uuids::uuid id()
{
return _id;
}
/*
* Set the generation when this organism is created.
*/
void set_created_gen(const size_t generation)
{
_created_gen = generation;
}
/*
* Get the generation when this organism is created.
*/
size_t created_gen() const
{
return _created_gen;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
sferes::phen::Indiv<Gen, Fit, Params, typename stc::FindExact<Image<Gen, Fit, Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & boost::serialization::make_nvp("uuid", _id.data);
ar & BOOST_SERIALIZATION_NVP(_created_gen);
}
protected:
boost::uuids::uuid _id; // The unique id of this organism
size_t _created_gen; // The generation when this image is created
};
}
}
#endif

@ -1,210 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_IMAGE_DIRECT_HPP
#define PHEN_IMAGE_DIRECT_HPP
#include <map>
#include "phen_image.hpp"
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include <modules/nn2/gen_hyper_nn.hpp>
// New stuff added ------------------------------------------
#include <cmath>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string/join.hpp>
#include <string>
#include "cvmat_serialization.h" // Serialize cv::Mat
#include <glog/logging.h> // Google Logging
// New stuff added ------------------------------------------
namespace sferes
{
namespace phen
{
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(ImageDirect, Image)
{
public:
ImageDirect():_developed(false)
{
}
void develop()
{
// Check if phenotype has not been developed
if (!_developed)
{
// Initialize the image to be a white background image
reset_image();
unsigned long int i = 0; // Index to access genome
// Change specific color of every pixel in the image
for (int x = 0; x < _image.cols; ++x)
{
for (int y = 0; y < _image.rows; ++y)
{
std::vector<float> output;
// Extract 3 values for H, L, S
for (int v = 0; v < 3; ++v)
{
output.push_back(this->_gen.data(i));
++i; // Move to the next color value for the current pixel location in genome
}
cv::Vec3b color = _image.at<cv::Vec3b>(cv::Point(x,y));
color[0] = convert_to_color_scale(255, output[0]); // H
color[1] = convert_to_color_scale(255, output[1]); // L
color[2] = convert_to_color_scale(255, output[2]); // S
_image.at<cv::Vec3b>(cv::Point(x,y)) = color;
}
}
_developed = true; // Raise the flag that this phenotype has been developed.
}
}
/**
* Programmatically put the patterns in here.
*/
void reset_image()
{
// Paint background : white
_image = cv::Mat(Params::image::size, Params::image::size, CV_8UC3, cv::Scalar(255,255,255));
}
/**
* Convert [-1, 1] range to a color scale
* [0, 255] for Saturation / Brightness or
* [0, 180] for Hue
*/
static int convert_to_color_scale(const int scale, const float value)
{
int color = value * scale;
if (value < 0)
{
color *= -1;
}
return color;
}
void write_png_image(const std::string fileName, const cv::Mat& map)
{
// Read the target bitmap
try
{
cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(map, output, CV_HLS2BGR);
// Parameters for cv::imwrite
std::vector<int> write_params;
write_params.push_back(CV_IMWRITE_PNG_COMPRESSION);
write_params.push_back(0); // Fastest writing without compression
// Write to a file
imwrite(fileName, output, write_params);
}
catch (std::runtime_error& ex)
{
std::cout << "Failed to write image: " << fileName << std::endl;
fprintf(stderr, "Exception converting image to PNG format: %s\n", ex.what());
}
}
void log_best_image_fitness(const std::string title)
{
std::vector < std::string > list;
list.push_back (title);
list.push_back (".png");
const std::string fileName = boost::algorithm::join (list, "");
write_png_image(fileName, _image);
std::cout << "Written to " << title << std::endl;
}
cv::Mat& image() {
return _image;
}
const cv::Mat& image() const {
return _image;
}
/**
* Returns image in BGR color space.
*/
void imageBGR(cv::Mat& output)
{
// Convert image to BGR before evaluating
// cv::Mat output;
// Convert HLS into BGR because imwrite uses BGR color space
cv::cvtColor(_image, output, CV_HLS2BGR);
// return output;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int version) {
dbg::trace trace("phen", DBG_HERE);
sferes::phen::Indiv<Gen, Fit, Params, typename stc::FindExact<ImageDirect<Gen, Fit, Params, Exact>, Exact>::ret>::serialize(ar, version);
ar & BOOST_SERIALIZATION_NVP(_image);
ar & BOOST_SERIALIZATION_NVP(_developed);
}
protected:
cv::Mat _image;
bool _developed;
};
}
}
#endif

@ -1,17 +0,0 @@
/*
* settings.h
*
* Created on: Jul 16, 2014
* Author: anh
*/
#ifndef SETTINGS_H_
#define SETTINGS_H_
//#define LOCAL_RUN
//#define NB_THREADS 16
#endif /* SETTINGS_H_ */

@ -1,171 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef BEST_FIT_IMAGE_
#define BEST_FIT_IMAGE_
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/nvp.hpp>
#include "image_stat.hpp"
#include <sferes/fit/fitness.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
// Headers specifics to the computations we need
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <exp/images/util/median.hpp>
#include <boost/filesystem.hpp>
namespace sferes {
namespace stat {
// assume that the population is sorted !
SFERES_STAT(BestFitImage, ImageStat){
public:
typedef boost::shared_ptr<Phen> indiv_t;
typedef std::vector<indiv_t> pop_t;
template<typename E>
void refresh(const E& ea) {
assert(!ea.pop().empty());
//_best = *ea.pop().begin();
// Create the log file
this->_create_log_file(ea, "bestfit.dat");
if (ea.dump_enabled() && ( ea.gen() % Params::pop::dump_period == 0 ))
{
// The data for which we wish to calculate median as the boost accumulator does not.
std::vector< double > data;
// Calculate all stats: mean, max, min
boost::accumulators::accumulator_set<double, boost::accumulators::stats<
boost::accumulators::tag::mean,
boost::accumulators::tag::max,
boost::accumulators::tag::min
> > stats;
int best_id = 0;
float best_fitness = 0.0f;
int id = 0;
BOOST_FOREACH(indiv_t i, ea.pop())
{
// With the stats object in hand, all we need is to push in the data.
float fitness = i->fit().value();
stats(fitness);
data.push_back(fitness); // Add it to the list for calculating median later
// Get the best individual by fitness
if (fitness > best_fitness)
{
best_id = id;
best_fitness = fitness;
}
++id;
}
// Best individual in the current pop
_best = ea.pop()[best_id];
assert(data.size() == Params::pop::size); // Make sure the list of values is of correct size
double median = sferes::util::Median::calculate_median(data); // Get the mdian
// Dump best_fit.dat file
(*this->_log_file) << ea.gen()
<< " " << median
<< " " << boost::accumulators::mean(stats)
<< " " << boost::accumulators::max(stats)
<< " " << boost::accumulators::min(stats)
<< std::endl;
// Dump best image
if (Params::log::best_image)
{
std::string image_fitness = boost::lexical_cast<std::string>(_best->fit().value());
std::string image_gen = boost::lexical_cast<std::string>(ea.gen());
std::string image_file = ea.res_dir() + "/" + image_gen + "_" + image_fitness;
_best->log_best_image_fitness(image_file);
}
// Save this generation population to a file
// Clear all individuals
_pop.clear();
// The mixed population (before selection)
for (size_t i = 0; i < ea.pop().size(); ++i)
{
_pop.push_back(ea.pop()[i]);
}
}
}
void show(std::ostream& os, size_t k) {
_best->develop();
_best->show(os);
_best->fit().set_mode(fit::mode::view);
_best->fit().eval(*_best);
}
const boost::shared_ptr<Phen> best() const {
return _best;
}
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(_pop);
ar & BOOST_SERIALIZATION_NVP(_best);
}
const pop_t& getPopulation() const
{
return _pop;
}
protected:
indiv_t _best;
pop_t _pop;
};
}
}
#endif

@ -1,162 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef BEST_FIT_MAP_IMAGE_
#define BEST_FIT_MAP_IMAGE_
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/nvp.hpp>
#include "image_stat.hpp"
#include <sferes/fit/fitness.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
// Headers specifics to the computations we need
#include <boost/accumulators/statistics/median.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/max.hpp>
#include <exp/images/util/median.hpp>
#include <boost/filesystem.hpp>
namespace sferes {
namespace stat {
// assume that the population is sorted !
SFERES_STAT(BestFitMapImage, ImageStat){
public:
typedef boost::shared_ptr<Phen> indiv_t;
typedef std::vector<indiv_t> pop_t;
template<typename E>
void refresh(const E& ea) {
assert(!ea.pop().empty());
// Create the log file
this->_create_log_file(ea, "bestfit.dat");
if (ea.dump_enabled() && ( ea.gen() % Params::pop::dump_period == 0 ))
{
// The data for which we wish to calculate median as the boost accumulator does not.
std::vector< double > data;
// Calculate all stats: mean, max, min
boost::accumulators::accumulator_set<double, boost::accumulators::stats<
boost::accumulators::tag::mean,
boost::accumulators::tag::max,
boost::accumulators::tag::min
> > stats;
int best_x = 0;
int best_y = 0;
float best_fitness = 0.0f;
// Iterate through the map of phenotypes in MAP-Elites
for (int x = 0; x < Params::ea::res_x; ++x)
{
for (int y = 0; y < Params::ea::res_y; ++y)
{
indiv_t i = ea.archive()[x][y];
float fitness = i->fit().value(y); // Get the fitness of individual
stats(fitness); // Add it to the stats accumulator
data.push_back(fitness); // Add it to the list for calculating median later
// Get the best individual by fitness
if (fitness > best_fitness)
{
best_x = x; // Record the best x and y
best_y = y;
best_fitness = fitness;
}
}
}
// Best individual in the current pop
_best = ea.archive()[best_x][best_y];
assert(data.size() == Params::ea::res_y); // Make sure the list of values is of correct size
double median = sferes::util::Median::calculate_median(data); // Get the mdian
// Dump best_fit.dat file
(*this->_log_file) << ea.gen()
<< " " << median
<< " " << boost::accumulators::mean(stats)
<< " " << boost::accumulators::max(stats)
<< " " << ea.jumps()
<< " " << boost::accumulators::min(stats)
<< std::endl;
// Dump best image
if (Params::log::best_image)
{
std::string image_fitness = boost::lexical_cast<std::string>(best_fitness);
std::string image_gen = boost::lexical_cast<std::string>(ea.gen());
std::string image_file = ea.res_dir() + "/" + image_gen + "_" + image_fitness;
_best->log_best_image_fitness(image_file);
}
}
}
void show(std::ostream& os, size_t k) {
_best->develop();
_best->show(os);
_best->fit().set_mode(fit::mode::view);
_best->fit().eval(*_best);
}
const boost::shared_ptr<Phen> best() const {
return _best;
}
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(_best);
}
protected:
indiv_t _best;
};
}
}
#endif

@ -1,70 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef IMAGE_STAT_
#define IMAGE_STAT_
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/nvp.hpp>
#include <sferes/stat/stat.hpp>
#include <sferes/fit/fitness.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/filesystem.hpp>
namespace sferes {
namespace stat {
// assume that the population is sorted !
SFERES_STAT(ImageStat, Stat){
protected:
template<typename E>
void _create_log_file(const E& ea, const std::string& name) {
if (!this->_log_file && ea.dump_enabled()) {
// Create a new file if not exists, append if exists
std::string log = ea.res_dir() + "/" + name;
// Append if file exists: std::fstream::app
this->_log_file = boost::shared_ptr<std::ofstream>(new std::ofstream(log.c_str(), std::fstream::app));
}
}
};
}
}
#endif

@ -1,208 +0,0 @@
#ifndef STAT_MAP_IMAGE_HPP
#define STAT_MAP_IMAGE_HPP
#include <numeric>
#include <boost/multi_array.hpp>
#include <sferes/stat/stat.hpp>
#include <glog/logging.h>
#include <boost/filesystem.hpp>
namespace sferes
{
namespace stat
{
SFERES_STAT(MapImage, Stat)
{
public:
typedef boost::shared_ptr<Phen> phen_t;
typedef boost::multi_array<phen_t, 2> array_t;
typedef boost::array<float, 2> point_t;
MapImage() : _xs(0), _ys(0) {}
template<typename E>
void refresh(const E& ea)
{
_archive.clear();
_xs = ea.archive().shape()[0];
_ys = ea.archive().shape()[1];
assert(_xs == Params::ea::res_x);
assert(_ys == Params::ea::res_y);
for (size_t i = 0; i < _xs; ++i)
for (size_t j = 0; j < _ys; ++j)
{
phen_t p = ea.archive()[i][j];
_archive.push_back(p);
}
// Report current generation every 10 generations
if (ea.gen() % 10 == 0)
{
std::cout << "gen.. " << ea.gen() << std::endl;
}
if (ea.gen() % Params::pop::dump_period == 0)
{
_write_archive(ea.archive(), ea.parents(), std::string("archive_"), ea, ea.gen());
#ifdef MAP_WRITE_PARENTS
_write_parents(ea.archive(), ea.parents(), std::string("parents_"), ea);
#endif
}
}
const std::vector<phen_t>& getPopulation() const
{
return _archive;
}
const std::vector<phen_t>& archive() const
{
return _archive;
}
void show(std::ostream& os, size_t k)
{
std::cerr << "loading "<< k / _ys << "," << k % _ys << std::endl;
if (_archive[k])
{
_archive[k]->develop();
_archive[k]->show(os);
_archive[k]->fit().set_mode(fit::mode::view);
_archive[k]->fit().eval(*_archive[k]);
}
else
std::cerr << "Warning, no point here" << std::endl;
}
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(_archive);
ar & BOOST_SERIALIZATION_NVP(_xs);
ar & BOOST_SERIALIZATION_NVP(_ys);
}
protected:
std::vector<phen_t> _archive;
int _xs, _ys;
template<typename EA>
void _write_parents(const array_t& array,
const array_t& p_array,
const std::string& prefix,
const EA& ea) const
{
std::cout << "writing..." << prefix << ea.gen() << std::endl;
std::string fname = ea.res_dir() + "/"
+ prefix
+ boost::lexical_cast<
std::string>(ea.gen())
+ std::string(".dat");
std::ofstream ofs(fname.c_str());
for (size_t i = 0; i < _xs; ++i)
for (size_t j = 0; j < _ys; ++j)
if (array[i][j] && p_array[i][j])
{
point_t p = _get_point(p_array[i][j]);
size_t x = round(p[0] * _xs);
size_t y = round(p[1] * _ys);
ofs << i / (float) _xs
<< " " << j / (float) _ys
<< " " << p_array[i][j]->fit().value()
<< " " << x / (float) _xs
<< " " << y / (float) _ys
<< " " << array[i][j]->fit().value()
<< std::endl;
}
}
std::string _make_gen_dir(const std::string& res_dir, const int gen) const
{
std::string gen_dir = res_dir + std::string("/map_gen_") + boost::lexical_cast<std::string>(gen);
boost::filesystem::path my_path(gen_dir);
boost::filesystem::create_directory(my_path);
return gen_dir;
}
template<typename EA>
void _write_archive(const array_t& array,
const array_t& p_array,
const std::string& prefix,
const EA& ea,
const int gen) const
{
std::cout << "writing..." << prefix << ea.gen() << std::endl;
std::string fname = ea.res_dir() + "/"
+ prefix
+ boost::lexical_cast<
std::string>(ea.gen())
+ std::string(".dat");
std::ofstream ofs(fname.c_str());
for (size_t i = 0; i < _xs; ++i)
{
for (size_t j = 0; j < _ys; ++j)
{
if (array[i][j])
{
float fitness = array[i][j]->fit().value(j);
ofs
<< " " << j // This dimension is categorical (1-1000). No need to normalize to be [0, 1].
<< " " << fitness;
// CPPN genome info
// << " " << array[i][j]->gen().get_nb_neurons()
// << " " << array[i][j]->gen().get_nb_connections();
if (Params::image::record_lineage)
{
ofs << " " << array[i][j]->id(); // Record the id of this organism
// Only print out the parent if this is a newly created organism
if (array[i][j]->created_gen() == ea.gen())
{
ofs << " " << p_array[i][j]->id(); // Record the id of this organism's parent
}
}
ofs << std::endl; // End of line
bool dump_map = false;
// Always print the map in the first generation and last generation
// if (
// (gen == 0 || gen == Params::pop::nb_gen - Params::pop::dump_period)
// Print out only when there is an improvement of 0.1
// || (fitness - p_array[i][j]->fit().value(j) >= 0.3)
// )
{
dump_map = true;
}
// Check if we should print out
if (dump_map)
{
// Create the directory
const std::string gen_dir = _make_gen_dir(ea.res_dir(), gen);
// Print out images at the current generation
std::string image_gen = boost::lexical_cast<std::string>(ea.gen());
std::string category = boost::lexical_cast<std::string>(j);
std::string image_fitness = boost::lexical_cast<std::string>(fitness);
std::string image_file = gen_dir + "/map_" + image_gen + "_" + category + "_" + image_fitness;
array[i][j]->log_best_image_fitness(image_file);
}
}
}
}
}
};
}
}
#endif

@ -1,80 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef UTIL_MEDIAN
#define UTIL_MEDIAN
#include <boost/range/algorithm.hpp>
#include <vector> // std::vector
namespace sferes {
namespace util {
class Median
{
public:
/**
* Calculate the median of the doubles in the given list.
*/
static double calculate_median(std::vector<double>& list)
{
size_t size = list.size(); // Size of the list
assert(size > 0);
std::sort(list.begin(), list.end());
// If there are an odd number of doubles
if (size % 2 == 1)
{
// Take the middle number
size_t index_middle = (size - 1)/2;
return list[index_middle];
}
// If there are an even number of doubles
else
{
size_t index_above = size / 2;
size_t index_below = index_above - 1;
// Average of two middle numbers
return (list[index_above] + list[index_below]) / 2;
}
}
};
}
}
#endif

@ -1,14 +0,0 @@
#! /usr/bin/env python
def build(bld):
obj = bld.new_task_gen('cxx', 'program')
obj.source = 'dl_map_elites_images_imagenet_direct_encoding.cpp'
#obj.source = 'dl_rank_simple_images_mnist_direct_encoding.cpp'
#obj.source = 'dl_rank_simple_images.cpp'
obj.includes = '. ../../ /usr/local/cuda-6.0/include'
obj.uselib_local = 'sferes2'
obj.uselib = ''
obj.cxxflags = ['-std=c++11']
obj.target = 'images'
obj.uselib_local = 'sferes2'
obj.lib=['png', 'cudart', 'caffe', 'opencv_core', 'opencv_highgui', 'opencv_imgproc', 'lmdb', 'glog']

@ -1,21 +0,0 @@
#!/bin/bash
# Uninstall caffe from Sferes
rm -rf ~/src/sferes/include/caffe/
rm ~/src/sferes/lib/libcaffe.*
echo "Removed old installation in ~/src/sferes/"
# Reinstall caffe to Sferes
# Include files
cp -R ~/src/caffe/include/caffe/ ~/src/sferes/include/
echo "Installed header files from ~/src/caffe/include/caffe/"
cp -R ~/src/caffe/build/src/caffe/ ~/src/sferes/include/
echo "Installed header files from ~/src/caffe/build/src/caffe/"
# Library files
cp ~/src/caffe/build/lib/libcaffe.* ~/src/sferes/lib/
echo "Installed library files from ~/src/caffe/build/lib/"
echo "Done."

@ -1,62 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#include <sferes/fit/fitness.hpp>
#define FIT_MAP(Name) SFERES_FITNESS(Name, sferes::fit::FitMap)
namespace sferes
{
namespace fit
{
SFERES_FITNESS(FitMap, sferes::fit::Fitness)
{
public:
FitMap() : _desc(2) { }
const std::vector<float>& desc() const { return _desc; }
void set_desc(float x1, float x2)
{
assert(x1 >= 0);
assert(x2 >= 0);
assert(x1 <= 1);
assert(x2 <= 1);
assert(_desc.size() >= 2);
_desc[0] = x1;
_desc[1] = x2;
}
protected:
std::vector<float> _desc;
};
}
}

@ -1,284 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef MAP_ELITE_HPP_
#define MAP_ELITE_HPP_
#include <algorithm>
#include <limits>
#include <boost/foreach.hpp>
#include <boost/multi_array.hpp>
#include <boost/array.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
#include <sferes/stc.hpp>
#include <exp/images/ea/ea_custom.hpp>
#include <sferes/fit/fitness.hpp>
#include <exp/images/continue_run/continue_run.hpp>
namespace sferes
{
namespace ea
{
// Main class
SFERES_EA(MapElite, EaCustom){
public:
typedef boost::shared_ptr<Phen> indiv_t;
typedef std::vector<indiv_t> raw_pop_t;
typedef MapElite<Phen, Eval, Stat, FitModifier, Params, Exact> this_t;
typedef typename std::vector<indiv_t> pop_t;
typedef typename pop_t::iterator it_t;
typedef typename std::vector<std::vector<indiv_t> > front_t;
typedef boost::array<float, 2> point_t;
typedef boost::shared_ptr<Phen> phen_t;
typedef boost::multi_array<phen_t, 2> array_t;
// typedef boost::shared_ptr<Stat> stat_t;
static const size_t res_x = Params::ea::res_x;
static const size_t res_y = Params::ea::res_y;
typedef Stat stat_t;
MapElite() :
_array(boost::extents[res_x][res_y]),
_array_parents(boost::extents[res_x][res_y]),
_jumps(0)
{
}
void random_pop()
{
// parallel::init(); We are not using TBB
// Continuing a run
sferes::cont::Continuator<this_t, Params> continuator;
bool continue_run = continuator.enabled() || this->_gen_file_path != "";
// Continuing a run manually from command line or continuing a run automatically if the job was pre-empted
if(continue_run)
{
// Load the population file
raw_pop_t raw_pop;
if (this->_gen_file_path == "")
{
raw_pop = continuator.getPopulationFromFile(*this);
}
else
{
raw_pop = continuator.getPopulationFromFile(*this, this->_gen_file_path);
}
// Assign this pop also to the current map
for (size_t i = 0; i < raw_pop.size(); ++i)
{
_add_to_archive(raw_pop[i], raw_pop[i]);
}
// Get the number of population to continue with
const size_t init_size = raw_pop.size();
// Resize the current population archive
this->_pop.resize(init_size);
// Add loaded individuals to the new population
int i = 0;
BOOST_FOREACH(boost::shared_ptr<Phen>&indiv, this->_pop)
{
indiv = boost::shared_ptr<Phen>(new Phen(*raw_pop[i]));
++i;
}
}
else // Run normally from gen = 0
{
// Original Map-Elites code
// Intialize a random population
this->_pop.resize(Params::pop::init_size);
BOOST_FOREACH(boost::shared_ptr<Phen>&indiv, this->_pop)
{
indiv = boost::shared_ptr<Phen>(new Phen());
indiv->random();
}
}
// Evaluate the initialized population
this->_eval.eval(this->_pop, 0, this->_pop.size());
BOOST_FOREACH(boost::shared_ptr<Phen>&indiv, this->_pop)
_add_to_archive(indiv, indiv);
// Continue a run from a specific generation
if(continue_run)
{
if (this->_gen_file_path == "")
{
continuator.run_with_current_population(*this);
}
else
{
continuator.run_with_current_population(*this, this->_gen_file_path);
}
}
}
//ADDED
void setGen(size_t gen)
{
this->_gen = gen;
}
//ADDED END
void epoch()
{
#ifdef PHELOGENETIC_TREE
// We start with only 1 organism in order to construct the phylogenetic tree
// Thus, no evolution happening at generation 0
if (this->_gen == 0) return;
#endif
this->_pop.clear();
for (size_t i = 0; i < res_x; ++i)
{
for (size_t j = 0; j < res_y; ++j)
{
if (_array[i][j])
{
this->_pop.push_back(_array[i][j]);
}
}
}
pop_t ptmp, p_parents;
for (size_t i = 0; i < Params::pop::size / 2; ++i)
{
indiv_t p1 = _selection(this->_pop);
indiv_t p2 = _selection(this->_pop);
boost::shared_ptr<Phen> i1, i2;
p1->cross(p2, i1, i2);
i1->mutate();
i2->mutate();
/*
Phenotypes are to be developed in eval() called below
this->_eval.eval(ptmp, 0, ptmp.size());
So no need to develop them here.
// i1->develop();
// i2->develop();
*/
// Add the generation when these two new organisms are created (mutated)
i1->set_created_gen(this->_gen);
i2->set_created_gen(this->_gen);
ptmp.push_back(i1);
ptmp.push_back(i2);
p_parents.push_back(p1);
p_parents.push_back(p2);
}
this->_eval.eval(ptmp, 0, ptmp.size());
assert(ptmp.size() == p_parents.size());
for (size_t i = 0; i < ptmp.size(); ++i)
{
_add_to_archive(ptmp[i], p_parents[i]);
}
}
const array_t& archive() const
{ return _array;}
const array_t& parents() const
{ return _array_parents;}
const unsigned long jumps() const
{ return _jumps;}
protected:
array_t _array;
array_t _prev_array;
array_t _array_parents;
unsigned long _jumps;
bool _add_to_archive(indiv_t i1, indiv_t parent)
{
bool added = false; // Flag raised when the individual is added to the archive in any cell
// We have a map of 1x1000 for the total of 1000 categories
assert(1 == res_x);
assert(i1->fit().desc().size() == res_y);
// Compare this individual with every top individual in every cell.
// If this individual is better, replace the current cell occupant with it.
for (int x = 0; x < res_x; ++x)
{
for (int y = 0; y < res_y; ++y)
{
float i1_fitness = i1->fit().value(y);
if (!_array[x][y] || i1_fitness > _array[x][y]->fit().value(y))
{
// Replace the current cell occupant with new individual and its parent
_array[x][y] = i1;
_array_parents[x][y] = parent;
added = true;
// Record a jump of an indiv to a cell
// One indiv could jump to many cells
_jumps++;
}
}
}
return added;
}
indiv_t _selection(const pop_t& pop)
{
int x1 = misc::rand< int > (0, pop.size());
return pop[x1];
}
};
}
}
#endif

@ -1,85 +0,0 @@
import sys
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from matplotlib.ticker import FuncFormatter
cdict = {'red': [(0.0, 0.0, 0.0),
(0.33, 0.0, 0.0),
(0.66, 1.0, 1.0),
(1.0, 1.0, 1.0)],
'blue': [(0.0, 0.0, 0.0),
(0.33, 1.0, 1.0),
(0.66, 0.0, 0.0),
(1.0, 0.0, 0.0)],
'green': [(0.0, 0.0, 0.0),
(0.33, 0.0, 0.0),
(0.66, 0.0, 0.0),
(1.0, 1.0, 1.0)]}
my_cmap = matplotlib.colors.LinearSegmentedColormap('my_colormap', cdict, 256)
def scale(x, pos):
'The two args are the value and tick position'
return '%1.1f' % (x / 100.0)
def scale2(x, pos):
'The two args are the value and tick position'
return '%1.1f' % (x / 100.0)
size = int(sys.argv[2])
x, y, z = np.loadtxt(sys.argv[1]).T
data = np.zeros((size, size))
m = 0
x_m = 0
y_m = 0
for i in range(0, len(z)):
data[round(x[i] * size), round(y[i] * size)] = z[i]
if z[i] > m:
x_m = round(x[i] * size)
y_m = round(y[i] * size)
m = z[i]
data = np.ma.masked_where(data == 0, data)
print "best:"+str(max(z))
def load_points(fname):
p_z, p_y, p_x = np.loadtxt(fname).T
p_x *= size
p_y *= size
p_p_x = []
p_p_y = []
np_p_x = []
np_p_y = []
for i in range(0, len(p_x)):
if p_z[i] == 1.0:
p_p_x += [p_x[i]]
p_p_y += [p_y[i]]
else:
np_p_x += [p_x[i]]
np_p_y += [p_y[i]]
return p_p_x, p_p_y, np_p_x, np_p_y
fig = plt.figure()
im = plt.imshow(data.T, origin='lower', cmap=my_cmap)
im.set_interpolation('nearest')
fig.subplots_adjust(top=0.98)
cb = plt.colorbar()
for t in cb.ax.get_xticklabels():
t.set_fontsize(130)
ax = fig.add_subplot(111)
ax.yaxis.set_major_formatter(FuncFormatter(scale))
ax.xaxis.set_major_formatter(FuncFormatter(scale2))
plt.savefig('heatmap.pdf')

@ -1,127 +0,0 @@
#ifndef STAT_MAP_HPP_
#define STAT_MAP_HPP_
#include <numeric>
#include <boost/multi_array.hpp>
#include <sferes/stat/stat.hpp>
namespace sferes
{
namespace stat
{
SFERES_STAT(Map, Stat)
{
public:
typedef boost::shared_ptr<Phen> phen_t;
typedef boost::multi_array<phen_t, 2> array_t;
typedef boost::array<float, 2> point_t;
Map() : _xs(0), _ys(0) {}
template<typename E>
void refresh(const E& ea)
{
_archive.clear();
_xs = ea.archive().shape()[0];
_ys = ea.archive().shape()[1];
assert(_xs == Params::ea::res_x);
assert(_ys == Params::ea::res_y);
for (size_t i = 0; i < _xs; ++i)
for (size_t j = 0; j < _ys; ++j)
{
phen_t p = ea.archive()[i][j];
_archive.push_back(p);
}
if (ea.gen() % Params::pop::dump_period == 0)
{
_write_archive(ea.archive(), std::string("archive_"), ea);
#ifdef MAP_WRITE_PARENTS
_write_parents(ea.archive(), ea.parents(), std::string("parents_"), ea);
#endif
}
}
void show(std::ostream& os, size_t k)
{
std::cerr << "loading "<< k / _ys << "," << k % _ys << std::endl;
if (_archive[k])
{
_archive[k]->develop();
_archive[k]->show(os);
_archive[k]->fit().set_mode(fit::mode::view);
_archive[k]->fit().eval(*_archive[k]);
}
else
std::cerr << "Warning, no point here" << std::endl;
}
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(_archive);
ar & BOOST_SERIALIZATION_NVP(_xs);
ar & BOOST_SERIALIZATION_NVP(_ys);
}
protected:
std::vector<phen_t> _archive;
int _xs, _ys;
template<typename EA>
void _write_parents(const array_t& array,
const array_t& p_array,
const std::string& prefix,
const EA& ea) const
{
std::cout << "writing..." << prefix << ea.gen() << std::endl;
std::string fname = ea.res_dir() + "/"
+ prefix
+ boost::lexical_cast<
std::string>(ea.gen())
+ std::string(".dat");
std::ofstream ofs(fname.c_str());
for (size_t i = 0; i < _xs; ++i)
for (size_t j = 0; j < _ys; ++j)
if (array[i][j] && p_array[i][j])
{
point_t p = _get_point(p_array[i][j]);
size_t x = round(p[0] * _xs);
size_t y = round(p[1] * _ys);
ofs << i / (float) _xs
<< " " << j / (float) _ys
<< " " << p_array[i][j]->fit().value()
<< " " << x / (float) _xs
<< " " << y / (float) _ys
<< " " << array[i][j]->fit().value()
<< std::endl;
}
}
template<typename EA>
void _write_archive(const array_t& array,
const std::string& prefix,
const EA& ea) const
{
std::cout << "writing..." << prefix << ea.gen() << std::endl;
std::string fname = ea.res_dir() + "/"
+ prefix
+ boost::lexical_cast<
std::string>(ea.gen())
+ std::string(".dat");
std::ofstream ofs(fname.c_str());
for (size_t i = 0; i < _xs; ++i)
for (size_t j = 0; j < _ys; ++j)
if (array[i][j])
{
ofs << i / (float) _xs
<< " " << j / (float) _ys
<< " " << array[i][j]->fit().value()
<< std::endl;
}
}
};
}
}
#endif

@ -1,124 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE map_elite
#include <iostream>
#include <cmath>
#include <boost/test/unit_test.hpp>
#include <sferes/eval/parallel.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/phen/parameters.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/run.hpp>
#include <sferes/stat/best_fit.hpp>
#include "map_elite.hpp"
#include "fit_map.hpp"
#include "stat_map.hpp"
using namespace sferes::gen::evo_float;
struct Params
{
struct ea
{
SFERES_CONST size_t res_x = 256;
SFERES_CONST size_t res_y = 256;
};
struct pop
{
// number of initial random points
SFERES_CONST size_t init_size = 1000;
// size of a batch
SFERES_CONST size_t size = 2000;
SFERES_CONST size_t nb_gen = 5001;
SFERES_CONST size_t dump_period = 1000;
};
struct parameters
{
SFERES_CONST float min = -5;
SFERES_CONST float max = 5;
};
struct evo_float
{
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float eta_m = 10.0f;
SFERES_CONST float eta_c = 10.0f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
};
};
// Rastrigin
FIT_MAP(Rastrigin)
{
public:
template<typename Indiv>
void eval(Indiv& ind)
{
float f = 10 * ind.size();
for (size_t i = 0; i < ind.size(); ++i)
f += ind.data(i) * ind.data(i) - 10 * cos(2 * M_PI * ind.data(i));
this->_value = -f;
this->set_desc(ind.gen().data(0), ind.gen().data(1));
}
};
//BOOST_AUTO_TEST_CASE(map_elite)
//{
// using namespace sferes;
//
// typedef Rastrigin<Params> fit_t;
// typedef gen::EvoFloat<10, Params> gen_t;
// typedef phen::Parameters<gen_t, fit_t, Params> phen_t;
// typedef eval::Parallel<Params> eval_t;
// typedef boost::fusion::vector<stat::Map<phen_t, Params>, stat::BestFit<phen_t, Params> > stat_t;
// typedef modif::Dummy<> modifier_t;
// typedef ea::MapElite<phen_t, eval_t, stat_t, modifier_t, Params> ea_t;
//
// ea_t ea;
//
// ea.run();
//
//}

@ -1,51 +0,0 @@
#! /usr/bin/env python
#| This file is a part of the sferes2 framework.
#| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
#| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
#|
#| This software is a computer program whose purpose is to facilitate
#| experiments in evolutionary computation and evolutionary robotics.
#|
#| This software is governed by the CeCILL license under French law
#| and abiding by the rules of distribution of free software. You
#| can use, modify and/ or redistribute the software under the terms
#| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
#| following URL "http://www.cecill.info".
#|
#| As a counterpart to the access to the source code and rights to
#| copy, modify and redistribute granted by the license, users are
#| provided only with a limited warranty and the software's author,
#| the holder of the economic rights, and the successive licensors
#| have only limited liability.
#|
#| In this respect, the user's attention is drawn to the risks
#| associated with loading, using, modifying and/or developing or
#| reproducing the software by the user in light of its specific
#| status of free software, that may mean that it is complicated to
#| manipulate, and that also therefore means that it is reserved for
#| developers and experienced professionals having in-depth computer
#| knowledge. Users are therefore encouraged to load and test the
#| software's suitability as regards their requirements in conditions
#| enabling the security of their systems and/or data to be ensured
#| and, more generally, to use and operate it in the same conditions
#| as regards security.
#|
#| The fact that you are presently reading this means that you have
#| had knowledge of the CeCILL license and that you accept its terms.
import os
def set_options(blah) : pass
def configure(blah): pass
def build(bld):
print ("Entering directory `" + os.getcwd() + "/modules/'")
test_map_elite = bld.new_task_gen('cxx', 'program')
test_map_elite.source = 'test_map_elite.cpp'
test_map_elite.includes = '. ../../'
test_map_elite.uselib_local = 'sferes2'
test_map_elite.uselib = 'EIGEN3 BOOST BOOST_UNIT_TEST_FRAMEWORK'
test_map_elite.target = 'test_map_elite'
test_map_elite.unit_test = 1
test_map_elite.cxxflags = ['-std=c++11']

@ -1,34 +0,0 @@
nn2
===
** This is a Sferes2 module **
NN2 is a generic toolbox for evolving neural networks (it depends on sferes2).
*If you use this software in an academic article, please cite:*
Mouret, J.-B. and Doncieux, S. (2012). Encouraging Behavioral Diversity in Evolutionary Robotics: an Empirical Study. Evolutionary Computation. Vol 20 No 1 Pages 91-133.
### Usage & installation
- copy nn2 to the "modules" directory in the sferes2 root directory.
- add nn2 in modules.conf in the sferes2 root directory
- run ./waf configure and ./waf build
### Academic paper that uses nn2
* Please note that many of these papers extends nn2 *
- Tonelli, P. and Mouret, J.-B. (2013). On the Relationships between Generative Encodings, Regularity, and Learning Abilities when Evolving Plastic Artificial Neural Networks. PLoS One. Vol 8 No 11 Pages e79138.
- Clune*, J. and Mouret, J.-B. and Lipson, H. (2013). The evolutionary origins of modularity. Proceedings of the Royal Society B. Vol 280 (J. Clune and J.-B. Mouret contributed equally to this work) Pages 20122863.
- Doncieux, S. and Mouret, J.B. (2013). Behavioral Diversity with Multiple Behavioral Distances. Proc. of IEEE Congress on Evolutionary Computation, 2013 (CEC 2013). Pages 1-8.
- Mouret, J.-B. and Doncieux, S. (2012). Encouraging Behavioral Diversity in Evolutionary Robotics: an Empirical Study. Evolutionary Computation. Vol 20 No 1 Pages 91-133.
- Ollion, Charles and Doncieux, Stéphane (2012). Towards Behavioral Consistency in Neuroevolution. From Animals to Animats: Proceedings of the 12th International Conference on Adaptive Behaviour (SAB 2012), Springer, publisher. Pages 1-10.
- Ollion, C. and Pinville, T. and Doncieux, S. (2012). With a little help from selection pressures: evolution of memory in robot controllers. Proc. Alife XIII. Pages 1-8.
- Mouret, J.-B. (2011). Novelty-based Multiobjectivization. New Horizons in Evolutionary Robotics: Extended Contributions from the 2009 EvoDeRob Workshop, Springer, publisher. Pages 139--154.
- Pinville, T. and Koos, S. and Mouret, J-B. and Doncieux, S. (2011). How to Promote Generalisation in Evolutionary Robotics: the ProGAb Approach.
GECCO'11: Proceedings of the 13th annual conference on Genetic and evolutionary computation ACM, publisher . Pages 259--266
- Mouret, J.-B. and Doncieux, S. and Girard, B. (2010). Importing the Computational Neuroscience Toolbox into Neuro-Evolution---Application to Basal Ganglia. GECCO'10: Proceedings of the 12th annual conference on Genetic and evolutionary computation ACM, publisher . Pages 587--594.
- Doncieux, S. and Mouret, J.-B. (2010). Behavioral diversity measures for Evolutionary Robotics. WCCI 2010 IEEE World Congress on Computational Intelligence, Congress on Evolutionary Computation (CEC). Pages 1303--1310.

@ -1,127 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_AF_HPP_
#define _NN_AF_HPP_
#include "params.hpp"
// classic activation functions
namespace nn
{
template <typename P = params::Dummy>
class Af
{
public:
typedef P params_t;
const params_t& get_params() const { return _params; }
params_t& get_params() { return _params; }
void set_params(const params_t& params) { _params = params; }
void init() {}
Af() {}
protected:
params_t _params;
};
// -1 to +1 sigmoid
template <typename P>
struct AfTanh : public Af<P>
{
typedef P params_t;
BOOST_STATIC_CONSTEXPR float lambda = 5.0f;
AfTanh() { assert(trait<P>::size(this->_params) == 1); }
float operator()(float p) const
{
return tanh(p * lambda + trait<P>::single_value(this->_params));
}
protected:
};
// -1 to +1 sigmoid
template <typename P = float>
struct AfTanhNoBias : public Af<P>
{
typedef params::Dummy params_t;
BOOST_STATIC_CONSTEXPR float lambda = 5.0f;
AfTanhNoBias() { }
float operator()(float p) const
{
return tanh(p * lambda);
}
};
template <typename P = float>
struct AfSigmoidNoBias : public Af<>
{
typedef params::Dummy params_t;
BOOST_STATIC_CONSTEXPR float lambda = 5.0f;
AfSigmoidNoBias() { }
float operator()(float p) const { return 1.0 / (exp(-p * lambda) + 1); }
protected:
};
template <typename P = float>
struct AfSigmoidBias : public Af<P>
{
typedef P params_t;
BOOST_STATIC_CONSTEXPR float lambda = 5.0f;
AfSigmoidBias() { assert(this->_params.size() == 1); }
float operator()(float p) const
{
return 1.0 / (exp(-p + trait<P>::single_value(this->_params) * lambda) + 1);
}
protected:
};
// copy input to output
// store an arbitrary parameter
template<typename P = params::Dummy>
struct AfDirect : public Af<P>
{
typedef P params_t;
float operator()(float p) const { return p; }
};
// copy input to output
template<typename T>
struct AfDirectT : public Af<params::Dummy>
{
typedef params::Dummy params_t;
T operator()(T p) const { return p; }
};
}
#endif

@ -1,121 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef AF_CPPN_HPP_
#define AF_CPPN_HPP_
#include <sferes/gen/sampled.hpp>
#include <sferes/gen/evo_float.hpp>
// classic activation functions
namespace nn
{
namespace cppn
{
enum func_e { sine = 0, sigmoid, gaussian, linear, tanh };
SFERES_CONST size_t nb_functions = 3;
SFERES_CLASS(AfParams)
{
public:
void set(float t, float p)
{
_type.set_data(0, t);
_param.data(0, p);
}
void mutate()
{
_type.mutate();
_param.mutate();
}
void random()
{
_type.random();
_param.random();
}
void develop() {
}
int type() const {
return _type.data(0);
}
float param() const {
return _param.data(0);
}
template<typename A>
void serialize(A& ar, unsigned int v)
{
ar& BOOST_SERIALIZATION_NVP(_type);
ar& BOOST_SERIALIZATION_NVP(_param);
}
protected:
sferes::gen::Sampled<1, Params> _type;
sferes::gen::EvoFloat<1, Params> _param;
};
}
// Activation function for Compositional Pattern Producing Networks
template<typename P>
struct AfCppn : public Af<P>
{
typedef P params_t;
float operator() (float p) const
{
float s = p > 0 ? 1 : -1;
//std::cout<<"type:"<<this->_params.type()<<" p:"<<p<<" this:"<<this
//<< " out:"<< p * exp(-powf(p * 10/ this->_params.param(), 2))<<std::endl;
switch (this->_params.type())
{
case cppn::sine:
return sin(p);
case cppn::sigmoid:
return ((1.0 / (1.0 + exp(-p))) - 0.5) * 2.0;
case cppn::gaussian:
return exp(-powf(p, 2));
case cppn::linear:
return std::min(std::max(p, -3.0f), 3.0f) / 3.0f;
case cppn::tanh:
return tanh(p * 5.0f);
default:
assert(0);
}
return 0;
}
};
}
#endif

@ -1,70 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#include "nn.hpp"
int main()
{
using namespace nn;
typedef NN<Neuron<PfWSum<>, AfTanh<float> >, Connection<> > nn_t;
nn_t nn;
BOOST_STATIC_CONSTEXPR size_t nb_io = 5;
BOOST_STATIC_CONSTEXPR size_t nb_h = 100;
nn.set_nb_inputs(nb_io);
nn.set_nb_outputs(nb_io);
std::vector<nn_t::vertex_desc_t> neurons;
for (size_t i = 0; i < nb_h; ++i)
neurons.push_back(nn.add_neuron("n"));
for (size_t i = 0; i < nn.get_nb_inputs(); ++i)
for (size_t j = 0; j < neurons.size(); ++j)
nn.add_connection(nn.get_input(i), neurons[j], 1.0f);
for (size_t i = 0; i < nn.get_nb_outputs(); ++i)
for (size_t j = 0; j < neurons.size(); ++j)
nn.add_connection(neurons[j], nn.get_output(i), 0.20f);
std::vector<float> in(nn.get_nb_inputs());
nn.init();
std::fill(in.begin(), in.end(), 1.0f);
size_t nb_steps = 50000;
for (size_t i = 0; i < nb_steps; ++i)
nn.step(in);
return 0;
}

@ -1,55 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_CONNECTiON_HPP
#define _NN_CONNECTiON_HPP
#include "params.hpp"
namespace nn
{
template<typename W = float, typename IO = float>
struct Connection
{
typedef W weight_t;
typedef IO io_t;
const weight_t& get_weight() const { return _weight; }
weight_t& get_weight() { return _weight; }
void set_weight(const weight_t& w) { _weight = w; }
protected:
weight_t _weight;
};
}
#endif

@ -1,135 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_ELMAN_HPP_
#define _NN_ELMAN_HPP_
#include "nn.hpp"
namespace nn
{
// a "modified" Elman network with self-recurrent context units
// E.g. : Training Elman and Jordan networks for system
// identification using genetic algorithms
// Artificial Intelligence in Engineering
// Volume 13, Issue 2, April 1999, Pages 107-117
// first input is a BIAS input (it should be set to 1)
template<typename N, typename C>
class Elman : public NN<N, C>
{
public:
typedef nn::NN<N, C> nn_t;
typedef typename nn_t::io_t io_t;
typedef typename nn_t::vertex_desc_t vertex_desc_t;
typedef typename nn_t::edge_desc_t edge_desc_t;
typedef typename nn_t::adj_it_t adj_it_t;
typedef typename nn_t::graph_t graph_t;
typedef N neuron_t;
typedef C conn_t;
Elman(size_t nb_inputs,
size_t nb_hidden,
size_t nb_outputs)
{
// neurons
this->set_nb_inputs(nb_inputs + 1);
this->set_nb_outputs(nb_outputs);
for (size_t i = 0; i < nb_hidden; ++i)
_hidden_neurons.
push_back(this->add_neuron(std::string("h")
+ boost::lexical_cast<std::string>(i)));
for (size_t i = 0; i < nb_hidden; ++i)
_context_neurons.
push_back(this->add_neuron(std::string("c")
+ boost::lexical_cast<std::string>(i)));
// connections
this->full_connect(this->_inputs, this->_hidden_neurons,
trait<typename N::weight_t>::zero());
this->full_connect(this->_hidden_neurons, this->_outputs,
trait<typename N::weight_t>::zero());
this->connect(this->_hidden_neurons, this->_context_neurons,
trait<typename N::weight_t>::zero());
this->connect(this->_context_neurons, this->_context_neurons,
trait<typename N::weight_t>::zero());
this->full_connect(this->_context_neurons, this->_hidden_neurons,
trait<typename N::weight_t>::zero());
// bias
// (hidden layer is already connect to input(0))
size_t last = this->get_nb_inputs();
for (size_t i = 0; i < _context_neurons.size(); ++i)
this->add_connection(this->get_input(last), _context_neurons[i],
trait<typename N::weight_t>::zero());
for (size_t i = 0; i < this->get_nb_outputs(); ++i)
this->add_connection(this->get_input(last), this->get_output(i),
trait<typename N::weight_t>::zero());
}
unsigned get_nb_inputs() const { return this->_inputs.size() - 1; }
void step(const std::vector<io_t>& in)
{
assert(in.size() == this->get_nb_inputs());
std::vector<io_t> inf = in;
inf.push_back(1.0f);
nn_t::_step(inf);
}
protected:
std::vector<vertex_desc_t> _hidden_neurons;
std::vector<vertex_desc_t> _context_neurons;
};
namespace elman
{
template<int NbInputs, int NbHidden, int NbOutputs>
struct Count
{
SFERES_CONST int nb_inputs = NbInputs + 1; // bias is an input
SFERES_CONST int nb_outputs = NbOutputs;
SFERES_CONST int nb_hidden = NbHidden;
SFERES_CONST int nb_params =
nb_inputs * nb_hidden // input to hidden (full)
+ nb_hidden * nb_outputs // hidden to output (full)
+ nb_hidden // hidden to context (1-1)
+ nb_hidden // context to itself (1-1)
+ nb_hidden * nb_hidden // context to hidden (full)
+ nb_hidden // bias context
+ nb_outputs; // bias outputs
};
}
}
#endif

@ -1,421 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef DNN_HPP_
#define DNN_HPP_
#include <bitset>
#include <boost/serialization/serialization.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/archive/text_oarchive.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/utility.hpp>
#include <sferes/dbg/dbg.hpp>
#include <sferes/misc.hpp>
#include "nn.hpp"
#include "trait.hpp"
namespace sferes
{
namespace gen
{
template <class Graph>
typename boost::graph_traits<Graph>::vertex_descriptor
random_vertex(Graph& g)
{
assert(num_vertices(g));
using namespace boost;
if (num_vertices(g) > 1)
{
std::size_t n = misc::rand(num_vertices(g));
typename graph_traits<Graph>::vertex_iterator i = vertices(g).first;
while (n-- > 0) ++i;
return *i;
}
else
return *vertices(g).first;
}
template <class Graph>
typename boost::graph_traits<Graph>::edge_descriptor
random_edge(Graph& g)
{
assert(num_edges(g));
using namespace boost;
if (num_edges(g) > 1)
{
std::size_t n = misc::rand(num_edges(g));
typename graph_traits<Graph>::edge_iterator i = edges(g).first;
while (n-- > 0) ++i;
return *i;
}
else
return *edges(g).first;
}
namespace dnn
{
enum init_t { ff = 0, random_topology };
}
template<typename N, typename C, typename Params>
class Dnn : public nn::NN<N, C>
{
public:
typedef nn::NN<N, C> nn_t;
typedef N neuron_t;
typedef C conn_t;
typedef typename nn_t::io_t io_t;
typedef typename nn_t::weight_t weight_t;
typedef typename nn_t::vertex_desc_t vertex_desc_t;
typedef typename nn_t::edge_desc_t edge_desc_t;
typedef typename nn_t::adj_it_t adj_it_t;
typedef typename nn_t::graph_t graph_t;
void random()
{
if (Params::dnn::init == dnn::ff)
_random_ff(Params::dnn::nb_inputs, Params::dnn::nb_outputs);
else
_random(Params::dnn::nb_inputs, Params::dnn::nb_outputs,
Params::dnn::min_nb_neurons, Params::dnn::max_nb_neurons,
Params::dnn::min_nb_conns, Params::dnn::max_nb_conns);
}
void mutate()
{
_change_conns();
_change_neurons();
if (misc::rand<float>() < Params::dnn::m_rate_add_conn)
_add_conn_nodup();
if (misc::rand<float>() < Params::dnn::m_rate_del_conn)
_del_conn();
if (misc::rand<float>() < Params::dnn::m_rate_add_neuron)
_add_neuron_on_conn();
if (misc::rand<float>() < Params::dnn::m_rate_del_neuron)
_del_neuron();
}
void cross(const Dnn& o, Dnn& c1, Dnn& c2)
{
#ifdef PHELOGENETIC_TREE
c1 = *this;
c2 = o;
#else
if (misc::flip_coin())
{
c1 = *this;
c2 = o;
}
else
{
c2 = *this;
c1 = o;
}
#endif
}
// serialize the graph "by hand"...
template<typename Archive>
void save(Archive& a, const unsigned v) const
{
dbg::trace("nn", DBG_HERE);
std::vector<int> inputs;
std::vector<int> outputs;
std::vector<typename neuron_t::af_t::params_t> afparams;
std::vector<typename neuron_t::pf_t::params_t> pfparams;
std::map<vertex_desc_t, int> nmap;
std::vector<std::pair<int, int> > conns;
std::vector<weight_t> weights;
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
{
if (this->is_input(v))
inputs.push_back(afparams.size());
if (this->is_output(v))
outputs.push_back(afparams.size());
nmap[v] = afparams.size();
afparams.push_back(this->_g[v].get_afparams());
pfparams.push_back(this->_g[v].get_pfparams());
}
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
{
conns.push_back(std::make_pair(nmap[source(e, this->_g)],
nmap[target(e, this->_g)]));
weights.push_back(this->_g[e].get_weight());
}
assert(pfparams.size() == afparams.size());
assert(weights.size() == conns.size());
a & BOOST_SERIALIZATION_NVP(afparams);
a & BOOST_SERIALIZATION_NVP(pfparams);
a & BOOST_SERIALIZATION_NVP(weights);
a & BOOST_SERIALIZATION_NVP(conns);
a & BOOST_SERIALIZATION_NVP(inputs);
a & BOOST_SERIALIZATION_NVP(outputs);
}
template<typename Archive>
void load(Archive& a, const unsigned v)
{
dbg::trace("nn", DBG_HERE);
std::vector<int> inputs;
std::vector<int> outputs;
std::vector<typename neuron_t::af_t::params_t> afparams;
std::vector<typename neuron_t::pf_t::params_t> pfparams;
std::map<size_t, vertex_desc_t> nmap;
std::vector<std::pair<int, int> > conns;
std::vector<weight_t> weights;
a & BOOST_SERIALIZATION_NVP(afparams);
a & BOOST_SERIALIZATION_NVP(pfparams);
a & BOOST_SERIALIZATION_NVP(weights);
a & BOOST_SERIALIZATION_NVP(conns);
a & BOOST_SERIALIZATION_NVP(inputs);
a & BOOST_SERIALIZATION_NVP(outputs);
assert(pfparams.size() == afparams.size());
assert(weights.size() == conns.size());
this->set_nb_inputs(inputs.size());
this->set_nb_outputs(outputs.size());
for (size_t i = 0; i < this->get_nb_inputs(); ++i)
nmap[inputs[i]] = this->get_input(i);
for (size_t i = 0; i < this->get_nb_outputs(); ++i)
nmap[outputs[i]] = this->get_output(i);
for (size_t i = 0; i < afparams.size(); ++i)
if (std::find(inputs.begin(), inputs.end(), i) == inputs.end()
&& std::find(outputs.begin(), outputs.end(), i) == outputs.end())
nmap[i] = this->add_neuron("n", pfparams[i], afparams[i]);
else
{
this->_g[nmap[i]].set_pfparams(pfparams[i]);
this->_g[nmap[i]].set_afparams(afparams[i]);
}
//assert(nmap.size() == num_vertices(this->_g));
for (size_t i = 0; i < conns.size(); ++i)
this->add_connection(nmap[conns[i].first], nmap[conns[i].second], weights[i]);
}
BOOST_SERIALIZATION_SPLIT_MEMBER();
protected:
void _random_neuron_params()
{
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
{
this->_g[v].get_pfparams().random();
this->_g[v].get_afparams().random();
}
}
// we start with a fully connected 0-layer perceptron with
// random weights
void _random_ff(size_t nb_inputs, size_t nb_outputs)
{
this->set_nb_inputs(nb_inputs);
this->set_nb_outputs(nb_outputs);
BOOST_FOREACH(vertex_desc_t& i, this->_inputs)
BOOST_FOREACH(vertex_desc_t& o, this->_outputs)
this->add_connection(i, o, _random_weight());
_random_neuron_params();
}
void _random(size_t nb_inputs, size_t nb_outputs,
size_t min_nb_neurons, size_t max_nb_neurons,
size_t min_nb_conns, size_t max_nb_conns)
{
// io
this->set_nb_inputs(nb_inputs);
this->set_nb_outputs(nb_outputs);
_random_neuron_params();
// neurons
size_t nb_neurons = misc::rand(min_nb_neurons, max_nb_neurons);
for (size_t i = 0; i < nb_neurons; ++i)
_add_neuron();//also call the random params
// conns
size_t nb_conns = misc::rand(min_nb_conns, max_nb_conns);
for (size_t i = 0; i < nb_conns; ++i)
_add_conn_nodup();
this->simplify();
}
vertex_desc_t _random_tgt()
{
vertex_desc_t v;
do
v = random_vertex(this->_g);
while (this->is_input(v));
return v;
}
vertex_desc_t _random_src()
{
vertex_desc_t v;
do
v = random_vertex(this->_g);
while (this->is_output(v));
return v;
}
vertex_desc_t _add_neuron()
{
vertex_desc_t v = this->add_neuron("n");
this->_g[v].get_pfparams().random();
this->_g[v].get_afparams().random();
return v;
}
vertex_desc_t _add_neuron_on_conn()
{
if (!num_edges(this->_g))
return (vertex_desc_t)0x0;
edge_desc_t e = random_edge(this->_g);
vertex_desc_t src = source(e, this->_g);
vertex_desc_t tgt = target(e, this->_g);
typename nn_t::weight_t w = this->_g[e].get_weight();
vertex_desc_t n = this->add_neuron("n");
this->_g[n].get_pfparams().random();
this->_g[n].get_afparams().random();
//
remove_edge(e, this->_g);
this->add_connection(src, n, w);// todo : find a kind of 1 ??
this->add_connection(n, tgt, w);
return n;
}
void _del_neuron()
{
assert(num_vertices(this->_g));
if (this->get_nb_neurons() <= this->get_nb_inputs() + this->get_nb_outputs())
return;
vertex_desc_t v;
do
v = random_vertex(this->_g);
while (this->is_output(v) || this->is_input(v));
clear_vertex(v, this->_g);
remove_vertex(v, this->_g);
}
typename nn_t::weight_t _random_weight()
{
typename nn_t::weight_t w;
w.random();
return w;
}
void _add_conn()
{
this->add_connection(_random_src(), _random_tgt(), _random_weight());
}
// add a random connection by avoiding to duplicate an existent connection
void _add_conn_nodup()
{
vertex_desc_t src, tgt;
// this is only an upper bound; a connection might of course
// be possible even after max_tries tries.
size_t max_tries = num_vertices(this->_g) * num_vertices(this->_g),
nb_tries = 0;
do
{
src = _random_src();
tgt = _random_tgt();
}
while (is_adjacent(this->_g, src, tgt) && ++nb_tries < max_tries);
if (nb_tries < max_tries)
{
typename nn_t::weight_t w;
w.random();
this->add_connection(src, tgt, w);
}
}
void _del_conn()
{
if (!this->get_nb_connections())
return;
remove_edge(random_edge(this->_g), this->_g);
}
void _change_neurons()
{
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
{
this->_g[v].get_afparams().mutate();
this->_g[v].get_pfparams().mutate();
}
}
// No dup version
void _change_conns()
{
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
this->_g[e].get_weight().mutate();
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
if (misc::rand<float>() < Params::dnn::m_rate_change_conn)
{
vertex_desc_t src = source(e, this->_g);
vertex_desc_t tgt = target(e, this->_g);
typename nn_t::weight_t w = this->_g[e].get_weight();
remove_edge(e, this->_g);
int max_tries = num_vertices(this->_g) * num_vertices(this->_g),
nb_tries = 0;
if (misc::flip_coin())
do
src = _random_src();
while(++nb_tries < max_tries && is_adjacent(this->_g, src, tgt));
else
do
tgt = _random_tgt();
while(++nb_tries < max_tries && is_adjacent(this->_g, src, tgt));
if (nb_tries < max_tries)
this->add_connection(src, tgt, w);
return;
}
}
};
}
}
#endif

@ -1,211 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef DNN_FF_HPP_
#define DNN_FF_HPP_
#include <modules/nn2/gen_dnn.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/dag_shortest_paths.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <boost/property_map/vector_property_map.hpp>
namespace sferes
{
namespace gen
{
template<typename N, typename C, typename Params>
class DnnFF : public Dnn<N, C, Params>
{
public:
typedef nn::NN<N, C> nn_t;
typedef N neuron_t;
typedef C conn_t;
typedef typename nn_t::io_t io_t;
typedef typename nn_t::vertex_desc_t vertex_desc_t;
typedef typename nn_t::edge_desc_t edge_desc_t;
typedef typename nn_t::graph_t graph_t;
DnnFF() {}
DnnFF& operator=(const DnnFF& o)
{
static_cast<nn::NN<N, C>& >(*this)
= static_cast<const nn::NN<N, C>& >(o);
return *this;
}
DnnFF(const DnnFF& o)
{ *this = o; }
void init()
{
Dnn<N, C, Params>::init();
_compute_depth();
}
void random()
{
assert(Params::dnn::init == dnn::ff);
this->_random_ff(Params::dnn::nb_inputs, Params::dnn::nb_outputs);
_make_all_vertices();
}
void mutate()
{
_change_conns();
this->_change_neurons();
if (misc::rand<float>() < Params::dnn::m_rate_add_conn)
_add_conn();
if (misc::rand<float>() < Params::dnn::m_rate_del_conn)
this->_del_conn();
if (misc::rand<float>() < Params::dnn::m_rate_add_neuron)
this->_add_neuron_on_conn();
if (misc::rand<float>() < Params::dnn::m_rate_del_neuron)
this->_del_neuron();
}
void cross(const DnnFF& o, DnnFF& c1, DnnFF& c2)
{
if (misc::flip_coin())
{
c1 = *this;
c2 = o;
}
else
{
c2 = *this;
c1 = o;
}
}
size_t get_depth() const { return _depth; }
protected:
std::set<vertex_desc_t> _all_vertices;
size_t _depth;
void _make_all_vertices()
{
_all_vertices.clear();
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
_all_vertices.insert(v);
}
void _change_conns()
{
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
this->_g[e].get_weight().mutate();
}
// add only feed-forward connections
void _add_conn()
{
using namespace boost;
vertex_desc_t v = this->_random_src();
std::set<vertex_desc_t> preds;
nn::bfs_pred_visitor<vertex_desc_t> vis(preds);
breadth_first_search(make_reverse_graph(this->_g),
v, color_map(get(&N::_color, this->_g)).visitor(vis));
_make_all_vertices();
std::set<vertex_desc_t> tmp, avail, in;
// avoid to connect to predecessors
std::set_difference(_all_vertices.begin(), _all_vertices.end(),
preds.begin(), preds.end(),
std::insert_iterator<std::set<vertex_desc_t> >(tmp, tmp.begin()));
// avoid to connect to inputs
BOOST_FOREACH(vertex_desc_t v, this->_inputs) // inputs need
// to be sorted
in.insert(v);
std::set_difference(tmp.begin(), tmp.end(),
in.begin(), in.end(),
std::insert_iterator<std::set<vertex_desc_t> >(avail, avail.begin()));
if (avail.empty())
return;
vertex_desc_t tgt = *misc::rand_l(avail);
typename nn_t::weight_t w;
w.random();
this->add_connection(v, tgt, w);
}
// useful to make the right number of steps
void _compute_depth()
{
using namespace boost;
typedef std::map<vertex_desc_t, size_t> int_map_t;
typedef std::map<vertex_desc_t, vertex_desc_t> vertex_map_t;
typedef std::map<vertex_desc_t, default_color_type> color_map_t;
typedef std::map<edge_desc_t, int> edge_map_t;
typedef associative_property_map<int_map_t> a_map_t;
typedef associative_property_map<color_map_t> c_map_t;
typedef associative_property_map<vertex_map_t> v_map_t;
typedef associative_property_map<edge_map_t> e_map_t;
color_map_t cm; c_map_t cmap(cm);
vertex_map_t vm; v_map_t pmap(vm);
edge_map_t em;
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
em[e] = 1;
e_map_t wmap(em);
_depth = 0;
// we compute the longest path between inputs and outputs
BOOST_FOREACH(vertex_desc_t s, this->_inputs)
{
int_map_t im; a_map_t dmap(im);
dag_shortest_paths
(this->_g, s, dmap, wmap, cmap, pmap,
dijkstra_visitor<null_visitor>(),
std::greater<int>(),
closed_plus<int>(),
std::numeric_limits<int>::min(), 0);
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
{
size_t d = get(dmap, v);
if (this->_g[v].get_out() != -1 && d <= num_vertices(this->_g))
_depth = std::max(_depth, d);
}
}
// add one to be sure
_depth ++;
}
};
}
}
#endif

@ -1,83 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef GEN_HYPER_NN_HPP_
#define GEN_HYPER_NN_HPP_
#include "neuron.hpp"
#include "pf.hpp"
#include "gen_dnn_ff.hpp"
#include "af_cppn.hpp"
namespace sferes
{
namespace gen
{
template<typename W, typename Params>
class HyperNn : public DnnFF<nn::Neuron<nn::PfWSum<W>,
nn::AfCppn<nn::cppn::AfParams<typename Params::cppn> > >,
nn::Connection<W>,
Params>
{
public:
typedef DnnFF<nn::Neuron<nn::PfWSum<W>,
nn::AfCppn<nn::cppn::AfParams<typename Params::cppn> > >,
nn::Connection<W>,
Params> nn_t;
typedef typename nn_t::neuron_t neuron_t;
typedef typename nn_t::conn_t conn_t;
void init()
{
BGL_FORALL_EDGES_T(e, this->get_graph(),
typename nn_t::graph_t)
this->get_graph()[e].get_weight().develop();
// develop the parameters
BGL_FORALL_VERTICES_T(v, this->get_graph(),
typename nn_t::graph_t)
{
this->get_graph()[v].get_afparams().develop();
this->get_graph()[v].get_pfparams().develop();
}
nn_t::init();
}
};
}
}
#endif

@ -1,111 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _IO_TRAIT_HPP_
#define _IO_TRAIT_HPP_
// for std::pair
#include <map>
#include <valarray>
#ifdef EIGEN3_ENABLED
#include <Eigen/Core>
#endif
namespace nn
{
// io trait
template<typename T>
struct io_trait
{
static T zero() { return T(0.0f); }
static T zero(size_t k) { return zero(); }
typedef std::valarray<T> vector_t;
};
#ifdef EIGEN3_ENABLED
// go with eigen with float (TODO : double)
template<>
struct io_trait<float>
{
typedef Eigen::VectorXf vector_t;
static float zero() { return 0.0f; }
static vector_t zero(size_t k) { return Eigen::VectorXf::Zero(k); }
};
#endif
template<>
struct io_trait<std::pair<float, float> >
{
static std::pair<float, float> zero() { return std::make_pair(0.0f, 0.0f); }
typedef std::valarray<std::pair<float, float> > vector_t;
};
// useful but wrong place (?)
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& ofs, const std::pair<float, float>& p)
{
return ofs<<p.first<<" "<<p.second;
}
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& ofs, const std::vector<float>& p)
{
for (size_t i = 0; i < p.size(); ++i)
ofs<<p[i]<<" ";
return ofs;
}
template<typename T1, typename T2>
std::istream& operator>>(std::istream& ifs, std::pair<T1, T2>& p)
{
T1 t1;
T2 t2;
ifs >> t1;
ifs >> t2;
return std::make_pair(t1, t2);
}
}
#endif

@ -1,100 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_MLP_HPP_
#define _NN_MLP_HPP_
#include "nn.hpp"
#include "connection.hpp"
#include "neuron.hpp"
namespace nn
{
// a basic multi-layer perceptron (feed-forward neural network)
// only one hidden layer in this version
// there's one autmatically added input for the bias
template<typename N, typename C>
class Mlp : public NN<N, C>
{
public:
typedef nn::NN<N, C> nn_t;
typedef typename nn_t::io_t io_t;
typedef typename nn_t::vertex_desc_t vertex_desc_t;
typedef typename nn_t::edge_desc_t edge_desc_t;
typedef typename nn_t::adj_it_t adj_it_t;
typedef typename nn_t::graph_t graph_t;
typedef N neuron_t;
typedef C conn_t;
Mlp(size_t nb_inputs,
size_t nb_hidden,
size_t nb_outputs)
{
// neurons
this->set_nb_inputs(nb_inputs + 1);
this->set_nb_outputs(nb_outputs);
for (size_t i = 0; i < nb_hidden; ++i)
_hidden_neurons.
push_back(this->add_neuron(std::string("h") + boost::lexical_cast<std::string>(i)));
// connections
this->full_connect(this->_inputs, this->_hidden_neurons,
trait<typename N::weight_t>::zero());
this->full_connect(this->_hidden_neurons, this->_outputs,
trait<typename N::weight_t>::zero());
// bias outputs too
for (size_t i = 0; i < nb_outputs; ++i)
this->add_connection(this->get_input(nb_inputs), this->get_output(i),
trait<typename N::weight_t>::zero());
}
unsigned get_nb_inputs() const { return this->_inputs.size() - 1; }
void step(const std::vector<io_t>& in)
{
assert(in.size() == this->get_nb_inputs());
std::vector<io_t> inf = in;
inf.push_back(1.0f);
nn_t::_step(inf);
}
protected:
std::vector<vertex_desc_t> _hidden_neurons;
};
// a basic MLP with float weights
typedef Mlp<Neuron<PfWSum<>, AfSigmoidNoBias<> >, Connection<> > mlp_t;
}
#endif

@ -1,157 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef NN_NEURON_HPP
#define NN_NEURON_HPP
#include <boost/graph/properties.hpp>
#include "trait.hpp"
namespace nn
{
// generic neuron
// Pot : potential functor (see pf.hpp)
// Act : activation functor (see af.hpp)
// IO : type of coupling between "neurons" (float or std::pair<float, float>)
template<typename Pot, typename Act, typename IO = float>
class Neuron
{
public:
typedef typename Pot::weight_t weight_t;
typedef IO io_t;
typedef Pot pf_t;
typedef Act af_t;
static io_t zero() { return trait<IO>::zero(); }
Neuron() :
_current_output(zero()),
_next_output(zero()),
_fixed(false),
_in(-1),
_out(-1)
{}
bool get_fixed() const { return _fixed; }
void set_fixed(bool b = true) { _fixed = b; }
io_t activate()
{
if (!_fixed)
_next_output = _af(_pf(_inputs));
return _next_output;
}
void init()
{
_pf.init();
_af.init();
if (get_in_degree() != 0)
_inputs = trait<io_t>::zero(get_in_degree());
_current_output = zero();
_next_output = zero();
}
void set_input(unsigned i, const io_t& in) { assert(i < _inputs.size()); _inputs[i] = in; }
void set_weight(unsigned i, const weight_t& w) { _pf.set_weight(i, w); }
typename af_t::params_t& get_afparams() { return _af.get_params(); }
typename pf_t::params_t& get_pfparams() { return _pf.get_params(); }
const typename af_t::params_t& get_afparams() const { return _af.get_params(); }
const typename pf_t::params_t& get_pfparams() const { return _pf.get_params(); }
void set_afparams(const typename af_t::params_t& p) { _af.set_params(p); }
void set_pfparams(const typename pf_t::params_t& p) { _pf.set_params(p); }
void step() { _current_output = _next_output; }
void set_in_degree(unsigned k)
{
_pf.set_nb_weights(k);
_inputs.resize(k);
if (k == 0)
return;
_inputs = trait<io_t>::zero(k);
}
unsigned get_in_degree() const { return _pf.get_weights().size(); }
// for input neurons
void set_current_output(const io_t& v) { _current_output = v; }
void set_next_output(const io_t& v) { _next_output = v; }
// standard output
const io_t& get_current_output() const { return _current_output; }
// next output
const io_t& get_next_output() const { return _next_output; }
// i/o
int get_in() const { return _in; }
void set_in(int i) { _in = i; }
int get_out() const { return _out; }
void set_out(int o) { _out = o; }
bool is_input() const { return _in != -1; }
bool is_output() const { return _out != -1; }
const Pot& get_pf() const { return _pf; }
Pot& get_pf() { return _pf; }
const Act& get_af() const { return _af; }
Act& get_af() { return _af; }
void set_id(const std::string& s) { _id = s; }
const std::string& get_id() const { return _id; }
const std::string& get_label() const { return _label; }
// for graph algorithms
std::string _id;
std::string _label;
boost::default_color_type _color;
int _index;
protected:
// activation functor
Act _af;
// potential functor
Pot _pf;
// outputs
io_t _current_output;
io_t _next_output;
// cache
typename trait<io_t>::vector_t _inputs;
// fixed = current_output is constant
bool _fixed;
// -1 if not an input of the nn, id of input otherwise
int _in;
// -1 if not an output of the nn, id of output otherwise
int _out;
};
}
#endif

@ -1,627 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_HPP_
#define _NN_HPP_
#include <iostream>
#include <fstream>
#include <utility>
#include <algorithm>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/properties.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/iteration_macros.hpp>
#include <boost/foreach.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/reverse_graph.hpp>
#include <boost/tuple/tuple.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/mpl/assert.hpp>
#include <cmath>
#include <valarray>
#include "pf.hpp"
#include "af.hpp"
#include "neuron.hpp"
#include "connection.hpp"
namespace nn
{
// a useful boost functor
template<typename V>
class bfs_pred_visitor : public boost::default_bfs_visitor
{
public:
bfs_pred_visitor(std::set<V>& pred) : _pred(pred) {}
template <typename Vertex, typename Graph >
void discover_vertex(Vertex u, const Graph & g)
{
_pred.insert(u);
}
protected:
std::set<V>& _pred;
};
// main class
// N : neuron type, C : connection type
template<typename N, typename C>
class NN
{
public:
// types
typedef boost::adjacency_list<boost::listS, boost::listS,
boost::bidirectionalS,
N, C> graph_t;
typedef typename boost::graph_traits<graph_t>::vertex_iterator vertex_it_t;
typedef typename boost::graph_traits<graph_t>::edge_iterator edge_it_t;
typedef typename boost::graph_traits<graph_t>::out_edge_iterator out_edge_it_t;
typedef typename boost::graph_traits<graph_t>::in_edge_iterator in_edge_it_t;
typedef typename boost::graph_traits<graph_t>::edge_descriptor edge_desc_t;
typedef typename boost::graph_traits<graph_t>::vertex_descriptor vertex_desc_t;
typedef typename boost::graph_traits<graph_t>::adjacency_iterator adj_it_t;
typedef typename std::vector<vertex_desc_t> vertex_list_t;
typedef N neuron_t;
typedef C conn_t;
typedef typename N::af_t af_t;
typedef typename N::pf_t pf_t;
typedef typename C::weight_t weight_t;
typedef typename C::io_t io_t;
// constructor
NN() : _neuron_counter(0), _init_done(false)
{}
NN(const NN& o) { *this = o; }
NN& operator=(const NN& o)
{
if (&o == this)
return *this;
_g = o._g;
_neuron_counter = o._neuron_counter;
_inputs.clear();
_outputs.clear();
_inputs.resize(o.get_nb_inputs());
_outputs.resize(o.get_nb_outputs());
_init_io();
_init_done = false;
return *this;
}
// init
void init() { _init(); }
// set id for inputs and outputs
void name_io() { _name_io(); }
// load/write
//void load(const std::string& fname) { _load_graph(fname); }
// void write(const std::string& fname) { _write_graph(fname); }
void write(std::ostream& ofs) { _write_dot(ofs); }
void dump(std::ostream& ofs) const
{
std::pair<vertex_it_t, vertex_it_t> vp;
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
ofs<<_g[*vp.first]._id<<" "<<_g[*vp.first].get_next_output()<<" ";
ofs<<std::endl;
}
// get the graph for graph algorithms
const graph_t& get_graph() const { return _g; }
graph_t& get_graph() { return _g; }
// construction
vertex_desc_t add_neuron(const std::string& label)
{
vertex_desc_t v = add_vertex(_g);
_g[v]._id = boost::lexical_cast<std::string>(_neuron_counter++);
_g[v]._label = label;
return v;
}
vertex_desc_t add_neuron(const std::string& label,
const typename pf_t::params_t& pf_params,
const typename af_t::params_t& af_params)
{
vertex_desc_t v = add_neuron(label);
_g[v].set_pfparams(pf_params);
_g[v].set_afparams(af_params);
return v;
}
bool add_connection(const vertex_desc_t& u,
const vertex_desc_t& v,
weight_t weight)
{
std::pair<edge_desc_t, bool> e = add_edge(u, v, _g);
if (e.second)
_g[e.first].set_weight(weight);
return e.second;
}
// special version when you need to increase weight
bool add_connection_w(const vertex_desc_t& u,
const vertex_desc_t& v,
weight_t weight)
{
std::pair<edge_desc_t, bool> e = add_edge(u, v, _g);
if (e.second)
_g[e.first].set_weight(weight);
else
_g[e.first].set_weight(_g[e.first].get_weight() + weight);
return e.second;
}
void set_all_pfparams(const std::vector<typename pf_t::params_t>& pfs)
{
assert(num_vertices(_g) == pfs.size());
size_t k = 0;
BGL_FORALL_VERTICES_T(v, _g, graph_t)
_g[v].set_pfparamst(pfs[k++]);
}
void set_all_afparams(const std::vector<typename af_t::params_t>& afs)
{
assert(num_vertices(_g) == afs.size());
size_t k = 0;
BGL_FORALL_VERTICES_T(v, _g, graph_t)
_g[v].set_afparamst(afs[k++]);
}
void set_all_weights(const std::vector<weight_t>& ws)
{
#ifndef NDEBUG
if (num_edges(_g) != ws.size())
std::cout << "param errors: "
<< num_edges(_g)
<< " whereas "
<< ws.size()
<< " provided" <<std::endl;
#endif
assert(num_edges(_g) == ws.size());
size_t k = 0;
BGL_FORALL_EDGES_T(e, _g, graph_t)
_g[e].set_weight(ws[k++]);
}
void set_nb_inputs(unsigned i)
{
_inputs.resize(i);
size_t k = 0;
BOOST_FOREACH(vertex_desc_t& v, _inputs)
{
v = add_vertex(_g);
this->_g[v].set_in(k++);
}
}
void set_nb_outputs(unsigned i)
{
_outputs.resize(i);
size_t k = 0;
BOOST_FOREACH(vertex_desc_t& v, _outputs)
{
v = add_vertex(_g);
this->_g[v].set_out(k++);
}
}
vertex_desc_t get_input(int i) const
{
assert((size_t)i < _inputs.size());
assert(this->_g[_inputs[i]].get_in() != -1);
return _inputs[i];
}
const std::vector<vertex_desc_t>& get_inputs() const { return _inputs; }
const std::vector<vertex_desc_t>& get_outputs() const { return _outputs; }
// warning : O(n)
vertex_desc_t get_neuron(size_t i) const
{
i = std::min(num_vertices(_g) - 1, i);
size_t k = 0;
BGL_FORALL_VERTICES_T(v, _g, graph_t)
if (k++ == i)
return v;
assert(0);
return (vertex_desc_t)(0x0);;
}
vertex_list_t get_neuron_list()
{
vertex_list_t neuron_list;
std::pair<vertex_it_t, vertex_it_t> vp;
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
{
neuron_list.push_back(vertex_desc_t(*vp.first));
}
return neuron_list;
}
neuron_t& get_neuron_by_vertex(vertex_desc_t v)
{
return this->_g[v];
}
io_t get_neuron_output(size_t i) const
{
return _g[get_neuron(i)].get_current_output();
}
std::string get_neuron_id(size_t i) const
{
return _g[get_neuron(i)]._id;
}
vertex_desc_t get_output(int i) const
{
assert((size_t) i < _outputs.size());
assert(this->_g[_outputs[i]].get_out() != -1);
return _outputs[i];
}
const N& get_output_neuron(int i) const
{
return _g[_outputs[i]];
}
bool is_output(const vertex_desc_t& v) const
{
return std::find(_outputs.begin(), _outputs.end(), v) != _outputs.end();
}
bool is_input(const vertex_desc_t& v) const
{
return std::find(_inputs.begin(), _inputs.end(), v) != _inputs.end();
}
// step
void step(const std::vector<io_t>& inputs) { _step(inputs); }
// accessors
const std::vector<io_t>& get_outf() const { return _outf; }
io_t get_outf(unsigned i) const { return _outf[i]; }
const std::vector<io_t>& outf() const { return get_outf(); }
io_t outf(unsigned i) const { return get_outf(i); }
unsigned get_nb_inputs() const { return _inputs.size(); }
unsigned get_nb_outputs() const { return _outputs.size(); }
unsigned get_nb_connections() const { return num_edges(_g); }
unsigned get_nb_neurons() const { return num_vertices(_g); }
// subnns
void remove_subnn(const std::set<vertex_desc_t>& subnn)
{
BOOST_FOREACH(vertex_desc_t v, subnn)
if (!is_input(v) && !is_output(v))
{
clear_vertex(v, _g);
remove_vertex(v, _g);
}
_init_io();
}
template<typename NN>
void add_subnn(const NN& nn,
const std::vector<size_t>& inputs,
const std::vector<size_t>& outputs)
{
assert(inputs.size() == nn.get_nb_inputs());
assert(outputs.size() == nn.get_nb_outputs());
std::map<typename NN::vertex_desc_t, vertex_desc_t> rmap;
const typename NN::graph_t& g_src = nn.get_graph();
BGL_FORALL_VERTICES_T(v, g_src, typename NN::graph_t)
if (g_src[v].get_in() == -1 && g_src[v].get_out() == -1)
{
vertex_desc_t nv = add_vertex(_g);
_g[nv] = g_src[v];
_g[nv]._id = boost::lexical_cast<std::string>(_neuron_counter++);
rmap[v] = nv;
}
std::vector<vertex_desc_t> vnodes;
// hoping that the order did not change too much
BGL_FORALL_VERTICES_T(v, _g, graph_t)
vnodes.push_back(v);
BGL_FORALL_EDGES_T(e, g_src, typename NN::graph_t)
{
std::pair<edge_desc_t, bool> ne;
int in = g_src[source(e, g_src)].get_in();
int out = g_src[target(e, g_src)].get_out();
assert(in == -1 || in < inputs.size());
assert(out == -1 || out < outputs.size());
if (in != -1 && out != -1)
{
int n_in = std::min(vnodes.size() - 1, inputs[in]);
int n_out = std::min(vnodes.size() - 1, outputs[out]);
ne = add_edge(vnodes[n_in], vnodes[n_out], _g);
}
else if (in != -1)
{
int n_in = std::min(vnodes.size() - 1, inputs[in]);
ne = add_edge(vnodes[n_in], rmap[target(e, g_src)], _g);
}
else if (out != -1)
{
int n_out = std::min(vnodes.size() - 1, outputs[out]);
ne = add_edge(rmap[source(e, g_src)], vnodes[n_out], _g);
}
else
{
assert(rmap.find(source(e, g_src)) != rmap.end());
assert(rmap.find(target(e, g_src)) != rmap.end());
ne = add_edge(rmap[source(e, g_src)], rmap[target(e, g_src)], _g);
}
_g[ne.first] = g_src[e];
}
_init_io();
}
// remove the connection with a weigth that is smaller (in absolute value) to the threshold
// !!! WARNING
// this method will destroy your neural network...
int remove_low_weights(float threshold)
{
int nb_removed = 0;
std::vector<edge_desc_t> to_remove;
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
{
if (fabs(_g[e].get_weight()) < threshold)
to_remove.push_back(e);
}
for (size_t i = 0; i < to_remove.size(); ++i)
remove_edge(to_remove[i], this->_g);
return to_remove.size();
}
// remove neurons that are not connected to both one input and
// one output (this is NOT callled automatically in NN
//
// WARNING: if simplify_in is true, this can change the behavior
// of neurons since neurons not connected to inputs but connected
// to outputs can output a constant value
//
// principle : keep the neurons that are successors of inputs
// and predecessors of outputs
void simplify(bool simplify_in = false)
{
// we need sets and not lists withouh io
std::set<vertex_desc_t> all_neurons;
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
if (!is_input(v) && !is_output(v))
all_neurons.insert(v);
std::set<vertex_desc_t> out_preds, in_succs;
// out
BOOST_FOREACH(vertex_desc_t v, this->_outputs)
{
std::set<vertex_desc_t> preds;
nn::bfs_pred_visitor<vertex_desc_t> vis(preds);
breadth_first_search(boost::make_reverse_graph(_g),
v, color_map(get(&N::_color, _g)).visitor(vis));
out_preds.insert(preds.begin(), preds.end());
}
// in
if (simplify_in)
BOOST_FOREACH(vertex_desc_t v, this->_inputs)
{
std::set<vertex_desc_t> succs;
nn::bfs_pred_visitor<vertex_desc_t> vis(succs);
breadth_first_search(_g,
v, color_map(get(&N::_color, _g)).visitor(vis));
in_succs.insert(succs.begin(), succs.end());
}
else
in_succs = all_neurons;
// make the intersection of in_succ and out_preds
std::set<vertex_desc_t> valid_neurons;
std::set_intersection(in_succs.begin(), in_succs.end(),
out_preds.begin(), out_preds.end(),
std::insert_iterator<std::set<vertex_desc_t> >(valid_neurons,
valid_neurons.begin()));
// get the list of neurons that are NOT in valid_neurons
std::set<vertex_desc_t> to_remove;
std::set_difference(all_neurons.begin(), all_neurons.end(),
valid_neurons.begin(), valid_neurons.end(),
std::insert_iterator<std::set<vertex_desc_t> >(to_remove,
to_remove.begin()));
// remove these neurons
BOOST_FOREACH(vertex_desc_t v, to_remove)
{
clear_vertex(v, _g);
remove_vertex(v, _g);
}
}
// fully connect two vectors of neurons
void full_connect(const std::vector<vertex_desc_t> v1,
const std::vector<vertex_desc_t> v2,
const weight_t& w)
{
BOOST_FOREACH(vertex_desc_t x, v1)
BOOST_FOREACH(vertex_desc_t y, v2)
this->add_connection(x, y, w);
}
// 1 to 1 connection
void connect(const std::vector<vertex_desc_t> v1,
const std::vector<vertex_desc_t> v2,
const weight_t& w)
{
assert(v1.size() == v2.size());
for (size_t i = 0; i < v1.size(); ++i)
this->add_connection(v1[i], v2[i], w);
}
protected:
// attributes
graph_t _g;
vertex_list_t _inputs;
vertex_list_t _outputs;
std::vector<io_t> _outf;
int _neuron_counter;
bool _init_done;
// methods
void _write_dot(std::ostream& ofs)
{
ofs << "digraph G {" << std::endl;
BGL_FORALL_VERTICES_T(v, this->_g, graph_t)
{
ofs << this->_g[v].get_id();
ofs << " [label=\""<<this->_g[v].get_id()<<"\"";
// ofs << " af"<< this->_g[v].get_afparams();
// ofs << "| pf"<< this->_g[v].get_pfparams() <<"\"";
if (is_input(v) || is_output(v))
ofs<<" shape=doublecircle";
ofs <<"]"<< std::endl;
}
BGL_FORALL_EDGES_T(e, this->_g, graph_t)
{
ofs << this->_g[source(e, this->_g)].get_id()
<< " -> " << this->_g[target(e, this->_g)].get_id()
<< "[label=\"" << _g[e].get_weight() << "\"]" << std::endl;
}
ofs << "}" << std::endl;
}
void _activate(vertex_desc_t n)
{
using namespace boost;
if (_g[n].get_fixed()) return;
in_edge_it_t in, in_end;
unsigned i = 0;
for (tie(in, in_end) = in_edges(n, _g); in != in_end; ++in, ++i)
_g[n].set_input(i, _g[source(*in, _g)].get_current_output());
_g[n].activate();
}
void _set_in(const std::vector<io_t>& inf)
{
assert(inf.size() == _inputs.size());
if (inf.size()>0) {
unsigned i = 0;
for (typename vertex_list_t::const_iterator it = _inputs.begin();
it != _inputs.end(); ++it, ++i)
{
_g[*it].set_current_output(inf[i]);
_g[*it].set_next_output(inf[i]);
}
}
}
void _set_out()
{
unsigned i = 0;
for (typename vertex_list_t::const_iterator it = _outputs.begin();
it != _outputs.end(); ++it, ++i)
_outf[i] = _g[*it].get_current_output();
}
void _step(const std::vector<io_t>& inf)
{
assert(_init_done);
// in
_set_in(inf);
// activate
std::pair<vertex_it_t, vertex_it_t> vp;
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
_activate(*vp.first);
// step
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
_g[*vp.first].step();
// out
_set_out();
}
void _name_io()
{
int i=0;
BOOST_FOREACH(vertex_desc_t v, _inputs)
{
_g[v]._id = std::string("i") + boost::lexical_cast<std::string>(i);
++i;
}
i = 0;
BOOST_FOREACH(vertex_desc_t v, _outputs) {
_g[v]._id = std::string("o") + boost::lexical_cast<std::string>(i);
++i;
}
}
void _init()
{
// BOOST_MPL_ASSERT((boost::mpl::is_same<N::weight_t, C::weight_t>));
// BOOST_MPL_ASSERT((boost::mpl::is_same<Pot::weight_t, C::weight_t>));
_outf.clear();
in_edge_it_t in, in_end;
std::pair<vertex_it_t, vertex_it_t> vp;
int k = 0;
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
{
vertex_desc_t n = *vp.first;
_g[n].set_in_degree(in_degree(n, _g));
_g[n].set_id(boost::lexical_cast<std::string>(k++));
unsigned i = 0;
for (tie(in, in_end) = in_edges(n, _g); in != in_end; ++in, ++i)
_g[n].set_weight(i, _g[*in].get_weight());
}
_outf.resize(_outputs.size());
BOOST_FOREACH(vertex_desc_t v, _inputs)
{
_g[v].set_fixed();
_g[v].set_current_output(N::zero());
}
// init to 0
for (vp = boost::vertices(_g); vp.first != vp.second; ++vp.first)
_g[*vp.first].init();
_init_io();
_name_io();
_init_done = true;
}
void _init_io()
{
BGL_FORALL_VERTICES_T(v, _g, graph_t)
{
if (_g[v].get_in() != -1)
{
assert(_g[v].get_in() < (int)_inputs.size());
_inputs[_g[v].get_in()] = v;
}
if (_g[v].get_out() != -1)
{
assert(_g[v].get_out() < (int)_outputs.size());
_outputs[_g[v].get_out()] = v;
}
}
}
};
}
#endif

@ -1,93 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_PARAMS_HPP_
#define _NN_PARAMS_HPP_
namespace nn
{
namespace params
{
struct Dummy
{
friend std::ostream& operator<<(std::ostream& output, const Dummy& e);
Dummy() : _x(42) {}
void mutate() {}
void random() {}
void develop() {}
size_t size() const { return 0; }
float data(size_t i) const { return 0.0f;}
float& operator[](size_t i) { return _x; }
float operator[](size_t i) const { return _x; }
template<typename A>
void serialize(A& ar, unsigned int v) {}
typedef float type_t;
protected:
float _x;
};
std::ostream& operator<<(std::ostream& output, const Dummy& e) {
return output;
}
template<int S>
struct Vectorf
{
typedef float type_t;
BOOST_STATIC_CONSTEXPR int s=S;
Vectorf() : _data(S) {}
// magic cast !
template<typename T>
Vectorf(const T& v) :
_data(S)
{
assert(v.size() == S);
for (size_t i = 0; i < v.size(); ++i)
_data[i] = v.data(i);
}
float data(size_t i) const { assert(i < S) ; return _data[i]; }
float& operator[](size_t i) { return _data[i]; }
float operator[](size_t i) const { return _data[i]; }
size_t size() const { return _data.size(); }
void mutate() {}
void random() {}
void develop() {}
protected:
std::vector<float> _data;
};
}
}
#endif

@ -1,168 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef NN_PF_HPP
#define NN_PF_HPP
#include <cstdlib>
#include <sferes/misc/rand.hpp>
#include "params.hpp"
#include "trait.hpp"
// potential functions (weighted sum, leaky integrator, etc.)
namespace nn
{
template<typename W = float, typename P = params::Dummy>
class Pf
{
public:
typedef P params_t;
typedef W weight_t;
const params_t& get_params() const { return _params; }
params_t& get_params() { return _params; }
void set_params(const params_t& params) { _params = params; }
void init() {}
// weights are stored in the pf function for efficiency reasons
void set_nb_weights(size_t n) { _weights.resize(n); }
void set_weight(size_t i, const W& w) { assert(i < _weights.size()); _weights[i] = w; }
const std::valarray<W>& get_weights() const { return _weights; }
// main function
template<typename IO>
float operator() (const typename trait<IO>::vector_t & inputs) const { return 0.0f; }
protected:
params_t _params;
// cache weights
std::valarray<W> _weights;
};
template<typename W = float>
struct PfWSum : public Pf<W>
{
typedef params::Dummy params_t;
typedef W weight_t;
void init()
{
_w_cache.resize(this->_weights.size());
for (size_t i = 0; i < this->_weights.size(); ++i)
_w_cache[i] = trait<weight_t>::single_value(this->_weights[i]);
}
float operator() (const trait<float>::vector_t & inputs) const
{
assert(inputs.size() == _w_cache.size());
//std::cout<<"in:"<<inputs.transpose()<<" w:"<<_w_cache.transpose()<<"=>"<<
//_w_cache.dot(inputs)<<std::endl;
if (inputs.size() == 0)
return 0.0f;
#ifdef EIGEN3_ENABLED
return _w_cache.dot(inputs);
#else
#warning "No EIGEN3 -> no vectorization of pwfsum"
return (_w_cache * inputs).sum();
#endif
}
protected:
trait<float>::vector_t _w_cache;
};
// Ijsspert's coupled non-linear oscillators
// see : Learning to Move in Modular Robots using Central Pattern
// Generators and Online Optimization, 2008
// Main parameters:
// - phi_i: phase lag
// - r_i: amplitude
// - x_i: offset
// - _omega: frequency
template<typename P>
struct PfIjspeert : public Pf<std::pair<float, float>, P>
{
typedef std::pair<float, float> weight_t;
typedef P params_t;
BOOST_STATIC_CONSTEXPR float dt = 0.01;
BOOST_STATIC_CONSTEXPR float a_r = 20.0f;
BOOST_STATIC_CONSTEXPR float a_x = 20.0f;
void set_r(float r) { _r = r; }
void set_x(float x) { _x = x; }
void set_omega(float o) { _omega = o; }
float get_theta_i() const { return _theta_i; }
void init()
{
_phi_i = 0; //sferes::misc::rand<float>();
_r_i = 0; //sferes::misc::rand<float>();
_x_i = 0; //sferes::misc::rand<float>();
_theta_i = 0;
_phi_i_d = 0; _r_i_d = 0; _x_i_d = 0;
}
// depends on r_j and phi_j
weight_t operator() (const trait<weight_t>::vector_t & inputs)
{
_phi_i_d = _omega;
for (size_t j = 0; j < inputs.size(); ++j)
{
float r_j = inputs[j].first;
float phi_j = inputs[j].second;
float w_ij = this->_weights[j].first;
float phi_ij = this->_weights[j].second;
std::cout << "phi_ij:" << phi_ij << " " << inputs.size() << std::endl;
_phi_i_d += w_ij * r_j * sin(phi_j - phi_ij - _phi_i);
}
float r_i_dd = a_r * (a_r / 4 * (_r - _r_i) - _r_i_d);
float x_i_dd = a_r * (a_r / 4 * (_x - _x_i) - _x_i_d);
// integrate
_r_i_d += r_i_dd * dt;
_r_i += _r_i_d * dt;
_x_i_d += x_i_dd * dt;
_x_i += _x_i_d * dt;
_phi_i += _phi_i_d * dt;
// result
_theta_i = _x_i + _r_i *cos(_phi_i);
return std::make_pair(_r_i, _phi_i);
}
private:
// states
float _phi_i, _r_i, _theta_i, _x_i;
// states dot
float _phi_i_d, _r_i_d, _x_i_d;
// parameters
float _r, _x, _omega;
};
}
#endif

@ -1,79 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_DNN_HPP
#define PHEN_DNN_HPP
#include <map>
#include <sferes/phen/indiv.hpp>
#include "gen_dnn.hpp"
namespace sferes
{
namespace phen
{
SFERES_INDIV(Dnn, Indiv)
{
public:
void develop()
{
// develop the parameters
BGL_FORALL_VERTICES_T(v, this->gen().get_graph(),
typename nn_t::graph_t)
{
this->gen().get_graph()[v].get_afparams().develop();
this->gen().get_graph()[v].get_pfparams().develop();
}
BGL_FORALL_EDGES_T(e, this->gen().get_graph(),
typename nn_t::graph_t)
{
this->gen().get_graph()[e].get_weight().develop();
}
// init everything
this->_gen.init();
}
void show(std::ostream& os) { this->gen().write(os); }
typedef typename Gen::nn_t nn_t;
nn_t& nn() { return this->gen(); }
const nn_t& nn() const { return this->gen(); }
protected:
};
}
}
#endif

@ -1,308 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef PHEN_HYPER_NN_HPP
#define PHEN_HYPER_NN_HPP
#include <map>
#include <sferes/phen/indiv.hpp>
#include <modules/nn2/nn.hpp>
#include <modules/nn2/params.hpp>
#include "gen_hyper_nn.hpp"
namespace sferes
{
namespace phen
{
namespace hnn
{
class Pos
{
public:
Pos() {
}
Pos(float x, float y, float z) : _x(x), _y(y), _z(z) {
}
float dist(const Pos& p) const
{
float x = _x - p._x;
float y = _y - p._y;
float z = _z - p._z;
return sqrt(x * x + y * y + z * z);
}
float x() const {
return _x;
}
float y() const {
return _y;
}
float z() const {
return _z;
}
template<class Archive>
void serialize(Archive& ar, const unsigned int version)
{
ar& BOOST_SERIALIZATION_NVP(_x);
ar& BOOST_SERIALIZATION_NVP(_y);
ar& BOOST_SERIALIZATION_NVP(_z);
}
bool operator == (const Pos &p)
{ return _x == p._x && _y == p._y && _z == p._z; }
protected:
float _x, _y, _z;
};
}
// hyperneat-inspired phenotype, based on a cppn
SFERES_INDIV(HyperNn, Indiv)
{
public:
typedef Gen gen_t;
typedef typename Params::hyper_nn::neuron_t neuron_t;
typedef typename Params::hyper_nn::connection_t connection_t;
typedef typename nn::NN<neuron_t, connection_t> nn_t;
typedef typename nn_t::vertex_desc_t v_d_t;
typedef typename gen_t::nn_t gen_nn_t;
SFERES_CONST size_t nb_pfparams = Params::hyper_nn::nb_pfparams;
SFERES_CONST size_t nb_afparams = Params::hyper_nn::nb_afparams;
SFERES_CONST size_t nb_cppn_inputs = 2 + 2;
SFERES_CONST size_t nb_cppn_outputs = 2;
void develop()
{
this->_nn = nn_t();
this->gen().init();
// develop the parameters
BGL_FORALL_VERTICES_T(v, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
{
this->gen().get_graph()[v].get_afparams().develop();
this->gen().get_graph()[v].get_pfparams().develop();
}
BGL_FORALL_EDGES_T(e, this->gen().get_graph(),
typename gen_t::nn_t::graph_t)
this->gen().get_graph()[e].get_weight().develop();
assert(nb_cppn_inputs == this->gen().get_nb_inputs());
assert(nb_cppn_outputs == this->gen().get_nb_outputs());
_all_neurons.clear();
size_t d = this->gen().get_depth();
// create the nn
_nn.set_nb_inputs(Params::hyper_nn::nb_inputs);
_nn.set_nb_outputs(Params::hyper_nn::nb_outputs);
SFERES_CONST size_t skip =
Params::hyper_nn::nb_inputs
+ Params::hyper_nn::nb_outputs;
SFERES_CONST size_t skip_total =
Params::hyper_nn::nb_inputs
+ Params::hyper_nn::nb_outputs
+ Params::hyper_nn::nb_hidden;
BGL_FORALL_VERTICES_T(v, _nn.get_graph(), typename nn_t::graph_t)
/**/ _all_neurons.push_back(v);
// hidden neurons
for (size_t i = 0; i < Params::hyper_nn::nb_hidden; ++i)
{
v_d_t v = _nn.add_neuron(boost::lexical_cast<std::string>(i));
_all_neurons.push_back(v);
}
assert(_all_neurons.size() ==
Params::hyper_nn::substrate_size() / 2
- Params::hyper_nn::nb_pfparams
- Params::hyper_nn::nb_afparams);
// build the coordinate map
for (size_t i = 0; i < _all_neurons.size() * 2; i += 2)
this->_coords_map[_all_neurons[i / 2]] =
hnn::Pos(Params::hyper_nn::substrate(i),
Params::hyper_nn::substrate(i + 1), 0);
// afparams and pfparams
for (size_t i = 0; i < _all_neurons.size(); ++i)
{
typename neuron_t::pf_t::params_t pfparams;
// we put pfparams & afparams in [0:1]
//for (size_t k = 0; k < nb_pfparams; ++k)
//{
// pfparams[k] = cppn_value(skip_total + k, i, false, 1) / 2.0f + 0.5f;
// std::cout << " " << pfparams[k] << " ";
//}
typename neuron_t::af_t::params_t
afparams;
for (size_t k = 0; k < nb_afparams; ++k)
{
float b = cppn_value(skip_total + k + nb_pfparams, i,
k + 1, false) / 2.0f + 0.5f;
size_t bi = b * Params::hyper_nn::bias_size();
bi = std::min(bi, Params::hyper_nn::bias_size() - 1);
afparams[k] = Params::hyper_nn::bias(bi);
}
_nn.get_graph()[_all_neurons[i]].
set_pfparams(pfparams);
_nn.get_graph()[_all_neurons[i]].
set_afparams(afparams);
}
// create connections
for (size_t i = 0; i < skip_total * 2; i += 2)
for (size_t j = 0; j < skip_total * 2; j += 2)
if (!_nn.is_input(_all_neurons[j / 2]))
{
float w = cppn_value(i, j, 0, true);
float ws = w >= 0 ? 1 : -1;
ws *=
(fabs(w) -
Params::hyper_nn::conn_threshold) / (1 - Params::hyper_nn::conn_threshold);
// TODO generalize this
// ws is in [-1, 1] TODO : no guarantee that ws is in [-1;1]
size_t wi = (int) ((ws / 2.0 + 0.5) * Params::hyper_nn::weights_size());
wi = std::min(wi, Params::hyper_nn::weights_size() - 1);
float wf = Params::hyper_nn::weights(wi);
typename connection_t::weight_t weight = typename connection_t::weight_t(wf);
if (fabs(w) >
Params::hyper_nn::conn_threshold)
_nn.add_connection(_all_neurons[i / 2],
_all_neurons[j / 2],
weight);
}
this->_nn.init();
}
float cppn_value(size_t i, size_t j,
size_t n, bool ff = false)
{
assert(i < Params::hyper_nn::substrate_size());
assert(j < Params::hyper_nn::substrate_size());
assert(i + 1 < Params::hyper_nn::substrate_size());
assert(j + 1 < Params::hyper_nn::substrate_size());
assert(n < nb_cppn_outputs);
std::vector<float> in(nb_cppn_inputs);
this->gen().init();
in[0] = Params::hyper_nn::substrate(i);
in[1] = Params::hyper_nn::substrate(i + 1);
in[2] = Params::hyper_nn::substrate(j);
in[3] = Params::hyper_nn::substrate(j + 1);
if (in[1] == in[3])
return 0;
if (ff && (in[1] > in[3] || fabs(in[1] - in[3]) > Params::hyper_nn::max_y))
return 0;
for (size_t k = 0; k < this->gen().get_depth(); ++k)
this->gen().step(in);
return this->gen().get_outf(n);
}
void write_svg(std::ostream& ofs)
{
//_nn.write(os);
//std::ofstream ofs("/tmp/nn.svg");
ofs << "<svg width=\"200px\" height=\"200px\" viewbox=\"-500 -500 500 500\">";
for (size_t i = 0; i < _all_neurons.size() * 2; i += 2)
{
float x = Params::hyper_nn::substrate(i);
float y = Params::hyper_nn::substrate(i + 1);
ofs << "<circle cx=\"" << x * 80 + 100
<< "\" cy=\"" << y * 80 + 100
<< "\" r=\"2\" fill=\"black\" "
<< "opacity=\""
<< 1
// << std::max(0.0f, _nn.get_graph()[_all_neurons[i / 2]].get_pfparams()[0])
<< "\" "
<< " />" << std::endl;
}
typedef typename nn_t::graph_t graph_t;
typedef typename nn_t::vertex_desc_t v_d_t;
const graph_t& g = this->nn().get_graph();
BGL_FORALL_EDGES_T(e, g, graph_t)
{
v_d_t src = boost::source(e, g);
v_d_t tgt = boost::target(e, g);
float x1 = _coords_map[src].x() * 80 + 100;
float y1 = _coords_map[src].y() * 80 + 100;
float x2 = _coords_map[tgt].x() * 80 + 100;
float y2 = _coords_map[tgt].y() * 80 + 100;
double weight = g[e].get_weight();
ofs << "<line x1=\"" << x1 << "\" y1=\"" << y1 << "\" "
<< "x2=\"" << x2 << "\" y2=\"" << y2 << "\""
<< " style=\"stroke:rgb("
<< (weight > 0 ? "0,255,0" : "255,0,0")
<< ");stroke-width:" << fabs(weight)
<< "\"/>"
<< std::endl;
}
ofs << "</svg>";
}
nn_t& nn() {
return _nn;
}
const nn_t& nn() const {
return _nn;
}
const std::vector<typename nn_t::vertex_desc_t>&
all_neurons() const {
return _all_neurons;
}
float compute_length(float min_length)
{
float length = 0;
BGL_FORALL_EDGES_T(e, _nn.get_graph(), typename nn_t::graph_t)
{
typename nn_t::vertex_desc_t src = boost::source(e, _nn.get_graph());
typename nn_t::vertex_desc_t tgt = boost::target(e, _nn.get_graph());
double weight = _nn.get_graph()[e].get_weight();
float l = _coords_map[src].dist(_coords_map[tgt]);
length += l > min_length ? l : 0;
}
return length;
}
protected:
nn_t _nn;
std::vector<typename nn_t::vertex_desc_t> _all_neurons;
std::map<typename nn_t::vertex_desc_t, hnn::Pos> _coords_map;
};
}
}
#endif

@ -1,219 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dnn
#include <iostream>
#include <cmath>
#include <algorithm>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/assign/std/vector.hpp>
#include <boost/assign/list_of.hpp>
#include <sferes/fit/fitness.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/phen/parameters.hpp>
#include "gen_dnn.hpp"
#include "phen_dnn.hpp"
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
template<typename T1, typename T2>
void check_list_equal(const T1& v1, const T2& v2)
{
BOOST_CHECK_EQUAL(v1.size(), v2.size());
typename T1::const_iterator it1 = v1.begin();
typename T1::const_iterator it2 = v2.begin();
for (; it1 != v1.end(); ++it1, ++it2)
BOOST_CHECK(fabs(*it1 - *it2) < 1e-3);
}
template<typename NN>
void check_nn_equal(NN& nn1, NN& nn2)
{
nn1.init();
nn2.init();
BOOST_CHECK_EQUAL(nn1.get_nb_inputs(), nn2.get_nb_inputs());
BOOST_CHECK_EQUAL(nn1.get_nb_outputs(), nn2.get_nb_outputs());
BOOST_CHECK_EQUAL(nn1.get_nb_neurons(), nn2.get_nb_neurons());
BOOST_CHECK_EQUAL(nn1.get_nb_connections(), nn2.get_nb_connections());
// nn1.write("/tmp/tmp1.dot");
// nn2.write("/tmp/tmp2.dot");
// std::ifstream ifs1("/tmp/tmp1.dot"), ifs2("/tmp/tmp2.dot");
// while(!ifs1.eof() && !ifs2.eof())
// {
// //if (ifs1.get() != ifs2.get()) exit(1);
// BOOST_CHECK_EQUAL((char)ifs1.get(), (char)ifs2.get());
// }
std::pair<typename NN::vertex_it_t, typename NN::vertex_it_t> vp1 =
boost::vertices(nn1.get_graph());
std::pair<typename NN::vertex_it_t, typename NN::vertex_it_t> vp2 =
boost::vertices(nn2.get_graph());
while (vp1.first != vp1.second)
{
BOOST_CHECK_EQUAL(nn1.get_graph()[*vp1.first].get_in_degree(),
nn2.get_graph()[*vp2.first].get_in_degree());
check_list_equal(nn1.get_graph()[*vp1.first].get_afparams(),
nn2.get_graph()[*vp1.first].get_afparams());
check_list_equal(nn1.get_graph()[*vp1.first].get_pfparams(),
nn2.get_graph()[*vp1.first].get_pfparams());
++vp1.first;
++vp2.first;
}
}
struct Params
{
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -5.0f;
// minimum value
SFERES_CONST float max = 5.0f;
};
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST size_t min_nb_neurons = 4;
SFERES_CONST size_t max_nb_neurons = 5;
SFERES_CONST size_t min_nb_conns = 100;
SFERES_CONST size_t max_nb_conns = 101;
SFERES_CONST float max_weight = 2.0f;
SFERES_CONST float max_bias = 2.0f;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 1.0f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 1.0f;
SFERES_CONST int io_param_evolving = true;
SFERES_CONST init_t init = random_topology;
};
};
BOOST_AUTO_TEST_CASE(direct_gen)
{
using namespace nn;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> bias_t;
typedef PfWSum<weight_t> pf_t;
typedef AfTanh<bias_t> af_t;
sferes::gen::Dnn<Neuron<pf_t, af_t>, Connection<weight_t>, Params> gen1, gen2, gen3, gen4;
gen1.random();
gen2.random();
gen1.cross(gen2, gen3, gen4);
gen3.mutate();
gen4.mutate();
gen2.mutate();
}
BOOST_AUTO_TEST_CASE(direct_nn_serialize)
{
srand(0);
using namespace nn;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> bias_t;
typedef PfWSum<weight_t> pf_t;
typedef AfTanh<bias_t> af_t;
typedef sferes::gen::Dnn<Neuron<pf_t, af_t>, Connection<weight_t>, Params> gen_t;
typedef phen::Dnn<gen_t, fit::FitDummy<>, Params> phen_t;
typedef boost::archive::binary_oarchive oa_t;
typedef boost::archive::binary_iarchive ia_t;
for (size_t i = 0; i < 10; ++i)
{
phen_t indiv[3];
indiv[0].random();
indiv[0].mutate();
indiv[0].mutate();
indiv[0].mutate();
indiv[0].nn().init();
{
std::ofstream ofs("/tmp/serialize_nn1.bin", std::ios::binary);
oa_t oa(ofs);
oa & indiv[0];
}
{
std::ifstream ifs("/tmp/serialize_nn1.bin", std::ios::binary);
ia_t ia(ifs);
ia & indiv[1];
}
indiv[2].nn() = indiv[0].nn();
using namespace boost::assign;
std::vector<float> in = list_of(0.5f)(1.0f)(-0.25f)(1.101f);
for (size_t j = 0; j < 3; ++j)
indiv[j].nn().init();
for (size_t i = 0; i < 10; ++i)
for (size_t j = 0; j < 3; ++j)
indiv[j].nn().step(in);
for (size_t j = 1; j < 3; ++j)
BOOST_CHECK_CLOSE(indiv[0].nn().get_outf(0), indiv[j].nn().get_outf(0), 1e-5);
}
}

@ -1,145 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dnn_ff
#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/serialization/nvp.hpp>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <boost/graph/depth_first_search.hpp>
#include <sferes/fit/fitness.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/phen/parameters.hpp>
#include "gen_dnn_ff.hpp"
#include "phen_dnn.hpp"
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params
{
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
// maximum value of parameters
SFERES_CONST float min = -5.0f;
// minimum value
SFERES_CONST float max = 5.0f;
};
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 2;
SFERES_CONST size_t min_nb_neurons = 4;
SFERES_CONST size_t max_nb_neurons = 5;
SFERES_CONST size_t min_nb_conns = 100;
SFERES_CONST size_t max_nb_conns = 101;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 0.1f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 1.0f;
SFERES_CONST int io_param_evolving = true;
SFERES_CONST init_t init = ff;
};
};
struct cycle_detector : public boost::dfs_visitor<>
{
cycle_detector(bool& has_cycle)
: m_has_cycle(has_cycle) { }
template <class Edge, class Graph>
void back_edge(Edge, Graph&) { m_has_cycle = true; }
protected:
bool& m_has_cycle;
};
BOOST_AUTO_TEST_CASE(direct_nn_ff)
{
srand(time(0));
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> weight_t;
typedef phen::Parameters<gen::EvoFloat<1, Params>, fit::FitDummy<>, Params> bias_t;
typedef nn::PfWSum<weight_t> pf_t;
typedef nn::AfTanh<bias_t> af_t;
typedef nn::Neuron<pf_t, af_t> neuron_t;
typedef nn::Connection<weight_t> connection_t;
typedef gen::DnnFF<neuron_t, connection_t, Params> gen_t;
typedef phen::Dnn<gen_t, fit::FitDummy<Params>, Params> phen_t;
phen_t i;
i.random();
i.develop();
std::vector<float> in(4);
std::fill(in.begin(), in.end(), 0);
i.nn().step(in);
BOOST_CHECK_EQUAL(i.nn().get_nb_inputs(), 4);
BOOST_CHECK_EQUAL(i.nn().get_nb_outputs(), 2);
BOOST_CHECK_EQUAL(i.nn().get_nb_neurons(), 6);
BOOST_CHECK_EQUAL(i.nn().get_nb_connections(), 8);
std::ofstream ofs("/tmp/nn.dot");
i.nn().write(ofs);
for (size_t k = 0; k < 40; ++k)
i.mutate();
std::ofstream ofs2("/tmp/nn2.dot");
i.nn().write(ofs2);
bool has_cycle = false;
cycle_detector vis(has_cycle);
boost::depth_first_search(i.nn().get_graph(),
boost::color_map(get(&phen_t::nn_t::neuron_t::_color,
i.nn().get_graph())).visitor(vis));
BOOST_CHECK(!has_cycle);
}

@ -1,240 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dnn
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <sferes/fit/fitness.hpp>
#include <sferes/phen/parameters.hpp>
#include "gen_dnn.hpp"
#include "gen_hyper_nn.hpp"
#include "phen_hyper_nn.hpp"
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params1
{
struct dnn
{
SFERES_CONST size_t nb_inputs = 3;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
SFERES_CONST float min = -2.0f;
SFERES_CONST float max = 2.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, 0, 1, 2);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
};
struct Params2
{
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST float weight_sigma = 0.5f;
SFERES_CONST float vect_sigma = 0.5f;
SFERES_CONST float m_rate_weight = 1.0f;
SFERES_CONST float m_rate_fparams = 1.0f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
SFERES_CONST float min = -2.0f;
SFERES_CONST float max = 2.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, 0, 1, 2);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
struct hyper_nn
{
SFERES_ARRAY(float, substrate,
0.2f, 0.2f, // in 1
0.2f, 0.8f, // in 2
0.5f, 0.5f, // out 1
0.8f, 0.8f, // hidden 1
0.8f, 0.2f, // hidden 2
0.2f, 0.5f, // hidden 3
0.5f, 0.2f // hidden 4
);
SFERES_ARRAY(float, weights, -1, 0, 1);
SFERES_ARRAY(float, bias, -1, 0, 1);
SFERES_CONST size_t nb_inputs = 2;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST size_t nb_hidden = 4;
SFERES_CONST size_t nb_pfparams = 0;
SFERES_CONST size_t nb_afparams = 1;
SFERES_CONST float conn_threshold = 0.2f;
SFERES_CONST float max_y = 10.0f;
typedef nn::Neuron<nn::PfWSum<>,
nn::AfTanh<nn::params::Vectorf<1> > > neuron_t;
typedef nn::Connection<> connection_t;
};
};
BOOST_AUTO_TEST_CASE(gen_cppn)
{
srand(time(0));
typedef phen::Parameters<gen::EvoFloat<1, Params1>, fit::FitDummy<>, Params1> weight_t;
typedef gen::HyperNn<weight_t, Params1> cppn_t;
cppn_t gen1, gen2, gen3, gen4;
gen1.random();
for (size_t i = 0; i < 20; ++i)
gen1.mutate();
gen1.init();
BOOST_CHECK(gen1.get_depth() >= 1);
std::ofstream ofs2("/tmp/nn.dot");
gen1.write(ofs2);
// generate a picture
char*pic = new char[256 * 256];
std::vector<float> in(3);
in[0] = 1;
for (size_t i = 0; i < 256; ++i)
for (size_t j = 0; j < 256; ++j)
{
in[1] = i / 128.0f - 1.0;
in[2] = j / 128.0f - 1.0;
for (size_t k = 0; k < gen1.get_depth(); ++k)
gen1.step(in);
pic[256 * i + j] = (int)(gen1.get_outf(0) * 256 + 255);
}
std::ofstream ofs("/tmp/pic.pgm");
ofs << "P5" << std::endl;
ofs << "256 256" << std::endl;
ofs << "255" << std::endl;
ofs.write(pic, 256 * 256);
}
BOOST_AUTO_TEST_CASE(phen_hyper_nn)
{
srand(time(0));
typedef fit::FitDummy<> fit_t;
typedef phen::Parameters<gen::EvoFloat<1, Params2>, fit::FitDummy<>, Params2> weight_t;
typedef gen::HyperNn<weight_t, Params2> gen_t;
typedef phen::HyperNn<gen_t, fit_t, Params2> phen_t;
phen_t indiv;
indiv.random();
for (size_t i = 0; i < 5; ++i)
indiv.mutate();
std::ofstream ofs("/tmp/nn_substrate.svg");
indiv.develop();
indiv.show(ofs);
// BOOST_CHECK_EQUAL(indiv.nn().get_nb_neurons(), 7);
}

@ -1,263 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE dnn
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <sferes/fit/fitness.hpp>
#include <sferes/phen/parameters.hpp>
#include "gen_dnn.hpp"
#include "gen_hyper_nn.hpp"
#include "phen_hyper_nn.hpp"
#include <boost/algorithm/string/join.hpp>
#include <vector>
using namespace sferes;
using namespace sferes::gen::dnn;
using namespace sferes::gen::evo_float;
struct Params1
{
struct dnn
{
SFERES_CONST size_t nb_inputs = 3;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.5f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
SFERES_CONST float min = -2.0f;
SFERES_CONST float max = 2.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, 0, 1, 2);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
};
struct Params2
{
struct dnn
{
SFERES_CONST size_t nb_inputs = 4;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST float m_rate_add_conn = 1.0f;
SFERES_CONST float m_rate_del_conn = 0.3f;
SFERES_CONST float m_rate_change_conn = 1.0f;
SFERES_CONST float m_rate_add_neuron = 1.0f;
SFERES_CONST float m_rate_del_neuron = 0.2f;
SFERES_CONST float weight_sigma = 0.5f;
SFERES_CONST float vect_sigma = 0.5f;
SFERES_CONST float m_rate_weight = 1.0f;
SFERES_CONST float m_rate_fparams = 1.0f;
SFERES_CONST init_t init = ff;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
struct parameters
{
SFERES_CONST float min = -2.0f;
SFERES_CONST float max = 2.0f;
};
struct cppn
{
// params of the CPPN
struct sampled
{
SFERES_ARRAY(float, values, 0, 1, 2);
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.25f;
SFERES_CONST bool ordered = false;
};
struct evo_float
{
SFERES_CONST float mutation_rate = 0.1f;
SFERES_CONST float cross_rate = 0.1f;
SFERES_CONST mutation_t mutation_type = polynomial;
SFERES_CONST cross_over_t cross_over_type = sbx;
SFERES_CONST float eta_m = 15.0f;
SFERES_CONST float eta_c = 15.0f;
};
};
struct hyper_nn
{
SFERES_ARRAY(float, substrate,
0.2f, 0.2f, // in 1
0.2f, 0.8f, // in 2
0.5f, 0.5f, // out 1
0.8f, 0.8f, // hidden 1
0.8f, 0.2f, // hidden 2
0.2f, 0.5f, // hidden 3
0.5f, 0.2f // hidden 4
);
SFERES_ARRAY(float, weights, -1, 0, 1);
SFERES_ARRAY(float, bias, -1, 0, 1);
SFERES_CONST size_t nb_inputs = 2;
SFERES_CONST size_t nb_outputs = 1;
SFERES_CONST size_t nb_hidden = 4;
SFERES_CONST size_t nb_pfparams = 0;
SFERES_CONST size_t nb_afparams = 1;
SFERES_CONST float conn_threshold = 0.2f;
SFERES_CONST float max_y = 10.0f;
typedef nn::Neuron<nn::PfWSum<>,
nn::AfTanh<nn::params::Vectorf<1> > > neuron_t;
typedef nn::Connection<> connection_t;
};
};
BOOST_AUTO_TEST_CASE(gen_cppn)
{
int nb_images = 0;
for (; nb_images < 10; ++nb_images)
{
// time_t seconds = time (nb_images);
srand (nb_images);
std::string ts = boost::lexical_cast<std::string> (nb_images);
typedef phen::Parameters<gen::EvoFloat<1, Params1>, fit::FitDummy<>,
Params1> weight_t;
typedef gen::HyperNn<weight_t, Params1> cppn_t;
cppn_t gen1, gen2, gen3, gen4;
gen1.random ();
// for (size_t i = 0; i < 20; ++i)
// gen1.mutate ();
gen1.init ();
BOOST_CHECK(gen1.get_depth () >= 1);
// std::ofstream ofs2 ("./nn.dot");
// gen1.write (ofs2);
// generate a picture
char*pic = new char[256 * 256];
std::vector<float> in (3);
in[0] = 1;
for (size_t i = 0; i < 256; ++i)
for (size_t j = 0; j < 256; ++j)
{
in[1] = i / 128.0f - 1.0;
in[2] = j / 128.0f - 1.0;
for (size_t k = 0; k < gen1.get_depth (); ++k)
gen1.step (in);
pic[256 * i + j] = (int) (gen1.get_outf (0) * 256 + 255);
}
std::vector < std::string > list;
list.push_back ("/home/anh/workspace/sferes/tmp/");
list.push_back ("image_");
list.push_back (ts);
list.push_back (".pgm");
std::string joined = boost::algorithm::join (list, "");
std::ofstream ofs (joined.c_str ());
ofs << "P5" << std::endl;
ofs << "256 256" << std::endl;
ofs << "255" << std::endl;
ofs.write (pic, 256 * 256);
}
}
/*
BOOST_AUTO_TEST_CASE(phen_hyper_nn)
{
srand(time(0));
typedef fit::FitDummy<> fit_t;
typedef phen::Parameters<gen::EvoFloat<1, Params2>, fit::FitDummy<>, Params2> weight_t;
typedef gen::HyperNn<weight_t, Params2> gen_t;
typedef phen::HyperNn<gen_t, fit_t, Params2> phen_t;
phen_t indiv;
indiv.random();
for (size_t i = 0; i < 5; ++i)
indiv.mutate();
std::ofstream ofs("/tmp/nn_substrate.svg");
indiv.develop();
indiv.show(ofs);
// BOOST_CHECK_EQUAL(indiv.nn().get_nb_neurons(), 7);
}
*/

@ -1,62 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE nn_mlp
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <cmath>
#include <algorithm>
#include "mlp.hpp"
BOOST_AUTO_TEST_CASE(nn_elman)
{
using namespace nn;
Mlp<Neuron<PfWSum<>, AfSigmoidNoBias<> >, Connection<> > nn(2, 3, 2);
nn.init();
BOOST_CHECK_EQUAL(nn.get_nb_neurons(), 3 + 3 + 2);
BOOST_CHECK_EQUAL(nn.get_nb_connections(), 9 + 6 + 2);
std::vector<float> in(2);
in[0] = 1.0f;
in[1] = 0.2f;
for (unsigned i = 0; i < 1000; ++i)
nn.step(in);
float out1 = nn.get_outf(0);
float out2 = nn.get_outf(1);
}

@ -1,138 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE nn
#include <boost/test/unit_test.hpp>
#include <boost/timer.hpp>
#include <iostream>
#include <cmath>
#include <algorithm>
#include "nn.hpp"
BOOST_AUTO_TEST_CASE(nn_basic)
{
using namespace nn;
NN<Neuron<PfWSum<>, AfTanh<float> >, Connection<> > nn1, nn2, nn3;
nn1.set_nb_inputs(1);
nn1.set_nb_outputs(2);
nn1.full_connect(nn1.get_inputs(), nn1.get_outputs(), 1.0f);
nn1.init();
std::vector<float> in(1);
in[0] = 1.0f;
for (size_t i = 0; i < 200; ++i)
nn1.step(in);
float out = nn1.get_outf(0);
BOOST_CHECK_CLOSE((double)out, tanh(5.0 * 1.0f), 1e-5);
std::ofstream ofs("/tmp/test.dot");
nn1.write(ofs);
// check memory usage
nn2 = nn1;
for (size_t i = 0; i < 2000; ++i)
{
nn3 = nn2;
nn2 = nn1;
nn1 = nn3;
}
BOOST_CHECK_EQUAL(nn3.get_nb_connections(), nn1.get_nb_connections());
BOOST_CHECK_EQUAL(nn3.get_nb_neurons(), nn1.get_nb_neurons());
BOOST_CHECK_EQUAL(nn3.get_nb_inputs(), nn1.get_nb_inputs());
BOOST_CHECK_EQUAL(nn3.get_nb_outputs(), nn1.get_nb_outputs());
}
BOOST_AUTO_TEST_CASE(nn_remove_small_weights)
{
using namespace nn;
NN<Neuron<PfWSum<>, AfTanh<float> >, Connection<> > nn;
nn.set_nb_inputs(3);
nn.set_nb_outputs(3);
nn.add_connection_w(nn.get_input(0), nn.get_output(0), 0.5);
nn.add_connection_w(nn.get_input(1), nn.get_output(0), 0.25);
nn.add_connection_w(nn.get_input(2), nn.get_output(2), -0.25);
nn.add_connection_w(nn.get_input(0), nn.get_output(2), 0.05);
nn.add_connection_w(nn.get_input(2), nn.get_output(1), -0.05);
nn.init();
BOOST_CHECK_EQUAL(nn.get_nb_connections(), 5);
int k = nn.remove_low_weights(0.1);
std::cout << k << std::endl;
BOOST_CHECK_EQUAL(nn.get_nb_connections(), 3);
}
BOOST_AUTO_TEST_CASE(nn_speed)
{
using namespace nn;
typedef NN<Neuron<PfWSum<>, AfTanh<float> >, Connection<> > nn_t;
nn_t nn;
nn.set_nb_inputs(40000);
nn.set_nb_outputs(4);
typedef std::vector<nn_t::vertex_desc_t> layer_t;
//std::vector<layer_t> layers;
// layers.push_back(nn.get_inputs());
// for (size_t i = 0; i < 10; ++i)
// {
// layer_t layer;
// for (size_t j = 0; j < 10; ++j)
// layer.push_back(nn.add_neuron("n"));
// layers.push_back(layer);
// }
// layers.push_back(nn.get_outputs());
// for (size_t i = 0; i < layers.size() - 1; ++i)
// nn.full_connect(layers[i], layers[i + 1], 1.0);
nn.full_connect(nn.get_inputs(), nn.get_outputs(), 0.25);
nn.init();
boost::timer timer;
std::vector<float> in(40000);
std::fill(in.begin(), in.end(), 0.10f);
for (size_t i = 0; i < 100; ++i)
nn.step(in);
std::cout<<"timer (1000 iterations):" << timer.elapsed() << std::endl;
std::ofstream ofs("/tmp/test.dot");
nn.write(ofs);
}

@ -1,93 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MODULE nn_osc
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <cmath>
#include <algorithm>
#include "nn.hpp"
BOOST_AUTO_TEST_CASE(nn_osc)
{
using namespace nn;
typedef std::pair<float, float> weight_t;
typedef PfIjspeert<params::Vectorf<3> > pf_t;
typedef AfDirectT<weight_t> af_t;
typedef Neuron<pf_t, af_t, weight_t> neuron_t;
typedef Connection<weight_t, weight_t> connection_t;
typedef NN<neuron_t, connection_t> nn_t;
typedef nn_t::vertex_desc_t vertex_desc_t;
nn_t nn;
std::vector<vertex_desc_t> vs;
float omega = 0.6;
float x = 0;
float r = 0.59;
float phi_ij = 0.81;
for (size_t i = 0; i < 5; ++i)
{
vertex_desc_t v = nn.add_neuron(boost::lexical_cast<std::string>(i));
nn.get_neuron_by_vertex(v).get_pf().set_omega(omega);
nn.get_neuron_by_vertex(v).get_pf().set_x(x);
nn.get_neuron_by_vertex(v).get_pf().set_r(r);
vs.push_back(v);
}
for (size_t i = 0; i < 4; ++i)
{
nn.add_connection(vs[i], vs[i + 1], std::make_pair(5, phi_ij));
nn.add_connection(vs[i + 1], vs[i], std::make_pair(5, -phi_ij));
}
nn.init();
for (size_t s = 0; s < 1000; ++s)
{
std::vector<weight_t> in;
nn.step(in);
for (size_t i = 0; i < vs.size(); ++i)
std::cout<< i << " "
<< nn.get_neuron_by_vertex(vs[i]).get_pf().get_theta_i()
<< std::endl;
}
// you should have beautiful oscillations
}

@ -1,127 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.
#ifndef _NN_TRAIT_HPP_
#define _NN_TRAIT_HPP_
// for std::pair
#include <map>
#include <valarray>
#ifdef EIGEN3_ENABLED
#include <Eigen/Core>
#endif
#include "params.hpp"
namespace nn
{
template<typename T>
struct trait
{
static T zero() { return T(0.0f); }
// a 0 initializer for vectors
static T zero(size_t k) { return zero(); }
typedef std::valarray<T> vector_t;
static size_t size(const T& t) { return t.size(); }
static typename T::type_t single_value(const T& t) { assert(t.size() == 1); return t.data(0); }
};
template<>
struct trait<params::Dummy>
{
typedef std::valarray<float> vector_t;
static float zero() { return 0.0f; }
static float zero(size_t k) { return zero(); }
static float single_value(const params::Dummy& t) { return 0.0f; }
static size_t size(const params::Dummy&) { return 0; }
};
// go with eigen with float (TODO : double)
template<>
struct trait<float>
{
typedef Eigen::VectorXf vector_t;
static float zero() { return 0.0f; }
static vector_t zero(size_t k) { return Eigen::VectorXf::Zero(k); }
static float single_value(const float& t) { return t; }
static size_t size(const float& t) { return 1; }
};
template<>
struct trait<std::pair<float, float> >
{
typedef std::valarray<std::pair<float, float> > vector_t;
static std::pair<float, float> zero() { return std::make_pair(0.0f, 0.0f); }
static std::pair<float, float> zero(size_t k) { return zero(); }
static float single_value(const std::pair<float, float>& t) { return t.first; }
static size_t size(const std::pair<float, float>& t) { return 2; }
};
// useful but wrong place (?)
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& ofs, const std::pair<float, float>& p)
{
return ofs<<p.first<<" "<<p.second;
}
template<typename _CharT, typename _Traits>
std::basic_ostream<_CharT, _Traits>&
operator<<(std::basic_ostream<_CharT, _Traits>& ofs, const std::vector<float>& p)
{
for (size_t i = 0; i < p.size(); ++i)
ofs<<p[i]<<" ";
return ofs;
}
template<typename T1, typename T2>
std::istream& operator>>(std::istream& ifs, std::pair<T1, T2>& p)
{
T1 t1;
T2 t2;
ifs >> t1;
ifs >> t2;
return std::make_pair(t1, t2);
}
}
#endif

@ -1,114 +0,0 @@
#! /usr/bin/env python
#| This file is a part of the sferes2 framework.
#| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
#| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
#|
#| This software is a computer program whose purpose is to facilitate
#| experiments in evolutionary computation and evolutionary robotics.
#|
#| This software is governed by the CeCILL license under French law
#| and abiding by the rules of distribution of free software. You
#| can use, modify and/ or redistribute the software under the terms
#| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
#| following URL "http://www.cecill.info".
#|
#| As a counterpart to the access to the source code and rights to
#| copy, modify and redistribute granted by the license, users are
#| provided only with a limited warranty and the software's author,
#| the holder of the economic rights, and the successive licensors
#| have only limited liability.
#|
#| In this respect, the user's attention is drawn to the risks
#| associated with loading, using, modifying and/or developing or
#| reproducing the software by the user in light of its specific
#| status of free software, that may mean that it is complicated to
#| manipulate, and that also therefore means that it is reserved for
#| developers and experienced professionals having in-depth computer
#| knowledge. Users are therefore encouraged to load and test the
#| software's suitability as regards their requirements in conditions
#| enabling the security of their systems and/or data to be ensured
#| and, more generally, to use and operate it in the same conditions
#| as regards security.
#|
#| The fact that you are presently reading this means that you have
#| had knowledge of the CeCILL license and that you accept its terms.
import os
def set_options(blah) : pass
def configure(blah): pass
def build(bld):
print ("Entering directory `" + os.getcwd() + "/modules/'")
test_nn = bld.new_task_gen('cxx', 'program')
test_nn.source = 'test_nn.cpp'
test_nn.includes = '. ../../'
test_nn.uselib_local = ''
test_nn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK'
test_nn.target = 'test_nn'
test_nn.unit_test = 1
test_dnn = bld.new_task_gen('cxx', 'program')
test_dnn.source = 'test_dnn.cpp'
test_dnn.includes = '. ../../'
test_dnn.uselib_local = 'sferes2'
test_dnn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_dnn.target = 'test_dnn'
test_dnn.unit_test = 1
test_mlp = bld.new_task_gen('cxx', 'program')
test_mlp.source = 'test_mlp.cpp'
test_mlp.includes = '. ../../'
test_mlp.uselib_local = 'sferes2'
test_mlp.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_mlp.target = 'test_mlp'
test_mlp.unit_test = 1
test_esn = bld.new_task_gen('cxx', 'program')
test_esn.source = 'test_hyper_nn.cpp'
test_esn.includes = '. ../../'
test_esn.uselib_local = 'sferes2'
test_esn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_esn.target = 'test_hyper_nn'
test_esn.unit_test = 1
test_esn = bld.new_task_gen('cxx', 'program')
test_esn.source = 'test_dnn_ff.cpp'
test_esn.includes = '. ../../'
test_esn.uselib_local = 'sferes2'
test_esn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_esn.target = 'test_dnn_ff'
test_esn.unit_test = 1
test_osc = bld.new_task_gen('cxx', 'program')
test_osc.source = 'test_osc.cpp'
test_osc.includes = '. ../../'
test_osc.uselib_local = 'sferes2'
test_osc.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_osc.target = 'test_osc'
test_osc.unit_test = 1
bench_nn = bld.new_task_gen('cxx', 'program')
bench_nn.source = 'bench_nn.cpp'
bench_nn.includes = '. ../../'
bench_nn.uselib_local = 'sferes2'
bench_nn.uselib = 'EIGEN3 BOOST_GRAPH BOOST'
bench_nn.target = 'bench_nn'
# Added tests by Anh --------------------------------------------------------------------
test_esn = bld.new_task_gen('cxx', 'program')
test_esn.source = 'test_hyper_nn_anh.cpp'
test_esn.includes = '. ../../'
test_esn.uselib_local = 'sferes2'
test_esn.uselib = 'EIGEN3 BOOST BOOST_GRAPH BOOST_UNIT_TEST_FRAMEWORK BOOST_SERIALIZATION'
test_esn.target = 'test_hyper_nn_anh'
test_esn.unit_test = 1

@ -1,43 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# JB Mouret - 2009
"""
Quick n dirty mpi detection
"""
import os, glob, types
import Options, Configure
def detect_mpi(conf):
env = conf.env
opt = Options.options
conf.env['LIB_MPI'] = ''
conf.env['MPI_FOUND'] = False
if Options.options.no_mpi :
return
if Options.options.mpi:
conf.env['CPPPATH_MPI'] = Options.options.mpi + '/include'
conf.env['LIBPATH_MPI'] = Options.options.mpi + '/lib'
else:
conf.env['CPPPATH_MPI'] = ['/usr/include/mpi', '/usr/local/include/mpi', '/usr/include', '/usr/local/include']
conf.env['LIBPATH_MPI'] = ['/usr/lib', '/usr/local/lib', '/usr/lib/openmpi']
res = Configure.find_file('mpi.h', conf.env['CPPPATH_MPI'] )
conf.check_message('header','mpi.h', (res != '') , res)
if (res == '') :
return 0
conf.env['MPI_FOUND'] = True
conf.env['LIB_MPI'] = ['mpi_cxx','mpi']
return 1
def detect(conf):
return detect_mpi(conf)
def set_options(opt):
opt.add_option("--no-mpi",
default=False, action='store_true',
help='disable mpi', dest='no_mpi')
opt.add_option('--mpi', type='string', help='path to mpi', dest='mpi')

@ -1,32 +0,0 @@
#! /usr/bin/env python
# encoding: utf-8
# JB Mouret - 2009
"""
Quick n dirty ODE detection
"""
import os, glob, types
import Options, Configure, config_c
import commands
def detect_ode(conf):
env = conf.env
opt = Options.options
ret = conf.find_program('ode-config')
conf.check_message_1('Checking for ODE (optional)')
if not ret:
conf.check_message_2('not found', 'YELLOW')
return 0
conf.check_message_2('ok')
res = commands.getoutput('ode-config --cflags --libs')
config_c.parse_flags(res, 'ODE', env)
return 1
def detect(conf):
return detect_ode(conf)
def set_options(opt):
pass

@ -1,17 +0,0 @@
#!/bin/sh
set -x
PATHS='sferes scripts tests modules/nn modules/cartpole'
FILES=`find $PATHS |egrep "(.hpp|.cpp)$"`
for i in $FILES; do
grep -v "//|" $i >/tmp/file
cp scripts/license_cpp.txt $i
cat /tmp/file >> $i
done
FILES=`find $PATHS |egrep "(wscript|.py)$"`
FILES="$FILES wscript"
for i in $FILES; do
grep -v "#|" $i|grep -v "#!" >/tmp/file
cat scripts/license_py.txt >> $i
cat /tmp/file >> $i
done

@ -1,72 +0,0 @@
#!/usr/bin/ruby
## error_parser.rb
## Login : <mandor@ithaqua>
## Started on Fri Apr 4 12:28:15 2008 mandor
## $Id$
##
## Copyright (C) 2008 mandor
#| This file is a part of the sferes2 framework.
#| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
#| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
#|
#| This software is a computer program whose purpose is to facilitate
#| experiments in evolutionary computation and evolutionary robotics.
#|
#| This software is governed by the CeCILL license under French law
#| and abiding by the rules of distribution of free software. You
#| can use, modify and/ or redistribute the software under the terms
#| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
#| following URL "http://www.cecill.info".
#|
#| As a counterpart to the access to the source code and rights to
#| copy, modify and redistribute granted by the license, users are
#| provided only with a limited warranty and the software's author,
#| the holder of the economic rights, and the successive licensors
#| have only limited liability.
#|
#| In this respect, the user's attention is drawn to the risks
#| associated with loading, using, modifying and/or developing or
#| reproducing the software by the user in light of its specific
#| status of free software, that may mean that it is complicated to
#| manipulate, and that also therefore means that it is reserved for
#| developers and experienced professionals having in-depth computer
#| knowledge. Users are therefore encouraged to load and test the
#| software's suitability as regards their requirements in conditions
#| enabling the security of their systems and/or data to be ensured
#| and, more generally, to use and operate it in the same conditions
#| as regards security.
#|
#| The fact that you are presently reading this means that you have
#| had knowledge of the CeCILL license and that you accept its terms.
def parse(line, level)
stack = [""]
if !line.include?("instantiated") and (line.include?("error") || line.include?("erreur")) then
line.scan(/./) { |c|
if c == '<' then
print "#{stack[0]}<" if stack.length < level + 2
stack[0] = ""
stack.unshift("")
elsif c == '>' then
print stack[0] if stack.length < level + 2
stack.shift()
print ">"
else
stack[0] += c if stack[0]
end
}
print stack[0] if stack[0]
print "\n"
end
end
level = ARGV[0].to_i
while $stdin.gets do
parse($_, level)
end

@ -1,34 +0,0 @@
//| This file is a part of the sferes2 framework.
//| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
//| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
//|
//| This software is a computer program whose purpose is to facilitate
//| experiments in evolutionary computation and evolutionary robotics.
//|
//| This software is governed by the CeCILL license under French law
//| and abiding by the rules of distribution of free software. You
//| can use, modify and/ or redistribute the software under the terms
//| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
//| following URL "http://www.cecill.info".
//|
//| As a counterpart to the access to the source code and rights to
//| copy, modify and redistribute granted by the license, users are
//| provided only with a limited warranty and the software's author,
//| the holder of the economic rights, and the successive licensors
//| have only limited liability.
//|
//| In this respect, the user's attention is drawn to the risks
//| associated with loading, using, modifying and/or developing or
//| reproducing the software by the user in light of its specific
//| status of free software, that may mean that it is complicated to
//| manipulate, and that also therefore means that it is reserved for
//| developers and experienced professionals having in-depth computer
//| knowledge. Users are therefore encouraged to load and test the
//| software's suitability as regards their requirements in conditions
//| enabling the security of their systems and/or data to be ensured
//| and, more generally, to use and operate it in the same conditions
//| as regards security.
//|
//| The fact that you are presently reading this means that you have
//| had knowledge of the CeCILL license and that you accept its terms.

@ -1,35 +0,0 @@
#! /usr/bin/env python
#| This file is a part of the sferes2 framework.
#| Copyright 2009, ISIR / Universite Pierre et Marie Curie (UPMC)
#| Main contributor(s): Jean-Baptiste Mouret, mouret@isir.fr
#|
#| This software is a computer program whose purpose is to facilitate
#| experiments in evolutionary computation and evolutionary robotics.
#|
#| This software is governed by the CeCILL license under French law
#| and abiding by the rules of distribution of free software. You
#| can use, modify and/ or redistribute the software under the terms
#| of the CeCILL license as circulated by CEA, CNRS and INRIA at the
#| following URL "http://www.cecill.info".
#|
#| As a counterpart to the access to the source code and rights to
#| copy, modify and redistribute granted by the license, users are
#| provided only with a limited warranty and the software's author,
#| the holder of the economic rights, and the successive licensors
#| have only limited liability.
#|
#| In this respect, the user's attention is drawn to the risks
#| associated with loading, using, modifying and/or developing or
#| reproducing the software by the user in light of its specific
#| status of free software, that may mean that it is complicated to
#| manipulate, and that also therefore means that it is reserved for
#| developers and experienced professionals having in-depth computer
#| knowledge. Users are therefore encouraged to load and test the
#| software's suitability as regards their requirements in conditions
#| enabling the security of their systems and/or data to be ensured
#| and, more generally, to use and operate it in the same conditions
#| as regards security.
#|
#| The fact that you are presently reading this means that you have
#| had knowledge of the CeCILL license and that you accept its terms.

@ -1,11 +0,0 @@
#!/bin/bash
# Setup the exp/images experiment
cd exp/images/
./build_wscript.sh
cd ../../
dir=$(echo $(pwd))
#echo "Please set LOCAL_RUN in $dir/exp/images/settings.h"
#vim $dir/exp/images/settings.h
echo "Done setting up."

@ -1,390 +0,0 @@
import sys, os
import subprocess
import commands
json_ok = True
try:
import simplejson
except:
json_ok = False
print "WARNING simplejson not found some function may not work"
import glob
#import xml.etree.cElementTree as etree
import Options
def create_variants(bld, source, uselib_local, target,
uselib, variants, includes=". ../../",
cxxflags='',
json=''):
# the basic one
# tgt = bld.new_task_gen('cxx', 'program')
# tgt.source = source
# tgt.includes = includes
# tgt.uselib_local = uselib_local
# tgt.uselib = uselib
# tgt.target = target
# the variants
c_src = bld.path.abspath() + '/'
for v in variants:
# create file
suff = ''
for d in v.split(' '): suff += d.lower() + '_'
tmp = source.replace('.cpp', '')
src_fname = tmp + '_' + suff[0:len(suff) - 1] + '.cpp'
f = open(c_src + src_fname, 'w')
f.write("// THIS IS A GENERATED FILE - DO NOT EDIT\n")
for d in v.split(' '): f.write("#define " + d + "\n")
f.write("#line 1 \"" + c_src + source + "\"\n")
code = open(c_src + source, 'r')
for line in code: f.write(line)
bin_name = src_fname.replace('.cpp', '')
bin_name = os.path.basename(bin_name)
# create build
tgt = bld.new_task_gen('cxx', 'program')
tgt.source = src_fname
tgt.includes = includes
tgt.uselib_local = uselib_local
tgt.uselib = uselib
tgt.target = bin_name
tgt.cxxflags = cxxflags
def create_exp(name):
ws_tpl = """
#! /usr/bin/env python
def build(bld):
obj = bld.new_task_gen('cxx', 'program')
obj.source = '@exp.cpp'
obj.includes = '. ../../'
obj.uselib_local = 'sferes2'
obj.uselib = ''
obj.target = '@exp'
obj.uselib_local = 'sferes2'
"""
os.mkdir('exp/' + name)
os.system("cp examples/ex_ea.cpp exp/" + name + "/" + name + ".cpp")
wscript = open('exp/' + name + "/wscript", "w")
wscript.write(ws_tpl.replace('@exp', name))
def parse_modules():
if (not os.path.exists("modules.conf")):
return []
mod = open("modules.conf")
modules = []
for i in mod:
if i[0] != '#' and len(i) != 1:
modules += ['modules/' + i[0:len(i)-1]]
return modules
def qsub(conf_file):
tpl = """
#! /bin/sh
#? nom du job affiche
#PBS -N @exp
#PBS -o stdout
#PBS -b stderr
#PBS -M @email
# maximum execution time
#PBS -l walltime=@wall_time
# mail parameters
#PBS -m abe
# number of nodes
#PBS -l nodes=@nb_cores:ppn=@ppn
#PBS -l pmem=5200mb -l mem=5200mb
export LD_LIBRARY_PATH=@ld_lib_path
exec @exec
"""
if os.environ.has_key('LD_LIBRARY_PATH'):
ld_lib_path = os.environ['LD_LIBRARY_PATH']
else:
ld_lib_path = "''"
home = os.environ['HOME']
print 'LD_LIBRARY_PATH=' + ld_lib_path
# parse conf
conf = simplejson.load(open(conf_file))
exps = conf['exps']
nb_runs = conf['nb_runs']
res_dir = conf['res_dir']
bin_dir = conf['bin_dir']
wall_time = conf['wall_time']
use_mpi = "false"
try: use_mpi = conf['use_mpi']
except: use_mpi = "false"
try: nb_cores = conf['nb_cores']
except: nb_cores = 1
try: args = conf['args']
except: args = ''
email = conf['email']
if (use_mpi == "true"):
ppn = '1'
mpirun = 'mpirun'
else:
nb_cores = 1;
ppn = '8'
mpirun = ''
for i in range(0, nb_runs):
for e in exps:
directory = res_dir + "/" + e + "/exp_" + str(i)
try:
os.makedirs(directory)
except:
print "WARNING, dir:" + directory + " not be created"
subprocess.call('cp ' + bin_dir + '/' + e + ' ' + directory, shell=True)
fname = home + "/tmp/" + e + "_" + str(i) + ".job"
f = open(fname, "w")
f.write(tpl
.replace("@exp", e)
.replace("@email", email)
.replace("@ld_lib_path", ld_lib_path)
.replace("@wall_time", wall_time)
.replace("@dir", directory)
.replace("@nb_cores", str(nb_cores))
.replace("@ppn", ppn)
.replace("@exec", mpirun + ' ' + directory + '/' + e + ' ' + args))
f.close()
s = "qsub -d " + directory + " " + fname
print "executing:" + s
retcode = subprocess.call(s, shell=True, env=None)
print "qsub returned:" + str(retcode)
def loadleveler(conf_file):
tpl = """
# @ job_name=<name>
# @ output = $(job_name).$(jobid)
# @ error = $(output)
# @ job_type = serial
# @ class = <class>
# @ resources=ConsumableMemory(<memory>) ConsumableCpus(<cpu>)
# @ queue
export LD_LIBRARY_PATH=<ld_library_path>
cd <initial_dir>
./<exec>
"""
if os.environ.has_key('LD_LIBRARY_PATH'):
ld_lib_path = os.environ['LD_LIBRARY_PATH']
else:
ld_lib_path = "''"
home = os.environ['HOME']
print 'LD_LIBRARY_PATH=' + ld_lib_path
# parse conf
conf = simplejson.load(open(conf_file))
jobname = conf['jobname']
exps = conf['exps']
nb_runs = conf['nb_runs']
res_dir = conf['res_dir']
bin_dir = conf['bin_dir']
jobclass = conf['class']
try:
memory=conf['memory']
except:
memory=3000
try:
cpu=conf['cpu']
except:
cpu=1
for i in range(0, nb_runs):
for e in exps:
directory = res_dir + "/" + e + "/exp_" + str(i)
try:
os.makedirs(directory)
except:
print "WARNING, dir:" + directory + " cannot be created"
subprocess.call('cp ' + bin_dir + '/' + e + ' ' + directory, shell=True)
try:
os.makedirs(home+"/tmp")
except:
pass
fname = home + "/tmp/" + e + "_" + str(i) + ".job"
f = open(fname, "w")
f.write(tpl
.replace("<name>", jobname)
.replace("<ld_library_path>", ld_lib_path)
.replace("<class>", jobclass)
.replace("<initial_dir>", directory)
.replace("<memory>", str(memory))
.replace("<cpu>", str(cpu))
.replace("<exec>", e))
f.close()
s = "llsubmit "+ fname
print "executing:" + s
retcode = subprocess.call(s, shell=True, env=None)
print "llsubmit returned:" + str(retcode)
def time_travel(conf_file):
print 'time_travel, conf = ' + conf_file
conf = simplejson.load(open(conf_file))
dir = conf['dir']
# get the diff
patch = glob.glob(dir + '/*.diff')[0].split('/')
patch = patch[len(patch) - 1]
version = patch[0:len(patch) - len('.diff')]
cwd = os.getcwd()
patch = cwd + '/' + dir + '/' + patch
# checkout
print 'svn co -r ' + version
os.system('cd ' + dir + ' && svn -r ' + version + ' co https://webia.lip6.fr:2004/svn/robur/sferes2')
os.system('cd ' + dir + '/sferes2 && patch -p0 < '+ patch)
os.chdir(cwd)
def get_gen(x):
g1 = x.split('_')
gen1 = int(g1[len(g1)-1])
return gen1
def get_exe(conf_file):
return os.path.split(conf_file.replace('.json', ''))[1]
def compare_gen(x, y):
return get_gen(x) - get_gen(y)
def kill(conf_file):
print 'kill, conf =' + conf_file
exe = get_exe(conf_file)
conf = simplejson.load(open(conf_file))
machines = conf['machines']
if conf['debug'] == 1:
exe += '_debug'
else:
exe += '_opt'
print 'kill '+ exe
for m in machines:
print m
s = "ssh -o CheckHostIP=false -f " + m + \
" killall -9 " + exe
print s
os.system(s)
def status(conf):
# parse configuration
print 'status, conf = ' + conf
conf = simplejson.load(open(conf))
exp = conf['exp']
dir = conf['dir']
exps = glob.glob(dir + '/exp_*/')
total = 0.0
for i in exps:
glist = glob.glob(i + '*/gen_*')
glist.sort(cmp=compare_gen)
last = glist[len(glist) - 1]
last_gen = get_gen(last)
r = ''
try:
tree = etree.parse(last)
l = tree.find("//x/_pareto_front/item/px/_fit/_objs")
if l == None:
l = tree.find("//x/_best/px/_fit/_value")
total += float(l.text)
r = l.text
else:
l = l[1:len(l)]
total += float(l[0].text)
for k in l:
r += k.text + ' '
print i + ' :\t' + str(last_gen) + '\t=> ' + r
except:
print "error"
total /= len(exps)
print "=> " + str(total)
def get_exp(conf_file):
conf = simplejson.load(open(conf_file))
return conf['exp'].sub('exp/', '')
def launch_exp(conf_file):
print '--- launch exp ---'
# parse configuration
print 'launch, conf = ' + conf_file
conf = simplejson.load(open(conf_file))
machines = conf['machines']
nb_runs = conf['nb_runs']
exp = conf['exp']
directory = conf['dir']
debug = conf['debug']
args = ""
if 'args' in conf : args=conf['args']
print 'exp = ' + exp
print 'dir = ' + directory
print 'nb_runs = ' + str(nb_runs)
print 'debug = ' + str(debug)
print 'machines =' + str(machines)
print 'args =' + str(args)
# copy binaries (debug and opt) & json file
exe = get_exe(conf_file)
try:
os.makedirs(directory + '/bin')
os.system('cp ' + 'build/default/' + exp +'/'+exe+ ' ' + directory + '/bin/' + exe + '_opt')
os.system('cp ' + 'build/debug/' + exp +'/'+exe+ ' ' + directory + '/bin/' + exe + '_debug')
print conf
print directory
os.system('cp ' + conf_file + ' ' + directory)
# create directories
for i in range(0, nb_runs * len(machines)):
os.makedirs(directory + '/exp_' + str(i))
except:
print '/!\ files exist, I cannot replace them'
return
print 'dirs created'
# make a svn diff
status, version = commands.getstatusoutput('svnversion')
if version[len(version)-1] == 'M':
version = version[0:len(version)-1]
os.system('svn diff >' + directory + '/' + version + '.diff')
print 'diff done [version=' + version + ']'
# run on each machines
if debug == 1:
exe = exe + '_debug'
else:
exe = exe + '_opt'
if os.environ.has_key('LD_LIBRARY_PATH'):
ld_lib_path = os.environ['LD_LIBRARY_PATH']
else:
ld_lib_path = "''"
k = 0
pids = []
for m in machines.iterkeys() :
pid = os.fork()
if (pid == 0): #son
for i in range(0, machines[m]):
if m == 'localhost':
s = "export LD_LIBRARY_PATH=" + ld_lib_path + \
" && cd " + os.getcwd() + '/' + directory + '/exp_'+ str(i + k) + \
" && " + os.getcwd() + '/' + directory + '/bin/' + exe + " " + args + \
" 1> stdout 2> stderr"
else:
s = "ssh -o CheckHostIP=false " + m + \
" 'export LD_LIBRARY_PATH=" + ld_lib_path + \
" && cd " + os.getcwd() + '/' + directory + '/exp_'+ str(i + k) + \
" && " + os.getcwd() + '/' + directory + '/bin/' + exe + " " + args + \
" 1> stdout 2> stderr'"
print 'run ' + str(i + k) + ' on ' + m
print s
ret = subprocess.call(s, shell=True)
print "ret = " + str(ret)
exit(0)
pids += [pid]
k += machines[m]
print "waitpid..."
for i in pids:
os.waitpid(i, 0)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save