diff --git a/src/core/include/variable.h b/src/core/include/variable.h index 2a65cc84a..a0257e0b0 100644 --- a/src/core/include/variable.h +++ b/src/core/include/variable.h @@ -143,6 +143,7 @@ class _Variable : public _Constant { virtual bool CheckFForDependence (_AVLList const&, bool = false); virtual bool HasBeenInitialized (void) const {return !(varFlags & HY_VARIABLE_NOTSET);} virtual void MarkModified (void) {varFlags = varFlags | HY_VARIABLE_CHANGED;} + virtual bool IsModified (void) const {return varFlags & HY_VARIABLE_CHANGED;} virtual void ClearModified (void) {if (varFlags & HY_VARIABLE_CHANGED) varFlags -= HY_VARIABLE_CHANGED;} _String const ContextFreeName (void) const; diff --git a/src/core/likefunc.cpp b/src/core/likefunc.cpp index de0711b13..40e401cd6 100644 --- a/src/core/likefunc.cpp +++ b/src/core/likefunc.cpp @@ -4126,11 +4126,16 @@ _Matrix* _LikelihoodFunction::Optimize (_AssociativeList const * options) } } + + _SimpleList untag; if (keepStartingPoint) { - indexInd.Each ([this] (long v, unsigned long i) -> void { + indexInd.Each ([this, &untag] (long v, unsigned long i) -> void { _Variable *iv = GetIthIndependentVar (i); if (iv->HasBeenInitialized()) { - iv->MarkModified(); + if (!iv->IsModified()) { + iv->MarkModified(); + untag << i; + } } }); } @@ -4140,11 +4145,9 @@ _Matrix* _LikelihoodFunction::Optimize (_AssociativeList const * options) } if (keepStartingPoint) { - indexInd.Each ([this] (long v, unsigned long i) -> void { + untag.Each ([this] (long v, unsigned long i) -> void { _Variable *iv = GetIthIndependentVar (i); - if (iv->HasBeenInitialized()) { - iv->ClearModified(); - } + iv->ClearModified(); }); }