Skip to content

Commit 592c6f1

Browse files
committed
Scipy: implemented method NCalls
1 parent 1dc8d65 commit 592c6f1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

math/scipy/inc/Math/ScipyMinimizer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ScipyMinimizer : public BasicMinimizer {
7676
PyObject *fBoundsMod;
7777
GenAlgoOptions fExtraOpts;
7878
std::function<bool(const std::vector<double> &, double *)> fHessianFunc;
79-
79+
unsigned int fCalls;
8080
protected:
8181
PyObject *fGlobalNS;
8282
PyObject *fLocalNS;
@@ -115,6 +115,10 @@ class ScipyMinimizer : public BasicMinimizer {
115115
*/
116116
void PyRunString(TString code, TString errorMessage = "Failed to run python code", int start = Py_single_input);
117117

118+
/*
119+
Number of function calls
120+
*/
121+
virtual unsigned int NCalls() const override;
118122
private:
119123
// usually copying is non trivial, so we make this unaccessible
120124

math/scipy/src/ScipyMinimizer.cxx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ PyObject *hessian_function(PyObject * /*self*/, PyObject *args)
7171
//_______________________________________________________________________
7272
ScipyMinimizer::ScipyMinimizer() : BasicMinimizer()
7373
{
74+
fCalls = 0;
7475
fOptions.SetMinimizerType("Scipy");
7576
fOptions.SetMinimizerAlgorithm("L-BFGS-B");
7677
PyInitialize();
@@ -82,6 +83,7 @@ ScipyMinimizer::ScipyMinimizer() : BasicMinimizer()
8283
//_______________________________________________________________________
8384
ScipyMinimizer::ScipyMinimizer(const char *type)
8485
{
86+
fCalls = 0;
8587
fOptions.SetMinimizerType("Scipy");
8688
fOptions.SetMinimizerAlgorithm(type);
8789
PyInitialize();
@@ -288,6 +290,7 @@ bool ScipyMinimizer::Minimize()
288290
SetFinalValues(x);
289291
auto obj_value = (*gFunction)(x);
290292
SetMinValue(obj_value);
293+
fCalls = nfev; //number of function evaluations
291294

292295
std::cout << "=== Status: " << status << std::endl;
293296
std::cout << "=== Message: " << message << std::endl;
@@ -312,3 +315,9 @@ void ScipyMinimizer::SetHessianFunction(std::function<bool(const std::vector<dou
312315
{
313316
fHessianFunc = func;
314317
}
318+
319+
//_______________________________________________________________________
320+
unsigned int ScipyMinimizer::NCalls() const
321+
{
322+
return fCalls;
323+
}

0 commit comments

Comments
 (0)