|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r56069 - in sandbox/statistics/survival_model: boost/statistics/survival/model/concept boost/statistics/survival/model/models/exponential libs/statistics/survival/model/doc libs/statistics/survival/model/example
From: erwann.rogard_at_[hidden]
Date: 2009-09-06 12:16:13
Author: e_r
Date: 2009-09-06 12:16:13 EDT (Sun, 06 Sep 2009)
New Revision: 56069
URL: http://svn.boost.org/trac/boost/changeset/56069
Log:
a/m
Added:
sandbox/statistics/survival_model/boost/statistics/survival/model/concept/
sandbox/statistics/survival_model/boost/statistics/survival/model/concept/random_failure.hpp (contents, props changed)
Text files modified:
sandbox/statistics/survival_model/boost/statistics/survival/model/models/exponential/log_likelihood.hpp | 18 +++++++--
sandbox/statistics/survival_model/libs/statistics/survival/model/doc/readme.txt | 22 ++---------
sandbox/statistics/survival_model/libs/statistics/survival/model/example/posterior_analysis.cpp | 75 +++++++++++++--------------------------
3 files changed, 44 insertions(+), 71 deletions(-)
Added: sandbox/statistics/survival_model/boost/statistics/survival/model/concept/random_failure.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/statistics/survival/model/concept/random_failure.hpp 2009-09-06 12:16:13 EDT (Sun, 06 Sep 2009)
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::model::concept::random_failure.hpp //
+// //
+// Copyright 2009 Erwann Rogard. Distributed under the Boost //
+// Software License, Version 1.0. (See accompanying file //
+// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_STATISTICS_SURVIVAL_MODEL_CONCEPT_RANDOM_FAILURE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_MODEL_CONCEPT_RANDOM_FAILURE_HPP_ER_2009
+#include <boost/concept_check.hpp>
+#include <boost/mpl/empty_base.hpp>
+#include <boost/statistics/model/wrap/aggregate/model_covariate_parameter.hpp>
+
+namespace boost{
+
+namespace random{ // fwd
+ template<typename T,typename M,typename U>
+ T failure_time(M m ,U& u);
+}
+
+namespace statistics{
+namespace survival{
+namespace model{
+
+ template<
+ typename T,
+ typename M,
+ typename X,
+ typename P,
+ typename U,
+ typename B = mpl::empty_base
+ >
+ class RandomFailure : B
+ {
+ public:
+ typedef statistics::model::model_covariate_parameter_<M,X,P> mcp_;
+
+ BOOST_CONCEPT_USAGE(RandomFailure){
+
+ ft = boost::random::failure_time<T>(mcp,urng);
+
+ }
+
+ private:
+ mcp_ mcp;
+ U urng;
+ T ft;
+
+ };
+
+
+}// model
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Modified: sandbox/statistics/survival_model/boost/statistics/survival/model/models/exponential/log_likelihood.hpp
==============================================================================
--- sandbox/statistics/survival_model/boost/statistics/survival/model/models/exponential/log_likelihood.hpp (original)
+++ sandbox/statistics/survival_model/boost/statistics/survival/model/models/exponential/log_likelihood.hpp 2009-09-06 12:16:13 EDT (Sun, 06 Sep 2009)
@@ -15,18 +15,28 @@
namespace statistics{
namespace model{
- // Models Model (sandbox/statistics/model).
+ // Models HasLogLikelihood (sandbox/statistics/model/concept).
//
// Intentionally not in namespace survival
- template<typename T,typename X,typename B>
+ template<typename T,typename X,typename P>
T log_likelihood(
typename survival::model::meta::model_data<
T,
survival::model::exponential::model<T>,
X
>::type md,
- const B& beta
+ const P& beta
){
+ // TODO check
+ // Models:
+ //HasLogLikelihood<
+ // T,
+ // survival::model::exponential::model<T>,
+ // X,
+ // typename meta::response<T>::type,
+ // P
+ //>
+
typedef survival::model::exponential::model<T> model_;
T lr = model_::log_rate(
@@ -39,7 +49,7 @@
);
}
- // If B == X we need this overload, or else the compiler cannot find
+ // If P == X we need this overload, or else the compiler cannot find
// the above definition
template<typename T,typename X>
T log_likelihood(
Modified: sandbox/statistics/survival_model/libs/statistics/survival/model/doc/readme.txt
==============================================================================
--- sandbox/statistics/survival_model/libs/statistics/survival/model/doc/readme.txt (original)
+++ sandbox/statistics/survival_model/libs/statistics/survival/model/doc/readme.txt 2009-09-06 12:16:13 EDT (Sun, 06 Sep 2009)
@@ -13,17 +13,13 @@
[ Overview ]
- In this C++ library, we provide models of Model (statistics/model) in the
- survival modeling framework.
+ In this C++ library, we provide models of HasLogLikelihood ( defined in statistics/model) for
+ survival likelihoods.
[ Notation ]
- See statistics/model/libs/model/doc/readme and the concept Model. Let mcp
- denote an instance of model_covariate_parameter_<M, X, P>
+ See statistics/model/libs/model/doc/readme. Let mcp an instance of model_covariate_parameter_<M, X, P>
-[ Bug ]
-
- See libs/statistics/survival/example/posterior_analysis.cpp
[ Compiler ]
@@ -58,17 +54,7 @@
[ models ]
-These are models of [ SurvivalModel ] defined as:
-
-Let U/u denote a type/object modeling UniformaRandomNumberGenerator (see
-Boost.Random)
-
-M refines SurvivalModel if it models Model with the requirement that
- Expression Returns
- random::failure_time<T>(mcp,urng) Object of type T
-
-Modeled by :
- model::exponential::model
+ e.g. model::exponential::model
[ meta ]
Modified: sandbox/statistics/survival_model/libs/statistics/survival/model/example/posterior_analysis.cpp
==============================================================================
--- sandbox/statistics/survival_model/libs/statistics/survival/model/example/posterior_analysis.cpp (original)
+++ sandbox/statistics/survival_model/libs/statistics/survival/model/example/posterior_analysis.cpp 2009-09-06 12:16:13 EDT (Sun, 06 Sep 2009)
@@ -34,12 +34,9 @@
#include <boost/statistics/survival/data/include.hpp>
#include <boost/statistics/survival/model/models/exponential/include.hpp>
-// Must come after the model to be used
+// Must come after survival/model/models/exponential/include
#include <boost/statistics/model/include.hpp>
-#include <boost/importance_weights/algorithm/prepare_weights.hpp>
-#include <boost/importance_sampling/include.hpp>
-
#include <libs/statistics/survival/model/example/posterior_analysis.h>
void example_posterior_analysis(std::ostream& out){
@@ -59,6 +56,7 @@
using namespace boost;
using namespace statistics;
namespace surv = survival;
+ namespace e_cdf = empirical_cdf;
namespace iw = importance_weights;
// Types
@@ -146,7 +144,7 @@
BOOST_ASSERT( n_batch % n_true_pars_kss == 0);
vals_ true_pars_kss;
true_pars_kss.reserve(n_true_pars_kss);
- statistics::empirical_cdf::sequential_kolmogorov_smirnov_distance(
+ e_cdf::sequential_kolmogorov_smirnov_distance(
mprior,
boost::begin(true_pars),
boost::end(true_pars),
@@ -176,8 +174,7 @@
// Targets
const long n_t_pars = 1e4;
- pars_ t_pars;
- t_pars.reserve( n_t_pars );
+ pars_ t_pars( n_t_pars );
ofs_ ofs_t_pars(t_pars_path);
oa_ oa_t_pars(ofs_t_pars);
@@ -205,16 +202,18 @@
// This one size fits all proposal is likely to result in a small ESS. You
// can monitor the ESS by calling out << pws. Ultimately, uniformity of
// the Cook-Gelman will determine if either the computations are wrong
- // or if n_proposal is too small. n_proposal = 1e4 works for N(0,5).
+ // or if n_proposal is too small. n_proposal = 1e4 works fine for N(0,5).
mproposal_ mproposal = mprior;
pars_ p_pars (n_proposal);
vals_ p_lpdfs(n_proposal);
-
// Weights
const val_ max_log = 100.0;
- typedef iw::prepare_weights<val_> pws_;
- pws_ pws( max_log );
+ typedef model::importance_sampler<val_> model_is_;
+ model_is_ model_is( max_log );
+
+ // typedef iw::prepare_weights<val_> pws_;
+ // pws_ pws( max_log );
vals_ iws;
iws.reserve( n_proposal );
@@ -239,7 +238,7 @@
BOOST_ASSERT( n_batch % n_p_pars_kss == 0 );
vals_ p_pars_kss;
p_pars_kss.reserve(n_p_pars_kss);
- statistics::empirical_cdf::sequential_kolmogorov_smirnov_distance(
+ e_cdf::sequential_kolmogorov_smirnov_distance(
mproposal,
boost::begin(p_pars),
boost::end(p_pars),
@@ -282,45 +281,23 @@
pmd_ pmd( mprior, model, x_cycle, events);
iws.resize( size( p_pars ) );
- // The reason I uncomment the if statement is that log_posteriors2
- // is supposed to work for either case.
- //if(
- // make_distribution_primitives( mprior )
- // ==make_distribution_primitives( mproposal )
- //){
- // model::log_likelihoods<val_>(
- // pmd,
- // boost::begin( p_pars ),
- // boost::end( p_pars ),
- // boost::begin( iws )
- // );
- //}else{
- statistics::model::log_posteriors<val_>(
- pmd,
- boost::begin( p_pars ),
- boost::end( p_pars ),
- boost::begin( p_lpdfs ),
- boost::begin( iws )
- );
- //}
-
- pws(
- boost::begin( iws ),
- boost::end( iws ),
- boost::begin( p_pars )
- );
t_pars.clear();
t_pars.resize( n_t_pars );
- is::generate(
- urng,
- boost::begin( iws ),
- boost::end( iws ),
+ model_is.prepare_weights(
+ pmd,
+ boost::begin( p_pars ),
+ boost::end( p_pars ),
+ boost::begin( p_lpdfs )
+ );
+ model_is.generate_n(
+ boost::begin(t_pars),
+ n_t_pars,
boost::begin( p_pars ),
- boost::begin( t_pars ),
- n_t_pars
+ urng
);
+
oa_t_pars << t_pars;
- val_ plt = statistics::empirical_cdf::proportion_less_than(
+ val_ plt = e_cdf::proportion_less_than(
boost::begin( t_pars ),
boost::end( t_pars ),
true_pars[i]
@@ -334,8 +311,8 @@
f
% i
% t.elapsed()
- % pws;
- out << std::endl << std::setprecision( 10 ) << f.str();
+ % model_is.pws();
+ out << std::endl << f.str();
}
}// Proposal sample
}// loop over batches
@@ -345,7 +322,7 @@
BOOST_ASSERT( n_batch % n_ks == 0 );
vals_ kss;
kss.reserve( n_batch );
- statistics::empirical_cdf::sequential_kolmogorov_smirnov_distance(
+ e_cdf::sequential_kolmogorov_smirnov_distance(
munif_(),
boost::begin( cgs ),
boost::end( cgs ),
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk