From 0ff20b1506d7af6f3d2ee88027d1f9e714665360 Mon Sep 17 00:00:00 2001 From: Segei L Kosakovsky Pond Date: Fri, 30 Oct 2020 13:44:32 -0400 Subject: [PATCH] Incorrect variable untagging in Optimize --- src/core/include/variable.h | 1 + src/core/likefunc.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) 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(); }); }