Skip to content

Commit

Permalink
Merge branch 'AugusteBourgois-lohner' into lohner
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonRohou committed Jan 11, 2021
2 parents 94e9fb5 + 3766805 commit 81b2507
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 65 deletions.
18 changes: 9 additions & 9 deletions doc/api/Doxyfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ OUTPUT_LANGUAGE = English
# Possible values are: None, LTR, RTL and Context.
# The default value is: None.

OUTPUT_TEXT_DIRECTION = None
# Not supported anymore: OUTPUT_TEXT_DIRECTION = None

# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member
# descriptions after the members that are listed in the file and class
Expand Down Expand Up @@ -205,7 +205,7 @@ JAVADOC_AUTOBRIEF = NO
# interpreted by doxygen.
# The default value is: NO.

JAVADOC_BANNER = NO
# Not supported anymore: JAVADOC_BANNER = NO

# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first
# line (until the first dot) of a Qt-style comment as the brief description. If
Expand Down Expand Up @@ -304,7 +304,7 @@ OPTIMIZE_OUTPUT_VHDL = NO
# separated into more groups, etc.
# The default value is: NO.

OPTIMIZE_OUTPUT_SLICE = NO
# Not supported anymore: OPTIMIZE_OUTPUT_SLICE = NO

# Doxygen selects the parser to use depending on the extension of the files it
# parses. With this tag you can assign which parser to use for a given
Expand Down Expand Up @@ -480,7 +480,7 @@ EXTRACT_PRIVATE = NO
# methods of a class will be included in the documentation.
# The default value is: NO.

EXTRACT_PRIV_VIRTUAL = NO
# Not supported anymore: EXTRACT_PRIV_VIRTUAL = NO

# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal
# scope will be included in the documentation.
Expand Down Expand Up @@ -1096,7 +1096,7 @@ CLANG_OPTIONS =
# Note: The availability of this option depends on whether or not doxygen was
# generated with the -Duse_libclang=ON option for CMake.

CLANG_DATABASE_PATH =
# Not supported anymore: CLANG_DATABASE_PATH =

#---------------------------------------------------------------------------
# Configuration options related to the alphabetical class index
Expand Down Expand Up @@ -1548,7 +1548,7 @@ FORMULA_TRANSPARENT = YES
# to create new LaTeX commands to be used in formulas as building blocks. See
# the section "Including formulas" for details.

FORMULA_MACROFILE =
# Not supported anymore: FORMULA_MACROFILE =

# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see
# https://www.mathjax.org) which uses client side JavaScript for the rendering
Expand Down Expand Up @@ -1733,7 +1733,7 @@ MAKEINDEX_CMD_NAME = makeindex
# The default value is: makeindex.
# This tag requires that the tag GENERATE_LATEX is set to YES.

LATEX_MAKEINDEX_CMD = makeindex
# Not supported anymore: LATEX_MAKEINDEX_CMD = makeindex

# If the COMPACT_LATEX tag is set to YES, doxygen generates more compact LaTeX
# documents. This may be useful for small projects and may help to save some
Expand Down Expand Up @@ -1875,7 +1875,7 @@ LATEX_TIMESTAMP = NO
# LATEX_OUTPUT directory will be used.
# This tag requires that the tag GENERATE_LATEX is set to YES.

LATEX_EMOJI_DIRECTORY =
# Not supported anymore: LATEX_EMOJI_DIRECTORY =

#---------------------------------------------------------------------------
# Configuration options related to the RTF output
Expand Down Expand Up @@ -2019,7 +2019,7 @@ XML_PROGRAMLISTING = YES
# The default value is: NO.
# This tag requires that the tag GENERATE_XML is set to YES.

XML_NS_MEMB_FILE_SCOPE = NO
# Not supported anymore: XML_NS_MEMB_FILE_SCOPE = NO

#---------------------------------------------------------------------------
# Configuration options related to the DOCBOOK output
Expand Down
20 changes: 10 additions & 10 deletions scripts/pybind/doxygen2docstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,16 +212,16 @@ def sentence(str):
print("\nArgs:", file=f)

