@@ -431,7 +431,7 @@ ISAM2Result ISAM2::update(const NonlinearFactorGraph& newFactors,
431431 addVariables (newTheta, result.details ());
432432
433433 // Update delta if we need it to check relinearization later
434- if (update.relinarizationNeeded (update_count_))
434+ if (update.relinarizationNeeded (update_count_) && !deltaReplacedMask_. empty () )
435435 updateDelta (updateParams.forceFullSolve );
436436
437437 // 1. Add any new factors \Factors:=\Factors\cup\Factors'.
@@ -756,9 +756,9 @@ void ISAM2::updateDelta(bool forceFullSolve) const {
756756 const VectorValues gradAtZero = this ->gradientAtZero (); // Compute gradient
757757 DeltaImpl::UpdateRgProd (roots_, deltaReplacedMask_, gradAtZero,
758758 &RgProd_); // Update RgProd
759- const VectorValues dx_u = DeltaImpl::ComputeGradientSearch (
760- gradAtZero, RgProd_); // Compute gradient search point
761-
759+ const VectorValues dx_u =
760+ VectorValues::Zero (deltaNewton_)
761+ . update ( DeltaImpl::ComputeGradientSearch (gradAtZero, RgProd_));
762762 // Clear replaced keys mask because now we've updated deltaNewton_ and
763763 // RgProd_
764764 deltaReplacedMask_.clear ();
@@ -777,6 +777,39 @@ void ISAM2::updateDelta(bool forceFullSolve) const {
777777 // Copy the VectorValues containing with the linear solution
778778 delta_ = doglegResult.dx_d ;
779779 gttoc (Copy_dx_d);
780+ } else if (std::holds_alternative<ISAM2DoglegLineSearchParams>(
781+ params_.optimizationParams )) {
782+ const ISAM2DoglegLineSearchParams& isamDllsParams =
783+ std::get<ISAM2DoglegLineSearchParams>(params_.optimizationParams );
784+ const double effectiveWildfireThreshold =
785+ forceFullSolve ? 0.0 : isamDllsParams.getWildfireThreshold ();
786+
787+ // Timer start
788+ gttic (DoglegLineSearch_Iterate);
789+
790+ // Compute Newton's method step
791+ gttic (Wildfire_update);
792+ DeltaImpl::UpdateGaussNewtonDelta (
793+ roots_, deltaReplacedMask_, effectiveWildfireThreshold, &deltaNewton_);
794+ gttoc (Wildfire_update);
795+
796+ // Compute steepest descent step
797+ const VectorValues gradAtZero = this ->gradientAtZero ();
798+ DeltaImpl::UpdateRgProd (roots_, deltaReplacedMask_, gradAtZero, &RgProd_);
799+ const VectorValues dx_u =
800+ VectorValues::Zero (deltaNewton_)
801+ .update (DeltaImpl::ComputeGradientSearch (gradAtZero, RgProd_));
802+ deltaReplacedMask_.clear ();
803+
804+ // Do the DogLeg Line Search
805+ DoglegOptimizerImpl::IterationResult doglegResult (
806+ DoglegLineSearchImpl::Iterate (isamDllsParams.dllsParams , dx_u,
807+ deltaNewton_, *this , nonlinearFactors_,
808+ theta_));
809+
810+ // Update Delta and linear step
811+ delta_ = doglegResult.dx_d ;
812+ gttoc (DoglegLineSearch_Iterate);
780813 } else {
781814 throw std::runtime_error (" iSAM2: unknown ISAM2Params type" );
782815 }
@@ -832,4 +865,41 @@ VectorValues ISAM2::gradientAtZero() const {
832865 return g;
833866}
834867
868+ /* ************************************************************************* */
869+ std::pair<KeySet, bool > ISAM2::predictUpdateInfo (
870+ const NonlinearFactorGraph& newFactors, const Values& newTheta,
871+ const ISAM2UpdateParams& updateParams) const {
872+ // Temp variables required by inputs below
873+ ISAM2Result result;
874+ UpdateImpl update (params_, updateParams);
875+
876+ if (update.relinarizationNeeded (update_count_) && !deltaReplacedMask_.empty ())
877+ updateDelta (updateParams.forceFullSolve );
878+
879+ // Gather the Keys involved from update params
880+ update.computeUnusedKeys (newFactors, variableIndex_,
881+ result.keysWithRemovedFactors , &result.unusedKeys );
882+ update.gatherInvolvedKeys (newFactors, nonlinearFactors_,
883+ result.keysWithRemovedFactors , &result.markedKeys );
884+ update.updateKeys (result.markedKeys , &result);
885+
886+ // Gather keys involved due to relinearization threshold
887+ // Note: increment by one as we are performing a one step look ahead
888+ KeySet relinKeys;
889+ if (update.relinarizationNeeded (update_count_ + 1 )) {
890+ relinKeys = update.gatherRelinearizeKeys (roots_, delta_, fixedVariables_,
891+ &result.markedKeys );
892+ if (!relinKeys.empty ())
893+ update.findFluid (roots_, relinKeys, &result.markedKeys , result.details ());
894+ }
895+ // Get the top of the bayes tree affected by all the involved keys
896+ KeySet affectedKeys = collectAffectedKeys (
897+ KeyVector (result.markedKeys .begin (), result.markedKeys .end ()));
898+ // Add the new keys to get the entire set of keys affected by the update
899+ KeySet newKeys = newFactors.keys ();
900+ affectedKeys.insert (newKeys.begin (), newKeys.end ());
901+ // Return the affected keys and whether or not this will be a batch update
902+ return {affectedKeys, affectedKeys.size () >= theta_.size () * 0.65 };
903+ }
904+
835905} // namespace gtsam
0 commit comments