Skip to content

Commit

Permalink
feat: Optimize likelihood calculation for "modelLikelihoodGalaxyPopul…
Browse files Browse the repository at this point in the history
…ation" class

If the state is identical for two (or more) successive evaluations simply reuse the already computed likelihood.
  • Loading branch information
abensonca committed Jul 29, 2021
1 parent baa8ebf commit e52547e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/models.likelihoods.galaxy_population.F90
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,20 @@ double precision function galaxyPopulationEvaluate(self,simulationState,modelPar
do iRank=0,mpiSelf%count()-1
! If prior probability is impossible, then no need to waste time evaluating the likelihood.
if (logPriorsProposed(iRank) <= logImpossible) cycle
! If the likelihood was evaluated for the previous rank, and the current state vector is identical to that of the previous rank, the proposed likelihood must be unchanged.
if (iRank > 0) then
if (logPriorsProposed(iRank-1) > logImpossible .and. all(stateVector(:,iRank) == stateVector(:,iRank-1))) then
if (iRank == mpiSelf%rank()) then
galaxyPopulationEvaluate=logLikelihoodProposed
if (verbosityLevel >= verbosityLevelStandard) then
write (valueText,'(e12.4)') logLikelihoodProposed
message=var_str("Chain ")//simulationState%chainIndex()//" has logℒ="//trim(valueText)
call displayMessage(message,verbosityLevelSilent)
end if
end if
cycle
end if
end if
! Update parameter values.
do i=1,size(modelParametersActive_)
if (self%modelParametersActive_(i)%indexElement == 0) then
Expand Down

0 comments on commit e52547e

Please sign in to comment.