Add support for bounds to ParameterBlock.

Add setters and getters for lower and upper bounds.
Generalize the Plus operation to include projection onto the
hypercube implied by the bounds.

Change-Id: I1e4028a9886c4064f31bbc5b7c22b0341a56c15d
This commit is contained in:
Sameer Agarwal
2014-02-18 15:58:59 -08:00
parent 978d931ba8
commit 5cf867be49
2 changed files with 85 additions and 5 deletions
+37
View File
@@ -169,5 +169,42 @@ TEST(ParameterBlock, DetectBadLocalParameterization) {
EXPECT_FALSE(parameter_block.SetState(&y));
}
TEST(ParameterBlock, DefaultBounds) {
double x[2];
ParameterBlock parameter_block(x, 2, -1, NULL);
const double* upper_bounds = parameter_block.upper_bounds();
EXPECT_EQ(upper_bounds[0], std::numeric_limits<double>::max());
EXPECT_EQ(upper_bounds[1], std::numeric_limits<double>::max());
const double* lower_bounds = parameter_block.lower_bounds();
EXPECT_EQ(lower_bounds[0], -std::numeric_limits<double>::max());
EXPECT_EQ(lower_bounds[1], -std::numeric_limits<double>::max());
}
TEST(ParameterBlock, SetBounds) {
double x[2];
ParameterBlock parameter_block(x, 2, -1, NULL);
parameter_block.SetUpperBound(1, 1);
parameter_block.SetLowerBound(0, 1);
const double* upper_bounds = parameter_block.upper_bounds();
EXPECT_EQ(upper_bounds[0], std::numeric_limits<double>::max());
EXPECT_EQ(upper_bounds[1], 1.0);
const double* lower_bounds = parameter_block.lower_bounds();
EXPECT_EQ(lower_bounds[0], 1.0);
EXPECT_EQ(lower_bounds[1], -std::numeric_limits<double>::max());
}
TEST(ParameterBlock, PlusWithBoundsConstraints) {
double x[] = {1.0, 0.0};
double delta[] = {2.0, -10.0};
ParameterBlock parameter_block(x, 2, -1, NULL);
parameter_block.SetUpperBound(0, 2.0);
parameter_block.SetLowerBound(1, -1.0);
double x_plus_delta[2];
parameter_block.Plus(x, delta, x_plus_delta);
EXPECT_EQ(x_plus_delta[0], 2.0);
EXPECT_EQ(x_plus_delta[1], -1.0);
}
} // namespace internal
} // namespace ceres