Commit a6eab970 authored by Jean-Baptiste Mouret's avatar Jean-Baptiste Mouret
Browse files

minor things

parent 56e07327
......@@ -3,7 +3,7 @@
# JB Mouret - 2009
"""
Quick n dirty eigen2 detection
Quick n dirty eigen3 detection
"""
import os, glob, types
......@@ -21,9 +21,8 @@ def check_eigen(conf):
conf.env.LIBPATH_EIGEN = [conf.options.eigen]
else:
conf.env.INCLUDES_EIGEN = ['/usr/include/eigen2',
'/usr/local/include/eigen2',
'/usr/local/include/eigen3',
'/usr/include', '/usr/local/include']
res = conf.find_file('Eigen/Core', conf.env.INCLUDES_EIGEN)
return 1
......
......@@ -17,8 +17,13 @@ def options(opt):
@conf
def check_sferes(conf):
if conf.options.sferes:
conf.env.INCLUDES_EIGEN = [conf.options.sferes]
conf.env.LIBPATH_EIGEN = [conf.options.sferes + '/build/default/sferes']
conf.env.INCLUDES_SFERES = [conf.options.sferes]
conf.env.LIBPATH_SFERES = [conf.options.sferes + '/build/default/sferes']
try:
res = conf.find_file('sferes/ea/ea.hpp', conf.env.INCLUDES_SFERES)
conf.define("USE_SFERES", 1)
except:
print 'SFERES not found'
return 1
#include "limbo/limbo.hpp"
#include "limbo/ns_ego.hpp"
#include "limbo/parego.hpp"
#include "limbo/stat_pareto.hpp"
using namespace limbo;
......
#include "limbo/parego.hpp"
#include "limbo/stat_pareto.hpp"
using namespace limbo;
......@@ -72,10 +71,9 @@ int main() {
Parego<Params> opt;
opt.optimize(mop2());
std::cout << "modeling pareto front..." << std::endl;
auto p_model = opt.model_pareto_front();
std::cout << "computing data pareto front" << std::endl;
auto p_data = opt.data_pareto_front();
std::cout << "optimization done" << std::endl;
auto p_model = opt.pareto_model();
auto p_data = opt.pareto_data();
std::ofstream pareto_model("mop2_pareto_model.dat"),
pareto_data("mop2_pareto_data.dat");
......
#ifndef BO_MULTI_HPP_
#define BO_MULTI_HPP_
#define VERSION "xxx"
#include <sferes/phen/parameters.hpp>
#include <sferes/gen/evo_float.hpp>
#include <sferes/eval/parallel.hpp>
#include <sferes/modif/dummy.hpp>
#include <sferes/ea/nsga2.hpp>
#include "bo_base.hpp"
#include "pareto.hpp"
namespace limbo {
namespace multi {
......@@ -82,29 +90,82 @@ namespace limbo {
size_t nb_objs() const {
return this->_observations[0].size();
}
protected:
void _compute_pareto_model() {
typedef sferes::gen::EvoFloat<EvalFunction::dim, multi::SferesParams> gen_t;
typedef sferes::phen::Parameters<gen_t, mulit::SferesFit<model_t>, multi::SferesParams> phen_t;
const pareto_t& pareto_model() const {
return _pareto_model;
}
const pareto_t& pareto_data() const {
return _pareto_data;
}
// will be automatically called at the end of the algo
void update_pareto_data() {
std::vector<Eigen::VectorXd> v(this->_samples.size());
size_t dim = this->_observations[0].size();
std::fill(v.begin(), v.end(), Eigen::VectorXd::Zero(dim));
_pareto_data = pareto::pareto_set(_pack_data(this->_samples, this->_observations, v));
}
// will be automatically called at the end of the algo
template<int D>
void update_pareto_model() {
this->_update_models();
typedef sferes::gen::EvoFloat<D, multi::SferesParams> gen_t;
typedef sferes::phen::Parameters<gen_t, multi::SferesFit<model_t>, multi::SferesParams> phen_t;
typedef sferes::eval::Parallel<multi::SferesParams> eval_t;
typedef boost::fusion::vector<> stat_t;
typedef sferes::modif::Dummy<> modifier_t;
typedef sferes::ea::Nsga2<phen_t, eval_t, stat_t, modifier_t, multi::SferesParams> nsga2_t;
nsga2_t ea;
ea.set_fit_proto(SferesFit<model_t>(models));
ea.set_fit_proto(multi::SferesFit<model_t>(_models));
ea.run();
auto pareto_front = ea.pareto_front();
par::sort(pareto_front.begin(), pareto_front.end(),
sferes::fit::compare_objs_lex());
_pareto_model.resize(pareto_front.size());
Eigen::VectorXd point(D),
objs(nb_objs()), sigma(nb_objs());
for (size_t p = 0; p < pareto_front.size(); ++p) {
for (size_t i = 0; i < pareto_front[p]->size(); ++i)
point(i) = pareto_front[p]->data(i);
for (size_t i = 0; i < nb_objs(); ++i) {
objs(i) = pareto_front[p]->fit().obj(i);
sigma(i) = _models[i].sigma(point);
}
_pareto_model[p] = std::make_tuple(point, objs, sigma);
}
}
protected:
std::vector<model_t> _models;
pareto_t _pareto_model;
pareto_t _pareto_data;
pareto_t _pack_data(const std::vector<Eigen::VectorXd>& points,
const std::vector<Eigen::VectorXd>& objs,
const std::vector<Eigen::VectorXd>& sigma) const {
assert(points.size() == objs.size());
assert(sigma.size() == objs.size());
pareto_t p(points.size());
par::loop (0, p.size(), [&](size_t k) {
p[k] = std::make_tuple(points[k], objs[k], sigma[k]);
});
return p;
}
void _update_models() {
size_t dim = this->_samples[0].size();
std::vector<std::vector<double> > uni_obs(nb_objs);
std::vector<std::vector<double> > uni_obs(nb_objs());
for (size_t i = 0; i < this->_observations.size(); ++i)
for (size_t j = 0; j < this->_observations[i].size(); ++j)
uni_obs[j].push_back(this->_observations[i][j]);
std::vector<model_t> models(nb_objs(), model_t(dim));
_models = models;
for (size_t i = 0; i < uni_obs.size(); ++i)
_models[i].compute(this->_samples, uni_obs[i], 0.0);
}
......
......@@ -26,9 +26,8 @@ namespace limbo {
this->_init(feval, reset);
while (this->_samples.size() == 0 || this->_pursue()) {
this->_update_models();
this->_update_pareto_front(feval);
auto pareto = this->model_pareto_front();
this->template update_pareto_model<EvalFunction::dim>();
auto pareto = this->pareto_model();
auto best = std::max_element(pareto.begin(), pareto.end(),
[](const pareto_point_t& x1, const pareto_point_t& x2) {
return std::get<2>(x1).sum() > std::get<2>(x2).sum();
......
......@@ -54,7 +54,8 @@ namespace limbo {
this->_iteration++;
}
this->_update_pareto_front(feval);
this->template update_pareto_model<EvalFunction::dim>();
this->update_pareto_data();
}
protected:
......
......@@ -8,23 +8,22 @@ def build(bld):
target = 'bo_functions',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
obj = bld.program(features = 'cxx test',
source = 'test_gp.cpp',
includes = '. .. ../../',
target = 'test_gp',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
source = 'test_gp.cpp',
includes = '. .. ../../',
target = 'test_gp',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
obj = bld.program(features = 'cxx test',
source = 'test_gp_auto.cpp',
includes = '. .. ../../',
target = 'test_gp_auto',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
source = 'test_gp_auto.cpp',
includes = '. .. ../../',
target = 'test_gp_auto',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
obj = bld.program(features = 'cxx test',
source = 'test_init_functions.cpp',
includes = '. .. ../../',
target = 'test_init_functions',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
source = 'test_init_functions.cpp',
includes = '. .. ../../',
target = 'test_init_functions',
uselib = 'BOOST EIGEN TBB',
use = 'limbo')
......@@ -28,8 +28,10 @@ def configure(conf):
common_flags = "-Wall -std=c++11 -fcolor-diagnostics"
cxxflags = conf.env['CXXFLAGS']
conf.check_boost(lib='serialization timer filesystem system unit_test_framework program_options graph mpi python thread',
min_version='1.35')
conf.check_boost(lib='serialization timer filesystem \
system unit_test_framework program_options \
graph mpi python thread',
min_version='1.35')
conf.check_eigen()
conf.check_tbb()
conf.check_sferes()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment