Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 1 | // Ceres Solver - A fast non-linear least squares minimizer |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 2 | // Copyright 2023 Google Inc. All rights reserved. |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 3 | // http://ceres-solver.org/ |
| 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 | #ifndef CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_ |
| 32 | #define CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_ |
| 33 | |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 34 | #include <memory> |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 35 | #include <vector> |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 36 | |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 37 | #include "ceres/graph.h" |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 38 | #include "ceres/internal/disable_warnings.h" |
| 39 | #include "ceres/internal/export.h" |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 40 | #include "ceres/ordered_groups.h" |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 41 | #include "ceres/types.h" |
| 42 | |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 43 | namespace ceres::internal { |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 44 | |
| 45 | class Program; |
| 46 | class ParameterBlock; |
| 47 | |
| 48 | // Uses an approximate independent set ordering to order the parameter |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 49 | // blocks of a problem so that it is suitable for use with Schur- |
| 50 | // complement-based solvers. The output variable ordering contains an |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 51 | // ordering of the parameter blocks and the return value is size of |
| 52 | // the independent set or the number of e_blocks (see |
| 53 | // schur_complement_solver.h for an explanation). Constant parameters |
| 54 | // are added to the end. |
| 55 | // |
| 56 | // The ordering vector has the structure |
| 57 | // |
| 58 | // ordering = [independent set, |
| 59 | // complement of the independent set, |
| 60 | // fixed blocks] |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 61 | CERES_NO_EXPORT int ComputeSchurOrdering( |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 62 | const Program& program, std::vector<ParameterBlock*>* ordering); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 63 | |
| 64 | // Same as above, except that ties while computing the independent set |
| 65 | // ordering are resolved in favour of the order in which the parameter |
| 66 | // blocks occur in the program. |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 67 | CERES_NO_EXPORT int ComputeStableSchurOrdering( |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 68 | const Program& program, std::vector<ParameterBlock*>* ordering); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 69 | |
| 70 | // Use an approximate independent set ordering to decompose the |
| 71 | // parameter blocks of a problem in a sequence of independent |
| 72 | // sets. The ordering covers all the non-constant parameter blocks in |
| 73 | // the program. |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 74 | CERES_NO_EXPORT void ComputeRecursiveIndependentSetOrdering( |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 75 | const Program& program, ParameterBlockOrdering* ordering); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 76 | |
| 77 | // Builds a graph on the parameter blocks of a Problem, whose |
| 78 | // structure reflects the sparsity structure of the Hessian. Each |
| 79 | // vertex corresponds to a parameter block in the Problem except for |
| 80 | // parameter blocks that are marked constant. An edge connects two |
| 81 | // parameter blocks, if they co-occur in a residual block. |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 82 | CERES_NO_EXPORT std::unique_ptr<Graph<ParameterBlock*>> CreateHessianGraph( |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 83 | const Program& program); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 84 | |
| 85 | // Iterate over each of the groups in order of their priority and fill |
| 86 | // summary with their sizes. |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 87 | CERES_NO_EXPORT void OrderingToGroupSizes( |
Austin Schuh | 1d1e6ea | 2020-12-23 21:56:30 -0800 | [diff] [blame] | 88 | const ParameterBlockOrdering* ordering, std::vector<int>* group_sizes); |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 89 | |
Austin Schuh | 3de38b0 | 2024-06-25 18:25:10 -0700 | [diff] [blame^] | 90 | } // namespace ceres::internal |
| 91 | |
| 92 | #include "ceres/internal/reenable_warnings.h" |
Austin Schuh | 70cc955 | 2019-01-21 19:46:48 -0800 | [diff] [blame] | 93 | |
| 94 | #endif // CERES_INTERNAL_PARAMETER_BLOCK_ORDERING_H_ |