|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55945 - in sandbox/statistics/survival_data: . boost boost/statistics boost/statistics/survival boost/statistics/survival/data boost/statistics/survival/data/algorithm boost/statistics/survival/data/algorithm/detail boost/statistics/survival/data/data boost/statistics/survival/data/meta boost/statistics/survival/data/random libs libs/statistics libs/statistics/survival libs/statistics/survival/data libs/statistics/survival/data/doc libs/statistics/survival/data/example libs/statistics/survival/data/src
From: erwann.rogard_at_[hidden]
Date: 2009-08-31 21:57:45
Author: e_r
Date: 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
New Revision: 55945
URL: http://svn.boost.org/trac/boost/changeset/55945
Log:
re-adding survival_data, but preceded by dir statistics
Added:
sandbox/statistics/survival_data/
sandbox/statistics/survival_data/boost/
sandbox/statistics/survival_data/boost/statistics/
sandbox/statistics/survival_data/boost/statistics/survival/
sandbox/statistics/survival_data/boost/statistics/survival/constant.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/detail/
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/detail/log_shift.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/events.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/logit_log.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/vectorize_events.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/data/
sandbox/statistics/survival_data/boost/statistics/survival/data/data/event.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/include.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_distribution.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_random.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/include.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/random/
sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/random/failure_time.hpp (contents, props changed)
sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp (contents, props changed)
sandbox/statistics/survival_data/libs/
sandbox/statistics/survival_data/libs/statistics/
sandbox/statistics/survival_data/libs/statistics/survival/
sandbox/statistics/survival_data/libs/statistics/survival/data/
sandbox/statistics/survival_data/libs/statistics/survival/data/doc/
sandbox/statistics/survival_data/libs/statistics/survival/data/doc/readme.txt (contents, props changed)
sandbox/statistics/survival_data/libs/statistics/survival/data/example/
sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.cpp (contents, props changed)
sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.h (contents, props changed)
sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp (contents, props changed)
sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h (contents, props changed)
sandbox/statistics/survival_data/libs/statistics/survival/data/src/
sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp (contents, props changed)
Added: sandbox/statistics/survival_data/boost/statistics/survival/constant.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/constant.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::constant.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_CONSTANT_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_CONSTANT_HPP_ER_2009
+#include <limits>
+#include <iostream>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+
+ template<typename T>
+ struct constant{
+ typedef numeric::converter<T,unsigned> conv_t;
+ static T zero_;
+ static T eps_;
+ static T one_;
+ static T two_;
+ static T lmin_; //exp(lmin_)>eps
+ static T lmax_; //exp(lmax_)<inf
+ static T inf_;
+ static T quiet_nan_;
+ static T sig_nan_;
+ };
+ template<typename T>
+ T constant<T>::zero_ = conv_t::convert(0);
+ template<typename T>
+ T constant<T>::eps_ = boost::math::tools::epsilon<T>();
+ template<typename T>
+ T constant<T>::one_ = conv_t::convert(1);
+ template<typename T>
+ T constant<T>::two_ = conv_t::convert(2);
+ template<typename T>
+ T constant<T>::lmin_ = math::tools::log_min_value<T>();
+ template<typename T>
+ T constant<T>::lmax_ = math::tools::log_max_value<T>();
+ template<typename T>
+ T constant<T>::inf_ = std::numeric_limits<T>::infinity();
+ template<typename T>
+ T constant<T>::quiet_nan_ = std::numeric_limits<T>::quiet_NaN();
+ template<typename T>
+ T constant<T>::sig_nan_ = std::numeric_limits<T>::signaling_NaN();
+
+}// survival
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/detail/log_shift.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/detail/log_shift.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,43 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::log_shift.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_ALGORITHM_DETAIL_LOG_SHIFT_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORITHM_DETAIL_LOG_SHIFT_HPP_ER_2009
+#include <boost/math/special_functions/log1p.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+namespace detail{
+
+ template<typename T>
+ T log_shift(
+ const T& x,
+ const T& t
+ ){
+ return log(x+t);
+ }
+
+ template<typename T>
+ T logit_shift(
+ const T& p,
+ const T& t
+ ){
+ // log(p/(1-p)) = log(p)-log(1-p)
+
+ return log_shift(p,t) - boost::math::log1p(t - p);
+ }
+
+
+}// detail
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/events.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/events.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,67 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::events.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_ALGORITHM_EVENTS_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORITHM_EVENTS_HPP_ER_2009
+#include <algorithm>
+#include <ext/algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/statistics/survival/data/data/record.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+ // Converts sorted records to events excluding those that are past
+ // entry_bound
+ template<typename ItR,typename T,typename ItE>
+ ItE events(
+ ItR b_r,
+ ItR e_r,
+ const T& entry_bound,
+ ItE out
+ ){
+ BOOST_ASSERT(
+ is_sorted(
+ b_r,
+ e_r
+ )
+ );
+ typedef typename iterator_value<ItR>::type record_;
+ typedef typename record_::value_type val_;
+ typedef event<val_> event_;
+
+ ItR i = std::lower_bound(
+ b_r,
+ e_r,
+ record_(static_cast<val_>(entry_bound))
+ );
+
+ typedef event_ (*ptr_)(const record_&,val_);
+ ptr_ f = make_event;
+
+ return std::transform(
+ b_r,
+ i,
+ out,
+ lambda::bind(
+ f,
+ lambda::_1,
+ entry_bound
+ )
+ );
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/include.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::include.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_ALGORTIHM_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORTIHM_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/survival/data/algorithm/events.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>
+
+#endif
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/logit_log.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/logit_log.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,50 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::logit_log.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_ALGORITHM_LOGIT_LOG_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORITHM_LOGIT_LOG_HPP_ER_2009
+#include <stdexcept>
+#include <iterator>
+#include <boost/format.hpp>
+#include <boost/statistics/survival/data/algorithm/detail/log_shift.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+// Transforms an alternating sequence of (usually mean) failures
+// and event times to their logit and log, with an offset that prevents nan.
+//
+// The rationale for a logit is that 0<= mean failure <=1
+template<typename It,typename ItO,typename T>
+ItO logit_log(
+ It b, // Alternating sequence, f[0],t[0],f[1],t[1],...
+ It e,
+ ItO o, // Output iterator
+ T t0,
+ T t1
+){
+ static const char* str = "logit_log : distance(b,e) = %1% mod 2 !=2";
+
+ if( std::distance(b,e)%2 != 0 ){
+ format f(str); f%distance(b,e);
+ throw std::runtime_error(f.str());
+ }
+ while(b!=e){
+ (*o++) = detail::logit_shift((*b++),t0);
+ (*o++) = detail::log_shift((*b++),t1);
+ }
+ return o;
+}
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/mean_events_by_covariate.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,139 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::mean_events_by_covariate.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_ALGORITHM_MEAN_EVENTS_BY_COVARIATE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORITHM_MEAN_EVENTS_BY_COVARIATE_HPP_ER_2009
+#include <vector>
+#include <boost/foreach.hpp>
+#include <boost/utility.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/statistics/survival/data/data/mean_event.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/functional/find.hpp>
+#include <boost/binary_op/functional/match_accumulator.hpp>
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <boost/binary_op/algorithm/heads.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+
+ // Updates a collection of mean_events, one for each covariate value.
+ //
+ // Requirements
+ // Let [b_x1,e_x1) denote a sequence of covariate values.
+ // i = f(b_x1,e_x1,x) must be in [b_x1,e_x1].
+ //
+ // If i == e_x1, x is put at the end to [b_x1,e_x1)
+ //
+ // Another valid choice for F is nn1::find
+ template<typename T,typename X,typename F = functional::find>
+ class mean_events_by_covariate{
+ public:
+ typedef mean_event<T> mean_event_;
+ typedef tuple<X,mean_event_> tuple_;
+ typedef std::vector<tuple_> tuples_type;
+
+ // Construct
+ mean_events_by_covariate();
+ template<typename Rx> mean_events_by_covariate(const Rx&);
+ template<typename Rx> mean_events_by_covariate(const Rx&,const F& f);
+ mean_events_by_covariate(const mean_events_by_covariate&);
+ mean_events_by_covariate& operator=(const mean_events_by_covariate&);
+
+ // Update
+ template<typename ItX,typename ItE>
+ void operator()(ItX b_x, ItX e_x, ItE b_e);
+
+ // Acces
+ const tuples_type& tuples()const;
+ template<typename It> It tails(It out); // copies the mean_events
+
+ private:
+ F finder_;
+ tuples_type tuples_;
+ template<typename Rx>
+ void set_covs(const Rx& rx);
+ };
+
+ // Implementation //
+
+ template<typename T,typename X,typename F>
+ mean_events_by_covariate<T,X,F>::mean_events_by_covariate(){}
+
+ template<typename T,typename X,typename F>
+ template<typename Rx>
+ mean_events_by_covariate<T,X,F>::mean_events_by_covariate(const Rx& rx)
+ :finder_(){
+ this->set_covs(rx);
+ }
+
+ template<typename T,typename X,typename F>
+ template<typename Rx>
+ mean_events_by_covariate<T,X,F>::mean_events_by_covariate(
+ const Rx& rx,const F& f)
+ :finder_(f){
+ this->set_covs(rx);
+ }
+
+ template<typename T,typename X,typename F>
+ template<typename Rx>
+ void mean_events_by_covariate<T,X,F>::set_covs(const Rx& rx){
+ typedef typename range_value<Rx>::type x_;
+ mean_event_ me;
+ BOOST_FOREACH(const x_& x,rx){
+ tuple_ t(x,me);
+ tuples_.push_back( t );
+ }
+ }
+
+ template<typename T,typename X,typename F>
+ template<typename ItX,typename ItE>
+ void mean_events_by_covariate<T,X,F>::operator()(ItX b_x,ItX e_x,ItE b_e)
+ {
+ typedef binary_op::match_accumulator<tuples_type&,F> functor_;
+ std::for_each(
+ make_zip_iterator( make_tuple( b_x, b_e ) ),
+ make_zip_iterator(
+ make_tuple(
+ e_x,
+ boost::next(
+ b_e,
+ std::distance(b_x,e_x)
+ )
+ )
+ ),
+ functor_(this->tuples_)
+ );
+ }
+
+ // Access
+ template<typename T,typename X,typename F>
+ const typename mean_events_by_covariate<T,X,F>::tuples_type&
+ mean_events_by_covariate<T,X,F>::tuples()const{
+ return (this->tuples_);
+ }
+
+
+ template<typename T,typename X,typename F>
+ template<typename It>
+ It mean_events_by_covariate<T,X,F>::tails(It out){
+ return binary_op::tails(
+ boost::begin(this->tuples()),
+ boost::end(this->tuples()),
+ out
+ );
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/vectorize_events.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/algorithm/vectorize_events.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::algorithm::make_mean_events.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_ALGORITHM_VECTORIZE_EVENTS_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_ALGORITHM_VECTORIZE_EVENTS_HPP_ER_2009
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+// Copies the failure and event time of each event in a sequence to an
+// output iterator
+template<typename ItE,typename ItO>
+ItO vectorize_events(
+ ItE b,
+ ItE e,
+ ItO o
+);
+
+ // Implementation //
+
+template<typename ItE,typename ItO>
+ItO vectorize_events(
+ ItE b,
+ ItE e,
+ ItO o
+){
+ typedef typename iterator_value<ItE>::type event_;
+ typedef typename event_::value_type val_;
+ typedef typename event_::failure_type fail_;
+ BOOST_MPL_ASSERT((
+ is_same<val_,fail_>
+ ));
+
+ while(b!=e){
+ *o = (b->failure()); ++o;
+ *o = (b->time()); ++o;
+ ++b;
+ }
+ return o;
+}
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/data/event.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/event.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,129 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::data::event.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_DATA_EVENT_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_DATA_EVENT_HPP_ER_2009
+#include <limits>
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/operators.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/statistics/survival/constant.hpp>
+#include <boost/arithmetic/equal.hpp>
+
+namespace boost {
+namespace statistics{
+namespace survival {
+namespace data {
+
+ // Abstraction for failure indicator and event time.
+ //
+ // B == T can be useful to represent a proportion of failures (see
+ // mean_event)
+ template<typename T,typename B = bool>
+ class event : equality_comparable<event<T,B> >{
+ typedef constant<T> const_;
+ public:
+ typedef T value_type;
+ typedef B failure_type;
+ // Construction
+ event(); // (f = false, t = infinity)
+ explicit event(B isf,value_type rt);
+ event(const event&);
+ event& operator=(const event&);
+
+ // Access
+ B failure()const;
+ value_type time()const;
+
+ // Operators
+ bool operator==(const event&);
+
+ protected:
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version);
+
+ B failure_; //!censored
+ value_type time_; //since entry time
+ };
+
+
+ template<typename T,typename B>
+ std::ostream& operator<<(std::ostream& out,const event<T,B>& e);
+
+ // Implementation //
+
+
+ //Construct
+ template<typename T,typename B>
+ event<T,B>::event():failure_(false),time_(const_::inf_){}
+
+ template<typename T,typename B>
+ event<T,B>::event(B isf,value_type rt)
+ :failure_(isf),time_(rt){}
+
+ template<typename T,typename B>
+ event<T,B>::event(const event& that)
+ :failure_(that.failure_),time_(that.time_){}
+
+ template<typename T,typename B>
+ event<T,B>&
+ event<T,B>::operator=(const event& that){
+ if(&that!=this){
+ failure_ = (that.failure_);
+ time_ = (that.time_);
+ }
+ return *this;
+ }
+
+ template<typename T,typename B>
+ std::ostream& operator<<(std::ostream& out,const event<T,B>& e){
+ static const char* str = "(%1%,%2%)";
+ format f(str);
+ f % e.failure() % e.time();
+ out << f.str();
+ return out;
+ }
+
+ template<typename T,typename B>
+ B event<T,B>::failure()const{ return failure_; }
+
+ template<typename T,typename B>
+ typename event<T,B>::value_type event<T,B>::time()const{
+ return time_;
+ }
+
+ template<typename T,typename B>
+ template<class Archive>
+ void event<T,B>::serialize(Archive & ar, const unsigned int version)
+ {
+ ar & failure_;
+ ar & time_;
+ }
+
+ // Operators
+ template<typename T,typename B>
+ bool event<T,B>::operator==(const event& e){
+ bool eq_1 = arithmetic_tools::equal(
+ e.time(),
+ (this->time())
+ );
+ bool eq_2 = arithmetic_tools::equal(
+ (this->failure_) , (e.failure())
+ );
+ return (eq_1 && eq_2);
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/include.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::data::include.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_DATA_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/survival/data/data/event.hpp>
+#include <boost/statistics/survival/data/data/mean_event.hpp>
+#include <boost/statistics/survival/data/data/record.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/mean_event.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,207 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data:data::mean_event.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_DATA_MEAN_EVENT_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_DATA_MEAN_EVENT_HPP_ER_2009
+#include <stdexcept>
+#include <boost/type_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/operators.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/statistics/survival/constant.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+
+ // This class can be used to accumulate the proportion of failures and
+ // mean event time in a sequence of events.
+ //
+ // In the case of the exponential, a collection of mean_events can
+ // form a sufficient statistic, assuming a discretized domain for
+ // the covariate: domain(x) = {x[k]:k=0,...,K-1}
+ //
+ // $\log L_i(\beta) = \nu_i \eta_i - t_i \exp(\eta_i)$
+ // where $\eta_i = \langle x_i,beta \rangle$
+ // log L(D,\beta) = sum{
+ // <x[k],\beta> sum{\nu[i]:x[i]==x[k]}
+ // -exp(<x[k],\beta>) sum{t[i] : x[i]==x[k]}
+ // :k=1,...,K
+ // }
+ // Sufficient statistic:
+ // {(sum{\nu[i]:x[i]==x[k]},sum{t[i] : x[i]==x[k]}):k=0,...,K-1}
+ template<typename T,typename B = bool>
+ class mean_event :
+ public event<T,T>,
+ boost::addable<
+ mean_event<T,B>,
+ addable<event<T,B> >
+ >
+ // TODO equality_comparable<mean_event<T,B> >
+ {
+ public:
+ typedef event<T,B> event_;
+ typedef event<T,T> super_;
+ typedef typename super_::value_type value_type;
+ typedef std::size_t size_type;
+
+ // Construction
+ mean_event();
+ mean_event(const event_&);
+ mean_event(const mean_event&);
+ mean_event& operator=(const mean_event&);
+
+ // Access
+ size_type count()const;
+
+ // Operators
+ mean_event& operator+=( const mean_event& e );
+ mean_event& operator+=( const event_& e );
+ mean_event& operator()( const event_& e ); //same as +=
+
+ // I/O
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int version);
+
+ private:
+ value_type impl(size_type n_a,value_type a,size_type n_b,value_type b);
+ size_type count_;
+ static super_ convert(const event_&);
+ };
+
+ template<typename T,typename B>
+ std::ostream& operator<<(std::ostream& out,const mean_event<T,B>& e);
+
+ template<typename E>
+ struct meta_mean_event{
+ typedef typename E::value_type value_type;
+ typedef mean_event<value_type> type;
+ };
+
+
+ // Implementation //
+
+ // Constructor
+ template<typename T,typename B>
+ mean_event<T,B>::mean_event()
+ :super_(static_cast<T>(false),static_cast<T>(0)),
+ count_(0){
+ // Using super_() instead, would initialize time to inf.
+ }
+
+ template<typename T,typename B>
+ mean_event<T,B>::mean_event(const event_& e)
+ :super_(convert(e)),count_(1){
+ const char* msg = "mean_event::mean_event(e), isinf(e.time())";
+ if(math::isinf(this->time())){
+ throw std::runtime_error(
+ msg
+ );
+ }
+ }
+
+ template<typename T,typename B>
+ mean_event<T,B>::mean_event(const mean_event& that)
+ :super_(that),count_(that.count_){}
+
+ template<typename T,typename B>
+ mean_event<T,B>&
+ mean_event<T,B>::operator=(const mean_event& that){
+ if(&that!=this){
+ super_::operator=( that );
+ count_ = that.count_;
+ }
+ return *this;
+ }
+
+ // Access
+ template<typename T,typename B>
+ typename mean_event<T,B>::size_type
+ mean_event<T,B>::count()const{ return count_; }
+
+ // Update
+ template<typename T,typename B>
+ mean_event<T,B>&
+ mean_event<T,B>::operator+=(const event_& e){
+ mean_event other(e);
+ return ( (*this) += other );
+ }
+
+ template<typename T,typename B>
+ mean_event<T,B>&
+ mean_event<T,B>::operator+=(const mean_event& other){
+ size_type n_a = this->count();
+ size_type n_b = other.count();
+ (this->failure_)
+ = (this->impl(n_a,this->failure(),n_b,other.failure()));
+ (this->time_)
+ = (this->impl(n_a,this->time(),n_b,other.time()));
+ (this->count_) += n_b;
+ return *this;
+ }
+
+ template<typename T,typename B>
+ mean_event<T,B>&
+ mean_event<T,B>::operator()(const event_& e){
+ return (*this)+=e;
+ }
+
+ //Private
+ template<typename T,typename B>
+ template<class Archive>
+ void mean_event<T,B>::serialize(Archive & ar, const unsigned int version)
+ {
+ ar & boost::serialization::base_object<super_>(*this);
+ ar & count_;
+ }
+
+ template<typename T,typename B>
+ typename mean_event<T,B>::value_type
+ mean_event<T,B>::impl(
+ size_type n_a,
+ value_type a,
+ size_type n_b,
+ value_type b
+ ){
+ return ( (n_a * a) + (n_b * b) ) / (n_a + n_b);
+ }
+
+ template<typename T,typename B>
+ std::ostream& operator<<(std::ostream& out,const mean_event<T,B>& that){
+ typedef mean_event<T,B> that_;
+ typedef typename that_::super_ super_;
+ static const char* str = "(%1%,%2%)";
+ format f(str);
+ f % that.count() % static_cast<const super_&>(that) ;
+ out << f.str();
+ return out;
+ }
+
+ template<typename T,typename B>
+ typename mean_event<T,B>::super_
+ mean_event<T,B>::convert(const event_& e){
+ static value_type zero = static_cast<value_type>(0);
+ static value_type one = static_cast<value_type>(1);
+ value_type t = e.time();
+ if(e.failure()){
+ return super_( one, t );
+ }else{
+ return super_( zero, t );
+ }
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/data/record.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,159 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::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
+#include <ostream>
+#include <limits>
+#include <boost/operators.hpp>
+#include <boost/format.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //isinf
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/statistics/survival/constant.hpp>
+#include <boost/statistics/survival/data/data/event.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+// Abstraction for entry time (t) and the failure time (rt).
+//
+// If not set during initialization, the failure time can be set later.
+template<typename T>
+class record : less_than_comparable<record<T> >{
+protected:
+ typedef constant<T> const_;
+public:
+ typedef T value_type;
+ record(); //inf,inf
+ record(value_type t);
+ record(value_type t, value_type rt);
+ // default copy/assign
+ void set_failure_time(value_type rt);
+ value_type entry_time()const;
+ value_type failure_time()const;
+
+ template<typename Archive>
+ void serialize(Archive & ar, const unsigned int version);
+
+ bool operator<(const record& other);
+
+protected:
+ value_type entry_time_; //t
+ value_type failure_time_; //rt
+};
+
+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
+time_since_entry(const record<T>& r, typename record<T>::value_type t);
+
+// TODO is_at_risk
+
+template<typename T>
+event<T> make_event(const record<T>& r, typename record<T>::value_type t);
+
+ // Implementation //
+
+// Construct
+template<typename T>
+record<T>::record():entry_time_(const_::inf_),failure_time_(const_::inf_){}
+
+template<typename T>
+record<T>::record(value_type t):entry_time_(t),failure_time_(const_::inf_){}
+
+template<typename T>
+record<T>::record(value_type t,value_type rt)
+:entry_time_(t),failure_time_(rt){}
+
+// Assign
+template<typename T>
+void record<T>::set_failure_time(value_type rt){
+ static const char* method = "statistics::survival::record::set_failure_time(%1%)";
+ if(math::isinf(this->failure_time_)){
+ this->failure_time_ = rt;
+ }else{
+ static const char* err = " error : overriding failure time";
+ throw exception(
+ format(method,rt).str(),
+ err,
+ *this
+ );
+ }
+}
+
+template<typename T>
+template<typename Archive>
+void record<T>::serialize(Archive & ar, const unsigned int version){
+ ar & entry_time_;
+ ar & failure_time_;
+}
+
+// Access
+
+template<typename T>
+typename record<T>::value_type
+record<T>::entry_time()const{ return entry_time_; }
+
+template<typename T>
+typename record<T>::value_type
+record<T>::failure_time()const{ return failure_time_; }
+
+template<typename T>
+std::ostream& operator<<(std::ostream& out,const record<T>& r){
+ out << '(' << r.entry_time() << ',' << r.failure_time() << ')';
+ return out;
+}
+
+template<typename T>
+bool record<T>::operator<(const record<T>& other){
+ return ( (this->entry_time()) < other.entry_time() );
+}
+
+template<typename T>
+typename record<T>::value_type
+time_since_entry(const record<T>& r, typename record<T>::value_type t)
+{
+ //Warning may be <0
+ return t-r.entry_time();
+}
+
+// TODO is_at_risk
+
+template<typename T>
+event<T> make_event(const record<T>& r, typename record<T>::value_type t){
+ static const char* fun = "statistics::survival::make_event(%1%,%2)";
+ typedef typename record<T>::value_type value_t;
+ value_t eps = math::tools::epsilon<T>();
+ value_t dt = time_since_entry(r,t);
+ if(dt>eps){
+ typedef event<T> result_type;
+ bool b = ( r.failure_time() <= dt );
+ value_t rt = b ? r.failure_time() : dt;
+ return result_type(b, rt);
+ }else{
+ static const char* err = "error: time_since_entry = %1%";
+ format f(fun); f%r%t;
+ std::string str = f.str();
+ f = format(err); f%dt; str+= f.str();
+ throw std::runtime_error( str );
+ }
+}
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/include.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,17 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::include.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_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/survival/constant.hpp>
+#include <boost/statistics/survival/data/algorithm/include.hpp>
+#include <boost/statistics/survival/data/data/include.hpp>
+#include <boost/statistics/survival/data/meta/include.hpp>
+#include <boost/statistics/survival/data/random/include.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_distribution.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::meta::failure_distribution.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_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#include <boost/statistics/model/wrap/aggregate/model_covariate_parameter.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+ // Model + Covariate + Parameter ---> failure time distribution (such as
+ // defined in boost/math/distributions)
+ //
+ // These are only declarations. The implementation must specialize on M.
+ template<typename M>
+ struct meta_failure_distribution{
+ // typedef ... type
+ };
+
+ template<typename M,typename X,typename P>
+ typename meta_failure_distribution<M>::type
+ make_failure_distribution(
+ boost::statistics::model::model_covariate_parameter_<M,X,P> mcp
+ ){
+ typedef meta_failure_distribution<M> meta_;
+ return meta_::make(
+ mcp
+ );
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/meta/failure_random.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,53 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::meta::failure_random.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_META_FAILURE_RANDOM_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_META_FAILURE_RANDOM_HPP_ER_2009
+#include <boost/dist_random/include.hpp>
+#include <boost/statistics/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/statistics/survival/data/meta/failure_distribution.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+
+ // Model + Covariate + Parameter ---> RandomDistribution (of failure time)
+ //
+ // These are default implementations that can be overloaded with a
+ // specialization on M
+
+ template<typename M>
+ struct meta_failure_random{
+ typedef meta_failure_distribution<M> map1_;
+ typedef typename map1_::type dist_;
+ typedef boost::dist_random<dist_> map2_;
+ typedef typename map2_::type type;
+ };
+
+ template<typename M,typename X,typename P>
+ typename meta_failure_random<M>::type
+ make_failure_random(boost::statistics::model::model_covariate_parameter_<M,X,P>);
+
+ // Implementation //
+
+ template<typename M,typename X,typename P>
+ typename meta_failure_random<M>::type
+ make_failure_random(boost::statistics::model::model_covariate_parameter_<M,X,P> mcp){
+ typedef meta_failure_random<M> map_;
+ typedef typename map_::map2_ map2_;
+ return map2_::make(
+ make_failure_distribution(mcp)
+ );
+ }
+
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/meta/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/meta/include.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::meta::include.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_META_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_META_INCLUDE_HPP_ER_2009
+
+#include <boost/statistics/survival/data/meta/failure_distribution.hpp>
+#include <boost/statistics/survival/data/meta/failure_random.hpp>
+#include <boost/statistics/survival/data/meta/random_input.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/meta/random_input.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,34 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::meta::random_input.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_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>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+namespace meta{
+
+ // Model + Covariate + Parameter ---> InputType
+ //
+ // This is a default implementation that can be overriden with a specializ-
+ // ation on M.
+ template<typename M>
+ struct random_input{
+ typedef typename meta_failure_random<M>::type rdist_;
+ typedef typename rdist_::input_type type;
+ };
+
+}// meta
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/batch.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,153 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::random::batch.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_RANDOM_BATCH_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_RANDOM_BATCH_HPP_ER_2009
+#include <iostream> // TODO remove
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/gen_to_random.hpp>
+#include <boost/statistics/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/statistics/survival/data/data/record.hpp>
+#include <boost/statistics/survival/data/random/failure_time.hpp>
+#include <boost/statistics/survival/data/meta/random_input.hpp>
+
+#include <boost/iterator/range_cycle.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+namespace random{
+
+ // Given model and parameter, simulates records (et,ft) like this:
+ // et is drawn from a random clock
+ // x random
+ // ft is drawn from the p(ft|x,p,model)
+ //
+ // Models RandomDistribution
+ template<
+ typename T, // float
+ typename M, // model
+ typename P, // parameter
+ typename RdC, // RandomDistribution // clock
+ typename RdX, // RandomDistribution // covariate
+ typename I = typename meta::random_input<M>::type
+ >
+ class batch : public model::model_parameter_<M,P>{
+ public:
+ typedef T value_type;
+ typedef I input_type;
+ typedef record<value_type> result_type;
+ typedef typename RdX::result_type covariate_type;
+
+ typedef model::model_parameter_<M,P> model_parameter_;
+ typedef model::model_covariate_parameter_<M,covariate_type,P>
+ model_covariate_parameter_;
+
+ // Constructor
+ batch();
+ batch( const M&, const P&,const RdC&,const RdX& );
+ batch( const batch& );
+ batch& operator=( const batch& );
+
+ // Random generation
+ template<typename U>
+ result_type operator()(U& u);
+
+ // Access
+ const covariate_type& covariate()const; //last generated covariate
+
+ private:
+ RdC rdc_;
+ RdX rdx_;
+ covariate_type x_;
+ template<typename U> void gen_x(U&);
+ };
+
+
+ // Implementation //
+
+ //Construction
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ batch<T,M,P,RdC,RdX,I>::batch():model_parameter_(){}
+
+ 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_(){}
+
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ batch<T,M,P,RdC,RdX,I>::batch(
+ const batch& that
+ ):model_parameter_(that),rdc_(that.rdc_),rdx_(that.rdx_),x_(that.x_){}
+
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ batch<T,M,P,RdC,RdX,I>&
+ batch<T,M,P,RdC,RdX,I>::operator=(
+ const batch& that
+ ){
+ if(&that!=this){
+ model_parameter_::operator=( that.model_parameter );
+ rdc_ = (that.rdc_);
+ rdx_ = (that.rdx_);
+ x_ = that.x_;
+ }
+ return (*this);
+ }
+
+ // Generation
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ template<typename U>
+ typename batch<T,M,P,RdC,RdX,I>::result_type
+ batch<T,M,P,RdC,RdX,I>::operator()(U& u){
+ this->gen_x(u);
+ value_type et = (this->rdc_)(u); //entry time
+ BOOST_ASSERT(!( et < static_cast<value_type>(0) ) );
+ const model_parameter_& mp
+ = static_cast<const model_parameter_&>(*this);
+ value_type ft = random::failure_time<value_type>(
+ boost::statistics::model::make_model_covariate_parameter(
+ mp.model(),
+ this->covariate(),
+ mp.parameter()
+ ),
+ u
+ );
+ return result_type(et,ft);
+ }
+
+ // Access
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ const typename batch<T,M,P,RdC,RdX,I>::covariate_type&
+ batch<T,M,P,RdC,RdX,I>::covariate()const{ return this->x_; }
+
+ // Private
+ template<
+ typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+ template<typename U>
+ void batch<T,M,P,RdC,RdX,I>::gen_x(U& urng){
+ typedef variate_generator<U&,RdX> vg_;
+ // Necessary in the likely case that RdX::input_type != I
+ vg_ vg(urng,rdx_);
+ this->x_ = vg();
+ }
+
+}// random
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/default_batch.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,93 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::random::default_batch.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_RANDOM_DEFAULT_BATCH_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_RANDOM_DEFAULT_BATCH_HPP_ER_2009
+#include <boost/random/gen_to_random.hpp>
+#include <boost/functional/clock.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/functional/visitor.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <boost/random/ref_distribution.hpp>
+#include <boost/statistics/survival/data/random/batch.hpp>
+
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+namespace random{
+
+ template<
+ typename T,
+ typename M,
+ typename P,
+ typename Rx, // Range // Covariate values
+ typename I = typename meta::random_input<M>::type
+ >
+ class meta_default_batch{
+ // Covariates
+ typedef range_cycle<> meta_;
+ typedef typename meta_::apply<Rx>::type cycle_;
+ typedef typename functional::visitor<cycle_> gcov_;
+ public:
+ typedef boost::random::gen_to_random<gcov_,I> rcov_;
+ private:
+ // Necessary in combination with cycle
+ typedef boost::random::ref_distribution<rcov_&> ref_rcov_;
+ typedef shared_ptr<rcov_> shared_;
+
+ // Clock
+ typedef functional::clock<T> gc_;
+ typedef boost::random::gen_to_random<gc_,I> rc_;
+
+ public:
+ typedef std::size_t size_type;
+ typedef gc_ clock_type;
+
+ typedef batch<T,M,P,rc_,ref_rcov_,I> type;
+
+ typedef typename type::model_parameter_ mp_;
+
+ static rcov_ rcov(
+ Rx& rx, // Not const Rx&? TODO see range_cycle
+ size_type offset,
+ size_type n
+
+ ){
+ return rcov_(
+ gcov_(
+ meta_::make(rx,offset,n)
+ )
+ );
+ }
+
+ // rcov above must be called from outside.
+ static type make(
+ const M& m,
+ const P& p,
+ const clock_type& c,
+ rcov_& rcov
+ ){
+ return type(
+ m,p,
+ rc_(c),
+ ref_rcov_(
+ rcov
+ )
+ );
+ }
+
+ };
+
+}// random
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/random/failure_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/failure_time.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::random::failure_time.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_RANDOM_FAILURE_TIME_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_RANDOM_FAILURE_TIME_HPP_ER_2009
+#include <boost/dist_random/include.hpp>
+#include <boost/statistics/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/statistics/survival/data/meta/failure_distribution.hpp>
+
+namespace boost{
+namespace statistics{
+namespace survival{
+namespace data{
+namespace random{
+
+ // Model + Covariate + Parameter + URNG ---> failure time
+ //
+ // This is a default implementaion that relies on meta::failure_random. It
+ // can be overloaded by specializing on M.
+ template<typename T,typename M,typename X,typename P,typename U>
+ T failure_time(
+ boost::statistics::model::model_covariate_parameter_<M,X,P> mcp,
+ U& urng
+ );
+
+ // Implementation //
+
+ template<typename T,typename M,typename X,typename P,typename U>
+ T failure_time(
+ boost::statistics::model::model_covariate_parameter_<M,X,P> mcp,
+ U& urng
+ ){
+ return make_failure_random(mcp)(urng);
+ }
+
+}// random
+}// data
+}// survival
+}// statistics
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/statistics/survival/data/random/include.hpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::random::include.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_RANDOM_INCLUDE_HPP_ER_2009
+#define BOOST_STATISTICS_SURVIVAL_DATA_RANDOM_INCLUDE_HPP_ER_2009
+
+#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>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/doc/readme.txt 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,90 @@
+//////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::doc::readme //
+// //
+// (C) Copyright 2009 Erwann Rogard //
+// Use, modification and distribution are subject to 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) //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These C++ classes are abstractions for survival data (right censored, staggered
+entry) and associated tools. See survival_model.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/
+/sandbox/statistics/joint_dist/
+/sandbox/statistics/survival_model/
+/sandbox/statistics/empirical_cdf/
+/sandbox/statistics/matrix_view/
+/sandbox/statistics/empirical_cdf/
+/sandbox/statistics/random/
+/sandbox/statistics/scalar_dist/
+/sandbox/statistics/dist_random/
+/sandbox/statistics/binary_op/
+/sandbox/statistics/functional/
+/sandbox/statistics/arithmetic/
+/sandbox/statistics/iterator/
+/sandbox/statistics/standard_distribution/
+
+Link to : libboost_serialization-xgcc42-mt-1_39.a
+
+[ History ]
+
+July 2009 : Current version
+
+[ Sources ]
+
+http://en.wikipedia.org/wiki/Survival_analysis
+
+[ Notation ]
+
+ Consider, for example, a clinical trial. t is a time measured since the
+ beginning of the trial. rt is a time relative to a data-unit's entry time
+ into the trial.
+
+ Type Class Object id Abstraction Concept
+ alias
+ T t, t1, rt is_scalar
+ R record<T> r entry & fail time
+ E event<T> e fail indic & event time
+ Me mean_event<T> me mean indic & event time
+
+[ data ]
+
+ R r(t,rt);
+ Me me;
+ E e0 = make_event(r,t0); me += e0;
+ E e1 = make_event(r,t1); me += e1;
+
+[ algorithm ]
+
+ Algorithms that iterate over a dataset
+
+[ random ]
+
+ Classes that simulate data given a model
+
+[ meta ]
+
+ A bridge between statistics::survival::data and statistics::survival::model
+
+
+[ Output ]
+
+main.cpp
+
+-> example_data : records : (0,2) (1,2) (2,2) (3,2) events : (1,2) (1,2) (0,1)
+ size(x_cycle) = 4
+mean_events : (2,(0,1)) (1,(1,2)) flattened mean_events : 0 1 1 2 <-
+-> example_random :
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.cpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,221 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::example::data.cpp //
+// //
+// 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) //
+///////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <ostream>
+#include <fstream>
+#include <stdexcept>
+#include <string> //needed?
+#include <algorithm>
+#include <iterator>
+#include <boost/tuple/tuple.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <boost/statistics/survival/data/include.hpp>
+#include <libs/statistics/survival/data/example/data.h>
+
+void example_data(std::ostream& out){
+ out << "-> example_data : ";
+
+ // Steps shown in this example:
+ //
+ // Records creation
+ // Events creation
+ // I/O
+ // Statistics
+
+ using namespace boost;
+ using namespace statistics;
+ namespace surv = statistics::survival;
+
+ // [ Types ]
+ typedef unsigned val_; // do not modify
+ typedef std::vector<val_> vals_;
+
+ // Records
+ typedef surv::data::record<val_> record_;
+ typedef std::vector<record_> records_;
+ typedef range_iterator<records_>::type it_record_;
+
+ // Events
+ typedef surv::data::event<val_> event_;
+ typedef std::vector<event_> events_;
+ typedef range_iterator<events_>::type it_event_;
+
+ // I/O
+ typedef boost::archive::text_oarchive oa_;
+ typedef boost::archive::text_iarchive ia_;
+
+ // Covariates
+ typedef val_ x_;
+ typedef vals_ r_x_;
+ typedef range_cycle<> range_cycle_;
+ typedef range_cycle_::apply<r_x_>::type x_cycle_;
+
+ // Statistics
+ typedef surv::data::mean_event<val_> me_;
+ typedef std::vector<me_> mes_;
+ typedef surv::data::mean_events_by_covariate<val_,x_> mes_by_x_;
+
+ // [ Constants ]
+ const unsigned n_record = 4;
+ const val_ entry_bound = n_record - 1;
+ const val_ fail_time = 2;
+
+ // [ Records ]
+ records_ records;
+ events_ events;
+ for(val_ i = 0; i<n_record; i++){
+ val_ entry_t = i;
+ record_ record(entry_t,fail_time);
+ records.push_back(record);
+ }
+
+ out << " records : ";
+ for(val_ i = 0; i<n_record; i++){
+ out << records[i] << ' ';
+ }
+
+ // [ Events ]
+
+ surv::data::events(
+ begin(records),
+ end(records),
+ entry_bound,
+ std::back_inserter(events)
+ );
+
+ // Analysis for n_record = 4 and entry_bound = 3;
+ // e ft dt ft<=dt min(ft,dt)
+ // 0 2 3 1 2
+ // 1 2 2 1 2
+ // 2 2 1 0 1
+ // 3 2 0 NA NA
+
+ BOOST_ASSERT(size(events) == entry_bound);
+ out << " events : ";
+ BOOST_FOREACH(const event_& e,events){
+ out << e << ' ';
+ }
+
+ // [ I/O ]
+ const char* path = "./serialized_events";
+
+ {
+ // Save events
+ std::ofstream ofs(path);
+ oa_ oa(ofs);
+ BOOST_FOREACH(const event_& e,events){
+ oa << e;
+ ofs.flush();
+ }
+ }
+ val_ n = size(events);
+ events_ events2;
+ {
+ // Recover events
+ event_ tmp;
+ std::ifstream ifs(path);
+ if(ifs.good()){
+ ia_ ia(ifs);
+ val_ j = 0;
+ //while(true){ //TODO
+ while(j<n){
+ ia >> tmp;
+ events2.push_back(tmp);
+ // TODO
+ //if (ifs.eof()) break;
+ //if (ifs.fail()){
+ // throw std::runtime_error("error reading");
+ //}
+ ++j;
+ }
+ }else{
+ std::string str = "error opening : ";
+ str.append( path );
+ throw std::runtime_error(str);
+ }
+ }
+ BOOST_ASSERT(n == size(events2));
+ for(val_ i = 0; i<n; i++){
+ BOOST_ASSERT(events[i] == events2[i]);
+ }
+
+ // [ Statistics ]
+ // Assume the records were generated conditional on the following
+ // covariates:
+ r_x_ r_x;
+ {
+ using namespace boost::assign;
+ r_x += 1, 2;
+ }
+ x_cycle_ x_cycle = range_cycle_::make(r_x,0,n_record);
+ out << "size(x_cycle) = " << size(x_cycle) << std::endl;
+ BOOST_ASSERT( size(x_cycle)>=size(events) );
+ // Resize x_cycle to a size that matches that of events
+ x_cycle.advance_end(
+ - (size(x_cycle) - size(events))
+ );
+ BOOST_ASSERT( size(x_cycle)==size(events) );
+
+ mes_by_x_ mes_by_x(r_x);
+ mes_by_x(
+ boost::begin(x_cycle),
+ boost::end(x_cycle),
+ boost::begin(events)
+ );
+
+ mes_ mes;
+ mes_by_x.tails(std::back_inserter(mes));
+
+ // Analysis for n_record = 4 and entry_bound = 3;
+ // x ft<=dt min(ft,dt)
+ // 1 1 2
+ // 2 1 2
+ // 1 0 1
+ // -------------------------------
+ // 1 1/2=0 3/2 = 1 // Remember, val_ = unsigned,
+ // 2 1 2 // not a float
+
+ out << "mean_events : ";
+ std::copy(
+ boost::begin( mes ),
+ boost::end( mes ),
+ std::ostream_iterator<me_>(out," ")
+ );
+
+ vals_ flat_mes;
+ surv::data::vectorize_events(
+ boost::begin( mes ),
+ boost::end( mes ),
+ std::back_inserter( flat_mes )
+ );
+
+ out << "flattened mean_events : ";
+ std::copy(
+ boost::begin( flat_mes ),
+ boost::end( flat_mes ),
+ std::ostream_iterator<val_>(out," ")
+ );
+
+// // Dont try this here because val_ = unsigned, but you get the idea
+// surv::data::logit_log(
+// boost::begin(flat_mes),
+// boost::end(flat_mes),
+// std::back_inserter(flat_mes),
+// 0.01,
+// 0.01
+// );
+ out << "<-" << std::endl;
+}
+
+
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/data.h 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::example::data.h //
+// //
+// 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 LIBS_SURVIVAL_DATA_EXAMPLE_DATA_HPP_ER_2009
+#define LIBS_SURVIVAL_DATA_EXAMPLE_DATA_HPP_ER_2009
+#include <ostream>
+
+void example_data(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.cpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,237 @@
+//#include <cmath>
+#include <stdexcept>
+#include <fstream>
+#include <ostream>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <algorithm>
+#include <ext/algorithm> // is_sorted
+#include <iterator>
+#include <functional>
+
+#include <boost/typeof/typeof.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/timer.hpp>
+#include <boost/range.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+
+#include <boost/math/tools/precision.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp> //prior
+#include <boost/standard_distribution/distributions/exponential.hpp> //data
+
+#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>
+
+
+void example_random(std::ostream& out){
+ out << "-> example_random : ";
+
+ using namespace boost;
+ using namespace statistics;
+ namespace surv = survival;
+
+ // Generates batches of iid random records as follows:
+ // 1) The parameter is generated, for each batch, given a prior.
+ // 2) The covariates are generated in cyclic fashion within each batch
+ // 3) Data is generated given model, parameter, covariate, entry time.
+ // KS distances are computed for each batch of data
+ // Each batch is saved using serialization
+
+ // Types
+ 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
+
+ // I/O
+ 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 = 1e4;
+ 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);
+
+ BOOST_ASSERT( n_record % k == 0 );
+ BOOST_ASSERT( n_ks_data % (n_record/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";
+
+ // [ Covariate values ]
+ vals_ x_vals;
+ {
+ using namespace boost::assign;
+ x_vals += -0.5, 0.5;
+ }
+ BOOST_ASSERT(size(x_vals) == k);
+
+ {
+ ofs_ ofs(x_vals_path);
+ oa_ oa(ofs);
+ oa << x_vals;
+ ofs.flush();
+ ofs.close();
+ }
+
+ // [ 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);
+ {
+ // 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_ks << "first and last ks of the failure times : " << std::endl;
+ for(unsigned i = 0; i<n_batch; i++){
+ records.clear();
+ par_ par = boost::sample(mprior,urng);
+ oa_pars << par;
+ ofs_pars.flush();
+ meta_batch_::rcov_ r = meta_batch_::rcov(
+ x_vals,
+ 0,
+ n_record
+ );
+ batch_ batch = meta_batch_::make(
+ model,
+ par,
+ clock,
+ r
+ );
+ true_pars.push_back( par );
+ vg_r vg_r( urng, batch );
+
+ std::generate_n(
+ std::back_inserter( records ),
+ n_record,
+ vg_r
+ );
+
+ BOOST_ASSERT(
+ is_sorted(
+ boost::begin( records ),
+ boost::end( records )
+ )
+ );// clock is supposed to tick forward
+
+ oa_batches << records;
+
+ 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),
+ i,
+ lambda::bind(&record_::failure_time,lambda::_1),
+ std::back_inserter(fts)
+ );
+ mcp_ mcp(
+ batch.model(),
+ x_vals[i],
+ batch.parameter()
+ );
+ fd_ fail_dist = surv::data::make_failure_distribution(mcp);
+
+ kss.clear();
+ statistics::empirical_cdf
+ ::sequential_kolmogorov_smirnov_distance(
+ fail_dist,
+ boost::begin( fts ),
+ boost::end( fts ),
+ n_ks_data,
+ std::back_inserter( kss )
+ );
+
+ if(n_ks_data>1){
+ // Desired result: kss[0] < kss.back();
+ ofs_ks << kss[0] << ',' << kss.back();
+ }
+ ofs_ks << std::endl;
+ ofs_ks.flush();
+ }
+ }
+ } // batch loop
+ ofs_ks.close();
+ ofs_pars.close();
+ ofs_batches.close();
+ } // records generation
+}
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/example/random.h 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::data::example::random.h //
+// //
+// 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 LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
+#define LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
+
+void example_random(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/statistics/survival/data/src/main.cpp 2009-08-31 21:57:42 EDT (Mon, 31 Aug 2009)
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+// statistics::survival::src::main.cpp //
+// //
+// 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) //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <fstream>
+#include <libs/statistics/survival/data/example/data.h>
+#include <libs/statistics/survival/data/example/random.h>
+
+int main(){
+
+ example_data(std::cout);
+ //example_random(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