robotic 0.3.4__cp38-cp38-manylinux2014_x86_64.whl → 0.3.4.dev2__cp38-cp38-manylinux2014_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of robotic might be problematic. Click here for more details.
- robotic/_robotic.pyi +32 -14
- robotic/_robotic.so +0 -0
- robotic/include/rai/Algo/RidgeRegression.h +1 -1
- robotic/include/rai/Algo/rungeKutta.h +1 -1
- robotic/include/rai/Core/array.h +30 -22
- robotic/include/rai/Core/array.ipp +53 -60
- robotic/include/rai/Core/arrayDouble.h +29 -25
- robotic/include/rai/DataGen/shapenetGrasps.h +1 -1
- robotic/include/rai/Geo/mesh.h +2 -4
- robotic/include/rai/Geo/pairCollision.h +40 -36
- robotic/include/rai/Geo/signedDistanceFunctions.h +6 -4
- robotic/include/rai/KOMO/komo.h +1 -1
- robotic/include/rai/Kin/dof_forceExchange.h +3 -3
- robotic/include/rai/Kin/feature.h +1 -1
- robotic/include/rai/Kin/frame.h +9 -12
- robotic/include/rai/Kin/proxy.h +1 -1
- robotic/include/rai/Optim/BayesOpt.h +14 -7
- robotic/include/rai/Optim/CMA/boundary_transformation.h +73 -0
- robotic/include/rai/Optim/CMA/cmaes.h +175 -0
- robotic/include/rai/Optim/CMA/cmaes_interface.h +68 -0
- robotic/include/rai/Optim/GlobalIterativeNewton.h +7 -3
- robotic/include/rai/Optim/NLP.h +15 -1
- robotic/include/rai/Optim/NLP_Solver.h +5 -5
- robotic/include/rai/Optim/constrained.h +3 -3
- robotic/include/rai/Optim/lagrangian.h +6 -5
- robotic/include/rai/Optim/m_EvoStrategies.h +94 -0
- robotic/include/rai/Optim/{gradient.h → m_Gradient.h} +12 -13
- robotic/include/rai/Optim/m_LBFGS.h +21 -0
- robotic/include/rai/Optim/m_LeastSquaresZeroOrder.h +18 -11
- robotic/include/rai/Optim/m_LocalGreedy.h +31 -0
- robotic/include/rai/Optim/m_NelderMead.h +17 -0
- robotic/include/rai/Optim/{newton.h → m_Newton.h} +8 -5
- robotic/include/rai/Optim/options.h +6 -7
- robotic/include/rai/Optim/primalDual.h +9 -5
- robotic/include/rai/Optim/testProblems_Opt.h +5 -5
- robotic/include/rai/Optim/utils.h +9 -20
- robotic/librai.so +0 -0
- robotic/meshTool +0 -0
- robotic/version.py +1 -1
- {robotic-0.3.4.dist-info → robotic-0.3.4.dev2.dist-info}/METADATA +1 -1
- {robotic-0.3.4.dist-info → robotic-0.3.4.dev2.dist-info}/RECORD +62 -56
- robotic/include/rai/Optim/lbfgs.h +0 -18
- /robotic/include/rai/Geo/{assimpInterface.h → i_assimp.h} +0 -0
- /robotic/include/rai/Geo/{fclInterface.h → i_fcl.h} +0 -0
- /robotic/include/rai/Kin/{kin_bullet.h → i_Bullet.h} +0 -0
- /robotic/include/rai/Kin/{kin_feather.h → i_Feather.h} +0 -0
- /robotic/include/rai/Kin/{kin_ode.h → i_Ode.h} +0 -0
- /robotic/include/rai/Kin/{kin_physx.h → i_Physx.h} +0 -0
- /robotic/include/rai/Optim/{opt-ceres.h → i_Ceres.h} +0 -0
- /robotic/include/rai/Optim/{opt-ipopt.h → i_Ipopt.h} +0 -0
- /robotic/include/rai/Optim/{opt-nlopt.h → i_NLopt.h} +0 -0
- /robotic/include/rai/Optim/{liblbfgs.h → liblbfgs/liblbfgs.h} +0 -0
- /robotic/include/rai/Optim/{SlackGaussNewton.h → m_SlackGaussNewton.h} +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-bot +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-h5info +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-info +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-meshTool +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-test +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-urdfConvert.py +0 -0
- {robotic-0.3.4.data → robotic-0.3.4.dev2.data}/scripts/ry-view +0 -0
- {robotic-0.3.4.dist-info → robotic-0.3.4.dev2.dist-info}/LICENSE +0 -0
- {robotic-0.3.4.dist-info → robotic-0.3.4.dev2.dist-info}/WHEEL +0 -0
- {robotic-0.3.4.dist-info → robotic-0.3.4.dev2.dist-info}/top_level.txt +0 -0
|
@@ -13,43 +13,18 @@
|
|
|
13
13
|
|
|
14
14
|
namespace rai {
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
* The constructor compute the collision geometry, the other methods are mostly readouts
|
|
18
|
-
* The default is distance between two convex meshes
|
|
19
|
-
* Also distance between point (=mesh1) and points (=mesh2)
|
|
20
|
-
* Also distance between point (=mesh1) and decomposed mesh (=mesh2)
|
|
21
|
-
*/
|
|
22
|
-
struct PairCollision : NonCopyable {
|
|
16
|
+
struct PairCollision {
|
|
23
17
|
//INPUTS
|
|
24
|
-
arr mesh1;
|
|
25
|
-
arr mesh2;
|
|
26
|
-
const rai::Transformation* t1=0;
|
|
27
|
-
const rai::Transformation* t2=0;
|
|
28
18
|
double rad1=0., rad2=0.; ///< only kinVector and glDraw account for this; the basic collision geometry (OUTPUTS below) is computed neglecting radii!!
|
|
29
19
|
|
|
30
20
|
//OUTPUTS
|
|
31
21
|
double distance=0.; ///< negative=penetration
|
|
32
|
-
arr p1, p2;
|
|
33
|
-
arr normal;
|
|
34
|
-
arr
|
|
35
|
-
arr simplex2; ///< simplex on obj2 defining the collision geometry
|
|
36
|
-
|
|
37
|
-
// arr m1, m2, eig1, eig2; ///< output of marginAnalysis: mean and eigenvalues of ALL point on the objs (not only simplex) that define the collision
|
|
38
|
-
|
|
39
|
-
arr poly, polyNorm;
|
|
40
|
-
|
|
41
|
-
//mesh-to-mesh
|
|
42
|
-
PairCollision(const arr& mesh1, const arr& mesh2,
|
|
43
|
-
const rai::Transformation& t1, const rai::Transformation& t2,
|
|
44
|
-
double rad1=0., double rad2=0.);
|
|
45
|
-
//sdf-to-sdf
|
|
46
|
-
PairCollision(ScalarFunction& func1, ScalarFunction& func2, const arr& seed);
|
|
47
|
-
|
|
48
|
-
~PairCollision() {}
|
|
49
|
-
|
|
50
|
-
void write(std::ostream& os) const;
|
|
22
|
+
arr p1, p2; ///< witness points on the shapes
|
|
23
|
+
arr normal; ///< normal such that "<normal, p1-p2> = distance" is guaranteed (pointing from obj2 to obj1)
|
|
24
|
+
arr simp1, simp2; ///< simplices on the shapes defining the collision geometry
|
|
51
25
|
|
|
52
26
|
double getDistance() { return distance-rad1-rad2; }
|
|
27
|
+
void write(std::ostream& os) const;
|
|
53
28
|
|
|
54
29
|
// differentiable readout methods (Jp1 and Jx1 are linear and angular Jacobians of mesh1)
|
|
55
30
|
void kinDistance(arr& y, arr& J, const arr& Jp1, const arr& Jp2);
|
|
@@ -59,23 +34,52 @@ struct PairCollision : NonCopyable {
|
|
|
59
34
|
void kinPointP2(arr& y, arr& J, const arr& Jp1, const arr& Jp2, const arr& Jx1, const arr& Jx2);
|
|
60
35
|
void kinCenter(arr& y, arr& J, const arr& Jp1, const arr& Jp2, const arr& Jx1, const arr& Jx2);
|
|
61
36
|
|
|
62
|
-
|
|
37
|
+
protected:
|
|
38
|
+
bool simplexType(uint i, uint j) { return simp1.d0==i && simp2.d0==j; } //helper
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//===========================================================================
|
|
42
|
+
|
|
43
|
+
/* A class to represent a basic function: distance between two convex (decomposed) meshes
|
|
44
|
+
* The constructor compute the collision geometry, the other methods are mostly readouts
|
|
45
|
+
* The default is distance between two convex meshes
|
|
46
|
+
* Also distance between point (=mesh1) and points (=mesh2)
|
|
47
|
+
* Also distance between point (=mesh1) and decomposed mesh (=mesh2)
|
|
48
|
+
*/
|
|
49
|
+
struct PairCollision_CvxCvx : PairCollision, NonCopyable {
|
|
63
50
|
|
|
64
|
-
|
|
51
|
+
//mesh-to-mesh
|
|
52
|
+
PairCollision_CvxCvx(const arr& pts1, const arr& pts2,
|
|
53
|
+
const rai::Transformation& t1, const rai::Transformation& t2,
|
|
54
|
+
double rad1=0., double rad2=0.);
|
|
55
|
+
//sdf-to-sdf -- TODO: own class!
|
|
56
|
+
PairCollision_CvxCvx(ScalarFunction func1, ScalarFunction func2, const arr& seed);
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// void nearSupportAnalysis(double eps=1e-6); ///< analyses not only closest obj support (the simplex) but all points within a margin
|
|
60
|
+
|
|
61
|
+
private:
|
|
65
62
|
//wrappers of external libs
|
|
66
63
|
enum CCDmethod { _ccdGJKIntersect, _ccdGJKSeparate, _ccdGJKPenetration, _ccdMPRIntersect, _ccdMPRPenetration };
|
|
67
64
|
void libccd(const arr& m1, const arr& m2, CCDmethod method); //calls ccdMPRPenetration of libccd
|
|
68
|
-
void GJK_sqrDistance(); //gjk_distance of libGJK
|
|
69
|
-
|
|
65
|
+
void GJK_sqrDistance(const arr& pts1, const arr& pts2, const rai::Transformation& t1, const rai::Transformation& t2); //gjk_distance of libGJK
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//===========================================================================
|
|
69
|
+
|
|
70
|
+
struct PairCollision_CvxDecomp : PairCollision, NonCopyable {
|
|
71
|
+
PairCollision_CvxDecomp(const arr& x, Mesh& mesh,
|
|
72
|
+
const rai::Transformation& t1, const rai::Transformation& t2,
|
|
73
|
+
double rad1=0., double rad2=0.);
|
|
70
74
|
};
|
|
71
75
|
|
|
72
76
|
//===========================================================================
|
|
73
77
|
|
|
74
|
-
struct
|
|
78
|
+
struct PairCollision_PtPcl {
|
|
75
79
|
//OUTPUTS
|
|
76
80
|
arr y, J;
|
|
77
81
|
|
|
78
|
-
|
|
82
|
+
PairCollision_PtPcl(const arr& x, ANN& ann,
|
|
79
83
|
const rai::Transformation& t1, const arr& Jp1, const arr& Jx1,
|
|
80
84
|
const rai::Transformation& t2, const arr& Jp2, const arr& Jx2,
|
|
81
85
|
double rad1=0., double rad2=0.,
|
|
@@ -16,15 +16,17 @@
|
|
|
16
16
|
// analytic distance functions
|
|
17
17
|
//
|
|
18
18
|
|
|
19
|
-
struct SDF
|
|
19
|
+
struct SDF {
|
|
20
20
|
SDF(const rai::Transformation& _pose)
|
|
21
|
-
|
|
21
|
+
: pose(_pose) {}
|
|
22
22
|
~SDF() {}
|
|
23
23
|
rai::Transformation pose;
|
|
24
24
|
arr lo, up;
|
|
25
25
|
virtual double f(arr& g, arr& H, const arr& x);
|
|
26
26
|
virtual double f_raw(arr& g, arr& H, const arr& x) { NIY; }
|
|
27
27
|
|
|
28
|
+
ScalarFunction f_scalar(){ return [this](arr& g, arr& H, const arr& x){ return this->f(g, H, x); }; }
|
|
29
|
+
|
|
28
30
|
arr eval(const arr& samples);
|
|
29
31
|
floatA evalFloat(const arr& samples);
|
|
30
32
|
floatA evalGrid(uint d0, int d1=-1, int d2=-1);
|
|
@@ -108,7 +110,7 @@ struct DensityDisplayData {
|
|
|
108
110
|
|
|
109
111
|
struct TensorShape : SDF {
|
|
110
112
|
floatA gridData;
|
|
111
|
-
shared_ptr<DensityDisplayData> _densityDisplayData;
|
|
113
|
+
// shared_ptr<DensityDisplayData> _densityDisplayData;
|
|
112
114
|
arr color;
|
|
113
115
|
|
|
114
116
|
TensorShape(const rai::Transformation& _pose, const floatA& _data, const arr& _lo, const arr& _up)
|
|
@@ -157,4 +159,4 @@ struct PCL2Field {
|
|
|
157
159
|
|
|
158
160
|
//===========================================================================
|
|
159
161
|
|
|
160
|
-
|
|
162
|
+
ScalarFunction DistanceFunction_SSBox();
|
robotic/include/rai/KOMO/komo.h
CHANGED
|
@@ -165,7 +165,7 @@ struct KOMO : rai::NonCopyable {
|
|
|
165
165
|
void updateAndShiftPrefix(const rai::Configuration& C);
|
|
166
166
|
|
|
167
167
|
//-- calling a solver
|
|
168
|
-
std::shared_ptr<SolverReturn> solve(double addInitializationNoise=.01, int splineKnots=-1, const rai::OptOptions& options
|
|
168
|
+
std::shared_ptr<SolverReturn> solve(double addInitializationNoise=.01, int splineKnots=-1, const rai::OptOptions& options=*DEFAULT_OPTIONS); ///< run the solver (same as run_prepare(); run(); )
|
|
169
169
|
void reset(); ///< reset the dual variables and feature value buffers (always needed when adding/changing objectives before continuing an optimization)
|
|
170
170
|
|
|
171
171
|
//advanced
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
namespace rai {
|
|
15
15
|
|
|
16
|
-
struct
|
|
16
|
+
struct PairCollision_CvxCvx;
|
|
17
17
|
|
|
18
18
|
//===========================================================================
|
|
19
19
|
|
|
@@ -26,7 +26,7 @@ struct ForceExchangeDof : Dof, NonCopyable {
|
|
|
26
26
|
double scale=1.;
|
|
27
27
|
double force_to_torque = 0.;
|
|
28
28
|
private:
|
|
29
|
-
|
|
29
|
+
PairCollision_CvxCvx* __coll=0;
|
|
30
30
|
public:
|
|
31
31
|
|
|
32
32
|
arr poa; //in world coordinates!
|
|
@@ -50,7 +50,7 @@ struct ForceExchangeDof : Dof, NonCopyable {
|
|
|
50
50
|
virtual void kinForce(arr& y, arr& J) const;
|
|
51
51
|
virtual void kinTorque(arr& y, arr& J) const;
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
PairCollision_CvxCvx* coll();
|
|
54
54
|
|
|
55
55
|
virtual void write(ostream& os) const;
|
|
56
56
|
};
|
|
@@ -49,7 +49,7 @@ struct Feature {
|
|
|
49
49
|
// Value eval(const FrameL& F) { arr y, J; eval(y, J, F); return Value(y, J); }
|
|
50
50
|
arr eval(const rai::Configuration& C) { return eval(getFrames(C)); }
|
|
51
51
|
uint dim(const FrameL& F) { uint d=dim_phi(F); return applyLinearTrans_dim(d); }
|
|
52
|
-
|
|
52
|
+
VectorFunction asFct(const FrameL& F);
|
|
53
53
|
|
|
54
54
|
virtual const char* typeString() { return rai::niceTypeidName(typeid(*this)); }
|
|
55
55
|
virtual rai::String shortTag(const rai::Configuration& C);
|
robotic/include/rai/Kin/frame.h
CHANGED
|
@@ -97,7 +97,7 @@ struct Frame : NonCopyable {
|
|
|
97
97
|
|
|
98
98
|
//attachments to the frame
|
|
99
99
|
Joint* joint=nullptr; ///< this frame is an articulated joint
|
|
100
|
-
Shape
|
|
100
|
+
shared_ptr<Shape> shape; ///< this frame has a (collision or visual) geometry
|
|
101
101
|
Inertia* inertia=nullptr; ///< this frame has inertia (is a mass)
|
|
102
102
|
//TODO have a single list of all attached dofs (also joint)
|
|
103
103
|
Array<ForceExchangeDof*> forces; ///< this frame exchanges forces with other frames
|
|
@@ -329,12 +329,12 @@ stdOutPipe(Inertia)
|
|
|
329
329
|
|
|
330
330
|
/// a Frame with Shape is a collision or visual object
|
|
331
331
|
struct Shape : NonCopyable {
|
|
332
|
-
|
|
333
|
-
Enum<ShapeType> _type;
|
|
332
|
+
Enum<ShapeType> _type = ST_none;
|
|
334
333
|
arr size;
|
|
335
334
|
shared_ptr<Mesh> _mesh;
|
|
336
335
|
shared_ptr<arr> _sscCore;
|
|
337
336
|
double coll_cvxRadius=-1.;
|
|
337
|
+
int version = 0;
|
|
338
338
|
shared_ptr<SDF> _sdf;
|
|
339
339
|
char cont=0; ///< are contacts registered (or filtered in the callback)
|
|
340
340
|
|
|
@@ -345,17 +345,14 @@ struct Shape : NonCopyable {
|
|
|
345
345
|
SDF& sdf() { if(!_sdf) { if(_type==ST_none) _type=ST_sdf; _sdf = make_shared<TensorShape>(); } return *_sdf; }
|
|
346
346
|
double alpha() { arr& C=mesh().C; if(C.N==4 || C.N==2 || (C.nd==2 && C.d1==4)) return C.elem(-1); return 1.; }
|
|
347
347
|
|
|
348
|
-
void createMeshes();
|
|
349
|
-
shared_ptr<
|
|
350
|
-
|
|
351
|
-
Shape(Frame& f, const Shape* copyShape=nullptr); //new Shape, being added to graph and frame's shape lists
|
|
352
|
-
virtual ~Shape();
|
|
348
|
+
void createMeshes(const str& name);
|
|
349
|
+
shared_ptr<SDF> functional(const rai::Transformation& pose=0);
|
|
353
350
|
|
|
354
|
-
bool
|
|
351
|
+
bool canCollide(const rai::Frame* f1, const Frame* f2) const;
|
|
355
352
|
|
|
356
|
-
void read(
|
|
357
|
-
void write(std::ostream& os) const;
|
|
358
|
-
void write(Graph& g);
|
|
353
|
+
void read(Frame& frame);
|
|
354
|
+
void write(std::ostream& os, const Frame& frame) const;
|
|
355
|
+
void write(Graph& g, const Frame& frame);
|
|
359
356
|
};
|
|
360
357
|
|
|
361
358
|
//===========================================================================
|
robotic/include/rai/Kin/proxy.h
CHANGED
|
@@ -11,30 +11,35 @@
|
|
|
11
11
|
#include "GlobalIterativeNewton.h"
|
|
12
12
|
#include "../Core/array.h"
|
|
13
13
|
|
|
14
|
+
struct KernelRidgeRegression;
|
|
15
|
+
struct DefaultKernelFunction;
|
|
16
|
+
|
|
17
|
+
namespace rai {
|
|
18
|
+
|
|
14
19
|
struct BayesOpt {
|
|
15
|
-
ScalarFunction
|
|
20
|
+
ScalarFunction f;
|
|
16
21
|
arr bounds;
|
|
17
22
|
|
|
18
23
|
arr data_X;
|
|
19
24
|
arr data_y;
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
KernelRidgeRegression* f_now;
|
|
27
|
+
KernelRidgeRegression* f_smaller;
|
|
23
28
|
|
|
24
29
|
GlobalIterativeNewton alphaMinima_now;
|
|
25
30
|
GlobalIterativeNewton alphaMinima_smaller;
|
|
26
31
|
|
|
27
|
-
|
|
28
|
-
|
|
32
|
+
DefaultKernelFunction* kernel_now;
|
|
33
|
+
DefaultKernelFunction* kernel_smaller;
|
|
29
34
|
double lengthScale;
|
|
30
35
|
|
|
31
36
|
//lengthScale is always relative to hi-lo
|
|
32
|
-
BayesOpt(ScalarFunction
|
|
37
|
+
BayesOpt(ScalarFunction f, const arr& bounds, shared_ptr<OptOptions> opt, double init_lengthScale=1., double prior_var=1.);
|
|
33
38
|
~BayesOpt();
|
|
34
39
|
|
|
35
40
|
void step();
|
|
36
41
|
void run(uint maxIt=10);
|
|
37
|
-
void report(bool display, ScalarFunction
|
|
42
|
+
void report(bool display, ScalarFunction f);
|
|
38
43
|
|
|
39
44
|
private:
|
|
40
45
|
void addDataPoint(const arr& x, double y); //and update the regressions
|
|
@@ -42,3 +47,5 @@ struct BayesOpt {
|
|
|
42
47
|
arr pickNextPoint();
|
|
43
48
|
void reduceLengthScale();
|
|
44
49
|
};
|
|
50
|
+
|
|
51
|
+
} //namespace
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* INTERFACE: the relevant functions are
|
|
3
|
+
*
|
|
4
|
+
* * cmaes_boundary_transformation_init(this, l_bound, u_bound, len)
|
|
5
|
+
* * cmaes_boundary_transformation_exit(this)
|
|
6
|
+
* * cmaes_boundary_transformation(this, x, y, len)
|
|
7
|
+
*
|
|
8
|
+
* implements a smooth mapping double *x -> double *y that guarantees
|
|
9
|
+
* elements of y to be within specified boundaries. The mapping is piecewise
|
|
10
|
+
* either linear or quadratic and can achieve values arbitrarily close to and
|
|
11
|
+
* on the boundaries. The middle of the domain l_bound + (u_bound-l_bound) / 2.0
|
|
12
|
+
* always maps to itself. Typically, 90% of feasible values (those not close
|
|
13
|
+
* to the boundaries) are mapped to themselves, preventing any numerical subtleties.
|
|
14
|
+
* Specifically, al, au > 0 are internally chosen offsets. The mapping
|
|
15
|
+
* [l_bound - al, u_bound + au] <-> [l_bound, u_bound] is monotonous, bijective
|
|
16
|
+
* and invertible. It is the identity within [l_bound + al, u_bound - au] and
|
|
17
|
+
* quadratic for [l_bound - 3*al, l_bound + al] (with l_bound - al -> l_bound)
|
|
18
|
+
* and for [u_bound - au, u_bound + 3*au] (with u_bound + au -> u_bound).
|
|
19
|
+
*
|
|
20
|
+
* The method is robust against very small/large boundary values, say
|
|
21
|
+
* -1e99 and/or 1e99, to emulated unbounded variables. In this case values
|
|
22
|
+
* between -1e98 and 1e98 are never changed, i.e. mapped to itself.
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
typedef struct {
|
|
27
|
+
double const *lower_bounds; /* array of size len_of_bounds */
|
|
28
|
+
double const *upper_bounds; /* array of size len_of_bounds */
|
|
29
|
+
unsigned long len_of_bounds; /* in case, last value is recycled */
|
|
30
|
+
double *al; /* "add"-on to lower boundary preimage, same length as bounds */
|
|
31
|
+
double *au; /* add-on to upper boundary preimage, same length as bounds */
|
|
32
|
+
} cmaes_boundary_transformation_t;
|
|
33
|
+
|
|
34
|
+
/* set lower and upper bounds, the values lower_bounds[len_of_bounds - 1] and
|
|
35
|
+
* upper_bounds[len_of_bounds - 1] are recycled for any element >= len_of_bounds.
|
|
36
|
+
* If len_of_bounds == 0, no bounds are assumed. If len_of_bounds == 1, the
|
|
37
|
+
* zero pointer is allowed for lower_bounds or upper_bounds and indicates no
|
|
38
|
+
* respective bounds. "no bounds" is "emulated" using the very small/large value
|
|
39
|
+
* of DBL_MAX / -1e2 and DBL_MAX / 1e2, respectively. */
|
|
40
|
+
void cmaes_boundary_transformation_init(cmaes_boundary_transformation_t *,
|
|
41
|
+
double const *lower_bounds, double const *upper_bounds, unsigned long len_of_bounds);
|
|
42
|
+
|
|
43
|
+
/* release memory */
|
|
44
|
+
void cmaes_boundary_transformation_exit(cmaes_boundary_transformation_t *);
|
|
45
|
+
|
|
46
|
+
/* on return, y is guaranteed to have all values within the boundaries.
|
|
47
|
+
* The caller inputs x and is responsible for having allocated y in that
|
|
48
|
+
* y[len-1] = x[len-1] is a valid operation. x==y is valid input, but
|
|
49
|
+
* will fail together with cmaes when x is an element of the population
|
|
50
|
+
* returned by cmaes_SamplePopulation (these elements are of type
|
|
51
|
+
* double const * for a reason).
|
|
52
|
+
* */
|
|
53
|
+
void cmaes_boundary_transformation(cmaes_boundary_transformation_t *,
|
|
54
|
+
double const *x, double *y, unsigned long len); /* new value into y */
|
|
55
|
+
|
|
56
|
+
/* after
|
|
57
|
+
* cmaes_boundary_transformation(b,x,y,l) ;
|
|
58
|
+
* the two consecutive calls
|
|
59
|
+
* cmaes_boundary_transformation_inverse(b,y,x,l) ; cmaes_boundary_transformation(b,x,y,l) ;
|
|
60
|
+
* have no effect on y anymore (but they might change x!).
|
|
61
|
+
* */
|
|
62
|
+
void cmaes_boundary_transformation_inverse(cmaes_boundary_transformation_t *t,
|
|
63
|
+
double const *y, double *x, unsigned long len); /* new value into x */
|
|
64
|
+
|
|
65
|
+
/* used by function cmaes_boundary_transformation. After applying the shift,
|
|
66
|
+
* cmaes_boundary_transformation_shift_into_feasible_preimage(b,x,x,l)
|
|
67
|
+
* the two consecutive calls
|
|
68
|
+
* cmaes_boundary_transformation(b,x,y,l) ; cmaes_boundary_transformation_inverse(b,y,x,l) ;
|
|
69
|
+
* have no effect on x anymore */
|
|
70
|
+
void cmaes_boundary_transformation_shift_into_feasible_preimage(cmaes_boundary_transformation_t *t,
|
|
71
|
+
double const *x, double *x_shifted, unsigned long len); /* new value into x_shifted */
|
|
72
|
+
|
|
73
|
+
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/* --------------------------------------------------------- */
|
|
2
|
+
/* --- File: cmaes.h ----------- Author: Nikolaus Hansen --- */
|
|
3
|
+
/* ---------------------- last modified: IX 2010 --- */
|
|
4
|
+
/* --------------------------------- by: Nikolaus Hansen --- */
|
|
5
|
+
/* --------------------------------------------------------- */
|
|
6
|
+
/*
|
|
7
|
+
CMA-ES for non-linear function minimization.
|
|
8
|
+
|
|
9
|
+
Copyright (C) 1996, 2003-2010 Nikolaus Hansen.
|
|
10
|
+
e-mail: nikolaus.hansen (you know what) inria.fr
|
|
11
|
+
|
|
12
|
+
License: see file cmaes.c
|
|
13
|
+
|
|
14
|
+
*/
|
|
15
|
+
#ifndef NH_cmaes_h /* only include ones */
|
|
16
|
+
#define NH_cmaes_h
|
|
17
|
+
|
|
18
|
+
#include <time.h>
|
|
19
|
+
|
|
20
|
+
typedef struct
|
|
21
|
+
/* cmaes_random_t
|
|
22
|
+
* sets up a pseudo random number generator instance
|
|
23
|
+
*/
|
|
24
|
+
{
|
|
25
|
+
/* Variables for Uniform() */
|
|
26
|
+
long int startseed;
|
|
27
|
+
long int aktseed;
|
|
28
|
+
long int aktrand;
|
|
29
|
+
long int *rgrand;
|
|
30
|
+
|
|
31
|
+
/* Variables for Gauss() */
|
|
32
|
+
short flgstored;
|
|
33
|
+
double hold;
|
|
34
|
+
} cmaes_random_t;
|
|
35
|
+
|
|
36
|
+
typedef struct
|
|
37
|
+
/* cmaes_timings_t
|
|
38
|
+
* time measurement, used to time eigendecomposition
|
|
39
|
+
*/
|
|
40
|
+
{
|
|
41
|
+
/* for outside use */
|
|
42
|
+
double totaltime; /* zeroed by calling re-calling cmaes_timings_start */
|
|
43
|
+
double totaltotaltime;
|
|
44
|
+
double tictoctime;
|
|
45
|
+
double lasttictoctime;
|
|
46
|
+
|
|
47
|
+
/* local fields */
|
|
48
|
+
clock_t lastclock;
|
|
49
|
+
time_t lasttime;
|
|
50
|
+
clock_t ticclock;
|
|
51
|
+
time_t tictime;
|
|
52
|
+
short istic;
|
|
53
|
+
short isstarted;
|
|
54
|
+
|
|
55
|
+
double lastdiff;
|
|
56
|
+
double tictoczwischensumme;
|
|
57
|
+
} cmaes_timings_t;
|
|
58
|
+
|
|
59
|
+
typedef struct
|
|
60
|
+
/* cmaes_readpara_t
|
|
61
|
+
* collects all parameters, in particular those that are read from
|
|
62
|
+
* a file before to start. This should split in future?
|
|
63
|
+
*/
|
|
64
|
+
{
|
|
65
|
+
char * filename; /* keep record of the file that was taken to read parameters */
|
|
66
|
+
short flgsupplemented;
|
|
67
|
+
|
|
68
|
+
/* input parameters */
|
|
69
|
+
int N; /* problem dimension, must stay constant, should be unsigned or long? */
|
|
70
|
+
unsigned int seed;
|
|
71
|
+
double * xstart;
|
|
72
|
+
double * typicalX;
|
|
73
|
+
int typicalXcase;
|
|
74
|
+
double * rgInitialStds;
|
|
75
|
+
double * rgDiffMinChange;
|
|
76
|
+
|
|
77
|
+
/* termination parameters */
|
|
78
|
+
double stopMaxFunEvals;
|
|
79
|
+
double facmaxeval;
|
|
80
|
+
double stopMaxIter;
|
|
81
|
+
struct { int flg; double val; } stStopFitness;
|
|
82
|
+
double stopTolFun;
|
|
83
|
+
double stopTolFunHist;
|
|
84
|
+
double stopTolX;
|
|
85
|
+
double stopTolUpXFactor;
|
|
86
|
+
|
|
87
|
+
/* internal evolution strategy parameters */
|
|
88
|
+
int lambda; /* -> mu, <- N */
|
|
89
|
+
int mu; /* -> weights, (lambda) */
|
|
90
|
+
double mucov, mueff; /* <- weights */
|
|
91
|
+
double *weights; /* <- mu, -> mueff, mucov, ccov */
|
|
92
|
+
double damps; /* <- cs, maxeval, lambda */
|
|
93
|
+
double cs; /* -> damps, <- N */
|
|
94
|
+
double ccumcov; /* <- N */
|
|
95
|
+
double ccov; /* <- mucov, <- N */
|
|
96
|
+
double diagonalCov; /* number of initial iterations */
|
|
97
|
+
struct { int flgalways; double modulo; double maxtime; } updateCmode;
|
|
98
|
+
double facupdateCmode;
|
|
99
|
+
|
|
100
|
+
/* supplementary variables */
|
|
101
|
+
|
|
102
|
+
char *weigkey;
|
|
103
|
+
char resumefile[99];
|
|
104
|
+
const char **rgsformat;
|
|
105
|
+
void **rgpadr;
|
|
106
|
+
const char **rgskeyar;
|
|
107
|
+
double ***rgp2adr;
|
|
108
|
+
int n1para, n1outpara;
|
|
109
|
+
int n2para;
|
|
110
|
+
} cmaes_readpara_t;
|
|
111
|
+
|
|
112
|
+
typedef struct
|
|
113
|
+
/* cmaes_t
|
|
114
|
+
* CMA-ES "object"
|
|
115
|
+
*/
|
|
116
|
+
{
|
|
117
|
+
const char *version;
|
|
118
|
+
/* char *signalsFilename; */
|
|
119
|
+
cmaes_readpara_t sp;
|
|
120
|
+
cmaes_random_t rand; /* random number generator */
|
|
121
|
+
|
|
122
|
+
double sigma; /* step size */
|
|
123
|
+
|
|
124
|
+
double *rgxmean; /* mean x vector, "parent" */
|
|
125
|
+
double *rgxbestever;
|
|
126
|
+
double **rgrgx; /* range of x-vectors, lambda offspring */
|
|
127
|
+
int *index; /* sorting index of sample pop. */
|
|
128
|
+
double *arFuncValueHist;
|
|
129
|
+
|
|
130
|
+
short flgIniphase; /* not really in use anymore */
|
|
131
|
+
short flgStop;
|
|
132
|
+
|
|
133
|
+
double chiN;
|
|
134
|
+
double **C; /* lower triangular matrix: i>=j for C[i][j] */
|
|
135
|
+
double **B; /* matrix with normalize eigenvectors in columns */
|
|
136
|
+
double *rgD; /* axis lengths */
|
|
137
|
+
|
|
138
|
+
double *rgpc;
|
|
139
|
+
double *rgps;
|
|
140
|
+
double *rgxold;
|
|
141
|
+
double *rgout;
|
|
142
|
+
double *rgBDz; /* for B*D*z */
|
|
143
|
+
double *rgdTmp; /* temporary (random) vector used in different places */
|
|
144
|
+
double *rgFuncValue;
|
|
145
|
+
double *publicFitness; /* returned by cmaes_init() */
|
|
146
|
+
|
|
147
|
+
double gen; /* Generation number */
|
|
148
|
+
double countevals;
|
|
149
|
+
double state; /* 1 == sampled, 2 == not in use anymore, 3 == updated */
|
|
150
|
+
|
|
151
|
+
double maxdiagC; /* repeatedly used for output */
|
|
152
|
+
double mindiagC;
|
|
153
|
+
double maxEW;
|
|
154
|
+
double minEW;
|
|
155
|
+
|
|
156
|
+
char sOutString[330]; /* 4x80 */
|
|
157
|
+
|
|
158
|
+
short flgEigensysIsUptodate;
|
|
159
|
+
short flgCheckEigen; /* control via cmaes_signals.par */
|
|
160
|
+
double genOfEigensysUpdate;
|
|
161
|
+
cmaes_timings_t eigenTimings;
|
|
162
|
+
|
|
163
|
+
double dMaxSignifKond;
|
|
164
|
+
double dLastMinEWgroesserNull;
|
|
165
|
+
|
|
166
|
+
short flgresumedone;
|
|
167
|
+
|
|
168
|
+
time_t printtime;
|
|
169
|
+
time_t writetime; /* ideally should keep track for each output file */
|
|
170
|
+
time_t firstwritetime;
|
|
171
|
+
time_t firstprinttime;
|
|
172
|
+
|
|
173
|
+
} cmaes_t;
|
|
174
|
+
|
|
175
|
+
#endif
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* --------------------------------------------------------- */
|
|
2
|
+
/* --- File: cmaes_interface.h - Author: Nikolaus Hansen --- */
|
|
3
|
+
/* ---------------------- last modified: IV 2007 --- */
|
|
4
|
+
/* --------------------------------- by: Nikolaus Hansen --- */
|
|
5
|
+
/* --------------------------------------------------------- */
|
|
6
|
+
/*
|
|
7
|
+
CMA-ES for non-linear function minimization.
|
|
8
|
+
|
|
9
|
+
Copyright (C) 1996, 2003, 2007 Nikolaus Hansen.
|
|
10
|
+
e-mail: hansen AT lri.fr
|
|
11
|
+
|
|
12
|
+
Documentation: see file docfunctions.txt
|
|
13
|
+
|
|
14
|
+
License: see file cmaes.c
|
|
15
|
+
*/
|
|
16
|
+
#include "cmaes.h"
|
|
17
|
+
|
|
18
|
+
/* --------------------------------------------------------- */
|
|
19
|
+
/* ------------------ Interface ---------------------------- */
|
|
20
|
+
/* --------------------------------------------------------- */
|
|
21
|
+
|
|
22
|
+
#ifdef __cplusplus
|
|
23
|
+
extern "C" {
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
/* --- initialization, constructors, destructors --- */
|
|
27
|
+
double * cmaes_init(cmaes_t *, int dimension , double *xstart,
|
|
28
|
+
double *stddev, long seed, int lambda,
|
|
29
|
+
const char *input_parameter_filename);
|
|
30
|
+
void cmaes_init_para(cmaes_t *, int dimension , double *xstart,
|
|
31
|
+
double *stddev, long seed, int lambda,
|
|
32
|
+
const char *input_parameter_filename);
|
|
33
|
+
double * cmaes_init_final(cmaes_t *);
|
|
34
|
+
void cmaes_resume_distribution(cmaes_t *evo_ptr, char *filename);
|
|
35
|
+
void cmaes_exit(cmaes_t *);
|
|
36
|
+
|
|
37
|
+
/* --- core functions --- */
|
|
38
|
+
double * const * cmaes_SamplePopulation(cmaes_t *);
|
|
39
|
+
double * cmaes_UpdateDistribution(cmaes_t *,
|
|
40
|
+
const double *rgFitnessValues);
|
|
41
|
+
const char * cmaes_TestForTermination(cmaes_t *);
|
|
42
|
+
|
|
43
|
+
/* --- additional functions --- */
|
|
44
|
+
double * const * cmaes_ReSampleSingle( cmaes_t *t, int index);
|
|
45
|
+
double const * cmaes_ReSampleSingle_old(cmaes_t *, double *rgx);
|
|
46
|
+
double * cmaes_SampleSingleInto( cmaes_t *t, double *rgx);
|
|
47
|
+
void cmaes_UpdateEigensystem(cmaes_t *, int flgforce);
|
|
48
|
+
|
|
49
|
+
/* --- getter functions --- */
|
|
50
|
+
double cmaes_Get(cmaes_t *, char const *keyword);
|
|
51
|
+
const double * cmaes_GetPtr(cmaes_t *, char const *keyword); /* e.g. "xbestever" */
|
|
52
|
+
double * cmaes_GetNew( cmaes_t *t, char const *keyword); /* user is responsible to free */
|
|
53
|
+
double * cmaes_GetInto( cmaes_t *t, char const *keyword, double *mem); /* allocs if mem==NULL, user is responsible to free */
|
|
54
|
+
|
|
55
|
+
/* --- online control and output --- */
|
|
56
|
+
void cmaes_ReadSignals(cmaes_t *, char const *filename);
|
|
57
|
+
void cmaes_WriteToFile(cmaes_t *, const char *szKeyWord,
|
|
58
|
+
const char *output_filename);
|
|
59
|
+
char * cmaes_SayHello(cmaes_t *);
|
|
60
|
+
/* --- misc --- */
|
|
61
|
+
double * cmaes_NewDouble(int n); /* user is responsible to free */
|
|
62
|
+
void cmaes_FATAL(char const *s1, char const *s2, char const *s3,
|
|
63
|
+
char const *s4);
|
|
64
|
+
|
|
65
|
+
#ifdef __cplusplus
|
|
66
|
+
} // end extern "C"
|
|
67
|
+
#endif
|
|
68
|
+
|
|
@@ -8,8 +8,10 @@
|
|
|
8
8
|
|
|
9
9
|
#pragma once
|
|
10
10
|
|
|
11
|
-
#include "
|
|
12
|
-
#include "
|
|
11
|
+
#include "m_Newton.h"
|
|
12
|
+
#include "m_Gradient.h"
|
|
13
|
+
|
|
14
|
+
namespace rai {
|
|
13
15
|
|
|
14
16
|
struct GlobalIterativeNewton {
|
|
15
17
|
arr x;
|
|
@@ -21,7 +23,7 @@ struct GlobalIterativeNewton {
|
|
|
21
23
|
rai::Array<LocalMinimum> localMinima;
|
|
22
24
|
LocalMinimum* best;
|
|
23
25
|
|
|
24
|
-
GlobalIterativeNewton(ScalarFunction
|
|
26
|
+
GlobalIterativeNewton(ScalarFunction f, const arr& bounds, std::shared_ptr<OptOptions> opt=make_shared<OptOptions>());
|
|
25
27
|
~GlobalIterativeNewton();
|
|
26
28
|
|
|
27
29
|
void step();
|
|
@@ -30,3 +32,5 @@ struct GlobalIterativeNewton {
|
|
|
30
32
|
|
|
31
33
|
void reOptimizeAllPoints();
|
|
32
34
|
};
|
|
35
|
+
|
|
36
|
+
} //namespace
|
robotic/include/rai/Optim/NLP.h
CHANGED
|
@@ -62,7 +62,8 @@ struct NLP : rai::NonCopyable {
|
|
|
62
62
|
|
|
63
63
|
//-- utilities
|
|
64
64
|
shared_ptr<NLP> ptr() { return shared_ptr<NLP>(this, [](NLP*) {}); }
|
|
65
|
-
double eval_scalar(arr& g, arr& H, const arr& x);
|
|
65
|
+
virtual double eval_scalar(arr& g, arr& H, const arr& x);
|
|
66
|
+
ScalarFunction f_scalar(){ return [this](arr& g, arr& H, const arr& x){ return this->eval_scalar(g, H, x); }; }
|
|
66
67
|
bool checkJacobian(const arr& x, double tolerance, const StringA& featureNames= {});
|
|
67
68
|
bool checkHessian(const arr& x, double tolerance);
|
|
68
69
|
bool checkBounds(bool strictlyLarger);
|
|
@@ -80,6 +81,19 @@ struct NLP : rai::NonCopyable {
|
|
|
80
81
|
|
|
81
82
|
//===========================================================================
|
|
82
83
|
|
|
84
|
+
struct NLP_Scalar : NLP {
|
|
85
|
+
arr x, H_x;
|
|
86
|
+
NLP_Scalar() { featureTypes.resize(1) = OT_f; }
|
|
87
|
+
virtual double f(arr& g, arr& H, const arr& x) = 0;
|
|
88
|
+
void evaluate(arr& phi, arr& J, const arr& _x){
|
|
89
|
+
x = _x;
|
|
90
|
+
double f_x = f(J, H_x, x);
|
|
91
|
+
phi.resize(1) = f_x;
|
|
92
|
+
if(!!J) J.reshape(1, x.N);
|
|
93
|
+
}
|
|
94
|
+
void getFHessian(arr& H, const arr& _x) { CHECK_EQ(_x, x, ""); H = H_x; }
|
|
95
|
+
};
|
|
96
|
+
|
|
83
97
|
struct NLP_Factored : NLP {
|
|
84
98
|
//-- problem factorization: needs to be defined in the constructor or a derived class
|
|
85
99
|
uintA variableDimensions; //the size of each variable block
|