Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
Sameer Agarwal | 5a30cae | 2023-09-19 15:29:34 -0700 | [diff] [blame] | 2 | // Copyright 2023 Google Inc. All rights reserved. |
Keir Mierle | 7492b0d | 2015-03-17 22:30:16 -0700 | [diff] [blame] | 3 | // http://ceres-solver.org/ |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 4 | // |
| 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are met: |
| 7 | // |
| 8 | // * Redistributions of source code must retain the above copyright notice, |
| 9 | // this list of conditions and the following disclaimer. |
| 10 | // * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | // this list of conditions and the following disclaimer in the documentation |
| 12 | // and/or other materials provided with the distribution. |
| 13 | // * Neither the name of Google Inc. nor the names of its contributors may be |
| 14 | // used to endorse or promote products derived from this software without |
| 15 | // specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 20 | // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 21 | // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 25 | // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 26 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 27 | // POSSIBILITY OF SUCH DAMAGE. |
| 28 | // |
| 29 | // Author: sameeragarwal@google.com (Sameer Agarwal) |
| 30 | |
| 31 | #include "ceres/covariance.h" |
| 32 | |
| 33 | #include <utility> |
| 34 | #include <vector> |
Nikolaus Demmel | 7b8f675 | 2020-09-20 21:45:24 +0200 | [diff] [blame] | 35 | |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 36 | #include "ceres/covariance_impl.h" |
| 37 | #include "ceres/problem.h" |
| 38 | #include "ceres/problem_impl.h" |
| 39 | |
| 40 | namespace ceres { |
| 41 | |
| 42 | Covariance::Covariance(const Covariance::Options& options) { |
Sameer Agarwal | ae65219 | 2022-02-02 13:17:29 -0800 | [diff] [blame] | 43 | impl_ = std::make_unique<internal::CovarianceImpl>(options); |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Sergiu Deitsch | a35bd1b | 2022-02-09 00:56:10 +0100 | [diff] [blame] | 46 | Covariance::~Covariance() = default; |
Sameer Agarwal | 45ac14f | 2013-05-20 09:15:57 -0700 | [diff] [blame] | 47 | |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 48 | bool Covariance::Compute( |
Sameer Agarwal | 9602ed7 | 2023-01-14 05:54:24 -0800 | [diff] [blame] | 49 | const std::vector<std::pair<const double*, const double*>>& |
| 50 | covariance_blocks, |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 51 | Problem* problem) { |
Dmitriy Korchemkin | b711682 | 2022-09-20 13:46:08 +0300 | [diff] [blame] | 52 | return impl_->Compute(covariance_blocks, problem->mutable_impl()); |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Alexander Ivanov | 53df5dd | 2023-01-11 16:51:38 +0000 | [diff] [blame] | 55 | bool Covariance::Compute(const std::vector<const double*>& parameter_blocks, |
Nikolaus Demmel | 7b8f675 | 2020-09-20 21:45:24 +0200 | [diff] [blame] | 56 | Problem* problem) { |
Dmitriy Korchemkin | b711682 | 2022-09-20 13:46:08 +0300 | [diff] [blame] | 57 | return impl_->Compute(parameter_blocks, problem->mutable_impl()); |
Wannes Van Loock | b0bf9fd | 2015-12-07 14:51:23 +0100 | [diff] [blame] | 58 | } |
| 59 | |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 60 | bool Covariance::GetCovarianceBlock(const double* parameter_block1, |
| 61 | const double* parameter_block2, |
| 62 | double* covariance_block) const { |
Steve Hsu | a1579be | 2015-03-12 09:30:11 -0700 | [diff] [blame] | 63 | return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1, |
| 64 | parameter_block2, |
| 65 | true, // ambient |
| 66 | covariance_block); |
| 67 | } |
| 68 | |
| 69 | bool Covariance::GetCovarianceBlockInTangentSpace( |
| 70 | const double* parameter_block1, |
| 71 | const double* parameter_block2, |
| 72 | double* covariance_block) const { |
| 73 | return impl_->GetCovarianceBlockInTangentOrAmbientSpace(parameter_block1, |
| 74 | parameter_block2, |
| 75 | false, // tangent |
| 76 | covariance_block); |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Wannes Van Loock | b0bf9fd | 2015-12-07 14:51:23 +0100 | [diff] [blame] | 79 | bool Covariance::GetCovarianceMatrix( |
Alexander Ivanov | 53df5dd | 2023-01-11 16:51:38 +0000 | [diff] [blame] | 80 | const std::vector<const double*>& parameter_blocks, |
Johannes Beck | 84fdac3 | 2020-03-24 08:02:21 +0100 | [diff] [blame] | 81 | double* covariance_matrix) const { |
Wannes Van Loock | b0bf9fd | 2015-12-07 14:51:23 +0100 | [diff] [blame] | 82 | return impl_->GetCovarianceMatrixInTangentOrAmbientSpace(parameter_blocks, |
| 83 | true, // ambient |
| 84 | covariance_matrix); |
| 85 | } |
| 86 | |
| 87 | bool Covariance::GetCovarianceMatrixInTangentSpace( |
Nikolaus Demmel | 7b8f675 | 2020-09-20 21:45:24 +0200 | [diff] [blame] | 88 | const std::vector<const double*>& parameter_blocks, |
| 89 | double* covariance_matrix) const { |
Wannes Van Loock | b0bf9fd | 2015-12-07 14:51:23 +0100 | [diff] [blame] | 90 | return impl_->GetCovarianceMatrixInTangentOrAmbientSpace(parameter_blocks, |
| 91 | false, // tangent |
| 92 | covariance_matrix); |
| 93 | } |
| 94 | |
Sameer Agarwal | 02706c1 | 2013-05-12 22:07:55 -0700 | [diff] [blame] | 95 | } // namespace ceres |