Commit 4d59929659cc2c2e3b7af2d852f8f0c9c38109da
1 parent
9a088680
Copy log-likelihood function in GObservations copy_members()
The result of the log-likelihood computation was lost in a copy of the GObservations class. Now it is conserved.
Showing
2 changed files
with
15 additions
and
8 deletions
src/obs/GObservations.cpp
| @@ -955,10 +955,9 @@ void GObservations::init_members(void) | @@ -955,10 +955,9 @@ void GObservations::init_members(void) | ||
| 955 | ***************************************************************************/ | 955 | ***************************************************************************/ |
| 956 | void GObservations::copy_members(const GObservations& obs) | 956 | void GObservations::copy_members(const GObservations& obs) |
| 957 | { | 957 | { |
| 958 | - // Copy attributes. WARNING: The member m_fct SHALL not be copied to not | ||
| 959 | - // corrupt its m_this pointer which should always point to the proper | ||
| 960 | - // observation. See note in init_members(). | 958 | + // Copy attributes |
| 961 | m_models = obs.m_models; | 959 | m_models = obs.m_models; |
| 960 | + m_fct = obs.m_fct; | ||
| 962 | 961 | ||
| 963 | // Copy observations | 962 | // Copy observations |
| 964 | m_obs.clear(); | 963 | m_obs.clear(); |
| @@ -966,6 +965,10 @@ void GObservations::copy_members(const GObservations& obs) | @@ -966,6 +965,10 @@ void GObservations::copy_members(const GObservations& obs) | ||
| 966 | m_obs.push_back((obs.m_obs[i]->clone())); | 965 | m_obs.push_back((obs.m_obs[i]->clone())); |
| 967 | } | 966 | } |
| 968 | 967 | ||
| 968 | + // Set likelihood function pointer to this instance. This makes sure | ||
| 969 | + // that the optimizer points to this instance | ||
| 970 | + m_fct.set(this); | ||
| 971 | + | ||
| 969 | // Return | 972 | // Return |
| 970 | return; | 973 | return; |
| 971 | } | 974 | } |
src/obs/GObservations_likelihood.cpp
| @@ -614,15 +614,19 @@ void GObservations::likelihood::init_members(void) | @@ -614,15 +614,19 @@ void GObservations::likelihood::init_members(void) | ||
| 614 | void GObservations::likelihood::copy_members(const likelihood& fct) | 614 | void GObservations::likelihood::copy_members(const likelihood& fct) |
| 615 | { | 615 | { |
| 616 | // Copy attributes | 616 | // Copy attributes |
| 617 | - m_value = fct.m_value; | ||
| 618 | - m_npred = fct.m_npred; | ||
| 619 | - m_this = fct.m_this; | 617 | + m_value = fct.m_value; |
| 618 | + m_npred = fct.m_npred; | ||
| 619 | + m_this = fct.m_this; | ||
| 620 | 620 | ||
| 621 | // Clone gradient if it exists | 621 | // Clone gradient if it exists |
| 622 | - if (fct.m_gradient != NULL) m_gradient = new GVector(*fct.m_gradient); | 622 | + if (fct.m_gradient != NULL) { |
| 623 | + m_gradient = new GVector(*fct.m_gradient); | ||
| 624 | + } | ||
| 623 | 625 | ||
| 624 | // Clone curvature matrix if it exists | 626 | // Clone curvature matrix if it exists |
| 625 | - if (fct.m_curvature != NULL) m_curvature = new GMatrixSparse(*fct.m_curvature); | 627 | + if (fct.m_curvature != NULL) { |
| 628 | + m_curvature = new GMatrixSparse(*fct.m_curvature); | ||
| 629 | + } | ||
| 626 | 630 | ||
| 627 | // Return | 631 | // Return |
| 628 | return; | 632 | return; |