Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51825 - in sandbox/conditionally_specified_distribution: . adaptive_rejection_sampling adaptive_rejection_sampling/boost adaptive_rejection_sampling/boost/adaptive_rejection_sampling adaptive_rejection_sampling/boost/adaptive_rejection_sampling/example adaptive_rejection_sampling/libs adaptive_rejection_sampling/libs/adaptive_rejection_sampling adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example conditionally_specified_distribution conditionally_specified_distribution/boost conditionally_specified_distribution/boost/conditionally_specified_distribution conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp conditionally_specified_distribution/boost/conditionally_specified_distribution/function conditionally_specified_distribution/boost/conditionally_specified_distribution/function/detail conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/detail conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/detail conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/detail conditionally_specified_distribution/boost/conditionally_specified_distribution/support conditionally_specified_distribution/boost/conditionally_specified_distribution/support/detail conditionally_specified_distribution/libs conditionally_specified_distribution/libs/conditionally_specified_distribution conditionally_specified_distribution/libs/conditionally_specified_distribution/src conditionally_specified_distribution/libs/conditionally_specified_distribution/src/doc conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler math_limit math_limit/boost math_limit/boost/math_limit shared_features shared_features/boost shared_features/boost/shared_features shared_features/boost/shared_features/feature shared_features/boost/shared_features/functor shared_features/libs shared_features/libs/shared_features shared_features/libs/shared_features/src shared_features/libs/shared_features/src/doc shared_features/libs/shared_features/src/example survival_data survival_data/boost survival_data/boost/generator survival_data/boost/random_regression survival_data/boost/survival_data survival_data/libs survival_data/libs/random_regression survival_data/libs/random_regression/src survival_data/libs/random_regression/src/doc survival_data/libs/random_regression/src/example survival_data/libs/survival_data survival_data/libs/survival_data/src survival_data/libs/survival_data/src/doc survival_data/libs/survival_data/src/example utility utility/boost utility/boost/utility
From: erwann.rogard_at_[hidden]
Date: 2009-03-17 22:36:28


Author: e_r
Date: 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
New Revision: 51825
URL: http://svn.boost.org/trac/boost/changeset/51825

