pub struct Problem { /* private fields */ }Implementations§
Source§impl Problem
impl Problem
pub fn new(jacobian_mode: JacobianMode) -> Self
Sourcepub fn mark_for_elimination(&mut self, key: VarKey)
pub fn mark_for_elimination(&mut self, key: VarKey)
Mark a variable to be eliminated by the Schur complement solver.
Nothing is eliminated by default — not even Rn(3) landmarks. A
bundle-adjustment problem only uses the Schur path once every landmark
carries an explicit mark (or the solver is configured with
auto-detection); unmarked variables are retained and form the reduced
system. The
eliminated set is not restricted to 3-DOF landmarks: any DOF works, sizes
may be mixed within one problem, and the eliminated variables need not be
adjacent in the variable ordering. That covers inverse-depth
parameterizations (1 DOF), LiDAR features, and sliding-window
marginalization of whole poses (6 DOF), as well as classic bundle
adjustment.
§Precondition
Eliminated variables must be mutually unconnected — no factor may
touch two of them. That is what makes H_ee block-diagonal and its
inverse cheap. Violating it is reported as an error on the first solve,
naming both variables, rather than silently producing a wrong step.
Sourcepub fn mark_as_schur_landmark(&mut self, key: VarKey)
👎Deprecated since 1.6.0: renamed to mark_for_elimination: elimination is not restricted to landmarks
pub fn mark_as_schur_landmark(&mut self, key: VarKey)
renamed to mark_for_elimination: elimination is not restricted to landmarks
Bundle-adjustment-flavoured alias for Self::mark_for_elimination.
Sourcepub fn add_variable(
&mut self,
manifold_type: ManifoldType,
params: DVector<f64>,
) -> VarKey
pub fn add_variable( &mut self, manifold_type: ManifoldType, params: DVector<f64>, ) -> VarKey
Add a variable with a given manifold type and initial parameter vector.
Returns a stable VarKey handle for use in add_residual_block, fix_variable, etc.
Sourcepub fn add_residual_block(
&mut self,
variable_keys: &[VarKey],
factor: Box<dyn Factor + Send + Sync>,
loss_func: Option<Box<dyn LossFunction + Send + Sync>>,
) -> FactorKey
pub fn add_residual_block( &mut self, variable_keys: &[VarKey], factor: Box<dyn Factor + Send + Sync>, loss_func: Option<Box<dyn LossFunction + Send + Sync>>, ) -> FactorKey
Add a residual block (factor + optional loss) connecting the given variables.
Returns a FactorKey that can be used to remove the block later.
Sourcepub fn add_residual_block_with_noise(
&mut self,
variable_keys: &[VarKey],
factor: Box<dyn Factor + Send + Sync>,
loss_func: Option<Box<dyn LossFunction + Send + Sync>>,
noise: NoiseModel,
) -> FactorKey
pub fn add_residual_block_with_noise( &mut self, variable_keys: &[VarKey], factor: Box<dyn Factor + Send + Sync>, loss_func: Option<Box<dyn LossFunction + Send + Sync>>, noise: NoiseModel, ) -> FactorKey
Register a residual block with a measurement noise model, keeping the
validation behaviour of Self::try_add_residual_block.
The model carries the square-root information S; residuals and
Jacobians are whitened (S·r, S·J) before the robust-loss corrector,
so the optimized objective is Σ ½·ρ(‖S·r‖²) — the Ω-weighted
objective g2o-style benchmarks report. Its dimension must equal the
factor’s residual_dim().
Sourcepub fn try_add_residual_block_with_noise(
&mut self,
variable_keys: &[VarKey],
factor: Box<dyn Factor + Send + Sync>,
loss_func: Option<Box<dyn LossFunction + Send + Sync>>,
noise: NoiseModel,
) -> CoreResult<FactorKey>
pub fn try_add_residual_block_with_noise( &mut self, variable_keys: &[VarKey], factor: Box<dyn Factor + Send + Sync>, loss_func: Option<Box<dyn LossFunction + Send + Sync>>, noise: NoiseModel, ) -> CoreResult<FactorKey>
Self::add_residual_block_with_noise returning a typed error.
Sourcepub fn try_add_residual_block(
&mut self,
variable_keys: &[VarKey],
factor: Box<dyn Factor + Send + Sync>,
loss_func: Option<Box<dyn LossFunction + Send + Sync>>,
) -> CoreResult<FactorKey>
pub fn try_add_residual_block( &mut self, variable_keys: &[VarKey], factor: Box<dyn Factor + Send + Sync>, loss_func: Option<Box<dyn LossFunction + Send + Sync>>, ) -> CoreResult<FactorKey>
Register a residual block, validating it against the referenced variables first.
Runs the factor’s Factor::validate_variables hook so shape
mismatches (e.g. a landmark variable whose parameter count disagrees
with the factor’s observations) surface as a typed registration error
instead of a panic inside the parallel assembly. Unknown variable keys
are rejected as well — they would otherwise be silently skipped during
linearization.
pub fn remove_residual_block( &mut self, block_id: FactorKey, ) -> Option<ResidualBlock>
Sourcepub fn fix_variable(&mut self, var_key: VarKey, idx: usize)
pub fn fix_variable(&mut self, var_key: VarKey, idx: usize)
Hold tangent-space component idx of var_key fixed during solving.
§Panics
If the key is unknown or idx is outside the variable’s DOF. Use
Self::try_fix_variable to handle that as an error.
Sourcepub fn try_fix_variable(
&mut self,
var_key: VarKey,
idx: usize,
) -> CoreResult<()>
pub fn try_fix_variable( &mut self, var_key: VarKey, idx: usize, ) -> CoreResult<()>
Self::fix_variable returning a typed error.
An out-of-range idx used to be accepted and then silently ignored
forever, because the constraint is only ever applied by index against a
tangent vector that never has that component.
pub fn unfix_variable(&mut self, var_key: VarKey)
Sourcepub fn set_variable_bounds(
&mut self,
var_key: VarKey,
idx: usize,
lower_bound: f64,
upper_bound: f64,
)
pub fn set_variable_bounds( &mut self, var_key: VarKey, idx: usize, lower_bound: f64, upper_bound: f64, )
Constrain tangent-space component idx of var_key to [lower, upper].
§Panics
If the key is unknown, idx is outside the variable’s DOF, or the range
is inverted. Use Self::try_set_variable_bounds to handle that as an
error.
Sourcepub fn try_set_variable_bounds(
&mut self,
var_key: VarKey,
idx: usize,
lower_bound: f64,
upper_bound: f64,
) -> CoreResult<()>
pub fn try_set_variable_bounds( &mut self, var_key: VarKey, idx: usize, lower_bound: f64, upper_bound: f64, ) -> CoreResult<()>
Self::set_variable_bounds returning a typed error.
An inverted range used to be warned about and then dropped, leaving the caller unable to distinguish “bound set” from “bound rejected”.
pub fn remove_variable_bounds(&mut self, var_key: VarKey)
Sourcepub fn apply_constraints_to_variables(
&self,
variables: &mut SlotMap<VarKey, Box<dyn ManifoldVariable>>,
)
pub fn apply_constraints_to_variables( &self, variables: &mut SlotMap<VarKey, Box<dyn ManifoldVariable>>, )
Apply fixed indices and bounds to a mutable clone of the variable map.
Optimizers call this after copying problem.variables to initialize working state.
pub fn num_residual_blocks(&self) -> usize
Sourcepub fn total_residual_dimension(&self) -> usize
pub fn total_residual_dimension(&self) -> usize
Total number of scalar residuals across all residual blocks.
This is the row count m of the assembled Jacobian.
Sourcepub fn compute_residual_sparse(
&self,
variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>,
) -> CoreResult<Mat<f64>>
pub fn compute_residual_sparse( &self, variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>, ) -> CoreResult<Mat<f64>>
Compute only the residual vector (no Jacobian) for the given variable values.
Sourcepub fn compute_residual_and_cost_sparse(
&self,
variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>,
) -> CoreResult<(Mat<f64>, f64)>
pub fn compute_residual_and_cost_sparse( &self, variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>, ) -> CoreResult<(Mat<f64>, f64)>
Compute the residual vector together with the objective value.
The cost is not 0.5·‖r‖² of the returned vector. For blocks carrying a
robust loss the returned residual is Triggs-corrected — it exists to drive
the linear system — while the cost is the true robust cost 0.5·ρ(‖r‖²).
Squaring the corrected residual gives a different function, which is what
made every reported cost and every trust-region ratio wrong for robust
problems.
For blocks with no loss function the two coincide at 0.5·‖r‖².
Sourcepub fn compute_residual_and_jacobian_sparse(
&self,
variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>,
variable_index_map: &SecondaryMap<VarKey, usize>,
symbolic_structure: &SymbolicStructure,
) -> CoreResult<(Mat<f64>, SparseColMat<usize, f64>)>
pub fn compute_residual_and_jacobian_sparse( &self, variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>, variable_index_map: &SecondaryMap<VarKey, usize>, symbolic_structure: &SymbolicStructure, ) -> CoreResult<(Mat<f64>, SparseColMat<usize, f64>)>
Compute residuals and sparse Jacobian.
Sourcepub fn compute_residual_and_jacobian_dense(
&self,
variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>,
variable_index_map: &SecondaryMap<VarKey, usize>,
total_dof: usize,
) -> CoreResult<(Mat<f64>, Mat<f64>)>
pub fn compute_residual_and_jacobian_dense( &self, variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>, variable_index_map: &SecondaryMap<VarKey, usize>, total_dof: usize, ) -> CoreResult<(Mat<f64>, Mat<f64>)>
Compute residuals and dense Jacobian.
pub fn log_residual_to_file( &self, residual: &DVector<f64>, filename: &str, ) -> Result<(), Error>
pub fn log_sparse_jacobian_to_file( &self, jacobian: &SparseColMat<usize, f64>, filename: &str, ) -> Result<(), Error>
pub fn log_variables_to_file( &self, variables: &SlotMap<VarKey, Box<dyn ManifoldVariable>>, filename: &str, ) -> Result<(), Error>
Sourcepub fn compute_and_set_covariances(
&self,
variables: &mut SlotMap<VarKey, Box<dyn ManifoldVariable>>,
options: CovarianceOptions,
) -> Option<SecondaryMap<VarKey, Mat<f64>>>
pub fn compute_and_set_covariances( &self, variables: &mut SlotMap<VarKey, Box<dyn ManifoldVariable>>, options: CovarianceOptions, ) -> Option<SecondaryMap<VarKey, Mat<f64>>>
Compute per-variable covariances at variables and store them on the
variables themselves.
This re-linearizes the problem at the given point and inverts a clean
H = JᵀJ — no Levenberg-Marquardt damping and no Jacobi scaling, both of
which are internal solver details and must not appear in the result. See
crate::linalg::covariance.
options selects the factorization algorithm and whether the result is
multiplied by the estimated noise variance σ̂² (scaled) or returned as
the raw H⁻¹ (unscaled). Optimizers pass their covariance_options
here.
Returns None if covariance estimation fails (most commonly a
rank-deficient H from unfixed gauge freedom), after logging the reason.
Callers that need to handle the failure should use
Covariance::compute
directly, which returns a typed error.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Problem
impl !UnwindSafe for Problem
impl Freeze for Problem
impl Send for Problem
impl Sync for Problem
impl Unpin for Problem
impl UnsafeUnpin for Problem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
Source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
Source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
Source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> StrictAs for T
impl<T> StrictAs for T
Source§fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
fn strict_as<Dst>(self) -> Dstwhere
T: StrictCast<Dst>,
Source§impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
impl<Src, Dst> StrictCastFrom<Src> for Dstwhere
Src: StrictCast<Dst>,
Source§fn strict_cast_from(src: Src) -> Dst
fn strict_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.