From 9c0eb6f71a841f0a0c76a13ece07d4eeb5f945d3 Mon Sep 17 00:00:00 2001 From: astrojhgu Date: Sat, 22 Aug 2009 17:13:39 +0000 Subject: git-svn-id: file:///home/svn/opt_utilities@51 ed2142bd-67ad-457f-ba7c-d818d4011675 --- misc/bootstrap.hpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/misc/bootstrap.hpp b/misc/bootstrap.hpp index c58ab1c..492ff9f 100644 --- a/misc/bootstrap.hpp +++ b/misc/bootstrap.hpp @@ -1,3 +1,8 @@ +/** + \file bootstrap.hpp +*/ + + #ifndef BOOT_STRIP #define BOOT_STRIP #include @@ -10,6 +15,15 @@ using std::cout; namespace opt_utilities { + + /** + using bootstrap method to estimate confidence interval + \tparam Ty the return type of a model + \tparam Tx the type of self-var + \tparam Tp the type of model parameters + \tparam Ts the type of statistic + \tparam Tstr the type of string used + */ template class bootstrap { @@ -32,15 +46,27 @@ namespace opt_utilities fitter* p_fitter; Tp origin_param; public: + + /** + default construct + */ bootstrap() :p_fitter(NULL) {} + /** + destructure + */ ~bootstrap() { reset(); } + + /** + set a fitter + \param pf the fitter, the confidence interval of which will be estimated + */ void set_fitter(fitter& pf) { param_pool.clear(); @@ -49,6 +75,11 @@ namespace opt_utilities origin_param=pf.get_all_params(); } + /** + reset the estimation + reload the data + restore the parameters + */ void reset() { if(p_fitter!=NULL) @@ -58,6 +89,11 @@ namespace opt_utilities } } + + /** + resample n times + \param n the times to sample + */ void sample(int n) { if(p_fitter!=NULL) @@ -76,6 +112,11 @@ namespace opt_utilities } } + /** + get the param of i-th sampling + \param i the order of parameter + \return the parameter + */ const Tp& get_param(int i)const { return param_pool.at(i); @@ -108,6 +149,13 @@ namespace opt_utilities } public: + + /** + Calculate the confdence interval for one parameter under given level + \param param_name the name of the parameter to be estimated + \param level the confidence level + \return a std::pair containing the lower and upper boundaries of the confidence interval + */ std::pair::element_type,typename element_type_trait::element_type> interval(const Tstr& param_name,double level) { -- cgit v1.2.2