Log:
Adding dir conditionally*
Added:
   sandbox/conditionally_specified_distribution/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation_impl.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/example/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/example/standard_gaussian.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/point.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/sampler.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/ars.ps (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/readme.txt (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.h (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.h (contents, props changed)
   sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/main.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/pair_independent.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/detail/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/detail/adapter.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/pair_independent.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/parameter.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/sampler.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/detail/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/detail/regression_coefficient.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/detail/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/detail/skip_position_operations.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/pair_independent.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/first.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_argument.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_support.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_value.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/functor.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/identifier.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/matching_covariate.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/mu.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/position.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_coefficient.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_covariate.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_data.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_skip_position_covariate_dot_coefficient.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/second.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/sigma.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/initializer.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/sampler.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/detail/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/detail/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/detail/negative_max_to_max.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/fwd.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/normal.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/doc/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/doc/readme.txt (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.h (contents, props changed)
   sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/main.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/math_limit/
   sandbox/conditionally_specified_distribution/math_limit/boost/
   sandbox/conditionally_specified_distribution/math_limit/boost/math_limit/
   sandbox/conditionally_specified_distribution/math_limit/boost/math_limit/miscellanea.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/
   sandbox/conditionally_specified_distribution/shared_features/boost/
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/creation.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/depends_on.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container_element.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/example.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/keyword.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/scalar.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/initialize.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/sample.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/update.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/mpl_features.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/parameter.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/predicate.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/result_of_extract.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/set.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/visitor.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/wrapper.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/doc/
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/doc/readme.txt (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.h (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.h (contents, props changed)
   sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/main.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/
   sandbox/conditionally_specified_distribution/survival_data/boost/
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/clock.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/constant.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/cycle_through_shared_containers.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/keyword.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/ref.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/generator/shared_container.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_distribution.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_regression.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/base.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/exponential.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/keyword.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/call_event_time.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/event_manager.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_fixed_design_no_censoring.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_given_entry_time_covariate.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/include.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/keyword.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/parser.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/stream_to_dataset.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/transform_if_to_unit_at_time.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit_at_time.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/doc/
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/doc/
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/doc/readme.txt (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/mice_data.txt (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.h (contents, props changed)
   sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/main.cpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/
   sandbox/conditionally_specified_distribution/utility/boost/
   sandbox/conditionally_specified_distribution/utility/boost/utility/
   sandbox/conditionally_specified_distribution/utility/boost/utility/assert_is_base_of.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/boost/utility/assert_not_empty.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/boost/utility/container_to_string.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/boost/utility/dont_care.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/boost/utility/nested_type.hpp (contents, props changed)
   sandbox/conditionally_specified_distribution/utility/boost/utility/remove_qualifier.hpp (contents, props changed)

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,190 @@
+////////////////////////////////////////////////////////////////////////////
+// approximation.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_ADAPTIVE_REJECTION_SAMPLING_APPROXIMATION_HPP_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_APPROXIMATION_HPP_ER_2009
+#include <vector>
+#include <stdexcept>
+#include <boost/range.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/adaptive_rejection_sampling/approximation_impl.hpp>
+namespace boost{
+namespace adaptive_rejection_sampling{
+
+ // approximation queries f (of DistFun) as necessary and forwards
+ // to approximation_impl.
+ // In addition, it recursively adjusts the initial abscissae (x1,x2)
+ // until certain necessary conditions are met.
+ //
+ // DistFun:
+ // Associated type:
+ // value_type
+ // Valid expressions:
+ // Expression return type
+ // f.unnormalized_pdf(x) value_type;
+ // f.derivative_unnormalized_pdf(x) value_type
+ //
+ // The interface is that of approximation_impl, and
+ //
+ // Constructor:
+ // approximation(f,max_recursion) //not initialized
+ // approximation(f,x0_init,x1_init,max_recursion)
+ //
+ // Modifier:
+ // initialize(x1,x2)
+ // update(x)
+ template<
+ typename DistFun,
+ template<typename,typename> class Cont = std::vector,
+ template<typename> class Alloc = std::allocator
+ >
+ class approximation : public approximation_impl<
+ typename DistFun::value_type,
+ Cont,
+ Alloc
+ >{
+ typedef approximation_impl<
+ typename DistFun::value_type,
+ Cont,
+ Alloc
+ > super_t;
+ typedef DistFun dist_f_t;
+ typedef std::pair<
+ typename super_t::point_t,
+ typename super_t::point_t
+ > pair_points_t;
+ protected:
+ // The search for adequate initial (x1,x2) quits and throws an error
+ // after max_recursion
+ approximation(
+ const dist_f_t& f,
+ typename super_t::size_type max_recursion
+ ):super_t(f.min(),f.max()),
+ dist_f_(f),
+ max_recursion_(max_recursion){
+ //warning not initialized
+ }
+ approximation(
+ const dist_f_t& f,
+ typename super_t::value_type x0_init,
+ typename super_t::value_type x1_init,
+ typename super_t::size_type max_recursion
+ ):super_t(f.min(),f.max()),
+ dist_f_(f),
+ max_recursion_(max_recursion){
+ this->initialize(x0_init,x1_init);
+ }
+
+ approximation(const approximation& that)
+ :super_t(that),
+ dist_f_(that.dist_f_),
+ max_recursion_(that.max_recursion_){}
+
+ approximation&
+ operator=(const approximation& that){
+ if(&that!=this){
+ super_t::operator=(that);
+ dist_f_ = that.dist_f_;
+ max_recursion_ = that.max_recursion_;
+ }
+ return *this;
+ }
+ public:
+ void initialize(
+ typename super_t::value_type x1,typename super_t::value_type x2){
+ try{
+ pair_points_t a
+ = find_valid_starting_points(x1,x2,max_recursion_);
+ initialize_impl(a.first,a.second);
+ }catch(std::exception& e){
+ throw std::runtime_error(e.what());
+ }
+ }
+ // Warning: The client may wish to supply his own update,
+ // so we leave this unprotected. By default, however, this is
+ // internal.
+ void update(typename super_t::value_type x){
+ typename super_t::point_t const p = this->get_point(x);
+ this->update_impl(p);
+ }
+
+ protected:
+ typename super_t::point_t
+ get_point(typename super_t::value_type x)const{
+ typename super_t::value_type y = dist_f_.unnormalized_log_pdf(x);
+ typename super_t::value_type dy
+ = dist_f_.derivative_unnormalized_log_pdf(x);
+ return typename super_t::point_t(x,y,dy);
+ }
+ typename super_t::value_type
+ get_y(typename super_t::value_type x)const{
+ typename super_t::value_type y = dist_f_.unnormalized_log_pdf(x);
+ return y;
+ }
+ private:
+ pair_points_t
+ find_valid_starting_points(
+ typename super_t::value_type x1,
+ typename super_t::value_type x2,
+ typename super_t::size_type max_recursion
+ ){
+ BOOST_ASSERT(x1<x2);
+ typename super_t::size_type recursion = 0;
+ typename super_t::value_type new_x1 = x1;
+ typename super_t::point_t p1 = get_point(new_x1);
+ bool is_ok_1 = is_valid_leftmost_point(p1.dy());
+
+ typename super_t::value_type new_x2 = x2;
+ typename super_t::point_t p2 = get_point(new_x2);
+ bool is_ok_2 = is_valid_rightmost_point(p2.dy());
+
+ while(
+ (!(is_ok_1 && is_ok_2)) && (recursion++<max_recursion)
+ ){
+ if(!is_ok_1){
+ BOOST_ASSERT(new_x1-new_x2<0.0);
+ new_x1 -= (new_x2-new_x1);
+ p1 = get_point(new_x1);
+ is_ok_1 = is_valid_leftmost_point(p1.dy());
+ }
+ if(!is_ok_2){
+ BOOST_ASSERT(new_x2-new_x1>0.0);
+ new_x2 += (new_x2-new_x1);
+ p2 = get_point(new_x2);
+ is_ok_2 = is_valid_rightmost_point(p2.dy());
+ }
+ }
+ if(!is_ok_1){
+ std::string str = "adaptive_rejection_sampling::";
+ str += "approximation::initialize";
+ str += "!is_valid_leftmost_point(dy1=%1%)";
+ str += "after %2% recursions, ";
+ str += "and x1 = %3%, x2 = %4%, new_x1 = %5%, new_x2 = %6%";
+ format f(str);
+ f % p1.dy() % recursion % x1 % x2 % new_x1 % new_x2;
+ throw std::runtime_error(f.str());
+ }
+ if(!is_ok_2){
+ std::string str = "adaptive_rejection_sampling::";
+ str += "approximation::initialize";
+ str += "!is_valid_rightmost_point(dy2=%1%)";
+ str += "after %2% recursions, ";
+ str += "and x1 = %3%, x2 = %4%, new_x1 = %5%, new_x2 = %6%";
+ format f(str);
+ f % p2.dy() % recursion % x1 % x2 % new_x1 % new_x2;
+ throw std::runtime_error(f.str());
+ }
+ return pair_points_t(p1,p2);
+ }
+
+ dist_f_t dist_f_;
+ typename super_t::size_type max_recursion_;
+
+ };
+}//adaptive_rejection_sampling
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation_impl.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/approximation_impl.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,567 @@
+////////////////////////////////////////////////////////////////////////////
+// approximation_impl.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_ADAPTIVE_REJECTION_SAMPLING_APPROXIMATION_IMPL_HPP_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_APPROXIMATION_IMPL_HPP_ER_2009
+#include <vector>
+#include <ext/algorithm> // is_sorted
+#include <algorithm>
+#include <functional>
+#include <iterator>
+#include <cmath>
+#include <boost/mpl/identity.hpp>
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/range.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/math_limit/miscellanea.hpp>
+#include <boost/utility/container_to_string.hpp>
+#include <boost/adaptive_rejection_sampling/point.hpp>
+namespace boost{
+namespace adaptive_rejection_sampling{
+
+ // approximation_impl keeps a set of of (n>2) points,
+ // n+1 intersection abscicae and n approximate unnormalized cdfs
+ //
+ // Constructor
+ // approximation_impl( // Warning : must be followed by
+ // value_type min, // initialize_impl(...)
+ // value_type max
+ // )
+ // approximation_impl(
+ // value_type min,
+ // value_type max,
+ // const point_t& a,
+ // const point_t& b
+ // )
+ // Const interface:
+ // min()const
+ // max()const
+ // lower(x)
+ // upper(x)
+ // total_unnormalized_cdf()const
+ // inverse_cdf(value_type u)const
+ //
+ // Modifier:
+ // void initialize_impl(const point_t& a,const point_t& b)
+ // update_impl(const point_t& p)
+ template<
+ typename RealType = double,
+ template<typename,typename> class Cont = std::vector,
+ template<typename> class Alloc = std::allocator
+ >
+ class approximation_impl{
+ public:
+ typedef RealType value_type;
+ typedef math_limit::limits<value_type> limits_t;
+ typedef point<value_type> point_t;
+ typedef Alloc<point_t> alloc_t;
+ typedef Cont<point_t,alloc_t> points_t;
+ typedef std::vector<value_type> upper_t;
+ typedef typename range_iterator<points_t>::type iter_t;
+ typedef typename range_iterator<upper_t>::type upper_iter_t;
+ typedef typename range_iterator<const points_t>::type
+ citer_t;
+ typedef typename range_iterator<const upper_t>::type
+ cupper_iter_t;
+
+ typedef typename range_size<points_t>::type size_type;
+ struct result_of_range_points : mpl::identity<const points_t&>{};
+ struct result_of_range_upper : mpl::identity<const upper_t&>{};
+
+ bool is_valid_leftmost_point(value_type dy){
+ return (!limits_t::is_negative_infinity(min())) || (dy>0.0);
+ }
+ bool is_valid_rightmost_point(value_type dy){
+ return (!limits_t::is_infinity(max())) || (dy<0.0);
+ }
+
+ approximation_impl(
+ value_type min,
+ value_type max
+ ):min_(min),max_(max),subtract_from_y_(0.0)
+ {
+ //Warning not initialized.
+ }
+
+ approximation_impl(
+ value_type min,
+ value_type max,
+ const point_t& a,
+ const point_t& b
+ ):min_(min),max_(max_),subtract_from_y_(0.0)
+ {
+ initialize_impl(a,b);
+ }
+ //TODO protected
+ void initialize_impl(
+ const point_t& a,
+ const point_t& b
+ ){
+ BOOST_ASSERT(a.x()<b.x());
+ BOOST_ASSERT(a.dy()>b.dy());
+ BOOST_ASSERT(is_valid_leftmost_point(a.dy()));
+ BOOST_ASSERT(is_valid_rightmost_point(b.dy()));
+ points_.clear();
+ points_.push_back(a);
+ points_.push_back(b);
+ upper_.clear();
+ upper_.push_back(min());
+ value_type ab = tangent_intersection(a,b);
+ upper_.push_back(ab);
+ upper_.push_back(max());
+ assert_upper_points();
+ assert_points_sorted();
+ assert_range_dy_sorted();
+ assert_upper_sorted();
+ update_unnormalized_cdf();
+
+ }
+ approximation_impl(const approximation_impl& that)
+ :min_(that.min_),
+ max_(that.max_),
+ points_(that.points_),
+ upper_(that.upper_),
+ range_unnormalized_cdf_(
+ that.range_unnormalized_cdf_){}
+
+ approximation_impl&
+ operator=(const approximation_impl& that){
+ if(&that!=this){
+ min_ = that.min_;
+ max_ = that.max_;
+ points_ = that.points_;
+ upper_ = that.upper_;
+ range_unnormalized_cdf_
+ = that.range_unnormalized_cdf_;
+ //unnormalized_cdf_ = that.unnormalized_cdf_;
+ }
+ return *this;
+ }
+
+ value_type min()const{return min_;}
+ value_type max()const{return max_;}
+ value_type
+ total_unnormalized_cdf()const{
+ BOOST_ASSERT(size(points_)>1);
+ return range_unnormalized_cdf_.back();
+ //warning : this is an approximation, whose magnitude
+ // is compounded by subtract_y (Ctrl+F), but as n-->inf,
+ // sutract_y should --->0
+
+ }
+ value_type
+ lower(value_type x)const{
+ BOOST_ASSERT(size(points_)>1);
+ value_type res = 0.0;
+ const point_t p(x,0.0,0.0);
+ citer_t i = upper_bound(
+ begin(points_),
+ end(points_),
+ p,
+ less<value_type>()
+ );
+ if(i!=end(points_)){
+ if(begin(points_)!=i){
+ value_type x_h = i -> x();
+ value_type y_h = i -> y();
+ --i;
+ value_type x_l = i -> x();
+ value_type y_l = i -> y();
+ res = y_l + (x-x_l) * (y_h-y_l) / (x_h-x_l);
+ }else{
+ res = negative_infinity();
+ }
+ }else{
+ res = negative_infinity();
+ }
+ return res;
+ }
+ value_type
+ upper(value_type x)const{
+ BOOST_ASSERT(size(points_)>1);
+
+ // Loops
+ // a b c
+ // / \ / \ / \
+ // z ab bc z (tangent intersections)
+ // x is_in [ab,bc], we need tangent at b
+ cupper_iter_t u = upper_bound(
+ begin(upper_),
+ end(upper_),
+ x
+ );
+ typedef typename range_difference<upper_t>::type u_diff_t;
+
+ u_diff_t u_diff = std::distance(begin(upper_),u);
+ BOOST_ASSERT(u_diff>0);
+ citer_t i = begin(points_);
+ std::advance(i,u_diff-1);
+ BOOST_ASSERT((i->x())<*u);
+ --u; BOOST_ASSERT(*u<=x);
+ return tangent(*i,x);
+ }
+ value_type inverse_cdf(value_type u)const{
+ BOOST_ASSERT(size(points_)>1);
+
+ // a---b---c---d
+ // /\ / \ / \ / \
+ // z- ab bc cd z+
+ // | | | |
+
+ const upper_t& rcdf
+ = range_unnormalized_cdf_;
+ cupper_iter_t i_cdf = begin(rcdf);
+ cupper_iter_t i_u = begin(upper_);
+ citer_t i_p = begin(points_);
+ value_type thresh = u * total_unnormalized_cdf();
+ while(*i_cdf< thresh){
+ ++i_cdf;
+ ++i_u;
+ ++i_p;
+ BOOST_ASSERT(
+ i_cdf!=end(range_unnormalized_cdf_)
+ );
+ }
+ value_type x = i_p->x();
+ value_type y = i_p->y() - subtract_from_y_;
+ value_type dy = i_p->dy();
+ //TODO distinguish based on is_negative_infinity(*i_u)
+ value_type t = tangent(*i_p,*i_u) - subtract_from_y_;
+ value_type cumul_cdf = 0.0;
+ if(i_cdf!=begin(rcdf)){
+ --i_cdf;
+ cumul_cdf = *i_cdf;
+ }
+ value_type res
+ = math_limit::safer_exp(t)+ dy * (thresh-cumul_cdf);
+ if(!(res>0.0)){
+ std::string str = "adaptive_rejection_sampling::";
+ str+= "approximation_impl::";
+ str+= "inverse_cdf : ";
+ str+= "!res=%1%>0.0";
+ str+= "x=%2% subtract_from_y_=%3% t=%4%";
+ format f(str);
+ f%res%x%subtract_from_y_;
+ f%t;
+ throw std::runtime_error(f.str());
+ }else{ //safer_log instead?
+ if(!(res<limits_t::infinity())){
+ std::string str = "inverse_cdf";
+ str+= "!(res=%1%<limits_t::max_value()=%2%)";
+ str+= "x=%3%";
+ format f(str);
+ f%res%limits_t::infinity()%x;
+ throw std::runtime_error(f.str());
+ }else{
+ res = x + ( log(res) - y ) / dy;
+ }
+ }
+ return res;
+ }
+
+ // For testing only.
+ typename result_of_range_points::type
+ range_point()const{ return points_; }
+ typename result_of_range_upper::type
+ range_upper()const{ return upper_; }
+ //TODO protected
+ void update_impl(value_type x,value_type y,value_type dy){
+ return update_impl(point_t(x,y,dy));
+ }
+ //TODO protected
+ void update_impl(const point_t& p){
+ BOOST_ASSERT(size(points_)>1);
+
+// lower_bound returns furthermost iterator i in [first, last) such that,
+// for every j in [first, i), *j < value or (comp(*j, value) is true)
+// upper_bound returns the furthermost iterator i in [first, last) such that
+//, for every iterator j in [first, i), value < *j is false.
+// or comp(value, *j) is false.
+
+ iter_t i = upper_bound(
+ begin(points_),
+ end(points_),
+ p,
+ less<value_type>()
+ );
+ bool is_not_largest = (i!=end(points_));
+ i = points_.insert(i,p);
+ bool is_not_smallest = (i!=begin(points_));
+ value_type z_l,z_r = 0.0; //left
+
+ if(is_not_smallest){
+ iter_t l = i; --l;
+ z_l = tangent_intersection(*l,*i);
+ }
+ if(is_not_largest){
+ iter_t r = i; ++r;
+ z_r = tangent_intersection(*i,*r);
+ }
+ // z[0] = m, z[1],...., z[n-1]=M, end
+ if(!is_not_smallest){
+ upper_iter_t j = begin(upper_); ++j; //*j = z[1]
+ upper_.insert(j,z_r);
+ }else{
+ if(is_not_largest){
+ // a b c
+ // / \ / \
+ // z- ac z+
+ upper_iter_t j = begin(upper_);
+ std::advance(j,distance(begin(points_),i)); //*j=ac
+ *j = z_r; //*j = bc
+ // a b c
+ // / \ / \
+ // z- bc z+
+ upper_.insert(j,z_l);
+ // a b c
+ // / \ / \ / \
+ // z- ab bc z+
+ }else{
+ upper_iter_t j = begin(upper_);
+ std::advance(j,size(upper_)-1); //*j = z+
+ upper_.insert(j,z_l);
+ }
+ }
+
+ assert_upper_points();
+ assert_points_sorted();
+ assert_range_dy_sorted();
+ assert_upper_sorted();
+ update_unnormalized_cdf();
+ }
+
+ std::string as_string()const{
+ typedef utility::container_to_string to_str_t;
+ std::string str;
+ str+= "[ upper_ = %1%\n";
+ str+= " range_unnormalized_cdf_ = %2%\n";
+ str+= " {x} = %3%\n";
+ str+= " {y} = %4%\n";
+ str+= " {dy} = %5% ]";
+ format f(str);
+ f%to_str_t::get_indexed(upper_);
+ f%to_str_t::get_indexed(range_unnormalized_cdf_);
+ f%to_str_t::get_indexed(range_x());
+ f%to_str_t::get_indexed(range_y());
+ f%to_str_t::get_indexed(range_dy());
+ return f.str();
+ }
+ protected:
+ value_type
+ negative_infinity()const{
+ return limits_t::negative_infinity();
+ }
+ value_type infinity()const{
+ return limits_t::infinity();
+ }
+
+ private:
+
+ void update_unnormalized_cdf(){
+ upper_t upper_ys;
+ value_type max_t = negative_infinity();
+ //min_nni_t = infinity(); // no use, for now.
+ subtract_from_y_ = 0.0;
+ {
+ citer_t i = begin(points_);
+ citer_t e = end(points_);
+ cupper_iter_t u = begin(upper_);
+ value_type t = tangent(*i,*u);
+ upper_ys.push_back(t);
+ ++u;
+ while(i < e){
+ BOOST_ASSERT(u!=end(upper_));
+ t = tangent(*i,*u);
+ upper_ys.push_back(t);
+ max_t = (t<max_t)?max_t : t;
+ //min_nni_t
+ // = ( (t<min_nni_t) && (!is_negative_infinity(t)) )
+ // ?t : min_nn_t;
+ ++i, ++u;
+ }
+ BOOST_ASSERT(max_t > negative_infinity());
+ }
+
+ { // narrows support to [log_min_value,log_max_value]
+ value_type max_allowed = limits_t::log_max_value();
+ subtract_from_y_ = max_t - max_allowed;
+ subtract_from_y_
+ = (subtract_from_y_>0.0)? subtract_from_y_ : 0.0;
+ upper_iter_t b = begin(upper_ys);
+ upper_iter_t e = end(upper_ys);
+ if(subtract_from_y_>0.0){
+ for(upper_iter_t i = b; i<e; i++){
+ if(
+ *i>subtract_from_y_+limits_t::log_min_value()
+ ){
+ (*i) -= subtract_from_y_;
+ }
+ }
+ }
+ }
+
+ range_unnormalized_cdf_.clear();
+ value_type unnormalized_cdf = 0.0;
+ citer_t i = begin(points_);
+ citer_t e = end(points_);
+ cupper_iter_t i_t = begin(upper_ys);
+ value_type t_prior = *i_t; //z-
+ value_type et_prior = math_limit::safer_exp(t_prior);
+ ++i_t;
+ value_type t, et, dy, delta = 0.0;
+ while(i < e){
+ BOOST_ASSERT(i_t<end(upper_ys));
+ t = *i_t;
+ et = math_limit::safer_exp(t);
+ dy = i->dy();
+ // sometimes et-et_prior = 0 even if (t-t_prior) !=0
+ // due to rounding
+ delta = (t - t_prior);
+ if(
+ ((dy>0.0) && (delta >0.0))
+ || ((dy<0.0) && (delta<0.0))
+ )
+ {
+ //Warning. Do not un-comment as leads to failure
+ //if(delta<limits_t::min_value() * dy){
+ // delta = limits_t::min_value();
+ //}else{
+ delta = (et-et_prior)/dy;
+ //}
+ }else{
+
+ //math_limit::safer_exp(t); //debugging only
+ typedef utility::container_to_string to_str_t;
+ std::string str = "adaptive_rejection_sampling::";
+ str+= "approximation_impl";
+ str+= "!(delta=%1%>0.0)\n";
+ str+= "subtract_from_y_=%2%\n, t_prior = %3%";
+ str+= " t = %4%, dy = %5%, et_prior = %6%";
+ str+= " et = %7%\n";
+ str+= " upper_ys = %8%\n";
+ str+= this->as_string();
+ format f(str);
+ f%delta%subtract_from_y_;
+ f%t_prior%t%dy%et_prior%et;
+ f%to_str_t::get_indexed(upper_ys);
+ throw std::runtime_error(f.str());
+ }
+ t_prior = t;
+ et_prior = et;
+ unnormalized_cdf += delta;
+ range_unnormalized_cdf_.push_back(unnormalized_cdf);
+ ++i; ++i_t;
+ } //while
+ assert_range_unnormalized_cdf_points();
+ assert_range_unnormalized_cdf_sorted();
+ }
+
+ /// --> For testing only
+ const upper_t&
+ range_dy()const{
+ static upper_t result;
+ result.clear();
+ transform(
+ begin(points_),
+ end(points_),
+ back_inserter(result),
+ bind(
+ &point_t::dy,
+ _1
+ )
+ );
+ return result;
+ }
+ const upper_t&
+ range_x()const{
+ static upper_t result;
+ result.clear();
+ transform(
+ begin(points_),
+ end(points_),
+ back_inserter(result),
+ bind(
+ &point_t::x,
+ _1
+ )
+ );
+ return result;
+ }
+ const upper_t&
+ range_y()const{
+ static upper_t result;
+ result.clear();
+ transform(
+ begin(points_),
+ end(points_),
+ back_inserter(result),
+ bind(
+ &point_t::y,
+ _1
+ )
+ );
+ return result;
+ }
+ /// <--- For Testing only
+ void assert_upper_points()const{
+ BOOST_ASSERT(
+ size(upper_) - (size(points_)+1) ==0
+ );
+ }
+ void assert_points_sorted()const{
+ BOOST_ASSERT(
+ is_sorted(
+ begin(points_),
+ end(points_),
+ less<value_type>()
+ )
+ );
+ }
+ void assert_upper_sorted()const{
+ BOOST_ASSERT(
+ is_sorted(begin(upper_),end(upper_))
+ );
+ }
+
+ void assert_range_dy_sorted()const{
+ BOOST_ASSERT(
+ is_sorted(
+ begin(range_dy()),
+ end(range_dy()),
+ std::greater<value_type>()
+ )
+ );
+ }
+
+
+ void assert_range_unnormalized_cdf_points()const{
+ BOOST_ASSERT(size(range_unnormalized_cdf_)==size(points_));
+ }
+ void assert_range_unnormalized_cdf_sorted()const{
+ BOOST_ASSERT(
+ is_sorted(
+ begin(range_unnormalized_cdf_),
+ end(range_unnormalized_cdf_)
+ )
+ );
+ }
+
+ value_type min_;
+ value_type max_;
+ points_t points_;
+ upper_t upper_;
+ upper_t range_unnormalized_cdf_;
+ //value_type unnormalized_cdf_;
+ value_type subtract_from_y_;
+ };
+
+}//adaptive rejection sampling
+}//boost
+
+
+#endif // UPPER_HULL_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/example/standard_gaussian.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/example/standard_gaussian.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,38 @@
+/////////////////////////////////////////////////////////////////////////////
+// example/standard_gaussian.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_ADAPTIVE_REJECTION_SAMPLING_STANDARD_GAUSSIAN_HPP_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_STANDARD_GAUSSIAN_HPP_ER_2009
+#include <boost/math_limit/miscellanea.hpp>
+
+namespace boost{
+namespace adaptive_rejection_sampling{
+ /// \class standard_gaussian_evaluator
+ /// \brief Example modeling LogConcaveEvaluator
+ template<typename RealType>
+ class standard_gaussian_evaluator{
+ typedef math_limit::limits<RealType> limits_t;
+ public:
+ typedef RealType value_type;
+ typedef standard_gaussian_evaluator base_type;
+ value_type unnormalized_log_pdf(value_type x)const{
+ return -x*x/2.0;
+ }
+ value_type derivative_unnormalized_log_pdf(value_type x)const{
+ return -x;
+ }
+ value_type min()const{
+ return limits_t::negative_infinity();
+ }
+ value_type max()const{
+ return limits_t::infinity();
+ }
+ };
+
+}
+}
+
+#endif // STANDARD_GAUSSIAN_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/point.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/point.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,123 @@
+////////////////////////////////////////////////////////////////////////////
+// point.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_ADAPTIVE_REJECTION_SAMPLING_POINT_HPP_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_POINT_HPP_ER_2009
+#include <stdexcept>
+#include <boost/format.hpp>
+#include <boost/math_limit/miscellanea.hpp>
+namespace boost{
+namespace adaptive_rejection_sampling{
+
+ template<typename RealType>
+ class point{
+ public:
+ typedef RealType value_type;
+
+ point(value_type x,value_type y,value_type dy)
+ :x_(x),y_(y),dy_(dy){}
+ value_type x()const{return x_;}
+ value_type y()const{return y_;}
+ value_type dy()const{return dy_;}
+
+ private:
+ value_type x_;
+ value_type y_;
+ value_type dy_;
+ };
+
+ template<typename RealType>
+ RealType
+ tangent_at_negative_infinity(const point<RealType>& p){
+ typedef math_limit::limits<RealType> limits_t;
+
+ RealType result = 0.0;
+ if(p.dy()>0.0){
+ result = limits_t::negative_infinity();
+ }else{
+ result = limits_t::infinity();
+ }
+ return result;
+ }
+ template<typename RealType>
+ RealType
+ tangent_at_infinity(const point<RealType>& p){
+ typedef math_limit::limits<RealType> limits_t;
+ RealType result = 0.0;
+ if(p.dy()>0.0){
+ result = limits_t::infinity();
+ }else{
+ result = limits_t::negative_infinity();
+ }
+ return result;
+ }
+ template<typename RealType>
+ RealType tangent_at_finite(const point<RealType>& p,RealType x){
+ return p.y()+(x-p.x()) * p.dy();
+ }
+
+ template<typename RealType>
+ RealType tangent(const point<RealType>& p,RealType x){
+ typedef math_limit::limits<RealType> limits_t;
+ if(limits_t::is_infinity(x)){
+ return tangent_at_infinity(p);
+ }else{
+ if(limits_t::is_negative_infinity(x)){
+ return tangent_at_negative_infinity(p);
+ }else{
+ return tangent_at_finite(p,x);
+ }
+ }
+ }
+
+
+ template<typename RealType>
+ RealType
+ tangent_intersection(
+ const point<RealType>& p0,
+ const point<RealType>& p1
+ ){
+ typedef RealType value_t;
+ value_t x0 = p0.x();
+ value_t x1 = p1.x();
+ value_t dy0 = p0.dy();
+ value_t dy1 = p1.dy();
+ std::string str = "adaptive_rejection_sampling::";
+ str += "tangent_intersection";
+
+ if(!(x0<x1)){
+ str += "!(x0=%1%<x1=%2%)";
+ format f(str);
+ f%x0%x1;
+ throw std::runtime_error(f.str());
+ }
+ if(!(dy0>dy1)){
+ str += "!(dy0=%1%>dy1=%2%)";
+ format f(str);
+ f%x0%x1;
+ throw std::runtime_error(f.str());
+ }
+ value_t zero = (value_t)(0);
+ value_t t0 = tangent(p0,zero);
+ value_t t1 = tangent(p1,zero);
+ return -(t1-t0)/(dy1-dy0);
+ }
+
+ template<typename RealType>
+ struct less{
+ less(){};
+ bool operator()(
+ const point<RealType>& p1,
+ const point<RealType>& p2
+ )const{
+ return (p1.x()<p2.x());
+ }
+ };
+
+}
+}
+
+#endif // POINT_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/boost/adaptive_rejection_sampling/sampler.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,152 @@
+////////////////////////////////////////////////////////////////////////////
+// sampler.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_ADAPTIVE_REJECTION_SAMPLING_SAMPLER_HPP_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_SAMPLER_HPP_ER_2009
+#include <vector>
+#include <stdexcept>
+#include <boost/assert.hpp>
+#include <stdexcept>
+#include <boost/adaptive_rejection_sampling/approximation.hpp>
+namespace boost{
+namespace adaptive_rejection_sampling{
+ // Interface:
+ // Constructor (forwards to approximation)
+ // sampler(
+ // const DistFun& f,
+ // result_type x0_init,
+ // result_type x1_init,
+ // size_type max_recursion
+ // )
+ // sampler(
+ // const DistFun& f,
+ // typename approx_t::size_type max_recursion
+ // )
+ // Modifier:
+ // initialize(x1,x2) // defined in approximation
+ // result_type operator()(Unif01& e)
+ //
+ template<
+ typename DistFun,
+ template<typename,typename> class Cont = std::vector,
+ template<typename> class Alloc = std::allocator
+ >
+ class sampler : public approximation<
+ DistFun,
+ Cont,
+ Alloc
+ >
+ {
+
+ typedef approximation<
+ DistFun,
+ Cont,
+ Alloc
+ > approx_t;
+ public:
+ typedef typename approx_t::value_type result_type;
+
+ sampler(
+ const DistFun& f,
+ typename approx_t::size_type max_recursion
+ ):approx_t(f,max_recursion),
+ is_postponed_(false),
+ postponed_(0.0)
+ {
+ //warning not initialized
+ }
+ sampler(
+ const DistFun& f,
+ result_type x0_init,
+ result_type x1_init,
+ typename approx_t::size_type max_recursion
+ ):approx_t(f,x0_init,x1_init,max_recursion)
+ ,is_postponed_(false),postponed_(0.0)
+ {}
+
+ sampler(const sampler& that)
+ :approx_t(that),
+ is_postponed_(that.is_postponed_),
+ postponed_(that.postponed_){}
+
+ sampler&
+ operator=(const sampler& that){
+ if(&that!=this){
+ approx_t::operator=(that);
+ is_postponed_ = that.is_postponed_;
+ postponed_ = that.postponed_;
+ }
+ return *this;
+ }
+ // e() samples from (0,1) or [0,1) or (0,1] or [0,1]
+ template<typename Unif01>
+ result_type operator()(Unif01& e){ //not a const because
+ // each call may update the approximation to dist_fun_
+ if(is_postponed_){
+ this->update(postponed_);
+ is_postponed_ = false;
+ }
+ bool reject = true ;
+ result_type u, x, thresh;
+ while(reject){
+ u = gen_excl_endpoints(e);
+ //std::cout << "u1=" << std::setprecision(10) << u;
+ x = approx_t::inverse_cdf(u);
+ //std::cout << "x=" << std::setprecision(10) << x;
+ thresh = exp_lower_minus_upper(x);
+ u = gen_excl_endpoints(e);
+ //std::cout << "u2=" << std::setprecision(10) << u;
+ reject = !( u <= thresh);
+
+ if( reject ){
+ thresh = exp_y_minus_upper(x);
+ u = gen_excl_endpoints(e);
+ //std::cout << "u3=" << std::setprecision(10) << u;
+ reject = !(u<=thresh);
+ if(reject){
+ approx_t::update(x);
+ }else{
+ postpone_update(x);
+ }
+ }
+ }
+ return x;
+ }
+
+ private:
+ bool is_postponed_;
+ result_type postponed_;
+ result_type
+ exp_lower_minus_upper(result_type x)const{
+ result_type a = approx_t::lower(x); // - inf?!
+ a -= approx_t::upper(x);
+ return math_limit::safer_exp(a);
+ }
+ result_type
+ exp_y_minus_upper(result_type x)const{
+ result_type a = approx_t::get_y(x);
+ a -= approx_t::upper(x);
+ return math_limit::safer_exp(a);
+ }
+ void postpone_update(result_type x){
+ is_postponed_ = true;
+ postponed_ = x;
+ }
+ template<typename Unif01>
+ result_type gen_excl_endpoints(Unif01& e)const{
+ result_type tmp = e();
+ bool is_endpoint = ((tmp==0.0)||(tmp==1.0));
+ BOOST_ASSERT(((tmp>0.0)&&(tmp<1.0)) || is_endpoint);
+ if(is_endpoint){
+ tmp = gen_excl_endpoints(e);
+ }//Rejection sampling
+ return tmp;
+ }
+ };
+}
+}
+
+#endif // SAMPLER_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/ars.ps
==============================================================================
Binary file. No diff available.

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/doc/readme.txt 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,88 @@
+//////////////////////////////////////////////////////////////////////////////
+// adaptive_rejection_sampling
+// (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 /
+///////////
+
+Please send questions or suggestions to erwann.rogard_at_[hidden]
+
+////////////
+/ Overview /
+////////////
+
+This collection of C++ classes constructs an approximation to an
+arbitrary log-concave distribution by evaluating its unnormalized log-pdf
+and derivative thereof, at a set of abscissae, and samples from the
+true distribution with a rejection rule.
+
+Individual files contain additional information.
+
+See the accompanying algorithm description (together with references)
+in ars.pdf.
+
+////////////////
+/ Requirements /
+////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+The compiler search path must include
+boost_1_37_0
+sandbox/conditionally_specified_distribution/adaptive_rejection_sampling
+sandbox/conditionally_specified_distribution/math_limit
+sandbox/conditionally_specified_distribution/utility
+//////////////
+/ Discussion /
+//////////////
+
+The algorithm may run into overflows/underflows problems. 1) Some of them
+are already dealt with (exceptions) but a more comprehensive
+approach is needed. 2) With a choice of initial values that are not too
+far in the tails, such problems usually do not arise.
+
+//////////////////////
+/ Output of main.cpp /
+//////////////////////
+
+limits::negative_infinity()-1.79769e+308
+limits::infinity()1.79769e+308
+limits::min_value()2.22507e-308
+limits::log_min_value()-708
+limits::log_max_value()709
+-> test_gaussian
+We draw from the standard-gaussian using the algorithm.
+Results are compared with a similar implementation inMathematica.
+A failure will be generated if the difference is greater than 0.0001
+The uniform draws were Mathematica generated.
+Initialized with (x1,x2)=(-0.5,1.5)
+At i = 1, normalizing constant = 3.45306 vs true value 2.50663
+At i = 21, normalizing constant = 2.57501 vs true value 2.50663
+At i = 41, normalizing constant = 2.57328 vs true value 2.50663
+At i = 61, normalizing constant = 2.56461 vs true value 2.50663
+At i = 81, normalizing constant = 2.56461 vs true value 2.50663
+At i = 101, normalizing constant = 2.54456 vs true value 2.50663
+At i = 121, normalizing constant = 2.54456 vs true value 2.50663
+At i = 141, normalizing constant = 2.52898 vs true value 2.50663
+At i = 161, normalizing constant = 2.52898 vs true value 2.50663
+At i = 181, normalizing constant = 2.52588 vs true value 2.50663
+Initialized with (x1,x2)=(-0.001,0.001)
+At i = 1, normalizing constant = 3.94626 vs true value 2.50663
+At i = 21, normalizing constant = 2.57218 vs true value 2.50663
+At i = 41, normalizing constant = 2.55671 vs true value 2.50663
+At i = 61, normalizing constant = 2.53946 vs true value 2.50663
+At i = 81, normalizing constant = 2.52847 vs true value 2.50663
+At i = 101, normalizing constant = 2.52636 vs true value 2.50663
+At i = 121, normalizing constant = 2.52378 vs true value 2.50663
+At i = 141, normalizing constant = 2.52378 vs true value 2.50663
+At i = 161, normalizing constant = 2.52378 vs true value 2.50663
+At i = 181, normalizing constant = 2.52269 vs true value 2.50663
+<-
+
+

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,259 @@
+/////////////////////////////////////////////////////////////////////////////
+// test_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 <libs/adaptive_rejection_sampling/src/example/test_data.h>
+
+namespace libs{namespace adaptive_rejection_sampling{
+ const double limitingNc=2.50663;//sqrt(2*pi)
+ const double initAr[rowsCount][2]={{-0.5,1.5},{-0.001,0.001}};
+ //TODO {-40,40} or above will generate overflow.
+
+ const double unifsAr[]={
+ //SeedRandom[0]; Table[Random[], {i, 1, 500}]
+0.0318536, 0.640208, 0.724303, 0.580884, 0.931151, 0.636734, 0.928425,
+0.0489398, 0.702304, 0.425234, 0.693611, 0.0187156, 0.741754, 0.803531,
+0.312868, 0.97356, 0.965564, 0.969633, 0.795063, 0.934604, 0.677499,
+0.551747, 0.0255607, 0.806945, 0.645645, 0.911538, 0.301258, 0.226061,
+0.714494, 0.274804, 0.372834, 0.177121, 0.0121903, 0.84957, 0.679223,
+0.158405, 0.270436, 0.0460394, 0.366355, 0.184846, 0.304872, 0.0764065,
+0.571292, 0.250241, 0.627373, 0.52466, 0.545731, 0.443296, 0.981728,
+0.613122, 0.244473, 0.217235, 0.267234, 0.338317, 0.871639, 0.0401144,
+0.255043, 0.488747, 0.192417, 0.881709, 0.984607, 0.442708, 0.826062,
+0.696863, 0.679735, 0.366301, 0.25477, 0.446622, 0.0523622, 0.841641,
+0.709039, 0.00332598, 0.0706346, 0.22852, 0.464566, 0.786091, 0.803401,
+0.890202, 0.592926, 0.745976, 0.548357, 0.401455, 0.40051, 0.864267, 0.56375,
+0.958748, 0.574448, 0.167404, 0.884015, 0.592447, 0.319678, 0.720782,
+0.831653, 0.750805, 0.61064, 0.717456, 0.761018, 0.522286, 0.146074,
+0.931365, 0.957617, 0.632083, 0.553148, 0.185389, 0.40926, 0.230628,
+0.152638, 0.321122, 0.84551, 0.27188, 0.57819, 0.153718, 0.961495, 0.679433,
+0.258512, 0.432936, 0.129842, 0.928628, 0.647872, 0.715481, 0.368824,
+0.406342, 0.501798, 0.784116, 0.411207, 0.774259, 0.94865, 0.598727,
+0.00194757, 0.543631, 0.796012, 0.277605, 0.156438, 0.271751, 0.217822,
+0.123887, 0.194943, 0.592318, 0.959311, 0.690951, 0.0651006, 0.66369,
+0.311439, 0.97547, 0.696276, 0.257348, 0.809641, 0.191355, 0.285069,
+0.483089, 0.86099, 0.592628, 0.283121, 0.939458, 0.0649782, 0.315023,
+0.126683, 0.667706, 0.847156, 0.191135, 0.93174, 0.0753886, 0.887845,
+0.500184, 0.86664, 0.411698, 0.576406, 0.524714, 0.170364, 0.154351,
+0.766766, 0.333359, 0.885295, 0.671262, 0.905775, 0.740731, 0.602173,
+0.731804, 0.840797, 0.425709, 0.47549, 0.0640975, 0.993641, 0.234573,
+0.543749, 0.988709, 0.105796, 0.734389, 0.67711, 0.57701, 0.52939, 0.209675,
+0.506746, 0.42266, 0.762624, 0.876316, 0.621451, 0.751398, 0.856849,
+0.135585, 0.019278, 0.0195941, 0.016052, 0.709877, 0.543788, 0.955497,
+0.0224109, 0.475303, 0.0000388042, 0.966788, 0.916615, 0.740914, 0.322929,
+0.389777, 0.387225, 0.531239, 0.816183, 0.967117, 0.624601, 0.654923,
+0.194732, 0.215719, 0.767752, 0.519338, 0.175454, 0.196125, 0.7517, 0.809461,
+0.631666, 0.240629, 0.72929, 0.334158, 0.631627, 0.273841, 0.812675,
+0.593243, 0.308698, 0.884064, 0.425449, 0.0620045, 0.492515, 0.916946,
+0.800848, 0.407082, 0.297782, 0.701227, 0.0330955, 0.887744, 0.122328,
+0.505102, 0.281395, 0.0782829, 0.490662, 0.264473, 0.552106, 0.744125,
+0.859035, 0.990632, 0.739431, 0.150882, 0.550337, 0.106569, 0.313982,
+0.0888772, 0.0578224, 0.189623, 0.513134, 0.681795, 0.76004, 0.488396,
+0.480038, 0.794051, 0.637712, 0.983294, 0.198643, 0.715769, 0.14705,
+0.718821, 0.646538, 0.971643, 0.288015, 0.728189, 0.907107, 0.820762,
+0.737678, 0.62162, 0.593125, 0.731885, 0.679855, 0.431998, 0.079991,
+0.0500892, 0.919815, 0.943602, 0.599953, 0.256038, 0.282103, 0.960308,
+0.40131, 0.540269, 0.135054, 0.241487, 0.754772, 0.568626, 0.847039,
+0.513298, 0.847666, 0.747864, 0.109361, 0.891678, 0.254541, 0.0159792,
+0.429506, 0.45968, 0.17455, 0.96589, 0.509691, 0.516078, 0.574597, 0.709852,
+0.227587, 0.555771, 0.173287, 0.169583, 0.0925333, 0.314284, 0.418515,
+0.600957, 0.245494, 0.800986, 0.57085, 0.853094, 0.136133, 0.909308,
+0.316309, 0.837114, 0.706627, 0.449628, 0.141759, 0.871224, 0.196936,
+0.93355, 0.567162, 0.161372, 0.969349, 0.377779, 0.393875, 0.991789,
+0.876816, 0.0634953, 0.97536, 0.390831, 0.631322, 0.262509, 0.40451,
+0.537738, 0.495189, 0.353201, 0.0882012, 0.700624, 0.788562, 0.903573,
+0.946442, 0.829399, 0.591625, 0.970023, 0.37928, 0.668027, 0.622276,
+0.592244, 0.985405, 0.676238, 0.74546, 0.528749, 0.0100459, 0.285407,
+0.114139, 0.266239, 0.605536, 0.747669, 0.61895, 0.913038, 0.517335,
+0.0470457, 0.830388, 0.00946538, 0.570893, 0.217646, 0.238763, 0.0394421,
+0.191613, 0.549619, 0.616487, 0.447198, 0.206207, 0.873381, 0.871027,
+0.918449, 0.196161, 0.587974, 0.756888, 0.65221, 0.590625, 0.840305,
+0.137938, 0.739172, 0.0732904, 0.793259, 0.307549, 0.729706, 0.502398,
+0.575612, 0.0687861, 0.690264, 0.310785, 0.0259931, 0.452299, 0.243066,
+0.104578, 0.152612, 0.581272, 0.324617, 0.908417, 0.564639, 0.824385,
+0.672407, 0.317792, 0.724334, 0.686447, 0.933235, 0.244501, 0.931075,
+0.378898, 0.203529, 0.742103, 0.355463, 0.310111, 0.513265, 0.431318,
+0.32947, 0.857812, 0.270199, 0.32674, 0.176857, 0.27654, 0.945583, 0.418323,
+0.612219, 0.452155, 0.273176, 0.100532, 0.887885, 0.765708, 0.339941,
+0.85603, 0.95681, 0.386811, 0.136412, 0.113927, 0.601347, 0.0766993,
+0.623147, 0.682609, 0.271877, 0.218887, 0.352948, 0.355869, 0.0950198,
+0.942347, 0.407365, 0.937545, 0.482801, 0.490192, 0.134189, 0.837014,
+0.594916, 0.724483, 0.794248, 0.980983, 0.638107, 0.337673, 0.657837,
+0.867056, 0.0367598, 0.260973, 0.0346899, 0.184448, 0.764883, 0.0420863,
+0.681742, 0.828579, 0.669863, 0.0997392, 0.274377, 0.891033, 0.187062,
+0.609547, 0.140188, 0.0540195, 0.592145
+ };
+
+ const double dbarsAr[rowsCount][colsCount]={
+//http://library.wolfram.com/infocenter/MathSource/7071/
+//Needs/@{"DerivativeBasedAdaptiveRejectionSampling`"}
+//(updf[x_]=-x^2/2);
+//derpdf[x_]=D[updf[x],x];fun[x_]:=Through[{updf,derpdf}[x]];
+//obj=Make[DerivativeBasedAdaptiveRejectionSampling,-Infinity,{-0.5,1.5},
+//Infinity,fun];
+//SeedRandom[0];
+//Table[Random[obj],{i,1,200}]
+ {
+0.141745, 1.46004, 0.435265, 0.405936, 0.569917, 0.69644, 0.28452, 1.31983,
+-0.948686, -0.355268, -2.28089, -1.0315, -1.69986, -0.921566, -1.47095,
+-0.690358, 0.0578929, -0.148842, -0.711542, -0.639049, 1.14158, -0.677548,
+-0.894439, 2.22401, 0.523814, -0.351621, -0.139481, 1.01296, -2.71976,
+-0.764845, 0.808851, 1.23049, 0.674951, -0.257876, 1.10572, 1.75395,
+-0.995511, 0.237257, 0.595794, 0.69054, 0.585606, 0.0547851, 1.49416,
+0.342468, -0.922238, -0.757723, -0.477841, -0.625136, -1.05489, -0.659164,
+-1.15407, 0.388236, -0.33907, 0.00665978, -0.226911, 1.64774, -2.89875,
+0.846041, -1.0304, -0.792532, -0.87503, 1.76212, -1.54685, -0.499185,
+0.525101, 0.894835, -0.577293, 1.09351, -0.583184, -1.54777, -1.16989,
+1.03661, 1.49894, 1.2201, 1.11822, 0.198862, -0.971502, 0.745697, 1.20699,
+1.32035, 0.266477, 1.01176, -0.0603491, 2.60336, 2.29275, 0.637665, 0.19831,
+-0.822231, -0.198492, 1.15692, 0.691748, -1.12689, -2.06152, 0.562544,
+1.70426, -0.0625452, 1.83791, -0.467944, -0.292193, 0.912702, 0.393499,
+-0.805756, 0.0410027, -0.876347, 0.874439, -0.722345, -0.441612, -0.618086,
+0.230796, 1.19514, -1.57416, 1.38229, -0.246109, 0.523543, 1.21369,
+0.00502308, -1.45678, -0.646947, 0.65328, 2.36906, -1.06022, -1.28207,
+-1.38752, -0.900858, 0.467792, -0.037129, 0.818464, 2.13572, 0.566456,
+0.575598, 1.90916, 0.603957, 0.917385, 0.305047, 0.615273, -0.181381,
+0.254675, -0.57974, -0.251611, -1.10844, 0.691832, 1.02829, 1.03096,
+-1.23667, -0.663676, -0.178793, -0.939778, 0.0241847, 0.189163, -0.749454,
+-0.944755, -1.33115, -0.207084, -0.692012, 0.179532, -1.10342, -0.480246,
+0.544648, -1.07765, -0.855219, 0.170068, 1.87704, -0.270944, -1.5292,
+0.337762, -0.241472, -0.0106132, -1.35404, 0.804609, 1.61488, 0.23439,
+-0.307646, 0.314074, 2.19449, 0.663366, -2.33366, -1.20824, 0.270442,
+0.305383, 0.0449081, 0.960354, 0.180996, -0.711864, -0.872776, 0.298954,
+-0.820307, 1.13637, -0.856141, 0.699548, 0.231805, -1.09235, -1.45408,
+-0.504153, 0.00741735, -1.48758, -0.494894, -0.118789, -1.25911, 0.207677,
+1.33258
+ },
+ {
+-1.0069, -0.0888453, -0.831128, -1.5793, -0.714572, -1.31585, -0.473706,
+0.449351, 2.24188, -0.762645, -0.40621, -0.646156, -0.861084, 2.15386,
+1.04294, -0.34856, -0.137735, 1.02059, -2.72294, -0.757315, 0.80602, 1.25789,
+0.674914, -0.254455, 1.1239, 1.74859, -0.984392, 0.237422, 0.596959,
+0.690173, 0.586869, 0.0568957, 1.51853, 0.127728, -0.240463, -1.05212,
+1.01533, 0.191764, 1.77757, -0.666622, -1.15893, 0.571003, -0.242494,
+0.785751, 0.75323, -2.89553, 0.827233, -1.02354, -0.789845, -0.87066,
+1.75448, -1.5403, -0.503064, -0.662954, -0.884808, -0.0474979, 0.230706,
+1.55874, -0.490513, 0.430597, -0.885626, -1.46475, 1.11678, 0.193279,
+-0.95459, 0.730364, 1.2089, 1.3218, 0.258749, 1.00223, -0.0621141, 2.52404,
+0.110627, 0.62817, 0.194668, -0.809695, -0.196692, 1.16396, 0.681194,
+-1.10443, -2.06919, 0.554977, 1.71459, -0.063567, 1.84927, -0.462767,
+-0.288571, 0.902549, 0.316573, -0.863094, 0.732137, -0.935636, 0.680162,
+0.335252, 0.610841, 0.335149, 0.889437, -0.503159, -0.190535, -0.0210858,
+0.846184, -0.534706, -1.84765, 0.0119911, -1.41872, -0.63189, 0.657138,
+2.3761, -1.03278, -1.2465, -1.3493, -0.878755, 0.473413, -0.0301713,
+0.822694, 2.14143, 0.571419, 0.58044, 1.91519, 0.608363, 0.920617, 0.309752,
+0.619516, -0.172522, -1.64758, 1.59082, -0.657837, 1.76081, 0.100862,
+-0.703407, 0.173077, 0.0326771, 0.668846, 1.23965, -2.15419, -0.102648,
+1.83136, 0.0396945, 0.554039, 0.140268, -0.95544, -0.485216, 0.256125,
+0.847413, 1.05309, 1.33953, 0.985332, -0.12802, 1.13626, 1.50674, -0.988656,
+-0.311724, 2.42764, -1.52918, -0.277536, -0.6379, 0.0944436, -0.377421,
+0.527194, 1.30549, 0.954255, 1.89024, 0.434891, 0.233669, 0.661652, -2.33993,
+-1.20633, 0.267835, 0.303034, 0.0423017, 0.958475, 0.178246, -0.712382,
+-0.871756, 0.296549, -0.819792, 1.13558, -0.855267, 0.697873, 0.229045,
+-1.09034, -1.45428, -0.504806, 0.00461931, -1.4878, -0.495555, -0.121771,
+-1.2577, 0.204893, 1.33436, 0.934877, -0.475671, 0.486964, -0.694213,
+-0.309207, 0.651196, -0.497478, -0.174707, 1.07433, -0.450561
+ }/*,
+ {
+0.529408, -0.572962, 0.513134, 1.09102, -0.446931, -2.31367, -1.07024,
+-1.65772, -0.991474, -1.41893, 0.316418, 0.101749, 2.20439, -0.789688,
+-0.455837, -0.671601, -0.133474, 0.533734, -0.33293, -0.123377, 1.01884,
+-2.84025, -0.739753, 0.817716, 1.23135, 0.68474, -0.240307, 1.1094, 1.74923,
+-0.964486, 0.247936, 0.605768, 0.700262, 0.595585, 0.0704208, 1.49061,
+0.351399, -0.893621, -0.732741, -0.457881, -0.602697, -1.02153, 0.482917,
+-0.158708, 1.4697, 0.589565, -0.22761, 0.810946, 0.777513, -0.588444,
+-0.606062, -1.15607, 0.238942, -1.51718, -0.491623, 0.5219, 0.891154,
+-0.568383, 1.09968, -0.574161, -1.51816, -1.14434, 1.04009, 1.49898, 1.2251,
+1.12483, 0.197319, -0.955108, 0.7397, 1.21228, 1.32328, 0.264442, 1.0136,
+-0.05877, 2.59868, 0.113766, 0.636344, 0.19926, -0.808387, -0.194002,
+1.16929, 0.68976, -1.10335, -2.06418, 0.562148, 1.71744, -0.0596623, 1.85829,
+0.656597, -0.278601, 0.0820534, 1.86301, 0.405698, -0.787386, 0.0518405,
+-0.856926, 0.890728, -0.704709, -0.427899, -0.602186, 0.241426, 1.20638,
+-1.54251, 1.39324, -0.233995, 0.536647, 1.22478, 0.0158325, -1.41932,
+-0.630541, 0.666663, 2.42852, 0.129343, -0.485568, -1.57847, 0.034831,
+0.715261, -0.0488615, 0.357443, 0.577802, 0.586948, 1.91679, 0.615296,
+0.930781, 0.31408, 0.626599, -0.171493, -1.64925, 1.59048, -0.657399,
+1.76157, 0.10329, -0.702949, 0.175781, 0.0348913, 0.676323, 1.24054, -2.1487,
+-0.100895, 1.83245, 0.0419179, 0.5602, 0.142844, -0.959328, -0.484952,
+0.259603, 0.856629, 1.06205, 1.33933, 0.995501, -0.126491, 1.14199, 1.50614,
+-0.99265, -0.311227, 2.43815, -1.53094, 0.34045, -0.241218, -0.0102394,
+-1.35164, 0.812487, 1.61671, 0.235734, -0.306519, 0.316296, 2.20262,
+0.669109, -2.33199, -1.20476, 0.272096, 0.307466, 0.0456673, 0.968802,
+0.182121, -0.71053, -0.873064, 0.300945, -0.82023, 1.14137, 0.221495,
+0.391493, 0.998431, 0.642341, 0.820357, 0.613393, 0.189654, 0.497326,
+-1.94589, -0.699194, -1.02964, -0.457675, 0.161575, 0.447034, 0.597158,
+1.50555, 1.48887, -0.832003, -0.372902, 0.0313541
+ }
+*/
+};
+
+const double dbarsAr_1[rowsCount][colsCount]={
+ {
+0.141745, 1.33381, 0.426831, 1.26225, -1.89854, -0.897882, 0.838643,
+-1.54007, -2.30111, -0.044346, 0.142936, -0.135894, 2.24405, 1.12291,
+-1.65728, 0.998875, 0.74184, -0.933235, -0.0388802, 1.04855, 0.489241,
+-0.754671, 1.70117, 1.012, 0.710938, 0.389866, -0.711446, -1.19651,
+-0.0203415, 1.74711, -0.598965, 0.20724, -0.725755, -0.701951, 0.0494646,
+-0.143604, -1.24613, 0.0279407, 2.15801, 0.681699, 0.328013, 1.44541,
+-1.23486, 0.828028, 1.36543, 1.03439, 0.918938, -0.0265206, -0.387218,
+-0.076768, 0.800854, -0.411455, 2.16942, 0.457931, -0.196697, -0.284127,
+0.534544, 0.503739, -3.41858, 1.84569, -1.18528, 0.0780855, 0.150777,
+0.408558, 0.443995, 0.156452, 0.692409, 1.01228, 0.759334, -1.34742, 1.03379,
+-0.290627, 2.86162, -0.119085, -1.24148, 0.700215, -2.29297, 0.964773,
+0.124512, 0.303614, 1.61431, -1.4556, -0.156011, 1.0084, 0.830255, 1.05757,
+0.154845, -1.88508, -0.129886, 1.03547, 1.176, 0.785608, 1.53973, 1.8992,
+2.77731, 2.04471, -1.59957, -0.330269, 1.26241, 0.0256007, 0.268512,
+-0.220542, -1.43231, 0.0720815, 1.204, 0.14314, -1.7892, -0.121695,
+-0.534143, 0.941237, 0.0132183, 0.022217, 0.470914, 0.626662, 0.445137,
+-1.29242, -0.00970714, 1.16948, 0.735443, -1.88325, -0.433613, -0.606454,
+-1.54183, -1.49544, 0.094033, 0.723201, 0.867906, -0.520399, -1.00751,
+1.47801, 1.42468, -0.350553, 0.785197, 0.629861, -2.46001, -2.30542,
+0.309157, -1.10753, -0.577067, 1.62911, 0.45703, -0.935387, -0.549376,
+-0.0946363, 0.371496, -2.41213, -0.220742, 0.175092, 1.09752, -0.62542,
+1.12166, -2.09823, -0.601381, -2.86214, 0.10954, 0.590989, -0.973066,
+1.46301, 0.792074, -1.34962, -0.879902, 1.65352, 0.437317, 0.173572,
+0.925062, 0.048294, -1.28388, -1.72524, 0.645622, -1.18075, -2.22984,
+-0.723657, 0.189837, 2.37712, -0.75926, 0.538907, -0.43072, 0.944666,
+-0.837109, 0.976338, 1.34111, 0.0991566, -0.258803, -1.06002, 1.21002,
+-1.44289, 0.638089, 1.00737, 1.71371, -0.597833, 0.0714153, 0.480828,
+-0.404158, 0.644062, 0.307913, -0.186949, -1.86538, 1.14846, -1.48996,
+-1.52847
+ }
+ ,{
+-1.0069, 0.156742, -0.417404, 0.437548, -0.281333, 1.04091, 0.227179,
+-1.42126, -0.117095, 0.170918, 0.32806, -0.869292, -1.08031, -0.781675,
+-0.633754, -0.303382, -0.10267, 2.09981, -0.580473, 1.42548, 0.46753,
+0.435109, -1.56679, 0.35183, 0.568393, 0.915227, 1.0314, -0.693608, 0.401515,
+-0.26384, 0.059707, -0.22768, 1.12433, 0.851969, -0.331733, -0.72248,
+-1.14998, 1.58311, -0.667841, -0.369045, -0.37373, 0.270167, 0.31521,
+1.35972, 0.306363, -0.345251, -0.015306, -0.130807, -0.189045, -1.49638,
+0.627692, 0.73079, 1.67192, -0.106333, 0.963331, 0.164454, 1.96056, -0.56965,
+1.9271, -0.504757, 2.23061, 0.5194, -1.19926, 0.0095152, -0.317078, 0.563346,
+-1.5221, 0.739839, -0.571485, -0.440377, 0.0709085, -0.747549, -0.0910522,
+1.40917, -0.260453, 0.0130628, -1.45343, 0.826262, 1.2158, 0.0783399,
+0.0412418, 0.963945, 1.15625, -1.91127, 0.189972, -0.382944, 0.0918011,
+0.454509, -0.703767, -0.174849, 0.159959, 1.05823, -0.4264, -0.590481,
+-1.2988, -0.848062, 0.241531, -0.510632, -0.0275028, 0.473148, 1.13515,
+0.242954, -0.14626, -1.01411, -0.2157, -0.737154, -0.633909, -0.654967,
+1.53957, 1.48028, 0.152267, -1.56139, -0.206021, 0.122424, 0.70234,
+-0.578689, 1.11168, 2.44343, 1.59295, -0.839182, 0.2639, -0.173227, -0.27531,
+-0.630458, -0.334442, 1.23416, -1.51948, 1.13123, -1.66876, -0.429953,
+-0.434543, 0.450697, -0.434158, 0.602726, 1.61313, -1.4758, -0.375996,
+-1.02527, -0.666235, -1.46841, -0.356521, 0.677749, 1.56872, 2.22185,
+1.00662, 0.108562, -0.118864, -1.16429, 0.513448, 0.161982, -0.189252,
+1.27415, -0.342396, -0.0141248, 1.49332, -1.12614, -0.0865247, -0.316942,
+0.951224, -0.10252, 0.577158, -0.0862558, -1.50196, -2.05539, 0.6763,
+1.44124, 2.1768, -1.88302, -1.30918, -0.805962, -1.45817, -0.136336,
+-0.0609584, 0.402924, 0.5517, 1.46616, 0.704505, 0.20012, -0.823511,
+-0.862812, -0.292884, 0.465785, 0.425288, 1.16758, 3.24276, -0.0773998,
+0.0257699, -1.71858, 0.108825, -0.67329, -1.22934, 0.29387, 0.347636,
+-0.442009, -0.824865, -0.540887, -0.618095, -1.14491, -0.0768351, -0.283569
+ }
+
+ };
+}//adaptive_rejection_sampling
+}//libs
+
+

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_data.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,63 @@
+/////////////////////////////////////////////////////////////////////////////
+// test_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 BOOST_ADAPTIVE_REJECTION_SAMPLING_TEST_DATA_H_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_TEST_DATA_H_ER_2009
+
+#include <vector>
+#include <cstddef>
+#include <boost/utility.hpp>
+#include <iostream>
+#include <stdexcept>
+#include <boost/shared_ptr.hpp>
+
+namespace libs{namespace adaptive_rejection_sampling{
+ extern const double limitingNc;//sqrt(2*pi)
+ const unsigned rowsCount=2;
+ const unsigned colsCount=200;
+ const unsigned unifsCount=500;
+ const unsigned show_count=1; //show every show_count iteration
+
+ extern const double dbarsAr[rowsCount][colsCount];
+ extern const double dbarsAr_1[rowsCount][colsCount];
+ extern const double initAr[rowsCount][2];
+ extern const double unifsAr[unifsCount];
+
+ ///A test class
+ class Uniform_sampler_mathematica :public boost::noncopyable{
+ public:
+ typedef double input_type;
+ typedef double result_type;
+ double min()const{return 0.0;};
+ double max()const{return 1.0;};
+ //(unsigned int* seed_):_seed(seed_){//forces a call to reset()
+ Uniform_sampler_mathematica(){
+ unifs.reserve(unifsCount);
+ for(size_t i=0; i<unifsCount; ++i){
+ //std::cout << "unifsAr[i]=" << unifsAr[i] << std::endl;
+ unifs.push_back(unifsAr[i]);
+ };
+ it = unifs.begin();
+ //std::cout << "unifs.size()=" << unifs.size() << std::endl;
+ };
+ unsigned long it_distance()const{return (it-unifs.begin());};
+ double operator()(){
+ double ret;
+ if(it!=unifs.end()){ret = (*it); ++it;}else{
+ throw std::runtime_error(
+ "Uniform_sampler_mathematica: out of range");};
+ return ret;
+ };
+ //not sure if this impl of reset models that of
+ unsigned int reset(){it=unifs.begin(); return unifs.size();};
+ private:
+ std::vector<double> unifs;
+ std::vector<double>::const_iterator it;
+ };
+
+}
+}
+#endif

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,82 @@
+/////////////////////////////////////////////////////////////////////////////
+// test_gaussian.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 <list>
+#include <vector>
+#include <boost/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/format.hpp>
+#include <boost/adaptive_rejection_sampling/example/standard_gaussian.hpp>
+#include <boost/adaptive_rejection_sampling/sampler.hpp>
+#include <libs/adaptive_rejection_sampling/src/example/test_data.h>
+#include <libs/adaptive_rejection_sampling/src/example/test_gaussian.h>
+namespace libs{
+namespace adaptive_rejection_sampling{
+ void example_standard_gaussian(){
+ std::cout<<"-> test_gaussian"<<std::endl;
+ const double tolerance = 1e-4; //1e-5 causes fail
+ const unsigned report_every = 20;
+ std::string str;
+ str+= "We draw from the standard-gaussian using the algorithm.";
+ str+= " Results are compared with a similar implementation in";
+ str+= "Mathematica. A failure will be generated if the difference";
+ str+= " is greater than %1%";
+ str+= " The uniform draws were Mathematica generated.";
+ boost::format f(str); f % tolerance;
+ std::cout << f.str() << std::endl;
+
+ Uniform_sampler_mathematica usm;
+ typedef boost::adaptive_rejection_sampling
+ ::standard_gaussian_evaluator<double>
+ dist_fun_type;
+ typedef boost::adaptive_rejection_sampling
+ ::sampler<dist_fun_type,std::vector> dbars_t;
+ dist_fun_type dist_fun;
+ dbars_t dbars0(dist_fun,10);
+ //,dist_fun,us);
+
+ //checks that copy constructor works
+ dbars_t dbars = dbars0;
+
+ try{
+ for(unsigned int j=0; j<rowsCount; ++j){
+ double drawVal,ncVal;
+ BOOST_STATIC_ASSERT(colsCount<=unifsCount);
+ usm.reset();
+ dbars.initialize(initAr[j][0], initAr[j][1]);
+ std::cout<<"Initialized with (x1,x2)=("<<
+ initAr[j][0]<<","<<initAr[j][1]<<")"<<std::endl;
+ for(unsigned int i=0; i<colsCount; i++){
+ //std::cout << "usm.it_distance()="
+ //<< usm.it_distance() << std::endl;
+ drawVal = dbars(usm);
+ ncVal = dbars.total_unnormalized_cdf();
+ BOOST_ASSERT(drawVal < dbarsAr[j][i]+tolerance);
+ BOOST_ASSERT(drawVal > dbarsAr[j][i]-tolerance);
+ if(!(i%report_every)){
+ std::cout
+ << "At i = "<< i+1
+ << ", normalizing constant = "
+ << ncVal
+ << " vs true value "
+ << limitingNc
+ << std::endl;
+ }
+ };
+ };
+ }catch(std::exception& e){
+ std::cerr << e.what() << std::endl;
+ std::cout << "This throw is meant to illustrate the"
+ << "!(delta>0.0) pitfall described in"
+ << " approximation_impl::update_unnormalized_cdf_impl"
+ << std::endl;
+ };
+
+ std::cout<<"<-"<<std::endl;
+ };
+}
+}

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/example/test_gaussian.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// test_gaussian.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 BOOST_ADAPTIVE_REJECTION_SAMPLING_TEST_GAUSSIAN_H_ER_2009
+#define BOOST_ADAPTIVE_REJECTION_SAMPLING_TEST_GAUSSIAN_H_ER_2009
+
+namespace libs{
+namespace adaptive_rejection_sampling{
+ extern void example_standard_gaussian();
+}
+}
+
+#endif /*DBARS_TEST_GAUSSIAN_H_*/

Added: sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/adaptive_rejection_sampling/libs/adaptive_rejection_sampling/src/main.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,35 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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 <boost/math_limit/miscellanea.hpp>
+#include <libs/adaptive_rejection_sampling/src/example/test_gaussian.h>
+
+using namespace std;
+
+int main()
+{
+
+ typedef boost::math_limit::limits<double> tmp_t;
+ std::cout
+ << "limits::negative_infinity()"
+ << tmp_t::negative_infinity() << std::endl;
+ std::cout
+ << "limits::infinity()"
+ << tmp_t::infinity() << std::endl;
+ std::cout
+ << "limits::min_value()"
+ << tmp_t::min_value() << std::endl;
+ std::cout
+ << "limits::log_min_value()"
+ << tmp_t::log_min_value() << std::endl;
+ std::cout
+ << "limits::log_max_value()"
+ << tmp_t::log_max_value() << std::endl;
+
+ libs::adaptive_rejection_sampling::example_standard_gaussian();
+ return 0;
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,14 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_INCLUDE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_INCLUDE_HPP_ER_2009
+
+#include <boost/conditionally_specified_distribution/crtp/pair_independent.hpp>
+#include <boost/conditionally_specified_distribution/crtp/normal.hpp>
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,20 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_NORMAL_HPP_ER_2009
+
+namespace boost{namespace conditionally_specified_distribution{
+namespace crtp{
+
+ template<typename D>
+ struct normal{};
+
+}
+}}
+
+#endif // BOOST_DISTRIBUTION_CRTP_NORMAL_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/pair_independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/crtp/pair_independent.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,20 @@
+/////////////////////////////////////////////////////////////////////////////
+// pair_independent.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_PAIR_INDEPENDENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_CRTP_PAIR_INDEPENDENT_HPP_ER_2009
+
+namespace boost{namespace conditionally_specified_distribution{
+namespace crtp{
+
+ template<typename D>
+ struct pair_independent{};
+
+}
+}}
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/detail/adapter.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/detail/adapter.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,93 @@
+/////////////////////////////////////////////////////////////////////////////
+// adapter.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_DETAIL_ADAPTER_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_DETAIL_ADAPTER_HPP_ER_2009
+#include <utility>//pair
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+#include <boost/conditionally_specified_distribution/support/include.hpp>
+#include <boost/conditionally_specified_distribution/function/include.hpp>
+namespace boost{namespace conditionally_specified_distribution{namespace function{
+
+namespace detail{
+
+ //This adapter is needed for adaptive rejection sampling
+
+ template<typename Par,typename Args>
+ class adapter{
+ typedef typename function_support<Par>::type support_t;
+ public:
+ typedef typename function_argument<Par>::type argument_type;
+ typedef typename function_value<Par>::type result_type;
+ //TODO see adpative_rejection_sampler::value_type
+ typedef result_type value_type;
+
+ adapter(const Par& par,const Args& args)
+ : par_(par),args_(args){}
+
+ adapter(
+ const adapter& that
+ ): par_(that.par_),args_(that.args_){}
+
+ result_type
+ unnormalized_log_pdf(argument_type x)const{
+ return function::unnormalized_log_pdf(
+ this->par_,this->args_,x
+ );
+ }
+ result_type
+ derivative_unnormalized_log_pdf(argument_type x)const{
+ return function::derivative_unnormalized_log_pdf(
+ this->par_,this->args_,x);
+ }
+
+ result_type
+ log_pdf(argument_type x)const{
+ return log_pdf(this->par_,this->args_,x);
+ }
+ result_type
+ score(argument_type x)const{
+ return score(this->par_,this->args_,x);
+ }
+
+ argument_type
+ min()const{
+ return (this->support()).first;
+ }
+
+ argument_type
+ max()const{
+ return (this->support()).second;
+ }
+
+ typename function_support<Par>::type
+ support()const{
+ return function::support(
+ (this->par_),
+ (this->args_)
+ );
+ }
+
+ private:
+ adapter();
+ adapter& operator()(const adapter&);
+ const Par& par_;
+ const Args& args_;
+
+ };
+
+template<typename Par,typename Args>
+adapter<Par,Args>
+make_adapter(const Par& p,const Args& a){
+ return adapter<Par,Args>(p,a);
+}
+
+}//detail
+}//function
+}//distribution
+}//boost
+#endif // BOOST_DISTRIBUTION_FUNCTION_BIND_ARGUMENT_PACK_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,14 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_INCLUDE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_INCLUDE_HPP_ER_2009
+
+#include <boost/conditionally_specified_distribution/function/normal.hpp>
+#include <boost/conditionally_specified_distribution/function/pair_independent.hpp>
+
+#endif // INCLUDE_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,73 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_NORMAL_HPP_ER_2009
+#include <cmath>
+#include <boost/math/special_functions/fpclassify.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace function{
+// T lgamma_imp(T z, const Policy& pol, const lanczos::undefined_lanczos& l, int*sign)
+//static const char* function = "boost::math::lgamma<%1%>(%1%)";
+// if(floor(z) == z)
+// return policies::raise_pole_error<T>(function, "Evaluation of tgamma at a negative integer %1%.", z, pol);
+
+ template<typename D,typename Args>
+ typename function_argument<D>::type
+ zscore(
+ const D& d, // d.mu(args), d.sigma(args)
+ const Args& args,
+ typename function_argument<D>::type x//,
+ //const Policy&, pol //TODO
+ ){
+ typedef typename function_argument<D>::type value_type;
+ value_type m = d.mu(args);
+ value_type s = d.sigma(args);
+ value_type result = (x-m)/s;
+
+ return result;
+ };
+
+ template<typename D,typename Args>
+ typename function_value<D>::type
+ unnormalized_log_pdf(
+ const crtp::normal<D>& d,
+ const Args& args,
+ typename function_argument<D>::type x
+ ){
+ typedef typename function_argument<D>::type value_type;
+ const D& d_ = static_cast<const D&>(d);
+ value_type z = zscore(d_,args,x);
+ value_type sigma = d_.sigma(args);
+ value_type log_sigma = log(sigma);
+ value_type result = -(z*z)/((value_type)(2)) - log_sigma;
+ return result;
+ };
+
+ template<typename D,typename Args>
+ typename function_value<D>::type
+ derivative_unnormalized_log_pdf(
+ const crtp::normal<D>& d,
+ const Args& args,
+ typename function_argument<D>::type x
+ ){
+ typedef typename function_argument<D>::type value_type;
+ const D& d_ = static_cast<const D&>(d);
+ value_type z = zscore(d_,args,x);
+ value_type sigma = d_.sigma(args);
+ value_type result = - (z / sigma);
+ return result;
+ };
+
+
+
+}
+}
+}
+
+#endif // BOOST_DISTRIBUTION_FUNCTION_NORMAL_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/pair_independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/function/pair_independent.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,65 @@
+/////////////////////////////////////////////////////////////////////////////
+// pair_independent.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_PAIR_IDEPENDENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FUNCTION_PAIR_IDEPENDENT_HPP_ER_2009
+#include <boost/conditionally_specified_distribution/crtp/pair_independent.hpp>
+#include <boost/conditionally_specified_distribution/result_of/first.hpp>
+#include <boost/conditionally_specified_distribution/result_of/second.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace function{
+
+
+ template<typename D,typename Args>
+ typename function_value<D>::type
+ unnormalized_log_pdf(
+ const crtp::pair_independent<D>& d,
+ const Args& args,
+ typename function_argument<D>::type x
+ ){
+ const D& d_ = static_cast<const D&>(d);
+
+ return
+ unnormalized_log_pdf(d_.first(args),args,x)
+ + unnormalized_log_pdf(d_.second(args),args,x);
+ };
+
+ template<typename D,typename Args>
+ typename function_value<D>::type
+ derivative_unnormalized_log_pdf(
+ const crtp::pair_independent<D>& d,
+ const Args& args,
+ typename function_argument<D>::type x
+ ){
+ const D& d_ = static_cast<const D&>(d);
+
+ // TODO find out why this fails
+ /*
+ typedef typename
+ result_of::template first<D(const Args&)>::type cref0_t;
+ typedef typename
+ result_of::template second<D(const Args&)>::type cref1_t;
+
+ cref0_t cref0 = d_.first(args);
+ cref1_t cref1 = d_.second(args);
+
+ return
+ derivative_unnormalized_log_pdf(cref0,args,x)
+ + derivative_unnormalized_log_pdf(cref1,args,x);
+ */
+ return
+ derivative_unnormalized_log_pdf(d_.first(args),args,x)
+ + derivative_unnormalized_log_pdf(d_.second(args),args,x);
+ };
+
+
+}
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/parameter.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,61 @@
+/////////////////////////////////////////////////////////////////////////////
+// parameter.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_KEYWORD_PARAMETER_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_KEYWORD_PARAMETER_HPP_ER_2009
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace parameter{
+namespace tag{
+ template<typename Id> struct mu_{};
+ template<typename Id> struct sigma_{};
+ template<typename Id> struct value_{};
+ template<typename Id> struct correlation_{};
+ //TODO nu, alpha, beta, p, n, etc.
+}
+namespace{
+ template<typename Id>
+ class kwd{
+ typedef tag::mu_<Id> mu_t;
+ typedef tag::sigma_<Id> sigma_t;
+ typedef tag::value_<Id> value_t;
+ typedef tag::correlation_<Id> corr_t;
+ public:
+ typedef Id id_type;
+ static ::boost::parameter::keyword<mu_t>& mu;
+ static ::boost::parameter::keyword<sigma_t>& sigma;
+ static ::boost::parameter::keyword<value_t>& value;
+ static ::boost::parameter::keyword<corr_t>& correlation;
+ };
+
+ template<typename Id>
+ ::boost::parameter::keyword<tag::mu_<Id> >&
+ kwd<Id>::mu =
+ ::boost::parameter::keyword<tag::mu_<Id> >::get();
+
+ template<typename Id>
+ ::boost::parameter::keyword<tag::sigma_<Id> >&
+ kwd<Id>::sigma =
+ ::boost::parameter::keyword<tag::sigma_<Id> >::get();
+
+ template<typename Id>
+ ::boost::parameter::keyword<tag::value_<Id> >&
+ kwd<Id>::value =
+ ::boost::parameter::keyword<tag::value_<Id> >::get();
+
+ template<typename Id>
+ ::boost::parameter::keyword<tag::correlation_<Id> >&
+ kwd<Id>::correlation =
+ ::boost::parameter::keyword<tag::correlation_<Id> >::get();
+}//anonymous
+}//parameter
+}//distribution
+}//boost
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/keyword/sampler.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,69 @@
+/////////////////////////////////////////////////////////////////////////////
+// sampler.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_KEYWORD_SAMPLER_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_KEYWORD_SAMPLER_HPP_ER_2009
+#include <boost/mpl/void.hpp>
+#include <boost/parameter/keyword.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace sampler{
+
+//The kwd random_number_generator need not be enclosed in
+// namepsace sampler{}
+//because it's very unlikely to conflict with keywords for parameters.
+
+namespace tag{
+ template<typename Id> struct random_number_generator_;
+ template<typename Id> struct ars_init_interval_;
+ template<typename Id> struct ars_interval_cdf_;
+ template<typename Id> struct ars_max_init_recursion_;
+}
+
+namespace{
+ template<typename Id = mpl::void_>
+ struct kwd{
+ typedef tag::random_number_generator_<Id> rng;
+ typedef tag::ars_init_interval_<Id> ars_i;
+ typedef tag::ars_interval_cdf_<Id> ars_c;
+ typedef tag::ars_max_init_recursion_<Id> ars_m_i_r;
+
+ static
+ ::boost::parameter::keyword<rng>& random_number_generator;
+ static
+ ::boost::parameter::keyword<ars_i>& ars_init_interval;
+ static
+ ::boost::parameter::keyword<ars_c>& ars_interval_cdf;
+ static
+ ::boost::parameter::keyword<ars_m_i_r>& ars_max_init_recursion;
+ };
+ template<typename Id>
+ ::boost::parameter::keyword<tag::random_number_generator_<Id> >&
+ kwd<Id>::random_number_generator =
+ ::boost::parameter::keyword<
+ tag::random_number_generator_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::ars_init_interval_<Id> >&
+ kwd<Id>::ars_init_interval =
+ ::boost::parameter::keyword<
+ tag::ars_init_interval_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::ars_interval_cdf_<Id> >&
+ kwd<Id>::ars_interval_cdf =
+ ::boost::parameter::keyword<
+ tag::ars_interval_cdf_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::ars_max_init_recursion_<Id> >&
+ kwd<Id>::ars_max_init_recursion =
+ ::boost::parameter::keyword<
+ tag::ars_max_init_recursion_<Id> >::get();
+}//anonymous
+}//sampler
+}//distribution
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/detail/regression_coefficient.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/detail/regression_coefficient.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,311 @@
+/////////////////////////////////////////////////////////////////////////////
+// regression_coefficient.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_DEPENDENT_REGRESSION_COEFFICIENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_DEPENDENT_REGRESSION_COEFFICIENT_HPP_ER_2009
+#include <vector>
+#include <boost/range.hpp>
+#include <boost/bind.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+#include <boost/utility/assert_is_base_of.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/depends_on.hpp>
+#include <boost/conditionally_specified_distribution/parameter/detail/skip_position_operations.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace parameter{
+namespace detail{
+
+/// A regression_coefficient computes the inner product (excluding the
+/// element at a specified position) for all datapoints.
+///
+/// {$\eta_{i,-j} = x_{i,0} \beta_0 + ... + x_{i,-j}\beta_{-j}$
+/// $+x_{i,j+1} \beta_{j+1}+...+x_{i,J-1} \beta_{J}$,i=1,...,n}
+
+namespace impl{
+ template<typename Id,typename DataBase,typename CoeffsBase>
+ class regression_coefficient_base{
+ public:
+ typedef std::size_t size_type;
+ // operations defined in regression_coefficient
+
+ struct identifier : mpl::identity<Id>{};
+ struct result_of_position : mpl::identity<size_type>{};
+
+ struct result_of_range_data
+ : conditionally_specified_distribution
+ ::result_of::functor<DataBase>
+ {};
+ protected:
+ struct data_unit
+ : range_value<
+ typename utility::remove_qualifier<
+ typename result_of_range_data::type
+ >::type
+ >
+ {};
+ struct result_of_range_covariate
+ : conditionally_specified_distribution
+ ::result_of::range_covariate<
+ typename data_unit::type
+ >
+ {};
+
+ public:
+ struct result_of_range_coefficient
+ : conditionally_specified_distribution
+ ::result_of::functor<CoeffsBase>
+ {};
+
+ struct result_of_matching_covariate
+ : range_value<
+ typename utility::remove_qualifier<
+ typename result_of_range_covariate::type
+ >::type
+ >
+ {};
+
+ protected:
+
+ typedef typename
+ range_value<
+ typename utility::remove_qualifier<
+ typename result_of_range_coefficient::type
+ >::type
+ >::type value_type;
+ typedef std::vector<value_type> container_type;
+
+ public:
+ struct result_of_range_skip_position_covariate_dot_coefficient
+ : mpl::identity<const container_type&>
+ {};
+
+ // outside interface
+ struct function_value : mpl::identity<value_type>{};
+ struct function_argument : mpl::identity<value_type>{};
+ };
+
+ template<typename Id, typename Dataset,typename Coefficients>
+ class regression_coefficient
+ : public regression_coefficient_base<
+ Id, typename Dataset::traits, typename Coefficients::traits
+ >{
+ typedef regression_coefficient_base<
+ Id,
+ typename Dataset::traits,
+ typename Coefficients::traits
+ > super_t;
+ typedef Dataset data_t;
+ typedef Coefficients coeffs_t;
+ typedef parameter::detail::skip_position_operations impl_t;
+ public:
+ regression_coefficient(typename super_t::size_type pos)
+ :position_(pos){
+ //Warning : state_ default initializes
+ }
+
+
+ template<typename Args>
+ regression_coefficient(const Args& args)
+ :position_(args[shared_features::kwd<Id>::position|0]){
+ //TODO less clumsy
+ typedef mpl::bool_<false> f;
+ alert_if(args[shared_features::kwd_do_initialize|f()],
+ args[shared_features::kwd<Id>::position|-1]
+ );
+ this->update_if(
+ args[shared_features::kwd_do_initialize|f()],
+ args
+ );
+ }
+
+ regression_coefficient(const regression_coefficient& that)
+ :position_(that.position_)
+ {
+ this->set(that.state_);
+ }
+
+ regression_coefficient&
+ operator=(const regression_coefficient& that){
+ if(&that!=this){
+ (this->position_) = that.position_;
+ (this->state_) = that.state_;
+ }
+ return *this;
+ }
+
+ typename conditionally_specified_distribution
+ ::result_of::position<super_t>::type
+ position()const{ return this->position_; }
+
+ typename conditionally_specified_distribution
+ ::result_of::position<super_t>::type
+ position(utility::dont_care)const{
+ return (this->position());
+ }
+
+ template<typename Args>
+ typename conditionally_specified_distribution
+ ::result_of::range_data<super_t>::type
+ range_data(const Args& args)const{
+ return this->get_data(args[shared_features::kwd_set])();
+ }
+
+ template<typename Args>
+ typename conditionally_specified_distribution
+ ::result_of::range_coefficient<super_t>::type
+ range_coefficient(const Args& args)const{
+ return this->get_coeffs(args[shared_features::kwd_set])();
+ }
+
+ typename conditionally_specified_distribution
+ ::result_of::matching_covariate<super_t>::type
+ matching_covariate(
+ typename super_t::data_unit::type const & u
+ )const{
+ impl_t impl(this->position());
+ return impl.matching_element(u.range_covariate());
+ }
+
+ typename conditionally_specified_distribution
+ ::result_of::matching_covariate<super_t>::type
+ matching_covariate(
+ utility::dont_care,
+ typename super_t::data_unit::type const & u
+ )const{
+ return this->matching_covariate(u);
+ }
+
+ // {<x[-i],b[j]> : i =1,...,n}
+ typename conditionally_specified_distribution::result_of
+ ::range_skip_position_covariate_dot_coefficient<
+ super_t
+ >::type
+ range_skip_position_covariate_dot_coefficient()const{
+ return this->state_;
+ }
+ typename conditionally_specified_distribution::result_of
+ ::range_skip_position_covariate_dot_coefficient<super_t>::type
+ range_skip_position_covariate_dot_coefficient(
+ utility::dont_care
+ )const{
+ return this->range_skip_position_covariate_dot_coefficient();
+ }
+
+ template<typename Args>
+ void update(const Args& args){
+ typedef typename utility::remove_qualifier<
+ typename conditionally_specified_distribution
+ ::result_of::range_coefficient<super_t>::type
+ >::type coeffs_type;
+ typedef op<coeffs_type> op_t;
+ op_t the_op(this->position(),this->range_coefficient(args));
+ state_.clear();
+ std::transform(
+ begin(range_data(args)),
+ end(range_data(args)),
+ back_inserter(
+ (this->state_)
+ ),
+ the_op
+ );
+ }
+ private:
+ void alert_if(mpl::bool_<true>,int i)const{
+ BOOST_ASSERT(i>-1);
+ }
+ void alert_if(mpl::bool_<false>,int i)const{}
+ template<typename Args>
+ void update_if(mpl::bool_<true>,const Args& args){
+ this->update(args);
+ }
+ void update_if(mpl::bool_<false>,utility::dont_care){}
+
+ template<typename R>
+ void set(const R& r){
+ state_.clear();
+ copy(
+ begin(r),
+ end(r),
+ back_inserter(
+ (this -> state_)
+ )
+ );
+ }
+ template<typename R>
+ class op{
+ public:
+ typedef typename range_value<R>::type result_type;
+
+ op(typename super_t::size_type pos, const R& coeffs)
+ :impl_(pos),coeffs_(coeffs){}
+
+ op(const op& that)
+ :impl_(that.impl_),coeffs_(that.coeffs_){}
+
+ template<typename DataUnit>
+ result_type
+ operator()(const DataUnit& u)const{
+ return impl_.inner_product_skip_position(
+ u.covariate(),
+ coeffs_
+ );
+ }
+
+ private:
+ op& operator=(const op&);
+ impl_t impl_;
+ const R& coeffs_;
+ };
+ template<typename Set>
+ typename Set::template result_of_extract<coeffs_t>::type const&
+ get_coeffs(const Set& set)const{
+ return set.template extract<coeffs_t>();
+ }
+ template<typename Set>
+ typename Set::template result_of_extract<data_t>::type const&
+ get_data(const Set& set)const{
+ return set.template extract<data_t>();
+ }
+ typename super_t::size_type position_;
+ typename super_t::container_type state_;
+ };
+} //impl
+
+namespace feature{
+ // Provided for testing purposes only
+ // Don't inherit from this feature.
+ template<typename Id, typename Dataset,typename Coefficients>
+ struct regression_coefficient : shared_features::depends_on<
+ mpl::vector<
+ Dataset,
+ Coefficients
+ >
+ >{
+ typedef impl::regression_coefficient_base<
+ Id,
+ typename Dataset::traits,
+ typename Coefficients::traits
+ > traits;
+ typedef impl::regression_coefficient<Id,Dataset,Coefficients> impl;
+ };
+}
+
+}//detail
+}//parameter
+}//csd
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,210 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal_given_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_NORMAL_GIVEN_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_NORMAL_GIVEN_NORMAL_HPP_ER_2009
+#include <cmath>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/depends_on.hpp>
+#include <boost/shared_features/set.hpp>
+
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/conditionally_specified_distribution/crtp/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+
+namespace boost {
+namespace conditionally_specified_distribution{
+namespace parameter{
+
+namespace impl
+{
+ template<typename ParY>
+ class normal_given_normal_base{
+ typedef normal_given_normal_base<ParY> super_t;
+
+ public:
+ struct identifier
+ : conditionally_specified_distribution::identifier<ParY>{};
+ typedef typename function_argument<ParY>::type
+ value_type;
+ // inside interface
+
+ struct result : function_argument<ParY>{};
+ struct result_of_mu : result{};
+ struct result_of_sigma : result{};
+ struct result_of_beta : result{};
+
+ // outside interface
+ struct function_argument : result{};
+ struct function_value : result{};
+
+ };
+
+ template<
+ typename ParY,
+ typename StateX,
+ typename ParX,
+ typename CorrXY
+ >
+ class normal_given_normal
+ : public normal_given_normal_base<typename ParY::traits>,
+ public crtp::normal<
+ normal_given_normal<
+ ParY,
+ StateX,
+ ParX,
+ CorrXY
+ >
+ >
+ {
+ typedef normal_given_normal_base<typename ParY::traits> super_t;
+ public:
+ typedef ParX par_x;
+ typedef ParY par_y;
+ typedef StateX x;
+ typedef CorrXY rho;
+
+ normal_given_normal()
+ : mu_((typename super_t::value_type)(0)),
+ sigma_((typename super_t::value_type)(0)),
+ beta_((typename super_t::value_type)(0))
+ {}
+
+ template<typename Args>
+ normal_given_normal(const Args& args)
+ : mu_((typename super_t::value_type)(0)),
+ sigma_(sigma(args[::boost::shared_features::kwd_set])),
+ beta_(beta(args[::boost::shared_features::kwd_set]))
+ {
+ this->update(args);
+ }
+
+
+ normal_given_normal(const normal_given_normal& that)
+ : mu_(that.mu_),sigma_(that.sigma_),beta_(that.beta_){}
+
+ normal_given_normal&
+ operator=(const normal_given_normal& that){
+ if(&that!=this){
+ mu_ = that.mu_;
+ sigma_ = that.sigma_;
+ beta_ = that.beta_;
+ }
+ return *this;
+ }
+ template<typename Args>
+ void update(Args& args){
+ this->update_impl(args[::boost::shared_features::kwd_set]);
+ }
+ typename result_of::mu<super_t>::type
+ mu()const{ return mu_; }
+ typename result_of::sigma<super_t>::type
+ sigma()const{ return sigma_; }
+ // TODO If the need arises, replace result_of_beta<this_type>
+ // not urgent as beta() is most likely internal only
+ typename super_t::result_of_beta::type
+ beta()const{ return beta_; }
+
+
+ typename result_of::mu<super_t>::type
+ mu(utility::dont_care)const{ return this->mu(); }
+ typename result_of::sigma<super_t>::type
+ sigma(utility::dont_care)const{ return this->sigma(); }
+ typename super_t::result_of_beta::type
+ beta(utility::dont_care)const{ return this->beta(); }
+
+ private:
+ typename super_t::value_type mu_;
+ typename super_t::value_type sigma_;
+ typename super_t::value_type beta_;
+ template<typename Set>
+ typename super_t::value_type sigma(const Set& set){
+ typename super_t::value_type sigma_y = get_par_y(set).sigma();
+ typename super_t::value_type r = get_rho(set)();
+ return sqrt(1.0-r*r)*sigma_y;
+ }
+ template<typename Set>
+ typename super_t::value_type beta(const Set& set){
+ typename super_t::value_type sigma_x = get_par_x(set).sigma();
+ typename super_t::value_type sigma_y = get_par_y(set).sigma();
+ typename super_t::value_type r = get_rho(set)();
+ return r*(sigma_y/sigma_x);
+ }
+
+ public://TODO private
+ template<typename Set>
+ void update_impl(Set& set){
+ typename super_t::value_type x_val = get_x(set)();
+ typename super_t::value_type mu_x = get_par_x(set).mu();
+ typename super_t::value_type mu_y = get_par_y(set).mu();
+ (this->mu_) = mu_y + this->beta()*(x_val-mu_x);
+ }
+
+ template<typename Set>
+ typename Set::template result_of_extract<par_y>::type const&
+ get_par_y(const Set& set)const{
+ return set.template extract<par_y>();
+ }
+ template<typename Set>
+ typename Set::template result_of_extract<par_x>::type const&
+ get_par_x(const Set& set)const{
+ return set.template extract<par_x>();
+ }
+ template<typename Set>
+ typename Set::template result_of_extract<rho>::type const&
+ get_rho(const Set& set)const{
+ //std::cout << "calling rho" << std::endl;
+ return set.template extract<rho>();
+ }
+ template<typename Set>
+ typename Set::template result_of_extract<x>::type const&
+ get_x(const Set& set)const{
+ return set.template extract<x>();
+ }
+ }; //normal_given_normal
+
+} // namespace impl
+namespace feature{
+ template <
+ typename ParY,
+ typename StateX,
+ typename ParX,
+ typename CorrXY
+ >
+ struct normal_given_normal
+ : shared_features::depends_on<
+ mpl::vector<
+ ParY,
+ StateX,
+ ParX,
+ CorrXY
+ >
+ >
+ {
+ /// INTERNAL ONLY
+ typedef impl::normal_given_normal_base<typename ParY::traits> traits;
+ typedef impl::normal_given_normal<
+ ParY,
+ StateX,
+ ParX,
+ CorrXY
+ > impl;
+ };
+}//feature
+
+}//distribution
+}//parameter
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/detail/skip_position_operations.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/detail/skip_position_operations.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,73 @@
+/////////////////////////////////////////////////////////////////////////////
+// skip_position_operations.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_DETAIL_SKIP_POSITION_OPERATIONS_HPP_ER2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_DETAIL_SKIP_POSITION_OPERATIONS_HPP_ER2009
+#include <vector>
+#include <boost/range.hpp>
+#include <boost/algorithm/inner_product_skip_one_position.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace parameter{
+namespace detail{
+
+/// $\eta_{i,-j} = x_{i,0} \beta_0 + ... + x_{i,-j}\beta_{-j}$
+/// $x_{i,j+1} \beta_{j+1}+...+x_{i,J-1} \beta_{J}$
+
+
+class skip_position_operations{
+ public:
+ typedef std::size_t size_type;
+ skip_position_operations(size_type pos)
+ :position_(pos){}
+
+ skip_position_operations(const skip_position_operations& that)
+ :position_(that.position_){}
+
+ skip_position_operations&
+ operator=(const skip_position_operations& that)
+ {
+ if(&that!=this){
+ position_ = that.position_;
+ }
+ return *this;
+ }
+ size_type position()const{ return position_; }
+
+ template<typename R>
+ typename range_value<R>::type
+ matching_element(const R& range)const{
+ typedef typename range_iterator<const R>::type iter_type;
+ iter_type iter = begin(range);
+ std::advance(iter,position());
+ return (*iter);
+ }
+ template<typename R0,typename R1>
+ typename range_value<R0>::type
+ inner_product_skip_position(const R0& r0,const R1& r1)const{
+ typedef typename range_value<R0>::type value_type;
+ return inner_product_skip_one_position(
+ r0,
+ r1,
+ this->position(),
+ (value_type)(0)
+ );
+ }
+
+ private:
+ skip_position_operations();
+ size_type position_;
+};
+
+}//detail
+}//parameter
+}//distribution
+}//boost
+
+
+#endif // REGRESSION_COEFFICIENT_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,123 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PARAMETER_NORMAL_HPP_ER_2009
+#include <boost/mpl/apply.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/utility/assert_is_base_of.hpp>
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+#include <boost/conditionally_specified_distribution/crtp/include.hpp>
+#include <boost/shared_features/depends_on.hpp>
+
+namespace boost {
+namespace conditionally_specified_distribution {
+namespace parameter {
+
+namespace impl
+{
+
+ template<typename RealType,typename Id>
+ class normal_base{
+
+ public:
+ struct identifier : mpl::identity<Id>{};
+ typedef RealType value_type;
+
+ // outside interface
+ struct function_argument : mpl::identity<value_type>{};
+ struct function_value : function_argument{};
+
+ // inside interface
+ struct result_of_mu : function_argument{};
+ struct result_of_sigma : function_argument{};
+
+ };
+
+ template<typename RealType,typename Id = mpl::void_>
+ class normal
+ : public normal_base<RealType,Id>,
+ public crtp::normal< normal<RealType,Id> >
+ {
+ typedef normal_base<RealType,Id> super_t;
+ typedef parameter::kwd<Id> kwd;
+ public:
+
+ normal()
+ : mu_((typename super_t::value_type)(0)),
+ sigma_((typename super_t::value_type)(1)){}
+
+ normal(
+ typename super_t::value_type mu,
+ typename super_t::value_type sigma
+ )
+ : mu_(mu),sigma_(sigma){}
+
+ template<typename Args>
+ normal(const Args& args)
+ //: //TODO pass normal directly as an option
+ :mu_(args[kwd::mu|(typename super_t::value_type)(0)]),
+ sigma_(args[kwd::sigma|(typename super_t::value_type)(1)])
+ {
+ }
+
+ normal(const normal& that) : mu_(that.mu_),sigma_(that.sigma_){}
+
+ normal& operator=(const normal& that){
+ if(&that!=this){
+ mu_ = that.mu_;
+ sigma_ = that.sigma_;
+ }
+ return *this;
+ }
+
+ template<typename Args>
+ void update(const Args& args){}
+
+ typename result_of::mu<super_t>::type
+ mu() const {
+ return this->mu_;
+ }
+ template<typename Args>
+ typename result_of::mu<super_t>::type
+ mu(const Args& args) const {
+ return this->mu();
+ }
+
+ typename result_of::sigma<super_t>::type
+ sigma() const {
+ return this->sigma_;
+ }
+ template<typename Args>
+ typename result_of::sigma<super_t>::type
+ sigma(const Args& args) const { return this->sigma(); }
+
+ private:
+ typename super_t::value_type mu_;
+ typename super_t::value_type sigma_;
+ };
+
+} // namespace impl
+
+namespace feature{
+ template <typename RealType,typename Id>
+ struct normal
+ : shared_features::depends_on0
+ {
+ typedef impl::normal_base<RealType,Id> traits;
+ typedef impl::normal<RealType,Id> impl;
+
+ };
+}
+
+
+}//distribution
+}//parameter
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/pair_independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/parameter/pair_independent.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,182 @@
+/////////////////////////////////////////////////////////////////////////////
+// pair_independent.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PAIR_INDEPENDENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PAIR_INDEPENDENT_HPP_ER_2009
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+//#include <boost/utility/assert_is_base_of.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+#include <boost/conditionally_specified_distribution/crtp/pair_independent.hpp>
+#include <boost/shared_features/depends_on.hpp>
+#include <boost/shared_features/result_of_extract.hpp>
+
+namespace boost {
+namespace conditionally_specified_distribution {
+namespace parameter {
+
+namespace impl
+{
+
+ template<typename T0,typename T1>
+ class pair_independent_base{
+ template<typename Args,typename T>
+ struct result_of_T
+ : add_reference<
+ typename add_const<
+ typename
+ shared_features::result_of_extract<Args,T>::type
+ >::type
+ >
+ {};
+ public:
+ struct identifier
+ : conditionally_specified_distribution::identifier<T0>{
+ //TODO chek same as T1
+ };
+
+ template<typename S>
+ struct result_of_first{};
+ template<typename F,typename Args>
+ struct result_of_first<F(Args)> : result_of_T<Args,T0>
+ {};
+ template<typename S>
+ struct result_of_second{};
+ template<typename F,typename Args>
+ struct result_of_second<F(Args)> : result_of_T<Args,T1>
+ {};
+
+
+ // outside interface
+ struct function_argument
+ : conditionally_specified_distribution::function_argument<T0>{};
+ struct function_value
+ : conditionally_specified_distribution::function_value<T0>{};
+
+ };
+
+ template<typename T0,typename T1>
+ class pair_independent
+ : public pair_independent_base<
+ typename T0::traits,
+ typename T1::traits
+ >,
+ public crtp::pair_independent< pair_independent<T0,T1> >
+ {
+ typedef pair_independent_base<T0,T1> super_t;
+ public:
+ pair_independent(){}
+
+ pair_independent(utility::dont_care){}
+
+ pair_independent(const pair_independent& that){}
+
+ pair_independent& operator=(const pair_independent& that){
+ if(&that!=this){}
+ return *this;
+ }
+
+ template<typename Set,typename Args>
+ void update(const Args& args){
+ this->update_impl(args[shared_features::kwd_set],args);
+ }
+
+ template<typename Args>
+ typename result_of::first<super_t(const Args&)>::type
+ first(const Args& args) const {
+ return first_impl(args[shared_features::kwd_set],args);
+ }
+
+ template<typename Args>
+ typename result_of::second<super_t(const Args&)>::type
+ second(const Args& args) const {
+ return second_impl(args[shared_features::kwd_set],args);
+ }
+ private:
+ template<typename Set,typename Args>
+ typename result_of::first<super_t(const Args&)>::type
+ first_impl(const Set& set,const Args& args) const {
+ check_first(set,args,set.template extract<T0>());
+ return set.template extract<T0>();
+ }
+
+ template<typename Set,typename Args,typename First>
+ void check_first(const Set& set,const Args& args,const First&) const {
+ typedef typename
+ result_of::first<super_t(const Args&)>::type cref_t;
+ BOOST_ASSERT((
+ is_same<
+ typename utility::remove_qualifier<cref_t>::type,
+ First
+ >::value
+ ));
+ BOOST_ASSERT((
+ is_same<
+ cref_t,
+ const First&
+ >::value
+ ));
+ }
+ template<typename Set,typename Args,typename Second>
+ void check_second(const Set& set,const Args& args,
+ const Second&) const {
+ typedef typename
+ result_of::second<super_t(const Args&)>::type cref_t;
+ BOOST_ASSERT((
+ is_same<
+ typename utility::remove_qualifier<cref_t>::type,
+ Second
+ >::value
+ ));
+ BOOST_ASSERT((
+ is_same<
+ cref_t,
+ const Second&
+ >::value
+ ));
+ }
+ template<typename Set,typename Args>
+ typename result_of::second<super_t(const Args&)>::type
+ second_impl(const Set& set,const Args& args) const {
+ return set.template extract<T1>();
+ }
+
+ template<typename Set,typename Args>
+ void update_impl(Set& set,const Args& args){
+ (set.template extract<T0>()).update(args);
+ (set.template extract<T1>()).update(args);
+ }
+ };
+
+} // namespace impl
+
+namespace feature{
+ template <typename T0,typename T1>
+ struct pair_independent
+ : shared_features::depends_on<
+ mpl::vector<T0,T1>
+ >
+ {
+ typedef impl::pair_independent_base<
+ typename T0::traits,
+ typename T1::traits
+ > traits;
+ typedef impl::pair_independent<T0,T1> impl;
+ };
+}
+
+
+}//distribution
+}//parameter
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/first.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/first.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,29 @@
+/////////////////////////////////////////////////////////////////////////////
+// first.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FIRST_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FIRST_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace result_of{
+
+ template<typename F>
+ struct first //: utility::remove_qualifier<F>::type::result_of_first
+ {};
+
+ template<typename F,typename Args>
+ struct first<F(Args)>
+ : F::template result_of_first<F(Args)>{};
+
+}
+}
+}
+
+
+#endif // FIRST_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_argument.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_argument.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,21 @@
+/////////////////////////////////////////////////////////////////////////////
+// function_argument.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTION_ARGUMENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTION_ARGUMENT_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{
+
+ template<typename F>
+ struct function_argument
+ : utility::remove_qualifier<F>::type::function_argument
+ {};
+
+}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_FUNCTION_ARGUMENT_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_support.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_support.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,30 @@
+/////////////////////////////////////////////////////////////////////////////
+// function_support.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SUPPORT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SUPPORT_HPP_ER_2009
+#include <utility>
+#include <boost/mpl/identity.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+#include <boost/conditionally_specified_distribution/result_of/function_argument.hpp>
+namespace boost{namespace conditionally_specified_distribution{
+
+ template<typename D>
+ struct function_support : mpl::identity<
+ std::pair<
+ typename function_argument<
+ typename utility::remove_qualifier<D>::type>::type,
+ typename function_argument<
+ typename utility::remove_qualifier<D>::type>::type
+ >
+ >
+ {};
+
+
+}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_SUPPORT_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_value.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/function_value.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////////////////
+// function_value.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTION_VALUE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTION_VALUE_HPP_ER_2009
+
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{
+
+ template<typename F>
+ struct function_value
+ : utility::remove_qualifier<F>::type::function_value
+ {};
+
+}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_FUNCTION_VALUE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/functor.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/functor.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+/////////////////////////////////////////////////////////////////////////////
+// functor.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTOR_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_FUNCTOR_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace result_of{
+
+
+ template<typename F>
+ struct functor
+ : utility::remove_qualifier<F>::type::result
+ {};
+
+
+
+}}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_NULLARY_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/identifier.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/identifier.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,20 @@
+/////////////////////////////////////////////////////////////////////////////
+// identifier.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_IDENTIFIER_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_IDENTIFIER_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+namespace boost{namespace conditionally_specified_distribution{
+
+ template<typename F>
+ struct identifier
+ : utility::remove_qualifier<F>::type::identifier
+ {};
+
+}}
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_INCLUDE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_INCLUDE_HPP_ER_2009
+#include <boost/conditionally_specified_distribution/result_of/matching_covariate.hpp>
+#include <boost/conditionally_specified_distribution/result_of/first.hpp>
+#include <boost/conditionally_specified_distribution/result_of/function_argument.hpp>
+#include <boost/conditionally_specified_distribution/result_of/function_value.hpp>
+#include <boost/conditionally_specified_distribution/result_of/functor.hpp>
+#include <boost/conditionally_specified_distribution/result_of/identifier.hpp>
+#include <boost/conditionally_specified_distribution/result_of/mu.hpp>
+#include <boost/conditionally_specified_distribution/result_of/position.hpp>
+#include <boost/conditionally_specified_distribution/result_of/range_covariate.hpp>
+#include <boost/conditionally_specified_distribution/result_of/range_coefficient.hpp>
+#include <boost/conditionally_specified_distribution/result_of/range_data.hpp>
+#include <boost/conditionally_specified_distribution/result_of/range_skip_position_covariate_dot_coefficient.hpp>
+#include <boost/conditionally_specified_distribution/result_of/second.hpp>
+#include <boost/conditionally_specified_distribution/result_of/sigma.hpp>
+#include <boost/conditionally_specified_distribution/result_of/function_support.hpp>
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/matching_covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/matching_covariate.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////////////////
+// matching_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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_MATCHING_COVARIATE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_MATCHING_COVARIATE_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+ template<typename F>
+ struct matching_covariate
+ : utility::remove_qualifier<F>::
+ type::result_of_matching_covariate
+ {};
+
+}}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_MATCHING_COVARIATE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/mu.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/mu.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,27 @@
+/////////////////////////////////////////////////////////////////////////////
+// mu.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_MU_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_MU_HPP_ER_2009
+
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace result_of{
+
+ template<typename F>
+ struct mu
+ : utility::remove_qualifier<F>::type::result_of_mu
+ {};
+
+
+
+}}}
+
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_MU_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/position.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/position.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////////////////
+// position.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_POSITION_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_POSITION_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+ template<typename F>
+ struct position
+ : utility::remove_qualifier<F>::type::result_of_position
+ {};
+
+}}}
+
+
+#endif // POSITION_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_coefficient.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_coefficient.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,23 @@
+/////////////////////////////////////////////////////////////////////////////
+// range_coefficient.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_COEFFICIENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_COEFFICIENT_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+
+ template<typename F>
+ struct range_coefficient
+ : utility::remove_qualifier<F>::
+ type::result_of_range_coefficient
+ {};
+
+}}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_COEFFICIENTS_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_covariate.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,24 @@
+/////////////////////////////////////////////////////////////////////////////
+// range_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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_COVARIATE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_COVARIATE_HPP_ER_2009
+
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+ template<typename F>
+ struct range_covariate
+ : utility::remove_qualifier<F>::type::result_of_range_covariate
+ {};
+
+}
+}
+}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_COVARIATE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_data.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+/////////////////////////////////////////////////////////////////////////////
+// range_data.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_DATA_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_DATA_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace result_of{
+
+ template<typename F>
+ struct range_data
+ : utility::remove_qualifier<F>::type::result_of_range_data
+ {};
+
+}
+}
+}
+
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_DATASET_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_skip_position_covariate_dot_coefficient.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/range_skip_position_covariate_dot_coefficient.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,24 @@
+/////////////////////////////////////////////////////////////////////////////
+// range_skip_position_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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_SKIP_POSITION_COVARIATE_DOT_COEFFICIENT_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_RANGE_SKIP_POSITION_COVARIATE_DOT_COEFFICIENT_HPP_ER_2009
+
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+ template<typename F>
+ struct range_skip_position_covariate_dot_coefficient
+ : utility::remove_qualifier<F>::
+ type::result_of_range_skip_position_covariate_dot_coefficient
+ {};
+
+}}}
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/second.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/second.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,28 @@
+/////////////////////////////////////////////////////////////////////////////
+// second.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SECOND_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SECOND_HPP_ER_2009
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace result_of{
+
+ template<typename F>
+ struct second //: utility::remove_qualifier<F>::type::result_of_second
+ {};
+
+ template<typename F,typename Args>
+ struct second<F(Args)>
+ : F::template result_of_second<F(Args)>{};
+
+}
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/sigma.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/result_of/sigma.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////////////////
+// sigma.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SIGMA_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_RESULT_OF_SIGMA_HPP_ER_2009
+
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{namespace conditionally_specified_distribution{namespace result_of{
+
+ template<typename F>
+ struct sigma
+ : utility::remove_qualifier<F>::type::result_of_sigma
+ {};
+
+}}}
+
+#endif // BOOST_DISTRIBUTION_RESULT_OF_SIGMA_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/initializer.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/initializer.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,153 @@
+/////////////////////////////////////////////////////////////////////////////
+// initializer.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_ADAPTIVE_REJECTION_INITIALIZATER_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_ADAPTIVE_REJECTION_INITIALIZATER_HPP_ER_2009
+#include <utility>
+#include <boost/assert.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace sampler{
+
+ template<typename RealType,typename Id = mpl::void_>
+ class pair_quantile_averaged_over_iterations{
+ typedef std::size_t size_type;
+ typedef RealType value_type;
+ typedef kwd<Id> kwd;
+ typedef std::pair<value_type,value_type> interval_t;
+ static interval_t default_interval(){
+ static interval_t result
+ = interval_t((value_type)(-1),(value_type)(1));
+ return result;
+ }
+ static interval_t default_interval_cdf(){
+ static interval_t result
+ = interval_t((value_type)(0.2),(value_type)(0.8));
+ return result;
+ }
+
+ public:
+ typedef const interval_t& result_type;
+
+ template<typename Args>
+ pair_quantile_averaged_over_iterations(const Args& args)
+ :l_(args[kwd::ars_init_interval|default_interval()].first),
+ h_(args[kwd::ars_init_interval|default_interval()].second),
+ result_(l_,h_),
+ n_(1),
+ low_cdf_(args[
+ kwd::ars_interval_cdf|default_interval_cdf()].first),
+ high_cdf_(args[
+ kwd::ars_interval_cdf|default_interval_cdf()].second)
+ {
+ BOOST_ASSERT(high_cdf_>low_cdf_);
+ }
+
+ result_type
+ operator()()const{
+ BOOST_ASSERT(result_.second>result_.first);
+ return result_;
+ }
+
+ template<typename Impl>
+ void update(
+ const Impl& impl //impl.inverse_cdf() needed
+ ){
+
+ l_ = impl.inverse_cdf(low_cdf_);
+ h_ = impl.inverse_cdf(high_cdf_);
+ value_type n_val = (value_type)(n_);
+ value_type avg_l_ = (*this)().first;
+ avg_l_ = (n_val-1) * avg_l_ + l_;
+ avg_l_ /= n_val;
+ value_type avg_h_ = (*this)().second;
+ avg_h_ = (n_val-1) * avg_h_ + h_;
+ avg_h_ /= n_val;
+ result_.first = avg_l_;
+ result_.second = avg_h_;
+ ++n_;
+ }
+ private:
+ pair_quantile_averaged_over_iterations();
+ value_type l_;
+ value_type h_;
+ interval_t result_;
+ size_type n_;
+ value_type low_cdf_;
+ value_type high_cdf_;
+ };
+
+ template<typename RealType,typename Id = mpl::void_>
+ class pair_quantile{
+ typedef std::size_t size_type;
+ typedef RealType value_type;
+ typedef kwd<Id> kwd;
+ typedef std::pair<value_type,value_type> interval_t;
+ static interval_t default_interval(){
+ static interval_t result
+ = interval_t((value_type)(-1),(value_type)(1));
+ return result;
+ }
+ static interval_t default_interval_cdf(){
+ static interval_t result
+ = interval_t((value_type)(0.2),(value_type)(0.8));
+ return result;
+ }
+
+ public:
+ typedef const interval_t& result_type;
+
+ template<typename Args>
+ pair_quantile(const Args& args) :
+ result_(
+ (args[kwd::ars_init_interval|default_interval()].first),
+ (args[kwd::ars_init_interval|default_interval()].second)
+ ),
+ low_cdf_(args[
+ kwd::ars_interval_cdf|default_interval_cdf()].first),
+ high_cdf_(args[
+ kwd::ars_interval_cdf|default_interval_cdf()].second)
+ {
+ BOOST_ASSERT(high_cdf_>low_cdf_);
+ }
+
+ result_type
+ operator()()const{
+ BOOST_ASSERT(result_.second>result_.first);
+ return result_;
+ }
+
+ template<typename Impl>
+ void update(
+ const Impl& impl //impl.inverse_cdf() needed
+ ){
+
+ value_type l_ = impl.inverse_cdf(low_cdf_);
+ value_type h_ = impl.inverse_cdf(high_cdf_);
+ result_.first = l_;
+ result_.second = h_;
+ }
+ private:
+ pair_quantile();
+ value_type l_;
+ value_type h_;
+ interval_t result_;
+ value_type low_cdf_;
+ value_type high_cdf_;
+ };
+
+
+}//sampler
+}//distribution
+}//boost
+
+
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/adaptive_rejection/sampler.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,196 @@
+/////////////////////////////////////////////////////////////////////////////
+// sampler.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_ADAPTIVE_REJECTION_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_ADAPTIVE_REJECTION_HPP_ER_2009
+#include <boost/assert.hpp>
+#include <vector>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/eval_if.hpp>
+//#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/parameter.hpp>
+//#include <boost/adaptive_rejection_sampler/simulator.hpp>
+#include <boost/adaptive_rejection_sampling/sampler.hpp>
+#include <boost/conditionally_specified_distribution/support/include.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <boost/conditionally_specified_distribution/function/detail/adapter.hpp>
+#include <boost/conditionally_specified_distribution/sampler/adaptive_rejection/initializer.hpp>
+namespace boost{namespace conditionally_specified_distribution{
+namespace sampler{
+
+namespace impl{
+
+ template<typename Par>
+ class adaptive_rejection_sampler_base{
+ public:
+ typedef typename function_argument<Par>::type value_type;
+ typedef std::size_t size_type;
+ struct identifier
+ : conditionally_specified_distribution::identifier<Par>{};
+
+ };
+ // Instance (i) of InitialzationPolicy : i.update(par,impl,args)
+ // Instance (s) of State: s.set(args,x)
+ template<
+ typename Par,
+ typename State,
+ template<typename,typename> class Initialize,
+ template<typename,typename> class Container,
+ template<typename> class Allocator,
+ template<typename> class Unif01
+ >
+ class adaptive_rejection_sampler
+ : public adaptive_rejection_sampler_base<typename Par::traits>
+ {
+ typedef
+ adaptive_rejection_sampler_base<typename Par::traits> super_t;
+ typedef typename conditionally_specified_distribution
+ ::identifier<super_t>::type id;
+ typedef Initialize<typename super_t::value_type,id> init_t;
+ // common urng, interval and max_init_
+ // TODO last 2 may require id-templatized kwd
+ typedef kwd<> kwd;
+
+ std::size_t static default_max_init_recursion(){
+ std::size_t static result = 100;
+ return result;
+ }
+
+ public:
+
+ template<typename Args>
+ adaptive_rejection_sampler(const Args& args)
+ : init_(args),
+ max_init_recursion_(
+ args[kwd::ars_max_init_recursion|default_max_init_recursion()]
+ ){}
+
+ adaptive_rejection_sampler(const adaptive_rejection_sampler& that)
+ : init_(that.init_),
+ max_init_recursion_(that.max_init_recursion_){}
+
+ //TODO check
+ adaptive_rejection_sampler&
+ operator=(const adaptive_rejection_sampler& that){
+ if(&that!=this){
+ init_ = that.init_;
+ max_init_recursion_ = that.max_init_recursion_;
+ }
+ return *this;
+ }
+
+ // U models UniformRandomNumberGenerator
+
+ template<typename Args>
+ void
+ sample(const Args& args)const{
+ this->update_par(args[shared_features::kwd_set],args);
+ return this->sample_impl(
+ args,
+ args[shared_features::kwd_set],
+ args[kwd::random_number_generator]
+ );
+ }
+
+ private:
+ template<typename Set,typename Args>
+ void update_par(Set& set,const Args& args)const{
+ typedef typename
+ Set::template result_of_extract<Par>::type extr_par_t;
+ extr_par_t& ref_par = set.template extract<Par>();
+ ref_par.update(args);
+ };
+
+ template<typename Args,typename Set,typename U>
+ void
+ sample_impl(const Args& args,Set& set, U& urng)const{
+ typedef Unif01<typename super_t::value_type> unif01_t;
+ typedef boost::variate_generator<U&,unif01_t> gen_t;
+ typedef typename init_t::result_type interval_t;
+ typedef typename
+ Set::template result_of_extract<Par>::type extr_par_t;
+ typedef typename
+ Set::template result_of_extract<State>::type extr_state_t;
+ typedef function::detail::adapter<extr_par_t,Args> adapter_t;
+// typedef ::boost::random::adaptive_rejection_sampler::simulator<
+// adapter_t,
+// Container,
+// Allocator
+// > impl_t;
+ typedef ::boost::adaptive_rejection_sampling::sampler<
+ adapter_t,
+ Container,
+ Allocator
+ > impl_t;
+ const extr_par_t& par = set.template extract<Par>();
+ adapter_t adapter (par,args);
+ impl_t impl(
+ adapter,
+ this->max_init_recursion_
+ );
+ interval_t interval = (this->init_)();
+ // Have had px!=0 fails here with gibbs rte::regression_coeff
+ impl.initialize(interval.first,interval.second);
+
+ gen_t gen(urng,unif01_t());
+ typename super_t::value_type x = impl(gen);
+
+ extr_state_t& extr_state = set.template extract<State>();
+ extr_state.set(args,x);
+ (this->init_).update(impl);
+ }
+ mutable init_t init_;
+ typename super_t::size_type max_init_recursion_;
+ };
+}//impl
+
+namespace feature{
+ // Warning : pair_quantile_averaged_over_iterations is non_markov
+ // Consequential theretically? Dunno, but from a practical
+ // standpoint, less likely to lead to stability issues
+ // such as exp(-inf).
+
+ template<
+ typename Par,
+ typename State,
+ template<typename,typename> class Initialize
+ = pair_quantile_averaged_over_iterations,
+ template<typename,typename> class Container = std::vector,
+ template<typename> class Allocator = std::allocator,
+ template<typename> class Unif01 = boost::uniform_real
+ >
+ struct adaptive_rejection_sampler : shared_features::depends_on<
+ mpl::vector<Par,State>
+ >{
+ typedef impl::adaptive_rejection_sampler_base<
+ typename Par::traits> traits;
+ typedef impl::adaptive_rejection_sampler<
+ Par,
+ State,
+ Initialize,
+ Container,
+ Allocator,
+ Unif01
+ > impl;
+ };
+}//feature
+}//sampler
+}//distribution
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/sampler/normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,119 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SAMPLER_NORMAL_HPP_ER_2009
+#include <boost/assert.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+//#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/conditionally_specified_distribution/result_of/include.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace sampler{
+
+namespace impl{
+ template<typename Par>
+ struct normal_base{
+ typedef typename function_argument<Par>::type value_type;
+ };
+ template<
+ typename Par,
+ typename State,
+ template<typename> class RNormal, //models RandomDistribution
+ template<typename> class Unif01
+ >
+ class normal : public normal_base<typename Par::traits>
+ //might want to add crtp if need arises
+ {
+ typedef Par par_t;
+ typedef State state_t;
+ typedef normal_base<typename Par::traits> super_t;
+
+ public:
+ normal(){};
+ normal(utility::dont_care){}
+
+ template<typename Args>
+ void sample(Args& args)const{
+ this->update_par(args[shared_features::kwd_set],args);
+ this->sample_impl(
+ args,
+ args[shared_features::kwd_set],
+ args[kwd<>::random_number_generator]
+ );
+ }
+
+ private:
+ template<typename Set,typename Args>
+ void update_par(Set& set, const Args& args)const{
+ typedef typename
+ Set::template result_of_extract<par_t>::type extr_par_t;
+ extr_par_t& ref_par = set.template extract<par_t>();
+ ref_par.update(args);
+ }
+
+ // U models UniformRandomNumberGenerator
+ template<typename Args,typename Set,typename U>
+ void sample_impl(
+ const Args& args,
+ Set& set,
+ U& u
+ )const{
+ typedef RNormal<typename super_t::value_type> rnorm_t;
+ typedef Unif01<typename super_t::value_type> unif_t;
+ typedef boost::variate_generator<U&,unif_t> gen_t;
+ static rnorm_t rnorm;
+ typedef typename
+ Set::template result_of_extract<par_t>::type extr_par_t;
+ typedef typename
+ Set::template result_of_extract<state_t>::type extr_state_t;
+
+ const extr_par_t& cref_par = set.template extract<par_t>();
+ typename super_t::value_type m = cref_par.mu(args);
+ typename super_t::value_type s = cref_par.sigma(args);
+
+ gen_t gen(u,unif_t());
+ typename super_t::value_type z = rnorm(gen);
+ typename super_t::value_type x = m + z * s;
+ extr_state_t& state = set.template extract<state_t>();
+ state.set(args,x);
+ }
+
+ };
+
+}
+namespace feature{
+ template<
+ typename Par,
+ typename State,
+ template<typename> class RNormal = boost::normal_distribution,
+ template<typename> class Unif01 = boost::uniform_real
+ >
+ struct normal : shared_features::depends_on<
+ mpl::vector<Par,State>
+ >{
+
+ typedef impl::normal_base<typename Par::traits> traits;
+ typedef impl::normal<Par,State,RNormal,Unif01> impl;
+ };
+}
+
+
+}
+}
+}
+
+#endif // BOOST_DISTRIBUTION_SAMPLER_NORMAL_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/detail/negative_max_to_max.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/detail/negative_max_to_max.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,39 @@
+/////////////////////////////////////////////////////////////////////////////
+// negative_max_to_max.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_FROM_NEGATIVE_MAX_TO_MAX_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_FROM_NEGATIVE_MAX_TO_MAX_HPP_ER_2009
+#include <utility>
+#include <boost/conditionally_specified_distribution/result_of/function_support.hpp>
+#include <boost/math/tools/precision.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace function{
+namespace detail{
+
+ template<typename D>
+ inline
+ typename function_support<D>::type
+ support_negative_max_to_max(
+ const D& d
+ ){
+ typedef typename function_support<D>::type fs;
+
+ using boost::math::tools::max_value;
+ return fs(
+ -max_value<typename fs::first_type>(),
+ max_value<typename fs::second_type>()
+ );
+ };
+
+}//detail
+}//function
+}//conditionally_specified_distribution
+}//boost
+
+
+#endif // BOOST_DISTRIBUTION_SUPPORT_FROM_NEGATIVE_MAX_TO_MAX_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/fwd.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/fwd.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,27 @@
+/////////////////////////////////////////////////////////////////////////////
+// fwd.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FWD_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_FWD_HPP_ER_2009
+#include <boost/conditionally_specified_distribution/result_of/function_support.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace function{
+
+template <typename D,typename Args>
+inline
+typename function_support<D>::type
+support(const D& d,const Args& args)
+{
+ return support(d);
+}
+
+}
+}//conditionally_specified_distribution
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,14 @@
+/////////////////////////////////////////////////////////////////////////////
+// pair_independent.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_INCLUDE_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_INCLUDE_HPP_ER_2009
+
+#include <boost/conditionally_specified_distribution/support/normal.hpp>
+#include <boost/conditionally_specified_distribution/support/fwd.hpp>
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/boost/conditionally_specified_distribution/support/normal.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,30 @@
+/////////////////////////////////////////////////////////////////////////////
+// normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_NORMAL_HPP_ER_2009
+#define BOOST_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SUPPORT_NORMAL_HPP_ER_2009
+#include <boost/conditionally_specified_distribution/result_of/function_support.hpp>
+#include <boost/conditionally_specified_distribution/crtp/normal.hpp>
+#include <boost/conditionally_specified_distribution/support/detail/negative_max_to_max.hpp>
+namespace boost{
+namespace conditionally_specified_distribution{
+namespace function{
+
+template <typename D>
+inline
+typename function_support<D>::type
+support(const crtp::normal<D>& d)
+{
+ const D& d_ = static_cast<const D&>(d);
+
+ return detail::support_negative_max_to_max(d_);
+}
+
+}
+}
+}
+#endif // BOOST_DISTRIBUTION_SUPPORT_NORMAL_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/doc/readme.txt 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,287 @@
+////////////////////////////////////////////////////////////////////////////
+// Conditionally Specified Distribution
+// (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)
+////////////////////////////////////////////////////////////////////////////
+
+
+////////////
+/ Overview /
+////////////
+
+This collection of C++ classes is a framework for managing a
+multivariate distribution that can be characterized by a collection of
+submodels, as arising in Bayesian modeling.
+
+The framework is built around the library shared_features, which
+allows to bundle multiple classes that depend on each other through
+a common class (set).
+
+////////////////
+/ Requirements /
+////////////////
+
+boost_1_37_0
+sandbox/conditionally_specified_distribution/adaptive_rejection_sampling
+sandbox/conditionally_specified_distribution/conditionally_specified_distribution
+sandbox/conditionally_specified_distribution/math_limit
+sandbox/conditionally_specified_distribution/utility
+sandbox/conditionally_specified_distribution/shared_features
+sandbox/conditionally_specified_distribution/survival_data (anticipated)
+
+/////////////////////////////////////////////////////
+/ Example of a conditionally specified distribution /
+/////////////////////////////////////////////////////
+
+(x,y) are jointly normal with parameters mu_x,mu_y,rho,sigma_x, sigma_y.
+An equivalent representation is
+{x~N(mu_x,sigma_x^2) , y|x~N(mu_y|x,sigma_{y|x}^)},
+where :
+ mu_y|x = mu_y + beta(x)(x-mu_x)
+ beta(x) = rho*(sigma_y/sigma_x);
+ sigma_y|x = sqrt(1.0-rho^2)*sigma_y;
+
+We can get an exact draw from (x,y) by sampling from x, then y|x.
+Alternatively, given starting values (x0, y0), the Gibbs procedure is
+(x[1]|y[0],y[1]|x[1])...(x[i]|y[i-1],y[i]|x[i])...(x[n]|y[n-1],y[n]|x[n]).
+which results in (x[n],y[n]) --d--> (x,y) as n ---> infinity.
+
+////////////////
+/ Organization /
+////////////////
+Folders:
+* crtp
+* function
+* keyword
+* parameter
+* result_of
+* sampler
+* support
+
+/////////
+/ Usage /
+/////////
+Familiarize yourself with the library shared_features first.
+
+Consider a conditional distribution Y|X (naturally this can be extended
+to a collection).
+
+To represent the state of X (or Y), we would typically reuse a feature
+defined in shared_features, for example:
+ typedef shared_features::feature::scalar<T> state_x;
+
+We now assume that Y|X has a pdf form F. For example, if (X,Y) are jointly
+normal, then F is univariate normal.
+
+If F is not already a part of the library, we would add:
+namespace crtp{
+ template<typename D>
+ struct F{};
+}
+
+We provide an implementation for the parameter of Y|X=x in namespace
+parameter. To begin, put some associated type in a base class
+namespace impl{
+ template<typename StateX,typename Other>
+ struct parameter_Y_base{
+ // (nullary) meta functions
+ struct function_argument{typedef ... type};
+ ...
+ };
+}
+
+If any of these types is needed by a client, we call them via meta-
+function fowards that are defined in folder result_of. For example,
+ function_value<D>::type.
+
+We now turn to the implementation:
+namespace impl{
+ template<typename StateX,typename Other>
+ struct parameter_Y
+ : parameter_Y_base,
+ crtp::F<parameter_Y<StateX,Other> >
+ {
+ template<typename Args>
+ void update(const Args& args){
+ //typically calls args[kwd_set].extract<StateX>()
+ }
+ // ... accessors such as mu(), sigma()
+ };
+}
+We now make Y|X a feature which specifies its dependencies :
+namespace feature{
+ template<typename StateX,typename Other>
+ class parameter_Y : depends_on1<StateX>{
+ typedef impl::parameter_Y_base<StateX,Other> traits;
+ typedef impl::parameter_Y<StateX,Other> impl;
+ };
+}
+
+If F not already a part of the library, we create free functions as
+needed such as:
+namespace function{
+ template<typename D>
+ typename function_value<D>::type
+ unnormalized_log_pdf(
+ const crtp::F<D>& d,
+ typename function_argument<D>::type x
+ ){
+ const D& d_ = static_cast<const D&>(d);
+ ...
+ }
+}
+namespace support{
+ ... similar set up
+}
+
+If F can be sampled exactly, we would would create a feature for that
+sampler:
+namespace impl{
+ ...
+}
+namespace feature{
+ template<typename Par,typename State>
+ struct sampler_F : depends_on<
+ mpl::vector<Par,State>
+ >{
+ template<typename Args>
+ void sample(const Args& args)const{
+ //typically queries set.template extract<Par>();
+ //and modifies set.template extract<State>();
+ }
+ }
+}
+If F cannot be sampled exactly, we would use (or, if necessary, define) a
+generic sampler ( e.g. adaptive rejection sampler) in a similar way.
+
+Here's how we would use of the above to sample Y|X=x
+
+ typedef shared::feature::scalar<T> state_x;
+ typedef shared::feature::scalar<T> state_y;
+ typedef parameter_Y par_y;
+ typedef sampler_F<
+ par_y,
+ state_y
+ > sampl_y;
+
+ typedef mpl::vector<sampl_y> features;
+ typedef shared_features::set<features> set_t;
+
+ const value_type state_x_val = some value;
+
+ set_t set;
+ set.initialize(
+ (
+ shared::kwd<>::scalar = state_x_val,
+ ...
+ )
+ );//Read shared_features on keyword to discriminate between features
+ BOOST_ASSERT(( set.extract<state_x>()() == state_x_val ));
+
+ typedef mpl::vector<sampl_y> samplers;
+ typedef shared::contains_feature_of<samplers,mpl::_> is_sampler;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+ typedef std::vector<T> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws;
+ draws.reserve(n);
+ for(unsigned i=0; i<n; ++i){
+ set.visit_if<is_sampler>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws.push_back(
+ set.extract<state_y>()()
+ );
+ }
+
+//////////////
+/ Discussion /
+//////////////
+In general, for simplicy, the base parameter is defined as
+struct base{
+ struct result_of_foo{};
+ ...
+}
+Accordingly in folder result_of:
+template<typename D>
+struct foo<D> : mpl::identity<typename D::result_of_foo>{};
+
+In other words, it is generally assumed that the result of D::foo(Args) is
+independent of Args.
+
+The exceptions are foo = first and foo = second, whose result depend on
+the function signature. Going forward, it may be necessary to generalize
+this.
+
+/////////////////
+/ Related Tools /
+/////////////////
+
+For MCMC convergence assessment, you might want to look into our library
+sandbox/acvf (auto-covariance function)
+
+////////////////////////
+/ Output from main.cpp /
+////////////////////////
+
+->example_parameter_normal_given_normal
+mu_y|x=0.1
+beta_y|x=0.75
+mu_y|x=0.175
+<-
+->example_exact_sample_normal_given_normal
+1000000 samples from y|x, with (x,y) jointly normal, and x fixed at -0.1
+mu_x = -0.1 sigma_x = 1 rho_xy = 0.5 mu_y = 0.1 sigma_y = 1.5 so that
+mu_y|x = 0.1, sigma_y|x = 1.29904and a normal sampler.
+sample statistics :
+ mu_y|x : 0.0999346
+ mu_y|x : 1.29991
+<-
+->example_sampler_exact_bivariate_normal
+1000000 samples from (x,y) jointly normal, mu_x = -0.1 sigma_x = 1
+rho_xy = -0.5 mu_y = 0.1 sigma_y = 1.5 using the decomposition (x, y|x)
+and a normal sampler for each component.
+sample statistics :
+ mu_x : -0.101468
+ sigma_x : 1.00053
+ mu_y : 0.102181
+ sigma_y : 1.5014
+ rho_xy :-0.500278
+<-
+-> example_ars_normal()
+1000000 samples from N(-5.1,10^2) using an adaptive rejection sampler,
+initialized withx1 = -24.7 and x2 = 14.5
+sample statistics :
+ mu :-5.08317
+sigma : 9.75805
+<-
+->example_sampler_exact_bivariate_normal
+1000000 samples from (x,y) jointly normal, mu_x = -0.1 sigma_x = 1
+rho_xy = -0.5 mu_y = 0.1 sigma_y = 1.5 using the decomposition (x, y|x)
+and a normal sampler for each component.
+sample statistics :
+ mu_x : -0.101468
+ sigma_x : 1.00053
+ mu_y : 0.102181
+ sigma_y : 1.5014
+ rho_xy :-0.500278
+<-
+->example_sampler_gibbs_ars_bivariate_normal
+1000000 samples from (x,y) jointly normal, mu_x = -0.1 sigma_x = 1
+rho_xy = 0.9 mu_y = 0.1 sigma_y = 1.5 using the decomposition (y|x, x|y)
+and an ars sampler for each component.
+sample statistics :
+ mu_x : -0.0976351
+ sigma_x : 0.972748
+ mu_y : 0.103237
+ sigma_y : 1.45947
+ rho_xy :0.896274
+<-
+->example_function_pair_independent
+ OK <-

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,114 @@
+////////////////////////////////////////////////////////////////////////////
+// pair_independent.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 <boost/assign/std/vector.hpp>
+#include <boost/shared_features/include.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/pair_independent.hpp>
+#include <boost/conditionally_specified_distribution/function/include.hpp>
+#include <libs/conditionally_specified_distribution/src/example/function/pair_independent.h>
+
+void example_function_pair_independent(){
+
+ std::cout << "->example_function_pair_independent" << std::endl;
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+
+ //Attention : par_x and par_y are of different type due to id_x, id_y
+
+ typedef par::feature::pair_independent<par_x,par_y> par_joint_xy;
+
+ typedef mpl::vector<par_joint_xy> implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+
+ set_t set;
+
+ set.initialize(
+ (
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val
+ )
+ );
+
+ typedef std::vector<value_type> x_values_t;
+ x_values_t x_values;
+ {
+ using namespace boost::assign;
+ x_values+= mu_x_val - sigma_x_val * 3.0;
+ x_values+= mu_x_val + sigma_x_val * 3.0;
+ x_values+= mu_y_val - sigma_y_val * 3.0;
+ x_values+= mu_y_val + sigma_y_val * 3.0;
+ }
+
+
+ for(unsigned int i = 0; i<size(x_values); i++){
+
+ value_type ulpdf =
+ csd::function::unnormalized_log_pdf(
+ set.extract<par_x>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ ulpdf += csd::function::unnormalized_log_pdf(
+ set.extract<par_y>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ value_type ulpdf2 =
+ csd::function::unnormalized_log_pdf(
+ set.extract<par_joint_xy>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ BOOST_ASSERT(ulpdf == ulpdf2);
+ value_type dulpdf =
+ csd::function::derivative_unnormalized_log_pdf(
+ set.extract<par_x>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ dulpdf += csd::function::derivative_unnormalized_log_pdf(
+ set.extract<par_y>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ value_type dulpdf2 =
+ csd::function::derivative_unnormalized_log_pdf(
+ set.extract<par_joint_xy>(),
+ ((shared::kwd_set = set)),
+ x_values[i]
+ );
+ BOOST_ASSERT(dulpdf == dulpdf2);
+
+ }
+ std::cout << " OK <-" << std::endl;
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/function/pair_independent.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// pair_independent.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PAIR_INDEPENDENT_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_PAIR_INDEPENDENT_H_ER_2009
+
+void example_function_pair_independent();
+
+#endif // PAIR_INDEPENDENT_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,134 @@
+////////////////////////////////////////////////////////////////////////////
+// normal_given_normal.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 <boost/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp>
+
+#include <libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.h>
+
+void example_parameter_normal_given_normal(){
+ std::cout << "->example_parameter_normal_given_normal" << std::endl;
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef shared::feature::scalar<value_type,id_y> state_y; //2
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+ typedef shared::feature::scalar<value_type,id_rho_xy> rho_xy; //5
+
+ // dependent feature
+ typedef
+ par::feature::normal_given_normal<
+ par_y,
+ state_x,
+ par_x,
+ rho_xy
+ >
+ par_y_given_x;
+
+ typedef mpl::vector<par_y_given_x> implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<5> desired_size;
+
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+
+ typedef mpl::back<features>::type actual_back;
+ typedef par_y_given_x desired_back;
+
+ BOOST_MPL_ASSERT((
+ is_same<desired_back,actual_back>
+ ));
+
+ // input
+ const value_type state_x_val = -0.1;
+ const value_type state_y_val = 0.1;
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+ const value_type rho_val = 0.5;
+
+ set_t set;
+
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ shared::kwd<id_y>::scalar = state_y_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val,
+ shared::kwd<id_rho_xy>::scalar = rho_val
+ )
+ );
+
+ BOOST_ASSERT(set.extract<state_x>()()==state_x_val);
+ //BOOST_ASSERT(set.extract<state_y>()()==scalar_y);
+ BOOST_ASSERT(set.extract<par_x>().mu()==mu_x_val);
+ BOOST_ASSERT(set.extract<par_x>().sigma()==sigma_x_val);
+ BOOST_ASSERT(set.extract<par_y>().mu()==mu_y_val);
+ BOOST_ASSERT(set.extract<par_y>().sigma()==sigma_y_val);
+
+ std::cout
+ << "mu_y|x=" << set.extract<par_y_given_x>().mu() << std::endl;
+
+ std::cout
+ << "beta_y|x=" << set.extract<par_y_given_x>().beta()
+ << std::endl;
+ set.extract<state_x>().set(0.0);
+ BOOST_ASSERT(set.extract<state_x>()()==0.0);
+
+ set.extract<par_y_given_x>().update((shared::kwd_set=set));
+
+ std::cout
+ << "mu_y|x=" << set.extract<par_y_given_x>().mu() << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// normal_given_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_NORMAL_GIVEN_NORMAL_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_NORMAL_GIVEN_NORMAL_H_ER_2009
+
+void example_parameter_normal_given_normal();
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,179 @@
+////////////////////////////////////////////////////////////////////////////
+// ars_normal.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 <numeric>
+#include <vector>
+#include <cmath>
+#include <utility>
+#include <iterator>
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/random/mersenne_twister.hpp>
+
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+
+#include <boost/conditionally_specified_distribution/sampler/adaptive_rejection/sampler.hpp>
+#include <libs/conditionally_specified_distribution/src/example/sampler/ars_normal.h>
+
+void example_sampler_ars_normal(){
+ std::cout << "-> example_ars_normal()" << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+ namespace sampl = csd::sampler;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef par::feature::normal<value_type,id_x> par_x; //2
+
+ //sampler
+ typedef sampl::feature::adaptive_rejection_sampler<
+ par_x,
+ state_x
+ > sampl_x;//3
+
+ typedef mpl::vector<sampl_x> implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<3> desired_size;
+
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+
+ // input
+ const value_type state_x_val = -0.1;
+ const value_type mu_x_val = -5.1;
+ const value_type sigma_x_val = 10.0;
+
+ //dependent
+ typedef std::pair<value_type,value_type> interval_t;
+ const value_type l = mu_x_val - 1.96 * sigma_x_val;
+ const value_type u = mu_x_val + 1.96 * sigma_x_val;
+ interval_t interval(l,u);
+
+ set_t set;
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ sampl::kwd<id_x>::ars_init_interval = interval
+ )
+ );
+
+ typedef mpl::vector<sampl_x> samplers;
+ typedef shared::contains_feature_of<samplers,mpl::_> is_sampler;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+
+ BOOST_ASSERT((
+ set.extract<state_x>()() == state_x_val
+ ));
+
+ typedef std::vector<value_type> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws;
+ draws.reserve(n);
+
+ std::string str = "%1% samples from N(%2%,%3%^2)";
+ str += " using an adaptive rejection sampler, initialized with";
+ str += "x1 = %4% and x2 = %5%";
+ format the_format(str);
+ the_format % n;
+ the_format % set.extract<par_x>().mu();
+ the_format % set.extract<par_x>().sigma();
+ the_format % l % u;
+ std::cout << the_format.str() << std::endl;
+ for(unsigned i=0; i<n; ++i){
+
+ set.visit_if<is_sampler>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws.push_back(
+ set.extract<state_x>()()
+ );
+ }
+
+ //copy(
+ // begin(draws),
+ // end(draws),
+ // std::ostream_iterator<value_type>(std::cout," ")
+ //);
+
+ value_type m = std::accumulate(begin(draws),end(draws),(value_type)(0));
+ m/=(value_type)(n);
+
+ std::cout << "sample statistics : " << std::endl;
+ std::cout
+ << " mu :" << m
+ << std::endl;
+
+ std::transform(
+ begin(draws),
+ end(draws),
+ begin(draws),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m
+ )
+ );
+
+ value_type s = std::inner_product(
+ begin(draws),
+ end(draws),
+ begin(draws),
+ (value_type)(0)
+ );
+ s = sqrt(s/(value_type)(n));
+
+ std::cout
+ << "sigma : "
+ << s
+ << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/ars_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// ars_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SRC_EXAMPLE_SAMPLER_ARS_NORMAL_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SRC_EXAMPLE_SAMPLER_ARS_NORMAL_H_ER_2009
+
+void example_sampler_ars_normal();
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,231 @@
+////////////////////////////////////////////////////////////////////////////
+// exact_bivariate_normal.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 <numeric>
+#include <vector>
+#include <cmath>
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp>
+
+#include <boost/conditionally_specified_distribution/sampler/normal.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.h>
+
+void example_sampler_exact_bivariate_normal(){
+ std::cout << "->example_sampler_exact_bivariate_normal" << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+ namespace sampl = csd::sampler;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef shared::feature::scalar<value_type,id_y> state_y; //2
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+ typedef shared::feature::scalar<value_type,id_rho_xy> rho_xy; //5
+
+ // dependent feature
+ typedef
+ par::feature::normal_given_normal<
+ par_y,
+ state_x,
+ par_x,
+ rho_xy
+ > //6
+ par_y_given_x;
+
+
+ //sampler
+ typedef sampl::feature::normal<par_y_given_x,state_y> sampl_y_given_x;//7
+ typedef sampl::feature::normal<par_x,state_x> sampl_x;//8
+
+ typedef mpl::vector<
+ sampl_y_given_x,
+ sampl_x
+ > implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<8> desired_size;
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+
+ // input
+
+ const value_type state_x_val = -0.1;
+ const value_type state_y_val = 0.1;
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+ const value_type rho_val = -0.5;
+
+ set_t set;
+
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ shared::kwd<id_y>::scalar = state_y_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val,
+ shared::kwd<id_rho_xy>::scalar = rho_val
+ )
+ );
+
+ typedef mpl::vector<sampl_x> sampler_x;
+ typedef shared::contains_feature_of<sampler_x,mpl::_> is_sampler_x;
+ typedef mpl::vector<sampl_y_given_x> sampler_y;
+ typedef shared::contains_feature_of<sampler_y,mpl::_> is_sampler_y;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+
+ BOOST_ASSERT((
+ set.extract<state_y>()() == state_y_val
+ ));
+
+ typedef std::vector<value_type> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws_x;
+ draws_x.reserve(n);
+ draws_t draws_y;
+ draws_y.reserve(n);
+
+ std::string str = "%1% samples from (x,y) jointly normal, ";
+ str += "mu_x = %2% ";
+ str += "sigma_x = %3% ";
+ str += "rho_xy = %4% ";
+ str += "mu_y = %5% ";
+ str += "sigma_y = %6% ";
+ str += "using the decomposition (x, y|x) ";
+ str += "and a normal sampler for each component.";
+ format the_format(str);
+ the_format % n ;
+ the_format % set.extract<par_x>().mu();
+ the_format % set.extract<par_x>().sigma();
+ the_format % set.extract<rho_xy>()();
+ the_format % set.extract<par_y>().mu();
+ the_format % set.extract<par_y>().sigma();
+ std::cout << the_format.str() << std::endl;
+
+
+ for(unsigned i=0; i<n; ++i){
+ set.visit_if<is_sampler_x>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_x.push_back(
+ set.extract<state_x>()()
+ );
+ set.visit_if<is_sampler_y>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_y.push_back(
+ set.extract<state_y>()()
+ );
+ }
+
+ std::cout << "sample statistics : " << std::endl;
+
+ typedef range_iterator<draws_t>::type iter_t;
+
+ value_type m_x = std::accumulate(
+ begin(draws_x),end(draws_x),(value_type)(0));
+ m_x/=(value_type)(n);
+ value_type s_x = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_x),(value_type)(0));
+ s_x -= n*m_x*m_x;
+ s_x = sqrt(s_x/(value_type)(n));
+
+ std::cout
+ << " mu_x : " << m_x << std::endl;
+ std::cout
+ << " sigma_x : " << s_x << std::endl;
+
+ value_type m_y = std::accumulate(
+ begin(draws_y),end(draws_y),(value_type)(0));
+ m_y/=(value_type)(n);
+ value_type s_y = std::inner_product(
+ begin(draws_y),end(draws_y),begin(draws_y),(value_type)(0));
+ s_y -= n*m_y*m_y;
+ s_y = sqrt(s_y/(value_type)(n));
+
+ std::cout
+ << " mu_y : " << m_y << std::endl;
+ std::cout
+ << " sigma_y : " << s_y << std::endl;
+
+
+ transform(begin(draws_x),end(draws_x),begin(draws_x),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_x
+ )
+ );
+ transform(begin(draws_y),end(draws_y),begin(draws_y),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_y
+ )
+ );
+
+ value_type s_xy = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_y),(value_type)(0));
+ s_xy = s_xy/(value_type)(n);
+ s_xy /= (s_x * s_y);
+
+ std::cout
+ << " rho_xy :" << s_xy << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// exact_bivariate_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_EXACT_BIVARIATE_NORMAL_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_EXACT_BIVARIATE_NORMAL_H_ER_2009
+
+void example_sampler_exact_bivariate_normal();
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,188 @@
+////////////////////////////////////////////////////////////////////////////
+// exact_normal_given_normal.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 <numeric>
+#include <vector>
+#include <cmath>
+#include <boost/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/format.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range.hpp>
+
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp>
+
+#include <boost/conditionally_specified_distribution/sampler/normal.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.h>
+
+
+void example_sampler_exact_normal_given_normal(){
+ std::cout << "->example_exact_sample_normal_given_normal" << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+ namespace sampl = csd::sampler;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef shared::feature::scalar<value_type,id_y> state_y; //2
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+ typedef shared::feature::scalar<value_type,id_rho_xy> rho_xy; //5
+
+ // dependent feature
+ typedef
+ par::feature::normal_given_normal<
+ par_y,
+ state_x,
+ par_x,
+ rho_xy
+ > //6
+ par_y_given_x;
+ //sampler
+ typedef sampl::feature::normal<par_y_given_x,state_y> sampl_y_given_x;//7
+
+
+ typedef mpl::vector<sampl_y_given_x> implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<7> desired_size;
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+ typedef mpl::back<features>::type actual_back;
+ typedef sampl_y_given_x desired_back;
+ BOOST_MPL_ASSERT((
+ is_same<desired_back,actual_back>
+ ));
+
+ // input
+ const value_type state_x_val = -0.1;
+ const value_type state_y_val = 0.1;
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+ const value_type rho_val = 0.5;
+
+ set_t set;
+
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ shared::kwd<id_y>::scalar = state_y_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val,
+ shared::kwd<id_rho_xy>::scalar = rho_val
+ )
+ );
+
+ typedef mpl::vector<sampl_y_given_x> samplers;
+ typedef shared::contains_feature_of<samplers,mpl::_> is_sampler;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+
+ BOOST_ASSERT((
+ set.extract<state_y>()() == state_y_val
+ ));
+
+ typedef std::vector<value_type> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws;
+ draws.reserve(n);
+
+ std::string str = "%1% samples from y|x, with (x,y) jointly normal, ";
+ str += " and x fixed at %2%";
+ str += "mu_x = %3% ";
+ str += "sigma_x = %4% ";
+ str += "rho_xy = %5% ";
+ str += "mu_y = %6% ";
+ str += "sigma_y = %7% ";
+ str += "so that mu_y|x = %8%, sigma_y|x = %9%";
+ str += "and a normal sampler.";
+ format the_format(str);
+ the_format % n ;
+ the_format % set.extract<state_x>()();
+ the_format % set.extract<par_x>().mu();
+ the_format % set.extract<par_x>().sigma();
+ the_format % set.extract<rho_xy>()();
+ the_format % set.extract<par_y>().mu();
+ the_format % set.extract<par_y>().sigma();
+ the_format % set.extract<par_y_given_x>().mu();
+ the_format % set.extract<par_y_given_x>().sigma();
+ std::cout << the_format.str() << std::endl;
+
+
+ for(unsigned i=0; i<n; ++i){
+ set.visit_if<is_sampler>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws.push_back(
+ set.extract<state_y>()()
+ );
+ }
+
+ std::cout << "sample statistics : " << std::endl;
+
+ value_type m = std::accumulate(begin(draws),end(draws),(value_type)(0));
+ m/=(value_type)(n);
+
+ std::cout << " mu_y|x : " << m << std::endl;
+
+ value_type s = std::inner_product(
+ begin(draws),
+ end(draws),
+ begin(draws),
+ (value_type)(0)
+ );
+ s -= n*m*m;
+ s = sqrt(s/(value_type)(n));
+
+ std::cout << " mu_y|x : " << s << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// exact_normal_given_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SRC_EXAMPLE_SAMPLER_NORMAL_GIVEN_NORMAL_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_SRC_EXAMPLE_SAMPLER_NORMAL_GIVEN_NORMAL_H_ER_2009
+
+void example_sampler_exact_normal_given_normal();
+
+#endif

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,265 @@
+////////////////////////////////////////////////////////////////////////////
+// gibbs_ars_bivariate_normal.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 <numeric>
+#include <vector>
+#include <cmath>
+#include <boost/assert.hpp>
+#include <boost/bind.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range.hpp>
+
+//#include <boost/iterator/vector2matrix_iterator.hpp>
+
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp>
+
+#include <boost/conditionally_specified_distribution/sampler/adaptive_rejection/sampler.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.h>
+
+void example_sampler_gibbs_ars_bivariate_normal(){
+ std::cout << "->example_sampler_gibbs_ars_bivariate_normal" << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+ namespace sampl = csd::sampler;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef shared::feature::scalar<value_type,id_y> state_y; //2
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+ typedef shared::feature::scalar<value_type,id_rho_xy> rho_xy; //5
+
+ // dependent feature
+ typedef
+ par::feature::normal_given_normal<
+ par_y,
+ state_x,
+ par_x,
+ rho_xy
+ > //6
+ par_y_given_x;
+ typedef
+ par::feature::normal_given_normal<
+ par_x,
+ state_y,
+ par_y,
+ rho_xy
+ > //7
+ par_x_given_y;
+
+ //sampler
+ typedef sampl::feature::adaptive_rejection_sampler<
+ par_x_given_y,
+ state_x
+ > sampl_x_given_y;
+ typedef sampl::feature::adaptive_rejection_sampler<
+ par_y_given_x,
+ state_y
+ > sampl_y_given_x;
+
+ typedef mpl::vector<
+ sampl_y_given_x,
+ sampl_x_given_y
+ > implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<9> desired_size;
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+
+ // input
+
+ const value_type state_x_val = -0.1;
+ const value_type state_y_val = 0.1;
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+ const value_type rho_val = 0.9;
+
+// The greater rho_val, the more likely a stability issues
+// such as exp(-inf). These issues, however, go away if
+// initializer = pair_quantiles_averaged_over_iterations
+// but see sampler::adaptive_rejection::sampler.hpp for further comment.
+// Warning: The output below shows a residual bias in sigma_x (0.97 vs 1.0)
+// Output
+// n = 10000000;
+// x:
+// mu : -0.1 vs m :-0.0996011
+// sigma : 1 vs s :0.973064
+// y:
+// mu : 0.1 vs m :0.100748
+// sigma : 1.5 vs s :1.45992
+// rho : 0.9 vs s_xy :0.896383
+
+ BOOST_ASSERT((rho_val<1.0) && (rho_val>-1.0));
+
+ set_t set;
+
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ shared::kwd<id_y>::scalar = state_y_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val,
+ shared::kwd<id_xy>::scalar = rho_val
+ )
+ );
+
+ typedef mpl::vector<sampl_x_given_y> sampler_x;
+ typedef shared::contains_feature_of<sampler_x,mpl::_> is_sampler_x;
+ typedef mpl::vector<sampl_y_given_x> sampler_y;
+ typedef shared::contains_feature_of<sampler_y,mpl::_> is_sampler_y;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+
+ BOOST_ASSERT((
+ set.extract<state_y>()() == state_y_val
+ ));
+ typedef std::vector<value_type> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws_x;
+ draws_x.reserve(n);
+ draws_t draws_y;
+ draws_y.reserve(n);
+
+ std::string str = "%1% samples from (x,y) jointly normal, ";
+ str += "mu_x = %2% ";
+ str += "sigma_x = %3% ";
+ str += "rho_xy = %4% ";
+ str += "mu_y = %5% ";
+ str += "sigma_y = %6% ";
+ str += "using the decomposition (y|x, x|y) ";
+ str += "and an ars sampler for each component.";
+ format the_format(str);
+ the_format % n ;
+ the_format % set.extract<par_x>().mu();
+ the_format % set.extract<par_x>().sigma();
+ the_format % set.extract<rho_xy>()();
+ the_format % set.extract<par_y>().mu();
+ the_format % set.extract<par_y>().sigma();
+ std::cout << the_format.str() << std::endl;
+
+
+ for(unsigned i=0; i<n; ++i){
+ //if(i%1e4==0){
+ // std::cout << "i=" << i << std::endl;
+ //}
+ set.visit_if<is_sampler_x>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_x.push_back(
+ set.extract<state_x>()()
+ );
+ set.visit_if<is_sampler_y>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_y.push_back(
+ set.extract<state_y>()()
+ );
+ }
+
+ std::cout << "sample statistics : " << std::endl;
+
+ typedef range_iterator<draws_t>::type iter_t;
+
+ value_type m_x = std::accumulate(
+ begin(draws_x),end(draws_x),(value_type)(0));
+ m_x/=(value_type)(n);
+ value_type s_x = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_x),(value_type)(0));
+ s_x -= n*m_x*m_x;
+ s_x = sqrt(s_x/(value_type)(n));
+
+ std::cout
+ << " mu_x : " << m_x << std::endl;
+ std::cout
+ << " sigma_x : " << s_x << std::endl;
+
+ value_type m_y = std::accumulate(
+ begin(draws_y),end(draws_y),(value_type)(0));
+ m_y/=(value_type)(n);
+ value_type s_y = std::inner_product(
+ begin(draws_y),end(draws_y),begin(draws_y),(value_type)(0));
+ s_y -= n*m_y*m_y;
+ s_y = sqrt(s_y/(value_type)(n));
+
+ std::cout
+ << " mu_y : " << m_y << std::endl;
+ std::cout
+ << " sigma_y : " << s_y << std::endl;
+
+ transform(begin(draws_x),end(draws_x),begin(draws_x),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_x
+ )
+ );
+ transform(begin(draws_y),end(draws_y),begin(draws_y),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_y
+ )
+ );
+
+ value_type s_xy = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_y),(value_type)(0));
+ s_xy = s_xy/(value_type)(n);
+ s_xy /= (s_x * s_y);
+
+ std::cout
+ << " rho_xy :" << s_xy << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}
+

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// gibbs_ars_bivariate_normal.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_CONDITIOANLLY_SPECIFIED_DISTRIBUTION_GIBBS_ARS_BIVARIATE_NORMAL_ARS_H_ER_2009
+#define LIBS_CONDITIOANLLY_SPECIFIED_DISTRIBUTION_GIBBS_ARS_BIVARIATE_NORMAL_ARS_H_ER_2009
+
+void example_sampler_gibbs_ars_bivariate_normal();
+
+#endif // GIBBS_NORMAL_ARS_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,250 @@
+////////////////////////////////////////////////////////////////////////////
+// gibbs_bivariate_normal.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 <numeric>
+#include <vector>
+#include <cmath>
+#include <boost/bind.hpp>
+#include <boost/assert.hpp>
+#include <boost/format.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/range.hpp>
+
+//#include <boost/iterator/vector2matrix_iterator.hpp>
+
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+
+#include <boost/conditionally_specified_distribution/keyword/parameter.hpp>
+#include <boost/conditionally_specified_distribution/parameter/normal.hpp>
+#include <boost/conditionally_specified_distribution/parameter/dependent/normal_given_normal.hpp>
+
+#include <boost/conditionally_specified_distribution/sampler/normal.hpp>
+#include <boost/conditionally_specified_distribution/keyword/sampler.hpp>
+#include <libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.h>
+
+void example_sampler_gibbs_bivariate_normal(){
+ std::cout << "->example_sampler_gibbs_bivariate_normal" << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+ namespace csd = conditionally_specified_distribution;
+ namespace par = csd::parameter;
+ namespace sampl = csd::sampler;
+
+ // data type
+ typedef double value_type;
+
+ // identifiers
+ typedef mpl::size_t<0> id_x;
+ typedef mpl::size_t<1> id_y;
+ typedef mpl::pair<id_x,id_y> id_xy;
+ typedef id_xy id_rho_xy;
+
+ // atomic features
+ typedef shared::feature::scalar<value_type,id_x> state_x; //1
+ typedef shared::feature::scalar<value_type,id_y> state_y; //2
+ typedef par::feature::normal<value_type,id_x> par_x; //3
+ typedef par::feature::normal<value_type,id_y> par_y; //4
+ typedef shared::feature::scalar<value_type,id_rho_xy> rho_xy; //5
+
+ // dependent feature
+ typedef
+ par::feature::normal_given_normal<
+ par_y,
+ state_x,
+ par_x,
+ rho_xy
+ > //6
+ par_y_given_x;
+ typedef
+ par::feature::normal_given_normal<
+ par_x,
+ state_y,
+ par_y,
+ rho_xy
+ > //7
+ par_x_given_y;
+
+ //sampler
+ typedef sampl::feature::normal<par_y_given_x,state_y> sampl_y_given_x;//8
+ typedef sampl::feature::normal<par_x_given_y,state_x> sampl_x_given_y;//9
+
+ typedef mpl::vector<
+ sampl_y_given_x,
+ sampl_x_given_y
+ > implicit_features;
+ typedef shared_features::set<implicit_features> set_t;
+ typedef set_t::mpl_features::type wrapped_features;
+
+ typedef mpl::transform<
+ wrapped_features,
+ shared::detail::feature_tag<mpl::_1>
+ >::type features;
+ typedef shared::detail::features<implicit_features>::sorted_vector
+ sorted_vector;
+ typedef mpl::size<features>::type actual_size;
+ typedef mpl::size_t<9> desired_size;
+ BOOST_MPL_ASSERT((
+ mpl::equal_to<actual_size,desired_size>
+ ));
+
+ // input
+
+ const value_type state_x_val = -0.1;
+ const value_type state_y_val = 0.1;
+ const value_type mu_x_val = -0.1;
+ const value_type sigma_x_val = 1.0;
+ const value_type mu_y_val = 0.1;
+ const value_type sigma_y_val = 1.5;
+ const value_type rho_val = 0.9;
+
+ // output
+ // n = 10000000;
+ // x:
+ // mu : -0.1 vs m :-0.100715
+ // sigma : 1 vs s :0.999715
+ // y:
+ // mu : 0.1 vs m :0.0989071
+ // sigma : 1.5 vs s :1.49954
+ // rho : 0.9 vs s_xy :0.899882
+
+
+ set_t set;
+
+ set.initialize(
+ (
+ shared::kwd<id_x>::scalar = state_x_val,
+ shared::kwd<id_y>::scalar = state_y_val,
+ par::kwd<id_x>::mu = mu_x_val,
+ par::kwd<id_x>::sigma = sigma_x_val,
+ par::kwd<id_y>::mu = mu_y_val,
+ par::kwd<id_y>::sigma = sigma_y_val,
+ shared::kwd<id_rho_xy>::scalar = rho_val
+ )
+ );
+
+ typedef mpl::vector<sampl_x_given_y> sampler_x;
+ typedef shared::contains_feature_of<sampler_x,mpl::_> is_sampler_x;
+ typedef mpl::vector<sampl_y_given_x> sampler_y;
+ typedef shared::contains_feature_of<sampler_y,mpl::_> is_sampler_y;
+
+ typedef boost::mt19937 urng_type;
+ const unsigned seed = 0;
+ urng_type urng((urng_type)(seed));
+
+ BOOST_ASSERT((
+ set.extract<state_y>()() == state_y_val
+ ));
+
+ typedef std::vector<value_type> draws_t;
+ const unsigned n = 1e6;
+ draws_t draws_x;
+ draws_x.reserve(n);
+ draws_t draws_y;
+ draws_y.reserve(n);
+
+ std::string str = "%1% samples from (x,y) jointly normal, ";
+ str += "mu_x = %2% ";
+ str += "sigma_x = %3% ";
+ str += "rho_xy = %4% ";
+ str += "mu_y = %5% ";
+ str += "sigma_y = %6% ";
+ str += "using the decomposition (y|x, x|y) ";
+ str += "and a normal sampler for each component.";
+ format the_format(str);
+ the_format % n ;
+ the_format % set.extract<par_x>().mu();
+ the_format % set.extract<par_x>().sigma();
+ the_format % set.extract<rho_xy>()();
+ the_format % set.extract<par_y>().mu();
+ the_format % set.extract<par_y>().sigma();
+ std::cout << the_format.str() << std::endl;
+
+
+ for(unsigned i=0; i<n; ++i){
+ set.visit_if<is_sampler_x>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_x.push_back(
+ set.extract<state_x>()()
+ );
+ set.visit_if<is_sampler_y>(
+ shared::functor::sample(),
+ (sampl::kwd<>::random_number_generator = urng)
+ );
+ draws_y.push_back(
+ set.extract<state_y>()()
+ );
+ }
+ std::cout << "sample statistics : " << std::endl;
+
+ typedef range_iterator<draws_t>::type iter_t;
+
+ value_type m_x = std::accumulate(
+ begin(draws_x),end(draws_x),(value_type)(0));
+ m_x/=(value_type)(n);
+ value_type s_x = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_x),(value_type)(0));
+ s_x -= n*m_x*m_x;
+ s_x = sqrt(s_x/(value_type)(n));
+
+ std::cout
+ << " mu_x : " << m_x << std::endl;
+ std::cout
+ << " sigma_x : " << s_x << std::endl;
+
+ value_type m_y = std::accumulate(
+ begin(draws_y),end(draws_y),(value_type)(0));
+ m_y/=(value_type)(n);
+ value_type s_y = std::inner_product(
+ begin(draws_y),end(draws_y),begin(draws_y),(value_type)(0));
+ s_y -= n*m_y*m_y;
+ s_y = sqrt(s_y/(value_type)(n));
+
+ std::cout
+ << " mu_y : " << m_y << std::endl;
+ std::cout
+ << " sigma_y : " << s_y << std::endl;
+
+ transform(begin(draws_x),end(draws_x),begin(draws_x),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_x
+ )
+ );
+ transform(begin(draws_y),end(draws_y),begin(draws_y),
+ bind(
+ std::minus<value_type>(),
+ _1,
+ m_y
+ )
+ );
+
+ value_type s_xy = std::inner_product(
+ begin(draws_x),end(draws_x),begin(draws_y),(value_type)(0));
+ s_xy = s_xy/(value_type)(n);
+ s_xy /= (s_x * s_y);
+
+ std::cout
+ << " rho_xy :" << s_xy << std::endl;
+
+ std::cout << "<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+////////////////////////////////////////////////////////////////////////////
+// gibbs_bivariate_normal.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_CONDITIONALLY_SPECIFIED_DISTRIBUTION_GIBBS_NORMAL_H_ER_2009
+#define LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_GIBBS_NORMAL_H_ER_2009
+
+void example_sampler_gibbs_normal();
+
+#endif // LIBS_CONDITIONALLY_SPECIFIED_DISTRIBUTION_GIBBS_NORMAL_H_ER_2009

