aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-22 17:13:39 +0000
committerastrojhgu <astrojhgu@ed2142bd-67ad-457f-ba7c-d818d4011675>2009-08-22 17:13:39 +0000
commit9c0eb6f71a841f0a0c76a13ece07d4eeb5f945d3 (patch)
treeb83e999aa9a04adab8ff0db157a980f750d12ffd
parent554c5d6de17264b2e66726eff8569d1fe57ffe92 (diff)
downloadopt-utilities-9c0eb6f71a841f0a0c76a13ece07d4eeb5f945d3.tar.bz2
git-svn-id: file:///home/svn/opt_utilities@51 ed2142bd-67ad-457f-ba7c-d818d4011675
-rw-r--r--misc/bootstrap.hpp48
1 files changed, 48 insertions, 0 deletions
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 <core/fitter.hpp>
@@ -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 <typename Ty,typename Tx,typename Tp,typename Ts,typename Tstr=std::string>
class bootstrap
{
@@ -32,15 +46,27 @@ namespace opt_utilities
fitter<Ty,Tx,Tp,Ts,Tstr>* 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<Ty,Tx,Tp,Ts,Tstr>& 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<typename element_type_trait<Tp>::element_type,typename element_type_trait<Tp>::element_type>
interval(const Tstr& param_name,double level)
{