|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r57093 - in sandbox/statistics/survival_data: boost/statistics/survival/data/algorithm boost/statistics/survival/data/data boost/statistics/survival/data/meta boost/statistics/survival/data/random libs/statistics/survival/data/example libs/statistics/survival/data/src
From: erwann.rogard_at_[hidden]
Date: 2009-10-23 10:55:21
Author: e_r
Date: 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
New Revision: 57093
URL: http://svn.boost.org/trac/boost/changeset/57093
Log:
m
Text files modified:
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp | 1
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp | 2
sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp | 1
sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp | 2
sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp | 13 -
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp | 2
sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp | 11 +
sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp | 13 +-
sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp | 1
sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp | 208 +++++++++++++++++++--------------------
sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h | 13 ++
sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp | 15 ++
12 files changed, 147 insertions(+), 135 deletions(-)
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -9,6 +9,7 @@
#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORTIHM_INCLUDE_HPP_ER_2009
#include <boost/statistics/survival/data/algorithm/events.hpp>
+#include <boost/statistics/survival/data/algorithm/failure_times.hpp>
#include <boost/statistics/survival/data/algorithm/vectorize_events.hpp>
#include <boost/statistics/survival/data/algorithm/logit_log.hpp>
#include <boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp>
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -23,7 +23,6 @@
namespace survival{
namespace data{
-
// Updates a collection of mean_events, one for each covariate value.
//
// Requirements
@@ -120,7 +119,6 @@
return (this->tuples_);
}
-
template<typename T,typename X,typename F>
template<typename It>
It mean_events_by_covariate<T,X,F>::tails(It out){
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -10,6 +10,7 @@
#include <boost/statistics/survival/data/data/event.hpp>
#include <boost/statistics/survival/data/data/mean_event.hpp>
+#include <boost/statistics/survival/data/data/mngr/include.hpp>
#include <boost/statistics/survival/data/data/record.hpp>
#endif
\ No newline at end of file
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -1,5 +1,5 @@
///////////////////////////////////////////////////////////////////////////////
-// statistics::survival::data:data::mean_event.hpp //
+// statistics::survival::data::data::mean_event.hpp //
// //
// Copyright 2009 Erwann Rogard. Distributed under the Boost //
// Software License, Version 1.0. (See accompanying file //
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -1,12 +1,12 @@
///////////////////////////////////////////////////////////////////////////////
-// statistics::survival::data::record.hpp //
+// statistics::survival::data::data::record.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_DATA_RECORDER_HPP_ER_2009
-#define BOOST_STATISTICS_SURVIVAL_DATA_RECORDER_HPP_ER_2009
+#ifndef BOOST_STATISTICS_SURVIVAL_DATA_DATA_RECORDER_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_DATA_RECORDER_HPP_ER_2009
#include <ostream>
#include <limits>
#include <boost/operators.hpp>
@@ -42,7 +42,7 @@
template<typename Archive>
void serialize(Archive & ar, const unsigned int version);
- bool operator<(const record& other);
+ bool operator<(const record& other)const;
protected:
value_type entry_time_; //t
@@ -51,9 +51,6 @@
template<typename T>
std::ostream& operator<<(std::ostream& out,const record<T>& r);
-
-template<typename T>
-bool operator<(const record<T>& a,const record<T>& b);
template<typename T>
typename record<T>::value_type
@@ -117,7 +114,7 @@
}
template<typename T>
-bool record<T>::operator<(const record<T>& other){
+bool record<T>::operator<(const record<T>& other)const{
return ( (this->entry_time()) < other.entry_time() );
}
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -7,7 +7,7 @@
///////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_STATISTICS_SURVIVAL_DATA_META_RANDOM_INPUT_HPP_ER_2009
#define BOOST_STATISTICS_SURVIVAL_DATA_META_RANDOM_INPUT_HPP_ER_2009
-#include <boost/statistics/survival/data/meta/failure_distribution.hpp>
+#include <boost/statistics/survival/data/meta/failure_random.hpp>
namespace boost{
namespace statistics{
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -27,7 +27,7 @@
// Given model and parameter, simulates records (et,ft) like this:
// et is drawn from a random clock
- // x random
+ // x is random
// ft is drawn from the p(ft|x,p,model)
//
// Models RandomDistribution
@@ -47,12 +47,13 @@
typedef typename RdX::result_type covariate_type;
typedef statistics::model::model_parameter_<M,P> model_parameter_;
- typedef statistics::model::model_covariate_parameter_<M,covariate_type,P>
+ typedef statistics
+ ::model::model_covariate_parameter_<M,covariate_type,P>
model_covariate_parameter_;
// Constructor
batch();
- batch( const M&, const P&,const RdC&,const RdX& );
+ batch( model_parameter_ mp,const RdC&,const RdX& );
batch( const batch& );
batch& operator=( const batch& );
@@ -81,8 +82,8 @@
template<
typename T,typename M,typename P, typename RdC,typename RdX,typename I>
batch<T,M,P,RdC,RdX,I>::batch(
- const M& m,const P& p, const RdC& rdc,const RdX& rdx
- ):model_parameter_(m,p),rdc_(rdc),rdx_(rdx),x_(){}
+ model_parameter_ mp, const RdC& rdc,const RdX& rdx
+ ):model_parameter_(mp),rdc_(rdc),rdx_(rdx),x_(){}
template<
typename T,typename M,typename P, typename RdC,typename RdX,typename I>
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -15,13 +15,15 @@
#include <boost/random/ref_distribution.hpp>
#include <boost/statistics/survival/data/random/batch.hpp>
-
namespace boost{
namespace statistics{
namespace survival{
namespace data{
namespace random{
+ // Same as batch, but
+ // x is drawn cyclically from a fixed set of values, referred to
+ // as "x_values", and the clock produces times at fixed intervals.
template<
typename T,
typename M,
@@ -54,27 +56,26 @@
typedef typename type::model_parameter_ mp_;
static rcov_ rcov(
- Rx& rx, // Not const Rx&? TODO see range_cycle
+ Rx& x_values, // Not const Rx&? TODO see range_cycle
size_type offset,
size_type n
){
return rcov_(
gcov_(
- meta_::make(rx,offset,n)
+ meta_::make(x_values,offset,n)
)
);
}
// rcov above must be called from outside.
static type make(
- const M& m,
- const P& p,
+ mp_ mp,
const clock_type& c,
rcov_& rcov
){
return type(
- m,p,
+ mp,
rc_(c),
ref_rcov_(
rcov
Modified: sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp
==============================================================================
--- sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp (original)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -11,5 +11,6 @@
#include <boost/statistics/survival/data/random/batch.hpp>
#include <boost/statistics/survival/data/random/default_batch.hpp>
#include <boost/statistics/survival/data/random/failure_time.hpp>
+#include <boost/statistics/survival/data/random/simulate_batches.hpp>
#endif
\ No newline at end of file
Modified: sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp
==============================================================================
--- sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp (original)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -30,16 +30,26 @@
#include <boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
-#include <boost/matrix_view/algorithm/transform_column.hpp>
#include <boost/dist_random/include.hpp>
#include <boost/statistics/model/include.hpp>
#include <boost/statistics/survival/data/include.hpp>
#include <boost/statistics/survival/model/models/exponential/include.hpp>
+#include <libs/statistics/survival/data/example/random.h>
-void example_random(std::ostream& out){
- out << "-> example_random : ";
+void example_random(
+ const unsigned& n_records, // = 1e2;
+ const unsigned& n_batches, // = 5e4;
+ const double& mu, // = 0.0;
+ const double& sigma, // = 5.0;
+ const double& t, // = 0.0
+ const double& delta_t, // = 0.0
+ const std::string& out_path,
+ std::ostream& out
+){
+ out << "-> example_random : ";
+ out.flush();
using namespace boost;
using namespace statistics;
@@ -53,161 +63,140 @@
// Each batch is saved using serialization
// Types
+ typedef std::string str_;
typedef double val_;
typedef std::vector<val_> vals_;
- typedef range_iterator<vals_>::type iter_val_;
typedef boost::mt19937 urng_;
// Covariates values
typedef val_ x_;
- typedef vals_ x_vals_;
- typedef range_cycle<> range_cycle_;
- typedef range_cycle_::apply<x_vals_>::type x_cycle_;
- typedef range_size<x_vals_>::type size_;
-
- // Survival data
- typedef surv::data::record<val_> record_;
- typedef std::vector<record_> records_;
- typedef std::vector<records_> records_batches_;
// Model
typedef math::normal_distribution<val_> mprior_;
typedef val_ par_;
- typedef std::vector<par_> pars_;
typedef surv::model::exponential::model<val_> model_;
-
- // Batch
- typedef surv::data::random::meta_default_batch<
- val_, model_, par_, x_vals_> meta_batch_;
-
- typedef meta_batch_::clock_type clock_;
- typedef meta_batch_::type batch_;
- typedef batch_::model_covariate_parameter_ mcp_;
- typedef mcp_::model_parameter_w_ mp_;
- typedef variate_generator<urng_&,batch_> vg_r; //record
+ typedef model::model_covariate_parameter_<model_,x_,par_> mcp_;
- // I/O
+ // Output
typedef boost::archive::text_oarchive oa_;
- typedef boost::archive::text_iarchive ia_;
typedef std::ofstream ofs_;
- // Failure time distribution
- typedef surv::data::meta_failure_distribution<model_> meta_fd_;
- typedef meta_fd_::type fd_;
-
// [Constants]
const unsigned k = 2; // # number x values
- const unsigned n_record = 1e2;
- const unsigned n_batch = 5e4;
- const unsigned n_ks_data = n_record/k;
- const val_ mu = 0.0;
- const val_ sigma = 5.0;
- const clock_ clock(0.0,0.0);
+ const unsigned n_ks_data = n_records/k;
- BOOST_ASSERT( n_record % k == 0 );
- BOOST_ASSERT( n_ks_data % (n_record/k) == 0 );
+ BOOST_ASSERT( n_records % k == 0 );
+ BOOST_ASSERT( n_ks_data % (n_records/k) == 0 );
// [ os ]
- const char* prior_path = "./prior";
- const char* x_vals_path = "./x_vals";
- const char* ks_path = "./ks_data";
- const char* batches_path = "./batches";
- const char* pars_path = "./pars";
+ const str_ prior_path = out_path + "prior";
+ const str_ ks_path = out_path + "ks_data";
+ const str_ xpm_mngr_path = out_path + "covariates_prior_model_mngr";
+ const str_ pr_mngrs_path = out_path + "par_records_mngrs_path";
- // [ Covariate values ]
- vals_ x_vals;
+ // [ covariates - model ]
+ typedef surv::data::default_covariates_model_mngr<x_,model_>
+ xm_mngr_;
+ typedef surv::data::default_covariates_prior_model_mngr<x_,mprior_,model_>
+ xpm_mngr_;
+ typedef surv::data::default_parameter_records_mngr<val_,par_>
+ pr_mngr_;
+
+ mprior_ mprior( mu, sigma );
+
+ xm_mngr_ xm_mngr;
+ xpm_mngr_ xpm_mngr;
{
- using namespace boost::assign;
- x_vals += -0.5, 0.5;
+ vals_ x_vals;
+ {
+ using namespace boost::assign;
+ x_vals += -0.5, 0.5;
+ }
+ BOOST_ASSERT(size(x_vals) == k);
+ typedef xpm_mngr_::prior_model_wrapper_type pm_;
+ xpm_mngr = xpm_mngr_(
+ boost::begin( x_vals ),
+ boost::end( x_vals ),
+ pm_(mprior,model_())
+ );
}
- BOOST_ASSERT(size(x_vals) == k);
-
{
- ofs_ ofs(x_vals_path);
+ ofs_ ofs(xpm_mngr_path.c_str());
oa_ oa(ofs);
- oa << x_vals;
+ oa << xpm_mngr;
ofs.flush();
ofs.close();
}
+ // [ par_records_mngr ]
+ pr_mngr_ pr_mngr;
+
// [ Initialization ]
- model_ model;
- mprior_ mprior( mu, sigma );
urng_ urng;
- {
- ofs_ ofs(prior_path);
- oa_ oa(ofs);
- BOOST_AUTO(prim,make_distribution_primitives(mprior));
- oa << prim;
- ofs.flush();
- ofs.close();
- }
// Buffers
- records_ records; records.reserve(n_record);
- pars_ true_pars; true_pars.reserve(n_batch);
vals_ kss;
kss.reserve(n_ks_data); // kolmogorov-smirnov
- vals_ fts; fts.reserve(n_record / k); // failure times
- vals_ pars; pars.reserve(n_record);
+ vals_ fts; fts.reserve(n_records / k); // failure times
+
+ {
+ ofs_ ofs_pr_mngrs(pr_mngrs_path.c_str());
+ surv::data::simulate_batches(
+ ofs_pr_mngrs,
+ xpm_mngr,
+ n_batches,
+ n_records,
+ t,
+ delta_t,
+ urng
+ );
+ }
+
+/*
{
// Simulate batches of records
- ofs_ ofs_ks(ks_path);
- ofs_ ofs_batches(batches_path);
- ofs_ ofs_pars(pars_path);
- oa_ oa_batches(ofs_batches);
- oa_ oa_pars(ofs_pars);
+ ofs_ ofs_ks(ks_path.c_str());
+ ofs_ ofs_pr_mngrs(pr_mngrs_path.c_str());
+ oa_ oa_pr_mngrs(ofs_pr_mngrs);
ofs_ks << "first and last ks of the failure times : " << std::endl;
- for(unsigned i = 0; i<n_batch; i++){
- records.clear();
+ for(unsigned i = 0; i<n_batches; i++){
+ //records.clear();
par_ par = boost::sample(mprior,urng);
- oa_pars << par;
- ofs_pars.flush();
- meta_batch_::rcov_ r_x = meta_batch_::rcov(
- x_vals,
- 0,
- n_record
- );
- batch_ batch = meta_batch_::make(
- model,
- par,
- clock,
- r_x
- );
- true_pars.push_back( par );
- vg_r vg_r( urng, batch );
- std::generate_n(
- std::back_inserter( records ),
- n_record,
- vg_r
+ pr_mngr.clear_records();
+ pr_mngr.set_parameter( par );
+ pr_mngr.back_generate(
+ n_records,
+ xm_mngr,
+ t,
+ delta_t,
+ urng
);
- BOOST_ASSERT(
- is_sorted(
- boost::begin( records ),
- boost::end( records )
- )
- );// clock is supposed to tick forward
-
- oa_batches << records;
+ {
+ oa_pr_mngrs << pr_mngr;
+ }
+ // Verify that the empirical distribution of failure times agrees
+ // with their assumed distribution
+ typedef surv::data::meta_failure_distribution<model_> meta_fd_;
+ typedef meta_fd_::type fd_;
if(n_ks_data>0){
ofs_ks << (format("batch %1%, ")%i).str() << std::endl;
for(unsigned i = 0; i<k; i++){
ofs_ks << (format("x[%1%] : ")%i).str();
fts.clear();
- matrix_view::transform_column<k>(
- boost::begin(records),
- boost::end(records),
+
+ surv::data::failure_times<k>(
+ boost::begin(pr_mngr.records()),
+ boost::end(pr_mngr.records()),
i,
- lambda::bind(&record_::failure_time,lambda::_1),
std::back_inserter(fts)
);
mcp_ mcp(
- batch.model(),
- x_vals[i],
- batch.parameter()
+ xm_mngr.model_wrapper(),
+ xm_mngr.x_values()[i],
+ par
);
fd_ fail_dist = surv::data::make_failure_distribution(mcp);
@@ -222,7 +211,7 @@
);
if(n_ks_data>1){
- // Desired result: kss[0] < kss.back();
+ // Desired result: kss[0] > kss.back();
ofs_ks << kss[0] << ',' << kss.back();
}
ofs_ks << std::endl;
@@ -231,7 +220,8 @@
}
} // batch loop
ofs_ks.close();
- ofs_pars.close();
- ofs_batches.close();
+ ofs_pr_mngrs.close();
} // records generation
+*/
+
}
\ No newline at end of file
Modified: sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h
==============================================================================
--- sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h (original)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -7,7 +7,18 @@
///////////////////////////////////////////////////////////////////////////////
#ifndef LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
#define LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
+#include <ostream>
+#include <string>
-void example_random(std::ostream& out);
+void example_random(
+ const unsigned& n_record, // = 1e2;
+ const unsigned& n_batch, // = 5e4;
+ const double& mu, // = 0.0;
+ const double& sigma, // = 5.0;
+ const double& t, // = 0.0
+ const double& delta_t, // = 0.0
+ const std::string& out_path,
+ std::ostream& out
+);
#endif
\ No newline at end of file
Modified: sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp
==============================================================================
--- sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp (original)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp 2009-10-23 10:55:20 EDT (Fri, 23 Oct 2009)
@@ -12,8 +12,19 @@
int main(){
- example_data(std::cout);
- example_random(std::cout);
+ //example_data(std::cout);
+ {
+ example_random(
+ 1e2,
+ 5e4,
+ 0.0,
+ 5.0,
+ 0.0,
+ 0.0,
+ "/Users/erwann/projets/2009/Xcode/survival/build/Release/",
+ std::cout
+ );
+ }
return 0;
}
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