Skip to content

Commit

Permalink
Correct number of function evaluations from a fit are now reported (i…
Browse files Browse the repository at this point in the history
…n the FitResult struct) when

Imfit::getFitResult() is called, and thus in the returned FitResult object when fit() is done.
  • Loading branch information
perwin committed Jul 15, 2024
1 parent 09d825e commit 85bfe91
Show file tree
Hide file tree
Showing 5 changed files with 1,055 additions and 918 deletions.
31 changes: 31 additions & 0 deletions new_notes_and_todo_for_python-wrapper_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,38 @@ PLAN:
** GENERAL/FUTURE TO-DO

[ ] Add indications of n_iterations to FitResult output in case of NM or DE fits

solverResults.GetNFunctionEvals

-- currently, FitResult.nIter = -1 when they succeed
fitting.py: Imfit.nIter
self._modelObjectWrapper.nIter
_modelObjectWrapper is set up by _setupModel
self._modelObjectWrapper = ModelObjectWrapper(...)

pyimfit_lib.pyx: ModelObjectWrapper class
from .imfit_lib cimport Convolver, ModelObject, SolverResults, DispatchToSolver
cdef SolverResults *_solverResults
cdef mp_result *_fitResult

fit() method:
if mode == 'LM':
self._fitResult = self._solverResults.GetMPResults()
if self._solverResults.ErrorsPresent():
self._solverResults.GetErrors(self._fitErrorsVect)

@property
def nIter(self):
if self.fittedLM:
return self._fitResult.niter
else:
return -1

[x] Add retrieval and storage of nFuncEvals in Imfit class
[x] Add code to print out nFuncEvals

[ ] Figure out how to retain number of iterations/generations when NM or DE fit is done
and save it in the FitResult object.


[X] Add ftol keyword to fitting.py --
Expand Down
9 changes: 9 additions & 0 deletions pyimfit/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def getFitResult( self ):
result.solverName = self._lastSolverUsed
result.fitConverged = self.fitConverged
result.nIter = self.nIter
result.nFuncEvals = self.nFuncEvals
result.fitStat = self.fitStatistic
result.fitStatReduced = self.reducedFitStatistic
result.aic = self.AIC
Expand Down Expand Up @@ -764,6 +765,14 @@ def nIter(self):
return self._modelObjectWrapper.nIter


@property
def nFuncEvals(self):
"""
int: number of 'function evaluations' (model-image computations) during fit.
"""
return self._modelObjectWrapper.nFuncEvals


@property
def parameterErrors(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion pyimfit/imfit_lib.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ cdef extern from "solver_results.h":
mp_result* GetMPResults( )
bool ErrorsPresent( )
void GetErrors( double *errors )
int GetNFunctionEvals
int GetNFunctionEvals()


cdef extern from "dispatch_solver.h":
Expand Down
Loading

0 comments on commit 85bfe91

Please sign in to comment.