Added: sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/conditionally_specified_distribution/libs/conditionally_specified_distribution/src/main.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,34 @@
+////////////////////////////////////////////////////////////////////////////
+// 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 <libs/conditionally_specified_distribution/src/example/parameter/normal_given_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/sampler/ars_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/sampler/exact_normal_given_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/sampler/exact_bivariate_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/sampler/gibbs_ars_bivariate_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/sampler/gibbs_bivariate_normal.h>
+#include <libs/conditionally_specified_distribution/src/example/function/pair_independent.h>
+
+using namespace std;
+
+int main()
+{
+ example_parameter_normal_given_normal();
+
+
+ //normal (from simple to complex):
+ example_sampler_exact_normal_given_normal();
+ example_sampler_exact_bivariate_normal();
+ example_sampler_ars_normal();
+ example_sampler_exact_bivariate_normal();
+ example_sampler_gibbs_ars_bivariate_normal();
+
+ example_function_pair_independent();
+
+
+ return 0;
+}

Added: sandbox/conditionally_specified_distribution/math_limit/boost/math_limit/miscellanea.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/math_limit/boost/math_limit/miscellanea.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,63 @@
+////////////////////////////////////////////////////////////////////////////
+// math_limit::miscellanea.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_MATH_LIMITS_MISCELLANEA_HPP_ER_2009
+#define BOOST_MATH_LIMITS_MISCELLANEA_HPP_ER_2009
+#include <boost/math/tools/precision.hpp>
+namespace boost{
+namespace math_limit{
+
+ template<typename RealType>
+ struct limits{
+ static RealType log_max_value(){
+ return math::tools::log_max_value<RealType>();
+ }
+ static RealType log_min_value(){
+ return math::tools::log_min_value<RealType>();
+ }
+ static RealType negative_infinity(){
+ return -infinity();
+ }
+ static RealType min_value(){
+ //beware math::tools::min_value<RealType>() is the
+ // min positive value (for floats);
+ return math::tools::min_value<RealType>();
+ }
+ static RealType infinity(){
+ return math::tools::max_value<RealType>();
+ }
+ static RealType is_negative_infinity(RealType x){
+ return !(x>negative_infinity());
+ }
+ static RealType is_infinity(RealType x){
+ return !(x<infinity());
+ }
+ };
+
+ template<typename RealType>
+ RealType
+ safer_exp(RealType a){
+ typedef math_limit::limits<RealType> limits_t;
+ RealType e = 0.0;
+ RealType lmx = limits_t::log_max_value();
+ RealType lmi = limits_t::log_min_value();
+ if(a < lmx){
+ if(a > lmi){
+ e = exp(a); // -inf < a < inf
+ }else{
+ e = 0.0;
+ }
+ }else{
+ e = limits_t::infinity(); // a = inf
+ }
+ BOOST_ASSERT(!std::isnan(e));
+ return e;
+ }
+
+}
+}
+
+#endif // MISCELLANEA_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/creation.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/creation.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,99 @@
+/////////////////////////////////////////////////////////////////////////////
+// creation.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_CREATION_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_CREATION_HPP_ER_2009
+#include <boost/fusion/include/next.hpp>
+#include <boost/fusion/include/equal_to.hpp>
+#include <boost/fusion/include/value_of.hpp>
+#include <boost/fusion/include/mpl.hpp>
+#include <boost/fusion/include/end.hpp>
+#include <boost/fusion/include/begin.hpp>
+#include <boost/fusion/include/cons.hpp>
+#include <boost/fusion/include/any.hpp>
+#include <boost/fusion/include/find_if.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+namespace boost{namespace shared_features{
+
+namespace detail{
+
+template<
+ typename First,
+ typename Last,
+ bool is_empty = fusion::result_of::equal_to<First,Last>::value
+> struct build_acc_list;
+
+template<typename First,typename Last>
+struct build_acc_list<First,Last,true>
+{
+ typedef fusion::nil type;
+ template<typename Args>
+ static fusion::nil
+ call(Args const & a, First const & f, Last const & l)
+ {
+ return fusion::nil();
+ }
+};
+
+template<typename First,typename Last>
+struct build_acc_list<First,Last,false>
+{
+ typedef build_acc_list<
+ typename fusion::result_of::next<First>::type,
+ Last
+ > next_build_acc_list;
+
+ typedef typename fusion::result_of::value_of<First>::type
+ first_type;
+
+ typedef fusion::cons<
+ first_type,
+ typename next_build_acc_list::type
+ > type;
+
+ template<typename Args>
+ static type
+ call(Args const & args, First const & f, Last const & l)
+ {
+ first_type first(args);
+ return type(
+ args,
+ next_build_acc_list::call(args,fusion::next(f),l)
+ );
+ }
+};
+ namespace meta{
+ template<typename Sequence>
+ struct make_acc_list : build_acc_list<
+ typename fusion::result_of::begin<Sequence>::type,
+ typename fusion::result_of::end<Sequence>::type>
+ {};
+ }
+
+ template<typename Sequence,typename Args>
+ typename meta::make_acc_list<Sequence>::type
+ make_acc_list(Sequence const &seq, Args const& args)
+ {
+
+ return meta::make_acc_list<Sequence>::call(args,fusion::begin(seq),
+ fusion::end(seq));
+ }
+
+
+
+}//detail
+}//shared_features
+}//boost
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/depends_on.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/depends_on.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,84 @@
+/////////////////////////////////////////////////////////////////////////////
+// depends_on.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_DEPENDS_ON_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_DEPENDS_ON_HPP_ER_2009
+#include <boost/mpl/inherit.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/sort.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/mpl/inherit_linearly.hpp>
+#include <boost/mpl/vector/vector10.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/accumulators/accumulators_fwd.hpp>
+#include <boost/preprocessor/repetition/repeat.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/facilities/intercept.hpp>
+namespace boost{namespace shared_features
+{
+ template<typename Feature>
+ struct as_feature{
+ typedef Feature type;
+ };
+
+ template<typename Feature>
+ struct feature_of{
+ typedef Feature type;
+ };
+
+namespace detail
+{
+ template<typename A,typename B>
+ struct is_dependent_on : is_base_and_derived<B,A>{};
+
+ template<typename Features>
+ struct depends_on_base
+ : mpl::inherit_linearly<
+ typename mpl::sort<
+ Features,is_dependent_on<mpl::_1,mpl::_2> >::type,
+ //don't inherit multiply from a feature
+ mpl::if_<
+ is_dependent_on<mpl::_1,mpl::_2>
+ , mpl::_1
+ , mpl::inherit<mpl::_1,mpl::_2>
+ >
+ >::type
+ {};
+}
+
+ // Usage: struct X : depends_on<A,B,C>{};
+ template<typename Features>
+ struct depends_on : detail::depends_on_base<
+ typename mpl::transform<Features, as_feature<mpl::_1>
+ >::type
+ >
+ {
+ typedef typename
+ mpl::transform<Features, as_feature<mpl::_1> >::type
+ dependencies;
+ };
+
+ struct depends_on0 : depends_on<mpl::vector0<> >
+ {};
+
+ template<typename Feature>
+ struct depends_on1 : depends_on<mpl::vector1<Feature> >
+ {};
+
+ template<typename F1,typename F2>
+ struct depends_on2 : depends_on<mpl::vector2<F1,F2> >
+ {};
+
+}
+}
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,203 @@
+////////////////////////////////////////////////////////////////////////////
+// container.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_CONTAINER_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_CONTAINER_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+
+namespace boost{namespace shared_features{
+
+namespace impl
+{
+
+ template<typename Container,typename Id>
+ class container_base{
+
+ protected:
+ typedef Container elements_t;
+
+ // used for returning a range (subset)
+ typedef iterator_range<const elements_t> iterator_range;
+
+ typedef typename range_size<elements_t>::type size_type;
+ typedef typename range_iterator<elements_t>::type iterator;
+
+ public:
+ typedef typename range_value<elements_t>::type value_type;
+
+ struct result : mpl::identity<const elements_t&>{};
+ struct result_of_at : mpl::identity<value_type>{};
+ struct result_of_range : mpl::identity<iterator_range>{};
+ struct identifier : mpl::identity<Id>{};
+ };
+
+ template<
+ typename Container,
+ typename Id
+ >
+ class container : public container_base<Container,Id>{
+ typedef container_base<Container,Id> super_t;
+ typedef kwd<Id> kwd;
+ typedef container<Container,Id> this_type;
+ public:
+
+ container(){}
+
+ template<typename Args>
+ container(const Args& args){
+ typedef mpl::bool_<false> f;
+ set_if(
+ args[shared_features::kwd_do_initialize|f()],
+ args
+ );
+ }
+
+ container(const container& that){
+ set(that());
+ }
+ container&
+ operator=(const container& that){
+ if(&that!=this){
+ set(that());
+ }
+ return (*this);
+ }
+
+ //modify
+ template<typename R>
+ void set(const R& r){
+ (this->elements_).clear();
+ std::copy(
+ begin(r),
+ end(r),
+ back_inserter(elements_)
+ );
+ };
+ template<typename R>
+ void set(utility::dont_care,const R& r){
+ return this->set(r);
+ }
+
+ void set_at(
+ typename super_t::size_type pos,
+ typename super_t::value_type x
+ ){
+ typedef typename
+ range_iterator<typename super_t::elements_t>::type it_t;
+ it_t i = begin(elements_);
+ std::advance(i,pos);
+ *i = x;
+ };
+ void set_at(
+ utility::dont_care,
+ typename super_t::size_type pos,
+ typename super_t::value_type x
+ ){
+ return this->set_at(pos,x);
+ }
+
+ template<typename R>
+ void replace(typename super_t::size_type position, const R& r){
+ BOOST_ASSERT(position+size(r)-(this->size())>=0);
+ typedef typename
+ range_iterator<typename super_t::elements_t>::type it_t;
+ it_t i = begin(elements_);
+ std::advance(i,position);
+ copy(
+ begin(r),
+ end(r),
+ i
+ );
+ }
+ template<typename R>
+ void replace(
+ utility::dont_care,
+ typename super_t::size_type position,
+ const R& r
+ ){
+ return this->replace(position,r);
+ }
+
+ //query
+ typename super_t::size_type
+ size()const{
+ return size(this->elements);
+ }
+ typename super_t::size_type
+ size(utility::dont_care)const{ return size(); }
+
+ typename super_t::result::type
+ operator()()const{ return this->elements_; }
+
+ typename super_t::result::type
+ operator()(utility::dont_care)const{ return this->operator()(); }
+
+ typename super_t::result_of_at::type
+ at(typename super_t::size_type pos)const{
+ typedef typename
+ range_iterator<
+ typename add_const<typename super_t::elements_t>::type
+ >::type const_it_t;
+ const_it_t i = begin(this->operator()());
+ std::advance(i,pos);
+ return (*i);
+ }
+ typename super_t::result_of_at::type
+ at(utility::dont_care,typename super_t::size_type pos)const{
+ return this->at(pos);
+ }
+
+ typename super_t::result_of_range::type
+ range(
+ typename super_t::size_type position,
+ typename super_t::size_type size
+ ){
+ return make_iterator_range(elements_,position,position+size);
+ }
+
+
+ typename super_t::result_of_range::type
+ range(
+ utility::dont_care,
+ typename super_t::size_type position,
+ typename super_t::size_type size
+ ){
+ return this->range(position,size) ;
+ }
+
+ private:
+ template<typename Args>
+ void set_if(mpl::bool_<true>,const Args& args){
+ set(args[kwd::container]);
+ }
+ void set_if(mpl::bool_<false>,utility::dont_care){}
+ typename super_t::elements_t elements_;
+ };
+
+} // namespace impl
+namespace feature{
+ // C is not a feature but physical container
+ template <typename C,typename Id = mpl::void_>
+ struct container
+ : shared_features::depends_on0
+ {
+ typedef impl::container_base<C,Id> traits;
+ typedef impl::container<C,Id> impl;
+ };
+}
+
+
+}}
+
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container_element.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/container_element.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,132 @@
+////////////////////////////////////////////////////////////////////////////
+// container_element.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_CONTAINER_ELEMENT_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_CONTAINER_ELEMENT_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+
+namespace boost{
+namespace shared_features{
+namespace impl
+{
+
+ template<typename Container,typename Id>
+ class container_element_base{
+ protected:
+ typedef typename Container::result::type cont_t;
+ typedef typename range_value<
+ typename utility::remove_qualifier<cont_t>::type
+ >::type value_type;
+ typedef typename range_size<
+ typename utility::remove_qualifier<cont_t>::type
+ >::type size_type;
+ public:
+ struct result : mpl::identity<value_type>{};
+ };
+
+ template<
+ typename Container,
+ typename Id
+ >
+ class container_element :
+ public container_element_base<typename Container::traits,Id>
+ {
+ typedef container_element_base<typename Container::traits,Id>
+ super_t;
+ typedef kwd<Id> kwd;
+ typedef Container feature_cont_t;
+ public:
+ container_element():position_(0){}
+ template<typename Args>
+ container_element(const Args& args)
+ :position_(args[kwd::position|0]){
+ typedef mpl::bool_<false> f;
+ alert_if(args[kwd_do_initialize|f()],args[kwd::position|-1]);
+ }
+ container_element(const container_element& that)
+ :position_(that.position_){}
+
+ container_element&
+ operator=(const container_element& that){
+ if(&that!=this){
+ position_ = that.position_;
+ }
+ return (*this);
+ }
+
+ template<typename Args>
+ void set(
+ const Args& args,
+ typename super_t::value_type x
+ ){
+ return this->set_impl(
+ args[kwd_set],
+ args,
+ x
+ );
+ }
+
+ template<typename Args>
+ typename super_t::result::type
+ operator()(const Args& args)const{
+ return get(args[kwd_set],args);
+ }
+
+ typename super_t::size_type
+ position()const{ return this->position_; }
+
+ typename super_t::size_type
+ position(utility::dont_care)const{ return this->position(); }
+
+ private:
+ template<typename Set,typename Args>
+ typename super_t::result::type
+ get(const Set& set,const Args& args)const{
+ typename super_t::size_type pos = this->position();
+ return (set.template extract<feature_cont_t>()).at(args,pos);
+ }
+ template<typename Set,typename Args>
+ void set_impl(
+ Set& set,
+ const Args& args,
+ typename super_t::value_type x
+ ){//const
+ typename super_t::size_type pos = (this->position());
+ (set.template extract<feature_cont_t>)().set_at(args,pos,x);
+ }
+ void alert_if(mpl::bool_<true>,int i)const{
+ BOOST_ASSERT(i>-1);
+ }
+ void alert_if(mpl::bool_<false>,int i)const{
+ }
+ typename super_t::size_type position_;
+ };
+} // namespace impl
+namespace feature{
+ template <typename Cont,typename Id = mpl::void_>
+ struct container_element
+ : shared_features::depends_on<
+ mpl::vector<Cont>
+ >
+ {
+ typedef impl::container_element_base<typename Cont::traits,Id> traits;
+ typedef impl::container_element<Cont,Id> impl;
+ };
+}
+
+}
+}
+
+
+#endif // ELEMENT_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/example.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/example.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,73 @@
+////////////////////////////////////////////////////////////////////////////
+// example.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_EXAMPLE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_EXAMPLE_HPP_ER_2009
+#include <boost/mpl/vector/vector10.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/depends_on.hpp>
+
+namespace boost{namespace shared_features{namespace example{
+
+ BOOST_PARAMETER_KEYWORD(tag,kwd_x_value)
+ BOOST_PARAMETER_KEYWORD(tag,kwd_y_value) //actually, not used
+
+namespace impl{
+ template<typename RealType>
+ struct X{
+
+ template<typename Args>
+ X(const Args& args): value_(args[kwd_x_value|(RealType)(0)]){}
+
+ template<typename Args>
+ void initialize(const Args& args){
+ value_ = args[kwd_x_value];
+ }
+
+ RealType value_;
+ };
+ template<typename X>
+ struct Y{
+ typedef X x_t;
+ typedef typename x_t::value_type value_type;
+
+ template<typename Args>
+ Y(const Args& args):value_(
+ get_x(args[kwd_set]).value_
+ ){}
+
+ template<typename Set>
+ typename Set::template result_of_extract<x_t>::type const&
+ get_x(const Set& set)const{
+ return set.template extract<x_t>();
+ }
+
+ value_type value_;
+ };
+}
+
+namespace feature{
+ template<typename RealType>
+ struct X : depends_on<
+ mpl::vector0<>
+ >{
+ typedef RealType value_type;
+ typedef impl::X<RealType> impl;
+ };
+ template<typename X>
+ struct Y : depends_on<
+ mpl::vector1<X>
+ >{
+ typedef impl::Y<X> impl;
+ };
+}
+
+}
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_EXAMPLE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/keyword.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,51 @@
+////////////////////////////////////////////////////////////////////////////
+// keyword.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_KEYWORD_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_KEYWORD_HPP_ER_2009
+#include <boost/mpl/void.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost{
+namespace shared_features{
+
+namespace tag{
+ template<typename Id> struct scalar_{};
+ template<typename Id> struct container_{};
+ template<typename Id> struct position_{};
+}
+namespace {
+ template<typename Id = mpl::void_>
+ class kwd{
+ typedef tag::scalar_<Id> scalar_t;
+ typedef tag::container_<Id> container_t;
+ typedef tag::position_<Id> position_t;
+ public:
+ typedef Id id_type;
+ static ::boost::parameter::keyword<scalar_t>& scalar;
+ static ::boost::parameter::keyword<container_t>& container;
+ static ::boost::parameter::keyword<position_t>& position;
+ };
+
+ template<typename Id>
+ ::boost::parameter::keyword<tag::scalar_<Id> >&
+ kwd<Id>::scalar =
+ ::boost::parameter::keyword<tag::scalar_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::container_<Id> >&
+ kwd<Id>::container =
+ ::boost::parameter::keyword<tag::container_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::position_<Id> >&
+ kwd<Id>::position =
+ ::boost::parameter::keyword<tag::position_<Id> >::get();
+}//anonymous
+}//state
+}//boost
+
+
+#endif // TAG_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/scalar.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/feature/scalar.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,95 @@
+////////////////////////////////////////////////////////////////////////////
+// scalar.hpp
+// (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)
+#ifndef BOOST_SHARED_FETURES_SCALAR_HPP_ER_2009
+#define BOOST_SHARED_FETURES_SCALAR_HPP_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/utility/assert_is_base_of.hpp>
+#include <boost/utility/dont_care.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+namespace boost{namespace shared_features{
+
+namespace impl
+{
+
+
+ template<typename T>
+ class scalar_base{
+ public:
+ typedef T value_type;
+ struct result : mpl::identity<T>{};
+ };
+
+ template<typename T,typename Id = mpl::void_>
+ class scalar : scalar_base<T>
+ {
+ typedef scalar_base<T> super_t;
+ typedef kwd<Id> kwd;
+ public:
+ typedef typename super_t::value_type value_type;
+
+
+ scalar(): value_((value_type)(0)){}
+
+ scalar(value_type value):value_(value){}
+
+ template<typename Args>
+ scalar(const Args& args)
+ : //TODO pass scalar directly as an option
+ value_((value_type)(0))
+ {
+ typedef mpl::bool_<false> f;
+ set_if(args[kwd_do_initialize|f()],args);
+ }
+
+ scalar(const scalar& that) : value_(that.value_){}
+
+ scalar&
+ operator=(const scalar& that){
+ if(&that!=this){
+ value_ = that.value_;
+ }
+ return *this;
+ }
+
+ void set(value_type value){
+ this->value_ = value;
+ };
+ void set(utility::dont_care,value_type value){
+ return this->set(value);
+ };
+
+ value_type operator()()const{return value_;}
+ value_type operator()(utility::dont_care)const{
+ return this->operator()();
+ }
+
+ private:
+ template<typename Args>
+ void set_if(mpl::bool_<true>,const Args& args){
+ set(args[kwd::scalar]);
+ }
+ void set_if(mpl::bool_<false>,utility::dont_care){}
+ value_type value_;
+ };
+
+} // namespace impl
+namespace feature{
+ template <typename T,typename Id>
+ struct scalar
+ : depends_on0
+ {
+ typedef impl::scalar_base<T> traits;
+ typedef impl::scalar<T,Id> impl;
+ };
+}
+
+
+}}
+
+#endif // SCALAR_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/initialize.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/initialize.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////
+// initialize.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_FUNCTOR_INITIALIZE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_FUNCTOR_INITIALIZE_HPP_ER_2009
+
+namespace boost{namespace shared_features{namespace functor{
+
+class initialize{
+ public:
+ initialize(){};
+
+ template<typename Wrapper,typename Args>
+ void operator()(Wrapper& w,const Args& args)const{
+ w = Wrapper(args);
+ }
+};
+
+}
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_INITIALIZE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/sample.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/sample.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////
+// sample.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_FUNCTOR_SAMPLE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_FUNCTOR_SAMPLE_HPP_ER_2009
+
+namespace boost{namespace shared_features{namespace functor{
+
+class sample{
+ public:
+ sample(){};
+
+ template<typename Wrapper,typename Args>
+ void operator()(Wrapper& w,const Args& args)const{
+ w.sample(args);
+ }
+};
+
+}
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_FUNCTOR_SAMPLE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/update.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/functor/update.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,26 @@
+////////////////////////////////////////////////////////////////////////////
+// update.hpp
+// (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)
+#ifndef BOOST_SHARED_FEATURES_FUNCTOR_UPDATE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_FUNCTOR_UPDATE_HPP_ER_2009
+
+namespace boost{namespace shared_features{namespace functor{
+
+class update{
+ public:
+ update(){};
+
+ template<typename Wrapper,typename Args>
+ void operator()(Wrapper& w,const Args& args)const{
+ w.update(args);
+ }
+};
+
+}
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_FUNCTORS_UPDATE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,30 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_INCLUDE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_INCLUDE_HPP_ER_2009
+
+#include <boost/shared_features/feature/container.hpp>
+#include <boost/shared_features/feature/container_element.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/feature/scalar.hpp>
+#include <boost/shared_features/functor/initialize.hpp>
+#include <boost/shared_features/functor/sample.hpp>
+#include <boost/shared_features/functor/update.hpp>
+#include <boost/shared_features/set.hpp>
+#include <boost/shared_features/result_of_extract.hpp>
+#include <boost/shared_features/parameter.hpp>
+
+
+
+#endif // INCLUDE_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/mpl_features.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/mpl_features.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,116 @@
+/////////////////////////////////////////////////////////////////////////////
+// mpl_features.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_MPL_FEATURES_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_MPL_FEATURES_HPP_ER_2009
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/version.hpp>
+
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/fold.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/insert.hpp>
+#include <boost/mpl/insert_range.hpp>
+#include <boost/mpl/is_sequence.hpp>
+#include <boost/mpl/map.hpp>
+#include <boost/mpl/map/map0.hpp>
+#include <boost/mpl/pair.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/mpl/protect.hpp>
+#include <boost/mpl/sort.hpp>
+#include <boost/mpl/transform_view.hpp>
+#include <boost/mpl/vector.hpp>
+
+#include <boost/shared_features/depends_on.hpp>
+namespace boost{ namespace shared_features{
+namespace detail{
+ template<typename Features>
+ struct as_feature_list
+ : mpl::transform_view<Features,as_feature<mpl::_1> >
+ {};
+
+ template<typename Map,typename Feature>
+ struct insert_feature
+ : mpl::eval_if<
+ mpl::has_key<Map, typename feature_of<Feature>::type>,
+ mpl::identity<Map>,
+ mpl::insert<
+ Map,
+ mpl::pair<
+ typename feature_of<Feature>::type,
+ Feature
+ >
+ >
+ >
+ {};
+
+ template<typename Map,typename Feature>
+ struct insert_dependencies
+ : mpl::fold<//Recall : depends_on<A,B,C>::dependencies
+ as_feature_list<typename Feature::dependencies>,
+ Map,
+ insert_dependencies<
+ insert_feature<mpl::_1,mpl::_2>,
+ mpl::_2
+ >
+ >
+ {};
+
+ template<typename Map,typename Features>
+ struct insert_sequence
+ : mpl::fold<
+ as_feature_list<Features>,
+ Map,
+ insert_feature<mpl::_1,mpl::_2>
+ >
+ {};
+
+ template<typename AskedFeatures>
+ struct features{
+
+ typedef typename mpl::fold<
+ as_feature_list<AskedFeatures>,
+ mpl::map0<>,
+ mpl::if_<
+ mpl::is_sequence<mpl::_2>,
+ insert_sequence<mpl::_1,mpl::_2>,
+ insert_feature<mpl::_1,mpl::_2>
+ >
+ >::type explicit_map;
+
+ typedef typename mpl::fold<
+ explicit_map,
+ explicit_map,
+ insert_dependencies<mpl::_1,mpl::second<mpl::_2> >
+ >::type map;
+
+ typedef typename mpl::insert_range<
+ mpl::vector<>,
+ mpl::end<mpl::vector<> >::type,
+ mpl::transform_view<map,mpl::second<mpl::_1> >
+ >::type vector;
+
+ typedef typename mpl::sort<
+ vector,
+ is_dependent_on<mpl::_2,mpl::_1>
+ >::type sorted_vector;
+
+ };
+}//detail
+}//shared_features
+}//boost
+
+#endif // DEPENDENCIES_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/parameter.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,47 @@
+/////////////////////////////////////////////////////////////////////////////
+// parameter.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_PARAMETER_HPP_INCLUDED
+#define BOOST_SHARED_FEATURES_PARAMETER_HPP_INCLUDED
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/mpl/placeholders.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+namespace boost{namespace shared_features{
+
+namespace tag{
+ struct kwd_set;
+ struct kwd_do_initialize;
+}
+
+namespace{
+ static ::boost::parameter::keyword<tag::kwd_set>& kwd_set =
+ ::boost::parameter::keyword<tag::kwd_set>::get();
+
+ static ::boost::parameter::keyword<tag::kwd_do_initialize>&
+ kwd_do_initialize =
+ ::boost::parameter::keyword<tag::kwd_do_initialize>::get();
+}
+
+namespace detail{
+
+ typedef parameter::parameters<
+ parameter::required<tag::kwd_set>
+ > params;
+
+}
+
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/predicate.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/predicate.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,62 @@
+/////////////////////////////////////////////////////////////////////////////
+// predicate.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_PREDICATE_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_PREDICATE_HPP_ER_2009
+#include <boost/mpl/contains.hpp>
+#include <boost/shared_features/depends_on.hpp>
+namespace boost{namespace shared_features{
+ namespace detail{
+ template<typename W>
+ struct feature_tag{
+ typedef typename W::feature_tag type;
+ };
+ }
+
+
+ template<typename Feature>
+ struct matches_feature{
+
+ template<typename Wrapper>
+ struct apply
+ : is_same<
+ typename feature_of<typename as_feature<Feature>::type>::type,
+ typename feature_of<typename as_feature<typename
+ detail::feature_tag<Wrapper>::type>::type>::type
+ >
+ {};
+ };
+
+ template<typename Features,typename Wrapper>
+ struct contains_feature_of{
+
+ typedef mpl::transform_view<
+ Features,
+ feature_of<as_feature<mpl::_> >
+ > features_list;
+
+ typedef typename
+ feature_of<typename detail::feature_tag<Wrapper>::type>::type
+ the_feature;
+
+ typedef
+ typename mpl::contains<features_list, the_feature>::type
+ type;
+
+ };
+
+
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_PREDICATE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/result_of_extract.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/result_of_extract.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,55 @@
+/////////////////////////////////////////////////////////////////////////////
+// result_of_extract.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_RESULT_OF_EXTRACT_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_RESULT_OF_EXTRACT_HPP_ER_2009
+#include <boost/mpl/placeholders.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/parameter/parameters.hpp>
+//#include <boost/parameter/keyword.hpp>
+#include <boost/parameter/binding.hpp>
+#include <boost/parameter/value_type.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/set.hpp>
+namespace boost{
+namespace shared_features{
+
+
+ template<typename Args>
+ struct args_to_set
+ : boost::parameter::value_type<//binding
+ typename utility::remove_qualifier<Args>::type,
+ boost::shared_features::tag::kwd_set
+ >
+ {
+ };
+
+
+ template<typename Set,typename T>
+ struct result_of_extract_given_set{
+ typedef typename Set::template result_of_extract<T>::type type;
+ };
+
+ template<typename Args,typename T>
+ struct result_of_extract
+ : result_of_extract_given_set<
+ typename args_to_set<Args>::type,
+ T
+ >
+ {
+ };
+
+}
+}
+#endif // RESULT_OF_EXTRACT_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/set.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/set.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,222 @@
+/////////////////////////////////////////////////////////////////////////////
+// set.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_SET_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_SET_HPP_ER_2009
+#include <stdexcept>
+#include <boost/version.hpp>
+#include <boost/ref.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/protect.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/is_sequence.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/fusion/include/any.hpp>
+#include <boost/fusion/include/find_if.hpp>
+#include <boost/fusion/include/for_each.hpp>
+#include <boost/fusion/include/filter_view.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/wrapper.hpp>
+#include <boost/shared_features/creation.hpp>
+#include <boost/shared_features/visitor.hpp>
+#include <boost/shared_features/functor/initialize.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/predicate.hpp>
+namespace boost{namespace shared_features{
+namespace detail{
+
+ struct set_base{};
+ template<typename T>
+ struct is_set : is_base_and_derived<set_base,T> {};
+
+ typedef parameter::parameters<
+ parameter::required<tag::kwd_set>
+ > params;
+}
+
+
+template<typename Features>
+class set : detail::set_base{
+ public:
+ typedef set<Features> this_type;
+ typedef Features asked_features_type;
+
+ typedef typename detail::wrappers<asked_features_type>::type
+ mpl_features;
+
+ typedef typename detail::meta::make_acc_list<
+ mpl_features
+ >::type
+ features_type;
+
+ set()
+ :features_(
+ detail::make_acc_list(
+ mpl_features(),
+ //detail::params()(*this)
+ (kwd_set=(*this))
+ )
+ )
+ {
+ // Do :
+ // set();
+ // set.initialize(args);
+ // Not do :
+ // set(args)
+ // news://news.gmane.org:119/gonju8$2da$1@ger.gmane.org
+ //
+ // Also see : initialize(args)
+ };
+
+ template<typename Args>
+ explicit set(Args const& args)
+ :features_(
+ detail::make_acc_list(
+ mpl_features(),
+ (kwd_set=(*this),args)
+ )
+ )
+ {
+ // To be avoided (see above)
+ }
+
+ template<typename BinaryFun>
+ void visit(const BinaryFun& f){
+ this->visit_impl(
+ detail::make_visitor(
+ f,
+ detail::params()(
+ *this
+ )
+ )
+ );
+ }
+
+ template<typename BinaryFun,typename Args>
+ void visit(const BinaryFun& f,const Args& args){
+ this->visit_impl(
+ detail::make_visitor(
+ f,
+ (
+ args,
+ (kwd_set = *this)
+ )
+ )
+ // TODO Warning. Weird that this cause compile error:
+ // See creation.cpp
+ //detail::make_visitor(
+ // f,
+ // (
+ // (kwd_set = *this),
+ // args
+ // )
+ //)
+ );
+ }
+
+ template<typename Filter,typename BinaryFun>
+ void visit_if(const BinaryFun& f){
+ this->visit_if_impl<Filter>(
+ detail::make_visitor(
+ f,
+ detail::params()(
+ *this
+ )
+ )
+ );
+ }
+
+ template<typename Filter,typename BinaryFun,typename Args>
+ void visit_if(const BinaryFun& f,const Args& args){
+ this->visit_if_impl<Filter>(
+ detail::make_visitor(
+ f,
+ (
+ args,
+ (kwd_set = *this)
+ )
+ )
+ );
+ }
+
+
+
+ template<typename Feature>
+ struct apply : fusion::result_of::value_of<
+ typename fusion::result_of::find_if<
+ features_type,
+ matches_feature<Feature>
+ >::type
+ >
+ {};
+
+
+ template<typename Args>
+ void initialize(const Args& args){
+ visit(
+ functor::initialize(),
+ (args,kwd_do_initialize = mpl::bool_<true>())
+ );
+ // See the warning in set().
+ // kwd_do_initialize used to distinguish default construction
+ // from call to intialize
+ }
+
+ template<typename Feature>
+ struct result_of_extract{
+ typedef typename apply<Feature>::type type;
+ };
+
+ template<typename Feature>
+ typename apply<Feature>::type& extract()
+ {
+ return *fusion::find_if<matches_feature<Feature> >(
+ this->features_
+ );
+ }
+
+ template<typename Feature>
+ typename apply<Feature>::type const &extract() const
+ {
+ return *fusion::find_if<matches_feature<Feature> >(
+ this->features_
+ );
+ }
+
+ private:
+ //protected:
+ template<typename UnaryFun>
+ void visit_impl(const UnaryFun& f){
+ fusion::for_each(this->features_,f);
+ }
+
+ template<typename Filter,typename UnaryFun>
+ void visit_if_impl(const UnaryFun& f){
+ typedef fusion::filter_view<features_type,Filter> view_t;
+ view_t view(this->features_);
+ fusion::for_each(view,f);
+ }
+ features_type features_;
+};
+
+
+
+}}
+
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/visitor.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,50 @@
+/////////////////////////////////////////////////////////////////////////////
+// visitor.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_VISITOR_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_VISITOR_HPP_ER_2009
+
+namespace boost{namespace shared_features{
+
+namespace detail{
+
+template<typename Fun,typename Args>
+class visitor{
+ public:
+ explicit visitor(Fun const & f,const Args& args)
+ : f_(f),args_(args){}
+
+ visitor(visitor const& that)
+ : f_(that.f_),args_(that.args_){}
+
+ template<typename Wrapper>
+ void operator()(Wrapper& w)const{
+ f_(w,args_);
+ }
+
+ private:
+ visitor& operator=(visitor const &);
+ Fun f_; //warning copy
+ Args const & args_;
+};
+
+template<typename Fun,typename Args>
+visitor<Fun,Args> const make_visitor(Fun const& f,Args const & args){
+ return visitor<Fun,Args>(f,args);
+}
+
+}
+}
+}
+
+#endif // BOOST_SHARED_FEATURES_VISITOR_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/wrapper.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/boost/shared_features/wrapper.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,62 @@
+/////////////////////////////////////////////////////////////////////////////
+// wrapper.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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulator and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SHARED_FEATURES_WRAPPER_HPP_ER_2009
+#define BOOST_SHARED_FEATURES_WRAPPER_HPP_ER_2009
+#include <boost/mpl/apply.hpp>
+#include <boost/mpl/transform.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+namespace boost{namespace shared_features{
+namespace detail{
+
+
+
+template<typename Impl,typename Feature>
+struct wrapper : Impl{
+ typedef Feature feature_tag;
+ wrapper(wrapper const &that)
+ : Impl(*static_cast<Impl const *>(&that))
+ {}
+
+ template<typename Args>
+ wrapper(Args const & args)
+ : Impl(args)
+ {}
+};
+
+
+template<typename Feature>
+struct to_wrapper{
+ typedef wrapper<
+ typename Feature::impl,
+ Feature
+ > type;
+};
+
+
+template<typename Features>
+struct wrappers{
+ typedef features<Features> features;
+ typedef typename features::sorted_vector sorted_vector;
+
+ typedef typename mpl::transform<sorted_vector,
+ to_wrapper<mpl::_1>
+ >::type type;
+};
+
+}
+}
+}
+
+
+#endif // WRAPPER_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/doc/readme.txt 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,149 @@
+////////////////////////////////////////////////////////////////////////////
+// shared_features
+// (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)
+////////////////////////////////////////////////////////////////////////////
+// Disclaimer :
+//
+// This code is a minor modification to Boost.Accumulators and serves a
+// particular purpose not readily provided by the original library.
+// Contact the Boost library for copyright implications.
+////////////////////////////////////////////////////////////////////////////
+
+///////////
+/ Contact /
+///////////
+
+Please send questions or suggestions to erwann.rogard_at_[hidden]
+
+///////////////
+/ Requirements/
+///////////////
+
+////////////////
+/ Requirements /
+////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+The compiler search path must include
+boost_1_37_0
+sandbox/conditionally_specified_distribution/shared_features
+sandbox/conditionally_specified_distribution/utility
+////////////
+/ Overview /
+////////////
+
+This collection of C++ classes may be used to manage objects that depend
+on one another through a common class (set). The classes of these
+objects are referred to as features.
+
+/////////
+/ Usage /
+/////////
+
+Assume B depends on A.
+
+* Feature definition
+ namespace impl{
+ struct B_base{
+ // associated types
+ };
+ struct B : B_base{
+ template<typename Args>
+ void foo(const Args& args){
+ //typically calls
+ // args[kwd_set].template extract<feature::A>();
+ }
+ };
+ }
+ namespace feature{
+ struct B depends_on1<feature::A>{
+ typedef impl::B_base traits;
+ typedef impl::B impl;
+ };
+ }
+
+Implemented features include:
+./feature/scalar.hpp
+./feature/container.hpp
+./feature/container_element.hpp
+./feature/example.hpp
+
+* Keyword ( See Boost.Parameter )
+Above we have extracted the set that A and B are "a part of" using
+ args[kwd_set]
+where kwd_set is defined in ./parameter.hpp.
+Another keyword associated with set is kwd_do_initialize, which we explain
+further below.
+
+If B takes other arguments as part of its interface
+(constructor, accessors etc.), a specific keyword may be needed :
+ class kwd_of_B{
+ public:
+ static ::boost::parameter::keyword<tag_0>& arg_0;
+ static ::boost::parameter::keyword<tag_1>& arg_1;
+ // etc.
+ };
+
+* Construction of a set:
+ typedef mpl::vector<feature::B> features;
+ typedef set<features> set_t; // includes A due to the dependence
+For a technical reason, default construct first, and initialize next:
+ set_t set;
+ set.initialize(args);
+The first command internally passes
+ (kwd_set=set)
+to the constructor of each feature. The second command overrides the
+existing feature with one constructed with
+ (kwd_set=set,kwd_do_initialize = true, args)
+You may want to take that into account in the definition of the feature.
+
+* Visitation of a set:
+Let {e[i] : i=1,...,n} denote elements in the set,
+sorted in such a way that each dependees precedes its dependants
+for each i=1,...n do binary_f(e[i],args) is executed with :
+ set.visit(binary_f(),args)
+
+Implemented binary functions include:
+./functor/initialize.hpp (used by set.initialize)
+./functor/sample.hpp
+./functor/update.hpp
+
+The last two have no particular use here. They are provided as a
+convenience to clients.
+
+* Argument passing
+If there are multiple features with an identical type we need to make the
+feature and the keyword which it uses depend on an additional type:
+namespace impl{
+ template<typename Id>
+ struct B;
+}
+ template<typename Id>
+ class kwd_of_B;
+
+//////////////
+/ Discussion /
+//////////////
+
+These are standard recommendations, but it won't hurt to remind them
+(it has spared us compiler errors) :
+Rather than
+ template<typename Args>
+ get_x(const Args& args){
+ return args[kwd_set].template extract<X>();
+ }
+Define
+ template<typename Args>
+ get_x(const Args& args){ this->get_x_impl(args[kwd_set]) }
+ template<typename Set>
+ get_x_impl(const Set& set){
+ return set.template extract<X>();
+ }
+
+

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,51 @@
+/////////////////////////////////////////////////////////////////////////////
+// container_element.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 <vector>
+#include <boost/mpl/int.hpp>
+#include <boost/shared_features/parameter.hpp>
+#include <boost/shared_features/feature/keyword.hpp>
+#include <boost/shared_features/feature/container_element.hpp>
+#include <boost/shared_features/feature/container.hpp>
+#include <libs/shared_features/src/example/container_element.h>
+
+void example_feature_container_element(){
+ std::cout
+ << "->example_feature_container_element"
+ << std::endl;
+
+ using namespace boost;
+ namespace shared = shared_features;
+
+ typedef double value_type;
+ typedef std::vector<value_type> vec_t;
+ vec_t vec(3);
+ vec[0] = 0.0;
+ vec[1] = 0.1;
+ vec[2] = 0.2;
+
+ typedef mpl::int_<1> id_1;
+ typedef shared::feature::container<vec_t> feature_cont_t;
+ typedef shared::feature::container_element<feature_cont_t,id_1>
+ feature_elem_1_t;
+
+ typedef shared::set<
+ mpl::vector<feature_elem_1_t>
+ > set_t;
+
+ set_t set;
+
+ set.initialize((
+ shared::kwd<>::container = vec,
+ shared::kwd<id_1>::position = 1
+ ));
+ std::cout
+ << "OK<-"
+ << std::endl;
+
+
+}

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/container_element.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,14 @@
+/////////////////////////////////////////////////////////////////////////////
+// container_element.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_SHARED_FEATURES_FEATURE_CONTAINER_ELEMENT_H_ER_2009
+#define LIBS_SHARED_FEATURES_FEATURE_CONTAINER_ELEMENT_H_ER_2009
+
+void example_feature_container_element();
+
+
+#endif // CONTAINER_ELEMENT_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,60 @@
+/////////////////////////////////////////////////////////////////////////////
+// features.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 <boost/mpl/fold.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/equal.hpp>
+#include <boost/mpl/pop_back.hpp>
+#include <boost/mpl/size.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/type_traits/is_base_and_derived.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/shared_features/mpl_features.hpp>
+#include <boost/shared_features/depends_on.hpp>
+#include <libs/shared_features/src/example/features.h>
+
+void example_features(){
+ std::cout << "-> example_features" << std::endl;
+
+ using namespace boost;
+ namespace mpl = boost::mpl;
+ namespace dep = shared_features;
+
+ typedef dep::depends_on0 x;
+ typedef dep::depends_on1<x> y;
+ typedef mpl::vector<x> vec_x;
+ typedef mpl::vector<y> vec_y;
+
+ typedef dep::detail::insert_feature<
+ mpl::map0<>,
+ vec_x
+ >::type insert_x;
+
+ BOOST_STATIC_ASSERT((
+ mpl::size<insert_x>::value == 1
+ ));
+
+ typedef dep::detail::insert_dependencies<
+ mpl::map0<>, y
+ >::type y_dep;
+
+ BOOST_STATIC_ASSERT((
+ mpl::size<y_dep>::value == 1
+ ));
+
+ typedef mpl::vector<y> explicit_features;
+ typedef dep::detail::features<explicit_features> set;
+ typedef set::vector features_as_vector;
+
+ BOOST_STATIC_ASSERT((
+ mpl::size<features_as_vector>::value == 2
+ ));
+
+ std::cout << "OK<-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/example/features.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+/////////////////////////////////////////////////////////////////////////////
+// features.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 EXAMPLE_FEATURES_H_ER_2009
+#define EXAMPLE_FEATURES_H_ER_2009
+
+void example_features();
+
+#endif

Added: sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/shared_features/libs/shared_features/src/main.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,20 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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 <libs/shared_features/src/example/features.h>
+#include <libs/shared_features/src/example/container_element.h>
+
+using namespace std;
+
+int main()
+{
+
+ example_feature_container_element();
+ example_features();
+
+ return 0;
+}

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/clock.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/clock.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,63 @@
+///////////////////////////////////////////////////////////////////////////////
+// clock.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_GENERATOR_CLOCK_HPP_ER_2009
+#define BOOST_GENERATOR_CLOCK_HPP_ER_2009
+#include <boost/mpl/void.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/generator/keyword.hpp>
+namespace boost{
+namespace generator{
+
+ /// \class clock
+ /// \brief Generates \f$ t, t+\delta, t+2\delta ... \f$
+ template<typename RealType,typename Id = mpl::void_>
+ class clock{
+ typedef kwd<Id> kwd;
+ public:
+ typedef RealType result_type;
+
+ clock(result_type start,result_type delta)
+ :t_(start),delta_(delta){
+
+ }
+
+ template<typename ArgumentPack>
+ clock(const ArgumentPack& args)
+ :t_(args[kwd::clock_start_time|0.0]),
+ delta_(args[kwd::clock_delta_time]){}
+
+ clock(const clock& that)
+ :t_(that.t_),delta_(that.delta_){}
+
+ clock& operator=(const clock& that){
+ if(&that!=this){
+ t_ = that.t_;
+ delta_ = that.delta_;
+ }
+ return *this;
+ }
+
+ result_type operator()(){
+ result_type t = t_;
+ t_+=delta_;
+ return t;
+ }
+
+ result_type delta()const{ return delta_; }
+ result_type start()const{ return t_; }
+
+ private:
+ clock();//dont impl
+ RealType t_;
+ RealType delta_;
+ };
+
+}//generator
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/constant.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/constant.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,43 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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_GENERATOR_CONSTANT_HPP_ER_2009
+#define BOOST_GENERATOR_CONSTANT_HPP_ER_2009
+#include <boost/math/tools/precision.hpp>
+
+namespace boost{
+namespace generator{
+
+ template<typename T>
+ class constant{
+ public:
+ typedef T result_type;
+ constant():x_(T()){}
+ constant(T x): x_(x){}
+
+ T operator()()const{
+ return x_;
+ }
+
+ private:
+ T x_;
+ };
+
+ //Useful as "no censoring"
+ template<typename T>
+ class max_value : public constant<T>{
+ typedef constant<T> super_t;
+ public:
+ max_value(): super_t(math::tools::max_value<T>()){}
+
+ private:
+ max_value(T x);
+ };
+
+
+}
+}
+#endif // CONSTANT_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/cycle_through_shared_containers.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/cycle_through_shared_containers.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,111 @@
+///////////////////////////////////////////////////////////////////////////////
+// cycle_through_shared_containers.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_CYCLE_THROUGH_SHARED_CONTAINERS_HPP_ER_2009
+#define BOOST_CYCLE_THROUGH_SHARED_CONTAINERS_HPP_ER_2009
+#include <algorithm>
+#include <stdexcept>
+#include <vector>
+#include <functional>
+#include <iterator>
+#include <boost/mpl/assert.hpp>
+#include <boost/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/generator/shared_container.hpp>
+#include <boost/generator/keyword.hpp>
+#include <boost/iterator/cycle_iterator.hpp>//in the vault
+namespace boost{
+namespace generator{
+
+ //DODO kwd
+
+ /// \class cycle_through_shared_containers
+ /// \brief Useful for experimenal design (fixed pool of covariates)
+ template<
+ typename Cont = const std::vector<double>,
+ typename Id = mpl::void_
+ >
+ class cycle_through_shared_containers{
+ public:
+ typedef shared_container<Cont> shared_t;
+ typedef std::vector<shared_t> collec_shared_t;
+ private:
+ typedef typename range_size<collec_shared_t>::type size_type;
+ typedef typename
+ range_iterator<collec_shared_t>::type base_iter_t;
+ typedef cycle_iterator<base_iter_t,size_type> cycle_t;
+ public:
+ typedef shared_t result_type;
+
+ template<typename R>
+ cycle_through_shared_containers(const R& r,size_type offset)
+ {
+ set(
+ r,
+ offset
+ );
+ }
+ template<typename ArgumentPack>
+ cycle_through_shared_containers(const ArgumentPack& args)
+ {
+ typedef kwd<Id> kwd;
+ set(
+ args[kwd::range_containers],
+ args[kwd::range_containers_offset]
+ );
+ }
+
+ cycle_through_shared_containers(
+ const cycle_through_shared_containers& that)
+ {
+ set(that.collec_shared_,that.offset());
+ }
+
+ cycle_through_shared_containers&
+ operator=(const cycle_through_shared_containers& that)
+ {
+ if(&that!=this){
+ set(that.collec_shared_,that.offset());
+ }
+ return *this;
+ }
+
+ template<typename R>
+ void set(const R& range_of_ranges,size_type offset = 0){
+ //range_of_ranges either ranges or shared containers;
+ collec_shared_.clear();
+
+ copy(
+ begin(range_of_ranges),
+ end(range_of_ranges),
+ back_inserter(collec_shared_)
+ );
+ cycle_ = make_cycle_iterator(
+ begin(collec_shared_),
+ end(collec_shared_),
+ offset
+ );
+ }
+
+ size_type offset()const { return cycle_.offset(); }
+
+ result_type operator()(){
+ shared_t result = (*cycle_);
+ std::advance(cycle_,1);
+ return result;
+ };
+
+ private:
+ cycle_through_shared_containers();
+ collec_shared_t collec_shared_;
+ cycle_t cycle_;
+ };
+
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/keyword.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,51 @@
+///////////////////////////////////////////////////////////////////////////////
+// keyword.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_GENERATOR_KEYWORD_HPP_ER_2009
+#define BOOST_GENERATOR_KEYWORD_HPP_ER_2009
+
+namespace boost{
+namespace generator{
+namespace tag{
+ template<typename Id> struct clock_start_time_{};
+ template<typename Id> struct clock_delta_time_{};
+ template<typename Id> struct range_containers_{};
+ template<typename Id> struct range_containers_offset_{};
+}
+namespace{
+ template<typename Id = mpl::void_>
+ struct kwd{
+ static ::boost::parameter::keyword<
+ tag::clock_start_time_<Id> >& clock_start_time;
+ static ::boost::parameter::keyword<
+ tag::clock_delta_time_<Id> >& clock_delta_time;
+ static ::boost::parameter::keyword<
+ tag::range_containers_<Id> >& range_containers;
+ static ::boost::parameter::keyword<
+ tag::range_containers_offset_<Id> >&
+ range_containers_offset;
+ };
+ template<typename Id>
+ ::boost::parameter::keyword<tag::clock_start_time_<Id> >&
+ kwd<Id>::clock_start_time =
+ ::boost::parameter::keyword<tag::clock_start_time_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::clock_delta_time_<Id> >&
+ kwd<Id>::clock_delta_time =
+ ::boost::parameter::keyword<tag::clock_delta_time_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::range_containers_<Id> >&
+ kwd<Id>::range_containers =
+ ::boost::parameter::keyword<tag::range_containers_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::range_containers_offset_<Id> >&
+ kwd<Id>::range_containers_offset =
+ ::boost::parameter::keyword<
+ tag::range_containers_offset_<Id> >::get();
+}//anonymous
+}//generator
+}//boost
+#endif // BOOST_GENERATOR_KEYWORD_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/ref.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/ref.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,52 @@
+///////////////////////////////////////////////////////////////////////////////
+// ref.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_GENERATOR_REF_HPP_ER_2009
+#define BOOST_GENERATOR_REF_HPP_ER_2009
+#include <boost/shared_ptr.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+
+namespace boost{
+namespace generator{
+
+ // A generator is likely to contain its own seed
+ // But as_random_distribution makes a copy
+ // hence the need for a ref wrapper
+
+
+ template<typename G>
+ class ref{
+ typedef typename utility::remove_qualifier<G>::type noqual;
+ BOOST_MPL_ASSERT((
+ is_same<G,noqual>
+ ));
+ typedef shared_ptr<G> pimpl_t;
+ public:
+ typedef typename G::result_type result_type;
+
+ ref(pimpl_t g):pimpl_(g){}
+ ref(const ref& that):pimpl_(that.pimpl_){}
+ ref& operator=(const ref& that){
+ if(&that!=this){
+ pimpl_ = that.pimpl_;
+ }
+ return *this;
+ }
+
+ result_type operator()(){
+ return pimpl_->operator()();
+ }
+
+ private:
+ ref();
+ pimpl_t pimpl_;
+ };
+
+
+}
+}
+
+#endif // REF_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/boost/generator/shared_container.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/generator/shared_container.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,67 @@
+///////////////////////////////////////////////////////////////////////////////
+// shared_container.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_SHARED_CONTAINER_HPP_ER2009
+#define BOOST_SHARED_CONTAINER_HPP_ER2009
+#include <algorithm>
+#include <iterator>
+#include <vector>
+#include <boost/range.hpp>
+#include <boost/shared_ptr.hpp>
+//#include <boost/call_traits.hpp>
+
+namespace boost{
+
+ /// \class shared_container
+ /// \brief Pter to a container.
+ ///
+ /// Can be used as a container shared across data units
+ /// (experimentatl design),
+ /// or to make copying a dataset cheap.
+ /// Cont models Back Insertion Sequence
+ template<typename Cont = const std::vector<double> >
+ class shared_container{
+ public:
+ typedef Cont container_type;
+ private:
+ typedef boost::shared_ptr<container_type> pimpl_type;
+ typedef typename range_iterator<container_type>::type iter_type;
+ public:
+ typedef typename range_size<Cont>::type size_type;
+ typedef typename iterator_value<iter_type>::type value_type;
+ typedef const container_type& result_type;
+
+ template<typename R>
+ shared_container(const R& container_)
+ {
+ container_type tmp;
+ copy(
+ begin(container_),
+ end(container_),
+ std::back_inserter(tmp)
+ );
+ pimpl = pimpl_type(new container_type(tmp));
+ }
+ shared_container(const shared_container& that):pimpl(that.pimpl){}
+ shared_container& operator=(const shared_container& that){
+ if(&that!=this){
+ pimpl = that.pimpl;
+ }
+ return *this;
+ }
+ result_type operator()()const{
+ return dereference();
+ }
+ private:
+ result_type dereference()const{
+ return (*pimpl);
+ }
+ pimpl_type pimpl;
+ };
+
+}
+
+#endif // SHARED_CONTAINER_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_distribution.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_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_GENERATOR_AS_RANDOM_DISTRIBUTION_HPP_ER_2009
+#define BOOST_GENERATOR_AS_RANDOM_DISTRIBUTION_HPP_ER_2009
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/mpl/has_xxx.hpp>
+#include <boost/mpl/eval_if.hpp>
+namespace boost{
+
+ BOOST_MPL_HAS_XXX_TRAIT_DEF(input_type);
+
+
+
+ // Maps Generator (or RandomDistribution) to RandomDistribution
+ template<
+ typename G,
+ typename InputType = unsigned long
+ >
+ class as_random_distribution : G{
+ typedef G super_t;
+ typedef has_input_type<super_t> has_it;
+ template<typename T>
+ struct input{
+ typedef typename T::input_type type;
+ };
+ public:
+ typedef typename mpl::eval_if<
+ has_it,
+ input<super_t>,
+ mpl::identity<InputType>
+ >::type input_type;
+ typedef typename super_t::result_type result_type;
+
+ as_random_distribution(const super_t& g)
+ :super_t(g){};
+
+ template<typename Args>
+ as_random_distribution(const Args& args)
+ :super_t(args){};
+
+// //Overload needed, for example, ref<Clock>(Clock&)
+// template<typename Args>
+// as_random_distribution(Args& args)
+// :super_t(args){};
+
+ as_random_distribution(const as_random_distribution& that)
+ :super_t(static_cast<const super_t&>(that)){};
+
+ as_random_distribution&
+ operator=(const as_random_distribution& that){
+ if(&that!=this){
+ super_t::operator=(that);
+ }
+ return *this;
+ }
+
+ template<typename U>
+ result_type
+ operator()(U& u){
+ return impl(typename has_it::type(),u);
+ }
+
+
+ private:
+
+ template <typename U >
+ result_type
+ impl(mpl::bool_<false>,U& u) {
+ return super_t::operator()();
+ }
+
+ template <typename U>
+ result_type
+ impl(mpl::bool_<true>,U& u) {
+ return super_t::operator()(u);
+ }
+};
+
+}//boost
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_regression.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/as_random_regression.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,76 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_regression.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_AS_RANDOM_REGRESSION_HPP_ER_2009
+#define BOOST_AS_RANDOM_REGRESSION_HPP_ER_2009
+
+#include <boost/mpl/bool.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/random_regression/base.hpp>
+namespace boost{
+
+
+ // Maps a RandomDistribution (or RandomRegression) to RandomRegression
+ template<typename RandomDist>
+ class as_random_regression : RandomDist{
+ typedef RandomDist super_t;
+ public:
+
+ typedef typename RandomDist::result_type result_type;
+ typedef typename RandomDist::input_type input_type;
+
+ as_random_regression(const super_t& g)
+ :super_t(g){}
+
+ template<typename Args>
+ as_random_regression(const Args& args)
+ :super_t(args){}
+
+ // template<typename Args>
+ // as_random_regression(Args& args)
+ // :super_t(args){
+ // //No known need, but for consistency w as_random_distribution
+ // }
+
+ as_random_regression(const as_random_regression& that)
+ :super_t(static_cast<const super_t&>(that)){}
+
+ as_random_regression&
+ operator=(const as_random_regression& that){
+ if(&that!=this){
+ super_t::operator=(that);
+ }
+ return *this;
+ }
+
+ template<typename U,typename X>
+ typename super_t::result_type
+ operator()(U& u,const X& x){
+ typedef typename
+ is_base_of<random_regression_base,super_t>::type is;
+ return impl(is(),u,x);
+ }
+
+ private:
+
+ template <typename U,typename X >
+ typename super_t::result_type
+ impl(mpl::bool_<true>,U& u,const X& x) {
+ return super_t::operator()(u,x);
+ }
+
+ template <typename U,typename X >
+ typename super_t::result_type
+ impl(mpl::bool_<false>,U& u,const X& x) {
+ return super_t::operator()(u);
+ }
+
+
+};
+
+}//boost
+#endif
+

Added: sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/base.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/base.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// random_regression_base.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_RANDOM_REGRESSION_BASE_HPP_ER_2009
+#define BOOST_RANDOM_REGRESSION_BASE_HPP_ER_2009
+
+namespace boost{
+
+// Concept RandomRegression
+// Valid expression
+// rr(U& u,const X& x)
+// Associated types:
+// R::input_type
+// R::result_type
+
+struct random_regression_base{
+ // Derive from this base to indicate that models RandomRegression
+};
+
+
+// // Not in use at present
+// template<typename T>
+// struct crtp : base{};
+
+}//boost
+
+#endif // RANDOM_REGRESSION_BASE_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/exponential.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,116 @@
+///////////////////////////////////////////////////////////////////////////////
+// exponential.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_RANDOM_REGRESSION_EXPONENTIAL_HPP_ER_2009
+#define BOOST_RANDOM_REGRESSION_EXPONENTIAL_HPP_ER_2009
+#include <functional>
+#include <algorithm>
+#include <numeric>
+#include <stdexcept>
+#include <cmath>
+#include <boost/assert.hpp>
+#include <boost/format.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/range.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/exponential_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random_regression/keyword.hpp>
+#include <boost/random_regression/base.hpp>
+namespace boost{
+namespace random_regression{
+
+ /// \class exponential
+ /// \brief Simulates \f$ \mathrm{Exponential}(\lambda) \f$, with
+ /// \f$ \lambda = exp(\langle x, coefficients \rangle) \f$
+ template<
+ typename Expon = boost::exponential_distribution<double>,
+ template<typename> class Unif01 = boost::uniform_real,
+ typename Id = mpl::void_
+ >
+ class exponential : random_regression_base{
+ public:
+ typedef typename Expon::result_type result_type;
+ typedef typename Unif01<result_type>::input_type input_type;
+ private:
+ typedef std::vector<result_type> coeffs_type;
+ typedef exponential<Expon,Unif01> this_type;
+ typedef Unif01<result_type> unif01_type;
+ public:
+// template<typename R>
+// exponential(const R& coefficients)
+// {
+// set(coefficients);
+// }
+
+ template<typename ArgumentPack>
+ exponential(const ArgumentPack& args)
+ {
+ set(args[kwd<Id>::coefficients|args]);
+ //in the absence of kwd, args has to be a Range
+ }
+
+ exponential(const exponential& that)
+ {
+ set(that.coefficients_);
+ }
+
+ exponential&
+ operator=(const exponential& that){
+ if(&that!=this){
+ set(that.coefficients_);
+ }
+ return *this;
+ }
+
+ //U models UniformRandomNumberGenerator
+ template<typename U,typename R>
+ result_type
+ operator()(U& urng, const R& covariate){
+ if(size(covariate)!=size(coefficients_)){
+ std::string str = "random_regression::";
+ str+= "exponential(urng,covariate)";
+ str+= " size(covariate) = %1% !=";
+ str+= " size(coefficients) = %2%";
+ format f(str);
+ f % size(covariate) % size(coefficients_);
+ throw std::runtime_error(f.str());
+ }else{
+ result_type log_lambda
+ = std::inner_product(
+ begin(coefficients_),
+ end(coefficients_),
+ begin(covariate),
+ (result_type)(0),
+ std::plus<result_type>(),
+ std::multiplies<result_type>()
+ );
+ typedef boost::variate_generator<U&,unif01_type> gen_t;
+ gen_t gen(urng,unif01_type());
+ result_type num = expon1_(gen);
+ //std::cout << "num/exp(log_lambda)="
+ //<< num/exp(log_lambda) << std::endl;
+ return num/exp(log_lambda);
+ }
+ }
+
+ template<typename R>
+ void set(const R& coefficients){
+ copy(
+ begin(coefficients),
+ end(coefficients),
+ back_inserter(coefficients_)
+ );
+ }
+
+ private:
+ coeffs_type coefficients_;
+ Expon expon1_;
+ };
+}}
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/random_regression/keyword.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,34 @@
+///////////////////////////////////////////////////////////////////////////////
+// keyword.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_SURVIVAL_DATA_RANDOM_KEYWORD_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RANDOM_KEYWORD_HPP_ER_2009
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost{
+namespace random_regression{
+
+namespace tag{
+ template<typename Id> struct coefficients_{};
+}
+
+namespace{
+ template<typename Id>
+ struct kwd{
+ static ::boost::parameter::keyword<
+ tag::coefficients_<Id> >& coefficients;
+ };
+ template<typename Id>
+ ::boost::parameter::keyword<tag::coefficients_<Id> >&
+ kwd<Id>::coefficients =
+ ::boost::parameter::keyword<tag::coefficients_<Id> >::get();
+}
+
+}//random_regression
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/call_event_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/call_event_time.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+// call_event_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_SURVIVAL_DATA_CALL_EVENT_TIME_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_CALL_EVENT_TIME_HPP_ER_2009
+namespace boost{namespace survival_data{
+ template<typename UnitOfObservation>
+ class call_event_time{
+ public:
+ typedef typename UnitOfObservation::value_type result_type;
+ typedef const UnitOfObservation& argument_type;
+ call_event_time(result_type t_):t(t_){};
+ result_type operator()(argument_type d)const{
+ return d.event_time(t);
+ };
+ private:
+ result_type t;
+ };
+}}
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/event_manager.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/event_manager.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,107 @@
+///////////////////////////////////////////////////////////////////////////////
+// event_manager.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_SURVIVAL_DATA_EVENT_MANAGER_ER_2009_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_EVENT_MANAGER_ER_2009_HPP_ER_2009
+#include <stdexcept>
+#include <boost/call_traits.hpp>
+
+namespace boost{namespace survival_data{
+ /// \class event_manager
+ /// \brief Manages event creation/retrieval for a data unit
+ ///
+ /// \details Right censoring
+ template<typename RealType>
+ class event_manager{
+ public:
+ typedef RealType value_type;
+ explicit event_manager(value_type entry_time_arg);
+ event_manager(const event_manager& that);
+ event_manager& operator=(const event_manager& that);
+ /// \details Once an event is set it cannot be changed
+ void set_event(bool is_failure_arg,value_type time_since_entry);
+ value_type entry_time()const;
+ value_type time_on_study(value_type t)const;
+ value_type event_time(value_type t)const;
+ bool is_failure(value_type t)const;
+ bool is_at_risk(value_type s,value_type t)const;
+ private:
+ value_type entry_time_; //on the calendar scaled
+ bool is_failure_;
+ bool is_event_;
+ value_type event_time_; //measured from time of entry
+ };
+
+ template<typename value_type>
+ event_manager<value_type>::event_manager(value_type entry_time_arg)
+ :entry_time_(entry_time_arg),is_failure_(false),is_event_(false){}
+
+ template<typename value_type>
+ event_manager<value_type>::event_manager(const event_manager& that)
+ :entry_time_(that.entry_time_),is_failure_(that.is_failure_),
+ is_event_(that.is_event_),event_time_(that.event_time_){}
+
+ template<typename value_type>
+ event_manager<value_type>&
+ event_manager<value_type>::operator=(const event_manager& that){
+ if(&that!=this){
+ entry_time_ = that.entry_time_;
+ is_failure_ = that.is_failure_;
+ is_event_ = that.is_event_;
+ event_time_ = that.event_time_;}
+ return *this;
+ }
+
+ template<typename value_type>
+ value_type event_manager<value_type>::entry_time()const{
+ return entry_time_;}
+
+ template<typename value_type>
+ void event_manager<value_type>::set_event(
+ bool is_failure,value_type time_since_entry){
+ if(is_event_){
+ throw std::runtime_error(
+ "Surv::event_manager<value_type>::set_event");
+ }else{
+ is_failure_ = is_failure;
+ event_time_ = time_since_entry;
+ is_event_ = true;
+ };
+ }
+
+ template<typename value_type>
+ value_type event_manager<value_type>::time_on_study(value_type t)const{
+ value_type x = t-entry_time();
+ return (x<0.0)? 0.0 : x;
+ }
+
+ template<typename value_type>
+ value_type event_manager<value_type>::event_time(value_type t)const{
+ value_type tos = time_on_study(t);
+ if(is_event_){
+ tos = (tos<event_time_)? tos : event_time_;
+ }
+ return tos;
+ }
+
+ template<typename value_type>
+ bool event_manager<value_type>::is_failure(value_type t)const{
+ bool is_failure_at_time_t = false;
+ if(is_failure_){
+ if(event_time_<time_on_study(t)){
+ is_failure_at_time_t = true;
+ }
+ }
+ return is_failure_at_time_t;
+ }
+
+ template<typename value_type>
+ bool event_manager<value_type>::is_at_risk(
+ value_type s,value_type t)const{
+ return (s<=event_time(t));}
+
+}}
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,99 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival_data::generate.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_SURVIVAL_DATA_GENERATE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_GENERATE_HPP_ER_2009
+#include <vector>
+#include <boost/random_regression/as_random_distribution.hpp>
+#include <boost/survival_data/generate_given_entry_time_covariate.hpp>
+#include <boost/survival_data/unit.hpp>
+namespace boost{
+namespace survival_data{
+ /// \class generate
+ /// \brief Generates survival data units
+ ///
+ /// Models RandomDistribution
+ /// Clock models RandomDistribution or Generator
+ /// Cov models RandomDistribution or Generator
+ /// Fail models RandomRegression or RandomDistribution
+ /// Cens models RandomRegression or RandomDistribution
+ template<
+ typename Clock,typename Cov,typename Fail,typename Cens,
+ template<typename,typename> class Cont = std::vector,
+ template<typename> class Alloc = std::allocator
+ >
+ class generate{
+ typedef generate_given_entry_time_covariate<
+ as_random_regression<Fail>,
+ as_random_regression<Cens>,
+ Cont,
+ Alloc
+ > impl_type;
+
+ public:
+ typedef typename impl_type::input_type input_type;
+ typedef typename impl_type::result_type result_type;
+ private:
+ typedef as_random_distribution<Clock,input_type> as_r_clock_t;
+ public:
+ template<typename ArgumentPack>
+ generate(const ArgumentPack& args)
+ :clock_(args),
+ gen_cov_(args),
+ impl_(args){}
+
+ template<
+ typename ClockArg,
+ typename CovArg,
+ typename FailArg,
+ typename CensArg
+ >
+ generate(
+ //If Clock = ref<Clock0>, pass Clock, not Clock0
+ const ClockArg& a0,
+ const CovArg& a1,
+ const FailArg& a2,
+ const CensArg& a3
+ ) //no const intentional
+ :clock_(a0),
+ gen_cov_(a1),
+ impl_(a2,a3){}
+
+ generate(const generate& that)
+ :clock_(that.clock_),
+ gen_cov_(that.gen_cov_),
+ impl_(that.impl_){}
+
+ generate&
+ operator=(const generate& that){
+ if(&that!=this){
+ clock_ = that.clock_;
+ gen_cov_ = that.gen_cov_;
+ impl_ = that.impl;
+ }
+ return *this;
+ }
+ template<typename U>
+ result_type operator()(U& urng){
+ return impl_(
+ urng,
+ clock_(urng),
+ gen_cov_(urng)
+ );
+ }
+
+ const as_r_clock_t& clock()const{ return clock_; }
+
+ private:
+ as_r_clock_t clock_;
+ as_random_distribution<Cov,input_type> gen_cov_;
+ impl_type impl_;
+ };
+
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_fixed_design_no_censoring.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_fixed_design_no_censoring.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,121 @@
+///////////////////////////////////////////////////////////////////////////////
+// generate_fixed_design_no_censoring.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_SURVIVAL_DATA_GENERATE_FIXED_DESIGN_NO_CENSORING_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_GENERATE_FIXED_DESIGN_NO_CENSORING_HPP_ER_2009
+#include <vector>
+#include <boost/shared_ptr.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/exponential_distribution.hpp>
+#include <boost/generator/clock.hpp>
+#include <boost/generator/constant.hpp>
+#include <boost/generator/cycle_through_shared_containers.hpp>
+#include <boost/generator/keyword.hpp>
+#include <boost/random_regression/as_random_distribution.hpp>
+#include <boost/random_regression/as_random_regression.hpp>
+#include <boost/random_regression/exponential.hpp>
+#include <boost/survival_data/generate.hpp>
+namespace boost{
+namespace survival_data{
+
+ template<typename ResultType,typename Id>
+ struct default_fail{
+ typedef exponential_distribution<ResultType> exp_t;
+ // Only meant to illustrate (possible) use of id
+ typedef random_regression::exponential<
+ exp_t,
+ uniform_real,
+ Id
+ > type;
+ };
+ template<typename Fail = default_fail<double,mpl::void_>::type >
+ class generate_fixed_design_no_censoring{
+ public:
+ typedef typename Fail::input_type input_type;
+ private:
+ typedef typename Fail::result_type value_type;
+
+ typedef std::vector<value_type> cont_t;
+ typedef generator::clock<value_type> clock_type;
+ typedef generator::ref<clock_type> ref_clock_type;
+ typedef generator::cycle_through_shared_containers<cont_t>
+ gen_cov_t;
+ typedef generator::max_value<value_type> cens0_t;
+ typedef as_random_distribution<cens0_t,input_type> gen_cens_t;
+
+ typedef generate<
+ ref_clock_type, //important to have ref if stop and go
+ gen_cov_t,
+ Fail,
+ gen_cens_t
+ > impl_t;
+ public:
+ typedef typename impl_t::result_type result_type;
+
+// template<
+// typename ClockArg,
+// typename CovArg,
+// typename FailArg
+// >
+// generate_fixed_design_no_censoring(
+// const ClockArg& a0,
+// const CovArg& a1,
+// const FailArg& a2
+// ):impl_(a0,a1,a2,cens0_t()){}
+
+ template<typename Design,typename FailArg>
+ generate_fixed_design_no_censoring(
+ value_type start_time,
+ value_type delta_time,
+ const Design& design, // e.g. std::vector<range_covariate_t>
+ const FailArg& fail_args
+ ):impl_(
+ make_ref_clock(start_time,delta_time),
+ gen_cov_t(
+ design,
+ 0
+ ),
+ fail_args,
+ cens0_t()
+ ){
+ }
+
+ generate_fixed_design_no_censoring(
+ const generate_fixed_design_no_censoring& that
+ ):impl_(that.impl_){}
+
+ generate_fixed_design_no_censoring&
+ operator=(
+ const generate_fixed_design_no_censoring& that
+ ){
+ if(&that!=this){
+ impl_ = that.impl_;
+ }
+ return *this;
+ }
+ template<typename U>
+ result_type operator()(U& u){
+ return impl_(u);
+ }
+
+ private:
+ generate_fixed_design_no_censoring();
+ ref_clock_type
+ make_ref_clock(value_type start,value_type delta){
+ typedef shared_ptr<clock_type> s_t;
+ s_t s(new clock_type(start,delta));
+ ref_clock_type ref_clock(s);
+
+ return ref_clock;
+ }
+ impl_t impl_;
+ };
+
+}//survival_data
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_given_entry_time_covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/generate_given_entry_time_covariate.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,85 @@
+///////////////////////////////////////////////////////////////////////////////
+// generate_given_entry_time_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_SURVIVAL_DATA_RANDOM_FAILURE_CENSORING_HPP_ER_2009_
+#define BOOST_SURVIVAL_DATA_RANDOM_FAILURE_CENSORING_HPP_ER_2009_
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <vector>
+#include <memory>
+#include <boost/survival_data/unit.hpp>
+namespace boost{
+namespace survival_data{
+
+ /// \class data unit
+ /// \brief Generates survival data units
+ ///
+ /// \param F (failure) models RandomRegression
+ /// \param Ce (censoring) models RandomRegression
+ template<
+ typename F,
+ typename Ce,
+ template<typename,typename> class Cont = std::vector,
+ template<typename> class Alloc = std::allocator
+ >
+ class generate_given_entry_time_covariate{
+ public:
+ typedef typename F::result_type value_type;
+ typedef typename F::input_type input_type;
+ BOOST_MPL_ASSERT((is_same<value_type,typename Ce::result_type>));
+ BOOST_MPL_ASSERT((is_same<input_type,typename Ce::input_type>));
+ private:
+ typedef Alloc<value_type> alloc_t;
+ typedef Cont<value_type,alloc_t> cont_t;
+ public:
+
+ typedef unit<cont_t> result_type;
+
+ template<typename ArgumentPack>
+ generate_given_entry_time_covariate(const ArgumentPack& args)
+ :failure_(args),censoring_(args){}
+
+ template<typename A0,typename A1>
+ generate_given_entry_time_covariate(const A0& a0,const A1& a1)
+ :failure_(a0),censoring_(a1){}
+
+ generate_given_entry_time_covariate(
+ const generate_given_entry_time_covariate& that)
+ :failure_(that.failure_),censoring_(that.censoring_){}
+
+ generate_given_entry_time_covariate&
+ operator=(const generate_given_entry_time_covariate& that){
+ if(&that!=this){
+ failure_ = that.failure_;
+ censoring_ = that.censoring_;
+ }
+ return *this;
+ }
+ template<typename U,typename R>
+ result_type
+ operator()(
+ U& urng,
+ value_type entry_time,
+ const R& covariate
+ ){
+
+ result_type unit(entry_time,covariate);
+ value_type f = failure_(urng,unit.covariate());
+ value_type c = censoring_(urng,unit.covariate());
+ bool is_f = (f<c) ? f : c;
+ value_type t = c; if(is_f){ t = f; }
+ unit.set_event(is_f,t);
+ return unit;
+ }
+ private:
+ F failure_;
+ Ce censoring_;
+ };
+
+}
+}
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/include.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// 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_SURVIVAL_DATA_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/generator/constant.hpp>
+#include <boost/generator/clock.hpp>
+#include <boost/generator/cycle_through_shared_containers.hpp>
+#include <boost/generator/ref.hpp>
+#include <boost/generator/shared_container.hpp>
+
+#include <boost/random_regression/as_random_distribution.hpp>
+#include <boost/random_regression/as_random_regression.hpp>
+#include <boost/random_regression/base.hpp>
+#include <boost/random_regression/exponential.hpp>
+#include <boost/random_regression/keyword.hpp>
+
+#include <boost/survival_data/transform_if_to_unit_at_time.hpp>
+#include <boost/survival_data/generate.hpp>
+#include <boost/survival_data/generate_fixed_design_no_censoring.hpp>
+#include <boost/survival_data/keyword.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/survival_data/unit_at_time.hpp>
+#include <boost/survival_data/stream_to_dataset.hpp>
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/keyword.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/keyword.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,60 @@
+///////////////////////////////////////////////////////////////////////////////
+// keyword.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_SURVIVAL_DATA_KEYWORD_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_KEYWORD_HPP_ER_2009
+#include <boost/mpl/void.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+
+namespace boost{
+namespace survival_data{
+namespace tag{
+ template<typename Id> struct covariate_{};
+ template<typename Id> struct entry_time_{};
+ template<typename Id> struct unit_{};
+ template<typename Id> struct unit_at_time_{};
+ template<typename Id> struct time_analysis_{};
+}
+namespace{
+ template<typename Id = mpl::void_>
+ struct kwd{
+ static ::boost::parameter::keyword<tag::
+ unit_<Id> >& unit;
+ static ::boost::parameter::keyword<tag::
+ unit_at_time_<Id> >& unit_at_time;
+ static ::boost::parameter::keyword<tag::
+ time_analysis_<Id> >& time_analysis;
+ static ::boost::parameter::keyword<tag::
+ entry_time_<Id> >& entry_time;
+ static ::boost::parameter::keyword<tag::
+ covariate_<Id> >& covariate;
+ };
+ template<typename Id>
+ ::boost::parameter::keyword<tag::unit_<Id> >&
+ kwd<Id>::unit =
+ ::boost::parameter::keyword<tag::unit_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::unit_at_time_<Id> >&
+ kwd<Id>::unit_at_time =
+ ::boost::parameter::keyword<tag::unit_at_time_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::time_analysis_<Id> >&
+ kwd<Id>::time_analysis =
+ ::boost::parameter::keyword<tag::time_analysis_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::entry_time_<Id> >&
+ kwd<Id>::entry_time =
+ ::boost::parameter::keyword<tag::entry_time_<Id> >::get();
+ template<typename Id>
+ ::boost::parameter::keyword<tag::covariate_<Id> >&
+ kwd<Id>::covariate =
+ ::boost::parameter::keyword<tag::covariate_<Id> >::get();
+}//anonymous
+}//survival_data
+}//boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/parser.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/parser.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// parser.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_SURVIVAL_DATA_MAKE_UNIT_OF_OBSERVATION_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_MAKE_UNIT_OF_OBSERVATION_HPP_ER_2009
+#include <stdexcept>
+#include <algorithm>
+#include <iterator>
+#include <functional>
+#include <vector>
+#include <istream>
+#include <string>
+#include <sstream>
+#include <boost/bind.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/numeric/conversion/cast.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace survival_data{
+
+ template<typename Observation,typename StringType>
+ Observation
+ parser(typename call_traits<StringType>::param_type line){
+ typedef Observation unit_obs_type;
+ typedef typename
+ unit_obs_type::result_of_covariate tmp;
+ typedef typename tmp::type covariate_result_type;
+ typedef typename remove_const<
+ covariate_result_type>::type covariate_type;
+ typedef typename unit_obs_type::value_type value_type;
+ typedef std::vector<StringType> buffer_type;
+ typedef std::vector<value_type> local_covariate_type;
+
+ buffer_type buffer;
+ local_covariate_type covariate;
+
+ std::istringstream ss(line);
+ StringType field; std::getline(ss,field,',');
+ value_type entry_time = boost::lexical_cast<value_type>(field);
+
+ buffer.clear();
+ unit_obs_type unit_obs(0.0,covariate);
+ while(std::getline(ss,field,',')){buffer.push_back(field);}
+ if(buffer.size()>2){
+ unsigned int K = buffer.size()-2;
+ transform(
+ buffer.begin(),
+ buffer.end(),
+ back_inserter(covariate),
+ boost::bind(
+ &boost::lexical_cast<
+ value_type,typename buffer_type::value_type>,
+ _1
+ )
+ );
+
+ bool is_failure = boost::lexical_cast<bool>(buffer[K]);//defective
+
+ value_type event_time =
+ boost::lexical_cast<value_type>(buffer[K+1]);
+ unit_obs = unit_obs_type(entry_time,covariate);//assignement
+ unit_obs.set_event(is_failure,event_time);
+ }else{
+ std::runtime_error("boost::stat::survival::make_data_unit");
+ }
+ return unit_obs;
+ };
+
+}//survival_data
+}//boost
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/stream_to_dataset.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/stream_to_dataset.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,62 @@
+///////////////////////////////////////////////////////////////////////////////
+// stream_to_dataset.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_SURVIVAL_DATA_FILL_DATASET_FROM_STREAM_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_FILL_DATASET_FROM_STREAM_HPP_ER_2009
+#include <istream>
+#include <string>
+#include <sstream>
+#include <boost/range.hpp>
+#include <boost/utility/remove_qualifier.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/survival_data/parser.hpp>
+namespace boost{
+namespace survival_data{
+
+ /// \class read_from_stream
+ /// \brief Reads a survival dataset from a stream
+ class stream_to_dataset{
+ public:
+ /// \param Dataset Back Insertion Sequence
+ /// \param is and input stream with each satisfying
+ /// the format shown between the arrows below: \n
+ /// ->entry_time, x_0, . . . x_{J-1}, is_failure, event_time<-\n
+ /// where
+ /// - entry_time is in \c Real_type or <tt> unsigned int </tt> format
+ /// - x_j is in \c Real_type or <tt> int </tt> format
+ /// - is_failure takes values is in \f$\{0,1\}\f$
+ /// - event_time is in \c Real_type or <tt> unsigned int </tt> format
+ ///
+ /// Here's how the data should be formatted for the
+ /// <a href="http://www.mathstat.helsinki.fi/openbugs/Examples/Mice.html">
+ /// mice data </a>
+ /// (showing observations 28 and 29):\n
+ /// ...\n
+ /// 0,0,1,0,0,0,40\n
+ /// 0,0,1,0,0,1,25\n
+ /// ...\n
+ template<typename Dataset>
+ static void fill(
+ std::istream& is,
+ Dataset& dataset
+ ){
+ typedef typename utility::remove_qualifier<
+ typename range_value<Dataset>::type
+ >::type unit_t;
+
+ std::string line;
+ //TODO exception handling
+ while(std::getline(is,line) ){
+ dataset.push_back(parser<unit_t,std::string>(line));
+ }
+ }
+ };
+
+}//survival_data
+}//boost
+
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/transform_if_to_unit_at_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/transform_if_to_unit_at_time.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,94 @@
+///////////////////////////////////////////////////////////////////////////////
+// transform_if_to_unit_at_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_SURVIVAL_DATA_DATASET_AT_TIME_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_DATASET_AT_TIME_HPP_ER_2009
+#include <algorithm>
+#include <vector>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/iterator/filter_iterator.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/survival_data/unit_at_time.hpp>
+namespace boost{
+namespace survival_data{
+
+ template<typename Unit>
+ class predicate{
+ typedef Unit unit_t;
+ public:
+ typedef typename unit_t::value_type value_type;
+ typedef bool result_type;
+ typedef const Unit& argument_type;
+ predicate(value_type t):t_(t){}
+ predicate(const predicate& that):t_(that.t_){}
+ predicate& operator=(const predicate& that){
+ if(&that!=this){
+ t_ = that.t_;
+ }
+ return *this;
+ }
+ result_type operator()(argument_type arg){
+ return (arg.entry_time()<=t_);
+ }
+ value_type t_;
+ };
+
+ template<typename Unit>
+ class factory{
+ typedef Unit unit_t;
+ public:
+ typedef typename unit_t::value_type value_type;
+ typedef unit_at_time<unit_t> result_type;
+ typedef const Unit& argument_type;
+
+ public:
+ factory(value_type t): time_analysis_(t){}
+
+ result_type operator()(argument_type u)const{
+ return result_type(u,time_analysis_);
+ }
+
+ private:
+ factory();
+ value_type time_analysis_;
+ };
+
+template<typename InputIter,typename OutputIter>
+OutputIter
+transform_if_to_unit_at_time(
+ InputIter b,
+ InputIter e,
+ OutputIter out,
+ typename factory<typename iterator_value<InputIter>::type>::value_type
+ time_analysis
+)
+{
+ typedef typename iterator_value<InputIter>::type unit_t;
+ typedef predicate<unit_t> pred_t;
+ typedef factory<unit_t> fact_t;
+
+ return std::transform(
+ boost::make_filter_iterator(
+ pred_t(time_analysis),
+ b,
+ e
+ ),
+ boost::make_filter_iterator(
+ pred_t(time_analysis),
+ e,
+ e
+ ),
+ out,
+ fact_t(time_analysis)
+ );
+}
+
+}// survival_data
+}// boost
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,189 @@
+///////////////////////////////////////////////////////////////////////////////
+// unit.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_SURVIVAL_DATA_UNIT_OF_OBSERVATION_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_UNIT_OF_OBSERVATION_HPP_ER_2009
+#include <vector>
+#include <string>
+#include <iterator>
+#include <boost/mpl/identity.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/format.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/utility/container_to_string.hpp>
+#include <boost/generator/shared_container.hpp>
+#include <boost/survival_data/event_manager.hpp>
+#include <boost/survival_data/keyword.hpp>
+namespace boost{
+namespace survival_data{
+
+ // see home/er/cpp/libs/stat/doc/covariate
+
+ template<typename Cont,typename Id>
+ struct unit_base{
+ typedef Cont cont_t;
+ typedef shared_container<Cont> shared_t;
+ typedef typename shared_t::size_type size_type;
+ typedef typename shared_t::value_type value_type;
+
+ struct identifier : mpl::identity<Id>{};
+ struct result_of_covariate
+ : mpl::identity<typename shared_t::result_type>
+ {};
+ // TODO see range_covariate() in derived
+ struct result_of_range_covariate
+ : result_of_covariate
+ {};
+ };
+
+ /// \class unit
+ /// \brief Staggered entry, right censored, fixed covariate
+ ///
+ /// Event state (before/after event) is shared across copies.
+ /// \param Cont models Back Insertion Sequence
+ template<typename Cont = std::vector<double,std::allocator<double> >,
+ typename Id = mpl::void_>
+ class unit : public unit_base<Cont,Id>{
+ typedef unit_base<Cont,Id> super_t;
+ typedef event_manager<typename super_t::value_type>
+ event_manager_type;
+ typedef boost::shared_ptr<event_manager_type>
+ ptr_event_manager_type;
+ protected:
+ typedef kwd<Id> kwd;
+ public:
+ typedef typename super_t::value_type value_type;
+ template<typename ArgPack>
+ unit(const ArgPack& args);
+ template<class R>
+ unit(value_type entry_time,const R& covariate);
+ unit(const unit&);
+ unit& operator=(const unit&);
+
+ /// \details Once set event cannot be changed
+ /// \warning If multiple clients have a copy of this
+ /// data unit, make sure the event has already been set.
+ void set_event(bool is_failure_,value_type time_since_entry);
+ value_type entry_time()const;
+ value_type time_on_study(value_type t)const;
+ value_type event_time(value_type t)const;
+ bool is_failure(value_type t)const;
+ bool is_at_risk(value_type s,value_type t)const;
+
+ typename super_t::result_of_covariate::type
+ covariate()const{
+ return shared_covariate_();
+ }
+ //TODO as needed by conditionally_specified_distribution
+ // redundant with covariate(). Maybe remove covariate()
+ typename super_t::result_of_range_covariate::type
+ range_covariate()const{
+ return this->covariate();
+ }
+ std::string as_string(value_type t)const;
+ private:
+ /// Pointers because a data unit may be part of a large dataset,
+ /// that maybe embeded in multiple clients
+ ptr_event_manager_type ptr_event_manager;
+ typename super_t::shared_t shared_covariate_;
+ };
+
+ template<typename Cont,typename Id>
+ template<typename ArgPack>
+ unit<Cont,Id>::unit(const ArgPack& args)
+ :ptr_event_manager(new event_manager_type(kwd::entry_time)),
+ shared_covariate_(args[kwd::covariate])
+ {}
+
+ template<typename Cont,typename Id>
+ template<class R>
+ unit<Cont,Id>::unit(
+ value_type entry_time_,
+ const R& r
+ )
+ :ptr_event_manager(new event_manager_type(entry_time_)),
+ shared_covariate_(r)
+ {}
+
+ template<typename Cont,typename Id>
+ unit<Cont,Id>::unit(const unit& that)
+ :ptr_event_manager(that.ptr_event_manager),
+ shared_covariate_(that.shared_covariate_)
+ {}
+
+ template<typename Cont,typename Id>
+ unit<Cont,Id>&
+ unit<Cont,Id>::operator=(const unit& that){
+ if(&that!=this){
+ ptr_event_manager = that.ptr_event_manager;
+ shared_covariate_ = that.shared_covariate_;
+ }
+ return *this;
+ }
+
+ template<typename Cont,typename Id>
+ void unit<Cont,Id>::set_event(
+ bool is_failure_,value_type time_since_entry){
+ ptr_event_manager->set_event(is_failure_,time_since_entry);
+ }
+
+ template<typename Cont,typename Id>
+ typename unit<Cont,Id>::value_type
+ unit<Cont,Id>::entry_time()const{
+ return ptr_event_manager->entry_time();
+ }
+
+ template<typename Cont,typename Id>
+ typename unit<Cont,Id>::value_type
+ unit<Cont,Id>::time_on_study(value_type t)const{
+ return ptr_event_manager->time_on_study(t);
+ }
+
+ template<typename Cont,typename Id>
+ typename unit<Cont,Id>::value_type
+ unit<Cont,Id>::event_time(value_type t)const{
+ return ptr_event_manager->event_time(t);
+ }
+
+ template<typename Cont,typename Id>
+ bool unit<Cont,Id>::is_failure(value_type t)const{
+ return ptr_event_manager->is_failure(t);
+ }
+
+ template<typename Cont,typename Id>
+ bool unit<Cont,Id>::is_at_risk(
+ value_type s,value_type t
+ )const{
+ return ptr_event_manager->is_at_risk(s,t);
+ }
+
+ template<typename Cont,typename Id>
+ std::string
+ unit<Cont,Id>::as_string(value_type t)const{
+ typedef utility::container_to_string cont_to_str_t;
+ std::string str = "[at t = %1%\n";
+ str+= "entry_time : %2%\n";
+ str+= "range_covariate : %3%\n";
+ str+= "time_on_study(t) : %4%\n";
+ str+= "event_time(t) : %5%\n";
+ str+= "is_failure(t) : %6%]";
+ format f(str);
+ f%t;
+ f%entry_time();
+ f%cont_to_str_t::get_indexed(range_covariate());
+ f%time_on_study(t);
+ f%event_time(t);
+ std::string str_b= "false";
+ if(this->is_failure(t)){ str_b = "true"; }
+ f%str_b;
+ return f.str();
+ }
+
+
+}//survival_data
+}//boost
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit_at_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/boost/survival_data/unit_at_time.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// unit_at_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_SURVIVAL_DATA_UNIT_OBSERVED_AT_TIME_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_UNIT_OBSERVED_AT_TIME_HPP_ER_2009
+#include <vector>
+#include <iterator>
+#include <string>
+#include <boost/call_traits.hpp>
+#include <boost/mpl/void.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/survival_data/keyword.hpp>
+#include <boost/survival_data/unit.hpp>
+namespace boost{namespace survival_data{
+ // see home/er/cpp/libs/stat/doc/covariate
+
+ /// \class unit_at_time
+ /// \brief Staggered entry, right censored, fixed covariate
+ ///
+ /// Event state (before/after event) is shared across copies.
+ /// \param Cont models Back Insertion Sequence
+ template<typename Unit>
+ class unit_at_time : public Unit
+ //TODO ideally only the base class is public, rest is private
+ {
+ typedef Unit super_t;
+ typedef typename super_t::kwd kwd;
+ public:
+
+ template<typename ArgPack>
+ unit_at_time(const ArgPack& args)
+ :super_t(args),
+ time_analysis_(args[kwd::time_analysis]){}
+
+ unit_at_time(
+ const super_t& impl,
+ typename super_t::value_type time_analysis
+ ):super_t(impl),
+ time_analysis_(time_analysis){}
+
+ unit_at_time&
+ operator=(const unit_at_time& that){
+ if(&that!=this){
+ super_t::operator=(that);
+ time_analysis_ = that.time_analysis_;
+ }
+ return *this;
+ }
+
+ //Beware that the base interface is still here
+ //Below overlaods but does not override
+ typename super_t::value_type
+ time_on_study()const{ return super_t::time_on_study(t()); }
+ typename super_t::value_type
+ event_time()const{ return super_t::event_time(t()); }
+ bool is_failure()const{ return super_t::is_failure(t()); }
+ bool is_at_risk(typename super_t::value_type s)const{
+ return super_t::is_at_risk(s,t());
+ }
+ typename super_t::value_type
+ time_analysis()const{ return t(); }
+
+ std::string
+ as_string()const{
+ return super_t::as_string(t());
+ }
+
+ private:
+ typename super_t::value_type t()const{ return time_analysis_; }
+ typename super_t::value_type time_analysis_;
+ };
+
+}}
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_distribution.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 <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/normal_distribution.hpp>
+
+#include <boost/generator/clock.hpp>
+#include <boost/generator/ref.hpp>
+#include <boost/random_regression/as_random_distribution.hpp>
+
+
+void example_as_random_distribution(){
+ std::cout << "->example_as_random_distribution" << std::endl;
+
+ using namespace boost;
+ namespace gen = boost::generator;
+ namespace ran = boost::random;
+ typedef double value_type;
+ typedef boost::mt19937 urng_t;
+ typedef urng_t::result_type input_t;
+ typedef gen::clock<value_type> clock_t;
+ typedef as_random_distribution<clock_t,input_t> as_r_clock_t;
+ typedef gen::ref<clock_t> ref_clock_t;
+ typedef as_random_distribution<ref_clock_t> as_r_ref_clock_t;
+
+ typedef boost::mt19937 urng_t;
+ typedef uniform_real<value_type> unif_t;
+ typedef variate_generator<urng_t&,as_r_clock_t> gen_clock_t;
+ typedef variate_generator<urng_t&,as_r_ref_clock_t> gen_ref_clock_t;
+ //TODO :
+ typedef variate_generator<urng_t&,unif_t> gen_unif_t;
+
+ const value_type start = 1.0;
+ const value_type delta = 0.1;
+ const unsigned n = 10;
+ const unsigned seed = 0;
+
+ as_r_clock_t as_r_clock((
+ gen::kwd<>::clock_start_time = start,
+ gen::kwd<>::clock_delta_time = delta
+ ));
+ clock_t clock((
+ gen::kwd<>::clock_start_time = start,
+ gen::kwd<>::clock_delta_time = delta
+ ));
+ ref_clock_t ref_clock(shared_ptr<clock_t>(new clock_t(clock)));
+
+
+ typedef std::vector<value_type> vec_t;
+ vec_t vec;
+
+ urng_t urng((urng_t)(seed));
+ gen_clock_t gen_clock(urng,as_r_clock);
+ gen_ref_clock_t gen_ref_clock(urng,as_r_ref_clock_t(ref_clock));
+
+ std::generate_n(back_inserter(vec),n,gen_ref_clock);
+ vec.clear();
+ std::generate_n(back_inserter(vec),n,gen_clock);
+
+ value_type zero = ((value_type)(n-1))*delta + start;
+ zero -= vec.back();
+
+ BOOST_ASSERT(
+ ( zero < 1e-10 ) && ( zero > -1e-10 )
+ );
+
+ vec.clear();
+ std::generate_n(back_inserter(vec),n,gen_clock);
+
+ zero = ((value_type)(n-1))*delta + start;
+ zero -= vec.back();
+
+ BOOST_ASSERT(
+ ( zero < 1e-10 ) && ( zero > -1e-10 )
+ );
+
+ copy(
+ begin(vec),
+ end(vec),
+ std::ostream_iterator<value_type>(std::cout," ")
+ ); std::cout << std::endl;
+
+ vec.clear();
+ std::generate_n(back_inserter(vec),n,gen_ref_clock);
+
+ zero = ((value_type)(2 * n-1))*delta + start;
+ zero -= vec.back();
+
+ BOOST_ASSERT(
+ ( zero < 1e-10 ) && ( zero > -1e-10 )
+ );
+
+ copy(
+ begin(vec),
+ end(vec),
+ std::ostream_iterator<value_type>(std::cout," ")
+ ); std::cout << std::endl;
+
+ std::cout << " <-" << std::endl;
+}

Added: sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_distribution.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_distribution.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_RANDOM_REGRESSION_AS_RANDOM_DISTRIBUTION_H_ER_2009
+#define LIBS_RANDOM_REGRESSION_AS_RANDOM_DISTRIBUTION_H_ER_2009
+#include <boost/random_regression/as_random_distribution.hpp>
+void example_as_random_distribution();
+
+#endif // AS_RANDOM_DISTIRBUTION_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,78 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_regression.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 <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/normal_distribution.hpp>
+
+#include <boost/generator/clock.hpp>
+#include <boost/generator/ref.hpp>
+#include <boost/random_regression/as_random_distribution.hpp>
+#include <boost/random_regression/as_random_regression.hpp>
+
+
+void example_as_random_regression(){
+ std::cout << "->example_as_random_regression" << std::endl;
+
+ using namespace boost;
+ namespace gen = boost::generator;
+ namespace ran = boost::random;
+ typedef double value_type;
+
+ typedef boost::mt19937 urng_t;
+ typedef uniform_real<value_type> unif_t;
+ typedef urng_t::result_type input_t;
+ typedef std::vector<value_type> vec_t;
+ typedef gen::clock<value_type> clock_t;
+ typedef as_random_distribution<clock_t,input_t> as_rdist_clock_t;
+ typedef as_random_regression<as_rdist_clock_t> as_reg_clock_t;
+
+ const value_type start = 1.0;
+ const value_type delta = 0.1;
+ const unsigned n = 10;
+ const unsigned seed = 0;
+
+ as_rdist_clock_t as_rdist_clock((
+ gen::kwd<>::clock_start_time = start,
+ gen::kwd<>::clock_delta_time = delta
+ ));
+ as_reg_clock_t as_reg_clock(
+ as_rdist_clock
+ );
+
+ vec_t x(3);
+ x[0] = 0.0;
+ x[1] = 0.1;
+ x[2] = 0.2;
+ urng_t urng((urng_t)(seed));
+
+ vec_t draws;
+ for(unsigned i =0; i< n; ++i){
+ value_type y = as_reg_clock(urng,x);
+ draws.push_back(y);
+ }
+
+ value_type zero = ((value_type)(n-1))*delta + start;
+ zero -= draws.back();
+
+ BOOST_ASSERT(
+ ( zero < 1e-10 ) && ( zero > -1e-10 )
+ );
+
+ copy(
+ begin(draws),
+ end(draws),
+ std::ostream_iterator<value_type>(std::cout," ")
+ ); std::cout << std::endl;
+
+
+ std::cout << " <-" << std::endl;
+}

Added: sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/random_regression/src/example/as_random_regression.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+///////////////////////////////////////////////////////////////////////////////
+// as_random_regression.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_GENERATOR_AS_RANDOM_REGRESSION_H_ER_2009
+#define LIBS_GENERATOR_AS_RANDOM_REGRESSION_H_ER_2009
+
+void example_as_random_regression();
+
+#endif // AS_RANDOM_REGRESSION_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/doc/readme.txt 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,182 @@
+/////////////////////////////////////////////////////////////////////////////
+// survival_data
+//
+// 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)
+/////////////////////////////////////////////////////////////////////////////
+
+///////////
+/ Contact /
+///////////
+
+Please send suggestions or questions to erwann.rogard_at_[hidden]
+
+////////////////
+/ Requirements /
+////////////////
+
+Compiles fine under
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+The compiler search path must include
+boost_1_37_0
+sandbox/conditionally_specified_distribution/survival_data
+sandbox/conditionally_specified_distribution/utility
+The folder that contains
+ iterator/cycle_iterator.hpp
+(currently in the Vault).
+////////////
+/ Overview /
+////////////
+
+This library provides C++ classes for managing and generating survival data
+(staggered entry, right censored, fixed covariate).
+
+Files:
+unit.hpp a data-unit
+unit_at_time.hpp a data-unit analysed at time t
+transform_if_to_unit_at_time.hpp make a dataset at time t from data-units
+generate.hpp tool for simulating data unit
+stream_to_dataset.hpp generates data-units from a data file
+
+//////////////
+/ Discussion /
+//////////////
+
+Copying of of a data unit is "shallow" i.e. the copy and the original
+share the same data (through shared_ptr). This generally more convenient
+and saves memory if multiple clients need access to the same data.
+
+This may not be suitable, however, for very large datasets.
+
+////////////////////////
+/ Output from main.cpp /
+////////////////////////
+
+->example_as_random_distribution
+1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
+2 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9
+ <-
+->example_as_random_regression
+1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9
+ <-
+->example_surival_data_unit
+ covariate=-1 0 1
+unit : 1.5
+ entry_time = 1
+ time_on_study(1.5)=0.5
+ event_time(1.5)=0.5
+ is_at_risk(0.5,1.5)=1
+ is_at_risk(1.0,1.5)=0
+ event_time(2.5)=1
+ is_failure(2.5)=1
+unit_at_time at : 1.5
+ entry_time = 1
+ time_on_study()=0.5
+ event_time()=0.5
+ is_at_risk(0.5)=1
+ is_at_risk(1.0)=0
+<-
+-> example_survival_data_generate
+ generation separately
+entry=0
+covariate=1 0
+failure time =0.879577
+censoring time =0.993063
+entry=0.1
+covariate=0 1
+failure time =1.02827
+censoring time =1.52252
+entry=0.2
+covariate=1 0
+failure time =1.02032
+censoring time =2.15679
+entry=0.3
+covariate=0 1
+failure time =0.644506
+censoring time =1.53837
+entry=0.4
+covariate=1 0
+failure time =0.609003
+censoring time =1.07976
+entry=0.5
+covariate=0 1
+failure time =0.849973
+censoring time =0.397189
+entry=0.6
+covariate=1 0
+failure time =0.636047
+censoring time =0.390301
+entry=0.7
+covariate=0 1
+failure time =1.82047
+censoring time =0.0478013
+entry=0.8
+covariate=1 0
+failure time =3.66354
+censoring time =0.351838
+entry=0.9
+covariate=0 1
+failure time =0.39594
+censoring time =0.531722
+ generation simulatneously
+entry=1
+covariate=1 0
+event time=0.879577
+entry=1.1
+covariate=0 1
+event time=1.02827
+entry=1.2
+covariate=1 0
+event time=1.02032
+entry=1.3
+covariate=0 1
+event time=0.644506
+entry=1.4
+covariate=1 0
+event time=0.609003
+entry=1.5
+covariate=0 1
+event time=0.849973
+entry=1.6
+covariate=1 0
+event time=0.636047
+entry=1.7
+covariate=0 1
+event time=1.82047
+entry=1.8
+covariate=1 0
+event time=3.66354
+entry=1.9
+covariate=0 1
+event time=0.39594
+<-
+-> example_survival_data_generate_fixed_design_no_censoring
+fail times:
+0.83668 0.773398 1.45918 1.76891 0.970558 1.67971 0.914597 1.78733 0.579301
+0.840917 1.20617 0.461468 0.605027 0.303967 2.58337 0.0555372 3.48487
+0.274012 0.561865 0.617772 1.64934 1.43929 0.874483 0.621992 0.882471
+0.429383 3.01874 1.72017 0.0774633 0.354248 0.105914 0.993666 0.0214728
+0.395279 2.07676 2.99653 1.58299 0.130166 2.37051 1.94136 4.04237 0.552324
+1.86502 1.53529 0.650663 0.63259 1.76196 1.08054 0.132328 1.0976 1.18673
+0.829778 0.162663 0.663464 3.36284 1.35204 0.775657 0.096353 0.622239
+0.610399 0.323035 0.177481 1.72911 1.27017 0.640311 0.210054 0.97633
+0.138193 0.0199411 0.3372 1.11697 0.154229 0.99555 0.216418 1.11484
+0.46473 3.02547 2.00451 1.33046 0.568594 0.468361 0.817238 0.667511
+2.21289 1.25743 0.0899967 0.0721677 3.32951 1.15525 0.911347 1.29033
+0.178285 0.248317 0.381641 0.160366 1.3213 0.398392 0.805676 0.525268
+0.37394 OK <-
+-> example_survival_data_transform_if_to_unit_at_time
+OK <-
+-> example_survival_data_stream_to_dataset()
+unit # =0
+covariate=1 0 0 0 1 12 is failure=1 event time=12
+unit # =20
+covariate=0 1 0 0 1 32 is failure=1 event time=32
+unit # =40
+covariate=0 0 1 0 1 22 is failure=1 event time=22
+unit # =60
+covariate=0 0 0 1 1 27 is failure=1 event time=27
+<-

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,145 @@
+/////////////////////////////////////////////////////////////////////////////
+// generate.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 <algorithm>
+#include <iterator>
+#include <functional>
+#include <iostream>
+
+#include <boost/bind.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/exponential_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/survival_data/include.hpp>
+#include <libs/survival_data/src/example/generate.h>
+
+ void example_survival_data_generate(){
+ std::cout << "-> example_survival_data_generate" << std::endl;
+ using namespace boost;
+ typedef mpl::int_<0> fail_id;
+ typedef mpl::int_<1> cens_id;
+
+ namespace gen = boost::generator;
+ namespace ran = boost::random;
+ namespace rg = boost::random_regression;
+ namespace surv = boost::survival_data;
+ typedef double value_type;
+ typedef std::vector<value_type> cont_t;
+ typedef boost::mt19937 urng_type;
+ typedef gen::clock<value_type> gen_clock_type;
+ typedef gen::ref<gen_clock_type> ref_clock_type;
+// typedef as_random_distribution<ref_clock_type> clock_type;
+ typedef gen::cycle_through_shared_containers<cont_t> gen_cov_t;
+ typedef exponential_distribution<value_type> exp_t;
+ // Only meant to illustrate (possible) use of id
+ typedef rg::exponential<exp_t,uniform_real,fail_id> gen_fail_t;
+ typedef rg::exponential<exp_t,uniform_real,cens_id> gen_cens_t;
+ typedef std::vector<value_type> covariate_t;
+ typedef std::vector<covariate_t> levels_t;
+ typedef surv::generate<
+ ref_clock_type, //important to have ref if stop and go
+ gen_cov_t,
+ gen_fail_t,
+ gen_cens_t
+ > surv_gen_t;
+
+ const unsigned seed = 0;
+ const unsigned sims_count = 10;
+ const value_type start_time = 0.0;
+ const value_type delta_time = 0.1;
+
+ levels_t covs;
+ {using namespace boost::assign;
+ std::vector<value_type> cov0, cov1;
+ cov0+=1.0,0.0;
+ cov1+=0.0,1.0;
+ covs+=cov0,cov1;
+ };
+ covariate_t beta;
+
+ {using namespace boost::assign; beta+=-0.1,0.2;};
+
+ urng_type urng((urng_type::result_type)(seed));
+ gen_clock_type gen_clock(
+ (
+ gen::kwd<>::clock_start_time = start_time,
+ gen::kwd<>::clock_delta_time = delta_time
+ )
+ );
+ gen_cov_t gen_cov(
+ (
+ gen::kwd<>::range_containers = covs,
+ gen::kwd<>::range_containers_offset = 0
+ )
+ );
+ gen_fail_t gen_fail(
+ (
+ rg::kwd<fail_id>::coefficients = beta
+ )
+ );
+ gen_cens_t gen_cens(
+ (
+ rg::kwd<cens_id>::coefficients = beta
+ )
+ );
+
+ std::cout << " generation separately " << std::endl;
+ for(unsigned int i=0; i<sims_count; i++){
+ std::cout << "entry=" << gen_clock() << std::endl;
+
+ typedef gen_cov_t::result_type cov_result_t;
+ cov_result_t cov = gen_cov();
+
+ std::cout << "covariate=";
+ copy(
+ boost::begin(cov()),
+ boost::end(cov()),
+ std::ostream_iterator<value_type>(std::cout," ")
+ ); std::cout << std::endl;
+
+ std::cout
+ << "failure time ="
+ << gen_fail(urng,cov())
+ << std::endl;
+ std::cout
+ << "censoring time ="
+ << gen_cens(urng,cov())
+ << std::endl;
+
+ }
+ std::cout << " generation simulatneously " << std::endl;
+
+ typedef shared_ptr<gen_clock_type> shared_clock_t;
+ shared_clock_t shared_clock(new gen_clock_type(gen_clock));
+
+ surv_gen_t surv_gen(
+ ref_clock_type(shared_clock), //cant pass gen_clock directly
+ gen_cov,
+ gen_fail,
+ gen_cens
+ );
+ urng_type urng1((urng_type::result_type)(seed));
+ for(unsigned int i=0; i<sims_count; i++){
+ surv_gen_t::result_type u_o = surv_gen(urng1);
+
+ std::cout << "entry=" << u_o.entry_time() << std::endl;
+ std::cout << "covariate=";
+ copy(
+ boost::begin(u_o.covariate()),
+ boost::end(u_o.covariate()),
+ std::ostream_iterator<value_type>(std::cout," ")
+ ); std::cout << std::endl;
+ std::cout
+ << "event time=" //min(failure,censoring)
+ << u_o.event_time((value_type)(1e8))
+ << std::endl;
+ }
+ std::cout << "<-" << std::endl;
+ }
+

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// generate.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_SRC_EXAMPLE_GENERATE_H_ER_2009
+#define LIBS_SURVIVAL_DATA_SRC_EXAMPLE_GENERATE_H_ER_2009
+
+
+void example_survival_data_generate();
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,142 @@
+/////////////////////////////////////////////////////////////////////////////
+// generate_fixed_design_no_censoring.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 <iterator>
+#include <algorithm>
+#include <functional>
+#include <boost/bind.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/exponential_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/survival_data/include.hpp>
+
+
+void example_survival_data_generate_fixed_design_no_censoring(){
+ std::cout << "-> example_survival_data_generate_fixed_design_no_censoring"
+ << std::endl;
+ using namespace boost;
+
+ namespace gen = boost::generator;
+ namespace ran = boost::random;
+ namespace rg = boost::random_regression;
+ namespace surv = boost::survival_data;
+ typedef double value_type;
+ typedef std::vector<value_type> cont_t;
+ typedef cont_t::size_type size_type;
+ typedef cont_t range_covariate_t;
+ typedef cont_t range_beta_t;
+ typedef boost::mt19937 urng_type;
+ typedef exponential_distribution<value_type> exp_t;
+ // Only meant to illustrate (possible) use of id
+ typedef mpl::void_ fail_id_t;
+ typedef rg::exponential<exp_t,uniform_real,fail_id_t> gen_fail_t;
+
+ typedef surv::generate_fixed_design_no_censoring<gen_fail_t> surv_rdist_t;
+ typedef variate_generator<urng_type&,surv_rdist_t> surv_gen_t;
+
+ const unsigned seed = 0;
+ const unsigned sims_count = 100;
+ const value_type start_time = 0.0;
+ const value_type delta_time = 0.1;
+
+ typedef surv_gen_t::result_type unit_t;
+ typedef std::vector<unit_t> range_data_t;
+ range_data_t range_data;
+ {
+ std::vector<range_covariate_t> fixed_design;
+ {using namespace boost::assign;
+ range_covariate_t cov0, cov1, cov2, cov3;
+ cov0+=-0.5,-0.5;
+ cov1+=-0.5, 0.5;
+ cov2+= 0.5,-0.5;
+ cov3+= 0.5, 0.5; //fixed design
+ fixed_design+=cov0,cov1,cov2,cov3;
+ };
+ range_beta_t true_beta;
+
+ {using namespace boost::assign; true_beta+=-0.1,0.2;};
+
+ urng_type urng((urng_type::result_type)(seed));
+ surv_rdist_t surv_rdist(
+ start_time,
+ delta_time,
+ fixed_design,
+ (
+ rg::kwd<fail_id_t>::coefficients = true_beta
+ )
+ );
+
+ std::generate_n(
+ back_inserter(range_data),
+ sims_count,
+ surv_gen_t(urng,surv_rdist)
+ );
+
+ BOOST_ASSERT(size(range_data)==sims_count);
+
+ for(unsigned n=0; n< sims_count; n++){
+ unsigned k = n % size(fixed_design);
+ range_covariate_t zero;
+ value_type zero_norm = 0.0;
+ zero.clear();
+ std::transform(
+ begin(range_data[n].range_covariate()),
+ end(range_data[n].range_covariate()),
+ begin(fixed_design[k]),
+ back_inserter(zero),
+ std::minus<value_type>()
+ );
+ zero_norm = *max_element(begin(zero),end(zero));
+ BOOST_ASSERT((zero_norm>-1e-10) && (zero_norm<1e-10));
+ zero_norm = *min_element(begin(zero),end(zero));
+ BOOST_ASSERT((zero_norm>-1e-10) && (zero_norm<1e-10));
+
+ zero_norm = range_data[n].entry_time();
+ zero_norm -= (n * delta_time+ start_time);
+ BOOST_ASSERT((zero_norm>-1e-10) && (zero_norm<1e-10));
+
+ }//end loop
+
+ typedef surv::unit_at_time<unit_t> unit_at_time_t;
+ typedef std::vector<unit_at_time_t> range_data_at_time_type;
+ value_type time_analysis = math::tools::max_value<value_type>();
+ range_data_at_time_type range_data_at_time;
+
+ transform_if_to_unit_at_time(
+ begin(range_data),
+ end(range_data),
+ back_inserter(range_data_at_time),
+ time_analysis
+ );
+
+ typedef std::vector<value_type> fail_times_t;
+ fail_times_t fail_times;
+ transform(
+ begin(range_data_at_time),
+ end(range_data_at_time),
+ back_inserter(fail_times),
+ bind(
+ &unit_at_time_t::event_time,
+ _1
+ )
+ );
+
+ std::cout << "fail times: "<< std::endl;
+ copy(
+ begin(fail_times),
+ end(fail_times),
+ std::ostream_iterator<value_type>(std::cout, " ")
+ );
+
+ std::cout << " OK <-" << std::endl;
+ }
+}

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/generate_fixed_design_no_censoring.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// generate_fixed_design_no_censoring.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_SRC_EXAMPLE_GENERATE_FIXED_DESIGN_NO_CENSORING_H_ER_2009
+#define LIBS_SURVIVAL_DATA_SRC_EXAMPLE_GENERATE_FIXED_DESIGN_NO_CENSORING_H_ER_2009
+
+void example_survival_data_generate_fixed_design_no_censoring();
+
+
+#endif // GENERATE_FIXED_DESIGN_NO_CENSORING_H_INCLUDED

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/mice_data.txt
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/mice_data.txt 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,80 @@
+0,1,0,0,0,1,12
+0,1,0,0,0,1,1
+0,1,0,0,0,1,21
+0,1,0,0,0,1,25
+0,1,0,0,0,1,11
+0,1,0,0,0,1,26
+0,1,0,0,0,1,27
+0,1,0,0,0,1,30
+0,1,0,0,0,1,13
+0,1,0,0,0,1,12
+0,1,0,0,0,1,21
+0,1,0,0,0,1,20
+0,1,0,0,0,1,23
+0,1,0,0,0,1,25
+0,1,0,0,0,1,23
+0,1,0,0,0,1,29
+0,1,0,0,0,1,35
+0,1,0,0,0,0,40
+0,1,0,0,0,1,31
+0,0,1,0,0,1,36
+0,0,1,0,0,1,32
+0,0,1,0,0,1,27
+0,0,1,0,0,1,23
+0,0,1,0,0,1,12
+0,0,1,0,0,1,18
+0,0,1,0,0,0,40
+0,0,1,0,0,0,40
+0,0,1,0,0,1,38
+0,0,1,0,0,1,29
+0,0,1,0,0,1,30
+0,0,1,0,0,0,40
+0,0,1,0,0,1,32
+0,0,1,0,0,0,40
+0,0,1,0,0,0,40
+0,0,1,0,0,0,40
+0,0,1,0,0,0,40
+0,0,1,0,0,1,25
+0,0,1,0,0,1,30
+0,0,1,0,0,1,37
+0,0,0,1,0,1,27
+0,0,0,1,0,1,22
+0,0,0,1,0,1,26
+0,0,0,1,0,0,10
+0,0,0,1,0,1,28
+0,0,0,1,0,1,19
+0,0,0,1,0,1,15
+0,0,0,1,0,1,12
+0,0,0,1,0,1,35
+0,0,0,1,0,1,35
+0,0,0,1,0,1,10
+0,0,0,1,0,1,22
+0,0,0,1,0,1,18
+0,0,0,1,0,0,24
+0,0,0,1,0,1,12
+0,0,0,1,0,0,40
+0,0,0,1,0,0,40
+0,0,0,1,0,1,31
+0,0,0,1,0,1,24
+0,0,0,1,0,1,37
+0,0,0,0,1,1,29
+0,0,0,0,1,1,27
+0,0,0,0,1,1,18
+0,0,0,0,1,1,22
+0,0,0,0,1,1,13
+0,0,0,0,1,1,18
+0,0,0,0,1,1,29
+0,0,0,0,1,1,28
+0,0,0,0,1,0,20
+0,0,0,0,1,1,16
+0,0,0,0,1,1,22
+0,0,0,0,1,1,26
+0,0,0,0,1,1,19
+0,0,0,0,1,0,29
+0,0,0,0,1,0,10
+0,0,0,0,1,1,17
+0,0,0,0,1,1,28
+0,0,0,0,1,1,26
+0,0,0,0,1,1,12
+0,0,0,0,1,1,17
+0,0,0,0,1,1,26

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,77 @@
+///////////////////////////////////////////////////////////////////////////////
+// stream_to_dataset.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 <stdexcept>
+#include <vector>
+#include <fstream>
+#include <algorithm>
+#include <iterator>
+#include <iostream>
+#include <boost/bind.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/survival_data/include.hpp>
+#include <libs/survival_data/src/example/stream_to_dataset.h>
+
+ void example_survival_data_stream_to_dataset(){
+ std::cout
+ << "-> example_survival_data_stream_to_dataset()"
+ << std::endl;
+ using namespace boost::assign;
+ using namespace boost::survival_data;
+ using namespace std;
+ // Warning : change the path as necessary
+ const char* filepath =
+ //"mice_data_shortened";
+ "/Users/erwann/sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/mice_data.txt";
+ //"./mice_data";
+ typedef double real_type;
+ typedef std::vector<real_type> container_type;
+ typedef unit<container_type> unit_obs_type;
+ typedef vector<unit_obs_type> dataset_type;
+ typedef dataset_type::size_type dataset_size_type;
+ typedef vector<real_type> coefficients_type;
+ coefficients_type coefficients; coefficients += -1.0, -0.1, 0.1, 1.0 ;
+ const dataset_size_type dataset_size = 80;
+ const unsigned modulo = 20;
+ const real_type max_censoring_time = 40.0;
+
+ dataset_type dataset; dataset.reserve(dataset_size);
+ std::ifstream mice_data(filepath);
+ try{
+ if(!mice_data.good()){
+ std::string str = "mice data not open check the filepath:";
+ str.append(filepath);
+ throw std::runtime_error(str);
+ }
+ stream_to_dataset::fill(mice_data,dataset);
+
+ for(unsigned int i = 0; i<dataset.size(); i++){//TODO algorithm
+ if(i%modulo==0){
+ std::cout << "unit # =" << i << std::endl;
+ unit_obs_type uo = dataset[i];
+ std::cout << "covariate=";
+ copy(
+ boost::begin(uo.covariate()),
+ boost::end(uo.covariate()),
+ std::ostream_iterator<real_type>(std::cout, " ")
+ );
+ std::cout
+ << "is failure="
+ << uo.is_failure(max_censoring_time)
+ << " ";
+ std::cout
+ << "event time="
+ << uo.event_time(max_censoring_time)
+ << std::endl;
+ }
+ }
+
+ }catch(const std::exception& e){
+ std::cout<< e.what() << std::endl;
+ }
+ std::cout << "<-" << std::endl;
+ }
+

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/stream_to_dataset.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+///////////////////////////////////////////////////////////////////////////////
+// stream_to_dataset.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_SRC_EXAMPLE_STREAM_TO_DATASET_H_ER_2009
+#define LIBS_SURVIVAL_DATA_SRC_EXAMPLE_STREAM_TO_DATASET_H_ER_2009
+
+void example_survival_data_stream_to_dataset();
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,76 @@
+/////////////////////////////////////////////////////////////////////////////
+// transform_if_to_unit_at_time.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 <boost/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/generator/shared_container.hpp>
+#include <boost/survival_data/transform_if_to_unit_at_time.hpp>
+#include <libs/survival_data/src/example/transform_if_to_unit_at_time.h>
+
+void example_survival_data_transform_if_to_unit_at_time(){
+ std::cout << "-> example_survival_data_transform_if_to_unit_at_time"
+ << std::endl;
+
+ using namespace boost;
+ using namespace boost::survival_data;
+ typedef double value_type;
+ typedef std::vector<value_type> covariate_t;
+ typedef unit<covariate_t> unit_t;
+ typedef unit_at_time<unit_t> unit_at_time_t;
+
+ covariate_t cov;
+ {
+ using namespace boost::assign;
+ cov+= -1.0, 0.0, 1.0;
+ }
+
+ const value_type entry_time0 = 2.0;
+ const value_type entry_time1 = 1.0;
+ const value_type event_time0 = 1.0;
+ const value_type event_time1 = 1.0;
+ const bool is_fail0 = true;
+ const bool is_fail1 = true;
+ //value_type max_entry_t
+ // = (entry_time0<entry_time1)? entry_time1 : entry_time0;
+
+ unit_t unit0(entry_time0,cov);
+ unit0.set_event(is_fail0,event_time0);
+ unit_t unit1(entry_time1,cov);
+ unit1.set_event(is_fail1,event_time1);
+
+ typedef std::vector<unit_t> dataset_type;
+ dataset_type dataset;
+ dataset.push_back(unit0);
+ dataset.push_back(unit1);
+
+ typedef std::vector<unit_at_time_t> dataset_at_time_type;
+ value_type time_analysis = (entry_time0+entry_time1)/2.0;
+ dataset_at_time_type dataset_at_time;
+
+ transform_if_to_unit_at_time(
+ begin(dataset),
+ end(dataset),
+ back_inserter(dataset_at_time),
+ time_analysis
+ );
+
+ std::size_t size_diff = size(dataset_at_time) - 1;
+ BOOST_ASSERT(size_diff == 0);
+
+ value_type desired_entry_time =
+ (entry_time0<entry_time1)? entry_time0 : entry_time1;
+ value_type entry_time_diff = desired_entry_time;
+ entry_time_diff -= dataset_at_time[0].entry_time();
+
+ BOOST_ASSERT(
+ (entry_time_diff > -1e-10) && (entry_time_diff<1e-10)
+ );
+
+ std::cout << "OK <-" << std::endl;
+
+}

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/transform_if_to_unit_at_time.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+///////////////////////////////////////////////////////////////////////////////
+// transform_if_to_unit_at_time.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_TRANSFORM_IF_TO_UNIT_AT_TIME_H_ER_2009
+#define LIBS_SURVIVAL_DATA_TRANSFORM_IF_TO_UNIT_AT_TIME_H_ER_2009
+
+void example_survival_data_transform_if_to_unit_at_time();
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,101 @@
+/////////////////////////////////////////////////////////////////////////////
+// unit.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 <vector>
+#include <boost/assign/std/vector.hpp>
+#include <boost/generator/shared_container.hpp>
+#include <boost/survival_data/unit.hpp>
+#include <boost/survival_data/unit_at_time.hpp>
+#include <libs/survival_data/src/example/unit.h>
+
+void example_survival_data_unit(){
+ std::cout << "->example_surival_data_unit" << std::endl;
+ using namespace boost;
+ namespace surv = boost::survival_data;
+ typedef double value_type;
+ typedef std::vector<value_type> cont_t;
+ typedef surv::unit<cont_t> unit_t;
+ typedef surv::unit_at_time<unit_t> unit_at_time_t;
+
+ cont_t container;
+ {
+ using namespace boost::assign;
+ container+= -1.0, 0.0, 1.0;
+ }
+
+ const value_type entry_time0 = 1.0;
+ const value_type event_time = 1.0;
+ value_type t = 1.5; //analysis time
+ unit_t unit0(entry_time0,container);
+ unit0.set_event(true,event_time);
+
+ std::cout << " covariate=";
+ copy(
+ begin(container),
+ end(container),
+ std::ostream_iterator<value_type>(std::cout, " ")
+ ); std::cout << std::endl;
+
+ std::cout << "unit : " << t << std::endl;
+ std::cout
+ << " entry_time = "
+ << unit0.entry_time()
+ << std::endl;
+ std::cout
+ << " time_on_study(" << t << ")="
+ << unit0.time_on_study(t)
+ << std::endl;
+ std::cout
+ << " event_time(" << t << ")="
+ << unit0.event_time(t) << std::endl;
+
+ std::cout
+ << " is_at_risk(0.5," << t << ")="
+ << unit0.is_at_risk(0.5,t) << std::endl;
+ std::cout
+ << " is_at_risk(1.0," << t << ")="
+ << unit0.is_at_risk(1.0,t) << std::endl;
+
+ t = 2.5;
+ std::cout
+ << " event_time(" << t << ")="
+ << unit0.event_time(t) << std::endl;
+ std::cout
+ << " is_failure(" << t << ")="
+ << unit0.is_failure(t) << std::endl;
+
+ t = 1.5;
+ unit_at_time_t unit_at_time(
+ unit0,
+ t
+ );
+
+ std::cout << "unit_at_time at : " << t << std::endl;
+
+ std::cout
+ << " entry_time = "
+ << unit_at_time.entry_time()
+ << std::endl;
+ std::cout
+ << " time_on_study()="
+ << unit_at_time.time_on_study()
+ << std::endl;
+ std::cout
+ << " event_time()="
+ << unit_at_time.event_time() << std::endl;
+
+ std::cout
+ << " is_at_risk(0.5)="
+ << unit_at_time.is_at_risk(0.5) << std::endl;
+ std::cout
+ << " is_at_risk(1.0)="
+ << unit_at_time.is_at_risk(1.0) << std::endl;
+
+
+ std::cout << "<-" << std::endl;
+}
+

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.h
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/example/unit.h 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,12 @@
+///////////////////////////////////////////////////////////////////////////////
+// unit.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_UNIT_OF_OBSERVATION_H_ER_2009
+#define LIBS_SURVIVAL_DATA_UNIT_OF_OBSERVATION_H_ER_2009
+
+void example_survival_data_unit();
+
+#endif

Added: sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/survival_data/libs/survival_data/src/main.cpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,27 @@
+/////////////////////////////////////////////////////////////////////////////
+// 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 <libs/random_regression/src/example/as_random_distribution.h>
+#include <libs/random_regression/src/example/as_random_regression.h>
+#include <libs/survival_data/src/example/unit.h>
+#include <libs/survival_data/src/example/generate.h>
+#include <libs/survival_data/src/example/generate_fixed_design_no_censoring.h>
+#include <libs/survival_data/src/example/transform_if_to_unit_at_time.h>
+#include <libs/survival_data/src/example/stream_to_dataset.h>
+
+int main(){
+
+ example_as_random_distribution();
+ example_as_random_regression();
+ example_survival_data_unit();
+ example_survival_data_generate();
+ example_survival_data_generate_fixed_design_no_censoring();
+ example_survival_data_transform_if_to_unit_at_time();
+ //Warning : make sure to set the path in the cpp file :
+ example_survival_data_stream_to_dataset();
+
+ return 0;
+};

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/assert_is_base_of.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/assert_is_base_of.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,23 @@
+////////////////////////////////////////////////////////////////////////////
+// utility::assert_is_base_of.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 ASSERT_IS_BASE_OF_HPP_INCLUDED
+#define ASSERT_IS_BASE_OF_HPP_INCLUDED
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{namespace utility{
+
+ template<typename B,typename D>
+ struct assert_is_base_of{
+ BOOST_MPL_ASSERT((
+ is_base_of<B,D>
+ ));
+ };
+
+}}
+
+#endif // ASSERT_IS_BASE_OF_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/assert_not_empty.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/assert_not_empty.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,27 @@
+////////////////////////////////////////////////////////////////////////////
+// utility::assert_not_empty.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_UTILITY_ASSERT_NOT_EMPTY_HPP_ER_2009
+#define BOOST_UTILITY_ASSERT_NOT_EMPTY_HPP_ER_2009
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{namespace utility{
+
+ template<typename T>
+ struct assert_not_empty{
+ BOOST_MPL_ASSERT((
+ mpl::if_<
+ is_empty<T>,
+ bool_<false>,
+ bool_<true>
+ >
+ ));
+ };
+
+#endif // BOOST_UTILITY_ASSERT_NOT_EMPTY_HPP_ER_2009

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/container_to_string.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/container_to_string.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,70 @@
+#ifndef BOOST_UTILITY_CONTAINER_TO_STRING_HPP_ER_2009
+#define BOOST_UTILITY_CONTAINER_TO_STRING_HPP_ER_2009
+#include <string>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+namespace boost{namespace utility{
+
+ struct container_to_string{
+ typedef std::string result_type;
+
+ // R ForwardRange
+ // func(*i)
+ template<typename R,typename Functor>
+ result_type
+ static get(const R& r,const Functor& func){
+ format f0("%1% ");
+ typedef typename range_iterator<const R>::type citer_t;
+ result_type str;
+ for(citer_t i = begin(r); i<end(r); i++){
+ format f = f0;
+ f%func(*i);
+ str+= f.str();
+ }
+ return str;
+ }
+ template<typename R,typename Functor>
+ result_type
+ static get_indexed(const R& r,const Functor& func){
+ format f0("[%1%]=%2% ");
+ typedef typename range_iterator<const R>::type citer_t;
+ typedef typename range_difference<const R>::type diff_t;
+ result_type str;
+ for(citer_t i = begin(r); i<end(r); i++){
+ format f = f0;
+ diff_t diff = std::distance(begin(r),i);
+ f%diff;
+ f%func(*i);
+ str+= f.str();
+ }
+ return str;
+ }
+
+ template<typename R>
+ result_type
+ static get_indexed(const R& r){
+ identity_func func;
+ return get_indexed(r,func);
+ }
+ template<typename R>
+ result_type
+ static get(const R& r){
+ identity_func func;
+ return get(r,func);
+ }
+
+ private:
+
+ struct identity_func{
+ identity_func(){}
+ template<typename T>
+ T operator()(T x)const{
+ return x;
+ }
+ };
+ };
+
+}//utility
+}//boost
+
+#endif // CONTAINER_TO_STRING_HPP_INCLUDED

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/dont_care.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/dont_care.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// dont_care.cpp
+// (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)
+#ifndef BOOST_UTILITY_DONT_CARE_HPP_ER_2009
+#define BOOST_UTILITY_DONT_CARE_HPP_ER_2009
+namespace boost{namespace utility{
+ //borrowed from Boost.Accumulator
+ struct dont_care
+ {
+ template<typename Args>
+ dont_care(Args const &)
+ {
+ }
+ };
+
+}}
+#endif

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/nested_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/nested_type.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// nested_type.hpp
+// (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)
+#ifndef BOOST_UTILITY_NESTED_TYPE_HPP_ER_2009
+#define BOOST_UTILITY_NESTED_TYPE_HPP_ER_2009
+#include <boost/mpl/has_xxx.hpp>
+#include <boost/mpl/eval_if.hpp>
+
+namespace boost{namespace utility{
+ BOOST_MPL_HAS_XXX_TRAIT_DEF(type);
+
+// See news://news.gmane.org:119/gma8hc$2a0$1@ger.gmane.org
+template<class T>
+struct nested_type :
+ boost::mpl::eval_if<has_type<T>,
+ T,
+ boost::mpl::identity<T> >
+{};
+
+}}
+#endif

Added: sandbox/conditionally_specified_distribution/utility/boost/utility/remove_qualifier.hpp
==============================================================================
--- (empty file)
+++ sandbox/conditionally_specified_distribution/utility/boost/utility/remove_qualifier.hpp 2009-03-17 22:36:15 EDT (Tue, 17 Mar 2009)
@@ -0,0 +1,21 @@
+////////////////////////////////////////////////////////////////////////////
+// utility::remove_qualifier.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_UTILITY_REMOVE_QUALIFIER_HPP_ER_2009
+#define BOOST_UTILITY_REMOVE_QUALIFIER_HPP_ER_2009
+
+#include <boost/type_traits.hpp>
+
+namespace boost{namespace utility{
+
+ template<typename T> //reverse order?
+ struct remove_qualifier: remove_cv<
+ typename remove_reference<T>::type
+ >
+ {};
+
+}}
+#endif // REMOVE_QUALIFIER_HPP_INCLUDED


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