for param in params:
param_name = param.find("declname").text
print(indent + param_name, "(" + get_tags_text(param.find("type")) + "): ", end='', file=f)

parameterlist = memberdef.find("detaileddescription/para/parameterlist")

if parameterlist:
for parameteritem in parameterlist.iter("parameteritem"):
if parameteritem.find("parameternamelist").find("parametername").text == param_name:
param_description = sentence(get_tags_text(parameteritem.find("parameterdescription")))
print(param_description, file=f)
param_name = param.find("declname")
if param_name:
print(indent + param_name.text, "(" + get_tags_text(param.find("type")) + "): ", end='', file=f)
parameterlist = memberdef.find("detaileddescription/para/parameterlist")

if parameterlist:
for parameteritem in parameterlist.iter("parameteritem"):
if parameteritem.find("parameternamelist").find("parametername").text == param_name.text:
param_description = sentence(get_tags_text(parameteritem.find("parameterdescription")))
print(param_description, file=f)

# Return value (if any)
return_val = memberdef.find(".//simplesect[@kind='return']")
Expand Down
35 changes: 19 additions & 16 deletions src/core/contractors/dyn/tubex_CtcLohner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ struct GlobalEnclosureError : public std::runtime_error {
*/
class LohnerAlgorithm {
public:
constexpr static const double FWD = 1, BWD = -1;
constexpr static const double FWD = 1., BWD = -1.;

/**
* \brief Creates a Lohner algorithm object
*
* \param f function defining the system \f$\dot{\mathbf{x}}=\mathbf{f}(\mathbf{x})\f$
* \param h time step of the integration method
* \param direction forward or backaward integration
* \param u0 initial condition of the system
* \param contractions number of contractions of the global enclosure by the estimated local enclosure
* \param eps inflation parameter for the global enclosure
*/
LohnerAlgorithm(const ibex::Function *f,
double h,
bool forward,
const ibex::IntervalVector &u0 = ibex::IntervalVector::empty(1),
int contractions = 1,
double eps = 0.1);
Expand All @@ -65,7 +67,7 @@ class LohnerAlgorithm {
* \param H parameter to overwrite the integration time step
* \return enclosure of the system's state
*/
const ibex::IntervalVector &integrate(uint steps, double H = -1);
const ibex::IntervalVector &integrate(unsigned int steps, double H = -1);

/**
* \brief contract the global & local enclosure of the previous integration step
Expand Down Expand Up @@ -93,13 +95,14 @@ class LohnerAlgorithm {
* \brief Computes an estimation of the global enclosure of the system
*
* \param initialGuess initial guess for the global enclosure
* \param direction forward or backward in time
* \param dir forward or backward in time
* \return estimation of the global enclosure
*/
ibex::IntervalVector globalEnclosure(const ibex::IntervalVector &initialGuess, double direction);
ibex::IntervalVector globalEnclosure(const ibex::IntervalVector &initialGuess, double dir);

uint dim; //!< dimension of the system's state
unsigned int dim; //!< dimension of the system's state
double h; //!< integration time step
double direction; //!< forward or backward integration
double eps; //!< inflation parameter for the global enclosure
int contractions; //!< number of contractions of the global enclosure by the estimated local enclosure
ibex::IntervalVector u; //!< local enclosure
Expand All @@ -115,11 +118,13 @@ class LohnerAlgorithm {

LohnerAlgorithm::LohnerAlgorithm(const ibex::Function *f,
double h,
bool forward,
const ibex::IntervalVector &u0,
int contractions,
double eps)
: dim(f->nb_var()),
h(h),
direction((forward) ? FWD : BWD),
eps(eps),
contractions(contractions),
u(u0),
Expand All @@ -140,12 +145,12 @@ const ibex::IntervalVector &LohnerAlgorithm::integrate(unsigned int steps, doubl
for (int j = 0; j < contractions; ++j) {
z1 = 0.5 * h * h * f->jacobian(u_t) * f->eval_vector(u_t);
ibex::Vector m1 = z1.mid();
ibex::IntervalMatrix A = ibex::Matrix::eye(dim) + h * f->jacobian(u);
ibex::IntervalMatrix A = ibex::Matrix::eye(dim) + h * direction * f->jacobian(u);
Eigen::HouseholderQR<Eigen::MatrixXd> qr(EigenHelpers::i2e((A * B).mid()));
B1 = EigenHelpers::e2i(qr.householderQ());
B1inv = ibex::real_inverse(B1);
r1 = (B1inv * A * B) * r + B1inv * (z1 - m1);
u_hat1 = u_hat + h * f->eval_vector(u_hat).mid() + m1;
u_hat1 = u_hat + h * direction * f->eval_vector(u_hat).mid() + m1;
u1 = u_hat1 + B1 * r1;
if (j < contractions - 1) {
u_t = u_t & globalEnclosure(u1, BWD);
Expand All @@ -156,10 +161,10 @@ const ibex::IntervalVector &LohnerAlgorithm::integrate(unsigned int steps, doubl
return u;
}

ibex::IntervalVector LohnerAlgorithm::globalEnclosure(const ibex::IntervalVector &initialGuess, double direction) {
ibex::IntervalVector LohnerAlgorithm::globalEnclosure(const ibex::IntervalVector &initialGuess, double dir) {
ibex::IntervalVector u_0 = initialGuess;
for (unsigned int i = 0; i < 30; ++i) {
ibex::IntervalVector u_1 = initialGuess + direction * ibex::Interval(0, h) * f->eval_vector(u_0);
ibex::IntervalVector u_1 = initialGuess + dir * direction * ibex::Interval(0, h) * f->eval_vector(u_0);
if (u_0.is_superset(u_1)) {
return u_0;
} else {
Expand All @@ -185,22 +190,20 @@ const ibex::IntervalVector &LohnerAlgorithm::getGlobalEnclosure() const {

CtcLohner::CtcLohner(const ibex::Function &f, int contractions, double eps)
: DynCtc(),
_x_(ExprSymbol::new_(Dim::col_vec(f.nb_var()))),
m_f(f),
m_f_1(_x_, -m_f(_x_)),
contractions(contractions),
dim(f.nb_var()),
eps(eps) {}

void CtcLohner::contract(tubex::TubeVector &tube, TimePropag t_propa) {
assert((!tube.is_empty())&&(tube.size() == dim));
assert((!tube.is_empty()) && (tube.size() == dim));
IntervalVector input_gate(dim, Interval(0)), output_gate(dim, Interval(0)), slice(dim, Interval(0));
double h;
if (t_propa & TimePropag::FORWARD) {
for (int j = 0; j < dim; ++j) {
input_gate[j] = tube[j].slice(0)->input_gate();
}
LohnerAlgorithm lo(&m_f, 0.1, input_gate, contractions, eps);
LohnerAlgorithm lo(&m_f, 0.1, true, input_gate, contractions, eps);
// Forward loop
for (int i = 0; i < tube.nb_slices(); ++i) {
h = tube[0].slice(i)->tdomain().diam();
Expand All @@ -218,7 +221,7 @@ void CtcLohner::contract(tubex::TubeVector &tube, TimePropag t_propa) {
for (int j = 0; j < dim; ++j) {
input_gate[j] = tube[j].last_slice()->output_gate();
}
LohnerAlgorithm lo2(&m_f_1, 0.1, input_gate, contractions, eps);
LohnerAlgorithm lo2(&m_f, 0.1, false, input_gate, contractions, eps);
// Backward loop
for (int i = tube.nb_slices() - 1; i >= 0; --i) {
h = tube[0].slice(i)->tdomain().diam();
Expand All @@ -235,7 +238,7 @@ void CtcLohner::contract(tubex::TubeVector &tube, TimePropag t_propa) {
}

void CtcLohner::contract(tubex::Tube &tube, TimePropag t_propa) {
assert(not tube.is_empty());
assert(!tube.is_empty());
tubex::TubeVector tubeVector(1, tube);
contract(tubeVector, t_propa);
tube = tubeVector[0];
Expand All @@ -252,7 +255,7 @@ vector<string> CtcLohner::m_str_expected_doms(
void CtcLohner::contract(vector<Domain *> &v_domains) {

// todo: manage the contractor on a slice level

if (v_domains.size() != 1)
throw DomainsTypeException(m_ctc_name, v_domains, m_str_expected_doms);

Expand Down
2 changes: 0 additions & 2 deletions src/core/contractors/dyn/tubex_CtcLohner.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ class CtcLohner : public tubex::DynCtc {
void contract(std::vector<tubex::Domain *> &v_domains) override;

protected:
const ibex::ExprSymbol &_x_; //!< symbol for inner litteral function
ibex::Function m_f; //!< forward function
ibex::Function m_f_1; //!< backward function
int contractions; //!< number of contractions of the global enclosure by the estimated local enclosure
int dim; //!< dimension of the state vector
double eps; //!< inflation parameter for the global enclosure
Expand Down
56 changes: 28 additions & 28 deletions tests/core/tests_ctc_lohner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,34 @@ TEST_CASE("CtcLohner") {
CHECK(x->output_gate().is_superset(Interval(exp(domain.ub()))));
}

// SECTION("Test CtcLohner / TubeVector - dim 2") {
// Interval domain(0., 1.);
//
// TubeVector x(domain, 2);
// IntervalVector condition(2, Interval(1.));
// x.set(condition, 0.);
//
// Function f("x", "y", "(-x ; y)");
// CtcLohner ctc_lohner(f);
// ctc_lohner.contract(x, TimePropag::FORWARD);
//
// CHECK_FALSE(x.codomain().is_unbounded());
// // TODO : CHECK(x.codomain()[0].is_superset(exp(-domain)));
// CHECK(x(0.)[0].is_superset(Interval(exp(-0.))));
// CHECK(x(1.)[0].is_superset(Interval(exp(-1.))));
// // TODO : CHECK(x.codomain()[1].is_superset(exp(domain)));
// CHECK(x(0.)[1].is_superset(Interval(exp(0.))));
// CHECK(x(1.)[1].is_superset(Interval(exp(1.))));
//
// //if(false & VIBES_DRAWING) // drawing results
// //{
// // vibes::beginDrawing();
// // VIBesFigTube fig_tube("picard", &x);
// // fig_tube.set_properties(100, 100, 500, 500);
// // fig_tube.show(true);
// // vibes::endDrawing();
// //}
// }
SECTION("Test CtcLohner / TubeVector - dim 2") {
Interval domain(0., 1.);
double dt = 0.1;
TubeVector x(domain, dt, 2);
IntervalVector condition(2, Interval(1.));
x.set(condition, 0.);

Function f("x", "y", "(-x ; y)");
CtcLohner ctc_lohner(f);
ctc_lohner.contract(x, TimePropag::FORWARD);

CHECK_FALSE(x.codomain().is_unbounded());
// TODO : CHECK(x.codomain()[0].is_superset(exp(-domain)));
CHECK(x(0.)[0].is_superset(Interval(exp(-0.))));
CHECK(x(1.)[0].is_superset(Interval(exp(-1.))));
// TODO : CHECK(x.codomain()[1].is_superset(exp(domain)));
CHECK(x(0.)[1].is_superset(Interval(exp(0.))));
CHECK(x(1.)[1].is_superset(Interval(exp(1.))));

//if(false & VIBES_DRAWING) // drawing results
//{
// vibes::beginDrawing();
// VIBesFigTube fig_tube("picard", &x);
// fig_tube.set_properties(100, 100, 500, 500);
// fig_tube.show(true);
// vibes::endDrawing();
//}
}

SECTION("Test CtcLohner / TubeVector - dim 1 - forward") {
Interval domain(0., 1.);
Expand Down

0 comments on commit 81b2507

Please sign in to comment.