From c38a8d7c3cca296c9f9a70bc3504075b416c68b6 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Tue, 4 Jan 2011 14:23:16 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@152 ed2142bd-67ad-457f-ba7c-d818d4011675 --- error_estimator/error_estimator.hpp | 136 ++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 error_estimator/error_estimator.hpp (limited to 'error_estimator') diff --git a/error_estimator/error_estimator.hpp b/error_estimator/error_estimator.hpp new file mode 100644 index 0000000..1e9fa84 --- /dev/null +++ b/error_estimator/error_estimator.hpp @@ -0,0 +1,136 @@ +#ifndef ERROR_EST +#define ERROR_EST +#include +#include + +namespace opt_utilities +{ + template + void estimate_error(fitter& fit,const Tstr& pname,typename element_type_trait::element_type& lower,typename element_type_trait::element_type& upper,const Ts& dchi) + { + + typedef typename element_type_trait::element_type Tpe; + fit.fit(); + if(fit.report_param_status(pname)=="frozen") + { + return; + } + try + { + freeze_param* pfp=dynamic_cast*>(&fit.get_param_modifier()); + if(pfp==0) + { + assert(0); + } + *pfp+=freeze_param(pname); + } + catch(const param_modifier_undefined&) + { + fit.set_param_modifier(freeze_param(pname)); + } + + Tpe current_value= + fit.get_param_value(pname); + Tp current_params(fit.get_model().get_all_params()); + Ts current_chi=fit.get_statistic_value(); + Tpe upper1=current_value; + Tpe step=upper-current_value; + while(1) + { + fit.set_param_value(pname,upper); + fit.fit(); + Ts chi=fit.get_statistic_value(); + cerr<current_chi+dchi) + { + break; + } + upper+=step; + } + + Ts target_chi=current_chi+dchi; + while(upper-upper1>1E-10) + { + std::cerr<=0) + { + upper=(upper+upper1)/2; + } + else if((s1-target_chi)*(s01-target_chi)>0&&(s-target_chi)*(s01-target_chi)<=0) + { + upper1=(upper+upper1)/2; + } + else + { + std::cerr<<"strange statistic structure"<current_chi+dchi) + { + break; + } + lower-=step; + } + + fit.set_param_value(pname,current_value); + fit.fit(); + + while(lower1-lower>1E-10) + { + fit.set_param_value(pname,lower1); + fit.fit(); + Ts s1=fit.get_statistic_value(); + fit.set_param_value(pname,lower); + fit.fit(); + Ts s=fit.get_statistic_value(); + fit.set_param_value(pname,(lower+lower1)/2); + fit.fit(); + Ts s01=fit.get_statistic_value(); + //std::cerr<<"l:"<=0) + { + lower=(lower+lower1)/2; + } + else if((s1-target_chi)*(s01-target_chi)>0&&(s-target_chi)*(s01-target_chi)<=0) + { + lower1=(lower+lower1)/2; + } + else + { + std::cerr<<"strange statistic structure"<& >(fit.get_param_modifier())-=freeze_param(pname); + + } +} + + +#endif +//EOF -- cgit v1.2.2