1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2023, LAAS-CNRS, University of Edinburgh |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#include "crocoddyl/core/activations/smooth-1norm.hpp" |
11 |
|
|
|
12 |
|
|
#include "python/crocoddyl/core/activation-base.hpp" |
13 |
|
|
#include "python/crocoddyl/core/core.hpp" |
14 |
|
|
#include "python/crocoddyl/utils/copyable.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
10 |
void exposeActivationSmooth1Norm() { |
20 |
|
|
boost::python::register_ptr_to_python< |
21 |
|
10 |
boost::shared_ptr<ActivationModelSmooth1Norm> >(); |
22 |
|
|
|
23 |
✓✗ |
10 |
bp::class_<ActivationModelSmooth1Norm, bp::bases<ActivationModelAbstract> >( |
24 |
|
|
"ActivationModelSmooth1Norm", |
25 |
|
|
"Smooth-absolute activation model.\n\n" |
26 |
|
|
"It describes a smooth representation of an absolute activation " |
27 |
|
|
"(1-norm), i.e.\n" |
28 |
|
|
"sum^nr_{i=0} sqrt{eps + ||ri||^2}, where ri is the scalar residual for " |
29 |
|
|
"the i constraints,\n." |
30 |
|
|
"and nr is the dimension of the residual vector.", |
31 |
✓✗ |
10 |
bp::init<int, bp::optional<double> >( |
32 |
|
20 |
bp::args("self", "nr", "eps"), |
33 |
|
|
"Initialize the activation model.\n\n" |
34 |
|
|
":param nr: dimension of the residual vector\n" |
35 |
|
|
":param eps: smoothing factor (default: 1.)")) |
36 |
|
|
.def("calc", &ActivationModelSmooth1Norm::calc, |
37 |
✓✗ |
20 |
bp::args("self", "data", "r"), |
38 |
|
|
"Compute the smooth-abs function.\n\n" |
39 |
|
|
":param data: activation data\n" |
40 |
✓✗ |
10 |
":param r: residual vector") |
41 |
|
|
.def("calcDiff", &ActivationModelSmooth1Norm::calcDiff, |
42 |
✓✗ |
20 |
bp::args("self", "data", "r"), |
43 |
|
|
"Compute the derivatives of a smooth-abs function.\n\n" |
44 |
|
|
"It assumes that calc has been run first.\n" |
45 |
|
|
":param data: activation data\n" |
46 |
✓✗ |
10 |
":param r: residual vector \n") |
47 |
|
|
.def("createData", &ActivationModelSmooth1Norm::createData, |
48 |
✓✗✓✗
|
20 |
bp::args("self"), "Create the smooth-abs activation data.\n\n") |
49 |
✓✗ |
10 |
.def(CopyableVisitor<ActivationModelSmooth1Norm>()); |
50 |
|
|
|
51 |
|
10 |
bp::register_ptr_to_python<boost::shared_ptr<ActivationDataSmooth1Norm> >(); |
52 |
|
|
|
53 |
✓✗ |
10 |
bp::class_<ActivationDataSmooth1Norm, bp::bases<ActivationDataAbstract> >( |
54 |
|
|
"ActivationDataSmooth1Norm", "Data for smooth-abs activation.\n\n", |
55 |
✓✗ |
10 |
bp::init<ActivationModelSmooth1Norm*>( |
56 |
|
20 |
bp::args("self", "model"), |
57 |
|
|
"Create smooth-abs activation data.\n\n" |
58 |
|
|
":param model: smooth-abs activation model")) |
59 |
|
|
.add_property("a", |
60 |
✓✗ |
10 |
bp::make_getter(&ActivationDataSmooth1Norm::a, |
61 |
|
10 |
bp::return_internal_reference<>()), |
62 |
✓✗ |
10 |
"sqrt{eps + ||ri||^2} value") |
63 |
✓✗ |
10 |
.def(CopyableVisitor<ActivationDataSmooth1Norm>()); |
64 |
|
10 |
} |
65 |
|
|
|
66 |
|
|
} // namespace python |
67 |
|
|
} // namespace crocoddyl |