Skip to content
Snippets Groups Projects
Commit 0b1e7f9d authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Updates in Fitting python API.

parent e6ba20d0
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@
#include "IMinimizer.h"
#include "IObserver.h"
#include <string>
#include <boost/date_time/posix_time/posix_time.hpp>
class Simulation;
class ParameterPool;
......@@ -109,6 +110,9 @@ class BA_CORE_API_ FitSuite : public IObservable
//! Set fixed flag for parameters from the list
void setParametersFixed(const std::vector<std::string> &pars, bool is_fixed);
//! Returns total wall time in seconds which was spend for run fit
double getRunTime() const;
private:
//! disabled copy constructor and assignment operator
FitSuite& operator=(const FitSuite& );
......@@ -126,6 +130,9 @@ class BA_CORE_API_ FitSuite : public IObservable
FitSuiteGradientFunction m_function_gradient;
bool m_is_last_iteration; //! Sets to true after last iteration complete
boost::posix_time::ptime m_start_time;
boost::posix_time::ptime m_end_time;
};
#endif // FITSUITE_H
......
......@@ -97,6 +97,8 @@ bool FitSuite::check_prerequisites() const
void FitSuite::runFit()
{
m_start_time = boost::posix_time::microsec_clock::local_time();
// check if all prerequisites are fullfilled before starting minimization
check_prerequisites();
......@@ -116,6 +118,7 @@ void FitSuite::runFit()
m_is_last_iteration = true;
notifyObservers();
m_end_time = boost::posix_time::microsec_clock::local_time();
}
......@@ -191,4 +194,10 @@ void FitSuite::setParametersFixed(const std::vector<std::string> &pars, bool is_
getFitParameters()->setParametersFixed(pars, is_fixed);
}
double FitSuite::getRunTime() const
{
boost::posix_time::time_duration diff = m_end_time - m_start_time;
return diff.total_milliseconds()/1000.;
}
......@@ -228,6 +228,15 @@ void register_FitSuite_class(){
"getNStrategy"
, getNStrategy_function_type( &::FitSuite::getNStrategy ) );
}
{ //::FitSuite::getRunTime
typedef double ( ::FitSuite::*getRunTime_function_type )( ) const;
FitSuite_exposer.def(
"getRunTime"
, getRunTime_function_type( &::FitSuite::getRunTime ) );
}
{ //::FitSuite::initPrint
......
......@@ -35,6 +35,18 @@ struct IMinimizer_wrapper : IMinimizer, bp::wrapper< IMinimizer > {
IMinimizer::clear( );
}
virtual ::std::string getAlgorithmName( ) const {
if( bp::override func_getAlgorithmName = this->get_override( "getAlgorithmName" ) )
return func_getAlgorithmName( );
else
return this->IMinimizer::getAlgorithmName( );
}
::std::string default_getAlgorithmName( ) const {
return IMinimizer::getAlgorithmName( );
}
virtual double getErrorOfVariable( ::std::size_t arg0 ) const {
if( bp::override func_getErrorOfVariable = this->get_override( "getErrorOfVariable" ) )
return func_getErrorOfVariable( arg0 );
......@@ -71,6 +83,18 @@ struct IMinimizer_wrapper : IMinimizer, bp::wrapper< IMinimizer > {
return IMinimizer::getMinValue( );
}
virtual ::std::string getMinimizerName( ) const {
if( bp::override func_getMinimizerName = this->get_override( "getMinimizerName" ) )
return func_getMinimizerName( );
else
return this->IMinimizer::getMinimizerName( );
}
::std::string default_getMinimizerName( ) const {
return IMinimizer::getMinimizerName( );
}
virtual ::std::size_t getNCalls( ) const {
if( bp::override func_getNCalls = this->get_override( "getNCalls" ) )
return func_getNCalls( );
......@@ -202,6 +226,17 @@ void register_IMinimizer_class(){
, clear_function_type(&::IMinimizer::clear)
, default_clear_function_type(&IMinimizer_wrapper::default_clear) );
}
{ //::IMinimizer::getAlgorithmName
typedef ::std::string ( ::IMinimizer::*getAlgorithmName_function_type )( ) const;
typedef ::std::string ( IMinimizer_wrapper::*default_getAlgorithmName_function_type )( ) const;
IMinimizer_exposer.def(
"getAlgorithmName"
, getAlgorithmName_function_type(&::IMinimizer::getAlgorithmName)
, default_getAlgorithmName_function_type(&IMinimizer_wrapper::default_getAlgorithmName) );
}
{ //::IMinimizer::getErrorOfVariable
......@@ -236,6 +271,17 @@ void register_IMinimizer_class(){
, getMinValue_function_type(&::IMinimizer::getMinValue)
, default_getMinValue_function_type(&IMinimizer_wrapper::default_getMinValue) );
}
{ //::IMinimizer::getMinimizerName
typedef ::std::string ( ::IMinimizer::*getMinimizerName_function_type )( ) const;
typedef ::std::string ( IMinimizer_wrapper::*default_getMinimizerName_function_type )( ) const;
IMinimizer_exposer.def(
"getMinimizerName"
, getMinimizerName_function_type(&::IMinimizer::getMinimizerName)
, default_getMinimizerName_function_type(&IMinimizer_wrapper::default_getMinimizerName) );
}
{ //::IMinimizer::getNCalls
......
......@@ -26,10 +26,10 @@ cylinder_radius = 5*nanometer
# minimizer name and type of minimization algorithm
Minimizers = [
("Minuit2", "Migrad"),
("Minuit2", "Fumili"),
("GSLMultiMin", "BFGS"),
("GSLMultiMin", "SteepestDescent"),
#("Minuit2", "Migrad"),
#("Minuit2", "Fumili"),
#("GSLMultiMin", "BFGS"),
#("GSLMultiMin", "SteepestDescent"),
("GSLLMA", ""),
# ("GSLSimAn","")
]
......
......@@ -87,8 +87,8 @@ def ManualClassTunings(mb):
cl = mb.class_("IMinimizer")
cl.member_function("setChiSquaredFunction").exclude()
cl.member_function("setGradientFunction").exclude()
cl.member_function("getAlgorithmName").exclude() # temporarily due to compilation problems under MSVC
cl.member_function("getMinimizerName").exclude() # temporarily due to compilation problems under MSVC
#cl.member_function("getAlgorithmName").exclude() # temporarily due to compilation problems under MSVC
#cl.member_function("getMinimizerName").exclude() # temporarily due to compilation problems under MSVC
for fun in cl.member_functions():
if "getOptions" in fun.name:
if "::MinimizerOptions const & ( ::IMinimizer::* )( ) const" in fun.decl_string:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment