From e2bc13a2a6a3b8e13b245b609f8ca7e0c4632cb1 Mon Sep 17 00:00:00 2001 From: Alex Cunningham Date: Fri, 18 Dec 2009 03:05:47 +0000 Subject: [PATCH] Renaming gradients -> jacobians --- cpp/NonlinearConstraint-inl.h | 22 ++++++++--------- cpp/NonlinearConstraint.h | 34 +++++++++++++------------- cpp/testNonlinearConstraint.cpp | 14 +++++------ cpp/testSQP.cpp | 10 ++++---- cpp/testSQPOptimizer.cpp | 42 ++++++++++++++++----------------- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/cpp/NonlinearConstraint-inl.h b/cpp/NonlinearConstraint-inl.h index 046b808e3..60fd59540 100644 --- a/cpp/NonlinearConstraint-inl.h +++ b/cpp/NonlinearConstraint-inl.h @@ -55,7 +55,7 @@ NonlinearConstraint1::NonlinearConstraint1( const std::string& lagrange_key, bool isEquality) : NonlinearConstraint(lagrange_key, dim_constraint, g, isEquality), - gradG_(boost::bind(gradG, _1)), key_(key) + G_(boost::bind(gradG, _1)), key_(key) { // set a good lagrange key here // TODO:should do something smart to find a unique one @@ -74,7 +74,7 @@ NonlinearConstraint1::NonlinearConstraint1( const std::string& lagrange_key, bool isEquality) : NonlinearConstraint(lagrange_key, dim_constraint, g, isEquality), - gradG_(gradG), key_(key) + G_(gradG), key_(key) { // set a good lagrange key here // TODO:should do something smart to find a unique one @@ -118,7 +118,7 @@ NonlinearConstraint1::linearize(const Config& config, const VectorConfig Vector g = g_(config); // construct the gradient - Matrix grad = gradG_(config); + Matrix grad = G_(config); // construct probabilistic factor Matrix A1 = vector_scale(lambda, grad); @@ -140,14 +140,14 @@ template NonlinearConstraint2::NonlinearConstraint2( Vector (*g)(const Config& config), const std::string& key1, - Matrix (*gradG1)(const Config& config), + Matrix (*G1)(const Config& config), const std::string& key2, - Matrix (*gradG2)(const Config& config), + Matrix (*G2)(const Config& config), size_t dim_constraint, const std::string& lagrange_key, bool isEquality) : NonlinearConstraint(lagrange_key, dim_constraint, g, isEquality), - gradG1_(boost::bind(gradG1, _1)), gradG2_(boost::bind(gradG2, _1)), + G1_(boost::bind(G1, _1)), G2_(boost::bind(G2, _1)), key1_(key1), key2_(key2) { // set a good lagrange key here @@ -163,14 +163,14 @@ template NonlinearConstraint2::NonlinearConstraint2( boost::function g, const std::string& key1, - boost::function gradG1, + boost::function G1, const std::string& key2, - boost::function gradG2, + boost::function G2, size_t dim_constraint, const std::string& lagrange_key, bool isEquality) : NonlinearConstraint(lagrange_key, dim_constraint, g, isEquality), - gradG1_(gradG1), gradG2_(gradG2), + G1_(G1), G2_(G2), key1_(key1), key2_(key2) { // set a good lagrange key here @@ -214,8 +214,8 @@ std::pair NonlinearConst Vector g = g_(config); // construct the gradients - Matrix grad1 = gradG1_(config); - Matrix grad2 = gradG2_(config); + Matrix grad1 = G1_(config); + Matrix grad2 = G2_(config); // construct probabilistic factor Matrix A1 = vector_scale(lambda, grad1); diff --git a/cpp/NonlinearConstraint.h b/cpp/NonlinearConstraint.h index 65ca74502..294fd1a04 100644 --- a/cpp/NonlinearConstraint.h +++ b/cpp/NonlinearConstraint.h @@ -115,7 +115,7 @@ public: /** - * A unary constraint with arbitrary cost and gradient functions + * A unary constraint with arbitrary cost and jacobian functions */ template class NonlinearConstraint1 : public NonlinearConstraint { @@ -123,13 +123,13 @@ class NonlinearConstraint1 : public NonlinearConstraint { private: /** - * Calculates the gradient of the constraint function + * Calculates the jacobian of the constraint function * returns a pxn matrix * Use boost.bind to create the function object * @param config to use for linearization * @return the jacobian of the constraint in terms of key */ - boost::function gradG_; + boost::function G_; /** key for the constrained variable */ std::string key_; @@ -139,7 +139,7 @@ public: /** * Basic constructor * @param key is the identifier for the variable constrained - * @param gradG gives the gradient of the constraint function + * @param G gives the jacobian of the constraint function * @param g is the constraint function * @param dim_constraint is the size of the constraint (p) * @param lagrange_key is the identifier for the lagrange multiplier @@ -148,7 +148,7 @@ public: NonlinearConstraint1( Vector (*g)(const Config& config), const std::string& key, - Matrix (*gradG)(const Config& config), + Matrix (*G)(const Config& config), size_t dim_constraint, const std::string& lagrange_key="", bool isEquality=true); @@ -156,7 +156,7 @@ public: /** * Basic constructor with boost function pointers * @param key is the identifier for the variable constrained - * @param gradG gives the gradient of the constraint function + * @param G gives the jacobian of the constraint function * @param g is the constraint function as a boost function pointer * @param dim_constraint is the size of the constraint (p) * @param lagrange_key is the identifier for the lagrange multiplier @@ -165,7 +165,7 @@ public: NonlinearConstraint1( boost::function g, const std::string& key, - boost::function gradG, + boost::function G, size_t dim_constraint, const std::string& lagrange_key="", bool isEquality=true); @@ -188,7 +188,7 @@ public: }; /** - * A binary constraint with arbitrary cost and gradient functions + * A binary constraint with arbitrary cost and jacobian functions */ template class NonlinearConstraint2 : public NonlinearConstraint { @@ -196,14 +196,14 @@ class NonlinearConstraint2 : public NonlinearConstraint { private: /** - * Calculates the gradients of the constraint function in terms of + * Calculates the jacobians of the constraint function in terms of * the first and second variables * returns a pxn matrix * @param config to use for linearization * @return the jacobian of the constraint in terms of key */ - boost::function gradG1_; - boost::function gradG2_; + boost::function G1_; + boost::function G2_; /** keys for the constrained variables */ std::string key1_; @@ -214,7 +214,7 @@ public: /** * Basic constructor * @param key is the identifier for the variable constrained - * @param gradG gives the gradient of the constraint function + * @param G gives the jacobian of the constraint function * @param g is the constraint function * @param dim_constraint is the size of the constraint (p) * @param lagrange_key is the identifier for the lagrange multiplier @@ -223,9 +223,9 @@ public: NonlinearConstraint2( Vector (*g)(const Config& config), const std::string& key1, - Matrix (*gradG1)(const Config& config), + Matrix (*G1)(const Config& config), const std::string& key2, - Matrix (*gradG2)(const Config& config), + Matrix (*G2)(const Config& config), size_t dim_constraint, const std::string& lagrange_key="", bool isEquality=true); @@ -234,7 +234,7 @@ public: * Basic constructor with direct function objects * Use boost.bind to construct the function objects * @param key is the identifier for the variable constrained - * @param gradG gives the gradient of the constraint function + * @param G gives the jacobian of the constraint function * @param g is the constraint function * @param dim_constraint is the size of the constraint (p) * @param lagrange_key is the identifier for the lagrange multiplier @@ -243,9 +243,9 @@ public: NonlinearConstraint2( boost::function g, const std::string& key1, - boost::function gradG1, + boost::function G1, const std::string& key2, - boost::function gradG2, + boost::function G2, size_t dim_constraint, const std::string& lagrange_key="", bool isEquality=true); diff --git a/cpp/testNonlinearConstraint.cpp b/cpp/testNonlinearConstraint.cpp index 387b91924..afa636c3e 100644 --- a/cpp/testNonlinearConstraint.cpp +++ b/cpp/testNonlinearConstraint.cpp @@ -27,7 +27,7 @@ namespace test1 { return Vector_(1, x * x - 5); } - /** p = 1, gradG(x) = 2x */ + /** p = 1, jacobianG(x) = 2x */ Matrix G(const VectorConfig& config, const list& keys) { double x = config[keys.front()](0); return Matrix_(1, 1, 2 * x); @@ -110,13 +110,13 @@ namespace test2 { return Vector_(1, x * x - 5.0 - y); } - /** gradient for x, gradG(x,y) in x: 2x*/ + /** jacobian for x, jacobianG(x,y) in x: 2x*/ Matrix G1(const VectorConfig& config, const list& keys) { double x = config[keys.front()](0); return Matrix_(1, 1, 2.0 * x); } - /** gradient for y, gradG(x,y) in y: -1 */ + /** jacobian for y, jacobianG(x,y) in y: -1 */ Matrix G2(const VectorConfig& config, const list& keys) { double x = config[keys.back()](0); return Matrix_(1, 1, -1.0); @@ -211,7 +211,7 @@ namespace inequality1 { return Vector_(1, g); // return the actual cost } - /** p = 1, gradG(x) = 2*x */ + /** p = 1, jacobianG(x) = 2*x */ Matrix G(const VectorConfig& config, const list& keys) { double x = config[keys.front()](0); return Matrix_(1, 1, 2 * x); @@ -289,7 +289,7 @@ namespace binding1 { return Vector_(1, g); // return the actual cost } - /** p = 1, gradG(x) = 2*x */ + /** p = 1, jacobianG(x) = 2*x */ Matrix G(double coeff, const VectorConfig& config, const list& keys) { double x = config[keys.front()](0); @@ -332,13 +332,13 @@ namespace binding2 { return Vector_(1, x * x - r - y); } - /** gradient for x, gradG(x,y) in x: 2x*/ + /** jacobian for x, jacobianG(x,y) in x: 2x*/ Matrix G1(double c, const VectorConfig& config, const list& keys) { double x = config[keys.front()](0); return Matrix_(1, 1, c * x); } - /** gradient for y, gradG(x,y) in y: -1 */ + /** jacobian for y, jacobianG(x,y) in y: -1 */ Matrix G2(double c, const VectorConfig& config, const list& keys) { double x = config[keys.back()](0); return Matrix_(1, 1, -1.0 * c); diff --git a/cpp/testSQP.cpp b/cpp/testSQP.cpp index 9b8d3968a..8e6fcc671 100644 --- a/cpp/testSQP.cpp +++ b/cpp/testSQP.cpp @@ -324,12 +324,12 @@ namespace sqp_test1 { return config[keys.front()] - config[keys.back()]; } - /** gradient at l1 */ + /** jacobian at l1 */ Matrix G1(const VectorConfig& config, const list& keys) { return eye(2); } - /** gradient at l2 */ + /** jacobian at l2 */ Matrix G2(const VectorConfig& config, const list& keys) { return -1 * eye(2); } @@ -344,7 +344,7 @@ namespace sqp_test2 { return config[keys.front()] - Vector_(2, 1.0, 1.0); } - /** gradient at x1 */ + /** jacobian at x1 */ Matrix G(const VectorConfig& config, const list& keys) { return eye(2); } @@ -633,12 +633,12 @@ namespace sqp_stereo { - config.landmarkPoint(getNum(keys.back())).vector(); } - /** gradient at l1 */ + /** jacobian at l1 */ Matrix G1(const VSLAMConfig& config, const list& keys) { return eye(3); } - /** gradient at l2 */ + /** jacobian at l2 */ Matrix G2(const VSLAMConfig& config, const list& keys) { return -1.0 * eye(3); } diff --git a/cpp/testSQPOptimizer.cpp b/cpp/testSQPOptimizer.cpp index 66cdd9367..7d55e732e 100644 --- a/cpp/testSQPOptimizer.cpp +++ b/cpp/testSQPOptimizer.cpp @@ -60,13 +60,13 @@ Vector g_func(const VectorConfig& config, const list& keys) { return config[keys.front()]-config[keys.back()]; } -/** gradient at l1 */ -Matrix grad_g1(const VectorConfig& config, const list& keys) { +/** jacobian at l1 */ +Matrix jac_g1(const VectorConfig& config, const list& keys) { return eye(2); } -/** gradient at l2 */ -Matrix grad_g2(const VectorConfig& config, const list& keys) { +/** jacobian at l2 */ +Matrix jac_g2(const VectorConfig& config, const list& keys) { return -1*eye(2); } } // \namespace sqp_LinearMapWarp2 @@ -78,8 +78,8 @@ Vector g_func(const VectorConfig& config, const list& keys) { return config[keys.front()]-Vector_(2, 1.0, 1.0); } -/** gradient at x1 */ -Matrix grad_g(const VectorConfig& config, const list& keys) { +/** jacobian at x1 */ +Matrix jac_g(const VectorConfig& config, const list& keys) { return eye(2); } } // \namespace sqp_LinearMapWarp12 @@ -96,7 +96,7 @@ NLGraph linearMapWarpGraph() { boost::shared_ptr > c1( new NonlinearConstraint1( boost::bind(sqp_LinearMapWarp1::g_func, _1, keyx), - "x1", boost::bind(sqp_LinearMapWarp1::grad_g, _1, keyx), + "x1", boost::bind(sqp_LinearMapWarp1::jac_g, _1, keyx), 2, "L_x1")); // measurement from x1 to l1 @@ -114,8 +114,8 @@ NLGraph linearMapWarpGraph() { boost::shared_ptr > c2( new NonlinearConstraint2( boost::bind(sqp_LinearMapWarp2::g_func, _1, keys), - "l1", boost::bind(sqp_LinearMapWarp2::grad_g1, _1, keys), - "l2", boost::bind(sqp_LinearMapWarp2::grad_g2, _1, keys), + "l1", boost::bind(sqp_LinearMapWarp2::jac_g1, _1, keys), + "l2", boost::bind(sqp_LinearMapWarp2::jac_g2, _1, keys), 2, "L_l1l2")); // construct the graph @@ -237,15 +237,15 @@ Vector g_func(const VectorConfig& config, const list& keys) { return Vector_(1, dist2-thresh); } -/** gradient at pose */ -Matrix grad_g1(const VectorConfig& config, const list& keys) { +/** jacobian at pose */ +Matrix jac_g1(const VectorConfig& config, const list& keys) { Vector x2 = config[keys.front()], obs = config[keys.back()]; Vector grad = 2.0*(x2-obs); return Matrix_(1,2, grad(0), grad(1)); } -/** gradient at obstacle */ -Matrix grad_g2(const VectorConfig& config, const list& keys) { +/** jacobian at obstacle */ +Matrix jac_g2(const VectorConfig& config, const list& keys) { Vector x2 = config[keys.front()], obs = config[keys.back()]; Vector grad = -2.0*(x2-obs); return Matrix_(1,2, grad(0), grad(1)); @@ -276,8 +276,8 @@ pair obstacleAvoidGraph() { // the obstacle list keys; keys += "x2", "obs"; shared_NLC2 c1(new NLC2(boost::bind(sqp_avoid1::g_func, _1, keys), - "x2", boost::bind(sqp_avoid1::grad_g1, _1, keys), - "obs",boost::bind(sqp_avoid1::grad_g2, _1, keys), + "x2", boost::bind(sqp_avoid1::jac_g1, _1, keys), + "obs",boost::bind(sqp_avoid1::jac_g2, _1, keys), 1, "L_x2obs", false)); // construct the graph @@ -367,15 +367,15 @@ Vector g_func(double radius, const VectorConfig& config, const list& key return Vector_(1, dist2-thresh); } -/** gradient at pose */ -Matrix grad_g1(const VectorConfig& config, const list& keys) { +/** jacobian at pose */ +Matrix jac_g1(const VectorConfig& config, const list& keys) { Vector x2 = config[keys.front()], obs = config[keys.back()]; Vector grad = 2.0*(x2-obs); return Matrix_(1,2, grad(0), grad(1)); } -/** gradient at obstacle */ -Matrix grad_g2(const VectorConfig& config, const list& keys) { +/** jacobian at obstacle */ +Matrix jac_g2(const VectorConfig& config, const list& keys) { Vector x2 = config[keys.front()], obs = config[keys.back()]; Vector grad = -2.0*(x2-obs); return Matrix_(1,2, grad(0), grad(1)); @@ -408,8 +408,8 @@ pair obstacleAvoidGraphGeneral() { // the obstacle list keys; keys += "x2", "obs"; shared_NLC2 c1(new NLC2(boost::bind(sqp_avoid2::g_func, radius, _1, keys), - "x2", boost::bind(sqp_avoid2::grad_g1, _1, keys), - "obs", boost::bind(sqp_avoid2::grad_g2, _1, keys), + "x2", boost::bind(sqp_avoid2::jac_g1, _1, keys), + "obs", boost::bind(sqp_avoid2::jac_g2, _1, keys), 1, "L_x2obs", false)); // construct the graph