diff options
author | Carlos Hernandez <chernand@google.com> | 2014-08-07 17:51:38 -0700 |
---|---|---|
committer | Carlos Hernandez <chernand@google.com> | 2014-08-11 20:38:34 +0000 |
commit | 79397c21138f54fcff6ec067b44b847f1f7e0e98 (patch) | |
tree | b2c33877af479b37f082fcbcaf50a24a49b69415 /internal/ceres/parameter_block.h | |
parent | ad78e589f893a53da23bbdf41274d89dae656f54 (diff) | |
download | ceres-solver-android-cts-5.1_r21.tar.gz |
Update ceres to the latest version in g3android-wear-5.0.0_r1android-cts-5.1_r9android-cts-5.1_r8android-cts-5.1_r7android-cts-5.1_r6android-cts-5.1_r5android-cts-5.1_r4android-cts-5.1_r3android-cts-5.1_r28android-cts-5.1_r27android-cts-5.1_r26android-cts-5.1_r25android-cts-5.1_r24android-cts-5.1_r23android-cts-5.1_r22android-cts-5.1_r21android-cts-5.1_r20android-cts-5.1_r2android-cts-5.1_r19android-cts-5.1_r18android-cts-5.1_r17android-cts-5.1_r16android-cts-5.1_r15android-cts-5.1_r14android-cts-5.1_r13android-cts-5.1_r10android-cts-5.1_r1android-cts-5.0_r9android-cts-5.0_r8android-cts-5.0_r7android-cts-5.0_r6android-cts-5.0_r5android-cts-5.0_r4android-cts-5.0_r3android-5.1.1_r9android-5.1.1_r8android-5.1.1_r7android-5.1.1_r6android-5.1.1_r5android-5.1.1_r4android-5.1.1_r38android-5.1.1_r37android-5.1.1_r36android-5.1.1_r35android-5.1.1_r34android-5.1.1_r33android-5.1.1_r30android-5.1.1_r3android-5.1.1_r29android-5.1.1_r28android-5.1.1_r26android-5.1.1_r25android-5.1.1_r24android-5.1.1_r23android-5.1.1_r22android-5.1.1_r20android-5.1.1_r2android-5.1.1_r19android-5.1.1_r18android-5.1.1_r17android-5.1.1_r16android-5.1.1_r15android-5.1.1_r14android-5.1.1_r13android-5.1.1_r12android-5.1.1_r10android-5.1.1_r1android-5.1.0_r5android-5.1.0_r4android-5.1.0_r3android-5.1.0_r1android-5.0.2_r3android-5.0.2_r1android-5.0.1_r1android-5.0.0_r7android-5.0.0_r6android-5.0.0_r5.1android-5.0.0_r5android-5.0.0_r4android-5.0.0_r3android-5.0.0_r2android-5.0.0_r1lollipop-wear-releaselollipop-releaselollipop-mr1-wfc-releaselollipop-mr1-releaselollipop-mr1-fi-releaselollipop-mr1-devlollipop-mr1-cts-releaselollipop-devlollipop-cts-release
Please pay special attention to the changes in Android.mk.
They are the only real changes I had to make.
Bug: 16953678
Change-Id: I44a644358e779aaff99a2ea822387fe49ac26888
Diffstat (limited to 'internal/ceres/parameter_block.h')
-rw-r--r-- | internal/ceres/parameter_block.h | 85 |
1 files changed, 80 insertions, 5 deletions
diff --git a/internal/ceres/parameter_block.h b/internal/ceres/parameter_block.h index 695fa6f..7bc823d 100644 --- a/internal/ceres/parameter_block.h +++ b/internal/ceres/parameter_block.h @@ -31,7 +31,9 @@ #ifndef CERES_INTERNAL_PARAMETER_BLOCK_H_ #define CERES_INTERNAL_PARAMETER_BLOCK_H_ +#include <algorithm> #include <cstdlib> +#include <limits> #include <string> #include "ceres/array_utils.h" #include "ceres/collections_port.h" @@ -180,16 +182,59 @@ class ParameterBlock { } } + void SetUpperBound(int index, double upper_bound) { + CHECK_LT(index, size_); + + if (upper_bounds_.get() == NULL) { + upper_bounds_.reset(new double[size_]); + std::fill(upper_bounds_.get(), + upper_bounds_.get() + size_, + std::numeric_limits<double>::max()); + } + + upper_bounds_[index] = upper_bound; + }; + + void SetLowerBound(int index, double lower_bound) { + CHECK_LT(index, size_); + + if (lower_bounds_.get() == NULL) { + lower_bounds_.reset(new double[size_]); + std::fill(lower_bounds_.get(), + lower_bounds_.get() + size_, + -std::numeric_limits<double>::max()); + } + + lower_bounds_[index] = lower_bound; + } + // Generalization of the addition operation. This is the same as - // LocalParameterization::Plus() but uses the parameter's current state - // instead of operating on a passed in pointer. + // LocalParameterization::Plus() followed by projection onto the + // hyper cube implied by the bounds constraints. bool Plus(const double *x, const double* delta, double* x_plus_delta) { - if (local_parameterization_ == NULL) { + if (local_parameterization_ != NULL) { + if (!local_parameterization_->Plus(x, delta, x_plus_delta)) { + return false; + } + } else { VectorRef(x_plus_delta, size_) = ConstVectorRef(x, size_) + ConstVectorRef(delta, size_); - return true; } - return local_parameterization_->Plus(x, delta, x_plus_delta); + + // Project onto the box constraints. + if (lower_bounds_.get() != NULL) { + for (int i = 0; i < size_; ++i) { + x_plus_delta[i] = std::max(x_plus_delta[i], lower_bounds_[i]); + } + } + + if (upper_bounds_.get() != NULL) { + for (int i = 0; i < size_; ++i) { + x_plus_delta[i] = std::min(x_plus_delta[i], upper_bounds_[i]); + } + } + + return true; } string ToString() const { @@ -234,6 +279,22 @@ class ParameterBlock { return residual_blocks_.get(); } + double LowerBoundForParameter(int index) const { + if (lower_bounds_.get() == NULL) { + return -std::numeric_limits<double>::max(); + } else { + return lower_bounds_[index]; + } + } + + double UpperBoundForParameter(int index) const { + if (upper_bounds_.get() == NULL) { + return std::numeric_limits<double>::max(); + } else { + return upper_bounds_[index]; + } + } + private: void Init(double* user_state, int size, @@ -312,6 +373,20 @@ class ParameterBlock { // If non-null, contains the residual blocks this parameter block is in. scoped_ptr<ResidualBlockSet> residual_blocks_; + // Upper and lower bounds for the parameter block. SetUpperBound + // and SetLowerBound lazily initialize the upper_bounds_ and + // lower_bounds_ arrays. If they are never called, then memory for + // these arrays is never allocated. Thus for problems where there + // are no bounds, or only one sided bounds we do not pay the cost of + // allocating memory for the inactive bounds constraints. + // + // Upon initialization these arrays are initialized to + // std::numeric_limits<double>::max() and + // -std::numeric_limits<double>::max() respectively which correspond + // to the parameter block being unconstrained. + scoped_array<double> upper_bounds_; + scoped_array<double> lower_bounds_; + // Necessary so ProblemImpl can clean up the parameterizations. friend class ProblemImpl; }; |