Skip to content

Commit d5d367b

Browse files
committed
Move utils in blackdrops
1 parent 7195ed5 commit d5d367b

File tree

15 files changed

+342
-338
lines changed

15 files changed

+342
-338
lines changed

include/blackdrops/reward/gp_reward.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
#include <limbo/model/gp.hpp>
6464

6565
#include <blackdrops/reward/reward.hpp>
66-
#include <utils/utils.hpp>
66+
#include <blackdrops/utils/utils.hpp>
6767

6868
namespace blackdrops {
6969

include/blackdrops/system/dart_system.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
#include <robot_dart/graphics/graphics.hpp>
7070
#endif
7171

72-
#include <utils/utils.hpp>
72+
#include <blackdrops/utils/utils.hpp>
7373

7474
namespace blackdrops {
7575
namespace system {

include/blackdrops/system/ode_system.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
#define BLACKDROPS_SYSTEM_ODE_SYSTEM_HPP
5858

5959
#include <boost/numeric/odeint.hpp>
60-
#include <utils/utils.hpp>
60+
#include <blackdrops/utils/utils.hpp>
6161

6262
namespace blackdrops {
6363
namespace system {
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
//| Copyright Inria July 2017
2+
//| This project has received funding from the European Research Council (ERC) under
3+
//| the European Union's Horizon 2020 research and innovation programme (grant
4+
//| agreement No 637972) - see http://www.resibots.eu
5+
//|
6+
//| Contributor(s):
7+
//| - Konstantinos Chatzilygeroudis ([email protected])
8+
//| - Rituraj Kaushik ([email protected])
9+
//| - Roberto Rama ([email protected])
10+
//|
11+
//| This software is the implementation of the Black-DROPS algorithm, which is
12+
//| a model-based policy search algorithm with the following main properties:
13+
//| - uses Gaussian processes (GPs) to model the dynamics of the robot/system
14+
//| - takes into account the uncertainty of the dynamical model when
15+
//| searching for a policy
16+
//| - is data-efficient or sample-efficient; i.e., it requires very small
17+
//| interaction time with the system to find a working policy (e.g.,
18+
//| around 16-20 seconds to learn a policy for the cart-pole swing up task)
19+
//| - when several cores are available, it can be faster than analytical
20+
//| approaches (e.g., PILCO)
21+
//| - it imposes no constraints on the type of the reward function (it can
22+
//| also be learned from data)
23+
//| - it imposes no constraints on the type of the policy representation
24+
//| (any parameterized policy can be used --- e.g., dynamic movement
25+
//| primitives or neural networks)
26+
//|
27+
//| Main repository: http://github.com/resibots/blackdrops
28+
//| Preprint: https://arxiv.org/abs/1703.07261
29+
//|
30+
//| This software is governed by the CeCILL-C license under French law and
31+
//| abiding by the rules of distribution of free software. You can use,
32+
//| modify and/ or redistribute the software under the terms of the CeCILL-C
33+
//| license as circulated by CEA, CNRS and INRIA at the following URL
34+
//| "http://www.cecill.info".
35+
//|
36+
//| As a counterpart to the access to the source code and rights to copy,
37+
//| modify and redistribute granted by the license, users are provided only
38+
//| with a limited warranty and the software's author, the holder of the
39+
//| economic rights, and the successive licensors have only limited
40+
//| liability.
41+
//|
42+
//| In this respect, the user's attention is drawn to the risks associated
43+
//| with loading, using, modifying and/or developing or reproducing the
44+
//| software by the user in light of its specific status of free software,
45+
//| that may mean that it is complicated to manipulate, and that also
46+
//| therefore means that it is reserved for developers and experienced
47+
//| professionals having in-depth computer knowledge. Users are therefore
48+
//| encouraged to load and test the software's suitability as regards their
49+
//| requirements in conditions enabling the security of their systems and/or
50+
//| data to be ensured and, more generally, to use and operate it in the
51+
//| same conditions as regards security.
52+
//|
53+
//| The fact that you are presently reading this means that you have had
54+
//| knowledge of the CeCILL-C license and that you accept its terms.
55+
//|
56+
#ifndef BLACKDROPS_UTILS_CMD_ARGS_HPP
57+
#define BLACKDROPS_UTILS_CMD_ARGS_HPP
58+
59+
#include <boost/program_options.hpp>
60+
61+
namespace po = boost::program_options;
62+
63+
namespace blackdrops {
64+
namespace utils {
65+
class CmdArgs {
66+
public:
67+
CmdArgs() : _verbose(false), _stochastic(false), _uncertainty(false), _threads(tbb::task_scheduler_init::automatic), _desc("Command line arguments") { _set_defaults(); }
68+
69+
int parse(int argc, char** argv)
70+
{
71+
try {
72+
po::variables_map vm;
73+
po::store(po::parse_command_line(argc, argv, _desc), vm);
74+
if (vm.count("help")) {
75+
std::cout << _desc << std::endl;
76+
return 0;
77+
}
78+
79+
po::notify(vm);
80+
81+
if (vm.count("threads")) {
82+
_threads = vm["threads"].as<int>();
83+
}
84+
if (vm.count("hidden_neurons")) {
85+
int c = vm["hidden_neurons"].as<int>();
86+
if (c < 1)
87+
c = 1;
88+
_neurons = c;
89+
}
90+
else {
91+
_neurons = 5;
92+
}
93+
if (vm.count("pseudo_samples")) {
94+
int c = vm["pseudo_samples"].as<int>();
95+
if (c < 1)
96+
c = 1;
97+
_pseudo_samples = c;
98+
}
99+
else {
100+
_pseudo_samples = 10;
101+
}
102+
if (vm.count("boundary")) {
103+
double c = vm["boundary"].as<double>();
104+
if (c < 0)
105+
c = 0;
106+
_boundary = c;
107+
}
108+
else {
109+
_boundary = 0.;
110+
}
111+
112+
// Cmaes parameters
113+
if (vm.count("max_evals")) {
114+
int c = vm["max_evals"].as<int>();
115+
_max_fun_evals = c;
116+
}
117+
else {
118+
_max_fun_evals = -1;
119+
}
120+
if (vm.count("tolerance")) {
121+
double c = vm["tolerance"].as<double>();
122+
if (c < 0.)
123+
c = 0.;
124+
_fun_tolerance = c;
125+
}
126+
else {
127+
_fun_tolerance = 1.;
128+
}
129+
if (vm.count("restarts")) {
130+
int c = vm["restarts"].as<int>();
131+
if (c < 1)
132+
c = 1;
133+
_restarts = c;
134+
}
135+
else {
136+
_restarts = 1;
137+
}
138+
if (vm.count("elitism")) {
139+
int c = vm["elitism"].as<int>();
140+
if (c < 0 || c > 3)
141+
c = 0;
142+
_elitism = c;
143+
}
144+
else {
145+
_elitism = 0;
146+
}
147+
if (vm.count("lambda")) {
148+
int l = vm["lambda"].as<int>();
149+
if (l < 0)
150+
l = -1;
151+
_lambda = l;
152+
}
153+
else {
154+
_lambda = -1;
155+
}
156+
}
157+
catch (po::error& e) {
158+
std::cerr << "[Exception caught while parsing command line arguments]: " << e.what() << std::endl;
159+
return 1;
160+
}
161+
162+
return -1;
163+
}
164+
165+
bool verbose() const { return _verbose; }
166+
bool stochastic() const { return _stochastic; }
167+
bool uncertainty() const { return _uncertainty; }
168+
169+
int threads() const { return _threads; }
170+
int neurons() const { return _neurons; }
171+
int pseudo_samples() const { return _pseudo_samples; }
172+
int max_fun_evals() const { return _max_fun_evals; }
173+
int restarts() const { return _restarts; }
174+
int elitism() const { return _elitism; }
175+
int lambda() const { return _lambda; }
176+
177+
double boundary() const { return _boundary; }
178+
double fun_tolerance() const { return _fun_tolerance; }
179+
180+
protected:
181+
bool _verbose, _stochastic, _uncertainty;
182+
int _threads, _neurons, _pseudo_samples, _max_fun_evals, _restarts, _elitism, _lambda;
183+
double _boundary, _fun_tolerance;
184+
185+
po::options_description _desc;
186+
187+
void _set_defaults()
188+
{
189+
// clang-format off
190+
_desc.add_options()("help,h", "Prints this help message")
191+
("hidden_neurons,n", po::value<int>(), "Number of hidden neurons in NN policy.")
192+
("pseudo_samples,p", po::value<int>(), "Number of pseudo samples in GP policy.")
193+
("boundary,b", po::value<double>(), "Boundary of the values during the optimization.")
194+
("max_evals,m", po::value<int>(), "Max function evaluations to optimize the policy.")
195+
("tolerance,t", po::value<double>(), "Maximum tolerance to continue optimizing the function.")
196+
("restarts,r", po::value<int>(), "Max number of restarts to use during optimization.")
197+
("elitism,e", po::value<int>(), "Elitism mode to use [0 to 3].")
198+
("lambda,l", po::value<int>(), "Initial population of CMA-ES. Defaults to -1 (i.e., automatically determined).")
199+
("uncertainty,u", po::bool_switch(&_uncertainty)->default_value(false), "Enable uncertainty handling in CMA-ES.")
200+
("stochastic,s", po::bool_switch(&_stochastic)->default_value(false), "Enable stochastic rollouts (i.e., not use the mean model).")
201+
("threads,d", po::value<int>(), "Max number of threads used by TBB")
202+
("verbose,v", po::bool_switch(&_verbose)->default_value(false), "Enable verbose mode.");
203+
// clang-format on
204+
}
205+
};
206+
} // namespace utils
207+
} // namespace blackdrops
208+
209+
#endif

include/utils/dart_utils.hpp renamed to include/blackdrops/utils/dart_utils.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,20 @@
6262
#include <streambuf>
6363
#include <string>
6464

65-
namespace utils {
66-
inline dart::dynamics::SkeletonPtr load_skel(const std::string& filename, const std::string& robot_name)
67-
{
68-
// Load file into string
69-
std::ifstream t(filename);
70-
std::string str((std::istreambuf_iterator<char>(t)),
71-
std::istreambuf_iterator<char>());
65+
namespace blackdrops {
66+
namespace utils {
67+
inline dart::dynamics::SkeletonPtr load_skel(const std::string& filename, const std::string& robot_name)
68+
{
69+
// Load file into string
70+
std::ifstream t(filename);
71+
std::string str((std::istreambuf_iterator<char>(t)),
72+
std::istreambuf_iterator<char>());
7273

73-
dart::simulation::WorldPtr world = dart::utils::SkelParser::readWorldXML(str);
74+
dart::simulation::WorldPtr world = dart::utils::SkelParser::readWorldXML(str);
7475

75-
return world->getSkeleton(robot_name);
76-
}
77-
}
76+
return world->getSkeleton(robot_name);
77+
}
78+
} // namespace utils
79+
} // namespace blackdrops
7880

7981
#endif

0 commit comments

Comments
 (0)