$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r55606 - in sandbox/statistics: . adaptive_rejection_sampling adaptive_rejection_sampling/boost adaptive_rejection_sampling/boost/ars adaptive_rejection_sampling/boost/ars/detail adaptive_rejection_sampling/boost/ars/functional adaptive_rejection_sampling/boost/ars/test adaptive_rejection_sampling/libs adaptive_rejection_sampling/libs/ars adaptive_rejection_sampling/libs/ars/doc adaptive_rejection_sampling/libs/ars/example arithmetic arithmetic/boost arithmetic/boost/arithmetic autocovariance autocovariance/boost autocovariance/boost/accumulators autocovariance/boost/accumulators/statistics autocovariance/boost/random autocovariance/libs autocovariance/libs/accumulators autocovariance/libs/accumulators/statistics autocovariance/libs/accumulators/statistics/doc autocovariance/libs/accumulators/statistics/example autocovariance/libs/accumulators/statistics/src binary_op binary_op/boost binary_op/boost/binary_op binary_op/boost/binary_op/algorithm binary_op/boost/binary_op/data binary_op/boost/binary_op/functional binary_op/boost/binary_op/functional/maybe_deprecated binary_op/libs binary_op/libs/binary_op binary_op/libs/binary_op/doc binary_op/libs/binary_op/example binary_op/libs/binary_op/src dist_random dist_random/boost dist_random/boost/dist_random dist_random/boost/dist_random/distributions dist_random/boost/dist_random/functional dist_random/boost/dist_random/meta dist_random/boost/dist_random/random dist_random/libs dist_random/libs/dist_random dist_random/libs/dist_random/doc dist_random/libs/dist_random/example dist_random/libs/dist_random/src functional functional/boost functional/boost/functional functional/libs functional/libs/functional functional/libs/functional/doc functional/libs/functional/example functional/libs/functional/src importance_sampling importance_sampling/boost importance_sampling/boost/importance_sampling importance_sampling/libs importance_sampling/libs/importance_sampling importance_sampling/libs/importance_sampling/doc importance_sampling/libs/importance_sampling/example importance_sampling/libs/importance_sampling/src importance_weights importance_weights/boost importance_weights/boost/importance_weights importance_weights/boost/importance_weights/algorithm importance_weights/boost/importance_weights/algorithm/detail importance_weights/libs importance_weights/libs/importance_weights importance_weights/libs/importance_weights/doc importance_weights/libs/importance_weights/example importance_weights/libs/importance_weights/src iterator iterator/boost iterator/boost/iterator iterator/libs iterator/libs/iterator iterator/libs/iterator/doc iterator/libs/iterator/example iterator/libs/iterator/src joint_dist joint_dist/boost joint_dist/boost/joint_dist joint_dist/boost/joint_dist/distribution joint_dist/boost/joint_dist/distribution/detail joint_dist/boost/joint_dist/distributions joint_dist/boost/joint_dist/fun_wrap joint_dist/boost/joint_dist/fun_wrap/detail joint_dist/boost/joint_dist/meta joint_dist/boost/joint_dist/random joint_dist/boost/joint_dist/unscope joint_dist/libs joint_dist/libs/joint_dist joint_dist/libs/joint_dist/doc joint_dist/libs/joint_dist/example joint_dist/libs/joint_dist/src kernel kernel/boost kernel/boost/kernel kernel/boost/kernel/bandwidth kernel/boost/kernel/functional kernel/boost/kernel/functional/detail kernel/boost/kernel/kernel kernel/boost/kernel/kernel/scalar kernel/boost/kernel/meta kernel/libs kernel/libs/kernel kernel/libs/kernel/doc kernel/libs/kernel/example kernel/libs/kernel/src matrix_view matrix_view/boost matrix_view/boost/matrix_view matrix_view/boost/matrix_view/algorithm matrix_view/boost/matrix_view/iterator matrix_view/libs matrix_view/libs/matrix_view matrix_view/libs/matrix_view/doc matrix_view/libs/matrix_view/example matrix_view/libs/matrix_view/src model model/boost model/boost/model model/boost/model/algorithm model/boost/model/functional model/boost/model/wrap model/boost/model/wrap/aggregate model/boost/model/wrap/unary model/boost/model/wrap/unary/detail model/libs model/libs/model model/libs/model/doc monomials_horner monomials_horner/boost monomials_horner/boost/monomials_horner monomials_horner/boost/monomials_horner/policy monomials_horner/libs monomials_horner/libs/monomials_horner monomials_horner/libs/monomials_horner/doc monomials_horner/libs/monomials_horner/example monomials_horner/libs/monomials_horner/src mpl mpl/boost mpl/boost/mpl nn1 nn1/boost nn1/boost/nn1 nn1/boost/nn1/algorithm nn1/boost/nn1/detail nn1/boost/nn1/functional nn1/libs nn1/libs/nn1 nn1/libs/nn1/doc nn1/libs/nn1/example nn1/libs/nn1/src non_param non_param/boost non_param/boost/non_param non_param/boost/non_param/algorithm non_param/libs non_param/libs/non_param non_param/libs/non_param/doc non_param/libs/non_param/example non_param/libs/non_param/src random random/boost random/boost/random random/libs random/libs/random random/libs/random/doc random/libs/random/src scalar_dist scalar_dist/boost scalar_dist/boost/scalar_dist scalar_dist/boost/scalar_dist/algorithm scalar_dist/boost/scalar_dist/fun_wrap scalar_dist/boost/scalar_dist/fun_wrap/detail scalar_dist/boost/scalar_dist/map_pdf scalar_dist/boost/scalar_dist/meta scalar_dist/boost/scalar_dist/unscope scalar_dist/libs scalar_dist/libs/scalar_dist scalar_dist/libs/scalar_dist/doc scalar_dist/libs/scalar_dist/example scalar_dist/libs/scalar_dist/src standard_distribution standard_distribution/boost standard_distribution/boost/standard_distribution standard_distribution/boost/standard_distribution/distributions standard_distribution/boost/standard_distribution/is_scalar_dist standard_distribution/boost/standard_distribution/normalizing_constant standard_distribution/boost/standard_distribution/os standard_distribution/boost/standard_distribution/primitives standard_distribution/boost/standard_distribution/serialize standard_distribution/boost/standard_distribution/transformation standard_distribution/boost/standard_distribution/unnormalized_pdf standard_distribution/libs standard_distribution/libs/standard_distribution standard_distribution/libs/standard_distribution/doc standard_distribution/libs/standard_distribution/example standard_distribution/libs/standard_distribution/src survival_data survival_data/boost survival_data/boost/survival survival_data/boost/survival/data survival_data/boost/survival/data/algorithm survival_data/boost/survival/data/algorithm/detail survival_data/boost/survival/data/data survival_data/boost/survival/data/meta survival_data/boost/survival/data/random survival_data/libs survival_data/libs/survival survival_data/libs/survival/data survival_data/libs/survival/data/doc survival_data/libs/survival/data/example survival_data/libs/survival/data/src survival_model survival_model/boost survival_model/boost/survival survival_model/boost/survival/model survival_model/boost/survival/model/algorithm survival_model/boost/survival/model/meta survival_model/boost/survival/model/models survival_model/boost/survival/model/models/exponential survival_model/boost/survival/model/models/exponential/detail survival_model/libs survival_model/libs/survival survival_model/libs/survival/model survival_model/libs/survival/model/doc survival_model/libs/survival/model/example survival_model/libs/survival/model/src tree tree/boost tree/boost/tree tree/libs tree/libs/doc tree/libs/src tree/libs/tree tree/libs/tree/example vector_space vector_space/boost vector_space/boost/vector_space vector_space/boost/vector_space/algorithm vector_space/boost/vector_space/data vector_space/boost/vector_space/data/detail vector_space/boost/vector_space/functional vector_space/libs vector_space/libs/vector_space vector_space/libs/vector_space/doc vector_space/libs/vector_space/example vector_space/libs/vector_space/src
From: erwann.rogard_at_[hidden]
Date: 2009-08-16 01:29:57
Author: e_r
Date: 2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
New Revision: 55606
URL: http://svn.boost.org/trac/boost/changeset/55606
Log:
Adding dir statistics
Added:
   sandbox/statistics/
   sandbox/statistics/adaptive_rejection_sampling/
   sandbox/statistics/adaptive_rejection_sampling/boost/
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/constant.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/area.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/data.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/tangent_intersection.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/function_signature.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/functional/
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/functional/standard_distribution.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/include.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/point.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/gamma_distribution.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/normal_distribution.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.h   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.cpp   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.h   (contents, props changed)
   sandbox/statistics/adaptive_rejection_sampling/libs/ars/main.cpp   (contents, props changed)
   sandbox/statistics/arithmetic/
   sandbox/statistics/arithmetic/boost/
   sandbox/statistics/arithmetic/boost/arithmetic/
   sandbox/statistics/arithmetic/boost/arithmetic/equal.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/
   sandbox/statistics/autocovariance/boost/
   sandbox/statistics/autocovariance/boost/accumulators/
   sandbox/statistics/autocovariance/boost/accumulators/statistics/
   sandbox/statistics/autocovariance/boost/accumulators/statistics/acf.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/acv0.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_analysis.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_moving_average.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acf.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acvf.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/percentage_effective_sample_size.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_autocorrelated.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_iid.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/boost/random/
   sandbox/statistics/autocovariance/boost/random/moving_average.hpp   (contents, props changed)
   sandbox/statistics/autocovariance/libs/
   sandbox/statistics/autocovariance/libs/accumulators/
   sandbox/statistics/autocovariance/libs/accumulators/statistics/
   sandbox/statistics/autocovariance/libs/accumulators/statistics/doc/
   sandbox/statistics/autocovariance/libs/accumulators/statistics/doc/readme.txt   (contents, props changed)
   sandbox/statistics/autocovariance/libs/accumulators/statistics/example/
   sandbox/statistics/autocovariance/libs/accumulators/statistics/example/main.cpp   (contents, props changed)
   sandbox/statistics/autocovariance/libs/accumulators/statistics/src/
   sandbox/statistics/binary_op/
   sandbox/statistics/binary_op/boost/
   sandbox/statistics/binary_op/boost/binary_op/
   sandbox/statistics/binary_op/boost/binary_op/algorithm/
   sandbox/statistics/binary_op/boost/binary_op/algorithm/for_each.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/algorithm/heads.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/algorithm/include.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/algorithm/sort_on_head.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/algorithm/tuples.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/data/
   sandbox/statistics/binary_op/boost/binary_op/data/include.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/data/tuple_range.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/functional/
   sandbox/statistics/binary_op/boost/binary_op/functional/include.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/functional/match_accumulator.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/functional/maybe_deprecated/
   sandbox/statistics/binary_op/boost/binary_op/functional/untupler.hpp   (contents, props changed)
   sandbox/statistics/binary_op/boost/binary_op/include.hpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/
   sandbox/statistics/binary_op/libs/binary_op/
   sandbox/statistics/binary_op/libs/binary_op/doc/
   sandbox/statistics/binary_op/libs/binary_op/doc/readme.txt   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/
   sandbox/statistics/binary_op/libs/binary_op/example/binary_f.cpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/binary_f.h   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.cpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.h   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/for_each.cpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/for_each.h   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.cpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.h   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/untuple.cpp   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/example/untuple.h   (contents, props changed)
   sandbox/statistics/binary_op/libs/binary_op/src/
   sandbox/statistics/binary_op/libs/binary_op/src/main.cpp   (contents, props changed)
   sandbox/statistics/dist_random/
   sandbox/statistics/dist_random/boost/
   sandbox/statistics/dist_random/boost/dist_random/
   sandbox/statistics/dist_random/boost/dist_random/distributions/
   sandbox/statistics/dist_random/boost/dist_random/distributions/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/exponential.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/gamma.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/include.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/location_scale.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/normal.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/distributions/students_t.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/functional/
   sandbox/statistics/dist_random/boost/dist_random/functional/check_convergence.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/functional/include.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/functional/make_random.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/include.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/meta/
   sandbox/statistics/dist_random/boost/dist_random/meta/dist_random.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_input.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_result.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/meta/include.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/random/
   sandbox/statistics/dist_random/boost/dist_random/random/generate_n.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/random/include.hpp   (contents, props changed)
   sandbox/statistics/dist_random/boost/dist_random/random/sample.hpp   (contents, props changed)
   sandbox/statistics/dist_random/libs/
   sandbox/statistics/dist_random/libs/dist_random/
   sandbox/statistics/dist_random/libs/dist_random/doc/
   sandbox/statistics/dist_random/libs/dist_random/doc/readme.txt   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/
   sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.cpp   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.h   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/generate_n.cpp   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/generate_n.h   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.cpp   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.h   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/sample.cpp   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/example/sample.h   (contents, props changed)
   sandbox/statistics/dist_random/libs/dist_random/src/
   sandbox/statistics/dist_random/libs/dist_random/src/main.cpp   (contents, props changed)
   sandbox/statistics/functional/
   sandbox/statistics/functional/boost/
   sandbox/statistics/functional/boost/functional/
   sandbox/statistics/functional/boost/functional/clock.hpp   (contents, props changed)
   sandbox/statistics/functional/boost/functional/find.hpp   (contents, props changed)
   sandbox/statistics/functional/boost/functional/fixed_value.hpp   (contents, props changed)
   sandbox/statistics/functional/boost/functional/mean_var_accumulator.hpp   (contents, props changed)
   sandbox/statistics/functional/boost/functional/visitor.hpp   (contents, props changed)
   sandbox/statistics/functional/boost/functional/zscore.hpp   (contents, props changed)
   sandbox/statistics/functional/libs/
   sandbox/statistics/functional/libs/functional/
   sandbox/statistics/functional/libs/functional/doc/
   sandbox/statistics/functional/libs/functional/doc/readme.txt   (contents, props changed)
   sandbox/statistics/functional/libs/functional/example/
   sandbox/statistics/functional/libs/functional/src/
   sandbox/statistics/importance_sampling/
   sandbox/statistics/importance_sampling/boost/
   sandbox/statistics/importance_sampling/boost/importance_sampling/
   sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp   (contents, props changed)
   sandbox/statistics/importance_sampling/boost/importance_sampling/grid.hpp   (contents, props changed)
   sandbox/statistics/importance_sampling/boost/importance_sampling/include.hpp   (contents, props changed)
   sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/
   sandbox/statistics/importance_sampling/libs/importance_sampling/
   sandbox/statistics/importance_sampling/libs/importance_sampling/doc/
   sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/importance_sampling/example/
   sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.cpp   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.h   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.h   (contents, props changed)
   sandbox/statistics/importance_sampling/libs/importance_sampling/src/
   sandbox/statistics/importance_sampling/libs/importance_sampling/src/main.cpp   (contents, props changed)
   sandbox/statistics/importance_weights/
   sandbox/statistics/importance_weights/boost/
   sandbox/statistics/importance_weights/boost/importance_weights/
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/apply_exp_offset.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/detail/
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/effective_sample_size.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/find_scale_to_finite_sum.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/maximal_finite_sums.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/prepare_weights.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/boost/importance_weights/algorithm/scale_to_finite_sum.hpp   (contents, props changed)
   sandbox/statistics/importance_weights/libs/
   sandbox/statistics/importance_weights/libs/importance_weights/
   sandbox/statistics/importance_weights/libs/importance_weights/doc/
   sandbox/statistics/importance_weights/libs/importance_weights/doc/readme.txt   (contents, props changed)
   sandbox/statistics/importance_weights/libs/importance_weights/example/
   sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.cpp   (contents, props changed)
   sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.h   (contents, props changed)
   sandbox/statistics/importance_weights/libs/importance_weights/src/
   sandbox/statistics/importance_weights/libs/importance_weights/src/main.cpp   (contents, props changed)
   sandbox/statistics/iterator/
   sandbox/statistics/iterator/boost/
   sandbox/statistics/iterator/boost/iterator/
   sandbox/statistics/iterator/boost/iterator/cycle_iterator2_ext.hpp   (contents, props changed)
   sandbox/statistics/iterator/boost/iterator/cycle_iterator_ext.hpp   (contents, props changed)
   sandbox/statistics/iterator/boost/iterator/range_cycle.hpp   (contents, props changed)
   sandbox/statistics/iterator/libs/
   sandbox/statistics/iterator/libs/iterator/
   sandbox/statistics/iterator/libs/iterator/doc/
   sandbox/statistics/iterator/libs/iterator/doc/readme.txt   (contents, props changed)
   sandbox/statistics/iterator/libs/iterator/example/
   sandbox/statistics/iterator/libs/iterator/example/range_cycle.cpp   (contents, props changed)
   sandbox/statistics/iterator/libs/iterator/example/range_cycle.h   (contents, props changed)
   sandbox/statistics/iterator/libs/iterator/src/
   sandbox/statistics/iterator/libs/iterator/src/main.cpp   (contents, props changed)
   sandbox/statistics/joint_dist/
   sandbox/statistics/joint_dist/boost/
   sandbox/statistics/joint_dist/boost/joint_dist/
   sandbox/statistics/joint_dist/boost/joint_dist/distribution/
   sandbox/statistics/joint_dist/boost/joint_dist/distribution/detail/
   sandbox/statistics/joint_dist/boost/joint_dist/distribution/detail/dim.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/distribution/iid.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/distribution/independent.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/distributions/
   sandbox/statistics/joint_dist/boost/joint_dist/distributions/iid.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/distributions/independent.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/
   sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/detail/
   sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/detail/fun_wrap.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/include.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/log_unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/meta/
   sandbox/statistics/joint_dist/boost/joint_dist/meta/delegate.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/meta/is_joint_dist.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/meta/pointer.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/meta/signature.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/random/
   sandbox/statistics/joint_dist/boost/joint_dist/random/generate_n.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/random/iid.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/random/independent.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/boost/joint_dist/unscope/
   sandbox/statistics/joint_dist/boost/joint_dist/unscope/log_unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/joint_dist/libs/
   sandbox/statistics/joint_dist/libs/joint_dist/
   sandbox/statistics/joint_dist/libs/joint_dist/doc/
   sandbox/statistics/joint_dist/libs/joint_dist/doc/readme.txt   (contents, props changed)
   sandbox/statistics/joint_dist/libs/joint_dist/example/
   sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.cpp   (contents, props changed)
   sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.h   (contents, props changed)
   sandbox/statistics/joint_dist/libs/joint_dist/src/
   sandbox/statistics/joint_dist/libs/joint_dist/src/main.cpp   (contents, props changed)
   sandbox/statistics/kernel/
   sandbox/statistics/kernel/boost/
   sandbox/statistics/kernel/boost/kernel/
   sandbox/statistics/kernel/boost/kernel/bandwidth/
   sandbox/statistics/kernel/boost/kernel/bandwidth/normal_distribution.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/
   sandbox/statistics/kernel/boost/kernel/functional/benchmark_nw.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/benchmark_rp.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/detail/
   sandbox/statistics/kernel/boost/kernel/functional/detail/mean_accumulator.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/detail/return_if.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/estimator.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/nw_visitor.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/nw_visitor_tuple.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/functional/rp_visitor.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/kernel/
   sandbox/statistics/kernel/boost/kernel/kernel/crtp.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/kernel/multi.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/kernel/scalar/
   sandbox/statistics/kernel/boost/kernel/kernel/scalar/crtp.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/kernel/scalar/gaussian.hpp   (contents, props changed)
   sandbox/statistics/kernel/boost/kernel/meta/
   sandbox/statistics/kernel/libs/
   sandbox/statistics/kernel/libs/kernel/
   sandbox/statistics/kernel/libs/kernel/doc/
   sandbox/statistics/kernel/libs/kernel/doc/readme.txt   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/
   sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.cpp   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.h   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/multi_rp.cpp   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/multi_rp.h   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/scalar_nw.cpp   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/scalar_nw.h   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/scalar_rp.cpp   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/example/scalar_rp.h   (contents, props changed)
   sandbox/statistics/kernel/libs/kernel/src/
   sandbox/statistics/kernel/libs/kernel/src/main.cpp   (contents, props changed)
   sandbox/statistics/matrix_view/
   sandbox/statistics/matrix_view/boost/
   sandbox/statistics/matrix_view/boost/matrix_view/
   sandbox/statistics/matrix_view/boost/matrix_view/algorithm/
   sandbox/statistics/matrix_view/boost/matrix_view/algorithm/main.cpp   (contents, props changed)
   sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp   (contents, props changed)
   sandbox/statistics/matrix_view/boost/matrix_view/iterator/
   sandbox/statistics/matrix_view/boost/matrix_view/iterator/row_iterator.hpp   (contents, props changed)
   sandbox/statistics/matrix_view/libs/
   sandbox/statistics/matrix_view/libs/matrix_view/
   sandbox/statistics/matrix_view/libs/matrix_view/doc/
   sandbox/statistics/matrix_view/libs/matrix_view/doc/readme.txt   (contents, props changed)
   sandbox/statistics/matrix_view/libs/matrix_view/example/
   sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.cpp   (contents, props changed)
   sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.h   (contents, props changed)
   sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.cpp   (contents, props changed)
   sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.h   (contents, props changed)
   sandbox/statistics/matrix_view/libs/matrix_view/src/
   sandbox/statistics/model/
   sandbox/statistics/model/boost/
   sandbox/statistics/model/boost/model/
   sandbox/statistics/model/boost/model/algorithm/
   sandbox/statistics/model/boost/model/algorithm/include.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/algorithm/log_likelihood.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/algorithm/log_likelihoods.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/algorithm/log_posteriors.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/functional/
   sandbox/statistics/model/boost/model/functional/include.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/functional/log_likelihood_accumulator.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/functional/log_likelihood_evaluator.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/functional/log_posterior_evaluator.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/include.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/
   sandbox/statistics/model/boost/model/wrap/aggregate/
   sandbox/statistics/model/boost/model/wrap/aggregate/data.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/dataset.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/model_covariate_parameter.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/model_data.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/model_dataset.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/model_parameter.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/aggregate/prior_model_dataset.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/include.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/
   sandbox/statistics/model/boost/model/wrap/unary/covariate.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/covariates.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/detail/
   sandbox/statistics/model/boost/model/wrap/unary/detail/base.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/model.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/parameter.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/prior.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/response.hpp   (contents, props changed)
   sandbox/statistics/model/boost/model/wrap/unary/responses.hpp   (contents, props changed)
   sandbox/statistics/model/libs/
   sandbox/statistics/model/libs/model/
   sandbox/statistics/model/libs/model/doc/
   sandbox/statistics/model/libs/model/doc/readme.txt   (contents, props changed)
   sandbox/statistics/monomials_horner/
   sandbox/statistics/monomials_horner/boost/
   sandbox/statistics/monomials_horner/boost/monomials_horner/
   sandbox/statistics/monomials_horner/boost/monomials_horner/monomials.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/monomials_properties.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes_derived.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/policy/
   sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_degree.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_factorial.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_power2divfact.hpp   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/
   sandbox/statistics/monomials_horner/libs/monomials_horner/
   sandbox/statistics/monomials_horner/libs/monomials_horner/doc/
   sandbox/statistics/monomials_horner/libs/monomials_horner/doc/readme.txt   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.cpp   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.h   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.cpp   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.h   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.cpp   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.h   (contents, props changed)
   sandbox/statistics/monomials_horner/libs/monomials_horner/src/
   sandbox/statistics/monomials_horner/libs/monomials_horner/src/main.cpp   (contents, props changed)
   sandbox/statistics/mpl/
   sandbox/statistics/mpl/boost/
   sandbox/statistics/mpl/boost/mpl/
   sandbox/statistics/mpl/boost/mpl/nested_type.hpp   (contents, props changed)
   sandbox/statistics/nn1/
   sandbox/statistics/nn1/boost/
   sandbox/statistics/nn1/boost/nn1/
   sandbox/statistics/nn1/boost/nn1/algorithm/
   sandbox/statistics/nn1/boost/nn1/algorithm/find.hpp   (contents, props changed)
   sandbox/statistics/nn1/boost/nn1/algorithm/find_if.hpp   (contents, props changed)
   sandbox/statistics/nn1/boost/nn1/algorithm/min_element.hpp   (contents, props changed)
   sandbox/statistics/nn1/boost/nn1/detail/
   sandbox/statistics/nn1/boost/nn1/detail/ui_abs_to.hpp   (contents, props changed)
   sandbox/statistics/nn1/boost/nn1/functional/
   sandbox/statistics/nn1/boost/nn1/functional/find_if.hpp   (contents, props changed)
   sandbox/statistics/nn1/libs/
   sandbox/statistics/nn1/libs/nn1/
   sandbox/statistics/nn1/libs/nn1/doc/
   sandbox/statistics/nn1/libs/nn1/doc/readme.txt   (contents, props changed)
   sandbox/statistics/nn1/libs/nn1/example/
   sandbox/statistics/nn1/libs/nn1/example/find_if.cpp   (contents, props changed)
   sandbox/statistics/nn1/libs/nn1/example/find_if.h   (contents, props changed)
   sandbox/statistics/nn1/libs/nn1/src/
   sandbox/statistics/nn1/libs/nn1/src/main.cpp   (contents, props changed)
   sandbox/statistics/non_param/
   sandbox/statistics/non_param/boost/
   sandbox/statistics/non_param/boost/non_param/
   sandbox/statistics/non_param/boost/non_param/algorithm/
   sandbox/statistics/non_param/boost/non_param/algorithm/cdf_empirical_cdf_differences.hpp   (contents, props changed)
   sandbox/statistics/non_param/boost/non_param/algorithm/kolmogorov_smirnov_distance.hpp   (contents, props changed)
   sandbox/statistics/non_param/boost/non_param/algorithm/proportion_less_than.hpp   (contents, props changed)
   sandbox/statistics/non_param/boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp   (contents, props changed)
   sandbox/statistics/non_param/libs/
   sandbox/statistics/non_param/libs/non_param/
   sandbox/statistics/non_param/libs/non_param/doc/
   sandbox/statistics/non_param/libs/non_param/doc/readme.txt   (contents, props changed)
   sandbox/statistics/non_param/libs/non_param/example/
   sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.cpp   (contents, props changed)
   sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.h   (contents, props changed)
   sandbox/statistics/non_param/libs/non_param/src/
   sandbox/statistics/non_param/libs/non_param/src/main.cpp   (contents, props changed)
   sandbox/statistics/random/
   sandbox/statistics/random/boost/
   sandbox/statistics/random/boost/random/
   sandbox/statistics/random/boost/random/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/gen_to_random.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/include.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/location_scale.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/multinomial_distribution.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/ref_distribution.hpp   (contents, props changed)
   sandbox/statistics/random/boost/random/students_t.hpp   (contents, props changed)
   sandbox/statistics/random/libs/
   sandbox/statistics/random/libs/random/
   sandbox/statistics/random/libs/random/doc/
   sandbox/statistics/random/libs/random/doc/readme.txt   (contents, props changed)
   sandbox/statistics/random/libs/random/src/
   sandbox/statistics/random/libs/random/src/main.cpp   (contents, props changed)
   sandbox/statistics/readme.txt   (contents, props changed)
   sandbox/statistics/scalar_dist/
   sandbox/statistics/scalar_dist/boost/
   sandbox/statistics/scalar_dist/boost/scalar_dist/
   sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/
   sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/accumulate.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/transform.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/cdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/detail/
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/quantile.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/
   sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/inverse_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/product_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/ratio_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/bind_delegate.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/delegate.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/distribution_base.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/has_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/is_scalar_dist.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/pointer.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/meta/signature.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/
   sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/include.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/log_unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/scalar_dist/libs/
   sandbox/statistics/scalar_dist/libs/scalar_dist/
   sandbox/statistics/scalar_dist/libs/scalar_dist/doc/
   sandbox/statistics/scalar_dist/libs/scalar_dist/doc/readme.txt   (contents, props changed)
   sandbox/statistics/scalar_dist/libs/scalar_dist/example/
   sandbox/statistics/scalar_dist/libs/scalar_dist/src/
   sandbox/statistics/scalar_dist/libs/scalar_dist/src/main.cpp   (contents, props changed)
   sandbox/statistics/standard_distribution/
   sandbox/statistics/standard_distribution/boost/
   sandbox/statistics/standard_distribution/boost/standard_distribution/
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/exponential.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/gamma.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/include.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/location_scale.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/students_t.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/uniform.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/exponential.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/gamma.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/location_scale.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/students_t.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/uniform.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/normalizing_constant/
   sandbox/statistics/standard_distribution/boost/standard_distribution/normalizing_constant/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/exponential.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/gamma.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/include.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/students_t.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/os/uniform.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/exponential.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/gamma.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/location_scale.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/meta.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/students_t.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/uniform.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/serialize/
   sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/
   sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/include.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/location_scale.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/chi_squared.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/exponential.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/gamma.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/include.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/normal.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/students_t.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/uniform.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/
   sandbox/statistics/standard_distribution/libs/standard_distribution/
   sandbox/statistics/standard_distribution/libs/standard_distribution/doc/
   sandbox/statistics/standard_distribution/libs/standard_distribution/doc/readme.txt   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/standard_distribution/example/
   sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.cpp   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.h   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.cpp   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.h   (contents, props changed)
   sandbox/statistics/standard_distribution/libs/standard_distribution/src/
   sandbox/statistics/standard_distribution/libs/standard_distribution/src/main.cpp   (contents, props changed)
   sandbox/statistics/survival_data/
   sandbox/statistics/survival_data/boost/
   sandbox/statistics/survival_data/boost/survival/
   sandbox/statistics/survival_data/boost/survival/constant.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/
   sandbox/statistics/survival_data/boost/survival/data/algorithm/
   sandbox/statistics/survival_data/boost/survival/data/algorithm/detail/
   sandbox/statistics/survival_data/boost/survival/data/algorithm/detail/log_shift.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/algorithm/events.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/algorithm/include.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/algorithm/logit_log.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/algorithm/mean_events_by_covariate.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/algorithm/vectorize_events.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/data/
   sandbox/statistics/survival_data/boost/survival/data/data/event.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/data/include.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/data/mean_event.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/data/record.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/include.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/meta/
   sandbox/statistics/survival_data/boost/survival/data/meta/failure_distribution.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/meta/failure_random.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/meta/include.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/meta/random_input.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/random/
   sandbox/statistics/survival_data/boost/survival/data/random/batch.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/random/default_batch.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/random/failure_time.hpp   (contents, props changed)
   sandbox/statistics/survival_data/boost/survival/data/random/include.hpp   (contents, props changed)
   sandbox/statistics/survival_data/libs/
   sandbox/statistics/survival_data/libs/survival/
   sandbox/statistics/survival_data/libs/survival/data/
   sandbox/statistics/survival_data/libs/survival/data/doc/
   sandbox/statistics/survival_data/libs/survival/data/doc/readme.txt   (contents, props changed)
   sandbox/statistics/survival_data/libs/survival/data/example/
   sandbox/statistics/survival_data/libs/survival/data/example/data.cpp   (contents, props changed)
   sandbox/statistics/survival_data/libs/survival/data/example/data.h   (contents, props changed)
   sandbox/statistics/survival_data/libs/survival/data/example/random.cpp   (contents, props changed)
   sandbox/statistics/survival_data/libs/survival/data/example/random.h   (contents, props changed)
   sandbox/statistics/survival_data/libs/survival/data/src/
   sandbox/statistics/survival_data/libs/survival/data/src/main.cpp   (contents, props changed)
   sandbox/statistics/survival_model/
   sandbox/statistics/survival_model/boost/
   sandbox/statistics/survival_model/boost/survival/
   sandbox/statistics/survival_model/boost/survival/model/
   sandbox/statistics/survival_model/boost/survival/model/algorithm/
   sandbox/statistics/survival_model/boost/survival/model/algorithm/include.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/algorithm/prepare_weights.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/include.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/meta/
   sandbox/statistics/survival_model/boost/survival/model/meta/data.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/meta/include.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/meta/model_data.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/meta/response.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/models/
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/detail/
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/detail/log_likelihood.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/include.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/log_likelihood.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/meta_failure_distribution.hpp   (contents, props changed)
   sandbox/statistics/survival_model/boost/survival/model/models/exponential/model.hpp   (contents, props changed)
   sandbox/statistics/survival_model/libs/
   sandbox/statistics/survival_model/libs/survival/
   sandbox/statistics/survival_model/libs/survival/model/
   sandbox/statistics/survival_model/libs/survival/model/doc/
   sandbox/statistics/survival_model/libs/survival/model/doc/readme.txt   (contents, props changed)
   sandbox/statistics/survival_model/libs/survival/model/example/
   sandbox/statistics/survival_model/libs/survival/model/example/exponential.cpp   (contents, props changed)
   sandbox/statistics/survival_model/libs/survival/model/example/exponential.h   (contents, props changed)
   sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.cpp   (contents, props changed)
   sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.h   (contents, props changed)
   sandbox/statistics/survival_model/libs/survival/model/src/
   sandbox/statistics/survival_model/libs/survival/model/src/main.cpp   (contents, props changed)
   sandbox/statistics/tree/
   sandbox/statistics/tree/boost/
   sandbox/statistics/tree/boost/tree/
   sandbox/statistics/tree/boost/tree/node.hpp   (contents, props changed)
   sandbox/statistics/tree/boost/tree/stage.hpp   (contents, props changed)
   sandbox/statistics/tree/libs/
   sandbox/statistics/tree/libs/doc/
   sandbox/statistics/tree/libs/doc/readme.txt   (contents, props changed)
   sandbox/statistics/tree/libs/src/
   sandbox/statistics/tree/libs/src/main.cpp   (contents, props changed)
   sandbox/statistics/tree/libs/tree/
   sandbox/statistics/tree/libs/tree/example/
   sandbox/statistics/tree/libs/tree/example/tree.cpp   (contents, props changed)
   sandbox/statistics/tree/libs/tree/example/tree.h   (contents, props changed)
   sandbox/statistics/vector_space/
   sandbox/statistics/vector_space/boost/
   sandbox/statistics/vector_space/boost/vector_space/
   sandbox/statistics/vector_space/boost/vector_space/algorithm/
   sandbox/statistics/vector_space/boost/vector_space/algorithm/find.hpp   (contents, props changed)
   sandbox/statistics/vector_space/boost/vector_space/data/
   sandbox/statistics/vector_space/boost/vector_space/data/detail/
   sandbox/statistics/vector_space/boost/vector_space/data/detail/cref.hpp   (contents, props changed)
   sandbox/statistics/vector_space/boost/vector_space/data/lazy_difference.hpp   (contents, props changed)
   sandbox/statistics/vector_space/boost/vector_space/functional/
   sandbox/statistics/vector_space/boost/vector_space/functional/equal.hpp   (contents, props changed)
   sandbox/statistics/vector_space/boost/vector_space/functional/l2_distance_squared.hpp   (contents, props changed)
   sandbox/statistics/vector_space/libs/
   sandbox/statistics/vector_space/libs/vector_space/
   sandbox/statistics/vector_space/libs/vector_space/doc/
   sandbox/statistics/vector_space/libs/vector_space/doc/readme.txt   (contents, props changed)
   sandbox/statistics/vector_space/libs/vector_space/example/
   sandbox/statistics/vector_space/libs/vector_space/example/difference.cpp   (contents, props changed)
   sandbox/statistics/vector_space/libs/vector_space/example/difference.h   (contents, props changed)
   sandbox/statistics/vector_space/libs/vector_space/example/equal.cpp   (contents, props changed)
   sandbox/statistics/vector_space/libs/vector_space/example/equal.h   (contents, props changed)
   sandbox/statistics/vector_space/libs/vector_space/src/
   sandbox/statistics/vector_space/libs/vector_space/src/main.cpp   (contents, props changed)
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/constant.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/constant.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,53 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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_ARS_CONSTANT_HPP_ER_2009
+#define BOOST_ARS_CONSTANT_HPP_ER_2009
+#include <limits>
+#include <iostream>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace ars{
+
+    template<typename T>
+    struct constant{
+        typedef numeric::converter<T,unsigned> conv_t;
+        static T zero_;
+        static T eps_;
+        static T one_;
+        static T two_;
+        static T lmin_; //exp(lmin_)>eps
+        static T lmax_; //exp(lmax_)<inf
+        static T inf_;
+        static T quiet_nan_;
+        static T sig_nan_;
+    };
+    template<typename T>
+    T constant<T>::zero_ = conv_t::convert(0);
+    template<typename T>
+    T constant<T>::eps_ = boost::math::tools::epsilon<T>();
+    template<typename T>
+    T constant<T>::one_ = conv_t::convert(1);
+    template<typename T>
+    T constant<T>::two_ = conv_t::convert(2);
+    template<typename T>
+    T constant<T>::lmin_ = math::tools::log_min_value<T>();
+    template<typename T>
+    T constant<T>::lmax_ = math::tools::log_max_value<T>();
+    template<typename T>
+    T constant<T>::inf_ = std::numeric_limits<T>::infinity();
+    template<typename T>
+    T constant<T>::quiet_nan_ = std::numeric_limits<T>::quiet_NaN();
+    template<typename T>
+    T constant<T>::sig_nan_ = std::numeric_limits<T>::signaling_NaN();
+
+}
+}
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/area.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/area.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::detail::area.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_ARS_DETAIL_AREA_HPP_ER_2009
+#define BOOST_ARS_DETAIL_AREA_HPP_ER_2009
+#include <stdexcept>
+#include <boost/ars/detail/data.hpp>
+
+namespace boost{
+namespace ars{
+
+// Area of the exponential tangent between two
+// 2 intersections (one of which is possibly -inf or inf).
+
+template<typename T>
+T area_flat_segment(
+    const tangent_intersection<T>& a,
+    const tangent_intersection<T>& b,
+    const T& offset
+){
+    typedef constant<T> const_;
+    T mid = (a.t() + b.t()) / const_::two_;
+    return (b.z() - a.z()) * exp(mid - offset);
+}
+
+template<typename T>
+T area_left_tail(
+    const data<T>& b,
+    const T& offset
+){
+    return exp( b.t() - offset) / b.dy();
+}
+template<typename T>
+T area_right_tail(
+    const tangent_intersection<T>& a,
+    const point<T>& b,
+    const T& offset
+){
+    return - exp( a.t() - offset) / b.dy();
+}
+
+template<typename T>
+T area_segment(
+    const tangent_intersection<T>& a,
+    const data<T>& b,
+    const T& offset
+){
+    typedef constant<T> const_;
+    // Note that b.dy() (a.z_-b.z_) == a.t_ - b.t_
+    T dt  = a.t() - b.t();
+    return exp( b.t() - offset) * (const_::one_ - exp(dt)) / b.dy();
+}
+
+template<typename T>
+T area_segment_safeguarded(
+    const tangent_intersection<T>& a,
+    const data<T>& b,
+    const T& offset
+)
+{
+    typedef constant<T> const_;
+    T area;
+    if(fabs(b.dy())<const_::lmin_){
+        area = area_flat_segment(a,b,offset);
+    }else{
+        if(a.t()-b.t()>const_::lmax_){
+            // exp(a.t_-iter_.t_) = inf,
+            // so 1) not computable and 2) b negligible
+            // This alternative is computable because (in principle)
+            // exp(a.t_- offset) <inf
+            area = area_right_tail(a,b,offset);
+        }else{
+            area = area_segment(a,b,offset);
+        }
+    }
+    return area;
+}
+
+
+}//ars
+}//boost
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/data.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,85 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::detail::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_ARS_DETAIL_DATA_HPP_ER_2009
+#define BOOST_ARS_DETAIL_DATA_HPP_ER_2009
+#include <boost/function.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/ars/constant.hpp>
+#include <boost/ars/point.hpp>
+#include <boost/ars/detail/tangent_intersection.hpp>
+#include <boost/ars/error.hpp>
+namespace boost{
+namespace ars{
+
+template<typename T>
+struct data : point<T>, tangent_intersection<T>{
+    typedef constant<T> const_;
+    typedef point<T> super1;
+    typedef tangent_intersection<T> super2;
+    data():super1(),super2(){}
+    data(const super1& p):super1(p),super2(){}
+    data(const super1& p,const super2& ti):super1(p),super2(ti){}
+
+};
+
+// Warning:
+// Since both point<T> and tangent<T> have operator <,
+// use a const reference to the desired type for a and b
+
+
+template <typename T>
+std::ostream&
+operator<<(std::ostream& out, const data<T> &d){
+    typedef point<T> point_t;
+    typedef tangent_intersection<T> tang_t;
+    const point_t& p = static_cast<const point_t&>(d);
+    const tang_t& ti = static_cast<const tang_t&>(d);
+    out << '(' << p << ',' << ti << ')';
+
+    return out;
+}
+
+
+// Usage:
+//
+// prior(end(datas))->z_ = tangent(prior(end(datas))),
+// adjacent_difference(
+//  make_reverse_iterator(end(datas)),
+//  make_reverse_iterator(begin(datas)),
+//  update_z<T>()
+// );
+
+template<typename T>
+struct update_tangent_intersection{
+    typedef point<T>            point_;
+    typedef const point_&       first_argument_type;
+    typedef const point_&       second_argument_type;
+    typedef data<T>             result_type;
+
+    result_type
+    operator()(first_argument_type a,second_argument_type b)const{
+        result_type result(a,tangent_intersection<T>(a,b));
+        return result;
+    }
+};
+
+struct pred_isinf{
+    typedef bool result_type;
+    // Used by find_if(begin(datas_),end(datas_),pred_isinf)
+    // because had problem with bind etc. (reason: mutable data?)
+    template<typename D>
+    result_type operator()(D& d)const{
+        return math::isinf(d.cum_sum_);
+    }
+};
+
+
+}//ars
+}//boost
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/tangent_intersection.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/detail/tangent_intersection.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,84 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::detail::tangent_intersection.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_ARS_DETAIL_TANGENT_INTERSECTION_HPP_ER_2009
+#define BOOST_ARS_DETAIL_TANGENT_INTERSECTION_HPP_ER_2009
+#include <boost/ars/constant.hpp>
+#include <boost/ars/point.hpp>
+namespace boost{
+namespace ars{
+
+        //    x1  x2  x3            point abscissae
+        //   / \ / \ / \
+        //  z0  z1  z2  z3 = zn     tangent abscissae
+        //
+        // z0 = x_min
+        // zn = x_max
+        // Let tang[i](x) = y[i] + dy[i](x-x[i])
+        // z[i] solves : tang[i+1](z[i]) == tang[i](z[i])
+        // t[i] = tang[i](z[i])
+
+template<typename T>
+struct tangent_intersection{
+    typedef constant<T> const_;
+
+    tangent_intersection()
+    :z_(const_::zero_),
+    t_(const_::zero_),
+    cum_sum_(const_::zero_){}
+
+    tangent_intersection(const point<T>& a,const point<T>& b){
+        T eps = exp(const_::lmin_); //TODO numeric_smallest()?
+        if(fabs(a.y()-b.y()) <= eps){
+            z_ = (a.x() + b.x()) / const_::two_;
+            t_ = (a.y() + b.y()) / const_::two_;
+        }else{
+            T ddy = b.dy() - a.dy();
+            // For greater precision :
+            if(fabs(a.dy())<fabs(b.dy())){
+                z_ = b.x() + (a.y() - b.y() + a.dy() * (b.x() - a.x()))/ddy;
+                t_ = a.y() + a.dy() * (z_ - a.x());
+            }else{
+                z_ = a.x() + (a.y() - b.y() + b.dy() * (b.x() - a.x()))/ddy;
+                t_ = b.y() +  b.dy() * (z_ - b.x());
+            }
+        }
+    }
+
+    tangent_intersection(T z,T t)
+    :z_(z), t_(t),cum_sum_(const_::zero_){}
+
+    const T& z()const{ return z_; }
+    const T& t()const{ return t_; }
+
+    private:
+    T z_; //abscissa
+    T t_; //ordinate
+    public:
+    T cum_sum_; //area under exp tangent up to z_
+};
+
+template <typename T>
+std::ostream&
+operator<<(std::ostream& out, const tangent_intersection<T> &ti)
+{
+    out << '(' << ti.z() << ',' << ti.t() << ',' << ti.cum_sum_ << ')';
+    return out;
+}
+
+template <typename T>
+bool operator<(
+    const tangent_intersection<T> &a,
+    const tangent_intersection<T> &b
+){
+    return (a.cum_sum_ < b.cum_sum_);
+}
+
+}
+}
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,80 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::error.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_ARS_ERROR_HPP_ER_2009
+#define BOOST_ARS_ERROR_HPP_ER_2009
+#include <stdexcept>
+#include <sstream>
+#include <boost/format.hpp>
+namespace boost{
+namespace ars{
+
+        class exception : public std::runtime_error{
+            typedef std::string str_t;
+            public:
+            typedef std::runtime_error super_t;
+            exception(
+                const str_t& a,
+                const str_t& b,
+                const str_t& c
+            ):super_t(this->str(a,b,c)){}
+
+            template<typename T>
+            exception(
+                const str_t& a,
+                const str_t& b,
+                const T& c
+            ):super_t(this->str(a,b,c)){}
+
+            template<typename T,typename U>
+            exception(
+                const str_t& a,
+                const str_t& b,
+                const T& c,
+                const U& d
+            ):super_t(this->str(a,b,c,d)){}
+
+            private:
+            str_t str(
+                const str_t& a,
+                const str_t& b,
+                const str_t& c
+            ){
+                format f("Call : %1%, error: %2%, state : %3%");
+                f % a % b % c;
+                return f.str();
+            }
+            template<typename T>
+            str_t str(
+                const str_t& a,
+                const str_t& b,
+                const T& c
+            ){
+                std::ostringstream os;
+                os << c;
+                return this->str(a, b, os.str());
+            }
+
+            template<typename T,typename U>
+            str_t str(
+                const str_t& a,
+                const str_t& b,
+                const T& c,
+                const U& d
+            ){
+                std::ostringstream os;
+                os << c << d;
+                return this->str(a, b, os.str());
+            }
+
+        };
+
+}//ars
+}//boost
+
+
+#endif // BOOST_ARS_ERROR_HPP_ER_2009
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/function_signature.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/function_signature.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,26 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::function_signature.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_ARS_FUNCTION_SIGNATURE_HPP_ER_2009
+#define BOOST_ARS_FUNCTION_SIGNATURE_HPP_ER_2009
+#include <boost/mpl/identity.hpp>
+
+namespace boost{
+namespace ars{
+
+    // This is the function signature required by the ars sampler.
+    //
+    // Given input x, fun(x, y, dy) writes the log unnormalized pdf and its
+    // derivative at x to y and dy, respectively.
+    template<typename T>
+    struct function_signature : mpl::identity<
+        void(const T&,T&,T&)
+    >{};
+}
+}
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/functional/standard_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/functional/standard_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,97 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::functional::standard_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_ARS_FUNCTIONAL_STANDARD_DISTRIBUTION_HPP_ER_2009
+#define BOOST_ARS_FUNCTIONAL_STANDARD_DISTRIBUTION_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/call_traits.hpp>
+
+namespace boost{
+
+namespace math{
+
+    template<typename D>
+    typename D::value_type  
+    log_unnormalized_pdf( //Fwd Declare
+        const D& d,
+        const typename D::value_type& x
+    );
+
+    template<typename D>
+    typename D::value_type  
+    derivative_log_unnormalized_pdf( //Fwd Declare
+        const D& d,
+        const typename D::value_type& x
+    );
+
+}
+
+namespace ars{
+namespace functional{
+
+// Maps a subset of the free functions associated with a distribution (D) to
+// a functor with the required signature.
+//
+// Requirements:
+// D::value_type is defined and we call it T. Let x and d instances of T and D.
+// Expression                               Returns
+// log_unnormalized_pdf(d,x)                object of type T
+// derivative_log_unnormalized_pdf(d,x)     object of type T
+// For distributions such as exponential, normal etc. these are defined
+// by the same author in standard_distribution/unnormalized_pdf
+template<typename D>
+class standard_distribution {
+
+    typedef typename remove_const<
+        typename remove_reference<
+            D
+        >::type
+    >::type dist_t;
+
+    public:
+    typedef typename dist_t::value_type      value_type;
+    typedef typename dist_t::policy_type     policy_type;
+    typedef standard_distribution<dist_t>    base_type;
+
+    standard_distribution(typename call_traits<D>::param_type d):d_(d){}
+    standard_distribution(const standard_distribution& that):d_(that.d_){}
+
+    standard_distribution&
+    operator=(const standard_distribution& that){
+        if(&that!=this){
+            d_ = that.d_;
+        }
+        return *this;
+    }
+
+    void operator()(
+        const value_type& x,
+        value_type& log_pdf,
+        value_type& dlog_pdf
+    ){
+        //math::log_unnormalized_pdf
+        log_pdf = log_unnormalized_pdf(
+            this->distribution(),x);
+            
+        dlog_pdf = derivative_log_unnormalized_pdf(
+            this->distribution(),x);
+    }
+
+    typename call_traits<D>::const_reference distribution()const{
+        return d_;
+    }
+
+    private:
+        typename call_traits<D>::value_type d_;
+
+};
+
+}
+}
+}
+#endif
+
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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_ARS_INCLUDE_HPP_ER_2009
+#define BOOST_ARS_INCLUDE_HPP_ER_2009
+
+#include <boost/ars/constant.hpp>
+#include <boost/ars/proposal_sampler.hpp>
+#include <boost/ars/sampler.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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_ARS_PARAMETER_HPP_ER_2009
+#define BOOST_ARS_PARAMETER_HPP_ER_2009
+#include <boost/math/tools/precision.hpp>
+#include <boost/ars/constant.hpp>
+
+namespace boost{
+namespace ars{
+
+// These parameters are used as defaults, but they can be changed at
+// runtime with sampler's interface.
+//
+// max_data_count:
+// The algorithm switches to standard rejection sampling once this
+// number is reached. Complex distributions may require a higher number.
+//
+// max_log:
+// The higher this number, the greater the precision, but it should not
+// exceed const_::lmax_.
+// A lower number may be needed to ensure finiteness of certain
+// quantities (?) such as cum_sum.
+template<typename T>
+struct parameter{
+    static unsigned max_data_count;
+    static T max_log;
+    static std::size_t reserve;
+    static unsigned n_max_reject;
+};
+template<typename T> unsigned parameter<T>::max_data_count = 20;
+template<typename T>
+T parameter<T>::max_log = constant<T>::lmax_/static_cast<T>(max_data_count);
+template<typename T> std::size_t parameter<T>::reserve = 5;
+template<typename T> unsigned parameter<T>::n_max_reject = 1e2;
+
+}
+}
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/point.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/point.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,101 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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_ARS_POINT_HPP_ER_2009
+#define BOOST_ARS_POINT_HPP_ER_2009
+#include <ostream>
+#include <boost/ars/constant.hpp>
+
+namespace boost{
+namespace ars{
+
+// Given an unnormalized density f, this class is a representation for (x,y,dy), 
+// where y = log f(x).
+template <typename T>
+class point{
+    typedef constant<T> const_;
+
+    public:
+    point(): x_(const_::zero_),y_(const_::zero_),dy_(const_::zero_){}
+    point(const T& x,const T& y,const T& dy)
+    : x_(x),y_(y),dy_(dy){}
+
+    const T& x()const{ return x_; }
+    const T& y()const{ return y_; }
+    const T& dy()const{ return dy_; }
+
+    private:
+    //abscissa, ordinate, derivative of the log density
+    T x_, y_, dy_;
+};
+
+template<typename T>
+void dump(const point<T>& p,T& x,T& y,T& dy){
+    x = p.x();
+    y = p.y();
+    dy = p.dy();
+}
+
+template <typename T>
+bool operator<(
+    const point<T> &a,
+    const point<T> &b
+){
+    return (a.x() < b.x());
+}
+
+template <typename T>
+std::ostream&
+operator<<(std::ostream &out, const point<T>& p)
+{
+    out << '(' << p.x() << ',' << p.y() << ',' << p.dy() << ')';
+    return out;
+}
+
+template<typename T,typename F>
+point<T>
+create_point(
+    const T& x,
+    const F& f
+){
+    typedef point<T> result_t;
+    T y, dy;
+    f(x,y,dy);
+    return result_t(x,y,dy);
+}
+
+template<typename T>
+T tangent(const point<T>& a, const T& x){
+    return a.y() + a.dy() * (x-a.x());
+}
+
+template<typename T>
+bool is_non_increasing_dy(const point<T>&a,const point<T>& b){
+    return !(a.dy()<b.dy());
+}
+
+template<typename T>
+bool is_concave(const point<T>&a,const point<T>& b){
+    T t_b = tangent(a,b.x());
+    T t_a = tangent(b,a.x());
+    return !( (t_b < b.y()) || (t_a < a.y()) );
+}
+
+template<typename T>
+T linearly_interpolate(
+    const point<T>& a,
+    const point<T>& b,
+    const T& x
+){
+    T slope =  (b.y() - a.y()) / (b.x() - a.x());
+    return a.y() + (x-a.x()) * slope;
+}
+
+}
+}
+
+#endif // BOOST_ARS_POINT_HPP_ER_2009
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,891 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::proposal_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_ARS_PROPOSAL_SAMPLER_HPP_ER_2009
+#define BOOST_ARS_PROPOSAL_SAMPLER_HPP_ER_2009
+#include <cmath>
+#include <vector>
+#include <iostream> //TODO needed?
+#include <algorithm>
+#include <functional>
+#include <ext/algorithm>
+//#include <typeinfo>
+#include <string>
+#include <iterator>
+#include <numeric>
+#include <limits>
+#include <boost/lambda/lambda.hpp> //what for?
+#include <boost/static_assert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/empty.hpp>
+#include <boost/type_traits/is_base_of.hpp>
+#include <boost/random.hpp>
+#include <boost/range.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/variant.hpp>
+#include <boost/format.hpp>
+//#include <boost/numeric/conversion/converter.hpp>
+//#include <boost/math/tools/precision.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+#include <boost/math/special_functions/log1p.hpp>
+#include <boost/math/special_functions/sign.hpp>
+
+#include <boost/ars/constant.hpp>
+#include <boost/ars/parameter.hpp>
+#include <boost/ars/error.hpp>
+#include <boost/ars/point.hpp>
+#include <boost/ars/function_signature.hpp>
+#include <boost/ars/detail/data.hpp>
+#include <boost/ars/detail/area.hpp>
+
+namespace boost{
+namespace ars{
+
+// The job of this class is to maintain an approximation to the cumulative 
+// density of interest and generate draws from it
+//
+// Requirements:
+// Cont holds the data and is required to be bi-directional and is to be used
+// in conjunction with lower_bound and insert, so deque is asymptotically the 
+// best choice. In practice, though, vector is probably the best choice.
+template<
+    typename T,
+    template<typename,typename> class Cont = std::vector,
+    template<typename> class Alloc = std::allocator
+>
+class proposal_sampler{
+
+    BOOST_STATIC_ASSERT(std::numeric_limits<T>::has_infinity);
+
+    protected:
+    typedef std::string                                         str_t;
+    typedef constant<T>                                         const_;
+    typedef parameter<T>                                        param_;
+    typedef point<T>                                            point_t;
+    typedef tangent_intersection<T>                             tang_t;
+    typedef data<T>                                             data_t;
+    typedef Alloc<data_t>                                       alloc_t;
+    typedef Cont<data_t,alloc_t>                                datas_t;
+    typedef typename range_difference<datas_t>::type            diff_t;
+    typedef typename range_iterator<datas_t>::type              iter_t;
+    typedef uniform_real<T>                                     runif_t;
+
+    public:
+    typedef typename ars::function_signature<T>::type function_signature;
+    typedef function<function_signature>                        delegate_type;
+
+    typedef typename range_size<datas_t>::type                  size_type;
+    typedef T                                                   result_type;
+    typedef typename runif_t::input_type                        input_type;
+
+    proposal_sampler();
+    proposal_sampler(const proposal_sampler& that);
+    proposal_sampler& operator=(const proposal_sampler& that);
+
+    // x_min must be constant<T>::inf_ if unbounded. Likewise x_max
+    // fun's syntax is fun(x,y,dy) writes to x and dy
+    void set_function(T x_min,T x_min,const delegate_type& fun);
+    template<typename R> //Range
+    void initialize(const R& initial_data);
+    void initialize(T x_0,T x_1);
+    // Increasing this number improves precision but may cause
+    // an infinite area (TODO investigate). In doubt, don't use it
+    void set_max_log(T v);
+
+    // Returns true if the draw is accepted, false otherwise
+    template<typename U>
+    bool sample(U &urng,T& draw) const;
+
+    delegate_type function()const{ return fun_; }
+    // Maximum number of evalutions
+    size_type max_data_count()const{ return max_data_count_; }
+
+    const T& x_min() const { return x_min_; }
+    const T& x_max() const { return x_max_; }
+    const datas_t& datas() const { return datas_; }
+
+    T max_log()const{ return max_log_; }
+    T max_tangent()const{ return max_tangent_; }
+    T cum_sum()const{ return cum_sum_; }
+    size_type size_data()const{ return size_datas_; }
+    T inverse_cum_sums(const T& u) const;
+
+    T offset()const; //> exp(t-offset)<inf
+
+    //TODO (RandomDistribution)
+    //os << x;
+    //is >> u;
+    // min()
+    // max()
+
+    std::ostream& description(std::ostream& stream)const;
+
+    protected:
+    template <typename U> iter_t inv_cum_sums_impl(T u,T& q);
+    void update_cum_sums(iter_t iter) const;
+    void insert(const point_t& p,iter_t iter)const;
+    // Returns first iter such that iter->cum_sum_>u
+    iter_t inv_cum_sums_impl(const T& u,T& draw)const;
+
+    delegate_type fun_;
+    T x_min_;
+    mutable T t_min_;
+    T x_max_;
+    bool has_function_,is_initialized_;
+    mutable bool do_update_;
+    size_type max_data_count_;
+    mutable T max_log_;
+    mutable T max_tangent_;
+    mutable T cum_sum_;
+    mutable datas_t datas_;
+    // Calling size(...) is not necessarily O(1) so saving it is prefarable
+    mutable size_type size_datas_;
+    mutable point_t pending_p_;
+    mutable diff_t pending_d_; // distance to where p should be inserted
+};
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+std::ostream&
+operator<<(std::ostream& out, const proposal_sampler<T,Cont,Alloc>& s){
+    return s.description(out);
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+std::ostream&
+proposal_sampler<T,Cont,Alloc>::description(std::ostream& out) const
+{
+    typedef data<T> data_t;
+    //TODO any other relevant info?
+    format f("x_min = %1%, t_min = %2%|");
+    f%x_min()%t_min_;
+    out << f.str();
+    std::copy(
+        begin(datas()),
+        end(datas()),
+        std::ostream_iterator<data_t>(out, "|")
+    );
+    out << ", mt = " << max_tangent() << ",  offset = " << offset();
+
+    return out;
+}
+
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+proposal_sampler<T,Cont,Alloc>::proposal_sampler()
+:
+fun_(),
+x_min_(const_::inf_),
+t_min_(const_::inf_),
+x_max_(const_::inf_),
+has_function_(false),
+is_initialized_(false),
+do_update_(false),
+max_data_count_(param_::max_data_count),
+max_log_(param_::max_log),
+max_tangent_(const_::zero_),
+cum_sum_(const_::zero_),
+datas_(),
+size_datas_(0),
+pending_p_(),
+pending_d_(0)
+{
+    datas_.reserve(param_::reserve);
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+proposal_sampler<T,Cont,Alloc>::proposal_sampler(
+    const proposal_sampler& that)
+:
+fun_( that.fun_ ),
+x_min_( that.x_min_ ),
+t_min_( that.t_min_ ),
+x_max_( that.x_max_ ),
+has_function_( that.has_function_ ),
+is_initialized_( that.is_initialized_ ),
+do_update_( that.do_update_ ),
+max_data_count_( that.max_data_count_ ),
+max_log_( that.max_log_ ),
+max_tangent_( that.max_tangent_ ),
+cum_sum_( that.cum_sum_ ),
+datas_( that.datas_ ),
+size_datas_( that.size_datas_ ),
+pending_p_( that.pending_p_ ),
+pending_d_(that.pending_d_)
+{}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+proposal_sampler<T,Cont,Alloc>&
+proposal_sampler<T,Cont,Alloc>::operator=(const proposal_sampler& that){
+    if(&that!=this){
+        fun_    = that.fun_;
+        x_min_  = that.x_min_;
+        t_min_  = that.t_min_;
+        x_max_  = that.x_max_;
+        has_function_ = that.has_function_;
+        is_initialized_ = that.is_initialized_;
+        do_update_ = that.do_update_;
+        max_data_count_ = that.max_data_count_;
+        max_log_ = that.max_log_;
+        max_tangent_ = that.max_tangent_;
+        cum_sum_ = that.cum_sum_;
+        datas_ = that.datas_;
+        size_datas_ = that.size_datas_;
+        pending_p_ = that.pending_p_;
+        pending_d_ = that.pending_d_;
+    }
+    return *this;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+T proposal_sampler<T,Cont,Alloc>::offset()const{
+    return max_tangent()-max_log();
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+void proposal_sampler<T,Cont,Alloc>::set_max_log(T v){
+    max_log_ = v;
+    update_cum_sums(begin(datas_)); //TODO anything else?
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+void proposal_sampler<T,Cont,Alloc>::set_function(
+    T x_min,
+    T x_max,
+    const delegate_type& fun
+)
+{
+    static const char* method = "ars::proposal_sampler::set_function";
+    x_min_ = x_min;
+    x_max_ = x_max;
+    // removing this-> would create a name conflict
+    if(!math::isinf( this->x_min() )){
+        if(!math::isinf( this->x_max() )){
+            if(!( this->x_min() < this->x_max() )){
+                throw exception(
+                    method,
+                    "x_min > x_max",
+                    *this
+               );
+            }
+        }
+    }
+    fun_ = fun;
+    has_function_ = true;
+    is_initialized_ = false;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+void proposal_sampler<T,Cont,Alloc>::initialize(T x_0,T x_1){
+
+    static const char* method = "ars::proposal_sampler::initialize(%1%,%2%)";
+    typedef std::vector<point_t> vec_t;
+    static vec_t vec;
+
+    if(!has_function_){
+        format f(method); f%x_0%x_1;
+        throw exception(
+            f.str(),
+            "no func",
+            *this
+        );
+    }
+    vec.clear();
+    vec.push_back( create_point<T,delegate_type>(x_0,fun_) );
+    vec.push_back( create_point<T,delegate_type>(x_1,fun_) );
+
+    return initialize(vec);
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+template<typename R> //Range
+void proposal_sampler<T,Cont,Alloc>::initialize(const R& initial_datas){
+    static const char* method
+        = "ars::proposal_sampler::initialize(const R& initial_datas)";
+    {
+        typedef typename range_value<R>::type value_t;
+        BOOST_MPL_ASSERT(
+            (is_base_of<point_t,value_t>)
+        );
+    }
+    if(size(initial_datas)<2){
+        throw exception(
+            method,
+            "size(initial_datas)<2",
+            *this
+        );
+    }
+
+// NB: Gilks also has:
+//      IF ((.NOT.lb).AND.(hpx(iwv(1)).LT.eps)) ifault=3
+//      IF ((.NOT.ub).AND.(hpx(iwv(2)).GT.-eps)) ifault=4
+
+    if(
+        math::isinf(x_min())
+    ){
+        T dy = begin(initial_datas)->dy();
+        if(!
+            (
+                dy > const_::zero_
+            )
+        ){
+            throw exception(
+                method,
+                (format("!dy = %1%>0")%dy).str(),
+                *this
+            );
+        }
+        t_min_ = const_::quiet_nan_;
+    }else{
+        t_min_ = tangent(*begin(initial_datas),x_min());
+        max_tangent_ = t_min_;
+    }
+
+    datas_.resize( size(initial_datas) );
+    // Let i,j = 0,...,n-1 iterators for data and initial_data.
+    // At i,j = n-1, *i = *j
+    // for i,j = n-2,...,0, *i = tangent_intersection(*j,*j+1)
+    std::adjacent_difference(
+        make_reverse_iterator(end(initial_datas)),
+        make_reverse_iterator(begin(initial_datas)),
+        make_reverse_iterator(end(datas_)),
+        update_tangent_intersection<T>()
+    );
+
+    iter_t back_iter = prior(end(datas_));
+    {
+        T t = max_element(
+            begin(datas_),back_iter,
+            bind<const T&>( &tang_t::t, _1 )
+        )->t();
+        max_tangent_ = (max_tangent()<t)? t : max_tangent();
+    }
+    const point_t& back_p = static_cast<const point_t&>(*back_iter);
+    tang_t& back_ti = static_cast<tang_t&>(*back_iter);
+
+    if(math::isinf(x_max())){
+        T dy = back_iter->dy();
+        if(
+            !(dy < const_::zero_)
+        ){
+            format f("!dy = %1% <0"); f%dy;
+            throw exception(method,f.str(),*this);
+        }
+        back_ti = tang_t(const_::quiet_nan_,const_::quiet_nan_);
+    }else{
+        back_ti =  tang_t(x_max(),tangent(back_p,x_max()));
+        max_tangent_
+            = (max_tangent()<back_ti.t())? back_ti.t() : max_tangent();
+    }
+
+    update_cum_sums(datas_.begin());
+
+    // Hupper hull > function, the RHS of which is integrable. If the LHS
+    // is not integrable in some segment, a midpoint (or reflection point)
+    // is added.
+    while( math::isinf( cum_sum() ) ) {
+        if(size_data()>max_data_count()){
+            throw exception(
+                method,
+                (format("size_data() = > max_data_count() = %2%")
+                    %size_data()%max_data_count()).str(),
+                *this
+            );
+        }
+        typedef boost::function<const T&(const data_t&)> fun2_t;
+
+        iter_t iter = std::find_if(
+            begin( datas_ ),
+            end( datas_ ),
+            pred_isinf()
+        );
+
+        T new_x;
+        if(next(iter)!=end(datas_)){
+            new_x = iter->z();
+        }else{
+            T x_0, x_1;
+            x_1 = iter->x();
+            if(math::isinf(x_max())){
+                x_0 = prior(iter)->x();
+                //reflection
+                new_x = x_1 + (x_1-x_0); //TODO what if = inf?
+            }else{
+                T x_2 = x_max();
+                new_x = ( x_1 + x_2 )/const_::two_;
+                if((new_x <= x_1)|| (new_x >= x_2))
+                {
+                    throw exception(
+                        method,
+                        "(new_x <= x_1)|| (new_x >= x_2)",
+                        *this
+                    );
+                }
+            }
+        }
+        point_t p = create_point(new_x,fun_);
+        insert(p,iter);
+    }
+    size_datas_ = size(datas_);
+    do_update_ = false;
+    is_initialized_ = true;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+T proposal_sampler<T,Cont,Alloc>::inverse_cum_sums(const T& u) const{
+    T q;
+    inv_cum_sums_impl(u,q);
+    return q;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+typename proposal_sampler<T,Cont,Alloc>::iter_t
+proposal_sampler<T,Cont,Alloc>::inv_cum_sums_impl(
+    const T& u, // in [0,cum_sum_)
+    T& q
+)const
+{
+    static const char* method = "ars::proposal_sampler::inv_cum_sums_impl";
+// What TODO about two consecutives segments with same cum_sum due
+// to roundoff? Is there a case for std::upper_bound vs std::lower_bound
+// upper_bound :  for every iterator j in [first, i), *j <= value
+// lower_bound : for every iterator j in [first, i), *j < value.
+    if(u>cum_sum()){
+        throw exception(
+            method,
+            "u>cum_sum()",
+            *this
+        );
+    }
+    tang_t value;
+    value.cum_sum_ = u;
+    iter_t iter =
+        std::lower_bound(
+            begin(datas_),
+            end(datas_),
+            value
+        );
+
+    //TODO delete ->
+    BOOST_ASSERT(iter!=end(datas_));
+    BOOST_ASSERT(iter->cum_sum_>u);
+    if(iter!=begin(datas_)){
+        BOOST_ASSERT(prior(iter)->cum_sum_<u);
+    }
+    // <-
+    bool skip = false;
+    T lz, lt, x, y, dy, du;
+    dump(*iter,x,y,dy);
+    if( iter != begin(datas_) ){
+        du = u - prior(iter)->cum_sum_;
+        lz = prior(iter)->z();
+        lt = prior(iter)->t();
+    }else{
+        if(math::isinf(x_min())){
+            // with y[i] <- y[i] - offset
+            // solves int[-inf,q]exp(y[i]+dy[i](x-x[i])) dx = u,
+            // <=> y[i]+dy[i](q-x[i]) = log(u * dy[i])
+            q = ( log( dy * u )-( y - offset() ) + x * dy ) / dy;
+            skip = true;
+        }else{
+            du = u;
+            lz = x_min();
+            lt = t_min_;
+        }
+    }
+    if(!skip){
+        // with t[i-1] <- t[i-1] - offset
+        lt -= offset();
+        if(dy < const_::lmin_){
+            // solves int[z[i-1],q] exp(t[i-1]) dx = u - area[i-1]
+            q = lz + du * exp(-lt);
+        }else{
+            // solves int[z[i-1],q] exp(t[i-1]+dy[i](x-z[i-1])) dx = du
+            // <=> q = z[i-1] + log(1 + du * dy[i] / exp(t[i-1]) ) / dy[i]
+            // alt: du * dy[i] = exp( log(du) + log(|dy[i]|) ) * sign(dy[i])
+            T a = log(du) + log(fabs(dy)) - lt;
+            if(a<const_::lmax_){
+                T sign = boost::math::sign(dy);
+                a = exp(a);
+                q = lz + log1p( sign * a ) / dy;
+            }else{
+                q = lz + a / dy;
+            }
+        }
+    }
+
+    //TODO create a local enum
+
+    if(math::isnan(q)){
+        throw exception(method,"isnan(q)",*this);
+    }
+    if(iter!=begin(datas_)){
+        if(q<prior(iter)->z()){
+            throw exception(method,"q<prior z",*this);
+        }
+    }else{
+        if(!math::isinf(x_min())){
+            if(q < x_min()){
+                throw exception(method,"q<x_min",*this);
+            }
+        }
+    }
+    if(
+        ( iter!=end(datas_))
+    ){
+        if(q>iter->z()){
+            throw exception(method,"q>z",*this);
+        }
+    }else{
+        if(q>iter->z()){
+            if( !math::isinf(x_max()) ){
+                throw exception(method,"q>z",*this);
+            }
+        }
+    }
+    return iter;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+template <typename U>
+bool proposal_sampler<T,Cont,Alloc>::sample(U &urng,T& draw) const
+{
+    static const char* method = "ars::proposal_sampler::sample";
+    if(!is_initialized_){
+        throw exception(method,"no init",*this);
+    }
+    if(do_update_){
+        insert(
+            pending_p_,
+            next(
+                boost::begin(datas_),
+                pending_d_
+            )
+        ); 
+        size_datas_ = size(datas_);
+    }
+    bool adaptive = (size_data()<max_data_count());
+
+    //Sample from the upper hull a.k.a the enveloppe
+    T u1, log_u2, upper;
+    {
+        runif_t runif(const_::zero_, cum_sum());
+        u1 = runif(urng);
+    }
+    iter_t iter = inv_cum_sums_impl(u1,draw);
+    upper = tangent(*iter,draw);
+    {
+        runif_t unif(const_::zero_, const_::one_);
+        log_u2 = log(unif(urng));
+    }
+    // Squeezing test
+    bool accept = false;
+    if(adaptive){
+        T lower;
+        // lower is -inf outside (x[1],x[n])
+        if(
+            ( (iter!=begin(datas_)) || (draw>(iter->x())))
+            && ( (iter!=prior(end(datas_))) || (draw<(iter->x())))
+        ){
+            if(draw<=(iter->x())){
+                lower = linearly_interpolate(*prior(iter),*iter,draw);
+            }else{
+                lower = linearly_interpolate(*iter,*next(iter),draw);
+            }
+            accept = ( log_u2 <= (lower-upper) );
+        }else{
+            // lower is -inf outside (x[1],x[n])
+        }
+    }
+    // Rejection test
+    if(!accept){
+        pending_p_ = create_point(draw,fun_);
+        pending_d_ = std::distance(boost::begin(datas_),iter); 
+        if(draw>iter->x()){
+            ++pending_d_; 
+        }
+        accept =  ( log_u2 <= (pending_p_.y() - upper) );
+        do_update_ = adaptive;
+    }
+    return accept;
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+void proposal_sampler<T,Cont,Alloc>::update_cum_sums(iter_t iter) const
+{
+    static const char* method = "ars::proposal_sampler::update_cum_sums";
+    //    x1  x2  x3        point abscissae
+    //   / \ / \ / \
+    //  z0  z1  z2  z3      tangent abscissae
+    //
+    // z0 = x_min
+    // zn = x_max
+    //
+    // Here we compute for each i>=j,
+    // the area under the tangent at x[i] over (z[i-1],z[i])
+    // If z0 = -inf, that's exp(t[1]-offset)/dy[1]
+    // It zn = inf, that's -exp(t[n-1]-offset)/dy[1]
+
+    //bool is_begin = false;
+    T area;
+    tang_t a;
+    if(iter != begin(datas_)) {
+        a = *prior(iter);
+        cum_sum_ = boost::prior(iter)->cum_sum_;
+    }else{
+        cum_sum_ = const_::zero_;
+        if(
+            math::isinf(x_min())
+        ){
+            T dy = iter->dy();
+            if(dy<const_::lmin_){
+                throw; //TODO
+            }else{
+                area = area_left_tail(*iter,offset());
+            }
+        }else{
+            a = tang_t(x_min(),t_min_);
+            area = area_segment_safeguarded(a,*iter,offset());
+        }
+        if(area<const_::zero_){
+            format f("area[%1%] = %2% <0");
+            f%std::distance(begin(datas_),iter)%area;
+            throw exception(method,f.str(),*this);
+        }
+        cum_sum_ += area;
+        iter->cum_sum_ = cum_sum_;
+        a = *iter;
+        ++iter;
+    }
+
+    iter_t j = prior(end(datas_));
+    // TODO adjacent_difference?
+    while(iter!=j){
+        T area = area_segment_safeguarded(a,*iter,offset());
+        if(area<const_::zero_){
+            format f("area[%1%] = %2% < 0");
+            f%std::distance(begin(datas_),iter)%area;
+            throw exception(method,f.str(),*this);
+        }
+        cum_sum_ += area;
+        iter->cum_sum_ = cum_sum_;
+        a = *iter;
+        ++iter;
+    }
+
+    if(
+        math::isinf(x_max())
+    ){
+        area = area_right_tail(a,*iter,offset());
+    }else{
+        area = area_segment_safeguarded(a,*iter,offset());
+    }
+    if(area<const_::zero_){
+        format f("area[n] = %1%<0");
+        f%area;
+        throw exception(method,f.str(),*this);
+    }
+    cum_sum_ += area;
+    iter->cum_sum_ = cum_sum_;
+    ++iter;
+    BOOST_ASSERT(!(iter!=end(datas_)));
+
+    BOOST_ASSERT(
+        is_sorted(
+            begin(datas_),
+            end(datas_),
+            bind<bool>(
+                std::less<tang_t>(),
+                _1,
+                _2
+            )
+        )
+    );
+}
+
+template<
+    typename T,
+    template<typename,typename> class Cont,
+    template<typename> class Alloc
+>
+void proposal_sampler<T,Cont,Alloc>::insert(
+    const point_t& p,
+    iter_t iter
+)const
+{
+    static const char* method = "ars::proposal_sampler::insert";
+
+    if(iter!=end(datas_)){
+        if(!std::less<point_t>()(p,*iter)){
+            throw exception(method,"p>next",*this);
+        }
+    }else{
+        if(!math::isinf(x_max())){
+            if(!p.x()<x_max()){
+                throw exception(method,"p>max",*this);
+            }
+        }
+    }
+
+    if(iter!=begin(datas_)){
+        if(!std::less<point_t>()(*prior(iter),p)){
+            throw exception(method,"p<prior",*this);
+        }
+    }else{
+        if(!math::isinf(x_min())){
+            if(!(p.x()>x_min())){
+                throw exception(method,"p<x_min",*this);
+            }
+        }
+    }
+
+    iter = datas_.insert(iter,p);
+    T m = math::tools::min_value<T>();
+
+    struct local{
+        static T impl(
+            data_t& a,
+            const data_t& b,
+            const proposal_sampler& s
+        ){
+            static const char* method = "ars::proposal_sampler::insert";
+            const point_t& a_p = a;
+            const point_t& b_p = b;
+            if(!(a_p<b_p)){
+                throw exception(method,"a>b",s);
+            }
+            if(!is_non_increasing_dy(a_p,b_p)){
+                throw exception(method,"dy non increasing",s);
+            }
+            if(!is_concave(a,b)){
+                throw exception(method,"not concave",s);
+            }
+            {
+                tang_t& a_ti = a;
+                a_ti = tang_t(a,b);
+            }
+            if(a.z()<a.x()){
+                throw exception(method,"z<x",s);
+            }
+            if(a.z()>b.x()){
+                throw exception(method,"z>next x",s);
+            }
+            return a.t();
+        }
+    };
+
+    if(iter!=begin(datas_)){
+        T t = local::impl(*prior(iter),*iter,*this);
+        m = (m<t)? t : m;
+    }else{
+        if(!math::isinf(x_min())){
+            t_min_ = tangent(*iter,x_min());
+        }
+    }
+    if(next(iter)!=end(datas_)){
+        T t = local::impl(*iter,*next(iter),*this);
+        m = (m<t)? t : m;
+    }else{
+        const point_t& p = (*iter);
+        tang_t& ti = (*iter);
+        if(math::isinf(x_max())){
+            ti = tang_t(const_::quiet_nan_, const_::quiet_nan_);
+        }else{
+            ti = tang_t(x_max(),tangent(p,x_max()));
+            T t = ti.t();
+            m = (m<t)? t : m;
+        }
+    }
+
+    if(max_tangent()<m){
+        max_tangent_ = m;
+        iter = begin(datas_);
+    }else{
+        if(iter!=begin(datas_)){
+            iter = prior(iter);
+        }
+    }
+
+    BOOST_ASSERT(
+        is_sorted(
+            begin(datas_),
+            end(datas_),
+            bind<bool>(
+                std::less<point_t>(),
+                _1,
+                _2
+            )
+        )
+    );
+
+
+    update_cum_sums(iter);
+}
+
+
+}//ars
+}//boost
+
+#endif
+
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,68 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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_ARS_SAMPLER_HPP_ER_2009
+#define BOOST_ARS_SAMPLER_HPP_ER_2009
+#include <boost/ars/error.hpp>
+#include <boost/ars/proposal_sampler.hpp>
+
+namespace boost{
+namespace ars{
+
+// This class adds a rejection steop to proposal_sampler 
+//
+// PropS is an instance of the class template proposal_sampler
+template<typename PropS>
+class sampler : public PropS{
+    typedef PropS super_t;
+    public:
+
+    sampler():
+    super_t(),n_max_reject_(super_t::param_::n_max_reject),n_reject_(0){}
+
+    sampler(const sampler& that)
+    :PropS(that),n_max_reject_(that.n_max_reject_),n_reject_(that.n_reject_)
+    {}
+
+    sampler& operator=(const sampler& that){
+        if(&that!=this){
+            PropS::operator=(that);
+            n_max_reject_ = that.n_max_reject_;
+            n_reject_ = that.n_reject_;
+        }
+        return *this;
+    }
+
+    void set_n_max_reject(unsigned n){ n_max_reject_ = n; }
+
+    template<typename U>
+    typename super_t::result_type operator()(U& u)const{
+        static const char* method
+            = "ars::sampler::operator()(U&) after n = %1%";
+        typename super_t::result_type draw;
+        for(typename super_t::size_type i = 0; i<n_max_reject(); i++){
+            n_reject_ = i;
+            if(this->sample(u,draw)){
+                return draw;
+            }
+        }
+        format f(method); f%n_max_reject();
+        throw exception(method,f.str(),*this);
+    }
+    typename super_t::size_type n_max_reject()const{ return n_max_reject_; }
+    typename super_t::size_type n_reject()const{ return n_reject_; }
+
+    protected:
+    typename super_t::size_type n_max_reject_;
+    mutable typename super_t::size_type n_reject_;
+};
+
+
+}//ars
+}//boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,160 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::search_reflection.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_ARS_SEARCH_REFLECTION_HPP_ER_2009
+#define BOOST_ARS_SEARCH_REFLECTION_HPP_ER_2009
+#include <string>
+#include <boost/format.hpp>
+#include <boost/function.hpp>
+#include <boost/ars/constant.hpp>
+#include <boost/ars/point.hpp>
+#include <boost/ars/error.hpp>
+#include <boost/ars/function_signature.hpp>
+#include <boost/ars/functional/standard_distribution.hpp>
+
+namespace boost{
+namespace ars{
+
+// This function searches by reflection for initial starting points 
+// (x_0,x_1) such that if x_min = -inf, dy_0>0 and if x_min = inf, dy_0<0
+
+//TODO even if x_min or x_max finite, |dy|>eps might be desirable
+template<typename T>
+unsigned
+search_reflection(
+    const T& x_min,
+    const T& x_max,
+    function<typename ars::function_signature<T>::type> delegate,
+    point<T>& p_0,
+    point<T>& p_1,
+    unsigned n_max
+){
+    static const char* function
+    = "search_reflection(%1%, %2%, ...)";
+
+    typedef point<T> point_t;
+    typedef constant<T> const_;
+
+    struct local{
+        static bool ok_0(const point_t& p){ 
+            return ( p.dy() >=  const_::eps_ ); }
+        static bool ok_1(const point_t& p){ 
+            return ( p.dy() <= (-const_::eps_) ); }
+    };
+
+    unsigned n = 0;
+    T new_x_0 = p_0.x();
+    T new_x_1 = p_1.x();
+    bool ok_0, ok_1 = true;
+    if(math::isinf(x_min)){ ok_0 = local::ok_0(p_0); }
+    if(math::isinf(x_max)){ ok_1 = local::ok_1(p_1); }
+
+    while(
+        (!(ok_0 && ok_1))
+    ){
+        if(n>n_max){
+            format f(function);
+            f % x_min % x_max;
+            throw ars::exception(f.str(),"n>n_max",p_0,p_1);
+        }
+
+        if(!ok_0){
+            T delta = (new_x_1-new_x_0);
+            if(delta < const_::eps_ ){
+                format f(function);
+                f % x_min % x_max;
+                throw ars::exception(
+                    f.str(),
+                    "new_x_0-new_x_1< (- const_::eps_)",
+                    p_0,p_1
+                );
+            }
+            //TODO max(new_x_0,-highest) ?
+            new_x_0 -=  delta;
+            p_0 = create_point<T>(new_x_0,delegate);
+            ok_0 = local::ok_0(p_0);
+        }
+        if(!ok_1){
+            T delta = (new_x_1-new_x_0);
+            if( delta < const_::eps_){
+                format f(function);
+                f % x_min % x_max;
+                throw ars::exception(
+                    f.str(),
+                    "new_x_1-new_x_0 > const_::eps_",
+                    p_0,p_1
+                );
+            }
+            new_x_1 += delta;
+            p_1 = create_point<T>(new_x_1,delegate);
+            ok_1 = local::ok_1(p_1);
+        }
+        ++n;
+    }
+    return n;
+}
+
+template<typename T>
+unsigned search_reflection(
+    const T& x_min,
+    const T& x_max,
+    function<typename ars::function_signature<T>::type> delegate,
+    const T& x_0,
+    const T& x_1,
+    point<T>& p_0,
+    point<T>& p_1,
+    unsigned n_max
+){
+    {
+        p_0 = create_point<T>(x_0,delegate);
+        p_1 = create_point<T>(x_1,delegate);
+    }
+    return search_reflection(
+        x_min,
+        x_max,
+        delegate,
+        p_0,
+        p_1,
+        n_max
+    );
+}
+
+// TODO theck that
+// T = remove_const< remove_reference< D> ::type >::type ::value_type
+template<typename D,typename T> // D = const E& or E
+unsigned search_reflection_dist(
+    const T& x_min,
+    const T& x_max,
+    const D& dist,
+    const T& x_0,
+    const T& x_1,
+    ars::point<T>& p_0,
+    ars::point<T>& p_1,
+    unsigned n_max
+){
+    typedef ars::functional::standard_distribution<const D&> fnal_t;
+    typedef typename ars::function_signature<T>::type   signature;
+    typedef boost::function<signature>                  delegate_t;
+    fnal_t fnal(dist);
+
+    return search_reflection<T>(
+        x_min,
+        x_max,
+        fnal, //automatic conversion
+        x_0,
+        x_1,
+        p_0,
+        p_1,
+        n_max
+    );
+}
+
+
+}//ars
+}//boost
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/gamma_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/gamma_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,68 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::test::gamma_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)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_ARS_TEST_GAMMA_DISTRIBUTION_HPP_ER_2009
+#define BOOST_ARS_TEST_GAMMA_DISTRIBUTION_HPP_ER_2009
+#include <iostream>
+#include <string>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/standard_distribution/distributions/gamma.hpp>
+#include <boost/ars/test/standard_distribution.hpp>
+
+namespace boost{
+namespace ars{
+namespace test{
+
+// Same as standard_distribution but for a specific distribution
+template<typename T>
+void gamma_distribution(
+    T shape,  // must be > 1
+    T scale,
+    T init_0, // must be >0 and < init_1
+    T init_1, // must be > mode = (m-1) * theta
+    unsigned draw_n,
+    unsigned repeat_n,
+    unsigned n_max_reject,
+    std::ostream& out
+)
+{
+
+    using namespace boost;
+    using namespace math;
+    using namespace assign;
+    typedef double                                          val_;
+    typedef ars::constant<val_>                             const_;
+    typedef math::gamma_distribution<val_>                  mdist_t;
+    typedef boost::mt19937                                  urng_;
+
+    format f("Gamma(%1%,%2%) : "); f%shape%scale;
+    out << f.str();
+    mdist_t mdist(shape,scale);
+    urng_ urng;
+
+    const val_ inf_ = const_::inf_;
+
+    boost::ars::test::standard_distribution(
+        mdist,
+        static_cast<val_>(0),   // x_min
+        inf_,                   // x_max
+        init_0,                 
+        init_1, 
+        urng,   
+        n_max_reject,
+        draw_n,
+        repeat_n,
+        out
+    );
+}
+
+}//test
+}//ars
+}//boost
+
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/normal_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/normal_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,67 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::test::normal_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)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_ARS_TEST_NORMAL_DISTRIBUTION_HPP_ER_2009
+#define BOOST_ARS_TEST_NORMAL_DISTRIBUTION_HPP_ER_2009
+#include <iostream>
+#include <string>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/ars/test/standard_distribution.hpp>
+
+namespace boost{
+namespace ars{
+namespace test{
+
+// Same as standard_distribution but for a specific distribution
+template<typename T>
+void normal_distribution(
+    T mu,
+    T sigma,
+    T init_0, //must be < mu
+    T init_1, //must be > mu
+    unsigned draw_n,
+    unsigned repeat_n,
+    unsigned n_max_reject,
+    std::ostream& out
+)
+{
+
+    using namespace boost;
+    using namespace math;
+    using namespace assign;
+    typedef double                                          value_t;
+    typedef ars::constant<value_t>                          const_;
+    typedef math::normal_distribution<value_t>              mdist_t;
+    typedef boost::mt19937                                  urng_t;
+
+    const value_t inf_ = const_::inf_;
+
+    format f("N(0,%1%) : "); f%sigma;
+    out << f.str();
+    mdist_t mdist(mu,sigma);
+    urng_t urng;
+
+    standard_distribution(
+        mdist,
+        inf_,
+        inf_,
+        init_0,
+        init_1,
+        urng,
+        n_max_reject,
+        draw_n,
+        repeat_n,
+        out
+    );
+}
+
+}//test
+}//ars
+}//boost
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,133 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::test::standard_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_ARS_TEST_STANDARD_DISTRIBUTION_HPP_ER_2009
+#define BOOST_ARS_TEST_STANDARD_DISTRIBUTION_HPP_ER_2009
+
+#include <iostream>
+#include <list>
+#include <string>
+#include <iterator>
+#include <vector>
+#include <algorithm>
+
+#include <boost/assert.hpp>
+#include <boost/assert.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/assign/std/vector.hpp>
+
+//#include <boost/math/distributions/unnormalized_pdf/include.hpp>
+//#include <boost/math/distributions/algorithm/transform.hpp>
+
+#include <boost/non_param/algorithm/kolmogorov_smirnov_distance.hpp>
+
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/ref_distribution.hpp>
+
+#include <boost/ars/functional/standard_distribution.hpp>
+#include <boost/ars/constant.hpp>
+#include <boost/ars/proposal_sampler.hpp>
+#include <boost/ars/sampler.hpp>
+
+namespace boost{
+namespace ars{
+namespace test{
+
+// This function draws repeat_n times by increments of draw_n
+// and ouputs the corresponding kolmogorov_distance for distribution D
+// and the number of rejections. D is a standard distribution
+// such as math::normal_distribution
+template<typename D,typename U>
+void standard_distribution(
+    const D& mdist, //e.g. D == math::normal_distribution
+    typename D::value_type x_min,
+    typename D::value_type x_max,
+    typename D::value_type init_0,
+    typename D::value_type init_1,
+    U& urng,
+    unsigned n_max_reject,
+    unsigned draw_n,
+    unsigned repeat_n,
+    std::ostream& out
+){
+    using namespace boost;
+    using namespace math;
+    using namespace assign;
+    typedef std::string                                     str_;
+    typedef std::runtime_error                              err_;
+    typedef typename D::value_type                          val_;
+    typedef std::vector<val_>                               vals_;
+    typedef std::vector<unsigned>                           ints_;
+
+    typedef ars::functional::standard_distribution<D>       fun_t;
+    typedef ars::proposal_sampler<val_,std::vector>         ps_;
+    typedef ars::sampler<ps_>                               s_;
+    typedef random::ref_distribution<s_&>                   ref_s_;
+    typedef variate_generator<U&,ref_s_>                    vg_;
+    //typedef boost::random::kolmogorov_smirnov<D>            check_dist_t;
+
+    s_ s;
+    s.set_function(x_min, x_max, fun_t(mdist));
+
+    vals_ draws; draws.reserve( repeat_n * draw_n );
+    vals_ kss; kss.reserve(repeat_n);
+    ints_ n_rejects; n_rejects.reserve(repeat_n);
+    try{
+        for(unsigned i = 0; i<repeat_n; i++){
+            try{
+                s.initialize(init_0,init_1);
+                vg_ vg(urng,ref_s_(s)); 
+                std::generate_n(std::back_inserter(draws),draw_n,vg);
+                // Without ref_s_, n would be reset to 0
+                unsigned n = (
+                    (vg.distribution()).distribution()
+                ).n_reject();
+                val_ e = non_param::kolmogorov_smirnov_distance(
+                    mdist,
+                    boost::begin(draws),
+                    boost::end(draws)
+                );
+                kss.push_back(e);
+                n_rejects.push_back(n);
+            }catch(std::exception& e){
+                format f("at i = %1% : %2%"); f % i % e.what();
+                throw std::runtime_error(f.str());
+            }
+        }
+    }catch(std::exception& e)
+    {
+        std::cerr << e.what() << std::endl;
+    }
+    format f("init_0 = %1%, init_1 = %2%, by increments of n = %3%, ");
+    f % init_0 % init_1 % draw_n;
+    out << f.str() << std::endl;
+    out << "KS distance : ";
+    copy(
+        begin(kss),
+        end(kss),
+        std::ostream_iterator<val_>(out," ")
+    );
+    out << std::endl << "n_reject : ";
+    copy(
+        begin(n_rejects),
+        end(n_rejects),
+        std::ostream_iterator<val_>(out," ")
+    );
+    out << std::endl;
+}
+
+}//test
+}//ars
+}//boost
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,161 @@
+//////////////////////////////////////////////////////////////////////////////
+// ars::doc::readme                                       		    //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+This package implements the derivative version of the adaptive rejection
+sampler (Gilks, 1992). 
+
+A tool for testing is provided for standard distributions, which makes use of 
+their known cdf to produce kolmogorov-smirnov statistics.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+
+[ History ]
+
+July 2009 : Current version
+March 2009 : 
+sandbox/conditionally_specified_distribution/adaptive_rejection_sampling is 
+now deprecated.
+
+[Artiles]
+
+@article{citeulike:3015268,
+	abstract = {We propose a method for rejection sampling from any
+	univariate log-concave probability density function.
+	The method is adaptive: as sampling proceeds, the rejection envelope
+	and the squeezing function converge to the density function.
+	The rejection envelope and squeezing function are piece-wise exponential
+	functions, the rejection envelope touching the density at previously
+	sampled points, and the squeezing function forming arcs between those
+	points of contact. The technique is intended for situations where
+	evaluation of the density is computationally expensive, in particular
+	for applications of Gibbs sampling to Bayesian models with non-conjugacy.
+	We apply the technique to a Gibbs sampling analysis of monoclonal
+	antibody reactivity.},
+	author = {Gilks, W. R.  and Wild, P. },
+	citeulike-article-id = {3015268},
+	doi = {10.2307/2347565},
+	journal = {Applied Statistics},
+	number = {2},
+	pages = {337--348},
+	posted-at = {2008-10-16 11:59:33},
+	priority = {5},
+	publisher = {Blackwell Publishing for the Royal Statistical Society},
+	title = {Adaptive Rejection Sampling for {Gibbs} Sampling},
+	url = {http://dx.doi.org/10.2307/2347565},
+	volume = {41},
+	year = {1992}
+}
+
+http://www.econ.ucsb.edu/~tedb/Theory/delta.pdf
+Log-Concave Probability and Its Applications by  Mark Bagnoli,
+Ted Bergstrom, University of Michigan, Current version: October 1989
+
+On Adaptive Rejection Sampling, Rajeeva L. Karandikar, Indian Statistical
+Institute, 2005.
+
+[Sofware]
+
+I coding this software we have looked at these implementations:
+
+ars.f by Gilks
+http://www.maths.leeds.ac.uk/~wally.gilks/adaptive.rejection/web_page/Welcome.html
+
+ars1d.h, started 22 April 2008 by tss
+www.cs.cmu.edu/~tss/README_ars1d.txt
+
+[Output]
+
+Here's the output from main.cpp :
+
+[Session started at 2009-07-24 20:48:28 -0400.]
+-> example_standard_distribution 
+Gamma(3,1) : init_0 = 102, init_1 = 102.01, by increments of n = 1, 
+KS distance : 0.899296 0.399296 0.565963 0.649296 0.499296 0.399296 0.327868 
+0.29257 0.232629 0.26757 0.303933 0.250903 0.282954 0.26833 0.225473 0.187973 
+0.20242 0.225296 0.245764 0.214185  
+n_reject : 3 2 2 2 2 2 1 3 2 2 5 3 2 3 2 2 4 3 2 2 
+
+Gamma(3,1) : init_0 = 2.01, init_1 = 2.02, by increments of n = 1, 
+KS distance : 0.905859 0.405859 0.572525 0.655859 0.505859 0.572525 0.620144 
+0.530859 0.546644 0.479978 0.492329 0.439299 0.394427 0.427394 0.389299 0.355966
+0.326554 0.30041 0.277018 0.255966  
+n_reject : 3 1 3 2 2 3 3 2 1 3 0 2 3 1 1 1 3 3 2 1 
+
+N(0,2) : init_0 = -100, init_1 = 0.01, by increments of n = 1, 
+KS distance : 0.329606 0.170394 0.21905 0.170394 0.270394 0.170394 0.171431
+0.190783 0.260179 0.215734 0.27028 0.312011 0.273549 0.28062 0.247287 0.21812 
+0.192385 0.169509 0.149041 0.13062 0.161573 0.144257 0.171925 0.15562 0.18062 
+0.165236 0.188028 0.173477 0.159931 0.147287 0.135459 0.128283 0.145329 0.133561
+0.123477 0.113954 0.123216 0.138152 0.126681 0.115783 0.105417 0.0955451 
+0.086132 0.0929632 0.104579 0.115691 0.126329 0.115691 0.125895 0.115691 
+0.125494 0.115691 0.106257 0.097172 0.0884178 0.0799762 0.0893747 0.0812077 
+0.0902668 0.0990238 0.0911003 0.0995615 0.091881 0.100066 0.0926136 0.0853875 
+0.0933024 0.0862787 0.0794586 0.0871191 0.0804792 0.0740238 0.0677453 0.0616365 
+0.0690238 0.0630589 0.0572489 0.0644085 0.0587285 0.0656905 0.060135 0.06691 
+0.0614736 0.0561667 0.0627493 0.057551 0.0524721 0.0588723 0.0538928 0.0490238 
+0.0442619 0.0470498 0.0531274 0.0488212 0.0519567 0.0550269 0.0580337 0.0507752 
+0.0473638 0.0478689  
+n_reject : 6 8 6 5 4 6 2 2 4 5 5 8 6 6 4 4 6 2 5 7 8 3 2 4 1 2 0 6 4 3 4 3 5 5 3
+ 6 2 7 4 3 4 7 3 3 4 7 6 7 6 3 2 4 5 4 3 6 7 5 3 3 7 7 6 2 5 6 3 4 5 5 7 4 5 3 4
+  1 4 4 6 3 3 5 3 3 5 2 1 3 4 4 5 4 4 1 8 2 4 2 3 8 
+  
+N(0,2) : init_0 = -0.01, init_1 = 100, by increments of n = 1, 
+KS distance : 0.224171 0.424326 0.590992 0.424326 0.324326 0.257659 0.21004 
+0.275829 0.220273 0.175829 0.230374 0.275829 0.237367 0.2044 0.242495 0.217415 
+0.246417 0.245193 0.204257 0.175829 0.176324 0.187147 0.194709 0.203767 0.172101
+ 0.181331 0.189878 0.197815 0.170721 0.178767 0.186294 0.193351 0.169676 
+ 0.147395 0.154958 0.162101 0.14183 0.148943 0.15569 0.137101 0.143808 0.150196 
+ 0.133031 0.139373 0.145434 0.129492 0.135505 0.120434 0.126386 0.112101 
+ 0.117983 0.104408 0.110214 0.115804 0.121191 0.126386 0.113855 0.101756 
+ 0.107016 0.112101 0.117019 0.121778 0.117197 0.121661 0.125988 0.115032 
+ 0.119329 0.108794 0.113056 0.102911 0.0930521 0.0973557 0.101541 0.105614 
+ 0.109578 0.10028 0.0912229 0.0952189 0.0864555 0.0779112 0.0819236 0.0736429 
+ 0.07761 0.069869 0.0736505 0.0773441 0.0809527 0.0731157 0.0766908 0.0690753 
+ 0.0718321 0.0699209 0.0687169 0.0662206 0.0644289 0.0626745 0.0609563 0.0592732
+  0.057624 0.0560079  n_reject : 6 5 6 4 6 4 7 5 4 7 2 9 5 5 7 3 3 5 6 7 7 4 5 4
+   6 4 8 5 5 6 3 6 5 1 2 5 7 4 6 6 4 5 6 3 5 3 5 4 3 0 6 8 6 5 5 6 6 5 5 6 5 4 4
+    5 6 2 5 6 6 4 5 4 0 6 7 5 6 4 2 5 6 4 4 5 3 3 7 1 6 2 2 1 5 3 4 7 4 4 5 1 
+    
+N(0,2) : init_0 = -0.01, init_1 = 0.01, by increments of n = 1, KS distance : 
+0.94637 0.44637 0.349201 0.19637 0.282535 0.349201 0.387313 0.423027 0.339693 
+0.273027 0.30939 0.25636 0.211488 0.173027 0.150519 0.148475 0.13224 0.0995606 
+0.122952 0.144005 0.115434 0.134914 0.152701 0.148219 0.163219 0.177065 0.172077
+ 0.183982 0.195066 0.205411 0.215088 0.192911 0.20238 0.211293 0.191125 0.199855
+  0.181086 0.163305 0.146436 0.155411 0.163947 0.172077 0.17993 0.166188 
+  0.153057 0.162236 0.171024 0.158613 0.146708 0.135279 0.143907 0.152202 
+  0.160185 0.167872 0.175279 0.182422 0.189314 0.195969 0.202398 0.191946 
+  0.19823 0.204311 0.194327 0.184654 0.190664 0.18134 0.172294 0.17822 0.183975 
+  0.175279 0.166828 0.158613 0.150622 0.15636 0.161946 0.167384 0.159695 
+  0.152202 0.157558 0.162779 0.155526 0.14845 0.141544 0.146708 0.139985 
+  0.133419 0.127003 0.123551 0.128275 0.121783 0.126423 0.130962 0.135403 
+  0.13975 0.133479 0.137755 0.141943 0.146046 0.139965 0.134005  
+  n_reject : 9 6 8 5 4 4 5 3 7 6 7 3 4 7 5 3 7 6 7 4 5 7 3 7 7 8 8 8 5 3 6 3 4 8
+   3 6 4 5 6 7 6 6 7 3 9 2 8 1 3 6 5 8 8 6 7 4 8 5 8 6 6 7 8 4 7 8 7 5 8 6 5 6 6
+    3 4 7 6 4 8 4 6 4 7 8 10 7 7 7 5 8 8 6 3 4 8 6 8 7 6 7 
+    
+-> example_search_reflection
+N(0,2)x_0 = 100, x_1 = 100.01, , n = 14, p_0 : (-63.83,-509.284,15.9575), 
+p_1 : (100.01,-1250.25,-25.0025)
+x_0 = -100.01, x_1 = -100, , n = 14, p_0 : (-100.01,-1250.25,25.0025), 
+p_1 : (63.83,-509.284,-15.9575)
+x_0 = -0.02, x_1 = -0.01, , n = 2, p_0 : (-0.02,-5e-05,0.005), 
+p_1 : (0.02,-5e-05,-0.005)
+<-
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,106 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::example::search_reflection.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 <boost/format.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/ars/search_reflection.hpp>
+#include <boost/ars/constant.hpp>
+
+void example_search_reflection(std::ostream& out){
+    std::cout << "-> example_search_reflection" << std::endl;
+    using namespace boost;
+
+    typedef double value_t;
+    typedef ars::point<value_t> point_t;
+    typedef ars::constant<value_t> const_;
+
+    struct local{
+        static std::ostream& write(
+            std::ostream& o,
+            const value_t& x_0,
+            const value_t& x_1,
+            unsigned n,
+            const point_t& p_0,
+            const point_t& p_1
+        ){
+            format f("x_0 = %1%, x_1 = %2%, ");
+            f % x_0 % x_1;
+            o << f.str();
+            o << ", n = " << n << ", p_0 : " << p_0 << ", p_1 : " << p_1;
+            return o;
+        }
+    };
+
+    value_t x_min,x_max, x_0, x_1;
+    point_t p_0,p_1;
+    unsigned n_max, n = 0;
+
+    {
+        typedef math::normal_distribution<value_t> mdist_t;
+        typedef const mdist_t& param_t;
+        x_min = const_::inf_;
+        x_max = const_::inf_;
+        n_max = 1e2;
+        const value_t mu = 0.0;
+        const value_t sigma = 2.0;
+        mdist_t mdist(mu,sigma);
+        out << (format("N(%1%,%2%)")%mu%sigma);
+
+        {
+            x_0 = 100.0;
+            x_1 = 100.01;
+            n = ars::search_reflection_dist(
+                x_min,
+                x_max,
+                mdist,
+                x_0,
+                x_1,
+                p_0,
+                p_1,
+                n_max
+            );
+            local::write(out,x_0,x_1,n,p_0,p_1);
+            out << std::endl;
+        } 
+        
+        {
+            x_0 = -100.01;
+            x_1 = -100.00;
+            n = ars::search_reflection_dist(
+                x_min,
+                x_max,
+                mdist,
+                x_0,
+                x_1,
+                p_0,
+                p_1,
+                n_max
+            );
+            local::write(out,x_0,x_1,n,p_0,p_1);
+            out << std::endl;
+        }
+
+        {
+            x_0 = -0.02;
+            x_1 = -0.01;
+            n = ars::search_reflection_dist(
+                x_min,
+                x_max,
+                mdist,
+                x_0,
+                x_1,
+                p_0,
+                p_1,
+                n_max
+            );
+            local::write(out,x_0,x_1,n,p_0,p_1);
+            out << std::endl;
+        }
+        
+    }
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::example::search_reflection.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_ARS_EXAMPLE_SEARCH_REFLECTION_H_ER_2009
+#define LIBS_ARS_EXAMPLE_SEARCH_REFLECTION_H_ER_2009
+#include <ostream>
+
+void example_search_reflection(std::ostream&);
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,88 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::example::standard_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 <iostream>
+#include <boost/standard_distribution/distributions/gamma.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/ars/test/gamma_distribution.hpp>
+#include <boost/ars/test/normal_distribution.hpp>
+#include <libs/ars/example/standard_distribution.h>
+
+// TODO all other concave standard distributions:
+// See paper by Mark Bagnoli
+
+void example_standard_distribution(std::ostream& out){
+    out << "-> example_standard_distribution " << std::endl;
+
+    typedef double value_;
+
+    // The initial values are chosen to test the robustness of the
+    // implementation, within the range allowed by the algorithm.
+    {   // Domain = [0,inf)
+        value_ shape = 3.0;
+        value_ scale = 1.0;
+        value_ mode = (shape - 1.0) * scale; //2
+        boost::ars::test::gamma_distribution<value_>(
+            shape,      //shape
+            scale,      //scale
+            mode + 100.0,//init0
+            mode + 100.01, //init1
+            1,          //draw_n = 1,
+            2e1,        //repeat_n = 1e2,
+            1e1,        //n_max_reject = 1e1
+            out
+        ); out << std::endl;
+        boost::ars::test::gamma_distribution<value_>(
+            shape,      //shape
+            scale,      //scale
+            mode + 0.01,//init0
+            mode + 0.02, //init1
+            1,          //draw_n = 1,
+            2e1,        //repeat_n = 1e2,
+            1e1,        //n_max_reject = 1e1
+            out
+        );
+        out << std::endl;
+    }
+    {   // Domain = (-inf,inf)
+        value_ mu = 0.0;
+        value_ sigma = 2.0;
+        boost::ars::test::normal_distribution<value_>(
+            mu,
+            sigma,
+            mu -100.0, //-100.0, //init0
+            mu + 0.01, //+ 0.01,    //init1
+            1,      //draw_n,
+            1e2,    //repeat_n,
+            1e1,    //n_max_reject
+            out
+        );
+        out << std::endl;
+        boost::ars::test::normal_distribution<value_>(
+            mu,
+            sigma,
+            mu - 0.01,   //init0
+            mu + 100.0,  //init1
+            1,      //draw_n,
+            1e2,    //repeat_n,
+            1e1,    //n_max_reject
+            out
+        );
+        out << std::endl;
+        boost::ars::test::normal_distribution<value_>(
+            mu,
+            sigma,
+            -0.01, //init0
+            0.01,    //init1
+            1,      //draw_n,
+            1e2,    //repeat_n,
+            1e1,    //n_max_reject
+            out
+        );
+        out << std::endl;
+    }
+}
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/standard_distribution.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::example::standard_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_ARS_EXAMPLE_STANDARD_DISTRIBUTION_H_ER_2009
+#define LIBS_ARS_EXAMPLE_STANDARD_DISTRIBUTION_H_ER_2009
+#include <ostream>
+
+void example_standard_distribution(std::ostream&);
+
+#endif
Added: sandbox/statistics/adaptive_rejection_sampling/libs/ars/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+// ars::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/ars/example/search_reflection.h>
+#include <libs/ars/example/standard_distribution.h>
+
+int main(){
+
+    example_standard_distribution(std::cout);
+    example_search_reflection(std::cout);
+
+    return 0;
+
+};
Added: sandbox/statistics/arithmetic/boost/arithmetic/equal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/arithmetic/boost/arithmetic/equal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,41 @@
+///////////////////////////////////////////////////////////////////////////////
+// utility::arithmetic::utility_equal.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_ARITHMETIC_EQUAL_HPP_ER_2009
+#define BOOST_UTILITY_ARITHMETIC_EQUAL_HPP_ER_2009
+#include <cmath>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_float.hpp>
+#include <boost/type_traits/is_integral.hpp>
+#include <boost/math/tools/precision.hpp>
+
+namespace boost{
+namespace arithmetic_tools{ //arithmetic already exists as class or namespace
+
+    template<typename T>
+    typename boost::enable_if<
+        typename is_float<T>::type,
+        bool
+    >::type
+    equal(const T& a,const T& b){
+        static T eps = boost::math::tools::epsilon<T>();
+        return fabs(a-b)<eps;
+    }
+
+    template<typename T>
+    typename enable_if<
+        typename is_integral<T>::type,
+        bool
+    >::type
+    equal(const T& a,const T& b){
+        return (a == b);
+    }
+
+}// arithmetic
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/acf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/acf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,133 @@
+///////////////////////////////////////////////////////////////////////////////
+// acf.hpp                                                                   //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_ACF_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACF_HPP_ER_2008_04
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <functional>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/bind.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/acvf.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // acf_impl
+    template<typename Sample,typename Discriminator>
+    class acf_impl
+      : public accumulator_base
+    {
+       //TODO via the feature for delay (?)
+	   typedef acvf_impl<Sample,Discriminator>      acvf_type;
+	   typedef typename acvf_type::result_type      acvfs_result_type;
+       typedef std::vector<Sample>                  acfs_type;
+    public:
+       typedef boost::iterator_range<
+            typename acfs_type::const_iterator>     result_type;
+
+        acf_impl(dont_care):acfs(0,(Sample)(0.0)){}
+
+        template<typename Args>
+        void operator ()(Args const &args){
+            const acvfs_result_type& range
+                = acvf<Discriminator>(args[accumulator]);
+            std::size_t sz = range.size();
+            acfs.resize(sz);
+            Sample acv0 = (*begin(range));
+            if(acv0>0.0){
+                Sample div=(1.0/acv0);
+                transform(
+                    begin(range),
+                    end(range),
+                    acfs.begin(),
+                    boost::bind(
+                        std::multiplies<Sample>(),
+                        _1,
+                        div
+                    )
+                );
+            }else{
+                std::fill_n(acfs.begin(),sz,0.0);
+            }
+        }
+        result_type result(dont_care) const
+        {
+          return boost::make_iterator_range(acfs.begin(),acfs.end());
+        }
+    private:
+        mutable acfs_type acfs;
+    };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::acf
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct acf
+      : depends_on<acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef accumulators::impl::acf_impl<mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acf
+//
+
+namespace extract
+{
+
+  template<typename Discriminator,typename AccumulatorSet>
+  typename
+    mpl::apply<AccumulatorSet,tag::acf<Discriminator> >::type::result_type
+  acf(AccumulatorSet const& acc){
+    typedef tag::acf<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }//typical call://acf<default_delay_discriminator>(acc)
+
+
+
+
+}
+
+using extract::acf;
+
+
+}} // namespace boost::accumulators
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/acv0.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/acv0.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////////
+// acv0.hpp                                                                  //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_ACV0_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACV0_HPP_ER_2008_04
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+//#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // acv0_impl
+    template<typename Sample,typename Discriminator>
+    class acv0_impl
+      : public accumulator_base
+    {
+    public:
+        typedef Sample result_type;
+        acv0_impl(dont_care)
+        {}
+
+        template<typename Args>
+        void operator()(Args const &args)
+        {
+            val = (*begin(acvf<Discriminator>(args[accumulator])));
+        }
+
+
+        result_type result(dont_care) const
+        {
+            return val;
+        }
+    private:
+        Sample val;
+    };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::acv0
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct acv0
+      : depends_on<acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef
+        accumulators::impl::acv0_impl<
+            mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acv0
+//
+
+namespace extract
+{
+
+
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::acv0<Discriminator>
+    >::type::result_type
+  acv0(AccumulatorSet const& acc){
+    typedef tag::acv0<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+}
+
+using extract::acv0;
+
+
+
+}} // namespace boost::accumulators
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,172 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf.hpp                                                                  //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_ACVF_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_HPP_ER_2008_04
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/count.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/delay.hpp> // in accumulators_filter
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // acvf_impl (Autocovariance function)
+    template<typename Sample,typename Discriminator>
+    class acvf_impl
+      : public accumulator_base
+    {
+	   typedef std::vector<Sample>	               acvs_type;
+       typedef delay_impl<Sample,Discriminator>    delay_type;
+	   typedef typename delay_type::result_type    input_type;
+    public:
+       typedef boost::iterator_range<
+            typename acvs_type::const_iterator
+            > result_type;
+
+
+        template<typename Args>
+        acvf_impl(Args const &args)
+        :acvs(
+            args[tag::delay<Discriminator>::cache_size|delay(args).size()],
+            (Sample)(0.0)
+        )
+        {
+        }
+
+        acvf_impl(const acvf_impl& that)
+        :acvs(that.acvs){}
+
+        acvf_impl& operator=(const acvf_impl& that){
+            if(&that!=this){acvs = that.acvs;} return *this;
+        }
+
+
+        template<typename Args>
+        void operator ()(Args const &args)
+        {
+          input_type in = delay(args); //0,1,2,...,K
+          typedef typename input_type::const_iterator  in_iter_type;
+          typedef typename acvs_type::iterator         out_iter_type;
+          std::size_t in_sz = in.size();
+
+          BOOST_ASSERT((in_sz<acvs.size())||(in_sz==acvs.size()));
+          in_iter_type i = begin(in);
+          in_iter_type e = end(in);
+
+          Sample x0 = (*i);
+          std::size_t n = count(args);
+          std::size_t k = 0;
+          //TODO replace by
+          //for_each(make_zip_iterator(
+          //  make_tuple(begin(in),acvs.begin())),...,local_class(...))
+		  while((k<in_sz) && (n>1+k)){
+		      BOOST_ASSERT(i<e);
+              Sample xk = (*i);
+              Sample div = (Sample) ((n-1)-k);
+              Sample sum_prod = acvs[k] * div;
+              Sample mean_val = mean(args);
+              sum_prod += (xk - mean_val) * (x0 - mean_val);
+              div = (Sample)(n-k);
+              acvs[k] = sum_prod / div;
+              ++i;
+              ++k;
+          }
+		}
+
+        result_type result(dont_care) const
+        {
+          return boost::make_iterator_range(acvs.begin(),acvs.end());
+        }
+
+    private:
+	   acvs_type   acvs;
+
+    };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::acvf
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct acvf
+      : depends_on<count,mean,delay<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef accumulators::impl::acvf_impl<mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::acvf
+//
+
+namespace extract
+{
+//  extractor<tag::acvf<> > const acvf = {};
+//  //a non-default discriminator requires
+//  //struct my_other_delay {};
+//  //extractor<tag::delay<my_other_delay> > other_delay={};
+
+  template<typename Discriminator,typename AccumulatorSet>
+  typename
+    mpl::apply<AccumulatorSet,tag::acvf<Discriminator> >::type::result_type
+  acvf(AccumulatorSet const& acc){
+    typedef tag::acvf<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }//typical call://acvf<default_delay_discriminator>(acc)
+
+//  TODO
+//  //overload
+//  template<typename AccumulatorSet>
+//  typename mpl::apply<AccumulatorSet,tag::acvf<> >::type::result_type
+//  acvf(AccumulatorSet const& acc){
+//    return acvf<default_delay_discriminator,AccumulatorSet>(acc);
+//  }
+// /../boost_1_35_0/boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp|39|error: no
+// class template named âapplyâ
+// in âstruct boost::accumulators::default_delay_discriminatorâ|
+
+}
+
+using extract::acvf;
+
+
+}} // namespace boost::accumulators
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_analysis.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_analysis.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,157 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf_analysis.hpp                                                         //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_ACVF_ANALYSIS_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_ANALYSIS_HPP_ER_2008_04
+#include <iostream>
+#include <algorithm>
+#include <iterator>
+#include <functional>
+#include <stdexcept>
+//#include <boost/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/parameter/parameters.hpp>
+#include <boost/parameter/keyword.hpp>
+#include <boost/bind.hpp>
+#include <boost/range.hpp>
+#include <boost/ref.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range/iterator_range.hpp>
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+#include <boost/accumulators/statistics/acvf_moving_average.hpp>
+#include <boost/accumulators/statistics/acvf.hpp>
+#include <boost/accumulators/statistics/acf.hpp>
+#include <boost/accumulators/statistics/percentage_effective_sample_size.hpp>
+#include <boost/accumulators/statistics/standard_error_autocorrelated.hpp>
+#include <boost/accumulators/statistics/standard_error_iid.hpp>
+
+namespace boost{namespace accumulators{
+namespace statistics{
+
+    template<
+        typename RealType,
+        typename Discriminator = default_delay_discriminator
+    >
+    class acvf_analysis{
+        typedef Discriminator discr_t;
+        public:
+        typedef RealType    value_type;
+
+        private:
+
+        typedef boost::accumulators::accumulator_set<
+        value_type, boost::accumulators::stats<
+            boost::accumulators::tag::mean,
+            boost::accumulators::tag::acf<discr_t>,
+            boost::accumulators::tag::integrated_acvf<discr_t>,
+            boost::accumulators::tag::percentage_effective_sample_size<
+                discr_t>,
+            boost::accumulators::tag::standard_error_autocorrelated<discr_t>,
+            boost::accumulators::tag::standard_error_iid<discr_t>
+            >
+        >  acc_type;
+
+    public://TODO define copy and assign
+        acvf_analysis(std::size_t max_lag)
+        :K(max_lag),
+        acc(boost::accumulators::tag::delay<discr_t>::cache_size=(K+1)){};
+
+        void operator()(value_type x){
+            return acc(x);
+        }
+
+        template<typename R>
+        void operator()(
+            const R& range,
+            std::size_t offset,
+            std::size_t stride){
+
+            // an iterator range?
+            typedef typename range_iterator<const R>::type const_iter_type;
+            typedef typename range_size<R>::type size_type;
+            const_iter_type i = boost::begin(range);
+            const_iter_type e = boost::end(range);
+            if(std::distance(i,e)>offset){
+                std::advance(i,offset);
+                //this has the effect of rounding to smallest
+                std::size_t d = (std::distance(i,e)-1)/stride;
+                d *= stride;
+                e = i; std::advance(e,d+1);
+
+                while(i<e){
+                    acc(*i);
+                    std::advance(i,stride);
+                }
+//            for_each(
+//                boost::begin(range),
+//                boost::end(range),
+//                boost::bind<void>(boost::ref(acc),_1)
+//            );
+            }else{
+                std::runtime_error("acvf_analysis");
+            }
+        }
+        std::size_t max_lag()const{ return K; }
+        value_type mean()const{ return accumulators::mean(acc); }
+        value_type standard_error_iid()const{
+            return accumulators::standard_error_iid<discr_t>(acc);
+        }
+        value_type standard_error_autocorrelated()const{
+            return accumulators
+                ::standard_error_autocorrelated<discr_t>(acc);
+        }
+        value_type integrated_acvf()const{
+            return accumulators
+                ::integrated_acvf<discr_t>(acc);
+        }
+
+        value_type percentage_effective_sample_size()const{
+            return accumulators
+                ::percentage_effective_sample_size<discr_t>(acc);
+        }
+
+        void print(std::ostream& os)const
+        {
+            //using namespace boost::accumulators;
+            os  << "count : " << accumulators::count(acc)
+                << "\nacf : ";
+                    copy(
+                        begin(accumulators::acf<discr_t>(acc)),
+                        end(accumulators::acf<discr_t>(acc)),
+                        std::ostream_iterator<value_type>(os," ")
+                    );
+            os  << "\nintegrated_acvf : "
+                << integrated_acvf()
+                << "\ness% : "
+                << percentage_effective_sample_size()
+                << "\nmean : " << mean()
+                << "\nstandard error : "
+                << "\n assuming iid : "
+                << standard_error_iid()
+                << "\n assuming acf is zero after lag "
+                << max_lag() << ": "
+                << standard_error_autocorrelated() << std::endl;
+        };
+
+    private:
+
+        std::size_t K;
+        acc_type acc;
+    };
+
+//TODO
+//    std::ostream& operator<<(std::ostream& os,const acvf_analysis& a){
+//        a.print(os);
+//        return os;
+//    };
+
+}
+}}
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_moving_average.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/acvf_moving_average.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+// acvf_moving_average.hpp                                                   //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_ACVF_MOVING_AVERAGE_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_ACVF_MOVING_AVERAGE_HPP_ER_2008_04
+
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <stdexcept>
+#include <boost/call_traits.hpp>
+//#include <boost/assert.hpp>
+#include <boost/range.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+namespace boost { namespace accumulators{
+
+    /// This is not an accumulator, only a formula:
+    /// Under model \f$ x_t = theta_0 e_{t-0} + ... + theta_q e_{t-q} \f$,
+    /// where the \f$ e_i \f$'s are independent and \f$Var[e_i]=1 \f$,
+    /// \f$ acvf(h) = sum_{j=0}^{q-h} theta_j theta_{j+h},
+    /// 0\leq h \leq q \f$
+    /// Multiply result by \f$ Var[e_i] \f$ if it is not 1.
+    template<typename R>
+    class acvf_moving_average{
+        typedef typename range_iterator<const R>::type iterator_type;
+    public:
+        typedef std::size_t                             argument_type;
+        typedef typename
+            boost::iterator_value<iterator_type>::type  result_type;
+            acvf_moving_average(const R& coeffs_):coeffs(coeffs_){}
+            acvf_moving_average(const acvf_moving_average& that)
+            :coeffs(that.coeffs){}
+            acvf_moving_average& operator=(const acvf_moving_average& that){
+                if(&that!=this){
+                        std::runtime_error("acvf_moving_average::operator=");}
+                return *this;
+            }
+            result_type operator()(argument_type delay)const{
+                typedef typename range_iterator<const R>::type iterator_type;
+                result_type res = 0.0;
+                size_t h = delay;
+                if(coeffs.size()>0){
+                    std::size_t q = coeffs.size()-1;//MA(q)
+                    if(!(h>q)){
+                        iterator_type i = coeffs.begin();
+                        iterator_type e = i; std::advance(e,q+1-h);
+                        iterator_type i_shifted = i; std::advance(i_shifted,h);
+                        iterator_type e_shifted = e; std::advance(e_shifted,h);
+                        while(i<e){
+                            res+=(*i)*(*i_shifted);
+                            ++i; ++i_shifted;
+                        }//TODO accumulate(make_zip_iterator(...
+                    }
+                }
+                return res;
+            }
+    private:
+        const R& coeffs;
+    };
+
+    template<typename R>
+    acvf_moving_average<R> make_acvf_moving_average(const R& coeffs){
+        return acvf_moving_average<R>(coeffs);
+    };
+
+
+}}
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,110 @@
+///////////////////////////////////////////////////////////////////////////////
+// integrated_acf.hpp                                                        //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_INTEGRATED_ACF_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_INTEGRATED_ACF_HPP_ER_2008_04
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <boost/mpl/int.hpp>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/acv0.hpp>
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // integrated_acf_impl
+    template<typename Sample,typename Discriminator>
+    class integrated_acf_impl
+      : public accumulator_base
+    {
+    public:
+        typedef Sample                              result_type;
+
+        integrated_acf_impl(dont_care):val((Sample)(0.0)){}
+
+        template<typename Args>
+        void operator ()(Args const &args)
+        {
+          Sample iacvf = integrated_acvf<Discriminator>(args[accumulator]);
+          Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+          if(acv0_val>0.0){val=iacvf/acv0_val;}else{val = 0.0;}
+		}
+
+        result_type result(dont_care) const{return val;}
+
+    private:
+	   Sample  val;
+
+    };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acf
+//
+
+namespace tag
+{
+
+    template <typename Discriminator = default_delay_discriminator>
+    struct integrated_acf
+      : depends_on<acv0<Discriminator>,integrated_acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef
+        accumulators::impl::integrated_acf_impl<mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::integrated_acf
+//
+
+namespace extract
+{
+
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::integrated_acf<Discriminator> >::type::result_type
+  integrated_acf(AccumulatorSet const& acc){
+    typedef tag::integrated_acf<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+}
+
+using extract::integrated_acf;
+
+
+}} // namespace boost::accumulators
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acvf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/integrated_acvf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,119 @@
+///////////////////////////////////////////////////////////////////////////////
+// integrated_acvf.hpp                                                       //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_INTEGRATED_ACVF_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_INTEGRATED_ACVF_HPP_ER_2008_04
+#include <cmath>
+#include <vector>
+#include <algorithm>
+#include <numeric>
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/acvf.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // integrated_acvf_impl
+    template<typename Sample,typename Discriminator>
+    class integrated_acvf_impl
+      : public accumulator_base
+    {
+       //TODO or via feature?
+        typedef acvf_impl<Sample,Discriminator>                      acvf_type;
+        typedef typename acvf_type::result_type                      range_type;
+    public:
+        typedef Sample result_type;
+        integrated_acvf_impl(dont_care):val(0.0){}
+
+        template<typename Args>
+        void operator ()(Args const &args)
+        {
+          range_type range = acvf<Discriminator>(args[accumulator]);
+          typedef typename range_type::const_iterator  iter_type;
+          Sample acv0_val = (*begin(range));
+          val = std::accumulate(begin(range),end(range),0.0);
+          val *=2.0;
+          val -=acv0_val;
+		}
+
+        result_type result(dont_care) const{return val;}
+
+    private:
+	   Sample  val;
+
+    };
+
+} // namespace impl
+
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct integrated_acvf
+      : depends_on<acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef accumulators::impl::integrated_acvf_impl<mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::integrated_acvf
+//
+
+namespace extract
+{
+
+//  extractor<tag::integrated_acvf<> > const integrated_acvf = {};
+
+  // see acvf about default_delay_discriminator
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::integrated_acvf<Discriminator>
+    >::type::result_type
+  integrated_acvf(AccumulatorSet const& acc){
+    typedef tag::integrated_acvf<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+//  TODO
+//  overload (default) see acvf
+
+}
+
+using extract::integrated_acvf;
+
+
+}} // namespace boost::accumulators
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/percentage_effective_sample_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/percentage_effective_sample_size.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,120 @@
+///////////////////////////////////////////////////////////////////////////////
+// percentage_effective_sample_size.hpp                                      //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_PERCENTAGE_EFFECTIVE_SAMPLE_SIZE_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_PERCENTAGE_EFFECTIVE_SAMPLE_SIZE_HPP_ER_2008_04
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/acv0.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // percentage_effective_sample_size
+    template<typename Sample,typename Discriminator>
+    class percentage_effective_sample_size_impl
+      : public accumulator_base
+    {
+    public:
+        typedef std::size_t result_type;
+
+        percentage_effective_sample_size_impl(dont_care):val(0){}
+
+        template<typename Args>
+        void operator()(const Args& args)
+        {
+            Sample iacvf = integrated_acvf<Discriminator>(args[accumulator]);
+            if(iacvf>0.0){
+
+                typedef boost::numeric::converter<result_type,Sample> Sample2res;
+                Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+                Sample tmp = 100.0*acv0_val/iacvf;
+                val = Sample2res::convert(tmp);
+            }else{
+                val = 0;
+            }
+        }
+
+        result_type result(dont_care) const
+        {
+            return val;
+        }
+    private:
+        result_type val;
+    };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct percentage_effective_sample_size
+      : depends_on<acv0<Discriminator>, integrated_acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef
+        accumulators::impl::percentage_effective_sample_size_impl<
+            mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::percentage_effective_sample_size
+//
+
+namespace extract
+{
+
+//  extractor<tag::percentage_effective_sample_size<> >
+//    const percentage_effective_sample_size = {};
+
+  // see acvf about default_delay_discriminator
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::percentage_effective_sample_size<Discriminator>
+    >::type::result_type
+  percentage_effective_sample_size(AccumulatorSet const& acc){
+    typedef tag::percentage_effective_sample_size<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+//  TODO
+//  overload (default) see acvf
+
+}
+
+using extract::percentage_effective_sample_size;
+}}
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_autocorrelated.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_autocorrelated.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,118 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_error_autocorrelated.hpp                                         //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_STANDARD_ERROR_AUTOCORRELATED_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_STANDARD_ERROR_AUTOCORRELATED_HPP_ER_2008_04
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+//#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // standard_error_autocorrelated
+    template<typename Sample,typename Discriminator>
+    class standard_error_autocorrelated_impl
+      : public accumulator_base
+    {
+    public:
+        typedef Sample result_type;
+
+        standard_error_autocorrelated_impl(dont_care)
+        {}
+
+        template<typename Args>
+        void operator()(Args const &args)
+        {
+            Sample iacv = integrated_acvf<Discriminator>(args[accumulator]);
+            Sample n = (Sample)(count(args));
+            val = 0.0;
+            if((iacv>0.0) && (n>0.0)){val = sqrt(iacv/n);}//also = sqrt(acv0/ess)
+        }
+
+        result_type result(dont_care) const
+        {
+            return val;
+        }
+    private:
+        Sample val;
+    };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::integrated_acvf
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct standard_error_autocorrelated
+      : depends_on<count,integrated_acvf<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef
+        accumulators::impl::standard_error_autocorrelated_impl<
+            mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::standard_error_autocorrelated
+//
+
+namespace extract
+{
+
+//  extractor<tag::standard_error_autocorrelated<> >
+//    const standard_error_autocorrelated = {};
+
+  // see acvf about default_delay_discriminator
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::standard_error_autocorrelated<Discriminator>
+    >::type::result_type
+  standard_error_autocorrelated(AccumulatorSet const& acc){
+    typedef tag::standard_error_autocorrelated<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+//  TODO
+//  overload (default) see acvf
+
+}
+
+using extract::standard_error_autocorrelated;
+
+}}
+
+#endif
Added: sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_iid.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/accumulators/statistics/standard_error_iid.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,119 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_error_iid.hpp                                                    //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_STATISTICS_STANDARD_ERROR_IID_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_STATISTICS_STANDARD_ERROR_IID_HPP_ER_2008_04
+#include <cmath>
+
+#include <boost/mpl/size_t.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/placeholders.hpp>
+
+#include <boost/call_traits.hpp>
+//#include <boost/assert.hpp>
+#include <boost/array.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/type_traits/add_const.hpp>
+
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/framework/accumulator_base.hpp>
+#include <boost/accumulators/framework/extractor.hpp>
+#include <boost/accumulators/numeric/functional.hpp>
+#include <boost/accumulators/framework/parameters/sample.hpp>
+#include <boost/accumulators/framework/depends_on.hpp>
+#include <boost/accumulators/statistics_fwd.hpp>
+
+#include <boost/accumulators/statistics/acv0.hpp>
+#include <boost/accumulators/statistics/count.hpp>
+
+namespace boost { namespace accumulators
+{
+
+
+namespace impl
+{
+    ////////////////////////////////////////////////////////////////////////////
+    // standard_error_iid
+    template<typename Sample,typename Discriminator>
+    class standard_error_iid_impl
+      : public accumulator_base
+    {
+    public:
+        typedef Sample result_type;
+
+        standard_error_iid_impl(dont_care)
+        {}
+
+        template<typename Args>
+        void operator()(Args const &args)
+        {
+            Sample acv0_val = acv0<Discriminator>(args[accumulator]);
+            Sample n = (Sample)(count(args));
+            val = 0.0;
+            if((acv0_val>0.0) && (n>0.0)){val = sqrt(acv0_val/n);}
+        }
+
+
+        result_type result(dont_care) const
+        {
+            return val;
+        }
+    private:
+        Sample val;
+    };
+
+} // namespace impl
+///////////////////////////////////////////////////////////////////////////////
+// tag::standard_error_iid
+//
+
+namespace tag
+{
+    template <typename Discriminator = default_delay_discriminator>
+    struct standard_error_iid
+      : depends_on<count,acv0<Discriminator> >
+    {
+        /// INTERNAL ONLY
+      typedef
+        accumulators::impl::standard_error_iid_impl<
+            mpl::_1,Discriminator> impl;
+
+    };
+}
+
+
+
+///////////////////////////////////////////////////////////////////////////////
+// extract::standard_error_iid
+//
+
+namespace extract
+{
+
+//  extractor<tag::standard_error_iid<> >
+//    const standard_error_iid = {};
+
+  // see acvf about default_delay_discriminator
+  template<typename Discriminator,typename AccumulatorSet>
+  typename mpl::apply<
+    AccumulatorSet,tag::standard_error_iid<Discriminator>
+    >::type::result_type
+  standard_error_iid(AccumulatorSet const& acc){
+    typedef tag::standard_error_iid<Discriminator> the_tag;
+    return extract_result<the_tag>(acc);
+  }
+
+//  TODO
+//  overload (default) see acvf
+
+}
+
+using extract::standard_error_iid;
+
+}}
+
+#endif
Added: sandbox/statistics/autocovariance/boost/random/moving_average.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/boost/random/moving_average.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,55 @@
+///////////////////////////////////////////////////////////////////////////////
+// moving_average.hpp                                                        //
+//                                                                           //
+//  Copyright 2008 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_ACCUMULATORS_RANDOM_MOVING_AVERAGE_HPP_ER_2008_04
+#define BOOST_ACCUMULATORS_RANDOM_MOVING_AVERAGE_HPP_ER_2008_04
+
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/fir.hpp>
+#include <boost/range/iterator_range.hpp>
+namespace boost{namespace random
+{
+
+// Simulates a Moving average process
+template<typename T>
+class moving_average{
+public:
+    typedef T               input_type;
+    typedef T               result_type ;
+    template<typename R>
+    moving_average(const R& coeffs)
+        :acc(
+            accumulators::tag::fir::coefficients=coeffs,
+            accumulators::tag::delay<>::cache_size=coeffs.size()){}
+    moving_average(const moving_average& that)
+        :acc(that.acc){}
+    moving_average& operator=(const moving_average& that){
+        if(&that!=this){
+            acc = that.acc;
+        }
+        return *this;
+    }
+    template<typename G>//G models NumberGenerator
+    result_type operator()(G& gen){
+        T x = gen();
+        acc(x);
+        return accumulators::extract::fir(acc);
+    }
+private:
+    typedef accumulators::accumulator_set<
+        T,
+        accumulators::stats<
+            accumulators::tag::fir,
+            accumulators::tag::delay<>
+        >
+    > acc_type;
+    acc_type acc;
+};
+
+}}
+#endif
Added: sandbox/statistics/autocovariance/libs/accumulators/statistics/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/libs/accumulators/statistics/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,100 @@
+//////////////////////////////////////////////////////////////////////////////
+// acvf                                                                     //
+//                                                                          //
+//  (C) Copyright 2008 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+Provides autocovariance and related statistics within the Boost.Accumulator 
+framework.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+accumulators_filters :
+
+[ Useful links] 
+
+Boost.Accumulator:
+http://boost-sandbox.sourceforge.net/libs/accumulators/doc/html/index.html
+
+accumulators_filters is here:
+http://www.boostpro.com/vault/index.php?directory=Math%20-%20Numerics
+
+[ History ]
+
+2009/07 :   Cosmetic changes
+2008/04 :   First version
+
+[ Sources ]
+    http://en.wikipedia.org/wiki/Autoregressive_moving_average_model
+    http://en.wikipedia.org/wiki/Autocovariance
+    http://en.wikipedia.org/wiki/Autocorrelation
+    Statistical Analysis of MarkovChain MC Data:
+        www.ims.nus.edu.sg/Programs/mcmc/files/berg_tl3.pdf
+
+[ Usage ]
+
+    typedef mpl::void_ discr_t;
+    typedef accumulator_set<
+        value_type, stats<
+            tag::acvf<discr_t>,
+            tag::acf<discr_t>,
+            tag::integrated_acvf<discr_t>,
+            tag::percentage_effective_sample_size<discr_t>,
+            tag::standard_error_autocorrelated<discr_t>,
+            tag::standard_error_iid<discr_t>
+            >
+    >            acc_type;
+    std::size_t max_lag = 3;
+    acc_type acc(max_lag);
+    acc(-1.0); acc(+1.0); acc(-1.0); acc(1.0);
+    acvf<discr_t>(acc);
+    percentage_effective_sample_size(acc);
+
+    Bundled version:
+    typedef acvf_analysis<value_type,discr_t> bundled_t;
+    std::ofstream out;
+    bundle_t bundle(max_lag);
+    bundle.acvf();
+    bundle.percentage_effective_sample_size();
+    bundle.print(out);
+
+[ Output ]
+
+Here's the output from main.cpp
+
+->true_acvf: 1.29 -0.6 0.2 <-
+->true_acf: 1 -0.465116 0.155039 <-
+->true var: 0.49<-
+->true ess%: 263<-
+->sample size: 100000
+->estimated acvf: 1.27563 -0.58848 0.190071 <-
+->estimated acf: 1 -0.461325 0.149002 <-
+->estimated var: 0.478814<-
+->estimated ess%: 266<-
+->estimated standard error assuming iid: 0.0035716<-
+->estimated standard error assuming acf is zero after lag 2: 0.00218818<-
+ --------- output from acvf_analysis:
+count :100000
+acf : 1 -0.461325 0.149002 0.00284592
+integrated_acvf : 0.486075
+ess% : 262
+mean : 0.00306125
+standard error :
+ assuming iid : 0.0035716
+ assuming acf is zero after lag 3: 0.00220471
+
+
Added: sandbox/statistics/autocovariance/libs/accumulators/statistics/example/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/autocovariance/libs/accumulators/statistics/example/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,143 @@
+///////////////////////////////////////////////////////////////////////////////
+// main.cpp
+//
+//  Copyright 2008 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 <algorithm>
+#include <iterator>
+#include <vector>
+#include <functional>
+#include <fstream>
+#include <boost/mpl/size_t.hpp>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/delay.hpp>
+#include <boost/accumulators/statistics/acvf_moving_average.hpp>
+#include <boost/accumulators/statistics/acvf.hpp>
+#include <boost/accumulators/statistics/acf.hpp>
+#include <boost/accumulators/statistics/integrated_acf.hpp>
+#include <boost/accumulators/statistics/integrated_acvf.hpp>
+#include <boost/accumulators/statistics/percentage_effective_sample_size.hpp>
+#include <boost/accumulators/statistics/standard_error_autocorrelated.hpp>
+#include <boost/accumulators/statistics/standard_error_iid.hpp>
+#include <boost/accumulators/statistics/acvf_analysis.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/moving_average.hpp>
+#include <boost/bind.hpp>
+#include <boost/ref.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range/iterator_range.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+int main(){
+
+    const char* filepath = "./acvf_output";
+    std::ofstream out(filepath);
+
+    using namespace boost::accumulators;
+    typedef boost::mt19937                                    urng_type;
+    typedef boost::normal_distribution<>                      nd_type;
+    typedef boost::variate_generator<urng_type&,nd_type>      gen_nd_type;
+    typedef double                                            value_type;
+    typedef boost::random::moving_average<value_type>         ma_type;
+    typedef std::vector<value_type>                           ma_vals_type;
+    //typedef default_delay_discriminator                       delaydisrc;
+    typedef default_delay_discriminator                       discr_t;
+    typedef accumulator_set<
+        value_type, stats<
+            tag::acvf<discr_t>,
+            tag::acf<discr_t>,
+            tag::integrated_acvf<discr_t>,
+            tag::percentage_effective_sample_size<discr_t>,
+            tag::standard_error_autocorrelated<discr_t>,
+            tag::standard_error_iid<discr_t>
+            >
+    >            acc_type;
+
+    //model parameters and related quantities
+    std::vector<value_type>     coeffs;
+    std::vector<unsigned int>   lags;
+    std::vector<value_type>     true_acfs;
+    value_type                  true_integrated_acvf = 0.0;
+    std::size_t                 true_ess = 0;
+    //with these coeffs, should expect ess% > 100
+    {using namespace boost::assign; coeffs+=1.0,-0.5,0.2; lags+=0,1,2;}
+    unsigned int  K = coeffs.size()-1;
+    transform(lags.begin(),lags.end(),back_inserter(true_acfs),
+        make_acvf_moving_average(coeffs));
+    true_integrated_acvf
+        = 2*std::accumulate(true_acfs.begin(),true_acfs.end(),0.0);
+    true_integrated_acvf -=  *true_acfs.begin();
+    true_ess = boost::numeric::converter<std::size_t,value_type>::convert(
+        100.0*true_acfs[0]/true_integrated_acvf);
+
+    out << "->true_acvf: ";
+    copy(true_acfs.begin(),true_acfs.end(),
+        std::ostream_iterator<value_type>(out," "));
+    out << "<-" << std::endl;
+    {   value_type div = 1.0/true_acfs[0];
+        transform(true_acfs.begin(),true_acfs.end(),true_acfs.begin(),
+            boost::bind(std::multiplies<value_type>(),_1,div));
+    }
+    out << "->true_acf: ";
+    copy(true_acfs.begin(),true_acfs.end(),
+        std::ostream_iterator<value_type>(out," ")); out << "<-" << std::endl;
+    out << "->true var: " << true_integrated_acvf << "<-" << std::endl;
+    out << "->true ess%: " << true_ess << "<-" << std::endl;
+
+    //generation of a Moving Average of order K process
+    const unsigned long N = 100000;
+    urng_type urng(0);
+    gen_nd_type gen_nd(urng,nd_type());
+    ma_type ma(boost::make_iterator_range(coeffs.begin(),coeffs.end()));
+    ma_vals_type ma_vals(N);
+    for(ma_vals_type::iterator i=ma_vals.begin(); i<ma_vals.end(); i++)
+    { (*i) = ma(gen_nd); }
+
+    //estimation
+    acc_type acc(tag::delay<discr_t>::cache_size=(K+1));
+    for_each(ma_vals.begin(),ma_vals.end(),
+        boost::bind<void>(boost::ref(acc),_1));
+    out << "->sample size: " << N << std::endl;
+    out << "->estimated acvf: ";
+    copy(begin(acvf<discr_t>(acc)),end(acvf<discr_t>(acc)),
+        std::ostream_iterator<value_type>(out," "));
+    out<<"<-"<<std::endl;
+
+    out << "->estimated acf: ";
+    copy(begin(acf<discr_t>(acc)),end(acf<discr_t>(acc)),
+        std::ostream_iterator<value_type>(out," "));
+    out<<"<-"<<std::endl;
+
+    out << "->estimated var: "
+        << integrated_acvf<discr_t>(acc) << "<-" << std::endl;
+
+    out << "->estimated ess%: "
+        << percentage_effective_sample_size<discr_t>(acc)
+        << "<-" << std::endl;
+
+    out << "->estimated standard error assuming iid: "
+        << standard_error_iid<discr_t>(acc) << "<-" << std::endl;
+
+    out << "->estimated standard error assuming acf is zero after lag "
+        << K << ": "
+        << standard_error_autocorrelated<discr_t>(acc) << "<-" << std::endl;
+
+    //the above bundled into one class:
+    out << " --------- ";
+    out << "output from acvf_analysis:" << std::endl;
+    const unsigned int offset = 0;
+    const unsigned int stride = 1;
+    const unsigned int assumed_lag = 3;
+    statistics::acvf_analysis<value_type,discr_t> acvf_x(assumed_lag);
+    acvf_x(ma_vals,offset,stride);
+    acvf_x.print(out);
+
+    std::cout << "output of libs/accumulators/main.cpp was written to"
+        << filepath << std::endl;
+
+    return 0;
+}
Added: sandbox/statistics/binary_op/boost/binary_op/algorithm/for_each.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/algorithm/for_each.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,92 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::algorithm::for_each.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_BINARY_OP_ALGORITHM_FOR_EACH_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_FOR_EACH_HPP_ER_2009
+#include <algorithm>
+#include <boost/call_traits.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/binary_op/functional/untupler.hpp>
+
+namespace boost{
+namespace binary_op{
+                    
+    // Extends std::for_each to a binary sequence
+    template<
+        unsigned I0,
+        unsigned I1,
+        typename F,     
+        typename It_0,
+        typename It_1
+    >
+    F for_each(
+        It_0 b_0,
+        It_0 e_0,
+        It_1 b_1,
+        F f
+    );
+
+    template<
+        typename F,
+        typename It_0,
+        typename It_1
+    >
+    F for_each(
+        It_0 b_0,
+        It_0 e_0,
+        It_1 b_1,
+        F f
+    );
+
+
+    // Implementation //
+
+    template<
+        unsigned I0,
+        unsigned I1,
+        typename F,     
+        typename It_0,
+        typename It_1
+    >
+    F for_each(
+        It_0 b_0,
+        It_0 e_0,
+        It_1 b_1,
+        F f
+    ){
+        return std::for_each(
+            boost::make_zip_iterator(
+                boost::make_tuple(b_0, b_1)
+            ),
+            boost::make_zip_iterator(
+                boost::make_tuple(e_0, next(b_1,std::distance(b_0,e_0)))
+            ),
+            untupler<F,I0,I1>(f)
+        );
+    }
+
+    template<
+        typename F,
+        typename It_0,
+        typename It_1
+    >
+    F for_each(
+        It_0 b_0,
+        It_0 e_0,
+        It_1 b_1,
+        F f
+    ){
+        return for_each<0,1,F,It_0,It_1>(
+            b_0, e_0, b_1, f
+        );
+    }
+     
+            
+}//algorithm
+}//boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/algorithm/heads.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/algorithm/heads.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::algorithm::heads.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_BINARY_OP_ALGORITHM_HEADS_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_HEADS_HPP_ER_2009
+#include <algorithm>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/tuple/tuple.hpp>
+
+namespace boost{
+namespace binary_op{
+
+    // Extracts the i^th element from each tuple in [b,e)
+    template<unsigned i,typename It,typename It1>
+    It1 elements(
+        It b,       // tuples
+        It e,
+        It1 io
+    );
+
+    template<typename It,typename It1>
+    It1 heads(
+        It b,       // tuples
+        It e,
+        It1 io
+    );
+
+    template<typename It,typename It1>
+    It1 tails(
+        It b,       // tuples
+        It e,
+        It1 io
+    );
+
+    // Implementation //
+
+    template<unsigned i,typename It,typename It1>
+    It1 elements(
+        It b,       // tuples
+        It e,
+        It1 io
+    ){
+
+        typedef typename iterator_value<It>::type tuple_;
+        typedef typename add_reference<tuple_>::type ref_tuple_;
+
+        typedef typename boost::tuples::element<i,tuple_>::type elem_; 
+
+        // Why a loop rather than transform? Because creating a
+        // delegate function<...(const tuple&)> for get<i> is not
+        // straightforward
+        for( ; b<e; b++){
+            elem_ elem = get<i>(*b);
+            *io;
+            (*io) = elem;
+            ++io;
+        }
+        return io;
+
+    }
+
+    template<typename It,typename It1>
+    It1 heads(
+        It b,       // tuples
+        It e,
+        It1 io
+    ){
+        return elements<0>(b,e,io);
+    }
+
+    template<typename It,typename It1>
+    It1 tails(
+        It b,       // tuples
+        It e,
+        It1 io
+    ){
+        return elements<1>(b,e,io);
+    }
+
+}// algorithm
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/algorithm/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::algorithm::include.hpp                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_BINARY_OP_ALGORITHM_INCLUDE_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_INCLUDE_HPP_ER_2009
+
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <boost/binary_op/algorithm/heads.hpp>
+#include <boost/binary_op/algorithm/sort_on_head.hpp>
+#include <boost/binary_op/algorithm/tuples.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/algorithm/sort_on_head.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/algorithm/sort_on_head.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,138 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::algorithm::sort_on_head.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_BINARY_OP_ALGORITHM_SORT_ON_HEAD_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_SORT_ON_HEAD_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <functional>
+#include <utility>
+#include <boost/function.hpp>
+#include <boost/lambda/construct.hpp>
+#include <boost/bind.hpp>
+#include <boost/range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+
+namespace boost{
+namespace binary_op{
+
+       // TODO : sort_on_element<i=0,1> and sort_on_head or tail .
+
+      // sort_on_head<P>(s1,s2) reorders s1 based on the ordering 
+      // predicate P, and applies the same rearrangement of elements
+      // to s2.
+      template<
+        typename It,
+        typename It1,
+        template<typename> class Pred
+    >
+      void
+      sort_on_head(
+        It b,
+        It e,
+        It1 b_1
+      );
+      
+      template<typename It,typename It1>
+      void sort_on_head_greater(
+            It b,
+            It e,
+            It1 b1
+      );
+
+
+
+    // Implementation //
+      
+    template<
+        typename It,
+        typename It1,
+        template<typename> class Pred
+    >
+    void sort_on_head(
+        It b,
+        It e,
+        It1 b_1
+      )
+      {
+            typedef typename iterator_value<It>::type   val_t;
+            typedef typename iterator_value<It1>::type  val1_t;
+            typedef std::pair<val_t,val1_t>             pair_t;
+            typedef std::vector<pair_t>                 pairs_t;
+            typedef typename range_size<pairs_t>::type size_type;
+
+            pairs_t pairs;
+            pairs.reserve(
+                static_cast<size_type>(
+                    std::distance(b,e)
+                )
+            );
+            std::transform(
+                b,
+                e,
+                b_1,
+                back_inserter(pairs),
+                bind<pair_t>(
+                    boost::lambda::constructor<pair_t>(),
+                    _1,
+                    _2
+                )
+            );
+
+            function<val1_t(pair_t)> first = &pair_t::first;
+
+            sort(
+                begin(pairs),
+                end(pairs),
+                bind<bool>(
+                    Pred<val1_t>(),
+                    bind<val1_t>(
+                        first,
+                        _1
+                    ),
+                    bind<val1_t>(
+                        first,
+                        _2
+                    )
+                )
+            );
+            transform(
+                begin(pairs),
+                end(pairs),
+                b,
+                bind<val1_t>(
+                    &pair_t::first,
+                    _1
+                )
+            );
+            std::transform(
+                boost::begin(pairs),
+                boost::end(pairs),
+                b_1,
+                bind<val1_t>(
+                    &pair_t::second,
+                    _1
+                )
+            );
+      }
+
+      template<typename It,typename It1>
+      void sort_on_head_greater(
+            It b,
+            It e,
+            It1 b1
+      ){
+        return sort_on_head<It,It1,std::greater>(
+            b,
+            e,
+            b1
+        );
+      }
+}// algorithm
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/algorithm/tuples.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/algorithm/tuples.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,55 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::algorithm::tuples.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_BINARY_OP_ALGORITHM_TUPLES_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_TUPLES_HPP_ER_2009
+#include <algorithm>
+#include <boost/utility.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+
+namespace boost{
+namespace binary_op{
+
+    
+    // Writes to b_t a sequence of tuples formed by combining the sequences
+    // [b_1,e_1) and [b_2,e2)
+    template<typename It1,typename It2,typename ItT>
+    ItT tuples(
+        It1 b_1,
+        It1 e_1,
+        It2 b_2,
+        ItT b_t
+    );
+
+    // Implementation //
+
+    template<typename It1,typename It2,typename ItT>
+    ItT tuples(
+        It1 b_1,
+        It1 e_1,
+        It2 b_2,
+        ItT b_t
+    )
+    {
+        typedef typename iterator_difference<It1>::type diff_1_;
+        typedef typename iterator_difference<It2>::type diff_2_;
+        diff_1_ diff_1 = std::distance(b_1,e_1);
+        diff_2_ diff_2 = static_cast<diff_2_>(diff_1);
+        It2 e_2 = boost::next(b_2,diff_2);
+        return std::transform(
+            make_zip_iterator( make_tuple( b_1, b_2 ) ),
+            make_zip_iterator( make_tuple( e_1, e_2 ) ),
+            b_t
+        );    
+    }
+    
+}// algorithm
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/data/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::data::include.hpp                                              //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_BINARY_OP_DATA_INCLUDE_HPP_ER_2009
+#define BOOST_BINARY_OP_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/binary_op/data/tuple_range.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/data/tuple_range.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/data/tuple_range.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,64 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::data::tuple_range.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_BINARY_OP_DATA_TUPLE_RANGE_HPP_ER_2009
+#define BOOST_BINARY_OP_DATA_TUPLE_RANGE_HPP_ER_2009
+
+#include <boost/type_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+
+namespace boost{
+namespace binary_op{
+
+// Creates a range of tuples from two ranges
+template<typename Rx,typename Ry>
+struct tuple_range{
+    typedef typename remove_reference<Rx>::type const_rx_;
+    typedef typename remove_reference<Ry>::type const_ry_;
+    typedef typename range_iterator<const_rx_>::type it_x_;
+    typedef typename range_iterator<const_ry_>::type it_y_;
+
+    typedef boost::tuple<
+        it_x_,
+        it_y_
+    > iterator_tuple_;
+
+    typedef boost::zip_iterator<
+        iterator_tuple_
+    > zip_iterator_;
+
+    typedef iterator_range<zip_iterator_> type;
+    
+    static type make(
+        typename call_traits<Rx>::param_type rx,
+        typename call_traits<Ry>::param_type ry
+    ){
+        return type(
+            make_zip_iterator(
+                make_tuple(
+                    begin(rx),
+                    begin(ry)
+                )
+            ),
+            make_zip_iterator(
+                make_tuple(
+                    end(rx),
+                    end(ry)
+                )
+            )
+        );
+    }
+    
+};
+
+}//binary_op
+}//boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/functional/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/functional/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::functional::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_BINARY_OP_FUNCTIONAL_INCLUDE_HPP_ER_2009
+#define BOOST_BINARY_OP_FUNCTIONAL_INCLUDE_HPP_ER_2009
+
+#include <boost/binary_op/functional/untupler.hpp>
+#include <boost/binary_op/functional/match_accumulator.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/functional/match_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/functional/match_accumulator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,213 @@
+//////////////////////////////////////////////////////////////////////////////
+// binary_op::match_accumulator.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_BINARY_OP_FUNCTIONAL_MATCH_ACCUMULATOR_HPP_ER_2009
+#define BOOST_BINARY_OP_FUNCTIONAL_MATCH_ACCUMULATOR_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/concept/assert.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/function.hpp>
+#include <boost/range.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/mpl/nested_type.hpp>
+
+namespace boost{
+namespace binary_op{
+// Notation
+// S is the type of a sequence of pairs, each of type P = tuple<H,A>. Let
+// P1 = tuple<H,T> another pair type;
+// Let ItH, and ItA denote iterators to the heads and tails, respectively.
+// F_H = F<ItH> is the type of functor. Let s,p=(h,a),p=(h,t), f, and m denote
+// instances of S, P, F_H and match_accumulator, respectively. Let [b_h,e_h) and
+//  [b_a,e_a) denote the heads and tails in s. 
+//
+// Requirements:
+// i=f(b_h,e_h,h) is an iterator in in [b_h,e_h]
+//
+// Operations:
+// m(p1) calls i=f(b_h,e_h,h1), and
+// if i!= e_h, calls a(t1) else makes a new p=(h1,a=A()); calls a(t1);
+// and pushes p at the back of s.
+//
+// NB: H is typically a "feature" or covariate, used to partition a sample.
+// A is typically an accumulator, and T the quantity to be accumulated.
+    
+template<typename S,typename F>
+class match_accumulator {
+    typedef typename remove_reference<S>::type tuples_type;
+    typedef is_const<tuples_type> tuples_is_const_;
+    typedef is_reference<tuples_type> tuples_is_ref_;
+    typedef is_reference<F> f_is_ref_;
+    BOOST_MPL_ASSERT((
+        mpl::not_<tuples_is_const_>
+    ));
+    typedef typename range_reference<tuples_type>::type reference_type;
+    typedef typename range_iterator<tuples_type>::type iterator_type;
+    typedef typename range_value<tuples_type>::type value_type;
+    
+    template<unsigned i>
+    struct element{
+        typedef typename 
+            boost::tuples::element<i,value_type>::type value_; 
+        typedef typename add_reference<value_>::type reference_;
+        typedef reference_ (sig) (reference_type);
+        struct get{
+            typedef reference_ result_type;
+            get(){}
+            result_type operator()(reference_type t)const{ 
+                return tuples::get<i>(t); 
+            }
+        };
+    
+    };
+
+    typedef element<0> head_;
+    typedef element<1> tail_;
+
+    public:
+
+    // Constructor    
+    match_accumulator();
+    match_accumulator(
+        typename call_traits<S>::param_type tuples
+    );
+    match_accumulator(
+        typename call_traits<S>::param_type tuples,
+        typename call_traits<F>::param_type f
+    );
+    match_accumulator(const match_accumulator& that);
+    match_accumulator& operator=(const match_accumulator& that);
+
+    // TODO see below for loosening the requirement
+    BOOST_CONCEPT_ASSERT((Sequence<tuples_type>));
+
+    // Update
+    typedef bool result_type;
+    template<typename T>
+    result_type match_accumulator::operator()(const T& t);
+
+    //Access
+    typename call_traits<S>::const_reference tuples()const;
+
+    private:
+    template<typename T> iterator_type find(const T& t)const;
+    template<typename T> void process(reference_type p, const T& t);
+    template<typename T> void new_(const T& t);
+    typename call_traits<S>::value_type tuples_;
+    typename call_traits<F>::value_type f_;
+};
+        
+template<typename S,typename F>
+match_accumulator<S,F>::match_accumulator():tuples_(),f_(){
+    BOOST_MPL_ASSERT((mpl::not_<tuples_is_ref_>));
+    BOOST_MPL_ASSERT((mpl::not_<f_is_ref_>));
+}
+
+template<typename S,typename F>
+match_accumulator<S,F>::match_accumulator(
+    typename call_traits<S>::param_type tuples
+):tuples_(tuples),f_(){
+    BOOST_MPL_ASSERT((mpl::not_<f_is_ref_>));
+}
+
+template<typename S,typename F>
+match_accumulator<S,F>::match_accumulator(
+    typename call_traits<S>::param_type tuples,
+    typename call_traits<F>::param_type f
+):tuples_(tuples),f_(f){}
+
+template<typename S,typename F>
+match_accumulator<S,F>::match_accumulator(const match_accumulator& that)
+:tuples_(that.tuples_),f_(that.f_){}
+
+template<typename S,typename F>
+match_accumulator<S,F>& match_accumulator<S,F>::operator=(
+    const match_accumulator& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((mpl::not_<tuples_is_ref_>));
+        BOOST_MPL_ASSERT((mpl::not_<f_is_ref_>));
+        tuples_ = that.tuples_;
+        f_ = that.f_;
+    }
+    return *this;
+}
+
+//Query
+template<typename S,typename F>
+typename call_traits<S>::const_reference 
+match_accumulator<S,F>::tuples()const{ return this->tuples_; }
+
+//Update        
+template<typename S,typename F>
+template<typename T>
+typename match_accumulator<S,F>::result_type 
+match_accumulator<S,F>::operator()(const T& t){
+    iterator_type it = this->find(t); 
+    if(it!=boost::end(tuples_)){
+        this->process(*it,t);
+        return false;
+    }else{
+        this->new_(t); 
+        return true;
+    }
+}
+
+//Private
+
+template<typename S,typename F>
+template<typename T>
+void match_accumulator<S,F>::process(reference_type p, const T& t){
+    //typename tail_::reference_ tail = get<1>(p);
+    (get<1>(p))(get<1>(t));
+}    
+
+template<typename S,typename F>
+template<typename T>
+void match_accumulator<S,F>::new_(const T& t){
+    typename tail_::value_ tp;
+    value_type p(get<0>(t),tp);
+    // iterator_type b = begin(tuples);
+    iterator_type back = (this->tuples_).insert(
+        boost::end(this->tuples_), 
+        p
+    );
+    this->process(*back,t);
+    { 
+        // TODO, conditional on mpl::not_<is_container> i.e. range
+        // tuples_ tuples_type(b,next(back));
+    }
+}    
+
+template<typename S,typename F>
+template<typename T>
+typename match_accumulator<S,F>::iterator_type
+match_accumulator<S,F>::find(const T& t)const{
+//    function<typename head_::sig> get_hp = get<0>; //fails
+
+    typedef typename head_::get get_;
+    return this->f_(
+        make_transform_iterator(
+            boost::begin(tuples_),
+            get_()
+        ),
+        make_transform_iterator(
+            boost::end(tuples_),
+            get_()
+        ),
+        get<0>(t)
+    ).base();
+}
+    
+}// binary_op
+}// boost
+
+
+#endif
Added: sandbox/statistics/binary_op/boost/binary_op/functional/untupler.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/functional/untupler.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,96 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::functional::untupler.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_BINARY_OP_ALGORITHM_UNTUPLER_HPP_ER_2009
+#define BOOST_BINARY_OP_ALGORITHM_UNTUPLER_HPP_ER_2009
+#include <boost/call_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/functional.hpp>
+
+namespace boost{
+namespace binary_op{
+
+
+// Forwards members of a tuple to a binary functor.
+//
+// Usage:
+// Let [b,e) and f an iterator range over tuples and f a binary functor,
+// algorithm(b,e,untupler<F>(f)) 
+
+template<typename F,unsigned I0 = 0,unsigned I1 = 1>
+class untupler{
+    public:
+    typedef typename F::result_type result_type;
+
+    typedef F base_type;
+    
+    // Construction
+    untupler();
+    untupler(F f);
+    untupler(const untupler& that);
+    untupler& operator=(const untupler& that);
+                
+    // Evaluate
+    template<typename T> result_type operator()(const T& tuple);    
+    template<typename T> result_type operator()(const T& tuple)const;    
+    
+    operator F ()const{ return f_; }
+    
+    const base_type& base()const;
+    
+    private:
+
+    F f_;
+};
+
+template<typename F,unsigned I0,unsigned I1>
+untupler<F,I0,I1>::untupler()
+:f_(){}
+
+template<typename F,unsigned I0,unsigned I1>
+untupler<F,I0,I1>::untupler(F f)
+:f_(f){}
+
+template<typename F,unsigned I0,unsigned I1>
+untupler<F,I0,I1>::untupler(const untupler& that):f_(that.f_){}
+
+template<typename F,unsigned I0,unsigned I1>
+untupler<F,I0,I1>& 
+untupler<F,I0,I1>::operator=(const untupler& that){
+    if(&that!=this){
+        f_ = that.f_;
+    }
+    return *this;
+}
+        
+template<typename F,unsigned I0,unsigned I1>
+template<typename T>
+typename untupler<F,I0,I1>::result_type 
+untupler<F,I0,I1>::operator()(const T& t){
+    return this->f_(get<I0>(t),get<I1>(t));
+}
+
+template<typename F,unsigned I0,unsigned I1>
+template<typename T>
+typename untupler<F,I0,I1>::result_type 
+untupler<F,I0,I1>::operator()(const T& t)const{
+    return this->f_(get<I0>(t),get<I1>(t));
+}
+
+template<typename F,unsigned I0,unsigned I1>
+const typename untupler<F,I0,I1>::base_type& 
+untupler<F,I0,I1>::base()const{
+    return this->f_;
+}
+
+}//functional
+}//boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/boost/binary_op/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/boost/binary_op/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::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_BINARY_OP_INCLUDE_HPP_ER_2009
+#define BOOST_BINARY_OP_INCLUDE_HPP_ER_2009
+
+#include <boost/binary_op/algorithm/include.hpp>
+#include <boost/binary_op/data/include.hpp>
+#include <boost/binary_op/functional/include.hpp>
+
+#endif
Added: sandbox/statistics/binary_op/libs/binary_op/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,39 @@
+//////////////////////////////////////////////////////////////////////////////
+// binary_op::doc::readme                                                   //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+    These are C++ tools that pertain to the need to transform a binary sequence 
+    to a sequence of tuples (pairs) and vice versa. This need arises in 
+    statistics where the data consists of a set covariates, and a set of
+    responses. 
+
+[ Notation ]
+
+    A pair is called a tuple with a head and tail components.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+/sandbox/statistics/nn1/ 
+/sandbox/statistics/mpl/ 
+/sandbox/statistics/functional/ 
+/sandbox/statistics/binary_op/
+
+[ History ]
+
+July 2009 : Current version
\ No newline at end of file
Added: sandbox/statistics/binary_op/libs/binary_op/example/binary_f.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/binary_f.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::functional::binary_f.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 <ostream>
+#include <libs/binary_op/example//binary_f.h>
+
+// Not an example, but to be used by examples.
+binary_f::binary_f(std::ostream& out):out_(out),a_(0),b_(0){}
+binary_f::binary_f(const binary_f& that)
+:out_(that.out_),a_(that.a_),b_(that.b_){}
+    
+binary_f::result_type binary_f::operator()(val_t a,val_t b){
+    out_ << '(' << a << ',' << b << ')';
+    a_ = a;
+    b_ = b;
+}
Added: sandbox/statistics/binary_op/libs/binary_op/example/binary_f.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/binary_f.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+//  binary_op::example::functional::binary_f.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_BINARY_OP_EXAMPLE_BINARY_F_H_ER_2009
+#define LIBS_BINARY_OP_EXAMPLE_BINARY_F_H_ER_2009
+#include <ostream>
+// This is to be used by examples.
+struct binary_f{
+    typedef void result_type;
+    typedef unsigned val_t;
+    binary_f(std::ostream& out);
+    binary_f(const binary_f& that);
+    
+    result_type operator()(val_t a,val_t b);
+    std::ostream& out_;
+    val_t a_;
+    val_t b_;
+};
+
+#endif
Added: sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,74 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::find_accumulate.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 <list>
+#include <algorithm>
+#include <boost/foreach.hpp>
+#include <boost/range.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/functional/mean_var_accumulator.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/tuple/tuple.hpp>
+
+#include <boost/functional/find.hpp>
+#include <boost/binary_op/functional/match_accumulator.hpp>
+#include <libs/binary_op/example/find_accumulate.h>
+
+void example_find_accumulate(std::ostream& out){
+    out << "-> example_find_accumulate : ";
+    using namespace boost;
+    using namespace binary_op;
+    namespace fun_ = functional;
+    
+    typedef unsigned val_;
+    typedef std::vector<val_> val_vec_;
+    typedef accumulators::stats<
+        accumulators::tag::mean
+    >  stat_;
+    typedef accumulators::accumulator_set<val_,stat_> a_;
+    typedef tuple<val_,a_> xa_;
+    // tuple elements are accessed by reference so a tuple of values
+    // rather than references is enough, as long as the tuple itself is 
+    // passed by reference to the functor below.
+    typedef std::vector<xa_> vec_xa_; 
+    
+    const unsigned n = 5;
+    const unsigned n_repeat = 2;
+    
+    val_vec_ vec_x(n);
+    val_vec_ vec_y(n);
+    vec_xa_ vec_xa;
+    {
+        for(unsigned i = 0; i<n; i++){
+            vec_x[i] = i;
+            vec_y[i] = i;
+        } 
+    }
+    
+    typedef functional::find find_;
+    typedef match_accumulator<vec_xa_&,find_> functor_;
+    
+    // Look here for difference with match_accumulator2
+    std::for_each(
+        make_zip_iterator( make_tuple( begin(vec_x), begin(vec_y) ) ),
+        make_zip_iterator( make_tuple( end(vec_x), end(vec_y) ) ),
+        functor_(vec_xa)
+    );
+    
+    for(val_ l = 0; l<n_repeat; l++){
+        for(val_ i = 0; i<n; i++){
+            val_ j = vec_y[i];
+            const a_& a = get<1>(vec_xa.at(i));
+            val_ k = accumulators::mean(a);
+            BOOST_ASSERT(j == k);
+        }
+    }
+    
+    out << "<-" << std::endl;
+    
+}
Added: sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/find_accumulate.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::find_accumulate.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_BINARY_OP_EXAMPLE_FIND_ACCUMULATE_H_ER_2009
+#define LIBS_BINARY_OP_EXAMPLE_FIND_ACCUMULATE_H_ER_2009
+#include <ostream>
+
+void example_find_accumulate(std::ostream& out);
+
+#endif
Added: sandbox/statistics/binary_op/libs/binary_op/example/for_each.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/for_each.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,54 @@
+///////////////////////////////////////////////////////////////////////////////
+//  binary_op::example::for_each.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 <ostream>
+#include <vector>
+#include <functional>
+#include <boost/assert.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range.hpp>
+#include <boost/bind.hpp>
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <libs/binary_op/example//binary_f.h>
+#include <libs/binary_op/example/for_each.h>
+
+void example_for_each(std::ostream& out){
+    out << "-> example_binary_for_each :";
+
+    typedef unsigned val_;
+    
+    using namespace boost;
+    using namespace binary_op;
+    
+    typedef std::vector<val_> vec_t;
+    
+    vec_t vec_0;
+    vec_t vec_1;
+    {
+        using namespace boost::assign;
+        vec_0 += 0, 1, 2, 3, 4, 5, 6, 7;
+        vec_1 += 7, 6, 5, 4, 3, 2, 1, 0;
+    }
+
+    
+    out << "by value : ";
+    binary_f f_0 = for_each(
+        begin(vec_0),
+        end(vec_0),
+        begin(vec_1),
+        binary_f(out)
+        //  ret<??>(out << '(' << lambda::_1 << ',' << lambda::_2 << ')' )
+    );//(0,7)(1,6)(2,5)(3,4)(4,3)(5,2)(6,1)(7,0)
+    out << ' ';
+
+    BOOST_ASSERT(vec_0.back() == f_0.a_);    
+    BOOST_ASSERT(vec_1.back() == f_0.b_);    
+
+    out << "<-" << std::endl;
+}
+
Added: sandbox/statistics/binary_op/libs/binary_op/example/for_each.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/for_each.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+//  binary_op::example::for_each.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_BINARY_OP_EXAMPLE_FOR_EACH_H_ER_2009
+#define LIBS_BINARY_OP_EXAMPLE_FOR_EACH_H_ER_2009
+#include <ostream>
+
+void example_for_each(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,75 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::nn1_accumulate.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 <boost/range.hpp>
+#include <boost/foreach.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/functional/mean_var_accumulator.hpp>
+#include <boost/nn1/detail/ui_abs_to.hpp>
+#include <boost/nn1/functional/find_if.hpp>
+#include <boost/binary_op/functional/match_accumulator.hpp>
+#include <libs/binary_op/example/find_accumulate.h>
+
+void example_nn1_accumulate(std::ostream& out){
+    out << "-> example_nn1_accumulate : ";
+    using namespace boost;
+    using namespace binary_op;
+    namespace fun_ = functional;
+    
+    typedef unsigned val_;
+    typedef std::vector<val_> val_vec_;
+    typedef functional::mean_var_accumulator<val_>::type a_;
+    typedef tuple<val_,a_> xa_;
+    // tuple elements are accessed by reference so a tuple of values
+    // rather than references is enough, as long as the tuple itself is 
+    // passed by reference to the functor below.
+
+    typedef std::vector<xa_> vec_xa_; 
+    
+    const unsigned n = 5;
+    const unsigned n_repeat = 2;
+    
+    val_vec_ vec_x(n);
+    val_vec_ vec_y(n);
+    vec_xa_ vec_xa;
+    {
+        for(unsigned i = 0; i<n; i++){
+            vec_x[i] = i;
+            vec_y[i] = i;
+        } 
+    }
+    
+    // Look here for difference with match_accumulator3
+    typedef nn1::functional::find_if<nn1::detail::ui_abs_to,val_> find_;
+    typedef match_accumulator<vec_xa_&,find_> functor_;
+    
+    val_ t = 1;
+    find_ find(t);
+    functor_ f(
+        vec_xa,
+        find
+    );
+
+    std::for_each(
+        make_zip_iterator( make_tuple( begin(vec_x), begin(vec_y) ) ),
+        make_zip_iterator( make_tuple( end(vec_x), end(vec_y) ) ),
+        f
+    );
+    
+    for(val_ l = 0; l<n_repeat; l++){
+        for(val_ i = 0; i<n; i++){
+            val_ j = vec_y[i];
+            const a_& a = get<1>(vec_xa.at(i));
+            val_ k = accumulators::mean(a);
+            BOOST_ASSERT(j == k);
+        }
+    }
+    
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/nn1_accumulate.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::nn1_accumulate.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_BINARY_OP_EXAMPLE_NN1_ACCUMULATE_H_ER_2009
+#define LIBS_BINARY_OP_EXAMPLE_NN1_ACCUMULATE_H_ER_2009
+#include <ostream>
+
+void example_nn1_accumulate(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/libs/binary_op/example/untuple.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/untuple.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::functional::untupler.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 <boost/type_traits/is_same.hpp>
+#include <boost/static_assert.hpp>
+#include <boost/assert.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/typeof/typeof.hpp>
+#include <boost/binary_op/functional/untupler.hpp>
+#include <libs/binary_op/example/binary_f.h>
+#include <libs/binary_op/example/untuple.h>
+
+#include <boost/ref.hpp>
+
+void example_untupler(std::ostream& out){
+    out << "-> example_untupler : ";
+
+    using namespace boost;
+    using namespace binary_op;
+    typedef untupler<binary_f,0,1> unt_;
+    
+    const unsigned a = 8;
+    const unsigned b = 9;
+    
+    BOOST_AUTO(t,make_tuple(a,b));
+    binary_f f_(out);
+    BOOST_ASSERT(f_.a_ == 0);
+    BOOST_ASSERT(f_.b_ == 0);
+
+    unt_ unt0(f_); 
+        
+    typedef 
+        boost::is_same<binary_f::result_type, unt_::result_type> pred_0;
+    BOOST_STATIC_ASSERT(pred_0::value);
+
+    unt0(t);
+    BOOST_ASSERT(f_.a_ == 0);
+    BOOST_ASSERT(f_.b_ == 0);
+
+
+    out << "<-" << std::endl;
+    
+}
\ No newline at end of file
Added: sandbox/statistics/binary_op/libs/binary_op/example/untuple.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/example/untuple.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// binary_op::example::functional::untupler.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_BINARY_OP_EXAMPLE_UNTUPLE_H_ER_2009
+#define LIBS_BINARY_OP_EXAMPLE_UNTUPLE_H_ER_2009
+
+#include <ostream>
+
+void example_untupler(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/binary_op/libs/binary_op/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/binary_op/libs/binary_op/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <libs/binary_op/example/for_each.h>
+#include <libs/binary_op/example/find_accumulate.h>
+#include <libs/binary_op/example/nn1_accumulate.h>
+
+int main(){
+
+    example_for_each(std::cout);
+    example_find_accumulate(std::cout);
+    example_nn1_accumulate(std::cout);
+
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::chi_squared.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_DIST_RANDOM_DISTRIBUTIONS_CHI_SQUARED_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_CHI_SQUARED_HPP_ER_2009
+#include <boost/standard_distribution/distributions/chi_squared.hpp>
+#include <boost/random/chi_squared.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename T,typename P>
+    struct dist_random< 
+        boost::math::chi_squared_distribution<T,P> 
+    >{
+        typedef math::chi_squared_distribution<T> dist_;
+        typedef boost::random::chi_squared_distribution<T> type;
+        
+        static type make(const dist_& d){ 
+            return type(d.degrees_of_freedom()); 
+        }
+    };
+    
+}// boost
+
+#endif
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,29 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::exponential.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_DIST_RANDOM_DISTRIBUTIONS_EXPONENTIAL_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_EXPONENTIAL_HPP_ER_2009
+#include <boost/standard_distribution/distributions/exponential.hpp>
+#include <boost/random/exponential_distribution.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename T,typename P>
+    struct dist_random< 
+        boost::math::exponential_distribution<T,P> 
+    >{
+        typedef boost::math::exponential_distribution<T> dist_;
+        typedef boost::exponential_distribution<T> type;
+        
+        static type make(const dist_& d){ return type(d.lambda()); }
+    };
+    
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::gamma.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_DIST_RANDOM_DISTRIBUTIONS_GAMMA_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_GAMMA_HPP_ER_2009
+#include <boost/standard_distribution/distributions/gamma.hpp>
+#include <boost/random/gamma_distribution.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename T,typename P>
+    struct dist_random< 
+        boost::math::gamma_distribution<T,P> 
+    >{
+        typedef boost::math::gamma_distribution<T,P> dist_;
+        typedef boost::gamma_distribution<T> type;
+        
+        static type make(const dist_& d){ 
+            return type(d.shape()); 
+        }
+    };
+    
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::include.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_DIST_RANDOM_DISTRIBUTIONS_INCLUDE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_INCLUDE_HPP_ER_2009
+
+#include <boost/dist_random/distributions/chi_squared.hpp>
+#include <boost/dist_random/distributions/exponential.hpp>
+#include <boost/dist_random/distributions/gamma.hpp>
+#include <boost/dist_random/distributions/normal.hpp>
+#include <boost/dist_random/distributions/location_scale.hpp>
+#include <boost/dist_random/distributions/students_t.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,37 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::location_scale.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_DIST_RANDOM_DISTRIBUTIONS_LOCATION_SCALE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_LOCATION_SCALE_HPP_ER_2009
+#include <boost/standard_distribution/distributions/location_scale.hpp>
+#include <boost/random/location_scale.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+#include <boost/dist_random/functional/make_random.hpp>
+
+namespace boost{
+
+    template<typename Z>
+    struct dist_random< 
+        boost::math::location_scale_distribution<Z> 
+    >{
+        typedef boost::math::location_scale_distribution<Z> dist_;
+        typedef typename dist_random<Z>::type z_;
+        typedef boost::random::location_scale_distribution<z_> type;
+        
+        static type make(const dist_& d){ 
+            return type(
+                make_random(d.z()),
+                d.mu(),
+                d.sigma()
+            ); 
+        }
+    };
+    
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::normal.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_DIST_RANDOM_DISTRIBUTIONS_NORMAL_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_NORMAL_HPP_ER_2009
+#include <boost/standard_distribution/distributions/exponential.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename T,typename P>
+    struct dist_random< 
+        boost::math::normal_distribution<T,P> 
+    >{
+        typedef math::normal_distribution<T,P> dist_;
+        typedef boost::normal_distribution<T> type;
+        
+        static type make(const dist_& d){ 
+            return type(d.location(),d.scale()); 
+        }
+    };
+    
+}// boost
+
+#endif
+
Added: sandbox/statistics/dist_random/boost/dist_random/distributions/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/distributions/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::distributions::students_t.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_DIST_RANDOM_DISTRIBUTIONS_STUDENTS_T_HPP_ER_2009
+#define BOOST_DIST_RANDOM_DISTRIBUTIONS_STUDENTS_T_HPP_ER_2009
+#include <boost/standard_distribution/distributions/students_t.hpp>
+#include <boost/random/students_t.hpp>
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename T,typename P>
+    struct dist_random< 
+        boost::math::students_t_distribution<T,P> 
+    >{
+        typedef boost::math::students_t_distribution<T,P> dist_;
+        typedef boost::random::students_t_distribution<T> type;
+        
+        static type make(const dist_& d){ 
+            return type(d.degrees_of_freedom()); 
+        }
+    };
+    
+}// boost
+
+#endif
Added: sandbox/statistics/dist_random/boost/dist_random/functional/check_convergence.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/functional/check_convergence.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,147 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::functional::check_convergence.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_DIST_RANDOM_FUNCTIONAL_CHECK_CONVERGENCE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_FUNCTIONAL_CHECK_CONVERGENCE_HPP_ER_2009
+#include <sstream>
+#include <ostream>
+#include <algorithm>
+#include <vector>
+#include <iterator>
+#include <string>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/random/mersenne_twister.hpp>
+
+#include <boost/random/ref_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+
+namespace boost{
+namespace random{
+
+    // Verifies that the distribution and the random generator agree
+    template<typename T>
+    class check_convergence{
+        typedef std::string str_;
+
+        public:
+        typedef T value_type;
+        typedef std::vector<T> vals_;
+        typedef typename range_size<vals_>::type size_type;
+        // Construction
+        check_convergence();
+    
+        // Update
+        template<typename R,typename D,typename U>
+        void operator()(
+            const D&  mdist,
+            const R&  rdist,  
+            size_type n_draw,
+            size_type n_ks,
+            U&        urng
+        );
+
+        // Access
+        const vals_& draws()const;
+        const vals_& kolmogorov_smirnovs()const;
+        str_ distribution()const;
+        size_type increment()const;
+        
+        private:
+        str_ dist_;
+        vals_ draws_;
+        vals_ kss_;
+    };
+
+    template<typename T>
+    std::ostream& operator<<(
+        std::ostream& out, const check_convergence<T> that);
+
+    // Implementation 
+
+    template<typename T>
+    std::ostream& operator<<(
+        std::ostream& out, const check_convergence<T> that){
+        static const char* msg 
+            = "%1% : ks distances by increments of n = %2% : ";
+        format f(msg); 
+        f % that.distribution() % that.increment();
+        out << f.str(); 
+        out.flush();
+        std::copy(
+            boost::begin(that.kolmogorov_smirnovs()),
+            boost::end(that.kolmogorov_smirnovs()),
+            std::ostream_iterator<T>(out," ")
+        );
+        return out;
+    }
+
+    template<typename T>
+    check_convergence<T>::check_convergence(){}
+
+    template<typename T>
+    template<typename R,typename D,typename U>
+    void check_convergence<T>::operator()(
+        const D&                    mdist,
+        const R&                    rdist,
+        size_type                   n_draw,
+        size_type                   n_ks,
+        U&                          urng
+    ){
+        BOOST_ASSERT(n_draw % n_ks == 0);
+        typedef boost::variate_generator<U&,R>        vg_;
+
+        dist_.clear();
+        std::ostringstream outs;  
+        outs << mdist;   
+        dist_ = outs.str();      
+        
+        draws_.resize(n_draw);
+        kss_.resize(n_ks);
+        vg_ vg(urng,rdist);
+
+        std::generate_n(boost::begin(draws_),n_draw,vg);
+        non_param::sequential_kolmogorov_smirnov_distance(
+            mdist,
+            boost::begin(draws()),
+            boost::end(draws()),
+            n_ks,
+            boost::begin(kss_)
+        );
+    }
+
+    template<typename T>
+    const typename check_convergence<T>::vals_&
+    check_convergence<T>::draws()const{
+        return draws_;
+    }
+
+    template<typename T>
+    const typename check_convergence<T>::vals_&
+    check_convergence<T>::kolmogorov_smirnovs()const{
+        return kss_;
+    }
+
+    template<typename T>
+    typename check_convergence<T>::str_ 
+    check_convergence<T>::distribution()const{
+        return dist_;
+    }
+
+    template<typename T>
+    typename check_convergence<T>::size_type
+    check_convergence<T>::increment()const{
+        return size(this->draws()) / size(this->kolmogorov_smirnovs());
+    }
+
+}// random
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/functional/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/functional/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::functional::include.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_DIST_RANDOM_FUNCTIONAL_INCLUDE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_FUNCTIONAL_INCLUDE_HPP_ER_2009
+
+#include <boost/dist_random/functional/check_convergence.hpp> 
+#include <boost/dist_random/functional/make_random.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/functional/make_random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/functional/make_random.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::functional::make_random.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_DIST_RANDOM_FUNCTIONAL_MAKE_RANDOM_HPP_ER_2009
+#define BOOST_DIST_RANDOM_FUNCTIONAL_MAKE_RANDOM_HPP_ER_2009
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    template<typename D>
+    typename dist_random<D>::type
+    make_random(const D& d){
+        typedef dist_random<D> meta_;
+        return meta_::make(d);
+    }
+
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::include.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_DIST_RANDOM_INCLUDE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_INCLUDE_HPP_ER_2009
+
+#include <boost/dist_random/meta/include.hpp>
+#include <boost/dist_random/distributions/include.hpp>
+#include <boost/dist_random/functional/include.hpp>
+#include <boost/dist_random/random/include.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/meta/dist_random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/meta/dist_random.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::meta::dist_random.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_DIST_RANDOM_META_DIST_RANDOM_HPP_ER_2009
+#define BOOST_DIST_RANDOM_META_DIST_RANDOM_HPP_ER_2009
+
+namespace boost{
+
+    // Specialized on D
+    template<typename D>
+    struct dist_random{
+        // typedef ... type
+        // type make(const D& d);
+    };
+
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_input.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_input.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,23 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::meta::dist_random_input.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_DIST_RANDOM_META_DIST_RANDOM_INPUT_HPP_ER_2009
+#define BOOST_DIST_RANDOM_META_DIST_RANDOM_INPUT_HPP_ER_2009
+
+namespace boost{
+
+    // Specialized on D
+    template<typename D>
+    struct dist_random_input{
+        typedef typename dist_random<D>::type r_;
+        typedef typename r_::input_type type;
+    };
+
+}// boost
+
+#endif
Added: sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_result.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/meta/dist_random_result.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::meta::dist_random_result.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_DIST_RANDOM_META_DIST_RANDOM_RESULT_HPP_ER_2009
+#define BOOST_DIST_RANDOM_META_DIST_RANDOM_RESULT_HPP_ER_2009
+#include <boost/dist_random/meta/dist_random.hpp>
+
+namespace boost{
+
+    // Specialized on D
+    template<typename D>
+    struct dist_random_result{
+        typedef typename dist_random<D>::type r_;
+        typedef typename r_::result_type type;
+    };
+
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/meta/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/meta/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,17 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::meta::include.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_DIST_RANDOM_META_INCLUDE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_META_INCLUDE_HPP_ER_2009
+
+#include<boost/dist_random/meta/dist_random.hpp>
+#include<boost/dist_random/meta/dist_random_input.hpp>
+#include<boost/dist_random/meta/dist_random_result.hpp>
+
+#endif
+
Added: sandbox/statistics/dist_random/boost/dist_random/random/generate_n.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/random/generate_n.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,113 @@
+///////////////////////////////////////////////////////////////////////////////
+// dist_random::random::generate_n.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_DIST_RANDOM_RANDOM_GENERATE_N_HPP_ER_2009
+#define BOOST_DIST_RANDOM_RANDOM_GENERATE_N_HPP_ER_2009
+#include <algorithm>
+#include <boost/concept_check.hpp>
+#include <boost/iterator/iterator_concepts.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/scalar_dist/fun_wrap/include.hpp>
+#include <boost/scalar_dist/algorithm/transform.hpp>
+#include <boost/dist_random/functional/make_random.hpp>
+
+namespace boost{
+
+    // Generates a sample from a distribution
+    template<typename ItX,typename N,typename D,typename U> 
+    typename enable_if<
+        math::is_scalar_dist<D>,
+        ItX 
+    >::type
+    generate_n(
+        ItX b_x, N n,const D& dist, U& urng
+    );
+
+    // Same as above and a function associated with the distribution
+    template<template<typename> class F,
+        typename ItX,typename N,typename ItF,typename D,
+        typename U> 
+    typename enable_if<
+        math::is_scalar_dist<D>,
+        ItX 
+    >::type
+    generate_function_n(
+        ItX b_x, ItF b_f, N n,const D& dist, U& urng
+    );
+
+    // F =  math::fun_wrap::log_unnormlized_pdf_ 
+    template<typename ItX,typename N,typename ItL,typename D,
+        typename U> 
+    typename enable_if<
+        math::is_scalar_dist<D>,
+        ItX 
+    >::type
+    generate_n(
+        ItX b_x, ItL b_lpdf, N n,const D& dist, U& urng
+    ){
+        return generate_function_n<math::fun_wrap::log_unnormalized_pdf_>(
+            b_x,b_lpdf,n,dist,urng
+        );
+    }
+
+    // Implementation //
+
+    template<typename ItX,typename N,typename D,typename U> 
+    typename enable_if<
+        math::is_scalar_dist<D>,
+        ItX 
+    >::type
+    generate_n(
+        ItX b_x, N n,const D& dist, U& urng
+    ){
+        typedef typename dist_random<D>::type rand_;
+        typedef boost::variate_generator<U&,rand_> vg_;
+        vg_ vg(
+            urng,
+            make_random(dist)
+        );
+        return std::generate_n(
+            b_x,
+            n,
+            vg
+        );
+    }
+    
+    template<
+        template<typename> class F,
+        typename ItX,
+        typename N,
+        typename ItF,
+        typename D,
+        typename U
+    > 
+    typename enable_if<
+        math::is_scalar_dist<D>,
+        ItX 
+    >::type
+    generate_function_n(ItX b_x, ItF b_f, N n,const D& dist, U& urng){
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<ItX>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<ItX>));
+        ItX e_x = generate_n(
+            b_x,
+            n,
+            dist,
+            urng
+        );
+        boost::math::transform<F>(
+            dist,
+            b_x,
+            e_x,
+            b_f
+        );
+        return e_x;
+    }
+
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/random/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/random/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::random::include.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_DIST_RANDOM_RANDOM_INCLUDE_HPP_ER_2009
+#define BOOST_DIST_RANDOM_RANDOM_INCLUDE_HPP_ER_2009
+
+#include <boost/dist_random/random/generate_n.hpp>
+#include <boost/dist_random/random/sample.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/boost/dist_random/random/sample.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/boost/dist_random/random/sample.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,38 @@
+///////////////////////////////////////////////////////////////////////////////
+// dist_random::random::sample.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_DIST_RANDOM_RANDOM_SAMPLE_N_HPP_ER_2009
+#define BOOST_DIST_RANDOM_RANDOM_SAMPLE_N_HPP_ER_2009
+#include <boost/random/variate_generator.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/dist_random/meta/dist_random_result.hpp>
+#include <boost/dist_random/functional/make_random.hpp>
+
+namespace boost{
+
+    // can't call it random because that name is also namespace
+
+    // Generates one draw from a distribution
+    // If you need to call this repeatedly, generate_n is faster
+    template<typename D,typename U> 
+    typename lazy_enable_if<
+        math::is_scalar_dist<D>,
+        dist_random_result<D> 
+    >::type
+    sample(const D& dist, U& urng){
+        typedef dist_random<D> dr_;
+        typedef typename dr_::type r_; 
+        typedef variate_generator<U&,r_> vg_;
+        // Costly but necessary to guarantee U is mapped to agree with 
+        // dist_random_input<D>::type
+        vg_ vg(urng,make_random(dist));
+        return vg();
+    }
+        
+}
+
+#endif
Added: sandbox/statistics/dist_random/libs/dist_random/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::doc::readme                                                 //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ classes that bridge a distribution type (D) defined in boost::math
+to a class type (Rd) that models RandomDistribution. For example,
+
+    generate_n(b_x, n,dist, urng);
+    sample(dist,urng)
+
+[ Useful links ]
+
+http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/index.html
+http://www.boost.org/doc/libs/1_39_0/libs/random/index.html
+
+[ meta ]
+
+    A metafunction that map a distribution to a type (or related traits) that 
+    model RandomDistribution. 
+
+[ distributions ]
+
+    Specializes dist_random for each distribution (normal, exponential etc.).
+
+[ functional ]
+
+    check_convergence<T>    Checks agreement between the distribution and its
+                            random counterpart based using a kolmogorov-smirnov
+                            methodology.
+[ random ]    
+    
+    Function templates that sample from the distribution 
+        generate_n(b_x, n,dist, urng);
+        sample(dist,urng)
+    The actual random generator is hidden in the implementation. These functions
+    are conditioned on is_scalar_dist<D> to avoid ambiguity (SFINAE) with a 
+    similar interface defined in joint_dist.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+/sandbox/arithmetic/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/non_param/ 
+/sandbox/statistics/random/ 
+/sandbox/statistics/standard_distribution/ 
+
+[ History ]
+
+July 2009 : Current version
+
+[ Output ]
+
+main.cpp:
+
+example_chi_squared -> 
+chi_squared(10) : ks distances by increments of n = 100 : 0.0453213 0.0646862 0.0456301 0.0390222 0.0376862 0.0480195 0.0357961 0.0262651 0.0223762 0.018956 <-
+
+example_location_scale_students_t -> 
+location_scale_distribution( 1 + 2 students_t(10)) : ks distances by increments of n = 100 : 0.0801433 0.0751433 0.0354292 0.0220838 0.0296084 0.034622 0.044622 0.0444561 0.0418166 0.040737 <-
+
+-> example_generate_n-0.0227775 -0.1228 -1.24091 -0.560956 -1.69145 -1.77806 -0.182816 -0.066972 -0.167195 -0.201216 -0.530185 -0.262165 -0.00662101 -0.202104 -4.52822 -0.416806 -5.25114 -0.392863 -3.26816 -0.164367 -0.389214 -0.904826 -3.83513 -0.133972 -0.108151 -0.00822772 -1.58654 -0.0134714 -0.034021 -0.318419 -0.00189254 -0.00290242 -0.0927241 -0.0265827 -0.760555 -0.260439 -0.144761 -1.96251 -0.656093 -0.044406 -0.49832 -1.10081 -0.426116 -0.0221952 -0.0810457 -0.157115 -0.957996 -0.185695 -0.0953613 -0.413364 -0.00318939 -1.34638 -0.00119814 -0.642699 -0.333056 -0.215277 -0.0598107 -0.131187 -0.0811628 -0.278249 -0.118659 -1.47727 -0.365579 -0.0150239 -0.0583624 -2.00072 -0.148264 -0.0132129 -3.44333 -1.68415 -0.342194 -1.38323 -0.0154377 -0.118303 -0.241623 -1.20124 -0.610643 -0.063857 -1.03923 -0.0502416 -0.115589 -0.0189673 -0.127707 -0.10828 -0.000498153 -0.0520764 -0.00291445 -0.0342074 -0.0784259 -0.447059 -0.60994 -0.00252972 -0.593436 -0.0751535 -0.580848 -0.99891 -0.1618 -2.37492 -0.0014284
8 -1.64639 <-
+
+-> example_sample<-
+
Added: sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,56 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::chi_squared.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <iterator>
+#include <boost/static_assert.hpp>
+#include <boost/random/mersenne_twister.hpp>
+
+#include <boost/standard_distribution/distributions/chi_squared.hpp>
+#include <boost/dist_random/distributions/chi_squared.hpp>
+#include <boost/dist_random/functional/check_convergence.hpp>
+#include <boost/random/ref_distribution.hpp>
+#include <boost/dist_random/functional/make_random.hpp>
+
+#include <libs/dist_random/example/chi_squared.h>
+
+void example_chi_squared(std::ostream& out){
+
+    out << "example_chi_squared -> " << std::endl;
+    using namespace boost;
+    
+    // Types
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vals_;
+    typedef mt19937                                         urng_;
+
+    typedef math::chi_squared_distribution<val_>            mdist_;
+    typedef boost::random::check_convergence<val_>          check_;
+
+    // Constants
+    const val_ df           = 10;
+    const unsigned n_draw   = 1e3;
+    const unsigned n_ks     = 1e1;
+
+    BOOST_STATIC_ASSERT(n_draw % n_ks == 0);
+    mdist_ mdist( df );
+    urng_ urng;
+
+    check_ check;
+    check(
+        mdist,
+        make_random(mdist),
+        n_draw,
+        n_ks,
+        urng
+    );
+    
+    out << check;
+    out << "<-" << std::endl;
+
+}
Added: sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/chi_squared.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::chi_squared.h                                      //
+//                                                                          //
+//  (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 LIBS_DIST_RANDOM_EXAMPLE_CHI_SQUARED_H_ER_2009
+#define LIBS_DIST_RANDOM_EXAMPLE_CHI_SQUARED_H_ER_2009
+#include <ostream>
+
+void example_chi_squared(std::ostream&);
+
+#endif
Added: sandbox/statistics/dist_random/libs/dist_random/example/generate_n.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/generate_n.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,50 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::generate_n.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <ostream>
+#include <vector>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/dist_random/distributions/normal.hpp>
+#include <boost/dist_random/random/generate_n.hpp>
+#include <libs/dist_random/example/generate_n.h>
+
+void example_generate_n(std::ostream& out){
+    out << "-> example_generate_n";
+    using namespace boost;
+    typedef double val_;
+    typedef std::vector<val_> vals_;
+    typedef mt19937 urng_;
+    const long n = 1e2;
+    urng_ urng;
+    vals_ draws(n);
+    vals_ lpdfs;
+    {
+        typedef math::normal_distribution<val_> dist_;
+        dist_ dist;
+        lpdfs.clear();
+        generate_n(
+            boost::begin(draws),
+            std::back_inserter(lpdfs),
+            n,
+            dist,
+            urng
+        );
+
+        std::copy(
+            boost::begin(lpdfs),
+            boost::end(lpdfs),
+            std::ostream_iterator<val_>(out," ")
+        );
+        
+    }
+
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/dist_random/libs/dist_random/example/generate_n.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/generate_n.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::generate_n.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 LIBS_DIST_RANDOM_EXAMPLE_GENERATE_N_H_ER_2009
+#define LIBS_DIST_RANDOM_EXAMPLE_GENERATE_N_H_ER_2009
+#include <ostream>
+
+void example_generate_n(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,61 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::location_scale_students_t.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <boost/static_assert.hpp>
+#include <boost/random/mersenne_twister.hpp>
+
+#include <boost/standard_distribution/distributions/students_t.hpp>
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+#include <boost/random/students_t.hpp>
+#include <boost/random/location_scale.hpp>
+#include <boost/dist_random/functional/check_convergence.hpp>
+#include <boost/dist_random/distributions/students_t.hpp>
+#include <boost/dist_random/distributions/location_scale.hpp>
+
+#include <libs/dist_random/example/location_scale_students_t.h>
+
+void example_location_scale_students_t(std::ostream& out){
+
+    out << "example_location_scale_students_t -> " << std::endl;
+    using namespace boost;
+    
+    // Types
+    typedef std::string                                     str_;
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vals_;
+    typedef mt19937                                         urng_;
+
+    typedef math::students_t_distribution<val_>             mstud_;
+    typedef math::location_scale_distribution<mstud_>       mdist_;
+
+    typedef boost::random::check_convergence<val_>          check_;
+
+    // Constants
+    const val_ df           = 10;
+    const val_ mu           = 1.0;
+    const val_ sigma        = 2.0;
+    const unsigned n_draw   = 1e3;
+    const unsigned n_ks     = 1e1;
+
+    BOOST_STATIC_ASSERT(n_draw % n_ks == 0);
+    mdist_ mdist( mstud_( df ), mu , sigma);
+    urng_ urng;
+
+    check_ check;
+    check(
+        mdist,
+        make_random(mdist),
+        n_draw,
+        n_ks,
+        urng
+    );
+    
+    out << check;
+    out << "<-" << std::endl;
+
+}
\ No newline at end of file
Added: sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/location_scale_students_t.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::location_scale_students.h                          //
+//                                                                          //
+//  (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 LIBS_DIST_RANDOM_EXAMPLE_LOCATION_SCALE_STUDENTS_T_H_ER_2009
+#define LIBS_DIST_RANDOM_EXAMPLE_LOCATION_SCALE_STUDENTS_T_H_ER_2009
+#include <ostream>
+
+void example_location_scale_students_t(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/dist_random/libs/dist_random/example/sample.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/sample.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,49 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::sample.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <ostream>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/standard_distribution/distributions/include.hpp>
+#include <boost/dist_random/distributions/include.hpp>
+#include <boost/dist_random/random/sample.hpp>
+
+void example_sample(std::ostream& out){
+    out << "-> example_sample";
+
+    using namespace boost;
+    typedef double val_;
+    typedef mt19937 urng_;
+    urng_ urng;
+
+    {
+        typedef math::chi_squared_distribution<val_>    dist_;
+        sample(dist_(4),urng);
+    }
+    {
+        typedef math::exponential_distribution<val_>    dist_;
+        sample(dist_(),urng);
+    }
+    {
+        typedef math::gamma_distribution<val_>          dist_;
+        sample(dist_(4),urng);
+    }
+    {
+        typedef math::normal_distribution<val_>         dist_;
+        sample(dist_(),urng);
+    }
+    {
+        typedef math::students_t_distribution<val_>     dist_;
+        sample(dist_(4),urng);
+    }
+    {
+        typedef math::students_t_distribution<val_>     dist_;
+        typedef math::location_scale_distribution<dist_> lsdist_;
+        sample(lsdist_(dist_(4),0,1),urng);
+    }
+    out << "<-";
+}
Added: sandbox/statistics/dist_random/libs/dist_random/example/sample.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/example/sample.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::example::sample.h                                           //
+//                                                                          //
+//  (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 LIBS_DIST_RANDOM_EXAMPLE_SAMPLE_H_ER_2009
+#define LIBS_DIST_RANDOM_EXAMPLE_SAMPLE_H_ER_2009
+#include <ostream>
+
+void example_sample(std::ostream&);
+
+#endif
Added: sandbox/statistics/dist_random/libs/dist_random/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/dist_random/libs/dist_random/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+// dist_random::src::main.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/dist_random/example/chi_squared.h>
+#include <libs/dist_random/example/location_scale_students_t.h>
+#include <libs/dist_random/example/generate_n.h>
+#include <libs/dist_random/example/sample.h>
+
+int main(){
+
+    example_chi_squared(std::cout); 
+    std::cout << std::endl;
+    example_location_scale_students_t(std::cout);
+    std::cout << std::endl;
+    example_generate_n(std::cout);
+    std::cout << std::endl;
+    example_sample(std::cout);
+
+    return 0;
+}
+
+
Added: sandbox/statistics/functional/boost/functional/clock.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/clock.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,88 @@
+///////////////////////////////////////////////////////////////////////////////
+// boost::functional::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_FUNCTIONAL_CLOCK_HPP_ER_2009
+#define BOOST_FUNCTIONAL_CLOCK_HPP_ER_2009
+#include <iostream>
+
+namespace boost{
+namespace functional{
+
+    // Models Generator
+    //
+    // This clock generates equally spaced times
+    template<typename T>
+    struct clock{
+        public:
+        clock();
+        clock(const T& start_time,const T& delta_time);
+        clock(const clock&);
+        clock& operator=(const clock&);
+
+        typedef T result_type;
+
+        result_type operator()();
+
+        template<typename T1>
+        friend std::istream& operator>>(std::istream& is, clock<T1>& c);
+
+        private:
+        T start_time_;
+        T delta_time_;  
+    };
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& os, const clock<T>& c);
+   
+    // Implementation //
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,const clock<T>& c){
+        out << '(' << c.start_time_ << ',' << c.delta_time_ << ')';
+        return out;
+    }
+    
+    template<typename T>
+    std::istream& operator>>(std::istream& is, clock<T>& c){
+        is >> std::ws >> c.start_time_ >> std::ws >> c.delta_time_ >> std::ws;
+        return is;
+    }
+    
+    template<typename T>
+    clock<T>::clock()
+    :start_time_(static_cast<T>(0)),delta_time_(static_cast<T>(0)){}
+    
+    template<typename T>
+    clock<T>::clock(const T& start_time,const T& delta_time)
+    :start_time_(start_time),delta_time_(delta_time){}
+
+    template<typename T>
+    clock<T>::clock(const clock& that)
+    :start_time_(that.start_time_),delta_time_(that.delta_time_){}
+    
+    template<typename T>
+    clock<T>& 
+    clock<T>::operator=(const clock& that){
+        if(&that!=this){
+            start_time_ = (that.start_time_);
+            delta_time_ = (that.delta_time_);
+        }
+        return *this;
+    }
+
+    template<typename T>
+    typename clock<T>::result_type 
+    clock<T>::operator()(){
+        result_type res = start_time_;
+        start_time_ += delta_time_;
+        return res;
+    }
+
+}// functional
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/functional/boost/functional/find.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/find.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,37 @@
+///////////////////////////////////////////////////////////////////////////////
+// functional::find.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_FUNCTIONAL_FIND_HPP_ER_2009
+#define BOOST_FUNCTIONAL_FIND_HPP_ER_2009
+#include <algorithm>
+
+namespace boost{
+namespace functional{
+
+// std::find made into a functor
+//
+// TODO specialize result_of<In(find)(In,In,const T&)>
+struct find{
+    find(){}
+    
+    template<typename In,typename T>
+    In operator()(In b,In e,const T& t)const;
+};
+
+    
+template<typename In,typename T>
+In find::operator()(In b,In e,const T& t)const{
+    return std::find(
+        b,
+        e,
+        t
+    );
+}
+    
+}//functional
+}//boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/functional/boost/functional/fixed_value.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/fixed_value.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,83 @@
+///////////////////////////////////////////////////////////////////////////////
+// functional::fixed_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_FUNCTIONAL_FIXED_VALUE_HPP_ER_2009
+#define BOOST_FUNCTIONAL_FIXED_VALUE_HPP_ER_2009
+#include <boost/call_traits.hpp>
+#include <boost/type_traits/remove_cv.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+
+namespace boost{
+namespace random{
+
+    // Returns a fixed value 
+    template<typename T>
+    struct fixed_value{
+    public:
+        typedef typename remove_cv<
+            typename remove_reference<
+                T
+            >::type
+        >::type value_type;
+    
+        fixed_value();
+        fixed_value(typename call_traits<T>::param_type value);
+        fixed_value(const fixed_value&);
+        fixed_value& operator=(const fixed_value&);
+        
+        
+        typedef I                                           input_type;
+        typedef typename call_traits<T>::const_reference    result_type;
+                
+        result_type operator()()const;
+        result_type value()const;
+        
+        // TODO os/is
+        
+    private:
+        typename call_traits<T>::value_type value_;
+    };
+
+    // Implementation //
+                    
+    template<typename T>
+    fixed_value<T>::fixed_value()
+    :value_(static_cast<value_type>(0)){}
+            
+    template<typename T>
+    fixed_value<T>::fixed_value(typename call_traits<T>::param_type value)
+    :value_(value){}
+            
+    template<typename T>
+    fixed_value<T>::fixed_value(const fixed_value& that)
+    :value_(that.value_){}
+            
+    template<typename T>
+    fixed_value<T>& 
+    fixed_value<T>::operator=(const fixed_value& that){
+        if(&that!=this){
+            value_ = (that.value_);
+        }
+        return *this;
+    }
+            
+    template<typename T>
+    typename fixed_value<T>::result_type 
+    fixed_value<T>::operator()()const{
+        return (this->value());
+    }
+                
+    template<typename T>
+    typename fixed_value<T>::result_type 
+    fixed_value<T>::value()const{
+        return (this->value_);
+    }
+
+}// functional
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/functional/boost/functional/mean_var_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/mean_var_accumulator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+///////////////////////////////////////////////////////////////////////////////
+// functional::mean_var_accumulator.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_FUNCTIONAL_MEAN_VAR_ACCUMULATOR_HPP_ER_2009
+#define BOOST_FUNCTIONAL_MEAN_VAR_ACCUMULATOR_HPP_ER_2009
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+
+namespace boost{
+namespace functional{
+
+    // This comes up often, so this metafunction saves a bit of time
+    template<typename T>
+    struct mean_var_accumulator{
+        typedef accumulators::stats<
+            accumulators::tag::mean,
+            accumulators::tag::variance
+        >  stat_;
+        typedef accumulators::accumulator_set<T,stat_> type;
+    };
+
+}// meta    
+}// boost
+
+#endif
Added: sandbox/statistics/functional/boost/functional/visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/visitor.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,95 @@
+///////////////////////////////////////////////////////////////////////////////
+// boost::functional::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)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_FUNCTIONAL_VISITOR_HPP_ER_2009
+#define BOOST_FUNCTIONAL_VISITOR_HPP_ER_2009
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/utility.hpp>
+
+namespace boost{
+namespace functional{
+
+    // Models Generator
+    //
+    // Successively returns elements of a range
+    template<typename R>
+    class visitor{
+        typedef typename range_iterator<R>::type it_t;
+        typedef std::size_t size_type;
+
+        public:
+        visitor();
+        visitor(const R& r);
+        visitor(const visitor&);
+        visitor& operator=(const visitor&);
+
+        typedef typename range_value<R>::type result_type;
+
+        result_type operator()();
+
+        void reset(size_type n);
+        
+        private:
+        R r_;
+        it_t it_;
+    };
+
+    // Implementation //
+
+    template<typename R>
+    visitor<R>::visitor(){}
+
+    template<typename R>
+    void visitor<R>::reset(size_type n){
+        this->it_ = boost::next(
+            boost::begin(this->r_),
+            n
+        );
+    }
+    
+    template<typename R>
+    visitor<R>::visitor(const R& r)
+    :r_(r){ this-> reset(0); }
+
+    template<typename R>
+    visitor<R>::visitor(const visitor& that)
+    :r_(that.r_){
+        this->reset(
+            std::distance(
+                boost::begin(that.r_),
+                that.it_
+            )
+        );
+    }
+    
+    template<typename R>
+    visitor<R>& 
+    visitor<R>::operator=(const visitor& that){
+        if(&that!=this){
+            this->r_ = that.r_;
+            this->reset(
+                std::distance(
+                    boost::begin(that.r_),
+                    that.it_
+                )
+            );
+        }
+        return *this;
+    }
+
+    template<typename R>
+    typename visitor<R>::result_type 
+    visitor<R>::operator()(){
+        typedef typename visitor<R>::result_type x_;
+        return *(this->it_++);
+    }
+
+}// functional
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/functional/boost/functional/zscore.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/boost/functional/zscore.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////
+// functional::zscore.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_FUNCTIONAL_ZSCORE_HPP_ER_2009           
+#define BOOST_FUNCTIONAL_ZSCORE_HPP_ER_2009 
+#include <cmath>
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+#include <boost/accumulators/statistics/variance.hpp>
+
+namespace boost{
+namespace functional{
+
+template<typename T>
+struct zscore{
+    typedef T result_type;
+    zscore(){}
+    template<typename T1>
+    result_type operator()(const A& a, const T1& x)const{
+        T m = static_cast<T>(boost::accumulators::mean(a));
+        T s = static_cast<T>(boost::accumulators::variance(a));
+        s = std::sqrt(s);
+        return (x - m)/s;
+    }
+};
+
+
+}// functional
+}// boost
+
+#endif
Added: sandbox/statistics/functional/libs/functional/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/functional/libs/functional/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+// functional::doc::readme                                                  //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ functors whose need has proped up in other subdivision of the 
+sandbox/statistics package.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+
+[ History ]
+
+July 2009 : Current version
+
Added: sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,76 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::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_IMPORTANCE_SAMPLING_GENERATE_HPP_ER_2009
+#define BOOST_IMPORTANCE_SAMPLING_GENERATE_HPP_ER_2009
+#include <iterator>
+#include <functional>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/utility.hpp>
+#include <boost/non_param/algorithm/proportion_less_than.hpp>
+#include <boost/importance_sampling/sampler.hpp>
+#include <boost/random/ref_distribution.hpp>
+
+namespace boost{
+namespace is{
+
+    template<typename U,typename ItW,typename ItP,typename ItT>
+    ItT generate(
+        U& urng,
+        ItW b_w,        // unnormalized weights
+        ItW e_w,        // unnormalized weights
+        ItP b_p,        // proposal values
+        ItT b_t,        // target values (output)
+        std::size_t n   // sample size
+    );
+
+    // Implementation
+
+    template<typename U,typename ItW,typename ItP,typename ItT>
+    ItT generate(
+        U& urng,
+        ItW b_w, 
+        ItW e_w, 
+        ItP b_p, 
+        ItT b_t, 
+        std::size_t n 
+    ){
+        typedef boost::iterator_range<ItW>                  range_w_;
+        typedef boost::iterator_range<ItP>                  range_p_;
+        typedef boost::is::sampler<range_p_>                iss_;
+        typedef boost::random::ref_distribution<iss_&>      ref_iss_;
+        typedef boost::variate_generator<U&,ref_iss_>       gen_iss_;
+        
+        range_w_    range_w(b_w,e_w);
+        range_p_    range_p(
+            b_p,
+            boost::next(
+                b_p,
+                std::distance(
+                    b_w,
+                    e_w
+                )
+            )
+        );
+
+        iss_        iss( range_w, range_p );
+        ref_iss_    ref_iss( iss );
+        gen_iss_    gen_iss( urng, iss );
+        
+        return std::generate_n(
+            b_t,
+            n,
+            gen_iss
+        );
+    }
+    
+}// is
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/boost/importance_sampling/grid.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/grid.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,51 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::grid.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_IMPORTANCE_SAMPLING_GRID_HPP_ER_2009
+#define BOOST_IMPORTANCE_SAMPLING_GRID_HPP_ER_2009
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/limits.hpp>
+
+namespace boost{
+namespace is{
+
+// Equally spaced univariate grid.
+template<typename T>
+class grid{
+    public:
+    typedef std::size_t size_type;
+    private:
+    typedef boost::numeric::converter<T,size_type> conv_t;
+    public:
+    typedef T result_type;
+    grid(T min, T max, size_type n);
+    T operator()();
+        
+    private:
+    size_type   n_;
+    size_type   i_;
+    T           d_;
+    T           x_;
+};
+
+template<typename T>
+grid<T>::grid(T min, T max, size_type n) 
+: n_(n), i_(0), d_((max-min)/conv_t::convert(n-1)),x_(min) {}
+        
+template<typename T>
+T grid<T>::operator()(){
+    BOOST_ASSERT(i_<n_);
+    T result = x_;
+    x_ += d_;
+    ++i_;
+    return result;
+}
+
+}// is            
+}// boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/boost/importance_sampling/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::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_IMPORTANCE_SAMPLING_INCLUDE_HPP_ER_2009
+#define BOOST_IMPORTANCE_SAMPLING_INCLUDE_HPP_ER_2009
+
+#include <boost/importance_sampling/generate.hpp>
+#include <boost/importance_sampling/grid.hpp>
+#include <boost/importance_sampling/sampler.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,125 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::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_IMPORTANCE_SAMPLING_SAMPLER_HPP_ER_2009
+#define BOOST_IMPORTANCE_SAMPLING_SAMPLER_HPP_ER_2009
+#include <vector>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/utility.hpp>
+#include <boost/range.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/random/multinomial_distribution.hpp>
+
+namespace boost{
+namespace is{
+
+// Samples by SIR given a set of proposal values and their unnormalized weights
+//
+// R1:  models Range or a reference thereof
+// U:   models RandomDistribution (uniform)
+//
+// Usage:
+// typedef S<R1,U> s_;
+// typedef s_::result_type res_;
+// s_ s(weights,proposal_draws);
+// res_ res = s(urng);
+//
+// NB: pre-sorting the weights from largest to smallest may speed up execution.
+template<typename R1, template<typename> class Ur = boost::uniform_real>
+class sampler{
+    typedef typename remove_reference<R1>::type const_values_;
+    typedef is_reference<R1>  is_ref_;
+    public:
+    typedef typename range_value<const_values_>::type result_type;
+    private:
+    typedef Ur<result_type>                             unif_;
+    typedef random::multinomial_distribution<unif_>     mult_dist_t;
+    public:
+    typedef typename mult_dist_t::input_type            input_type;
+
+    sampler();
+    template<typename R0>
+    sampler(
+        const R0& unnormalized_weights,
+        typename call_traits<R1>::param_type values
+    );
+    sampler(const sampler& that);
+    sampler& operator=(const sampler& that);
+
+    template<typename U> result_type operator()(U& urng)const;
+    const mult_dist_t& multinomial_distribution()const;
+
+    // TODO os/is
+
+    private:
+    mult_dist_t mult_dist_;
+    typename call_traits<R1>::value_type values_;
+};
+
+// Definition //
+
+template<typename R1, template<typename> class Ur>
+sampler<R1,Ur>::sampler(){
+    BOOST_MPL_ASSERT((
+        mpl::not_<is_ref_>
+    ));
+}
+
+template<typename R1, template<typename> class Ur>
+template<typename R0>
+sampler<R1,Ur>::sampler(
+    const R0& unnormalized_weights,
+    typename call_traits<R1>::param_type values
+):mult_dist_(unnormalized_weights),values_(values){
+    BOOST_ASSERT(
+        size(unnormalized_weights) == size(values_)
+    );
+}
+    
+template<typename R1, template<typename> class Ur>
+sampler<R1,Ur>::sampler(
+    const sampler& that
+)
+:mult_dist_(that.mult_dist_),values_(that.values_){}
+
+template<typename R1, template<typename> class Ur>
+sampler<R1,Ur>&
+sampler<R1,Ur>::operator=(const sampler& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((
+            mpl::not_<is_ref_>
+        ));
+        mult_dist_ = that.mult_dist_;
+        values_ = that.values_;
+    }
+    return (*this);
+}
+
+// Random        
+template<typename R1, template<typename> class Ur>
+template<typename U>
+typename sampler<R1,Ur>::result_type
+sampler<R1,Ur>::operator()(U& urng)const{
+    typedef typename mult_dist_t::result_type k_t;
+    k_t k = mult_dist_(urng);
+    BOOST_ASSERT( k < size(values_) );
+    return (*next(boost::begin(values_),k));
+}
+
+// Access
+template<typename R1, template<typename> class Ur>
+const typename sampler<R1,Ur>::mult_dist_t&
+sampler<R1,Ur>::multinomial_distribution()const{ return mult_dist_; }
+
+}//random
+}//boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,82 @@
+//////////////////////////////////////////////////////////////////////////////
+// importance_sampling::doc::readme                                         //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ tools for sampling by importance weights. For example:
+    generate(urng,b_w, e_w, b_p, b_t, n);
+
+See the related package sandbox/statistics/importance_weights
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+/sandbox/statistics/utility/ 
+/sandbox/statistics/standard_distribution/ 
+/sandbox/statistics/stl/
+
+Link to libboost_serialization-gcc40-mt-1_37.a
+
+[ Models RandomDistribution ]
+    Let R denote a range of values (not restricted to scalars) representing
+    the proposal sample.
+
+    Class
+    is::sampler<R>                      SIR sampler    
+
+[ Sources ]
+
+[1] http://en.wikipedia.org/wiki/Multinomial_distribution
+
+[2] http://en.wikipedia.org/wiki/Particle_filter
+
+[3] A note on Importance Sampling using standardized weights, Augustine Kong,
+Technical report 348, Department of statistics, UChicago, 1992.
+
+[4] Bayesian analysis of massive datasets via particle filters,
+Ridgeway and Madigan
+
+[5] Andrew Gelman et al., Bayesian Data Analysis, CRC Press
+
+[ History ]
+
+July 2009 : Current version
+
+[Output]
+
+Here's the ouput from main.cpp:
+
+->example_sampler : 
+
+->example_sampler : 
+
+Initial sample : 
+(offset,scaling_factor,pc_ess,pc_lt_eps)
+(-1,1,0.438938,0)
+kolmorov smirnov distance series :0.212692,0.162692,0.135872,0.110872,0.0926924,
+0.079359,0.0436733,0.0530073,0.043285,0.0455073,0.0580085,0.0564934,0.0552113,
+0.0469696,0.0464934,0.0520131,0.0516455,0.0568742,0.0595787,0.0448241,0.0462527,
+0.0475514,0.0487372,0.0456575,0.0414679,0.0402088,0.0416852,0.0436694,0.0403644,
+0.0401345,0.0393403,0.0373241,0.0517948,0.0560643,0.0486694,0.0416852,0.0377813,
+0.0419776,0.0485228,0.0497408,0.0519114,0.0546989,0.0503799,0.0511118,0.0526995,
+0.0437623,0.0463637,0.0450339,0.0432469,0.0407926,0.0433182,0.0421493,0.0435474,
+0.0394593,0.0373381,0.0365077,0.0342207,0.037185,0.0349641,0.0328172,0.0326287,
+0.0324701,0.0307292,0.0290426,0.0289465,0.0318836,0.0332404,0.0330868,0.0343868,
+0.0370784,0.0354687,0.0380704,0.039231,0.0376575,0.036126,0.0359505,0.0409745,
+0.0420234,0.04178,0.0415426,0.0413112,0.0398658,0.0384553,0.0370784,0.0357338,
+0.0355833,0.0365857,0.0352926,0.0362758,0.0376072,0.0350797,0.0347811,0.0335453,
+0.0320753,0.0318177,0.0321924,0.0315911,0.0300562,0.0338698,0.0366072,<-
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,3 @@
+
+
+// TODO
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/example/multi_sampler.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,3 @@
+
+
+// TODO
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::example::sampler.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 <cmath>
+#include <algorithm>
+#include <iterator>
+#include <boost/bind.hpp>
+#include <boost/random.hpp>
+#include <boost/format.hpp>
+#include <boost/function.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/random/normal_distribution.hpp>
+// Must come before non_param/algorithm/sequential_kolmogorov_smirnov_distance:
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+#include <boost/scalar_dist/include.hpp>
+#include <boost/importance_weights/algorithm/prepare_weights.hpp>
+#include <boost/importance_sampling/include.hpp>
+
+void example_sampler(std::ostream& out){
+    out << "->example_sampler : \n";
+
+    // We sample from N(x|mu,sigma^2)N(x|mu,sigma^2) = N(x|mu,sigma^2/2), 
+    // using SIR with N(x|mu+sigma,sigma^2) as proposal density. 
+    // The quality of the sample is assessed by a series of 
+    // kolmorov-distances along the the sample size of the targets.    
+    using namespace boost;
+    typedef std::string                                 str_t;
+    typedef double                                      val_;
+    typedef std::vector<val_>                           vec_;
+    typedef range_iterator<vec_>::type                  it_val_;
+    typedef std::vector<vec_>                           mat_;
+    typedef math::normal_distribution<val_>             mnd_;
+    typedef math::meta_ratio_pdf<mnd_,mnd_>             meta_ratio_;
+    typedef normal_distribution<val_>                   rd_;
+    typedef mt19937                                     urng_;
+    typedef variate_generator<urng_&, rd_>              gen_t;
+    typedef function<val_(mnd_,val_)>                   pdf_fun_; 
+    typedef importance_weights::prepare_weights<val_>   prepare_weights_;
+
+    // Constants
+    const unsigned n_p          = 5e3;  // Proposal sample size
+    const unsigned n_t_pl       = 1e1;  // Target sample size per loop
+    const unsigned n_ks         = 1e2;
+    const val_ max_log          = 0.0;  
+    const val_ mu               = 0.0;
+    const val_ sigma            = 1.0;
+    const val_ target_mu        = mu + sigma;
+    const val_ target_sigma     = sigma/sqrt(2.0);
+
+    // Initialization
+    prepare_weights_ prepare_weights( max_log );
+    mnd_ md_proposal( mu, sigma );               
+    mnd_ md_target( target_mu, target_sigma );   
+    rd_ rd( mu, sigma );
+
+    urng_ urng;
+    vec_ vec_ks; vec_ks.reserve(n_ks * n_t_pl);
+    vec_ proposals;
+    proposals.reserve(n_p);
+    vec_ targets; 
+    targets.reserve( n_ks * n_t_pl );
+    vec_ is_weights;
+    is_weights.reserve(n_p);
+    gen_t gen(urng,rd);
+    std::generate_n( std::back_inserter(proposals), n_p, gen );
+
+    is_weights.clear();
+    math::transform<math::fun_wrap::log_unnormalized_pdf_>(
+        meta_ratio_::make(md_target,md_proposal),
+        boost::begin(proposals),
+        boost::end(proposals),
+        std::back_inserter(is_weights)
+    );
+
+    prepare_weights(
+        boost::begin(is_weights),
+        boost::end(is_weights),
+        boost::begin(proposals)
+    );
+
+    out << std::endl << "Initial sample : " << std::endl
+        << prepare_weights_::header << std::endl
+        << prepare_weights << std::endl;
+
+    targets.clear();
+    is::generate(
+        urng,
+        boost::begin(is_weights),
+        boost::end(is_weights),
+        boost::begin(proposals),
+        std::back_inserter(targets),
+        n_t_pl * n_ks
+    );
+    {
+        // i       0       1        ...    n-1           
+        // [b,e)  [0,m)    [m,2m)   ...    [(n-1)m,n m)
+        boost::non_param::sequential_kolmogorov_smirnov_distance(
+            md_target,
+            boost::begin(targets),
+            boost::end(targets),
+            n_ks,
+            std::back_inserter(vec_ks)  
+        );
+        
+    }
+
+    out << "kolmorov smirnov distance series :";
+    std::copy(
+        boost::begin(vec_ks),
+        boost::end(vec_ks),
+        std::ostream_iterator<val_>(out, ",")
+    );
+    
+    std::cout << "<-" << std::endl;
+
+}
+
+
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::example::sampler.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_IMPORTANCE_SAMPLING_EXAMPLE_SAMPLER_H_ER_2009
+#define LIBS_IMPORTANCE_SAMPLING_EXAMPLE_SAMPLER_H_ER_2009
+#include <ostream>
+
+void example_sampler(std::ostream&);
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/importance_sampling/libs/importance_sampling/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,18 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::src::main.cpp                                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <boost/assert.hpp>
+#include <libs/importance_sampling/example/sampler.h>
+
+int main(){
+    
+    example_sampler(std::cout);
+    
+    return 0;
+}
+
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/apply_exp_offset.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/apply_exp_offset.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,60 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::algorithm::apply_exp_offset                           //
+//                                                                           //
+//  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_IMPORTANCE_WEIGHTS_ALGORITHM_APPLY_EXP_OFFSET_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_APPLY_EXP_OFFSET_HPP_ER_2009
+#include <cmath>
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/math/tools/precision.hpp>
+
+namespace boost{
+namespace importance_weights{
+    
+    // Returns          The smallest value, c, s/t *i + c <= t, i in [b_w,e_w)
+    // Side effect:     *i <- exp(*i+c)
+    //
+    // The greater c, the higher the precision but also risk of isinf.
+    // Textbook often show t = 0 so that exp(w+c) <= 1. 
+    template<typename It>
+    typename iterator_value<It>::type
+    apply_exp_offset(
+        It b,
+        It e,
+        typename iterator_value<It>::type t
+    ){
+        typedef typename iterator_value<It>::type val_;
+        val_ max = *std::max_element(b,e);
+        val_ offset = (t - max); 
+        std::transform(b,e,b,
+            lambda::bind<val_>(exp,lambda::_1 + offset)
+        );
+        return offset;
+    }
+
+    // Same as above, but t set such that exp(t+epsilon) = inf, exp(t)<inf 
+    template<typename It>
+    typename iterator_value<It>::type
+    apply_exp_offset(
+        It b,
+        It e
+    ){
+        typedef typename iterator_value<It>::type val_;
+        const val_ log_max = boost::math::tools::log_max_value<val_>();
+
+        return apply_exp_offset(
+            b,
+            e,
+            log_max
+        );
+    }
+
+}// importance_weights
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/effective_sample_size.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/effective_sample_size.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,68 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::effective_sample_size.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_IMPORTANCE_WEIGHTS_ALGORITHM_EFFECTIVE_SAMPLE_SIZE_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_EFFECTIVE_SAMPLE_SIZE_HPP_ER_2009
+#include <algorithm>
+#include <numeric>
+#include <iterator>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/ref.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/functional/mean_var_accumulator.hpp>
+
+namespace boost{
+namespace importance_weights{
+    
+    // Finds the number of iid observations whose standard error equates that
+    // of the importance sample mean. The number is reported in proportion to
+    // the input sample size (m). See sources [3] or [4].
+    //
+    // n = m / (1+Var(w)) where the w's are standardized weights 
+    // i.e. w[j]<- uw[j]/mean(uw[j]:j=1,...,m), solves A = B, where
+    //  A = V((1/n) sum{y[i],i=1,...,n}), y~p(y) (iid) 
+    //  B = V(sum{y[j]uw[j],i=1,...,m}/sum{uw[j]:j=1,...,m}), y~q, uw propto p/q
+    template<typename InIt>
+    typename iterator_value<InIt>::type
+    percentage_effective_sample_size(
+        InIt b_w, // un-normalized weights 
+        InIt e_w
+    );
+
+    // Implementation //
+    
+    template<typename InIt>
+    typename iterator_value<InIt>::type
+    percentage_effective_sample_size(
+        InIt b_w, // un-normalized weights 
+        InIt e_w
+    ){
+        typedef typename iterator_value<InIt>::type val_;
+        typedef typename functional::mean_var_accumulator<val_>::type acc_;
+
+        // Var(w/c) = Var(w) / c^2
+
+        static val_ one = static_cast<val_>(1);
+
+        acc_ acc;
+        std::for_each(b_w,e_w, lambda::bind<void>(boost::ref(acc),lambda::_1));
+        val_ v = static_cast<val_>(
+            boost::accumulators::variance(acc)
+        );
+        val_ c = static_cast<val_>(
+            boost::accumulators::mean(acc)
+        );
+        v /= (c*c);
+
+        return one / (one + v);
+    }
+
+}// importance_weights            
+}// boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/find_scale_to_finite_sum.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/find_scale_to_finite_sum.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,139 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::algorithm::find_scale_to_finite_sum.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_IMPORTANCE_WEIGHTS_ALGORITHM_FIND_SCALE_TO_FINITE_SUM_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_FIND_SCALE_TO_FINITE_SUM_HPP_ER_2009
+#include <cmath>
+#include <numeric>
+#include <stdexcept>
+#include <boost/lambda/lambda.hpp>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/numeric/conversion/bounds.hpp>
+#include <boost/importance_weights/algorithm/maximal_finite_sums.hpp>
+
+namespace boost{
+namespace importance_weights{
+
+    // Finds c such that the sum over sum{*i/c, i in [b,e)} < inf using the
+    // bisection method.
+    //
+    // Warning: The value c is not insensitive to permutations of [b,e), due
+    // to non-associativity in the fp system
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    find_scale_to_finite_sum(
+        InIt b,InIt e,
+        typename iterator_value<InIt>::type low_init,
+        typename iterator_value<InIt>::type high_init
+    );
+    
+    // This version may be faster than that above with low = 1, high = highest
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    find_scale_to_finite_sum(InIt b,InIt e);
+
+    // Implementation //
+
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    find_scale_to_finite_sum(
+        InIt b,InIt e,
+        typename iterator_value<InIt>::type low_init,
+        typename iterator_value<InIt>::type high_init
+    ){
+        typedef typename iterator_value<InIt>::type val_;
+        static val_ zero = static_cast<val_>(0);
+        static val_ two = static_cast<val_>(2);
+        static val_ eps = math::tools::epsilon<val_>();
+
+        BOOST_ASSERT(low_init < high_init);
+        BOOST_ASSERT(low_init > zero);
+        BOOST_ASSERT(high_init > zero);
+        val_ low = low_init;
+        val_ high = high_init;
+        val_ mid = (low + high)/two;
+        val_ delta, acc;
+        
+        do{
+            delta = high - low;
+            acc =
+                std::accumulate(b,e,zero, lambda::_1 + ( lambda::_2 / mid) );
+            if(boost::math::isinf(acc)){
+                low = mid;
+            }else{
+                high = mid;
+            }
+            mid = (low+high)/two;
+        }while(
+            delta - (high - low)>eps
+        );
+        static  
+            const char* str = "%3% = find_scale_to_finite_sum(b,e,%1%,%2%) = inf";
+        if(
+            boost::math::isinf(
+                std::accumulate(b,e,zero, lambda::_1 + ( lambda::_2 / high) )
+            )
+        ){
+            format f(str); f%low_init%high_init%high;
+            throw std::runtime_error(f.str());
+        }
+        return high;
+    }
+
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    find_scale_to_finite_sum(InIt b,InIt e){
+        typedef typename iterator_value<InIt>::type val_;
+        typedef numeric::bounds<val_>               bounds_;
+        typedef std::vector<val_>                   vec_;
+        static val_ zero = static_cast<val_>(0);
+        static val_ one = static_cast<val_>(1);
+        static val_ two = static_cast<val_>(2);
+        static val_ highest = bounds_::highest();
+        vec_ vec;
+        maximal_finite_sums(b,e,std::back_inserter(vec));
+        val_ low = one;
+        val_ high = highest;
+        val_ mid = find_scale_to_finite_sum(
+            boost::begin(vec),
+            boost::end(vec),
+            low,high
+        );
+        low = mid;
+        high = mid;
+        while( 
+            !boost::math::isinf(
+                std::accumulate(b,e,zero, lambda::_1 + ( lambda::_2 / low) )
+            )
+        ){
+            low /= two;
+            if(low<one){
+                low = one;
+                break;
+            }
+        }
+        while( 
+            boost::math::isinf(
+                std::accumulate(b,e,zero, lambda::_1 + ( lambda::_2 / high) )
+            )
+        ){
+            high *= two;
+            if(boost::math::isinf(high)){
+                high = highest;
+                break;
+            }
+        }
+        return find_scale_to_finite_sum(b,e,low,high);
+    }
+
+}// importance_weights
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/maximal_finite_sums.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/maximal_finite_sums.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,40 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::algorithm::maximal_finite_sums.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_IMPORTANCE_WEIGHTS_ALGORITHM_MAXIMAL_FINITE_SUMS_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_MAXIMAL_FINITE_SUMS_HPP_ER_2009
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+
+namespace boost{
+namespace importance_weights{
+
+    // Breaks down the summation of *i, i in [b,e) into maximal finite amounts,
+    // each of which are copied to the output iterator i
+    template<typename InIt,typename OutIt>
+    OutIt maximal_finite_sums(InIt b, InIt e, OutIt i)
+    {
+        typedef typename iterator_value<InIt>::type value_type;
+        value_type sum = static_cast<value_type>(0);
+        while(b!=e){
+            value_type d = *b;
+            if( boost::math::isinf( sum + d ) ){
+                *i = sum;
+                sum = d;
+                ++i;
+            }else{
+                sum += d;
+            }
+            ++b;
+        }
+        return i;
+    };
+    
+}// importance_weights
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/prepare_weights.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/prepare_weights.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,162 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::algorithm::prepare_weights.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_IMPORTANCE_WEIGHTS_ALGORITHM_PREPARE_WEIGHTS_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_PREPARE_WEIGHTS_HPP_ER_2009
+#include <iterator>
+#include <functional>
+#include <boost/lambda/lambda.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/binary_op/algorithm/sort_on_head.hpp>
+#include <boost/non_param/algorithm/proportion_less_than.hpp>
+#include <boost/importance_weights/algorithm/apply_exp_offset.hpp>
+#include <boost/importance_weights/algorithm/scale_to_finite_sum.hpp>
+#include <boost/importance_weights/algorithm/effective_sample_size.hpp>
+
+namespace boost{
+namespace importance_weights{
+
+    // Warning: read side effects carefully.
+    template<typename T>
+    class prepare_weights{
+        public:
+        typedef T value_type;
+        typedef std::size_t size_type;
+
+        prepare_weights();
+        prepare_weights(value_type max_log);
+        // Default copy/assign
+
+        // [ Input ]
+        // max_log controls precision hence raising it should decr pc_lt_eps
+        // but also incr risk that cum_sum isinf. 
+        value_type max_log;  
+ 
+        // [ Output ]
+        value_type offset;        // lw <- lw + offset, max{lw}+offset = max_log
+        value_type scaling_factor;// w <- w/c such that sum{w/c}<inf
+        value_type pc_ess;        // pc effective sample size
+        value_type pc_lt_eps;     // pc w<eps
+        
+        // [ Side effect ] 
+        // 1) w <- exp(lw+offset)
+        // 2) if needed, w <- w/c such that sum{w} < inf
+        // 3) Sorts [b_w,e_w) in decr order, and [b_p,e_p) accordingly
+        template<typename ItW,typename ItP>
+        void operator()(
+            ItW b_w,    // log( unnormalized weights )
+            ItW e_w,
+            ItP b_p     // proposal values
+        );
+
+        public:
+        static value_type zero;
+        static value_type eps;
+        static value_type default_max_log;
+        static const char* header;
+
+    };
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out, 
+        const prepare_weights<T>& that);
+
+    // Implementation
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out, 
+        const prepare_weights<T>& that){
+        out 
+            << '(' << that.offset
+            << ',' << that.scaling_factor
+            << ',' << that.pc_ess
+            << ',' << that.pc_lt_eps
+            << ')';
+        return out;
+    }
+
+    template<typename T>
+    const char* prepare_weights<T>::header 
+        = "(offset,scaling_factor,pc_ess,pc_lt_eps)";
+
+    template<typename T>
+    typename prepare_weights<T>::value_type
+    prepare_weights<T>::eps = math::tools::epsilon<value_type>();
+
+    template<typename T>
+    typename prepare_weights<T>::value_type
+    prepare_weights<T>::default_max_log = static_cast<value_type>(0);
+
+    template<typename T>
+    typename prepare_weights<T>::value_type
+    prepare_weights<T>::zero = static_cast<value_type>(0);
+
+    template<typename T>
+    prepare_weights<T>::prepare_weights()
+    :max_log(default_max_log),
+    offset(zero),scaling_factor(zero),pc_ess(zero),pc_lt_eps(zero){}
+
+    template<typename T>
+    prepare_weights<T>::prepare_weights(value_type ml)
+    :max_log(ml),
+    offset(zero),scaling_factor(zero),pc_ess(zero),pc_lt_eps(zero){}
+    
+    template<typename T>
+    template<typename ItW,typename ItP>
+    void
+    prepare_weights<T>::operator()(
+        ItW b_w,
+        ItW e_w,
+        ItP b_p
+    ){
+        offset = apply_exp_offset(
+            b_w,
+            e_w,
+            max_log
+        );
+
+        // crucial that this step precedes scale_to_finite_sum because
+        // finiteness is not nec preserved by reordering (non associativity)
+        binary_op::sort_on_head_greater(
+            b_w,
+            e_w,
+            b_p
+        );  
+
+        // if max_log is small enough (which costs precision), this does not 
+        // nothing i.e. scaling_factor = 1
+        scaling_factor = scale_to_finite_sum(
+            b_w,
+            e_w
+        ); 
+
+        ItW i_lt_eps = std::lower_bound(
+            b_w,
+            e_w,
+            eps,
+            ( boost::lambda::_1 >= boost::lambda::_2 )
+        );
+        
+        value_type n_gt_eps 
+            = static_cast<value_type>( std::distance(b_w,i_lt_eps) );
+        value_type n_lt_eps 
+            = static_cast<value_type>( std::distance(i_lt_eps,e_w) );
+        
+        // Increasing max_log should decrease this number
+        pc_lt_eps = n_lt_eps / ( n_lt_eps + n_gt_eps ) ;
+
+        // Beware that pc_lt_eps >0  may distort ess
+        pc_ess = percentage_effective_sample_size(
+            b_w,
+            e_w
+        );
+    }
+
+}// importance_weights
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_weights/boost/importance_weights/algorithm/scale_to_finite_sum.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/boost/importance_weights/algorithm/scale_to_finite_sum.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,72 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::algorithm::scale_to_finite_sum.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_IMPORTANCE_WEIGHTS_ALGORITHM_SCALE_TO_FINITE_SUM_HPP_ER_2009
+#define BOOST_IMPORTANCE_WEIGHTS_ALGORITHM_SCALE_TO_FINITE_SUM_HPP_ER_2009
+#include <numeric>
+#include <boost/lambda/lambda.hpp>
+#include <boost/range.hpp>
+#include <boost/importance_weights/algorithm/find_scale_to_finite_sum.hpp>
+
+namespace boost{
+namespace importance_weights{
+
+    // Scales each element [b,e) by the smallest factor, c, such that the sum 
+    // is finite.
+    //
+    // [ Warning ] c is not insensitive to permutations of [b,e), due
+    // to non-associativity in the fp system
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    scale_to_finite_sum(InIt b,InIt e,
+        typename iterator_value<InIt>::type low,
+        typename iterator_value<InIt>::type high
+    );
+
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    scale_to_finite_sum(InIt b,InIt e);
+
+    // Implementation //
+
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    scale_to_finite_sum(InIt b,InIt e,
+        typename iterator_value<InIt>::type low,
+        typename iterator_value<InIt>::type high
+    ){
+        typedef typename iterator_value<InIt>::type val_;
+        val_ c = find_scale_finite_sum(
+            b,e,low,high
+        );
+        std::transform(
+            b,
+            e,
+            b,
+            boost::lambda::_1 / c
+        );
+        return c;
+    }
+
+    template<typename InIt>
+    typename iterator_value<InIt>::type 
+    scale_to_finite_sum(InIt b,InIt e){
+        typedef typename iterator_value<InIt>::type val_;
+        val_ c = find_scale_to_finite_sum(b,e);
+        std::transform(
+            b,
+            e,
+            b,
+            boost::lambda::_1 / c
+        );
+        return c;
+    }
+
+}// importance_weights
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/importance_weights/libs/importance_weights/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/libs/importance_weights/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,55 @@
+//////////////////////////////////////////////////////////////////////////////
+// importance_weights::doc::readme                                          //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+This C++ package contains tools that are commonly needed in manipulating 
+importance weights. 
+
+[ algorithm ]
+
+The file prepare_weights.hpp probably meets the most common needs and has 
+detailed instructions.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+/sandbox/statistics/non_param/ 
+/sandbox/statistics/binary_op/ 
+/sandbox/statistics/functional/
+
+[ Sources ]
+
+[1] http://en.wikipedia.org/wiki/Multinomial_distribution
+[2] http://en.wikipedia.org/wiki/Particle_filter
+[3] A note on Importance Sampling using standardized weights, Augustine Kong,
+Technical report 348, Department of statistics, UChicago, 1992.
+[4] Bayesian analysis of massive datasets via particle filters, Ridgeway and 
+Madigan
+
+[ History ]
+
+July 2009 : Current version
+
+[ Output ]
+
+main.cpp:
+
+-> example_algorithm_scale_sum_to_finite : val = 1.79769e+308
+c = 13
+cum_sum = 1.79769e+308
+<-
Added: sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,63 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::example::scale_to_finite_sum.cpp                      //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#include <vector>
+#include <ostream>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/numeric/conversion/bounds.hpp>
+#include <boost/importance_weights/algorithm/scale_to_finite_sum.hpp>
+#include <libs/importance_weights/example/scale_to_finite_sum.h>
+    
+void example_scale_to_finite_sum(std::ostream& out){
+    out << "-> example_algorithm_scale_sum_to_finite : ";
+    using namespace boost;
+        
+    // Types
+    typedef double val_;
+    typedef std::vector<val_> vec_;
+    typedef numeric::bounds<val_> bounds_;
+        
+    // Constants
+    const range_size<vec_>::type n = 10;
+    
+    // Initialization
+    val_ val =  bounds_::highest();
+    out << "val = " << val << std::endl;
+    BOOST_ASSERT( !math::isinf( val ) );
+    BOOST_ASSERT( math::isinf( val + val ) );
+        
+    vec_ vec_in(n,val);
+    {
+        using namespace assign;
+        vec_in += val, val, val;
+    }
+
+    // Computations
+    val_ c = importance_weights::scale_to_finite_sum(
+        boost::begin(vec_in),
+        boost::end(vec_in)
+    );
+    BOOST_ASSERT( !math::isinf( c ) );
+
+    out << "c = " << c << std::endl;
+
+    val_ cum_sum = std::accumulate(
+        boost::begin(vec_in),
+        boost::end(vec_in),
+        static_cast<val_>(0)
+    );
+    
+    out << "cum_sum = " << cum_sum << std::endl;
+    
+    BOOST_ASSERT( !math::isinf( cum_sum ) );
+        
+    out << "<-" << std::endl;
+        
+}
+    
Added: sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/libs/importance_weights/example/scale_to_finite_sum.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::example::scale_to_finite_sum.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_IMPORTANCE_WEIGHTS_EXAMPLE_SCALE_TO_FINITE_SUM_H_ER_2009
+#define LIBS_IMPORTANCE_WEIGHTS_EXAMPLE_SCALE_TO_FINITE_SUM_H_ER_2009
+#include <ostream>
+
+void example_scale_to_finite_sum(std::ostream&);
+
+#endif
Added: sandbox/statistics/importance_weights/libs/importance_weights/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_weights/libs/importance_weights/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// importance_weights::example::scale_to_finite_sum.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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#include <iostream>
+#include <libs/importance_weights/example/scale_to_finite_sum.h>
+
+int main(){
+
+    example_scale_to_finite_sum(std::cout);
+
+    // See package statistics/importance_sampling for more examples.
+
+    return 0;
+}
+
+
+
Added: sandbox/statistics/iterator/boost/iterator/cycle_iterator2_ext.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/boost/iterator/cycle_iterator2_ext.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,163 @@
+// Erwann Rogard, wrote in July 2009:
+//
+// This iterator is by nbecker and was found in the boost's vault. 
+// Changes that I made are shown by ER_2007_07
+//
+// arch-tag: d007cbba-7c3d-48e0-9567-af7299fe5708
+#ifndef cycle_iterator2_ext_H
+#define cycle_iterator2_ext_H
+
+#include <boost/iterator/iterator_adaptor.hpp>
+#include <iterator>
+
+namespace boost {
+
+  //! This is a cycle iterator that does NOT keep track of wraparound.
+  template<typename BaseIterator, typename offset_t>
+  class cycle_iterator2_ext : public boost::iterator_adaptor<cycle_iterator2_ext<BaseIterator, offset_t>,
+							 BaseIterator
+						       >
+  {
+  public:
+    typedef typename boost::iterator_adaptor<cycle_iterator2_ext<BaseIterator, offset_t>,
+					     BaseIterator
+					    > super_t;
+
+    typedef typename super_t::difference_type difference_type;
+    typedef typename super_t::reference reference;
+
+    explicit cycle_iterator2_ext()
+    :size(0),position(0) // ER_2009_07
+      {}
+
+    explicit cycle_iterator2_ext (BaseIterator const& _b, BaseIterator const& _e, offset_t offset=0) :
+      // base(_b),  // ER_2009_07
+      super_t(_b),
+      size (std::distance (_b, _e)) {
+      SetPos (offset);
+    }
+
+    template <typename OtherBase, typename OtherOffset>
+    cycle_iterator2_ext (cycle_iterator2_ext<OtherBase,OtherOffset> const& other,
+		     typename enable_if_convertible<OtherBase, BaseIterator>::type* = 0) :
+      // base (other.base), //ER_2009_07
+      super_t(other),
+      size (other.size),
+      position (other.position)
+    {}
+
+    // ER_2009_07
+    template <typename OtherBase, typename OtherOffset>
+    enable_if<
+        is_convertible<OtherBase,BaseIterator>,
+        cycle_iterator2_ext&
+    >
+    operator= (cycle_iterator2_ext<OtherBase,OtherOffset> const& other)
+    {
+        if(&other!=this){
+            super_t& super = static_cast<super_t&>(this);
+            super = other;
+            size = (other.size);
+            position = (other.position);
+        }
+        return *this;
+    }
+
+  private:
+    friend class boost::iterator_core_access;
+  
+
+    void increment () {
+      ++position;
+      if (position >= size) {
+	position -= size;
+      }
+    }
+
+    void decrement () {
+      --position;
+      if (position < 0) {
+	position += size;
+      }
+    }
+
+    void SetPos (offset_t newpos) {
+      position = newpos % size;
+      if (position < 0)
+	position += size;
+    }
+
+    void advance (difference_type n) {
+      offset_t newpos = position + n;
+      SetPos (newpos);
+    }
+
+    template<typename OtherBase, typename OtherOffset>
+    difference_type
+    distance_to (cycle_iterator2_ext<OtherBase, OtherOffset> const& y) const {
+      if (size == 0)
+	return 0;
+
+      else {
+	offset_t pos1 = realposition();
+	offset_t pos2 = y.realposition();
+	//	return -(pos1 - pos2);
+	offset_t diff = pos1 - pos2;
+	if (diff < 0)
+	  diff += size;
+	return -diff;
+      }
+    }
+
+    template<typename OtherBase, typename OtherOffset>
+    bool equal (cycle_iterator2_ext<OtherBase, OtherOffset> const& y) const {
+      return distance_to (y) == 0;
+    }
+
+    reference dereference() const { 
+        //return *(base + position); //ER_2009_07
+        return  *(this->base_reference() + position);
+    }
+
+    offset_t PositiveMod (offset_t x) const {
+      offset_t y = x % size;
+      if (y < 0)
+	y += size;
+      return y;
+    }
+
+  public:
+
+
+    reference operator[] (difference_type n) const { 
+//        return *(base + PositiveMod (position + n)); //ER_2009_07
+        return *(this->base_reference() + PositiveMod (position + n)); 
+    }
+
+    offset_t offset() const { return position; }
+
+    offset_t realposition () const {
+      return position;
+    }
+
+
+    //  private:
+
+    //BaseIterator base; //ER_2009_07
+    offset_t size;
+    offset_t position;
+  };
+
+  template<typename offset_t, typename BaseIterator>
+  cycle_iterator2_ext<BaseIterator, offset_t> make_cycle_iterator2_ext(BaseIterator b, BaseIterator e, offset_t offset=0) {
+    return cycle_iterator2_ext<BaseIterator, offset_t> (b, e, offset);
+  }
+
+  template<typename BaseIterator>
+  cycle_iterator2_ext<BaseIterator, int> make_cycle_iterator2_ext(BaseIterator b, BaseIterator e, int offset=0) {
+    return cycle_iterator2_ext<BaseIterator, int> (b, e, offset);
+  }
+
+} //namespace boost
+
+#endif
Added: sandbox/statistics/iterator/boost/iterator/cycle_iterator_ext.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/boost/iterator/cycle_iterator_ext.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,170 @@
+// Erwann Rogard, wrote in July 2009:
+//
+// This iterator is by nbecker and was found in the boost's vault. 
+// Changes that I made are shown by ER_2007_07
+//
+// arch-tag: ed320324-7f40-4e99-8364-8a6b7cf4d19e
+#ifndef cycle_iterator_ext_HPP_2009
+#define cycle_iterator_ext_HPP_2009
+#include <boost/type_traits/is_convertible.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/iterator/iterator_adaptor.hpp>
+#include <iterator>
+
+namespace boost {
+
+  //! This is a cycle iterator that does keep track of wraparound.
+  template<typename BaseIterator, typename offset_t>
+  class cycle_iterator_ext : public boost::iterator_adaptor<cycle_iterator_ext<BaseIterator, offset_t>,
+							BaseIterator
+						       >
+  {
+  public:
+    typedef typename boost::iterator_adaptor<cycle_iterator_ext<BaseIterator, offset_t>,
+					     BaseIterator
+					    > super_t;
+
+    typedef typename super_t::difference_type difference_type;
+    typedef typename super_t::reference reference;
+
+    explicit cycle_iterator_ext()
+    :super_t(),size(0),position(0),wrap(0) // ER_2009_07 
+    {}
+
+    explicit cycle_iterator_ext (BaseIterator const& _b, BaseIterator const& _e, offset_t offset=0) :
+      //base(_b), //ER_2009_07
+      super_t(_b), //ER_2009_07
+      size (std::distance (_b, _e))
+      , wrap(0) //ER_2009_07
+    {
+      SetPos (offset);
+    }
+
+
+    template <typename OtherBase, typename OtherOffset>
+    cycle_iterator_ext (cycle_iterator_ext<OtherBase,OtherOffset> const& other,
+		    typename enable_if_convertible<OtherBase, BaseIterator>::type* = 0) :
+      super_t(other),       // ER_2009_07
+      //base (other.base),  // ER_2009_07
+      size (other.size),
+      position (other.position),
+      wrap (other.wrap)
+    {}
+
+    // ER_2009_07
+    template <typename OtherBase, typename OtherOffset>
+    enable_if<
+        is_convertible<OtherBase,BaseIterator>,
+        cycle_iterator_ext&
+    >
+    operator= (cycle_iterator_ext<OtherBase,OtherOffset> const& other)
+    {
+        if(&other!=this){
+            super_t& super = static_cast<super_t&>(this);
+            super = other;
+            size = (other.size),
+            position = (other.position),
+            wrap = (other.wrap);
+        }
+        return *this;
+    }
+
+  private:
+    friend class boost::iterator_core_access;
+
+    void increment () {
+      ++position;
+      if (position >= size) {
+	++wrap;
+	position -= size;
+      }
+    }
+
+    void decrement () {
+      --position;
+      if (position < 0) {
+	--wrap;
+	position += size;
+      }
+    }
+
+    void SetPos (offset_t newpos) {
+      position = newpos % size;
+      wrap = newpos / size;
+      if (position < 0) {
+	--wrap;
+	position += size;
+      }
+    }
+
+    void advance (difference_type n) {
+      offset_t newpos = realposition() + n;
+      SetPos (newpos);
+    }
+
+    template<typename OtherBase, typename OtherOffset>
+    difference_type
+    distance_to (cycle_iterator_ext<OtherBase, OtherOffset> const& y) const {
+      if (size == 0)
+	return 0;
+
+      else {
+	offset_t pos1 = realposition();
+	offset_t pos2 = y.realposition();
+	return -(pos1 - pos2);
+      }
+    }
+
+    template<typename OtherBase, typename OtherOffset>
+    bool equal (cycle_iterator_ext<OtherBase, OtherOffset> const& y) const {
+      return distance_to (y) == 0;
+    }
+
+    reference dereference() const { 
+       // return *(base + position); // ER_2009_07
+        return *(this->base_reference() + position); // ER_2009_07
+    }
+
+   offset_t PositiveMod (offset_t x) const {
+      offset_t y = x % size;
+      if (y < 0)
+	y += size;
+      return y;
+    }
+
+  public:
+
+
+    reference operator[] (difference_type n) const { 
+        // return *(base + PositiveMod (position + n)); // ER_2009_07
+        return *(this->base_reference() + PositiveMod (position + n)); // ER_2009_07
+    }
+
+    offset_t offset() const { return position; }
+
+    offset_t realposition () const {
+      return position + wrap * size;
+    }
+
+
+    //  private:
+
+    // BaseIterator base; // ER_2009
+    offset_t size;
+    offset_t position;
+    offset_t wrap;
+  };
+
+  template<typename offset_t, typename BaseIterator>
+  cycle_iterator_ext<BaseIterator, offset_t> make_cycle_iterator_ext(BaseIterator b, BaseIterator e, offset_t offset=0) {
+    return cycle_iterator_ext<BaseIterator, offset_t> (b, e, offset);
+  }
+
+  template<typename BaseIterator>
+  cycle_iterator_ext<BaseIterator, int> make_cycle_iterator_ext(BaseIterator b, BaseIterator e, int offset=0) {
+    return cycle_iterator_ext<BaseIterator, int> (b, e, offset);
+  }
+
+} //namespace boost
+
+#endif
Added: sandbox/statistics/iterator/boost/iterator/range_cycle.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/boost/iterator/range_cycle.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,81 @@
+///////////////////////////////////////////////////////////////////////////////
+// iterator::range_cycle.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_ITERATOR_RANGE_CYCLE_ER_2009
+#define BOOST_ITERATOR_RANGE_CYCLE_ER_2009
+#include <boost/range.hpp>
+#include <boost/utility.hpp> 
+#include <boost/iterator/cycle_iterator_ext.hpp> 
+#include <boost/iterator/cycle_iterator2_ext.hpp> 
+#include <boost/numeric/conversion/bounds.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+
+namespace boost{
+
+    // W = cycle_iterator_ext or  = cycle_iterator2_ext
+    template<template<typename,typename> class W>
+    class iterator_cycle{ 
+        public:
+        typedef std::size_t                 size_type;
+ 
+        template<typename It>
+        struct apply{
+            typedef W<It,size_type>         it_;
+            typedef iterator_range<it_>     type;
+        };
+                                            
+        template<typename It>
+        typename apply<It>::type
+        static make(
+            It b, 
+            It e,
+            size_type offset ,
+            size_type n
+        ){
+            typedef typename apply<It>::it_     it_;
+            typedef typename apply<It>::type    res_;
+            it_ it(b,e,offset);
+            return res_(
+                it,
+                boost::next(it,n)
+            );
+        }
+
+    };
+
+    // From a range to a cycle
+    template<template<typename,typename> class W = cycle_iterator_ext>
+    class range_cycle{ 
+        public:
+
+        typedef iterator_cycle<W>                       it_cycle_;
+        typedef typename it_cycle_::size_type           size_type;
+ 
+        template<typename R>
+        struct apply : 
+            it_cycle_::template apply<typename range_iterator<R>::type> {};
+                                            
+        template<typename R>
+        typename apply<R>::type
+        static make(
+            R& r,
+            size_type offset,
+            size_type n
+        ){
+            return it_cycle_::make(
+                boost::begin(r),
+                boost::end(r),
+                offset,
+                n
+            );
+        }
+
+    };
+    
+} //boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/iterator/libs/iterator/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/libs/iterator/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// iterator::doc::readme                                                    //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+This C++ package contains iterators.
+
+[ Useful links ]
+
+http://www.boost.org/doc/libs/1_39_0/libs/iterator/doc/index.html
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+
+[ History ]
+
+July 2009 : Current version
+
Added: sandbox/statistics/iterator/libs/iterator/example/range_cycle.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/libs/iterator/example/range_cycle.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,62 @@
+///////////////////////////////////////////////////////////////////////////////
+// example::iterator::range_cycle.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/range.hpp>
+#include <vector>
+#include <boost/iterator/cycle_iterator_ext.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <libs/iterator/example/range_cycle.h>
+
+void example_range_cycle(std::ostream& out){
+    out << "->example_iterator_cycle_range : ";
+
+    using namespace boost;
+
+    typedef unsigned                                    val_;
+    typedef std::vector<val_>                           vals_;
+    typedef range_size<vals_>::type                     size_;
+
+    typedef boost::range_cycle<>                        range_cycle_;
+    typedef range_cycle_::apply<vals_>::type            cycle_;
+    const size_ n = 5;
+    const size_ k = 2;
+
+    vals_ vals;
+    {   
+        using namespace assign;
+        for(unsigned i = 0; i<k; i++){
+            vals.push_back(i);
+        }
+    }
+
+    cycle_ cycle = range_cycle_::make(vals,0,n);
+    BOOST_ASSERT( !cycle.is_singular() );
+    BOOST_ASSERT(size( cycle ) == n);
+    for(unsigned i = 0; i<n; i++){
+        BOOST_ASSERT(
+         *next(boost::begin(cycle),i) == (i%k)
+        );
+    }
+    cycle_ cycle2;
+    BOOST_ASSERT( cycle2.is_singular() );
+    cycle2 = cycle;
+    for(unsigned i = 0; i<n; i++){
+        BOOST_ASSERT(
+         *next(boost::begin(cycle2),i) == (i%k)
+        );
+    }
+    
+//    copy(
+//        boost::begin(cycle2),
+//        boost::end(cycle2),
+//        std::ostream_iterator<val_>(out," ")
+//    );
+    
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/iterator/libs/iterator/example/range_cycle.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/libs/iterator/example/range_cycle.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// example::iterator::range_cycle.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_ITERATOR_EXAMPLE_RANGE_CYCLE_ER_2009
+#define LIBS_ITERATOR_EXAMPLE_RANGE_CYCLE_ER_2009
+
+#include <ostream>
+
+void example_range_cycle(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/iterator/libs/iterator/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/iterator/libs/iterator/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,9 @@
+#include <iostream>
+#include <libs/iterator/example/range_cycle.h>
+
+int main () {
+
+    example_range_cycle(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/joint_dist/boost/joint_dist/distribution/detail/dim.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/distribution/detail/dim.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::distribution::detail::dim.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_JOINT_DIST_DISTRIBUTION_DETAIL_DIM_HPP_ER_2009
+#define BOOST_JOINT_DIST_DISTRIBUTION_DETAIL_DIM_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+
+namespace boost{
+namespace joint_dist{
+namespace detail{
+
+    struct dim{
+        typedef std::size_t size_type;
+        
+        dim();
+        dim(size_type n);
+        
+        const size_type& dimension()const;
+        
+        private:
+        size_type n_;
+    };
+
+    std::ostream& operator<<(std::ostream& out,const dim& d);
+
+    // Implementation //
+    
+    dim::dim():n_(0){};
+    dim::dim(size_type n):n_(n){};
+    const dim::size_type& dim::dimension()const{ return n_; }
+
+    std::ostream& operator<<(std::ostream& out,const dim& d){
+        return (out << (format("dim(%1%)")%d.dimension()).str());
+    }
+
+
+}// detail
+}// joint_dist
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/distribution/iid.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/distribution/iid.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,122 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::distribution::iid.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_JOINT_DIST_DISTRIBUTION_IID_HPP_ER_2009
+#define BOOST_JOINT_DIST_DISTRIBUTION_IID_HPP_ER_2009
+#include <cmath>
+#include <stdexcept>
+#include <numeric>
+#include <functional>
+#include <ostream>
+#include <boost/mpl/bool.hpp>
+#include <boost/range.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/format.hpp>
+#include <boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp>
+#include <boost/scalar_dist/algorithm/accumulate.hpp>
+#include <boost/joint_dist/distribution/detail/dim.hpp>
+#include <boost/joint_dist/meta/is_joint_dist.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    // An iid distribution
+    template<typename D>
+    class iid : D, public detail::dim{
+        public:
+        typedef typename D::value_type                  value_type;
+        typedef typename D::policy_type                 policy_type;
+        typedef D                                       element_type;
+    
+        iid();
+        iid(const D& d,size_type dim);
+        iid(const iid& that);
+        iid& operator=(const iid& that);
+
+        const element_type& element()const;
+
+    };
+
+    template<typename D>
+    struct is_joint_dist< iid<D> > : mpl::bool_<true> {};
+
+    template<typename D>    
+    std::ostream& operator<<(std::ostream& out, const iid<D>& that);
+
+    template<typename D,typename R>
+    typename D::value_type log_unnormalized_pdf(
+        const iid<D>& dist,
+        const R& sample
+    );
+
+    template<typename D,typename R>
+    typename D::value_type pdf(
+        const iid<D>& dist,
+        const R& sample
+    );
+
+    // Implementation //
+
+    template<typename D>
+    const typename iid<D>::element_type& 
+    iid<D>::element()const{ 
+        return static_cast<const D&>(*this);
+    }
+
+    template<typename D> iid<D>::iid() : D(), dim(0){}
+
+    template<typename D> 
+    iid<D>::iid(const D& d,size_type n):D(d),dim(n){}
+
+    template<typename D> iid<D>::iid(const iid& that):D(that),dim(that){}
+
+    template<typename D> iid<D>& 
+    iid<D>::operator=(const iid& that){
+        if(&that!=this){
+            D::operator=(that);
+            dim::operator=(that);
+        }
+        return *this;
+    }
+
+    template<typename D>
+    std::ostream& operator<<(std::ostream& out, const iid<D>& that){
+        static const char* msg = "iid{%1%:i=0,...,%2%}";
+        return (out<<
+            ( 
+                format(msg) % that.element() % that.dimension() 
+            ).str()
+        );
+    }
+
+    template<typename D,typename R>
+    typename D::value_type log_unnormalized_pdf(const iid<D>& dist,const R& x){
+        const char* msg = "log_unnormalized_pdf(%1%) : size(x) = != dim = %2%";
+        if( boost::size(x) != dist.dimension() ){
+            throw std::runtime_error(
+                (format(msg)%size(x)%dist.dimension()).str()
+            );
+        }
+        typedef iid<D> iid_;
+        typedef typename iid_::value_type val_;
+        val_ init = static_cast<val_>(0);
+        val_ log_pdf 
+            = math::accumulate<std::plus,math::fun_wrap::log_unnormalized_pdf_>(
+            dist.element(),
+            boost::begin(x),
+            boost::end(x),
+            init
+        );
+        return log_pdf;
+    };
+
+}// joint_dist
+}// boost 
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/distribution/independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/distribution/independent.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,132 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::distribution::independent.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_JOINT_DIST_DISTRIBUTION_INDEPENDENT_HPP_ER_2009
+#define BOOST_JOINT_DIST_DISTRIBUTION_INDEPENDENT_HPP_ER_2009
+#include <cmath>
+#include <vector>
+#include <ostream>
+#include <numeric>
+#include <boost/mpl/bool.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/foreach.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp>
+#include <boost/joint_dist/distribution/detail/dim.hpp>
+#include <boost/joint_dist/meta/is_joint_dist.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    // Joint distribution of a collection of indepdendent variables, each from 
+    // the same distribution, but with different parameters
+    template<typename R>
+    class independent : detail::dim{
+        public:
+        typedef typename remove_reference<R>::type  cv_r_;
+        typedef typename remove_cv<cv_r_>::type     elements_type;
+        typedef 
+            typename range_value<elements_type>::type element_type;
+
+        typedef typename element_type::value_type    value_type;
+        typedef typename element_type::policy_type   policy_type;
+    
+        independent();
+        independent(typename call_traits<R>::param_type vec);
+        independent(const independent&);
+        independent& operator=(const independent& that);
+
+        typename call_traits<R>::const_reference elements()const;
+    
+        private:
+        typename call_traits<R>::value_type distributions_;
+    };        
+
+    template<typename D>
+    struct is_joint_dist< independent<D> > : mpl::bool_<true> {};
+
+    template<typename R>
+    std::ostream& operator<<(std::ostream& out, const independent<R>& d);
+
+    template<typename R,typename R1>
+    typename independent<R>::value_type 
+    log_unnormalized_pdf(const independent<R>& dist,const R1& x);
+
+    // Implementation //
+    
+    template<typename R>
+    std::ostream& operator<<(std::ostream& out, const independent<R>& d){
+        out << "independent"<< '(' << ' ';
+        typedef independent<R> indeps_;
+        typedef typename indeps_::element_type elem_;
+        BOOST_FOREACH(const elem_& elem,d.elements()){
+            out << elem << ' ';
+        }
+        out << ')';
+        return out;
+    }
+
+    template<typename R>
+    independent<R>::independent():distributions_(),dim(){}
+
+    template<typename R>
+    independent<R>::independent(typename call_traits<R>::param_type vec)
+    :distributions_(vec),dim(boost::size(vec)){}
+
+    template<typename R>
+    independent<R>::independent(const independent& that)
+    :distributions_(that.distributions_),dim(that){}
+
+    template<typename R>
+    independent<R>& 
+    independent<R>::operator=(const independent& that){
+        if(&that!=this){
+            (this->distributions) = that.distributions;
+            dim::operator=(that);
+        }
+        return *this;
+    }
+
+    template<typename R>
+    typename call_traits<R>::const_reference 
+    independent<R>::elements()const{
+        return this->distributions_;
+    }
+    
+    template<typename R,typename R1>
+    typename independent<R>::value_type
+    log_unnormalized_pdf(const independent<R>& dist,const R1& x){
+        typedef independent<R>                          indeps_;
+        typedef typename indeps_::value_type            val_;
+        typedef typename indeps_::element_type     dist_;
+        val_ init = static_cast<val_>(0);
+        BOOST_ASSERT(
+            boost::size(x) == boost::size(dist.elements())
+        );
+        typedef math::fun_wrap::log_unnormalized_pdf_<dist_> f_;
+        val_ log_pdf = std::inner_product(
+            boost::begin(dist.elements()),
+            boost::end(dist.elements()),
+            boost::begin(x),
+            init,
+            lambda::_1 + lambda::_2,
+            lambda::bind(
+                f_::instance,
+                lambda::_1,
+                lambda::_2
+            )
+        );
+        return  log_pdf;
+    }
+
+}// joint_dist
+}// boost 
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/distributions/iid.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/distributions/iid.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::distributions::iid.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_JOINT_DIST_DISTRIBUTIONS_IID_HPP_ER_2009
+#define BOOST_JOINT_DIST_DISTRIBUTIONS_IID_HPP_ER_2009
+
+#include <boost/joint_dist/distribution/iid.hpp>
+#include <boost/joint_dist/random/iid.hpp>
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/distributions/independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/distributions/independent.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::distributions::independent.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_JOINT_DIST_DISTRIBUTIONS_INDEPENDENT_HPP_ER_2009
+#define BOOST_JOINT_DIST_DISTRIBUTIONS_INDEPENDENT_HPP_ER_2009
+
+#include <boost/joint_dist/distribution/independent.hpp>
+#include <boost/joint_dist/random/independent.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/detail/fun_wrap.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/detail/fun_wrap.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,33 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::fun_wrap::cdf::detail::fun_wrap.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_JOINT_DIST_FUN_WRAP_DETAIL_FUN_WRAP_ER_2009
+#define BOOST_JOINT_DIST_FUN_WRAP_DETAIL_FUN_WRAP_ER_2009
+#include <boost/joint_dist/meta/pointer.hpp>
+
+namespace boost{
+namespace joint_dist{
+namespace fun_wrap{
+namespace detail{
+
+    template<typename D,typename R,typename pointer<D,R>::type f>
+    struct fun_wrap{
+        typedef function<D> fun_;
+        typedef typename pointer<D,R>::type type;
+        static type instance;
+    };
+
+    template<typename D,typename R,typename pointer<D,R>::type f>
+    typename fun_wrap<D,R,f>::type
+    fun_wrap<D,R,f>::instance = f;
+
+}// detail
+}// fun_wrap
+}// joint_dist
+}// boost
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::fun_wrap::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_JOINT_DIST_FUN_WRAP_INCLUDE_PDF_ER_2009
+#define BOOST_JOINT_DIST_FUN_WRAP_INCLUDE_PDF_ER_2009
+
+#include <boost/joint_dist/fun_wrap/log_unnormalized_pdf.hpp>
+
+#endif
+
Added: sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/log_unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/fun_wrap/log_unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::fun_wrap::log_unnormalized_pdf.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_JOINT_DIST_FUN_WRAP_LOG_UNNORMALIZED_PDF_ER_2009
+#define BOOST_JOINT_DIST_FUN_WRAP_LOG_UNNORMALIZED_PDF_ER_2009
+#include <boost/joint_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    template<typename D,typename R> 
+    typename D::value_type log_unnormalized_pdf(const D& d,const R& x);
+    
+    namespace fun_wrap{
+        template<typename D,typename R> 
+        struct log_unnormalized_pdf_
+            : detail::fun_wrap<D,R,log_unnormalized_pdf>{};
+    }
+
+}// joint_dist
+}// boost
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/meta/delegate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/meta/delegate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,27 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::meta::delegate.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_JOINT_DIST_META_DELEGATE_ER_2009
+#define BOOST_JOINT_DIST_META_DELEGATE_ER_2009
+#include <boost/function.hpp>
+#include <boost/joint_dist/meta/signature.hpp>
+#include <boost/joint_dist/meta/pointer.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    template<typename D,typename R>
+    struct delegate{
+        typedef signature<R> meta_sig;
+        typedef typename meta_sig::type sig_;
+        typedef boost::function<sig_> type;
+    };
+
+}// joint_dist
+}// boost
+
+#endif
Added: sandbox/statistics/joint_dist/boost/joint_dist/meta/is_joint_dist.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/meta/is_joint_dist.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::meta::is_joint_dist.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_JOINT_DIST_FUN_WRAP_META_IS_JOINT_DIST_ER_2009
+#define BOOST_JOINT_DIST_FUN_WRAP_META_IS_JOINT_DIST_ER_2009
+#include <boost/mpl/bool.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    template<typename D>
+    struct is_joint_dist : mpl::bool_<false> {};
+
+    // What for? Manage overload set externally
+
+}// joint_dist
+}// boost
+
+#endif
+
+
Added: sandbox/statistics/joint_dist/boost/joint_dist/meta/pointer.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/meta/pointer.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::meta::pointer.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_JOINT_DIST_META_POINTER_ER_2009
+#define BOOST_JOINT_DIST_META_POINTER_ER_2009
+#include <boost/joint_dist/meta/signature.hpp>
+
+namespace boost{
+namespace joint_dist{
+
+    template<typename D,typename R>
+    struct pointer{
+        typedef signature<D,R> meta_sig_;
+        typedef typename meta_sig_::type sig_;
+        typedef sig_* type;
+    };
+
+}// joint_dist
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/meta/signature.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/meta/signature.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,26 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::meta::signature.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_JOINT_DIST_META_SIGNATURE_ER_2009
+#define BOOST_JOINT_DIST_META_SIGNATURE_ER_2009
+
+namespace boost{
+namespace joint_dist{
+
+    template<typename D,typename R>
+    struct signature{
+        typedef typename D::value_type value_type;
+        typedef value_type type(
+            const D&,
+            const R&
+        );
+    };
+    
+}// joint_dist
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/random/generate_n.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/random/generate_n.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,114 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::random::generate_n.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_JOINT_DIST_RANDOM_GENERATE_N_ER_2009
+#define BOOST_JOINT_DIST_RANDOM_GENERATE_N_ER_2009
+#include <algorithm>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/iterator/iterator_concepts.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/range.hpp>
+#include <boost/mpl/nested_type.hpp>
+#include <boost/dist_random/random/generate_n.hpp>
+#include <boost/dist_random/random/sample.hpp>
+#include <boost/joint_dist/fun_wrap/include.hpp>
+#include <boost/joint_dist/meta/is_joint_dist.hpp>
+
+namespace boost{
+
+    // To be consistent with dist_random, generate_n is in namespace boost
+    // not namespace boost::joint_dist. enable_if is used instead.
+
+    // Requirements:
+    // size(*it_rx) == jd.dimension()
+    template<typename ItRx,typename N,typename D,typename U>
+    typename enable_if<
+        joint_dist::is_joint_dist<D>,
+        ItRx
+    >::type
+    generate_n(ItRx b_rx,N n,const D& jd,U& urng);
+
+    // F is defined in joint_dist/fun_wrap
+    template<template<typename,typename> class F,
+        typename ItRx,typename ItF,typename N,typename D,typename U>
+    typename enable_if<
+        joint_dist::is_joint_dist<D>,
+        ItRx
+    >::type
+    generate_function_n(ItRx b_rx,ItF b_f,N n,const D& jd,U& urng);
+
+    // Same a previous, but F = fun_wrap::log_unnormalized_pdf_
+    template<typename ItRx,typename ItF,typename N,typename D,typename U>
+    typename enable_if<
+        joint_dist::is_joint_dist<D>,
+        ItRx
+    >::type
+    generate_n(ItRx b_rx,ItF b_f,N n,const D& jd,U& urng){
+        return generate_function_n<joint_dist::fun_wrap::log_unnormalized_pdf_>(
+            b_rx,b_f,n,jd,urng
+        );
+    } 
+           
+    // Implementation //
+
+    template<typename ItRx,typename N,typename D,typename U>
+    typename enable_if<
+        joint_dist::is_joint_dist<D>,
+        ItRx
+    >::type
+    generate_n(ItRx b_rx,N n,const D& jd,U& urng){
+        typedef typename iterator_value<ItRx>::type row_;
+
+        // std::back_inserter cannot work
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<ItRx>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<ItRx>));
+
+        typedef N size_;
+        size_ i = 0;
+        while(i<n){
+            row_& row = *b_rx;
+            sample(
+                boost::begin( row ),
+                jd,
+                urng
+            );
+            ++b_rx;
+            ++i;
+        }
+        return b_rx;
+    }
+
+    template<template<typename,typename> class F,
+        typename ItRx,typename ItF,typename N,typename D,typename U>
+    typename enable_if<
+        joint_dist::is_joint_dist<D>,
+        ItRx
+    >::type
+    generate_function_n(ItRx b_rx,ItF b_f,N n,const D& jd,U& urng){
+        ItRx e_rx = generate_n(b_rx,n,jd,urng);
+
+        typedef typename iterator_value<ItRx>::type r_;
+        typedef F<D,r_> mf_;
+        typename mf_::type f = mf_::instance;
+
+        std::transform(
+            b_rx,
+            e_rx,
+            b_f,
+            boost::lambda::bind(f,jd,boost::lambda::_1)
+        );
+        return e_rx;
+    }
+
+
+//} // intentional
+}//boost
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/random/iid.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/random/iid.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,33 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::random::iid.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_JOINT_DIST_RANDOM_IID_ER_2009
+#define BOOST_JOINT_DIST_RANDOM_IID_ER_2009
+#include <algorithm>
+#include <boost/dist_random/random/generate_n.hpp>
+#include <boost/joint_dist/distribution/iid.hpp>
+
+namespace boost{
+
+    // Warning: include this file after
+    // <boost/dist_random/distributions/D.hpp>
+
+    template<typename It,typename D,typename U>
+    It sample(It out,const joint_dist::iid<D>& dist,U& urng);
+
+    // Implem
+
+    template<typename It,typename D,typename U>
+    It sample(It out,const joint_dist::iid<D>& dist,U& urng){
+        return generate_n(
+            out, dist.dimension(),dist.element(), urng
+        );
+    }
+
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/random/independent.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/random/independent.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,43 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::random::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_JOINT_DIST_RANDOM_INDEPENDENT_ER_2009
+#define BOOST_JOINT_DIST_RANDOM_INDEPENDENT_ER_2009
+#include <algorithm>
+#include <boost/foreach.hpp>
+#include <boost/concept_check.hpp>
+#include <boost/iterator/iterator_concepts.hpp>
+#include <boost/dist_random/random/sample.hpp>
+#include <boost/joint_dist/distribution/independent.hpp>
+
+namespace boost{
+
+    // Warning: include this file after
+    // <boost/dist_random/distributions/D.hpp>
+
+    template<typename It,typename Ds,typename U>
+    It sample(It out,const joint_dist::independent<Ds>& dist,U& urng);
+
+    // Implem
+
+    template<typename It,typename Ds,typename U>
+    It sample(It out,const joint_dist::independent<Ds>& dist,U& urng){
+        BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<It>));
+        BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<It>));
+        typedef typename joint_dist::independent<Ds> ind_;
+        typedef typename ind_::element_type d_;
+        // TODO: std::transform
+        BOOST_FOREACH(const d_& d,dist.elements()){
+            *out = sample(d,urng);
+            ++out;
+        }
+        return out;
+    }
+
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/boost/joint_dist/unscope/log_unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/boost/joint_dist/unscope/log_unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::unscope::log_unnormalized_pdf.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_JOINT_DIST_UNSCOPE_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#define BOOST_JOINT_DIST_UNSCOPE_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#include <boost/utility/enable_if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/joint_dist/meta/is_joint_dist.hpp>
+
+namespace boost{
+
+    namespace joint_dist{
+        template<typename D,typename X>
+        typename D::value_type log_unnormalized_pdf(const D& d,const X& x);
+    }
+
+    template<typename D,typename X>
+    typename boost::lazy_enable_if<
+        D,
+        mpl::identity<typename D::value_type>
+    >
+    log_unnormalized_pdf(const D& d,const X& x){
+        return joint_dist::log_unnormalized_pdf<D>(d,x);
+    }
+
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/libs/joint_dist/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/libs/joint_dist/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,105 @@
+//////////////////////////////////////////////////////////////////////////////
+// joint_dist::doc::readme                                                  //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These C++ classes mirror sandbox/statistics/scalar_dist but in the multivariate 
+framework.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+/sandbox/statistics/arithmetic/ 
+/sandbox/statistics/dist_random 
+/sandbox/statistics/mpl/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/standard_distribution/ 
+/sandbox/statistics/vector_space/ 
+
+[ Bugs ]
+
+A possible bug is described in example_1.cpp
+
+[ History ]
+
+July 2009 : Current version
+
+[ distributions ]
+    Collects hpp files pertaining to a given distribution
+
+[ distribution ]
+
+    Defines a distribution and possibly associated functions 
+    (log_unnormalized_pdf). Currently:
+        iid
+        independent
+
+[ fun_wrap ]
+
+    Similar to fun_wrap in scalard_dist
+
+[ meta ]
+
+    Similar to meta in scalard_dist. 
+    
+    is_joint_dist is used to manage the overload set non-intrusively (SFINAE), 
+    by client libraries, where either a scalar or a joint distribution is a 
+    valid argument to a function template.
+    
+[ random ]
+
+    Let b_x point to the beginning of a range of scalars
+    Let b_row point to beginning of a range of ranges of scalars.
+
+        sample(b_x,joint,urng);
+        generate_n(b_row,n,joint,urng);
+
+[ unscope ]
+
+    A version of pdf, cdf etc., defined in scope boost that forwards to that 
+    in scope boost::joint_dist. 
+    
+    The rationale for this, is that some function templates in other libraries 
+    in sandbox/statitics apply to scalar and joint distributions alike, and 
+    therefore require a common interface. 
+
+[ Output ]
+
+main.cpp
+
+ -> example_example_1
+0.213436 -0.49558 
+1.57538 -1.0592 
+1.83927 1.88577 
+0.604675 -0.365983 
+-0.578264 -0.634376 
+1.02974 0.724106 
+-0.115074 0.635774 
+-3.00939 -0.913024 
+3.24072 -0.886412 
+2.55662 -0.573354 
+
+0.213436 1.57538 
+1.83927 0.604675 
+-0.578264 1.02974 
+-0.115074 -3.00939 
+3.24072 2.55662 
+0.882285 2.76953 
+0.465082 -1.78131 
+0.260849 0.0615231 
+-0.430637 1.23333 
+0.538072 1.14551 <-
Added: sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,84 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::example::example_1.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <boost/range.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/foreach.hpp>
+#include <boost/vector_space/functional/equal.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+// This must precede joint_dist
+#include <boost/dist_random/distributions/normal.hpp>
+#include <boost/joint_dist/distributions/iid.hpp>
+#include <boost/joint_dist/distributions/independent.hpp>
+#include <boost/joint_dist/random/generate_n.hpp>
+
+void example_example_1(std::ostream& out){
+    out << " -> example_example_1";
+    using namespace boost;
+
+    const long dim = 2;   // each sample of size dim
+    const long n = 1e1;     // number of samples
+
+    typedef double val_;
+    typedef boost::mt19937                  urng_;
+    typedef std::vector<val_>               row_;
+    typedef std::vector<row_>               mat_;
+    typedef range_iterator<mat_>            it_row_;
+    typedef math::normal_distribution<val_> dist_;
+    typedef std::vector<dist_>              dists_;
+    typedef joint_dist::iid<dist_>          iid_;
+    typedef joint_dist::independent<dists_> ind_;
+
+    urng_ urng;
+    urng_ urng2 = urng;
+
+    mat_ mat(n,row_(dim)); 
+    row_ lpdfs; lpdfs.reserve(n);
+
+    iid_ iid( dist_(), dim );
+    ind_ ind( dists_(dim,iid.element()) ); //so they are the same
+
+    generate_n(
+        boost::begin(mat),
+        std::back_inserter(lpdfs),
+        n,
+        iid,
+        urng
+    );
+
+    BOOST_FOREACH(const row_& r,mat){
+        out << std::endl;
+        BOOST_FOREACH(const val_& x,r){
+            out << x << " ";
+        }
+    }
+
+    row_ lpdfs2; lpdfs2.reserve(n);
+    generate_n(
+        boost::begin(mat),
+        std::back_inserter(lpdfs2),
+        n,
+        ind,
+        urng2
+    );
+
+    out << std::endl;
+    BOOST_FOREACH(const row_& r,mat){
+        out << std::endl;
+        BOOST_FOREACH(const val_& x,r){
+            out << x << " ";
+        }
+    }
+
+    typedef vector_space::equal<row_&> vs_eq_;
+    
+    vs_eq_ vs_eq(lpdfs);
+    
+    //BOOST_ASSERT(vs_eq(lpdfs2)); // TODO don't agree. Bug?
+
+    out << "<-";
+}
\ No newline at end of file
Added: sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/libs/joint_dist/example/example_1.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::example::example_1.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_JOINT_DIST_EXAMPLE_EXAMPLE_1_H_ER_2009
+#define LIBS_JOINT_DIST_EXAMPLE_EXAMPLE_1_H_ER_2009
+#include <ostream>
+
+void example_example_1(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/joint_dist/libs/joint_dist/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/joint_dist/libs/joint_dist/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// joint_dist::src::main.cpp                                                 //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/joint_dist/example/example_1.h>
+
+int main(){
+
+    example_example_1(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/kernel/boost/kernel/bandwidth/normal_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/bandwidth/normal_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,44 @@
+//////////////////////////////////////////////////////////////////////////////
+// boost::kernel::bandwidth::normal_distribution.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_KERNEL_BANDWIDTH_NORMAL_DISRTIBUTION_HPP_ER_2009           
+#define BOOST_KERNEL_BANDWIDTH_NORMAL_DISRTIBUTION_HPP_ER_2009
+#include <cmath>
+
+namespace boost{
+namespace kernel{
+
+// Finds the optimal density (RP) bandwidth for the Gaussian kernel assuming 
+// 1) x is a normal vector each coordinate having stddev sigma
+// 2) kernel is Gaussian.
+
+template<unsigned M, typename T>
+struct normal_distribution{
+    typedef T value_type;
+    static value_type rp_bandwidth(std::size_t n); // Assumes sigma = 1
+    static value_type rp_bandwidth(value_type sigma,unsigned n);
+    // For M == 1, bandwdith = sigma (3n/4)^(-1/5) = 1.06 sigma n^(-1/5)
+};
+template<unsigned M, typename T>
+typename normal_distribution<M,T>::value_type
+normal_distribution<M,T>::rp_bandwidth(std::size_t n){
+    static const value_type e = -static_cast<T>(1)/static_cast<T>(M+4);
+    static const value_type r = static_cast<T>(2+M)/ static_cast<T>(4);
+    value_type a =  static_cast<T>(n) * r;
+    return std::pow( a, e );
+}
+
+template<unsigned M, typename T>
+typename normal_distribution<M,T>::value_type
+normal_distribution<M,T>::rp_bandwidth(value_type sigma,unsigned n){
+    return sigma * rp_bandwidth(n);
+}
+
+}// kernel
+}// boost
+#endif
Added: sandbox/statistics/kernel/boost/kernel/functional/benchmark_nw.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/benchmark_nw.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,249 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::benchmark_nw.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_KERNEL_FUNCTIONAL_BENCHMARK_NW_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_BENCHMARK_NW_H_ER_2009
+#include <cmath>
+#include <ostream>
+#include <string>
+#include <boost/format.hpp>
+#include <boost/timer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/range.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/binary_op/data/tuple_range.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+#include <boost/kernel/functional/nw_visitor_tuple.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+
+namespace boost{
+namespace kernel{
+        
+// Computes the error in estimating the conditional mean with a 
+// particular kernel. see benchmark_rp.hpp
+template<typename Sx,typename Sp,typename Sy,typename K, typename Ae  = 
+        typename kernel::detail::mean_accumulator<typename K::result_type>::type
+>
+class benchmark_nw{
+public:
+    typedef typename K::result_type value_type;
+    typedef typename kernel::detail::mean_accumulator<value_type>::type acc_;
+    private:
+    typedef is_reference<Sx> is_ref_sx_;
+    typedef is_reference<Sp> is_ref_sp_;
+    typedef is_reference<Sp> is_ref_sy_;
+    typedef typename remove_reference<Sx>::type const_sx_;
+    typedef typename remove_reference<Sp>::type const_sp_;
+    typedef typename remove_reference<Sy>::type const_sy_;
+    public:
+    // Construct
+    benchmark_nw();
+    benchmark_nw(
+        typename call_traits<Sx>::param_type,
+        typename call_traits<Sp>::param_type,
+        typename call_traits<Sy>::param_type,
+        K k
+    );
+    benchmark_nw(
+        typename call_traits<Sx>::param_type,
+        typename call_traits<Sp>::param_type,
+        typename call_traits<Sy>::param_type
+    );
+    benchmark_nw(const benchmark_nw&);
+    benchmark_nw& operator=(const benchmark_nw&);
+        
+    void set_kernel(K k);
+        
+    // Update
+    template<typename Sx1,typename Sy1> 
+    void operator()(const Sx1& in_x,const Sy1& in_y);
+        
+    // Access
+    const K& kernel()const;
+    const Ae& error_accumulator_p()const;
+    const Ae& error_accumulator_y()const;
+    value_type error_p()const;
+    value_type error_y()const;
+    unsigned n()const; // in-sample size
+    unsigned m()const; // out-sample size
+    value_type time()const;
+        
+    static std::string header; 
+        
+    private:
+    K k_;
+    typename call_traits<Sx>::value_type sx_; 
+    typename call_traits<Sp>::value_type sp_; 
+    typename call_traits<Sy>::value_type sy_;
+    Ae error_acc_p_;
+    Ae error_acc_y_;
+    value_type time_;
+    unsigned n_;
+};
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+std::string benchmark_nw<Sx,Sp,Sy,K,Ae>::header = "(n, avg_t,e_p,e_y)";
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+std::ostream& 
+operator<<(std::ostream& out,const benchmark_nw<Sx,Sp,Sy,K,Ae>& b){
+    static const char* str = "(%1%, %2%, %3%, %4%)";
+    typedef benchmark_nw<Sx,Sp,Sy,K,Ae> bench_;
+    typedef typename bench_::value_type value_type;
+    value_type m_ = static_cast<value_type>(b.m());
+    value_type n_ = static_cast<value_type>(b.n());
+    value_type avg_t = (b.time()) / (m_); //Should increase linearly with n
+    format f(str); 
+    f%(b.n())%(avg_t)%(b.error_p())%(b.error_y());
+    out << f.str();
+    return out;
+}
+
+// Construction
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+benchmark_nw<Sx,Sp,Sy,K,Ae>::benchmark_nw(){
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_sx_>));
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_sp_>));
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_sy_>));
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+benchmark_nw<Sx,Sp,Sy,K,Ae>::benchmark_nw(
+    typename call_traits<Sx>::param_type sx,
+    typename call_traits<Sp>::param_type sp,
+    typename call_traits<Sy>::param_type sy,
+    K k
+):k_(k),sx_(sx),sp_(sp),sy_(sy),
+error_acc_p_(),error_acc_y_(),time_(static_cast<value_type>(0)){}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+benchmark_nw<Sx,Sp,Sy,K,Ae>::benchmark_nw(
+    typename call_traits<Sx>::param_type sx,
+    typename call_traits<Sp>::param_type sp,
+    typename call_traits<Sy>::param_type sy
+):k_(K()),sx_(sx),sp_(sp),sy_(sy),
+error_acc_p_(),error_acc_y_(),time_(static_cast<value_type>(0)){}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+benchmark_nw<Sx,Sp,Sy,K,Ae>::benchmark_nw(const benchmark_nw& that)
+:k_(that.k_),sx_(that.sx_),sp_(that.sp_),sy_(that.sy_),
+error_acc_p_(that.error_acc_p_),error_acc_y_(that.error_acc_y_),
+time_(that.time_){}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+benchmark_nw<Sx,Sp,Sy,K,Ae>& 
+benchmark_nw<Sx,Sp,Sy,K,Ae>::operator=(const benchmark_nw& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_sx_>));
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_sp_>));
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_sy_>));
+        k_ = (that.k_);
+        sx_ = (that.sx_);
+        sp_ = (that.sp_);
+        sy_ = (that.sy_);
+        error_acc_p_ = (that.error_acc_p_);
+        error_acc_p_ = (that.error_acc_y_);
+        time_ = (that.time_);    
+    }
+    return (*this);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+void benchmark_nw<Sx,Sp,Sy,K,Ae>::set_kernel(K k){
+    k_ = k;
+}
+    
+// Update
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+template<typename Sx1,typename Sy1>
+void benchmark_nw<Sx,Sp,Sy,K,Ae>::operator()(const Sx1& sx1,const Sy1& sy1){
+    typedef const Sx1& call_x1_;
+    typedef const Sy1& call_y1_;
+    typedef binary_op::tuple_range<call_x1_,call_y1_> factory_;
+    typedef typename factory_::type range_tuple_;
+    typedef estimator<range_tuple_,nw_visitor_tuple,K,acc_> estimator_type;
+
+    timer t;
+    range_tuple_ range_tuple = factory_::make(sx1,sy1);
+    estimator_type estimator(range_tuple,this->kernel());
+        
+    typedef typename range_iterator<const_sx_>::type iter_sx_;
+    typedef typename range_iterator<const_sp_>::type iter_sp_;
+    typedef typename range_iterator<const_sy_>::type iter_sy_;
+    typedef typename range_iterator<range_tuple_>::type iter_data_;
+
+    iter_sx_ i_x = boost::begin(sx_);
+    iter_sx_ e_x = boost::end(sx_);
+    iter_sp_ i_p = boost::begin(sp_);
+    iter_sy_ i_y = boost::begin(sy_);
+    value_type a, b;
+    while(i_x != e_x){
+        BOOST_AUTO(obj,estimator(*i_x));
+        a =  obj.rp_estimate();
+        b = (*i_p);
+        error_acc_p_(fabs(a-b));
+        a =  obj.nw_estimate();
+        b = (*i_y);
+        error_acc_y_(fabs(a-b));
+        ++i_x;
+        ++i_p;
+        ++i_y;
+    }
+    n_ = boost::size(range_tuple);
+    time_ = t.elapsed();
+}
+    
+// Access
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+const K& benchmark_nw<Sx,Sp,Sy,K,Ae>::kernel()const{
+    return (this->k_);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+const Ae& benchmark_nw<Sx,Sp,Sy,K,Ae>::error_accumulator_p()const{
+    return (this->error_acc_p_);
+}
+
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+const Ae& benchmark_nw<Sx,Sp,Sy,K,Ae>::error_accumulator_y()const{
+    return (this->error_acc_y_);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+typename benchmark_nw<Sx,Sp,Sy,K,Ae>::value_type 
+benchmark_nw<Sx,Sp,Sy,K,Ae>::error_p()const{
+    return accumulators::mean(this->error_acc_p_);
+}
+
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+typename benchmark_nw<Sx,Sp,Sy,K,Ae>::value_type 
+benchmark_nw<Sx,Sp,Sy,K,Ae>::error_y()const{
+    return accumulators::mean(this->error_acc_y_);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+unsigned benchmark_nw<Sx,Sp,Sy,K,Ae>::n()const{
+    return (this->n_);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+unsigned benchmark_nw<Sx,Sp,Sy,K,Ae>::m()const{
+    return accumulators::count(this->error_acc_p_);
+}
+    
+template<typename Sx,typename Sp, typename Sy,typename K,typename Ae>
+typename benchmark_nw<Sx,Sp,Sy,K,Ae>::value_type 
+benchmark_nw<Sx,Sp,Sy,K,Ae>::time()const{
+    return (this->time_);
+}
+    
+}// kernel
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/kernel/functional/benchmark_rp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/benchmark_rp.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,218 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::benchmark_rp.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_KERNEL_FUNCTIONAL_BENCHMARK_RP_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_BENCHMARK_RP_H_ER_2009
+#include <cmath>
+#include <ostream>
+#include <string>
+#include <boost/format.hpp>
+#include <boost/timer.hpp>
+#include <boost/foreach.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/range.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+#include <boost/kernel/functional/rp_visitor.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+
+namespace boost{
+namespace kernel{
+
+// Computes the error in estimating the density with a particular kernel.
+//
+// Ae specifies the accumulator used to compute the error
+//
+// Let sx of type Sx denote a sequence of values and sp of type Sx
+// their correponding density under a given probability distribution. Let
+// sx1 of type Sx1 denote a (training) sample from the same distribution.
+// 
+// Usage:
+// typedef benchmark_rp<Sx,Sp,K,Ae> bench_;
+// bench_ bench(sx,sp);
+// bench.set_kernel(bandwidth);
+// bench(sx1);
+// bench.error();
+template<typename Sx,typename Sp,typename K, typename Ae  = 
+    typename kernel::detail::mean_accumulator<typename K::result_type>::type
+>
+class benchmark_rp{
+    public:
+    typedef typename K::result_type value_type;
+    typedef typename kernel::detail::mean_accumulator<value_type>::type acc_;
+    private:
+    typedef is_reference<Sx> is_ref_sx_;
+    typedef is_reference<Sp> is_ref_sp_;
+    typedef typename remove_reference<Sp>::type const_sp_;
+    public:
+    // Construct
+    benchmark_rp();
+    benchmark_rp(
+        typename call_traits<Sx>::param_type,
+        typename call_traits<Sp>::param_type,
+        K k
+    );
+    benchmark_rp(
+        typename call_traits<Sx>::param_type,
+        typename call_traits<Sp>::param_type
+    );
+    benchmark_rp(const benchmark_rp&);
+    benchmark_rp& operator=(const benchmark_rp&);
+
+    void set_kernel(K k);
+
+    // Update
+    template<typename Sx1> void operator()(const Sx1& in_sample);
+        
+    // Access
+    const K& kernel()const;
+    const Ae& error_accumulator()const;
+    value_type error()const;
+    unsigned n()const; // in-sample size
+    unsigned m()const; // out-sample size
+    value_type time()const;
+
+    static std::string header; 
+
+    private:
+    K k_;
+    typename call_traits<Sx>::value_type sx_; 
+    typename call_traits<Sp>::value_type sp_; 
+    Ae error_acc_;
+    value_type time_;
+    unsigned n_;
+};
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+std::string benchmark_rp<Sx,Sp,K,Ae>::header = "(n, avg_t,e)";
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+std::ostream& operator<<(std::ostream& out,const benchmark_rp<Sx,Sp,K,Ae>& b){
+    static const char* str = "(%1%, %2%, %3%)";
+    typedef benchmark_rp<Sx,Sp,K,Ae> bench_;
+    typedef typename bench_::value_type value_type;
+    value_type m_ = static_cast<value_type>(b.m());
+    value_type n_ = static_cast<value_type>(b.n());
+    value_type avg_t = (b.time()) / (m_); //Should increase linearly with n
+    format f(str); 
+    f%(b.n())%(avg_t)%(b.error());
+    out << f.str();
+    return out;
+}
+
+
+// Construction
+template<typename Sx,typename Sp, typename K,typename Ae>
+benchmark_rp<Sx,Sp,K,Ae>::benchmark_rp(){
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_sx_>));
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_sp_>));
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+benchmark_rp<Sx,Sp,K,Ae>::benchmark_rp(
+    typename call_traits<Sx>::param_type sx,
+    typename call_traits<Sp>::param_type sp,
+    K k
+):k_(k),sx_(sx),sp_(sp),
+error_acc_(),time_(static_cast<value_type>(0)){
+    BOOST_ASSERT(size(sx) == size(sp));
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+benchmark_rp<Sx,Sp,K,Ae>::benchmark_rp(
+    typename call_traits<Sx>::param_type sx,
+    typename call_traits<Sp>::param_type sp
+):k_(K()),sx_(sx),sp_(sp),
+error_acc_(),time_(static_cast<value_type>(0)){
+    BOOST_ASSERT(size(sx) == size(sp));
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+benchmark_rp<Sx,Sp,K,Ae>::benchmark_rp(const benchmark_rp& that)
+:k_(that.k_),sx_(that.sx_),sp_(that.sp_),
+error_acc_(that.error_acc_),time_(that.time_){}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+benchmark_rp<Sx,Sp,K,Ae>& 
+benchmark_rp<Sx,Sp,K,Ae>::operator=(const benchmark_rp& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_sx_>));
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_sp_>));
+        k_ = (that.k_);
+        sx_ = (that.sx_);
+        sp_ = (that.sp_);
+        error_acc_ = (that.error_acc_);
+        time_ = (that.time_);    
+    }
+    return (*this);
+}
+    
+template<typename Sx,typename Sp, typename K,typename Ae>
+void benchmark_rp<Sx,Sp,K,Ae>::set_kernel(K k){
+    k_ = k;
+}
+
+// Update
+template<typename Sx,typename Sp, typename K,typename Ae>
+template<typename Sx1>
+void benchmark_rp<Sx,Sp,K,Ae>::operator()(const Sx1& data){
+    typedef const Sx1& call_;
+    typedef estimator<call_,rp_visitor,K,acc_> estimator_type;
+    timer t;
+    estimator_type estimator(data,this->kernel());
+    typedef typename range_value<Sx1>::type unit_;
+    typedef typename range_iterator<const_sp_>::type iter_y_;
+    
+    iter_y_ i = boost::begin(sp_);
+    BOOST_FOREACH(const unit_& u, sx_){
+        value_type a =  estimator(u).estimate();
+        value_type b = (*i);
+        error_acc_(fabs(a-b));
+        ++i;
+    }
+    n_ = boost::size(data);
+    time_ = t.elapsed();
+}
+
+// Access
+template<typename Sx,typename Sp, typename K,typename Ae>
+const K& benchmark_rp<Sx,Sp,K,Ae>::kernel()const{
+    return (this->k_);
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+const Ae& benchmark_rp<Sx,Sp,K,Ae>::error_accumulator()const{
+    return (this->error_acc_);
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+typename benchmark_rp<Sx,Sp,K,Ae>::value_type 
+benchmark_rp<Sx,Sp,K,Ae>::error()const{
+    return accumulators::mean(this->error_acc_);
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+unsigned benchmark_rp<Sx,Sp,K,Ae>::n()const{
+    return (this->n_);
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+unsigned benchmark_rp<Sx,Sp,K,Ae>::m()const{
+    return accumulators::count(this->error_acc_);
+}
+
+template<typename Sx,typename Sp, typename K,typename Ae>
+typename benchmark_rp<Sx,Sp,K,Ae>::value_type 
+benchmark_rp<Sx,Sp,K,Ae>::time()const{
+    return (this->time_);
+}
+    
+}// kernel
+}// boost
+
+#endif
Added: sandbox/statistics/kernel/boost/kernel/functional/detail/mean_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/detail/mean_accumulator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::detail::mean_accumulator.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_KERNEL_FUNCTIONAL_DETAIL_MEAN_ACCUMULATOR_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_DETAIL_MEAN_ACCUMULATOR_H_ER_2009
+#include <boost/accumulators/accumulators.hpp>
+#include <boost/accumulators/statistics/stats.hpp>
+#include <boost/accumulators/statistics/mean.hpp>
+
+namespace boost{
+namespace kernel{
+namespace detail{
+
+    // The Rosenblatt-Parzen estimator is a density estimator
+    template<typename T>
+    struct mean_accumulator{
+        typedef accumulators::stats<
+            accumulators::tag::mean
+        >  stat_;
+        typedef accumulators::accumulator_set<T,stat_> type;
+    };
+        
+}// detail
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/functional/detail/return_if.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/detail/return_if.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,35 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::detail::return_if.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_KERNEL_FUNCTIONAL_DETAIL_RETURN_IF_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_DETAIL_RETURN_IF_H_ER_2009
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+
+namespace boost{
+namespace kernel{
+namespace detail{
+
+// TODO no longer needed
+
+template<typename X1,typename R>
+struct return_if_scalar : boost::enable_if<
+    boost::is_scalar<X1>,
+    R     
+>{};
+
+template<typename X1,typename R>
+struct return_if_multi : boost::disable_if<
+    boost::is_scalar<X1>,
+    R     
+>{};
+
+}
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/functional/estimator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/estimator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,186 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::rp_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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_KERNEL_FUNCTIONAL_DENSITY_VISITOR_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_DENSITY_VISITOR_H_ER_2009
+#include <algorithm>
+#include <boost/call_traits.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/type_traits/is_reference.hpp>
+
+#include <boost/mpl/nested_type.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+
+namespace boost{
+namespace kernel{
+
+// S:   sequence of training points 
+// V:   visitor
+// K:   kernel
+// A:   accumulator
+//
+// V                        S
+// rp_visitor               {x[i]:i=1,...,n}
+// nw_visitor_tuple         {(x,y)[i]:i=1,...,n}
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A = typename 
+        kernel::detail::mean_accumulator<typename K::result_type>::type 
+>
+class estimator{
+    typedef boost::is_reference<S> is_ref_;
+    
+    public:
+    typedef S data_type;
+    typedef K kernel_type;
+    typedef A accumulator_type;
+
+    template<typename X>
+    struct result{
+        // Passing X by ref is highly recommended if it is a range,
+        // and it won't hurt if X is a scalar
+        typedef V<K,const X&,A> arg_;
+        typedef typename mpl::nested_type<arg_>::type type;
+    };
+    
+    // Constructor
+    estimator();
+    estimator(typename call_traits<S>::param_type data,K k);
+    estimator(typename call_traits<S>::param_type data,K k,const A&);
+    estimator(const estimator&);
+    estimator& operator=(const estimator&);
+    
+    // Evaluate
+    template<typename X>
+    typename result<X>::type  operator()(const X& x)const;    
+
+    // Access
+    typename call_traits<S>::const_reference data()const;
+    const K& kernel()const;
+    const A& accumulator()const;
+
+private:
+    typename call_traits<S>::value_type data_;
+    K k_;
+    A a_; // Serves and stays as an initialized accumulator
+};
+
+// Constructor
+
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+estimator<S,V,K,A>::estimator():data_(),k_(),a_(){
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_>));
+}
+
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+estimator<S,V,K,A>::estimator(typename call_traits<S>::param_type data,K k)
+:data_(data),k_(k),a_(){}
+
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+estimator<S,V,K,A>::estimator(
+    typename call_traits<S>::param_type data,
+    K k,
+    const A& a
+)
+:data_(data),k_(k),a_(a){}
+    
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+estimator<S,V,K,A>::estimator(const estimator& that)
+:data_(that.data_),k_(that.k_),a_(that.a_){}
+    
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+estimator<S,V,K,A>& 
+estimator<S,V,K,A>::operator=(const estimator& that){
+    if(&that=this){
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_>));
+        data_ = that.data_;
+        k_ = that.k_;
+        a_ = that.a_;
+    }
+    return *this;
+}
+
+// Evaluate
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+    template<typename X>
+typename estimator<S,V,K,A>::template result<X>::type 
+estimator<S,V,K,A>::operator()(const X& x)const{
+    typedef typename estimator<S,V,K,A>::template result<X>::type result_;
+    return std::for_each(
+        begin(data()),
+        end(data()),
+        result_(kernel(),x,a_)
+    );
+}
+
+// Access
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+typename call_traits<S>::const_reference 
+estimator<S,V,K,A>::data()const{ return data_; }
+
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+const K& estimator<S,V,K,A>::kernel()const{ return k_; }
+    
+template<
+    typename S, 
+    template<typename,typename,typename> class V,
+    typename K,
+    typename A
+>
+const A&
+estimator<S,V,K,A>::accumulator()const{
+    return a_;
+}
+    
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/functional/nw_visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/nw_visitor.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,140 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::nw_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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_KERNEL_FUNCTIONAL_NW_VISITOR_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_NW_VISITOR_H_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+#include <boost/kernel/functional/rp_visitor.hpp>
+
+namespace boost{
+namespace kernel{
+   
+// Let E[Y|X=x] denote the conditional mean of Y given X = x
+//
+// This class is to be used to visit the training data, to obtain an estimator,
+// by the Nadaraya-Watson method, of E[Y|X=x]
+template<
+    typename K,
+    typename X,
+    typename A = typename 
+        kernel::detail::mean_accumulator<typename K::result_type>::type 
+>
+class nw_visitor{
+    public:
+    typedef rp_visitor<K,X,A> rp_visitor_type;
+    typedef typename rp_visitor_type::result_type result_type;
+    typedef K kernel_type;
+    typedef A accumulator_type;
+        
+    //Construct
+    nw_visitor();
+    nw_visitor(typename call_traits<X>::param_type);
+    nw_visitor(
+        K k, // passing radius should call implicit conversion
+        typename call_traits<X>::param_type x  
+    );
+    nw_visitor(
+        K k,
+        typename call_traits<X>::param_type,
+        const accumulator_type&
+    );
+    nw_visitor(const nw_visitor&);
+    nw_visitor& operator=(const nw_visitor&);
+        
+    // Update
+    template<typename X1,typename Y1> // Training data point
+    result_type operator()(const X1& x1,const Y1& y1);
+        
+    // Access
+    result_type unnormalized_estimate()const;
+    result_type normalizing_constant()const;
+    result_type estimate()const; 
+
+    const A& accumulator()const;
+    const rp_visitor_type& rp_visitor()const;
+        
+    private:
+    rp_visitor_type rp_visitor_;
+    A a_;
+};
+    
+//Construction
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor():rp_visitor_(),a_(){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(K k,typename call_traits<X>::param_type x)
+:rp_visitor_(k,x),a_(){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(
+    K k,typename call_traits<X>::param_type x,const A& a
+):rp_visitor_(k,x,a),a_(a){}
+    
+template<typename K,typename X,typename A>
+nw_visitor<K,X,A>::nw_visitor(const nw_visitor& that)
+:rp_visitor_(that.rp_visitor_),a_(that.a_){}
+    
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::nw_visitor& 
+nw_visitor<K,X,A>::operator=(const nw_visitor& that){
+    if(&that!=this){
+        rp_visitor_ = that.rp_visitor_;
+        a_ = that.a_;
+    }   
+    return *this;
+}
+    
+// Update
+template<typename K,typename X,typename A>
+template<typename X1,typename Y1>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::operator()(const X1& x1,const Y1& y){
+    result_type w = (this->rp_visitor_(x1));
+    result_type wy = w * y; 
+    this->a_(wy);
+    return wy;
+}
+
+// Access
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::unnormalized_estimate()const{
+    return accumulators::mean(
+        this->accumulator()
+    );
+}
+
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::normalizing_constant()const{
+    return (this->rp_visitor_).estimate();
+}
+    
+template<typename K,typename X,typename A>
+typename nw_visitor<K,X,A>::result_type
+nw_visitor<K,X,A>::estimate()const{
+    return (this->unnormalized_estimate()/this->normalizing_constant());
+}
+    
+template<typename K,typename X,typename A>
+const A& nw_visitor<K,X,A>::accumulator()const{ return  this->a_; }
+        
+template<typename K,typename X,typename A>
+const rp_visitor<K,X,A>& 
+nw_visitor<K,X,A>::rp_visitor()const{
+    return (this->rp_visitor_);
+}
+    
+    
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/functional/nw_visitor_tuple.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/nw_visitor_tuple.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::nw_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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_KERNEL_FUNCTIONAL_TUPLE_NW_VISITOR_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_TUPLE_NW_VISITOR_H_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/binary_op/functional/untupler.hpp>
+#include <boost/binary_op/data/tuple_range.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+#include <boost/kernel/functional/nw_visitor.hpp>
+
+namespace boost{
+namespace kernel{
+
+// This functor (f) is like nw_visitor, but rather than f(x,y),
+// the appropriate call is f(t), where t=(x,y) is a tuple. 
+template<typename K,typename X, typename A = typename 
+        kernel::detail::mean_accumulator<typename K::result_type>::type >
+class nw_visitor_tuple 
+    : public binary_op::untupler<nw_visitor<K,X,A>,0,1>{
+    typedef nw_visitor<K,X,A> binary_;
+    typedef binary_op::untupler<binary_,0,1> super_t;
+
+    public:
+    typedef binary_ nw_visitor_type;
+    typedef typename binary_::rp_visitor_type rp_visitor_type;
+    typedef typename super_t::result_type result_type;
+
+    // Construction
+    nw_visitor_tuple(
+        K k,
+        typename call_traits<X>::param_type
+    );
+    nw_visitor_tuple(
+        K k,
+        typename call_traits<X>::param_type,
+        const A&
+    );
+    nw_visitor_tuple(const nw_visitor_tuple&);
+    nw_visitor_tuple& operator=(const nw_visitor_tuple&);
+
+    // Access
+    rp_visitor_type rp_visitor()const;
+    nw_visitor_type nw_visitor()const;
+    result_type rp_estimate()const;
+    result_type nw_estimate()const;
+    result_type estimate()const; //same as nw_estimate
+
+    private:
+    nw_visitor_tuple();
+};
+
+// Construction
+template<typename K,typename X,typename A>
+nw_visitor_tuple<K,X,A>::nw_visitor_tuple(
+    K k,
+    typename call_traits<X>::param_type x
+):super_t(binary_(k,x)){}
+
+    template<typename K,typename X,typename A>
+nw_visitor_tuple<K,X,A>::nw_visitor_tuple(
+    K k,
+    typename call_traits<X>::param_type x,
+    const A& a
+):super_t(binary_(k,x,a)){}
+
+
+template<typename K,typename X,typename A>
+nw_visitor_tuple<K,X,A>::nw_visitor_tuple(const nw_visitor_tuple& that)
+:super_t(static_cast<const super_t&>(that)){}
+
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::nw_visitor_tuple& 
+nw_visitor_tuple<K,X,A>::nw_visitor_tuple::operator=(
+    const nw_visitor_tuple& that
+){
+    if(&that!=this){
+        super_t::operator=(that);
+    }
+    return *this;
+}
+
+// Access
+
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::nw_visitor_type
+nw_visitor_tuple<K,X,A>::nw_visitor()const{
+    return this->base();
+}
+
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::rp_visitor_type 
+nw_visitor_tuple<K,X,A>::rp_visitor()const{
+    return (this->nw_visitor()).rp_visitor();
+}
+
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::result_type 
+nw_visitor_tuple<K,X,A>::rp_estimate()const{
+    return (this->rp_visitor()).estimate();
+}
+
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::result_type 
+nw_visitor_tuple<K,X,A>::nw_estimate()const{
+    return (this->nw_visitor()).estimate();
+}
+    
+template<typename K,typename X,typename A>
+typename nw_visitor_tuple<K,X,A>::result_type 
+nw_visitor_tuple<K,X,A>::estimate()const{
+    return (this->nw_estimate());
+}
+    
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/functional/rp_visitor.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/functional/rp_visitor.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,147 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::functional::rp_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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_KERNEL_FUNCTIONAL_RP_VISITOR_H_ER_2009
+#define BOOST_KERNEL_FUNCTIONAL_RP_VISITOR_H_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/kernel/functional/detail/mean_accumulator.hpp>
+//#include <boost/kernel/functional/detail/return_if.hpp>
+//#include <boost/kernel/functional/detail/range_difference.hpp>
+
+namespace boost{
+namespace kernel{
+
+// Let p(x) denote the density of X = x
+//
+// This class is to be used to visit the training data, to obtain an estimator,
+// by the Rosenblatt-Parzen method, of p(x)
+template<
+    typename K,
+    typename X,
+    typename A = typename 
+        kernel::detail::mean_accumulator<typename K::result_type>::type 
+>
+class rp_visitor : K{ //, addable<rp_visitor<K,X,A> >{ // 
+    typedef is_reference<X> is_ref_;
+    public:
+    typedef K kernel_type;
+    typedef A accumulator_type;
+    typedef typename K::result_type result_type;
+
+    // Construct
+    rp_visitor();
+    rp_visitor(typename call_traits<X>::param_type);
+    rp_visitor(
+        K k, // passing radius calls implicit conversion
+        typename call_traits<X>::param_type x
+    );
+    rp_visitor(
+        K k,
+        typename call_traits<X>::param_type,
+        const accumulator_type&
+    );
+    rp_visitor(const rp_visitor&);
+    rp_visitor& operator=(const rp_visitor&);
+    
+    // Update
+    // Passing the training data x1 updates the estimator
+    template<typename X1> result_type operator()(const X1& x1);
+    
+    // Access
+    typename call_traits<X>::const_reference x()const;
+    const A& accumulator()const;
+    const result_type& normalizing_constant()const;
+
+    result_type estimate()const; 
+
+    private:
+    typename call_traits<X>::value_type x_;
+    A acc_;
+};
+
+//Construction
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(){
+    BOOST_MPL_ASSERT((
+        mpl::not_<is_ref_>
+    ));
+}
+
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(K k,typename call_traits<X>::param_type x)
+:K(k),x_(x),acc_(){}
+    
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(
+    K k,
+    typename call_traits<X>::param_type x,
+    const A& a
+):K(k),x_(x),acc_(a){}
+
+template<typename K,typename X,typename A>
+rp_visitor<K,X,A>::rp_visitor(const rp_visitor& that)
+:K(static_cast<const K&>(that)),x_(that.x_),acc_(that.acc_){}
+
+template<typename K,typename X,typename A>
+typename rp_visitor<K,X,A>::rp_visitor& 
+rp_visitor<K,X,A>::operator=(const rp_visitor& that){
+    if(&that!=this){
+        BOOST_MPL_ASSERT((mpl::not_<is_ref_>));
+        K::operator=(static_cast<const K&>(*that)); 
+        x_ = that.x_;
+        acc_ = that.acc_;
+    }   
+    return *this;
+}
+
+// Evaluate
+template<typename K,typename X,typename A>
+template<typename X1>
+typename rp_visitor<K,X,A>::result_type
+rp_visitor<K,X,A>::operator()(const X1& x1){
+    const K& kernel = static_cast<const K&>(*this);
+    result_type t = kernel(x(),x1);
+    this->acc_(t);
+    return t;
+}
+
+
+// Access
+template<typename K,typename X,typename A>
+typename rp_visitor<K,X,A>::result_type
+rp_visitor<K,X,A>::estimate()const{
+    return accumulators::mean(
+        this->accumulator()
+    );
+}
+
+template<typename K,typename X,typename A>
+const A&
+rp_visitor<K,X,A>::accumulator()const{
+    return  this->acc_;
+}
+    
+template<typename K,typename X,typename A>
+const typename rp_visitor<K,X,A>::result_type&
+rp_visitor<K,X,A>::normalizing_constant()const{
+    const K& k = static_cast<const K&>(*this);
+    return k.normalizing_constant();
+}
+
+template<typename K,typename X,typename A>
+typename call_traits<X>::const_reference
+rp_visitor<K,X,A>::x()const{
+    return this->x_;
+}
+    
+
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/kernel/crtp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/kernel/crtp.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,21 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::crtp.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_KERNEL_KERNEL_CRTP_H_ER_2009
+#define BOOST_KERNEL_KERNEL_CRTP_H_ER_2009
+
+namespace boost{
+namespace kernel{
+
+    // This has no purpose other signifying that the derived class is 
+    // a kernel, and it is currently not in use, but this may change. 
+    template<typename D> struct crtp{};
+
+}
+}
+
+#endif
Added: sandbox/statistics/kernel/boost/kernel/kernel/multi.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/kernel/multi.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,122 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::multi.hpp                                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICEMSE_1_0.txt or copy at http://www.boost.org/LICEMSE_1_0.txt)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef BOOST_KERNEL_KERNEL_MULTI_H_ER_2009
+#define BOOST_KERNEL_KERNEL_MULTI_H_ER_2009
+#include <cmath>
+#include <numeric>
+#include <boost/lambda/lambda.hpp>
+#include <boost/vector_space/data/lazy_difference.hpp>
+#include <boost/kernel/kernel/crtp.hpp>
+
+namespace boost{
+namespace kernel{
+
+// Overview: Multivariate kernel, common bandwidth across coordinates.
+//
+// Notation: Let x denote a vector of size M,
+//
+// Usage:
+// typedef multi<scalar::gaussian<T>,M> mult_;
+// typedef mult_::result_type result_;
+// mult_ mult(bandwidth);
+// result_ r = mult(x);
+template<typename K,unsigned M>
+class multi : K{
+    public:
+    typedef typename K::result_type result_type;
+
+    //Construction
+    multi();
+    template<typename K1> multi(K1 k1); //pass bandwith, or kernel
+    
+    // Evaluate
+    template<typename X> result_type profile(const X& x)const;    
+    template<typename X> result_type operator()(const X& x)const;    
+    template<typename X,typename X1> 
+    result_type operator()(const X& x,const X1& x1)const;
+    
+    // Access
+    static unsigned dimension;
+    result_type radius()const;
+    result_type normalizing_constant()const;
+    
+    private:
+    result_type normalizing_constant_; //no ambiguity because inherit K privately
+    result_type comp_nc()const; 
+};
+
+// Construction
+template<typename K,unsigned M> 
+multi<K,M>::multi():K(),normalizing_constant_(comp_nc()){}
+
+template<typename K,unsigned M> 
+template<typename K1>
+multi<K,M>::multi(K1 k1):K(k1),normalizing_constant_(comp_nc()){}
+        
+// Evaluate
+template<typename K,unsigned M> 
+template<typename X> 
+typename multi<K,M>::result_type 
+multi<K,M>::profile(const X& x)const{
+    static result_type init = static_cast<result_type>(0);
+    const K& k = static_cast<const K&>(*this);
+    result_type norm = std::accumulate(
+        boost::begin(x),
+        boost::end(x),
+        init,
+        ( lambda::_1 + (lambda::_2 * lambda::_2 ) )
+    );   
+    norm = std::sqrt(norm);
+    return k.profile(norm);
+}
+
+template<typename K,unsigned M> 
+template<typename X> 
+typename multi<K,M>::result_type 
+multi<K,M>::operator()(const X& x)const{
+    return this->profile(x) / this->normalizing_constant();
+}
+
+template<typename K,unsigned M> 
+template<typename X,typename X1> 
+typename multi<K,M>::result_type 
+multi<K,M>::operator()(const X& x,const X1& x1)const{
+    typedef vector_space::lazy_difference<X,X1> diff_;
+    typedef typename range_size<X>::type size_type;
+    BOOST_ASSERT(size(x) == static_cast<size_type>(size(x1)));
+    BOOST_ASSERT(size(x) == static_cast<size_type>(M));
+    diff_ diff(x,x1);
+    return (*this)(diff);
+}
+        
+// Access
+template<typename K,unsigned M> unsigned multi<K,M>::dimension = M;
+
+template<typename K,unsigned M>
+typename multi<K,M>::result_type 
+multi<K,M>::radius()const{ 
+    const K& k = static_cast<const K&>(*this);
+    return k.radius();
+}
+
+template<typename K,unsigned M>
+typename multi<K,M>::result_type 
+multi<K,M>::normalizing_constant()const{ return normalizing_constant_; }
+    
+template<typename K,unsigned M>
+typename multi<K,M>::result_type 
+multi<K,M>::comp_nc()const{
+    const K& k = static_cast<const K&>(*this);
+    static result_type m = static_cast<result_type>(M);
+    result_type nc = k.normalizing_constant();
+    return std::pow(nc,m);
+}
+        
+}// kernel
+}// boost   
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/kernel/scalar/crtp.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/kernel/scalar/crtp.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,114 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::scalar::crtp.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_KERNEL_SCALAR_CRTP_H_ER_2009
+#define BOOST_KERNEL_SCALAR_CRTP_H_ER_2009
+#include <boost/format.hpp>
+
+namespace boost{
+namespace kernel{
+namespace scalar{
+
+// Overview: provides common operations for a kernel whose implementation
+// is specified by a derived class, D.
+//
+// Let d note an instance of D, and T == D::result_type
+//
+// Requirements
+// crtp<D,T> is a base of D
+// D::result_type is defined
+// D::core_profile(const T&)        returns an object of type T
+// D::core_nc                       returns an object of type T (normalzing c)
+// D d;                             Constructor Forwards to crtp<D,T>
+// D d(r)                           Constructor Forwards to crtp<D,T>
+template<typename D,typename T> 
+class crtp{
+    public:
+    typedef T result_type;
+
+    // Construction
+    crtp();
+    crtp(const result_type& bandwidth);
+    
+    // Evaluate
+    template<typename X> result_type profile(const X& x)const;
+    template<typename X> result_type operator()(const X& x)const;
+    template<typename X,typename X1> 
+    result_type operator()(const X& x,const X1& x1)const;
+    
+    // Access
+    result_type bandwidth()const;
+    result_type normalizing_constant()const;
+    
+    private:
+    result_type bandwidth_;
+    result_type normalizing_constant_;
+    result_type comp_nc(result_type bandwidth);
+};
+
+template<typename D,typename T>
+std::ostream& operator<<(std::ostream& out,const crtp<D,T>& k){
+    const char* str = "(%1%,%2%)";
+    format f(str); f%k.bandwidth()%k.normalizing_constant();
+    out << f.str();
+    return out; 
+}
+
+// Construction
+template<typename D,typename T> crtp<D,T>::crtp()
+:bandwidth_(static_cast<result_type>(1)),
+normalizing_constant_(this->comp_nc(bandwidth())){}
+
+template<typename D,typename T> crtp<D,T>::crtp(const result_type& bandwidth)
+:bandwidth_(bandwidth),
+normalizing_constant_(this->comp_nc(this->bandwidth())){}
+
+
+// Evaluate
+template<typename D,typename T>    
+template<typename X>
+typename crtp<D,T>::result_type 
+crtp<D,T>::profile(const X& x)const{
+    result_type u = x / this->bandwidth();
+    return D::core_profile(u);
+} 
+
+template<typename D,typename T>    
+template<typename X>
+typename crtp<D,T>::result_type 
+crtp<D,T>::operator()(const X& x)const{
+    return ( this->profile(x) ) / ( this->normalizing_constant()) ;
+} 
+
+template<typename D,typename T>
+template<typename X,typename X1> 
+typename crtp<D,T>::result_type 
+crtp<D,T>::operator()(const X& x,const X1& x1)const{
+    return (*this)(x-x1);
+}
+  
+// Access
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::bandwidth()const{ 
+    return this->bandwidth_; 
+}
+
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::normalizing_constant()const{ 
+    return this->normalizing_constant_; 
+}
+
+// Implem
+template<typename D,typename T>    
+typename crtp<D,T>::result_type crtp<D,T>::comp_nc(result_type bandwidth){ 
+    return D::core_nc * bandwidth;  
+}
+
+}// scalar
+}// kernel
+}// boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/boost/kernel/kernel/scalar/gaussian.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/boost/kernel/kernel/scalar/gaussian.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,51 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::scalar::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_KERNEL_SCALAR_GAUSSIAN_H_ER_2009
+#define BOOST_KERNEL_SCALAR_GAUSSIAN_H_ER_2009
+#include <cmath>
+#include <boost/kernel/kernel/scalar/crtp.hpp>
+#include <boost/math/constants/constants.hpp>
+
+namespace boost{
+namespace kernel{
+namespace scalar{
+
+template<typename T>
+struct gaussian : scalar::crtp<gaussian<T>,T >{ 
+    typedef gaussian<T> this_type;
+    typedef scalar::crtp<this_type,T> crtp_;
+    public:
+    typedef typename crtp_::result_type result_type;
+    
+    gaussian();
+    gaussian(const result_type& bandwidth);
+    
+    static result_type core_profile(const result_type& x);
+    static result_type core_nc;
+};
+
+template<typename T>  gaussian<T>::gaussian():crtp_(){}
+template<typename T> gaussian<T>::gaussian(const result_type& bandwidth)
+:crtp_(bandwidth){}
+    
+template<typename T>
+typename gaussian<T>::result_type
+gaussian<T>::core_profile(const result_type& x){
+    static result_type two = static_cast<T>(2);
+    return exp(- x * x / two);
+}
+    
+template<typename T>
+typename gaussian<T>::result_type
+gaussian<T>::core_nc = math::constants::root_two_pi<T>();
+
+}// scalar
+}// kernel
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,145 @@
+//////////////////////////////////////////////////////////////////////////////
+// kernel::doc::readme                                                      //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ classes for kernel based density estimation and conditional mean 
+estimation by the method of Rosenblatt-Parzen and Nadaraya-Watson, respectively.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+/sandbox/statistics/vector_space/ 
+/sandbox/statistics/binary_op/ 
+/sandbox/statistics/arithmetic/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/mpl/ 
+/sandbox/statistics/standard_distribution/ 
+/sandbox/statistics/kernel/
+
+[ Sources ]
+
+http://en.wikipedia.org/wiki/Kernel_(statistics)
+http://en.wikipedia.org/wiki/Kernel_density_estimation
+@book{citeulike:300228,
+	author = {Silverman, B. W.},
+	howpublished = {Hardcover},
+	isbn = {0412246201},
+	keywords = {density-estimation},
+	month = {April},
+	posted-at = {2008-01-13 17:43:25},
+	priority = {2},
+	publisher = {{Chapman \& Hall/CRC}},
+	title = {Density Estimation for Statistics and Data Analysis},
+	year = {1986}
+}
+
+[ History ]
+
+July 2009 : Current version
+March 2009: improved_fast_gauss_transform is now deprecated
+
+[Design]
+
+Let h denote bandwidth, d dimension, ||.|| norm. 
+
+To perform density or conditional mean estimation, we are interested in 
+operations that involve an abitrary bandwidth binary kernel, K[h](x0,x1), 
+and/or possibly its multivariate extension  K[d,h](x0,x1). 
+
+Our design rests on the following relationships (see [Math representation])
+ - standardized kernel (bandwidth = 1) and kernels indexed by a bandwidth
+ - unary kernels, K(x), and binary kernels, K(x0,x1)
+ - univariate and multivariate kernels.
+
+The client need only specify the standardized kernel, such as 
+scalar::gaussian, while a crtp mechanism, implemented in scalar::crtp,  
+adds the remaining functionality. 
+
+The class template kernel::multi, parameterized by an arbitrary unavariate 
+kernel provides a multivariate analogue to the latter.
+
+The classes rp_visitor and nw_visitor are implementations for the Rosenblatt-
+Parzen and Nadaraya-Watson estimators for a given test value, x. 
+
+Iterating either of the above estimators over a training sample is implemented
+by kernel::estimator, which, in turn, can be used in a std::for_each construct 
+to iterate over test data. 
+
+Bandwidth selection for density estimation is provided by 
+bandwith::normal_distribution.
+
+[TODO]
+
+- Bandwidth selection by cross validation and other methods.
+- Provide a IFGT version of the above (see our deprecated 
+improved_fast_gauss_transform package)
+- Kernel regression etc.
+
+[Math representation]
+
+Univariate
+    Unary:
+        Unnormalized:   Ku(x)   :   [0,inf)   ->  [0,inf)
+        Normalized:     K(x)    :   [0,inf)   ->  [0,1)
+            K(x)  =  Ku(x) / c such that integral K(x) dx = 1
+        Parameterized   
+        by bandwidth    K[h](x) =   K(x/h) / h
+
+    e.g. 
+    Ku(x)   :   exp(-x^2/2) 
+    c       :   sqrt(2 pi)
+    K(x)    :   exp(-x^2/2) / sqrt(2 pi)
+    K[h](x) :   exp(-(x/h)^2 /2) / ( sqrt(2 pi) * h)
+
+Binary:
+    K(x0,x1) = K(|x0-x1|)
+
+Multivariate:
+    Ku[d](x)    :       Ku(||x||)
+    
+    e.g
+    Ku[d](x)    :       exp(-||x||^2)       :   Ku(||x||)
+    c[d]        :       (sqrt(2 pi))^d      :   c^d
+    K[d](x)     :       Ku[d](x)/c[d]   
+    
+    K[d,h](x)   :       exp(-||x/h||^2)/(c * h)^d       
+                        = Ku(||x||/h) / (c * h)^d
+
+[Output]
+
+Here's a copy of the output from libs/src/main.cpp:
+
+-> example_scalar_rp : 0.256009 0.390986 0.229151 0.261866 0.232843 0.228334 
+0.185519 0.382394 0.388576 0.383203 <-
+-> example_scalar_nw : <-
+-> example_multi_rp : <-
+-> example_benchmark_scalar : m = 10000
+rp : (n, avg_t,e)nw : (n, avg_t,e_p,e_y)
+rp : (2, 4.0672e-06, 0.173297) nw : (2, 8.3822e-06, 0.173297, 1.2265)
+rp : (4, 2.859e-06, 0.138165) nw : (4, 5.86085e-06, 0.138165, 1.06847)
+rp : (8, 3.01747e-06, 0.104602) nw : (8, 6.289e-06, 0.104602, 0.831601)
+rp : (16, 3.96233e-06, 0.0978568) nw : (16, 8.16075e-06, 0.0978568, 0.702637)
+rp : (32, 5.94066e-06, 0.0818718) nw : (32, 1.20646e-05, 0.0818718, 0.595622)
+rp : (64, 9.40283e-06, 0.0719671) nw : (64, 1.95258e-05, 0.0719671, 0.531848)
+rp : (128, 1.57752e-05, 0.0634377) nw : (128, 3.26977e-05, 0.0634377, 0.477009)
+rp : (256, 2.72618e-05, 0.0565864) nw : (256, 5.64065e-05, 0.0565864, 0.432414)
+rp : (512, 4.81542e-05, 0.0511678) nw : (512, 0.00010056, 0.0511678, 0.398781)
+rp : (1024, 8.67954e-05, 0.0469132) nw : (1024, 0.000179972, 0.0469132, 0.371483)
+<-
+
+
Added: sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,139 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::benchmark_scalar.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 <cmath>
+#include <algorithm>
+#include <iterator>
+#include <boost/function.hpp>
+#include <boost/range.hpp>
+#include <boost/foreach.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //needed?
+#include <boost/math/tools/precision.hpp>
+
+// Order of the files matters!
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/scalar_dist/fun_wrap/pdf.hpp>
+#include <boost/scalar_dist/meta/delegate.hpp>
+#include <boost/scalar_dist/algorithm/transform.hpp>
+
+#include <boost/binary_op/data/tuple_range.hpp>
+#include <boost/kernel/bandwidth/normal_distribution.hpp>
+#include <boost/kernel/kernel/scalar/gaussian.hpp>
+#include <boost/kernel/functional/benchmark_rp.hpp>
+#include <boost/kernel/functional/benchmark_nw.hpp>
+#include <boost/kernel/functional/nw_visitor_tuple.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+#include <libs/kernel/example/benchmark_scalar.h>
+
+void example_benchmark_scalar(std::ostream& out){
+    out << "-> example_benchmark_scalar : ";
+
+    using namespace boost;
+
+    // Types
+    typedef double                                          val_;
+    typedef function<val_(const val_&)>                     y_delegate_;
+    typedef std::vector<val_>                               vec_;
+    typedef mt19937                                         urng_;
+    typedef normal_distribution<val_>                       rnorm_;
+    typedef variate_generator<urng_&,rnorm_>                gen_;
+    typedef kernel::scalar::gaussian<val_>                  gauss_k_;
+    typedef kernel::rp_visitor<gauss_k_,val_>               rp_visitor_;
+    typedef math::normal_distribution<val_>                 mnorm_;
+    typedef math::delegate<mnorm_>                          meta_delegate_;
+
+    typedef const vec_& call_vec_;
+    typedef kernel::benchmark_rp<call_vec_,call_vec_,gauss_k_> bench_rp_;
+    typedef kernel::benchmark_nw<call_vec_,call_vec_,call_vec_,gauss_k_> 
+        bench_nw_;
+    
+    // Constants
+    const val_ bandwidth = 0.5;
+    const val_ eps = math::tools::epsilon<val_>();
+    const unsigned dim = 1;
+    typedef kernel::normal_distribution<dim,val_> opt_;
+
+    const unsigned n_loops = 10;
+    const unsigned n_in_factor = 2; 
+    unsigned n_in = 2;
+    const unsigned n_out = 1e4;
+    const val_ mu = 0.0;
+    const val_ sigma = 2.0;
+
+    // Initialization
+    y_delegate_ y_delegate = fabs;
+        
+    vec_ vec_x_out(n_out);
+    vec_ vec_y_out(n_out);
+    vec_ vec_pdf_out(n_out);
+        urng_ urng;
+        rnorm_ rnorm(mu,sigma);
+        gen_ gen(urng,rnorm);
+    {
+
+        std::generate_n(begin(vec_x_out),n_out,gen);
+
+        mnorm_ mnorm(mu,sigma); 
+        meta_delegate_::type mnorm_delegate
+            = meta_delegate_::make<math::fun_wrap::pdf_>();
+
+        math::transform<math::fun_wrap::pdf_>(
+            mnorm,
+            begin(vec_x_out),
+            end(vec_x_out),
+            begin(vec_pdf_out)
+        );
+        std::transform(
+            boost::begin(vec_x_out),
+            boost::end(vec_x_out),
+            boost::begin(vec_y_out),
+            y_delegate
+        );
+    }
+
+    vec_ vec_x_in;     
+    vec_ vec_y_in;     
+
+    // Computations
+    
+    bench_rp_ bench_rp(vec_x_out,vec_pdf_out,gauss_k_(bandwidth));
+    bench_nw_ bench_nw(vec_x_out,vec_pdf_out,vec_y_out,gauss_k_(bandwidth));
+    out << "m = " << n_out << std::endl;
+    out << "rp : " << bench_rp.header;
+    out << "nw : " << bench_nw.header << std::endl;
+    for(unsigned i = 0; i<n_loops; i++){
+        vec_x_in.clear();
+        vec_x_in.reserve(n_in);
+        opt_::rp_bandwidth(sigma, n_in);
+        std::generate_n( std::back_inserter(vec_x_in), n_in, gen);
+        bench_rp(vec_x_in);
+        
+        vec_y_in.clear();
+        vec_y_in.reserve(n_in);
+        std::transform(
+            boost::begin(vec_x_in),
+            boost::end(vec_x_in),
+            std::back_inserter(vec_y_in),
+            y_delegate
+        );
+        bench_nw(vec_x_in,vec_y_in);
+
+        out << "rp : " << bench_rp << " nw : " << bench_nw << std::endl;
+                
+        n_in *= n_in_factor;
+    }
+    
+    
+    out << "<-" << std::endl;
+}
+
+
+
Added: sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/benchmark_scalar.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::benchmark_scalar.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_KERNEL_EXAMPLE_BENCHMARK_SCALAR_RP_H_ER_2009
+#define LIBS_KERNEL_EXAMPLE_BENCHMARK_SCALAR_RP_H_ER_2009
+#include <ostream>
+
+void example_benchmark_scalar(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/example/multi_rp.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/multi_rp.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,92 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::multi_rp.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/foreach.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //needed?
+#include <boost/math/tools/precision.hpp>
+
+#include <boost/kernel/kernel/scalar/gaussian.hpp>
+#include <boost/kernel/kernel/multi.hpp>
+#include <boost/kernel/functional/rp_visitor.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+#include <libs/kernel/example/scalar_rp.h>
+
+void example_multi_rp(std::ostream& out){
+    out << "-> example_multi_rp : ";
+    using namespace boost;
+    
+    // Types
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vec_;
+    typedef std::vector<vec_>                               mat_;
+    typedef mt19937                                         urng_;
+    typedef normal_distribution<val_>                       norm_;
+    typedef variate_generator<urng_&,norm_>                 gen_;
+    typedef kernel::scalar::gaussian<val_>                  gauss_k_;
+
+    const unsigned dim = 2;
+    typedef kernel::multi<gauss_k_,dim>                     multi_k_;
+    // NB const vec_&, not vec_
+    typedef kernel::rp_visitor<multi_k_,const vec_&>        rp_visitor_;
+    
+    // Constants
+    const val_ bandwidth = 0.5;
+    const val_ eps = math::tools::epsilon<val_>();
+    const unsigned n = 10;
+    
+    // Generate sample
+    mat_ vec_x; vec_x.reserve(n);
+    vec_ vec_rp; vec_rp.reserve(n);
+    urng_ urng;
+    norm_ norm;
+    gen_ gen(urng,norm);
+    for(unsigned i = 0; i<n; i++){
+        vec_ tmp(dim);
+        std::generate_n(
+            begin(tmp),
+            dim,
+            gen
+        );
+        vec_x.push_back( tmp );
+    }
+
+    multi_k_ multi_k(bandwidth);
+    
+    multi_k(vec_x[0],vec_x[1]);
+    // Density estimate for each x in vec_x using vec_x as the sample
+    BOOST_FOREACH(const vec_& x,vec_x){
+        val_ rp = std::for_each(
+            begin(vec_x),
+            end(vec_x),
+            rp_visitor_(bandwidth,x)
+        ).estimate();
+        vec_rp.push_back(rp);
+    } 
+    typedef kernel::estimator<
+        const mat_&,
+        kernel::rp_visitor,
+        multi_k_
+    > estimator_;
+    estimator_ estimator(vec_x,bandwidth);
+    vec_ vec_rp2; vec_rp2.reserve(n);
+
+    // Same as previous but calls estimator instead of for_each
+    for(unsigned i = 0; i<n; i++){
+        vec_ x = vec_x[i];
+        val_ rp = vec_rp[i];
+        val_ rp2 = estimator(x).estimate();
+        BOOST_ASSERT(fabs(rp-rp2)<eps);
+    } 
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/example/multi_rp.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/multi_rp.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::multi_rp.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_KERNEL_EXAMPLE_MULTI_RP_H_ER_2009
+#define LIBS_KERNEL_EXAMPLE_MULTI_RP_H_ER_2009
+#include <ostream>
+
+void example_multi_rp(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/example/scalar_nw.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/scalar_nw.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,112 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::scalar_nw.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/foreach.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //needed?
+#include <boost/math/tools/precision.hpp>
+#include <boost/typeof/typeof.hpp>
+
+#include <boost/binary_op/data/tuple_range.hpp>
+#include <boost/kernel/kernel/scalar/gaussian.hpp>
+#include <boost/kernel/functional/nw_visitor_tuple.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+#include <libs/kernel/example/scalar_nw.h>
+
+void example_scalar_nw(std::ostream& out){
+    out << "-> example_scalar_nw : ";
+    using namespace boost;
+
+    // Types
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vec_;
+    typedef mt19937                                         urng_;
+    typedef normal_distribution<val_>                       norm_;
+    typedef variate_generator<urng_&,norm_>                 gen_;
+    typedef kernel::scalar::gaussian<val_>                  gauss_k_;
+    typedef kernel::nw_visitor_tuple<gauss_k_,val_>         nw_visitor_tuple_;
+    typedef nw_visitor_tuple_::nw_visitor_type              nw_visitor_;
+    typedef nw_visitor_tuple_::rp_visitor_type              rp_visitor_;
+    
+    // Constants
+    const val_ bandwidth = 0.5;
+    const val_ eps = math::tools::epsilon<val_>();
+    const unsigned n = 10;
+    
+    // Initialization
+    vec_ vec_x(n);
+    vec_ vec_y(n,static_cast<val_>(1)); 
+    vec_ vec_rp; vec_rp.reserve(n);
+    vec_ vec_nw; vec_nw.reserve(n);
+    urng_ urng;
+    norm_ norm;
+    gen_ gen(urng,norm);
+    std::generate_n(
+        begin(vec_x),
+        n,
+        gen
+    );
+
+    // Computes a conditional mean estimate (nw) for each x in vec_x using 
+    // a sequence of (x,y) tuples constructed from (vec_x,vec_y) as training
+    // sample. The density (rp) is computed as a by-product. 
+    // Here, y = 1, so we should have rp = nw (un-normalized).
+    BOOST_FOREACH(val_& x,vec_x){
+        typedef binary_op::tuple_range<const vec_&,const vec_&> factory_;
+        typedef factory_::type range_tuple_;
+        range_tuple_ range_tuple = factory_::make(vec_x,vec_y);
+        nw_visitor_ nw_visitor = std::for_each(
+            begin(range_tuple),
+            end(range_tuple),
+            nw_visitor_tuple_(bandwidth,x)
+        ).nw_visitor();
+        val_ u_nw = nw_visitor.unnormalized_estimate();
+        vec_nw.push_back(u_nw);
+        rp_visitor_ rp_visitor = nw_visitor.rp_visitor();
+        val_ rp = rp_visitor.estimate();
+        BOOST_ASSERT(fabs(rp-u_nw)<eps);
+    } 
+
+    typedef binary_op::tuple_range<const vec_&,const vec_&> factory_;
+    typedef factory_::type range_xy_;
+    range_xy_ range_xy = factory_::make(vec_x,vec_y);
+    // A pair of iterators is cheap to copy so no need to pass it by reference
+    typedef kernel::estimator<range_xy_,kernel::nw_visitor_tuple,gauss_k_>
+        estimator_;
+    estimator_ estimator(range_xy,bandwidth);
+    
+    // Same as previous but calls estimator instead of for_each
+    BOOST_FOREACH(val_& x,vec_x){
+        // A local definition of nw_visitor_ is needed because x is passed
+        // by ref, not by value as in that outside the scope
+        typedef estimator_::result<val_>::type result_type;
+        typedef result_type::nw_visitor_type nw_visitor_;
+        typedef result_type::rp_visitor_type rp_visitor_;
+        nw_visitor_ nw_visitor = estimator(x).nw_visitor();
+        val_ u_nw = nw_visitor.unnormalized_estimate();
+        rp_visitor_ rp_visitor = nw_visitor.rp_visitor();
+        val_ rp = rp_visitor.estimate();
+        BOOST_ASSERT(fabs(rp-u_nw)<eps);
+    } 
+    
+    // Shorter version of the above
+    BOOST_FOREACH(val_& x,vec_x){
+        BOOST_AUTO( nw_visitor , estimator(x).nw_visitor() );
+        val_ u_nw = nw_visitor.unnormalized_estimate();
+        BOOST_AUTO( rp_visitor , nw_visitor.rp_visitor() );
+        val_ rp = rp_visitor.estimate();
+        BOOST_ASSERT(fabs(rp-u_nw)<eps);
+    } 
+    
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/example/scalar_nw.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/scalar_nw.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::scalar_nw.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_KERNEL_EXAMPLE_SCALAR_NW_H_ER_2009
+#define LIBS_KERNEL_EXAMPLE_SCALAR_NW_H_ER_2009
+#include <ostream>
+
+void example_scalar_nw(std::ostream&);
+
+#endif
+
Added: sandbox/statistics/kernel/libs/kernel/example/scalar_rp.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/scalar_rp.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,84 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::scalar_rp.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/foreach.hpp>
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //needed?
+#include <boost/math/tools/precision.hpp>
+
+#include <boost/kernel/kernel/scalar/gaussian.hpp>
+#include <boost/kernel/functional/rp_visitor.hpp>
+#include <boost/kernel/functional/estimator.hpp>
+#include <libs/kernel/example/scalar_rp.h>
+
+void example_scalar_rp(std::ostream& out){
+    out << "-> example_scalar_rp : ";
+    using namespace boost;
+
+    //Types
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vec_;
+    typedef mt19937                                         urng_;
+    typedef normal_distribution<val_>                       norm_;
+    typedef variate_generator<urng_&,norm_>                 gen_;
+    typedef kernel::scalar::gaussian<val_>                  gauss_k_;
+    typedef kernel::rp_visitor<gauss_k_,val_>               rp_visitor_;
+
+    // Contants
+    const val_ bandwidth = 0.5;
+    const val_ eps = math::tools::epsilon<val_>();
+    const unsigned n = 10;
+
+    // Initialization
+    vec_ vec_x(n);
+    vec_ vec_rp; vec_rp.reserve(n);
+    urng_ urng;
+    norm_ norm;
+    gen_ gen(urng,norm);
+    std::generate_n(
+        begin(vec_x),
+        n,
+        gen
+    );
+
+    // Computes a density estimate for each x in vec_x using vec_x as sample
+    BOOST_FOREACH(val_& x,vec_x){
+        val_ rp = for_each(
+            begin(vec_x),
+            end(vec_x),
+            rp_visitor_(bandwidth,x)
+        ).estimate();
+        vec_rp.push_back(rp);
+    } 
+
+    std::copy(
+        begin(vec_rp),
+        end(vec_rp),
+        std::ostream_iterator<val_>(out," ")
+    );
+    
+    typedef 
+        kernel::estimator<const vec_&,kernel::rp_visitor,gauss_k_> estimator_;
+    estimator_ estimator(vec_x,bandwidth);
+    vec_ vec_rp2; vec_rp2.reserve(n);
+    
+    // Same as previous but calls estimator instead of for_each
+    for(unsigned i = 0; i<n; i++){
+        val_ x = vec_x[i];
+        val_ rp = vec_rp[i];
+        val_ rp2 = estimator(x).estimate();
+        BOOST_ASSERT(fabs(rp-rp2)<eps);
+    } 
+            
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/kernel/libs/kernel/example/scalar_rp.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/example/scalar_rp.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::example::scalar_rp.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_KERNEL_EXAMPLE_SCALAR_RP_H_ER_2009
+#define LIBS_KERNEL_EXAMPLE_SCALAR_RP_H_ER_2009
+#include <ostream>
+
+void example_scalar_rp(std::ostream&);
+
+#endif
+
Added: sandbox/statistics/kernel/libs/kernel/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/kernel/libs/kernel/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+// kernel::src::main.cpp                                                     //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#include <iostream>
+#include <libs/kernel/example/scalar_rp.h>
+#include <libs/kernel/example/scalar_nw.h>
+#include <libs/kernel/example/multi_rp.h>
+#include <libs/kernel/example/benchmark_scalar.h>
+
+int main(){
+
+    example_scalar_rp(std::cout);
+    example_scalar_nw(std::cout);
+    example_multi_rp(std::cout);
+    example_benchmark_scalar(std::cout);
+    
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/matrix_view/boost/matrix_view/algorithm/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/boost/matrix_view/algorithm/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::src::main.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/matrix_view/example/row_iterator.h>
+#include <libs/matrix_view/example/transform_column.h>
+
+int main(){
+
+    example_row_iterator(std::cout);
+    example_transform_column(std::cout);
+
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/boost/matrix_view/algorithm/transform_column.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,63 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::algorithm::transform_column.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_MATRIX_VIEW_ALGORITHM_TRANSFORM_COLUMN_HPP_ER_2009
+#define BOOST_MATRIX_VIEW_ALGORITHM_TRANSFORM_COLUMN_HPP_ER_2009
+#include <iterator>
+#include <boost/utility.hpp>
+#include <boost/lambda/lambda.hpp>
+
+namespace boost{
+namespace matrix_view{
+
+    // Visits the subsequence defined by a stride and an offset, and transforms
+    // it by f. 
+    //
+    // | b |___|___|___|___|___| ... |___| e | 
+    // | 0 |___|___| 1 |___|___| ... |n-1|___| 
+    //
+    // A k-step iterator + algorithm would be more general, but until then...
+    template<unsigned k,typename F,typename It,typename ItO>
+    ItO transform_column(
+        It b,
+        It e,
+        unsigned offset,
+        F f, 
+        ItO i_o
+    ){
+        typedef typename iterator_difference<It>::type diff_;
+        diff_ d = std::distance(b,e);
+        BOOST_ASSERT(d>=0);
+        if(d<offset){
+            return i_o;
+        }
+        b = next(b,offset);
+        diff_ n = d / k;
+        i_o = f(*b);                         
+        for(unsigned i = 1; i<n; ++i){
+            std::advance(b,k);            
+            i_o = f(*b);
+            ++i_o;
+        }
+        return i_o;
+    }
+
+
+    template<unsigned k,typename It,typename ItO>
+    ItO copy_column(
+        It b,
+        It e,
+        unsigned offset,
+        ItO i_o
+    ){
+        return transform_column<k>(b, e, offset, boost::lambda::_1, i_o);
+    }
+
+}// algorithm
+}// boost
+
+#endif
Added: sandbox/statistics/matrix_view/boost/matrix_view/iterator/row_iterator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/boost/matrix_view/iterator/row_iterator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,113 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::iterator::row_iterator.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_MATRIX_VIEW_ITERATOR_ROW_ITERATOR_HPP_ER_2009
+#define BOOST_MATRIX_VIEW_ITERATOR_ROW_ITERATOR_HPP_ER_2009
+#include <iterator>
+#include <algorithm>
+#include <cmath>
+#include <iostream>
+#include <boost/iterator/iterator_facade.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/range.hpp>
+
+namespace boost{
+namespace matrix_view{
+
+// Maps a pair of iterators and a stride to an iterator that iterates over
+// ranges. In matrix terminology,  ++row_iterator moves down one row.
+template<
+    typename BaseIter,
+    typename Categ = typename iterator_category<BaseIter>::type,
+    typename Diff = typename iterator_difference<BaseIter>::type>
+class row_iterator
+  : public iterator_facade<
+        row_iterator<BaseIter>
+      , iterator_range<BaseIter>
+      , Categ
+      , iterator_range<BaseIter>
+      , Diff
+    >
+{
+ public:
+    row_iterator(){}
+
+    explicit row_iterator(BaseIter i,std::size_t stride)
+    :stride_(stride),base_iter(i){}
+    row_iterator(const row_iterator& that)
+    :stride_(that.stride_),base_iter(that.base_iter){}
+    row_iterator& operator=(const row_iterator& that){
+        if(&that!=this){
+            stride_ = that.stride_;
+            base_iter = that.base_iter;
+        }
+        return *this;
+    }
+
+    BaseIter base(){return base_iter;}
+    std::size_t stride()const{return stride_;}
+ private:
+    typedef iterator_range<BaseIter> Value;
+
+    friend class iterator_core_access;
+
+    void increment() { std::advance(this->base_iter,stride_); }
+
+    Diff distance_to(row_iterator const& other) const{
+        Diff d = std::distance(this->base_iter,other.base_iter);
+        d/=(Diff)(stride());
+        return d;
+    };
+
+    bool equal(row_iterator const& other) const
+    {
+        return this->base_iter == other.base_iter;
+    }
+
+    Value dereference() const {
+        //Value& inappropriate as result is local
+        BaseIter i = this->base_iter;
+        std::advance(i,stride_);
+        return make_iterator_range(this->base_iter,i);
+    }
+
+    void advance(Diff n)
+    {
+        std::advance(this->base_iter, n*stride());
+    }
+
+    std::size_t stride_;
+    BaseIter base_iter;
+};
+
+template<typename BaseIter>
+row_iterator<BaseIter>
+make_end_row_iterator(BaseIter b,BaseIter e,std::size_t stride){
+    //BOOST_ASSERT(std::distance(b,e)>0);
+    BOOST_ASSERT( ( std::distance(b,e)>0 ) || ( std::distance(b,e)==0 ) );
+    BaseIter ee = e;
+    //std::size_t d = (std::size_t)(std::distance(b,ee)-1)/stride;
+
+    std::size_t d = (std::size_t)(std::distance(b,ee))/stride;
+    d *= stride;
+    //ee = b; std::advance(ee,d+1);
+    ee = b; std::advance(ee,d);
+
+   return row_iterator<BaseIter>(ee,stride);
+}
+
+template<typename BaseIter>
+row_iterator<BaseIter>
+make_row_iterator(BaseIter b,std::size_t stride){
+   return row_iterator<BaseIter>(b,stride);
+}
+
+}// matrix_view
+}// boost
+
+#endif
Added: sandbox/statistics/matrix_view/libs/matrix_view/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/libs/matrix_view/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,48 @@
+//////////////////////////////////////////////////////////////////////////////
+// matrix_view::doc::readme                                                 //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+This C++ package provides a row-major matrix view of a vector.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/ 
+
+[ iterator ]
+
+	row_iterator
+
+[ algorithm ]
+
+	transform_column	
+
+[ History ]
+
+July 2009 :     Revamped row_iterator (previously vector2matrix) and added
+                transform_column
+March 2009 :    vector2matrix
+
+[ Output ]
+
+main.cpp
+
+-> example_row_iterator
+std::distance(b,e) : 0 0 1 1 2 2 3 3 <-
+-> example_transform_column <-
+
+
Added: sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,87 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::example::row_iterator.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <list>
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/foreach.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/matrix_view/iterator/row_iterator.hpp>
+#include <libs/matrix_view/example/row_iterator.h>
+
+void example_row_iterator(std::ostream& out)
+{
+    out << "-> example_row_iterator" << std::endl;
+    
+    using namespace boost;
+    typedef int                                     val_;
+    typedef std::vector<val_>                       vec_;
+    typedef range_size<vec_>::type                  size_;
+    int stride = 2;
+
+    {
+        typedef range_iterator<vec_>::type          it_;
+        typedef matrix_view::row_iterator<it_>      row_it_;
+        typedef matrix_view::row_iterator<it_>      row_it_;
+
+        vec_ vec;
+        vec_ vecc;
+        {
+            using namespace boost::assign; 
+            vec += 0,1,2,3,4,5,6,7,8;
+        }
+        //important to use the const qualifier
+        it_ base_b = boost::begin(vec);
+        it_ base_e = boost::end(vec);
+        row_it_ b(base_b,stride); 
+        row_it_ i = b;
+        row_it_ e = matrix_view::make_end_row_iterator(
+            base_b,base_e,stride
+        );
+        while(i<e){
+            row_it_::value_type r = *i;
+            std::copy(boost::begin(r),boost::end(r),back_inserter(vecc));
+            ++i;
+        }
+        {
+            size_ i = 0;
+            BOOST_FOREACH(const val_& x, vecc){
+                x == vec[i];
+                ++i;
+            }
+        }
+    }
+
+    {
+        typedef vec_::const_iterator                it_;
+        typedef matrix_view::row_iterator<it_> row_it_;
+        typedef matrix_view::row_iterator<it_> row_it_;
+
+        vec_ vec,vec_a;
+        { 
+            using namespace boost::assign; 
+            vec += 0,1,2,3,4,5,6,7; 
+        }
+        it_ base_b = boost::begin(vec);
+        it_ base_e = boost::end(vec);
+        row_it_  b(base_b,stride);
+        out << "std::distance(b,e) : ";
+        for(it_ base_i = base_b; base_i<base_e; base_i++){
+            row_it_ e = matrix_view::make_end_row_iterator(
+                base_b,base_i,stride
+            );
+            out << std::distance(b,e) << ' '; 
+        } 
+    }
+
+
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/libs/matrix_view/example/row_iterator.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::example::row_iterator.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_MATRIX_VIEW_EXAMPLE_ROW_ITERATOR_H_ER_2009
+#define LIBS_MATRIX_VIEW_EXAMPLE_ROW_ITERATOR_H_ER_2009
+#include <ostream>
+
+void example_row_iterator(std::ostream&);
+
+#endif
Added: sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::example::transform_column.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <list>
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/foreach.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/matrix_view/algorithm/transform_column.hpp>
+#include <libs/matrix_view/example/transform_column.h>
+
+void example_transform_column(std::ostream& out)
+{
+    out << "-> example_transform_column" << std::endl;
+    
+    using namespace boost;
+    typedef int                                     val_;
+    typedef std::vector<val_>                       vec_;
+    typedef range_size<vec_>::type                  size_;
+
+    const unsigned n_col = 2;
+    const unsigned n_row = 5;
+    {
+        typedef range_iterator<vec_>::type              it_;
+
+        vec_ vec;
+        vec_ column;
+        {
+            using namespace boost::assign; 
+            size_ n = n_col * n_row;
+            for(unsigned i = 0; i< n; i++){
+                vec.push_back(i);
+            }
+        }
+        for(unsigned j = 0; j<n_col; j++){
+            column.clear();
+            matrix_view::copy_column<n_col>(
+                boost::begin(vec),
+                boost::end(vec),
+                j,
+                std::back_inserter(column)
+            );
+            for(unsigned i = 0; i<n_row; i++){
+                BOOST_ASSERT(
+                    vec[ i * n_col + j ] == column[i]
+                );
+            }
+        }
+
+    }
+
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/matrix_view/libs/matrix_view/example/transform_column.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// matrix_view::example::transform_column.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_MATRIX_VIEW_EXAMPLE_TRANSFORM_COLUMN_H_ER_2009
+#define LIBS_MATRIX_VIEW_EXAMPLE_TRANSFORM_COLUMN_H_ER_2009
+#include <ostream>
+
+void example_transform_column(std::ostream&);
+
+#endif
Added: sandbox/statistics/model/boost/model/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/algorithm/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::algorithm::include.hpp                                             //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_MODEL_ALGORITHM_INCLUDE_HPP_ER_2009
+#define BOOST_MODEL_ALGORITHM_INCLUDE_HPP_ER_2009
+
+#include <boost/model/algorithm/log_likelihood.hpp>
+#include <boost/model/algorithm/log_likelihoods.hpp>
+#include <boost/model/algorithm/log_posteriors.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/algorithm/log_likelihood.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/algorithm/log_likelihood.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,42 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::algorithm::log_likelihood.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_MODEL_ALGORITHM_LOG_LIKELIHOOD_HPP_ER_2009
+#define BOOST_MODEL_ALGORITHM_LOG_LIKELIHOOD_HPP_ER_2009
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <boost/model/wrap/aggregate/model_parameter.hpp>
+#include <boost/model/functional/log_likelihood_accumulator.hpp>
+
+namespace boost{
+namespace model{        
+
+    // Evaluates the likelihood at mp.parameter(), given model mp.model(),
+    // by summing all contributions from a dataset i.e. a
+    // sequence of covariates, [b_x,e_x), and reponses (starting at b_y)
+    template<typename T,typename M,typename P,typename ItX,typename ItE>
+    T
+    log_likelihood(
+        model_parameter_<M,P> mp,
+        ItX b_x,
+        ItX e_x,
+        ItE b_y
+    ){
+        typedef log_likelihood_accumulator<T,M,P> acc_;
+        acc_ acc(mp);
+        return boost::binary_op::for_each<acc_>(
+            b_x,
+            e_x,
+            b_y,
+            acc
+        ).value();
+    }
+
+    
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/algorithm/log_likelihoods.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/algorithm/log_likelihoods.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,70 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::algorithm::log_likelihoods.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_MODEL_ALGORITHM_LOG_LIKELIHOODS_HPP_ER_2009
+#define BOOST_MODEL_ALGORITHM_LOG_LIKELIHOODS_HPP_ER_2009
+#include <algorithm>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/model/wrap/aggregate/model_dataset.hpp>
+#include <boost/model/functional/log_likelihood_evaluator.hpp>
+
+namespace boost{
+namespace model{   
+
+// Evaluates the log-likelihood for each parameter in [b_p,e_p), given 
+// model and data md
+template<typename T,
+    typename M,typename Rx,typename Ry,typename ItP,typename ItLw>
+ItLw log_likelihoods(
+    model_dataset_<M,Rx,Ry> md,
+    ItP b_p,
+    ItP e_p,
+    ItLw o_lw
+){
+    typedef log_likelihood_evaluator<T,M,Rx,Ry> eval_;
+    return std::transform(
+        b_p,
+        e_p,
+        o_lw,
+        eval_(md)
+    );
+}
+
+// Maps the input log-pdf to the ratio-log-pdf
+template<
+    typename T,
+    typename M,
+    typename Rx,
+    typename Ry,
+    typename ItP,
+    typename ItLw
+>
+ItLw
+log_likelihoods(
+    model_dataset_<M,Rx,Ry> md,
+    ItP b_p,
+    ItP e_p,
+    ItLw b_lw,   
+    ItLw o_lw   // lw <- (log_likelihod - lw)
+){
+    typedef log_likelihood_evaluator<T,M,Rx,Ry> eval_;
+    eval_ e(md);
+    return std::transform(
+        b_p,
+        e_p,
+        b_lw,
+        o_lw,
+        boost::lambda::bind(e,boost::lambda::_2) - boost::lambda::_1
+    );
+}
+
+
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/algorithm/log_posteriors.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/algorithm/log_posteriors.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,75 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::algorithm::log_posteriors.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_MODEL_ALGORITHM_LOG_POSTERIORS_HPP_ER_2009
+#define BOOST_MODEL_ALGORITHM_LOG_POSTERIORS_HPP_ER_2009
+#include <algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/model/wrap/aggregate/prior_model_dataset.hpp>
+#include <boost/model/functional/log_posterior_evaluator.hpp>
+
+namespace boost{
+namespace model{   
+
+// Evaluates the log-postetior for each parameter in [b_p,e_p)
+template<
+    typename T,typename D,typename M,typename Rx,typename Ry,typename ItP,
+    typename ItLw
+>
+ItLw
+log_posteriors(
+    boost::model::prior_model_dataset_<D,M,Rx,Ry> pmd,
+    ItP b_p,
+    ItP e_p,
+    ItLw o_lw
+){
+    typedef log_posterior_evaluator<T,D,M,Rx,Ry> eval_;
+    return std::transform(
+        b_p,
+        e_p,
+        o_lw,
+        eval_(pmd)
+    );
+}
+
+// log-pdf_Q --> log_pdf P + log_pdf L - log_pdf_Q
+template<
+    typename T,
+    typename D,
+    typename M,
+    typename Rx,
+    typename Ry,
+    typename ItP,
+    typename ItLw,
+    typename ItLw2
+>
+ItLw
+log_posteriors(
+    prior_model_dataset_<D,M,Rx,Ry> pmd,
+    ItP b_p,
+    ItP e_p,
+    ItLw b_lw,   
+    ItLw2 o_lw   // lw <- (log_posterior - lw)
+){
+    typedef log_posterior_evaluator<T,D,M,Rx,Ry> eval_;
+    eval_ e(pmd);
+    return std::transform(
+        b_p,    //1
+        e_p,
+        b_lw,   //2
+        o_lw,
+        boost::lambda::bind(
+            e,
+            boost::lambda::_1
+        ) - boost::lambda::_2
+    );
+}
+
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/functional/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/functional/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::functional::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_MODEL_FUNCTIONAL_INCLUDE_HPP_ER_2009
+#define BOOST_MODEL_FUNCTIONAL_INCLUDE_HPP_ER_2009
+
+#include <boost/model/functional/log_likelihood_accumulator.hpp>
+#include <boost/model/functional/log_likelihood_evaluator.hpp>
+#include <boost/model/functional/log_posterior_evaluator.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/functional/log_likelihood_accumulator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/functional/log_likelihood_accumulator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,145 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::functional::log_likelihood_accumulator.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_MODEL_FUNCTIONAL_LOG_LIKELIHOOD_ACCUMULATOR_HPP_ER_2009
+#define BOOST_MODEL_FUNCTIONAL_LOG_LIKELIHOOD_ACCUMULATOR_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/operators.hpp>
+#include <boost/model/wrap/aggregate/model_parameter.hpp>
+#include <boost/model/wrap/aggregate/model_data.hpp>
+#include <boost/joint_dist/unscope/log_unnormalized_pdf.hpp>
+#include <boost/scalar_dist/unscope/log_unnormalized_pdf.hpp>
+
+namespace boost{
+
+    // fwd declare
+    template<typename T,typename M,typename X,typename Y,typename P>
+    T log_likelihood(
+        model::model_data_<M,X,Y>,
+        const P&
+    );
+
+namespace model{
+
+// Functor that accumulates the data contribution to the likelihood of a model 
+// and its parameter.
+//
+// Used by algorithm::log_likelihood        
+template<
+    typename T, // result_type
+    typename M, // Model
+    typename P  // parameter
+>
+class log_likelihood_accumulator : boost::addable<
+    log_likelihood_accumulator<T,M,P>
+>{
+public:
+    typedef T                        result_type;
+    typedef model_parameter_<M,P>    model_parameter_type;
+
+
+    // Construction
+    log_likelihood_accumulator();
+    log_likelihood_accumulator(model_parameter_type);
+    log_likelihood_accumulator(const log_likelihood_accumulator& );
+    log_likelihood_accumulator& operator=(const log_likelihood_accumulator& );
+
+    // Operator
+    log_likelihood_accumulator& operator+=(
+        const log_likelihood_accumulator& that
+    );
+    
+    // Update
+    template<typename X,typename Y> 
+    result_type operator()(const X&,const Y& y);
+    
+    // Access
+    const model_parameter_type& model_parameter()const;
+    result_type value()const;
+    
+private:
+    model_parameter_type mp_;
+    result_type cum_sum_;
+    static result_type zero_;
+};
+    
+    // Implementation //
+
+template<typename T,typename M,typename P>
+typename log_likelihood_accumulator<T,M,P>::result_type
+log_likelihood_accumulator<T,M,P>::zero_ = static_cast<result_type>(0);    
+
+// Construction
+template<typename T,typename M,typename P>
+log_likelihood_accumulator<T,M,P>::log_likelihood_accumulator()
+:mp_(),cum_sum_(zero_){}
+
+template<typename T,typename M,typename P>
+log_likelihood_accumulator<T,M,P>::log_likelihood_accumulator(
+    model_parameter_type mp
+):mp_(mp),cum_sum_(zero_){}
+
+template<typename T,typename M,typename P>
+log_likelihood_accumulator<T,M,P>::log_likelihood_accumulator(
+    const log_likelihood_accumulator& that
+):mp_(that.mp_),cum_sum_(that.cum_sum_){}
+
+template<typename T,typename M,typename P>
+log_likelihood_accumulator<T,M,P>& 
+log_likelihood_accumulator<T,M,P>::operator=(
+    const log_likelihood_accumulator& that
+){
+    if(&that!=this){
+        mp_ = that.mp_;
+        cum_sum_ = that.cum_sum_;
+    }
+    return (*this);
+}
+
+// Operator
+
+template<typename T,typename M,typename P>
+log_likelihood_accumulator<T,M,P>& 
+log_likelihood_accumulator<T,M,P>::operator+=(
+    const log_likelihood_accumulator& that
+){
+    (this->cum_sum_)+= that.value();
+}
+    
+// Update
+template<typename T,typename M,typename P>
+template<typename X,typename Y>
+typename log_likelihood_accumulator<T,M,P>::result_type 
+log_likelihood_accumulator<T,M,P>::operator()(const X& x,const Y& y){
+
+    result_type l = log_likelihood<T>(
+        make_model_data(
+            model_parameter().model(),
+            x,
+            y
+        ),
+        model_parameter().parameter()
+    );
+    cum_sum_ += l;
+    return cum_sum_;
+}
+
+// Access
+
+template<typename T,typename M,typename P>
+const typename log_likelihood_accumulator<T,M,P>::model_parameter_type&
+log_likelihood_accumulator<T,M,P>::model_parameter()const{ return mp_; }
+
+template<typename T,typename M,typename P>
+typename log_likelihood_accumulator<T,M,P>::result_type 
+log_likelihood_accumulator<T,M,P>::value()const{ return cum_sum_; }
+
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/functional/log_likelihood_evaluator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/functional/log_likelihood_evaluator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,97 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::functional::log_likelihood_evaluator.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_MODEL_FUNCTIONAL_LOG_LIKELIHOOD_EVALUATOR_HPP_ER_2009
+#define BOOST_MODEL_FUNCTIONAL_LOG_LIKELIHOOD_EVALUATOR_HPP_ER_2009
+#include <boost/range.hpp>
+#include <boost/model/wrap/aggregate/model_parameter.hpp>
+#include <boost/model/wrap/aggregate/model_dataset.hpp>
+#include <boost/model/algorithm/log_likelihood.hpp>
+
+namespace boost{
+namespace model{  
+
+    // Evaluates the log-likelihood at a parameter values given a model and
+    // a dataset.
+    //
+    // T is the result_type
+    template<typename T,typename M,typename Rx,typename Ry>
+    class log_likelihood_evaluator{
+        public:
+        typedef T result_type;
+        typedef model_dataset_<M,Rx,Ry> model_dataset_type;
+        
+        // Constructor
+        log_likelihood_evaluator();
+        log_likelihood_evaluator(const model_dataset_type&);
+        log_likelihood_evaluator(const log_likelihood_evaluator&);
+        log_likelihood_evaluator& operator=(const log_likelihood_evaluator&);
+
+        // Evaluate
+        template<typename P> result_type operator()(const P& p)const;
+
+        // Access
+        const model_dataset_type& model_dataset()const;
+        
+        private:
+        model_dataset_type md_;
+    };
+
+    // Implementation //
+    
+    // Construction
+    template<typename T,typename M,typename Rx,typename Ry>
+    log_likelihood_evaluator<T,M,Rx,Ry>::log_likelihood_evaluator(){}
+    
+    template<typename T,typename M,typename Rx,typename Ry>
+    log_likelihood_evaluator<T,M,Rx,Ry>::log_likelihood_evaluator(
+        const model_dataset_type& md
+    ):md_(md){}
+
+    template<typename T,typename M,typename Rx,typename Ry>
+    log_likelihood_evaluator<T,M,Rx,Ry>::log_likelihood_evaluator(
+        const log_likelihood_evaluator& that
+    ):md_(that.md_){}
+
+    template<typename T,typename M,typename Rx,typename Ry>
+    log_likelihood_evaluator<T,M,Rx,Ry>&
+    log_likelihood_evaluator<T,M,Rx,Ry>::operator=(
+        const log_likelihood_evaluator& that
+    ){
+        if(&that!=this){
+            md_ = (that.md_);
+        }
+        return (*this);
+    }
+    
+    // Evaluate
+    template<typename T,typename M,typename Rx,typename Ry>
+    template<typename P>
+    typename log_likelihood_evaluator<T,M,Rx,Ry>::result_type 
+    log_likelihood_evaluator<T,M,Rx,Ry>::operator()(const P& p)const{
+        return log_likelihood<T>(
+            make_model_parameter(
+                model_dataset().model(),
+                p
+            ),
+            boost::begin( model_dataset().covariates() ),
+            boost::end( model_dataset().covariates() ),
+            boost::begin( model_dataset().responses() )
+        );
+    }
+
+    // Access
+    template<typename T,typename M,typename Rx,typename Ry>
+    const typename log_likelihood_evaluator<T,M,Rx,Ry>::model_dataset_type& 
+    log_likelihood_evaluator<T,M,Rx,Ry>::model_dataset()const{
+        return (this->md_);
+    }
+
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/functional/log_posterior_evaluator.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/functional/log_posterior_evaluator.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,107 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::functional::log_posterior_evaluator.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_MODEL_FUNCTIONAL_LOG_POSTERIOR_EVALUATOR_HPP_ER_2009
+#define BOOST_MODEL_FUNCTIONAL_LOG_POSTERIOR_EVALUATOR_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/operators.hpp>
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <boost/joint_dist/unscope/log_unnormalized_pdf.hpp>
+#include <boost/scalar_dist/unscope/log_unnormalized_pdf.hpp>
+#include <boost/model/wrap/aggregate/prior_model_dataset.hpp>
+#include <boost/model/functional/log_likelihood_evaluator.hpp>
+
+namespace boost{
+namespace model{  
+
+    // Augments algorithm::log_likehood with a prior of type D
+    //
+    // Requirements:
+    // Let d denote an instance of D and p a parameter, then
+    // log_unnormalized_pdf(p_dist,p) must return an object of type T    
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    class log_posterior_evaluator : log_likelihood_evaluator<T,M,Rx,Ry>{
+        typedef log_likelihood_evaluator<T,M,Rx,Ry> super_;
+        public:
+        typedef prior_model_dataset_<D,M,Rx,Ry> prior_model_dataset_type;
+        typedef typename prior_model_dataset_type::prior_type prior_type;
+        typedef typename super_::result_type result_type;
+        
+        // Constructor
+        log_posterior_evaluator();
+        log_posterior_evaluator(const prior_model_dataset_type&);
+        log_posterior_evaluator(const log_posterior_evaluator&);
+        log_posterior_evaluator& operator=(const log_posterior_evaluator&);
+
+        // Evaluate
+        template<typename P> 
+        result_type operator()(const P& p)const;
+
+        // Access
+        const prior_model_dataset_type& prior_model_dataset()const;
+        
+        private:
+        prior_model_dataset_type pmd_;
+    };
+
+    // Implementation //
+    
+    // Construction
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    log_posterior_evaluator<T,D,M,Rx,Ry>::log_posterior_evaluator():
+    super_(){}
+    
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    log_posterior_evaluator<T,D,M,Rx,Ry>::log_posterior_evaluator(
+        const prior_model_dataset_type& pmd
+    ):super_(pmd),pmd_(pmd){}
+
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    log_posterior_evaluator<T,D,M,Rx,Ry>::log_posterior_evaluator(
+        const log_posterior_evaluator& that
+    ):super_(that),pmd_(that.pmd_){}
+
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    log_posterior_evaluator<T,D,M,Rx,Ry>&
+    log_posterior_evaluator<T,D,M,Rx,Ry>::operator=(
+        const log_posterior_evaluator& that
+    ){
+        if(&that!=this){
+            super_::operator=(that);
+            pmd_ = (that.pmd_);
+        }
+        return (*this);
+    }
+    
+    // Evaluate
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    template<typename P>
+    typename log_posterior_evaluator<T,D,M,Rx,Ry>::result_type 
+    log_posterior_evaluator<T,D,M,Rx,Ry>::operator()(const P& p)const{
+        const super_& super = static_cast<const super_&>(*this);
+        result_type res =  super(p);
+        res += log_unnormalized_pdf(
+            prior_model_dataset().prior(),
+            p
+        );
+        return res;
+    }
+
+    // Access
+    template<typename T,typename D,typename M,typename Rx,typename Ry>
+    const 
+        typename 
+            log_posterior_evaluator<T,D,M,Rx,Ry>::prior_model_dataset_type& 
+    log_posterior_evaluator<T,D,M,Rx,Ry>::prior_model_dataset()const{
+        return (this->pmd_);
+    }
+
+}// model
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::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_MODEL_INCLUDE_HPP_ER_2009
+#define BOOST_MODEL_INCLUDE_HPP_ER_2009
+
+#include <boost/model/algorithm/include.hpp>
+#include <boost/model/wrap/include.hpp>
+#include <boost/model/functional/include.hpp>
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/wrap/aggregate/data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/data.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::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_MODEL_WRAP_AGGREGATE_DATA_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_DATA_HPP_ER_2009
+#include <boost/model/wrap/unary/covariate.hpp>
+#include <boost/model/wrap/unary/response.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename X,typename Y>
+    class data_ : 
+        public covariate_<X>, 
+        public response_<Y>
+    {
+        typedef covariate_<X> cov_;
+        typedef response_<Y> resp_;
+
+    public:
+        typedef data_<X,Y> data_w_;
+        
+        // Construction
+        data_();
+        data_(cov_ cov,resp_ resp);
+        data_(const data_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename X,typename Y>
+    data_<X,Y>::data_() : cov_(),resp_(){}
+        
+    template<typename X,typename Y>
+    data_<X,Y>::data_( cov_ cov, resp_ resp ) : cov_( cov ), resp_( resp ){}
+        
+    template<typename X,typename Y>
+    data_<X,Y>::data_(const data_& that)
+    :cov_( that ),resp_( that ) {}
+
+    // Free functions
+        
+    template<typename X,typename Y>
+    data_<X,Y> 
+    make_data(const X& x,const Y& y){
+        typedef data_<X,Y> result_type;
+        return result_type(x,y);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/dataset.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/dataset.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::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_MODEL_WRAP_AGGREGATE_DATASET_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_DATASET_HPP_ER_2009
+#include <boost/model/wrap/unary/covariates.hpp>
+#include <boost/model/wrap/unary/responses.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename Rx,typename Ry>
+    class dataset_ : 
+        public covariates_<Rx>, 
+        public responses_<Ry>
+    {
+        typedef covariates_<Rx> covs_;
+        typedef responses_<Ry> resps_;
+
+        public:
+        typedef dataset_<Rx,Ry> dataset_w_;
+        
+        // Construction
+        dataset_();
+        dataset_(covs_ covs,resps_ resps);
+        dataset_(const dataset_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename Rx,typename Ry>
+    dataset_<Rx,Ry>::dataset_() : covs_(), resps_(){}
+        
+    template<typename Rx,typename Ry>
+    dataset_<Rx,Ry>::dataset_( covs_ covs, resps_ resps) 
+    : covs_( covs ), resps_( resps ){}
+        
+    template<typename Rx,typename Ry>
+    dataset_<Rx,Ry>::dataset_(const dataset_& that)
+    :covs_( that ), resps_( that ) {}
+
+    // Free functions
+        
+    template<typename Rx,typename Ry>
+    dataset_<Rx,Ry> 
+    make_dataset(const Rx& rx,const Ry& ry){
+        typedef dataset_<Rx,Ry> result_type;
+        return result_type(rx,ry);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/model_covariate_parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/model_covariate_parameter.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,77 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::model_covariate_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_MODEL_WRAP_AGGREGATE_MODEL_COVARIATE_PARAMETER_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_MODEL_COVARIATE_PARAMETER_HPP_ER_2009
+#include <boost/model/wrap/aggregate/model_parameter.hpp>
+#include <boost/model/wrap/unary/covariate.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename M,typename X,typename P>
+    class model_covariate_parameter_ : 
+        public model_parameter_<M,P>, 
+        public covariate_<X>
+    {
+        typedef model_parameter_<M,P>       model_parameter_;
+        typedef covariate_<X>               covariate_;
+
+        public:
+
+        typedef model_covariate_parameter_<M,X,P> model_covariate_parameter_w_;
+            
+        // Construction
+        model_covariate_parameter_();
+        model_covariate_parameter_(model_parameter_ mp,covariate_ cov);
+        model_covariate_parameter_(
+            typename model_parameter_::model_w_ model,
+            covariate_ cov, 
+            typename model_parameter_::parameter_w_ par
+        );
+        model_covariate_parameter_(const model_covariate_parameter_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename M,typename X,typename P>
+    model_covariate_parameter_<M,X,P>::model_covariate_parameter_() 
+    : model_parameter_(),covariate_(){}
+        
+    template<typename M,typename X,typename P>
+    model_covariate_parameter_<M,X,P>::model_covariate_parameter_( 
+        model_parameter_ mp, covariate_ cov 
+    )
+     : model_parameter_( mp ), covariate_( cov ){}
+
+    template<typename M,typename X,typename P>
+    model_covariate_parameter_<M,X,P>::model_covariate_parameter_( 
+        typename model_parameter_::model_w_ m, 
+        covariate_ cov, 
+        typename model_parameter_::parameter_w_ p
+    )
+     : model_parameter_( m, p ), covariate_( cov ){}
+        
+    template<typename M,typename X,typename P>
+    model_covariate_parameter_<M,X,P>::model_covariate_parameter_(
+        const model_covariate_parameter_& that
+    ) : model_parameter_( that ), covariate_( that ) {}
+
+    // Free functions
+        
+    template<typename M,typename X,typename P>
+    model_covariate_parameter_<M,X,P> 
+    make_model_covariate_parameter(const M& m,const X& x,const P& p){
+        typedef model_covariate_parameter_<M,X,P> result_type;
+        return result_type(m,x,p);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/model_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/model_data.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,66 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::model_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_MODEL_WRAP_AGGREGATE_MODEL_DATA_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_MODEL_DATA_HPP_ER_2009
+#include <boost/model/wrap/unary/model.hpp>
+#include <boost/model/wrap/aggregate/data.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename M,typename X,typename Y>
+    class model_data_ : 
+        public model_<M>, 
+        public data_<X,Y>
+    {
+        typedef model_<M> model_;
+        typedef data_<X,Y> data_;
+    public:
+        typedef model_data_<M,X,Y> model_data_w_;
+            
+        // Construction
+        model_data_();
+        model_data_(model_ model,data_ data);
+        model_data_(
+            model_ model,
+            typename data_::covariate_w_ cov,
+            typename data_::response_w_ resp
+        );
+        model_data_(const model_data_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename M,typename X,typename Y>
+    model_data_<M,X,Y>::model_data_() : model_(),data_(){}
+        
+    template<typename M,typename X,typename Y>
+    model_data_<M,X,Y>::model_data_(
+            model_ model,
+            typename data_::covariate_w_ covs,
+            typename data_::response_w_ resps
+    ) : model_( model ), data_ (covs,resps) {}
+        
+    template<typename M,typename X,typename Y>
+    model_data_<M,X,Y>::model_data_(const model_data_& that)
+    :model_( that ),data_( that ) {}
+
+    // Free functions
+        
+    template<typename M,typename X,typename Y>
+    model_data_<M,X,Y> 
+    make_model_data(const M& m,const X& x,const Y& y){
+        typedef model_data_<M,X,Y> result_type;
+        return result_type(m,x,y);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/model_dataset.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/model_dataset.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,66 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::model_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_MODEL_WRAP_AGGREGATE_MODEL_DATASET_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_MODEL_DATASET_HPP_ER_2009
+#include <boost/model/wrap/unary/model.hpp>
+#include <boost/model/wrap/aggregate/dataset.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename M,typename Rx,typename Ry>
+    class model_dataset_ : 
+        public  model_<M>, 
+        public dataset_<Rx,Ry>
+    {
+        typedef model_<M> model_;
+        typedef dataset_<Rx,Ry> dataset_;
+    public:
+        typedef model_dataset_<M,Rx,Ry> model_dataset_w_;
+            
+        // Construction
+        model_dataset_();
+        model_dataset_(model_ model,dataset_ dataset);
+        model_dataset_(
+            model_ model,
+            typename dataset_::covariates_w_ covs,
+            typename dataset_::responses_w_ resps
+        );
+        model_dataset_(const model_dataset_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename M,typename Rx,typename Ry>
+    model_dataset_<M,Rx,Ry>::model_dataset_() : model_(),dataset_(){}
+        
+    template<typename M,typename Rx,typename Ry>
+    model_dataset_<M,Rx,Ry>::model_dataset_(
+            model_ model,
+            typename dataset_::covariates_w_ covs,
+            typename dataset_::responses_w_ resps
+    ) : model_( model ), dataset_ (covs,resps) {}
+        
+    template<typename M,typename Rx,typename Ry>
+    model_dataset_<M,Rx,Ry>::model_dataset_(const model_dataset_& that)
+    :model_( that ),dataset_( that ) {}
+
+    // Free functions
+        
+    template<typename M,typename Rx,typename Ry>
+    model_dataset_<M,Rx,Ry> 
+    make_model_dataset(const M& m,const Rx& rx,const Ry& ry){
+        typedef model_dataset_<M,Rx,Ry> result_type;
+        return result_type(m,rx,ry);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/model_parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/model_parameter.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,60 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::model_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_MODEL_WRAP_AGGREGATE_MODEL_PARAMETER_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_MODEL_PARAMETER_HPP_ER_2009
+#include <boost/model/wrap/unary/model.hpp>
+#include <boost/model/wrap/unary/parameter.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename M,typename P>
+    class model_parameter_ : 
+        public model_<M>, 
+        public parameter_<P>
+    {
+        typedef model_<M> model_;
+        typedef parameter_<P> parameter_;
+
+    public:
+
+        typedef model_parameter_<M,P> model_parameter_w_;
+            
+        // Construction
+        model_parameter_();
+        model_parameter_(model_ model,parameter_ par);
+        model_parameter_(const model_parameter_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename M,typename P>
+    model_parameter_<M,P>::model_parameter_() : model_(),parameter_(){}
+        
+    template<typename M,typename P>
+    model_parameter_<M,P>::model_parameter_( model_ m, parameter_ p )
+     : model_( m ), parameter_( p ){}
+        
+    template<typename M,typename P>
+    model_parameter_<M,P>::model_parameter_(const model_parameter_& that)
+    :model_( that ),parameter_( that ) {}
+
+    // Free functions
+        
+    template<typename M,typename P>
+    model_parameter_<M,P> 
+    make_model_parameter(const M& m,const P& p){
+        typedef model_parameter_<M,P> result_type;
+        return result_type(m,p);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/aggregate/prior_model_dataset.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/aggregate/prior_model_dataset.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,71 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::aggregate::prior_model_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_MODEL_WRAP_AGGREGATE_PRIOR_MODEL_DATASET_HPP_ER_2009
+#define BOOST_MODEL_WRAP_AGGREGATE_PRIOR_MODEL_DATASET_HPP_ER_2009
+#include <boost/model/wrap/unary/prior.hpp>
+#include <boost/model/wrap/aggregate/model_dataset.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename D,typename M,typename Rx,typename Ry>
+    class prior_model_dataset_ : 
+        public prior_<D>,
+        public model_dataset_<M,Rx,Ry>
+    {
+        typedef prior_<D> prior_;
+        typedef model_dataset_<M,Rx,Ry> model_dataset_;
+    public:
+        typedef prior_model_dataset_<D,M,Rx,Ry> prior_model_dataset_w_;
+            
+        // Construction
+        prior_model_dataset_();
+        prior_model_dataset_(prior_ prior,model_dataset_ model_dataset);
+        prior_model_dataset_(
+            prior_ prior,
+            typename model_dataset_::model_w_ m,
+            typename model_dataset_::covariates_w_ covs,
+            typename model_dataset_::responses_w_ resps
+        );
+        prior_model_dataset_(const prior_model_dataset_&);
+            
+    };
+
+    // Implementation //
+            
+    template<typename D,typename M,typename Rx,typename Ry>
+    prior_model_dataset_<D,M,Rx,Ry>::prior_model_dataset_() 
+        : prior_(),model_dataset_(){}
+        
+    template<typename D,typename M,typename Rx,typename Ry>
+    prior_model_dataset_<D,M,Rx,Ry>::prior_model_dataset_(
+            prior_ prior,
+            typename model_dataset_::model_w_ m,
+            typename model_dataset_::covariates_w_ covs,
+            typename model_dataset_::responses_w_ resps
+    ) : prior_( prior ), model_dataset_ ( m, covs, resps) {}
+        
+    template<typename D,typename M,typename Rx,typename Ry>
+    prior_model_dataset_<D,M,Rx,Ry>::prior_model_dataset_(
+        const prior_model_dataset_& that)
+    :prior_( that ),model_dataset_( that ) {}
+
+    // Free functions
+        
+    template<typename D,typename M,typename Rx,typename Ry>
+    prior_model_dataset_<D,M,Rx,Ry> 
+    make_prior_model_dataset(const D& d,const M& m,const Rx& rx,const Ry& ry){
+        typedef prior_model_dataset_<D,M,Rx,Ry> result_type;
+        return result_type(d,m,rx,ry);
+    }
+
+}// model    
+}// boost
+
+#endif
+
Added: sandbox/statistics/model/boost/model/wrap/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::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_MODEL_WRAP_INCLUDE_HPP_ER_2009
+#define BOOST_MODEL_WRAP_INCLUDE_HPP_ER_2009
+
+#include <boost/model/wrap/unary/covariate.hpp>
+#include <boost/model/wrap/unary/model.hpp>
+#include <boost/model/wrap/unary/prior.hpp>
+#include <boost/model/wrap/unary/response.hpp>
+#include <boost/model/wrap/unary/covariates.hpp>
+#include <boost/model/wrap/unary/responses.hpp>
+
+#include <boost/model/wrap/aggregate/data.hpp>
+#include <boost/model/wrap/aggregate/dataset.hpp>
+#include <boost/model/wrap/aggregate/model_parameter.hpp>
+#include <boost/model/wrap/aggregate/model_dataset.hpp>
+#include <boost/model/wrap/aggregate/prior_model_dataset.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/model/boost/model/wrap/unary/covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/covariate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::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_MODEL_WRAP_UNARY_COVARIATE_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_COVARIATE_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename X>
+    class covariate_ : detail::base_<X>{
+        typedef detail::base_<X> base_;
+    public:
+        typedef X                       covariate_type;
+        typedef covariate_<X>           covariate_w_;
+            
+        // Construction
+        covariate_();
+        covariate_(const X& x);
+        covariate_(const covariate_&);
+            
+        // Access
+        const X& covariate()const;
+    };
+
+    // Implementation //
+            
+    template<typename X>
+    covariate_<X>::covariate_() : base_(){}
+        
+    template<typename X>
+    covariate_<X>::covariate_( const X& x ) : base_(x){}
+        
+    template<typename X>
+    covariate_<X>::covariate_(const covariate_& that)
+    :base_(that){}
+
+    template<typename X>
+    const X& covariate_<X>::covariate()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename X>
+    covariate_<X> 
+    make_covariate_(const X& x){
+        typedef covariate_<X> result_type;
+        return result_type(x);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/covariates.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/covariates.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::covariates.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_MODEL_WRAP_UNARY_COVARIATES_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_COVARIATES_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename Rx>
+    class covariates_ : detail::base_<Rx>{
+        typedef detail::base_<Rx> base_;
+    public:
+        typedef Rx                  covariates_type;
+        typedef covariates_<Rx>     covariates_w_;
+
+        // Construction
+        covariates_();
+        covariates_(const Rx& x);
+        covariates_(const covariates_&);
+            
+        // Access
+        const Rx& covariates()const;
+    };
+
+    // Implementation //
+            
+    template<typename Rx>
+    covariates_<Rx>::covariates_() : base_(){}
+        
+    template<typename Rx>
+    covariates_<Rx>::covariates_( const Rx& rx ) : base_(rx){}
+        
+    template<typename Rx>
+    covariates_<Rx>::covariates_(const covariates_& that)
+    :base_(that){}
+
+    template<typename Rx>
+    const Rx& covariates_<Rx>::covariates()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename Rx>
+    covariates_<Rx> 
+    make_covariates(const Rx& rx){
+        typedef covariates_<Rx> result_type;
+        return result_type(rx);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/detail/base.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/detail/base.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::detail::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_MODEL_WRAP_UNARY_DETAIL_BASE_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_DETAIL_BASE_HPP_ER_2009
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_reference.hpp>
+
+namespace boost{
+namespace model{
+namespace detail{
+
+    // D represents the prior distribution
+    template<typename T>
+    class base_{
+        typedef is_reference<T> is_ref_;
+        BOOST_MPL_ASSERT((
+            mpl::not_<is_ref_>
+        ));
+    public:
+        // Construction
+        base_();
+        base_(const T&);
+        base_(const base_&);
+        const T& value;
+    private:
+        base_& operator=(const base_&);
+        static const T& make();
+    };
+
+    // Implementation //
+
+    template<typename T>
+    base_<T>::base_() : value(make()){}
+                    
+    template<typename T>
+    base_<T>::base_(
+        const T& t
+    ) : value(t){}
+        
+    template<typename T>
+    base_<T>::base_(const base_& that)
+    :value( that.value ){}
+
+    template<typename T>
+    const T& base_<T>::make(){
+        static T t = T();
+        return t;
+    }
+      
+}// detail
+}// model        
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/model.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/model.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::model.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_MODEL_WRAP_UNARY_MODEL_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_MODEL_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+
+    template<typename M>
+    class model_ : detail::base_<M>{
+        typedef detail::base_<M> base_;
+    public:
+        typedef M                                   model_type;
+        typedef model_<M>                    model_w_;
+            
+        // Construction
+        model_();
+        model_(const M& m);
+        model_(const model_&);
+            
+        // Access
+        const M& model()const;
+    };
+
+    // Implementation //
+            
+    template<typename M>
+    model_<M>::model_() : base_(){}
+        
+    template<typename M>
+    model_<M>::model_( const M& m ) : base_(m){}
+        
+    template<typename M>
+    model_<M>::model_(const model_& that)
+    :base_(that){}
+
+    template<typename M>
+    const M& model_<M>::model()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename M>
+    model_<M> 
+    make_model(const M& m){
+        typedef model_<M> result_type;
+        return result_type(m);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/parameter.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/parameter.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::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_MODEL_WRAP_UNARY_PARAMETER_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_PARAMETER_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename X>
+    class parameter_ : detail::base_<X>{
+        typedef detail::base_<X> base_;
+    public:
+        typedef X                 parameter_type;
+        typedef parameter_<X>     parameter_w_;
+            
+        // Construction
+        parameter_();
+        parameter_(const X& x);
+        parameter_(const parameter_&);
+            
+        // Access
+        const X& parameter()const;
+    };
+
+    // Implementation //
+            
+    template<typename X>
+    parameter_<X>::parameter_() : base_(){}
+        
+    template<typename X>
+    parameter_<X>::parameter_( const X& x ) : base_(x){}
+        
+    template<typename X>
+    parameter_<X>::parameter_(const parameter_& that)
+    :base_(that){}
+
+    template<typename X>
+    const X& parameter_<X>::parameter()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename X>
+    parameter_<X> 
+    make_parameter(const X& x){
+        typedef parameter_<X> result_type;
+        return result_type(x);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/prior.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/prior.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// prior::wrap::unary::prior.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_MODEL_WRAP_UNARY_PRIOR_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_PRIOR_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename D>
+    class prior_ : detail::base_<D>{
+        typedef detail::base_<D> base_;
+    public:
+        typedef D                 prior_type;
+        typedef prior_<D>         prior_w_;
+
+            
+        // Construction
+        prior_();
+        prior_(const D& d);
+        prior_(const prior_&);
+            
+        // Access
+        const D& prior()const;
+    };
+
+    // Implementation //
+            
+    template<typename D>
+    prior_<D>::prior_() : base_(){}
+        
+    template<typename D>
+    prior_<D>::prior_( const D& d ) : base_(d){}
+        
+    template<typename D>
+    prior_<D>::prior_(const prior_& that)
+    :base_(that){}
+
+    template<typename D>
+    const D& prior_<D>::prior()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename D>
+    prior_<D> 
+    make_prior(const D& d){
+        typedef prior_<D> result_type;
+        return result_type(d);
+    }
+
+}// prior    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/response.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/response.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::response.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_MODEL_WRAP_UNARY_RESPONSE_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_RESPONSE_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename Y>
+    class response_ : detail::base_<Y>{
+        typedef detail::base_<Y> base_;
+    public:
+        typedef Y                 response_type;
+        typedef response_<Y>      response_w_;
+            
+        // Construction
+        response_();
+        response_(const Y& y);
+        response_(const response_&);
+            
+        // Access
+        const Y& response()const;
+    };
+
+    // Implementation //
+            
+    template<typename Y>
+    response_<Y>::response_() : base_(){}
+        
+    template<typename Y>
+    response_<Y>::response_( const Y& y ) : base_(y){}
+        
+    template<typename Y>
+    response_<Y>::response_(const response_& that)
+    :base_(that){}
+
+    template<typename Y>
+    const Y& response_<Y>::response()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename Y>
+    response_<Y> 
+    make_response(const Y& y){
+        typedef response_<Y> result_type;
+        return result_type(y);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/boost/model/wrap/unary/responses.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/boost/model/wrap/unary/responses.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// model::wrap::unary::responses.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_MODEL_WRAP_UNARY_RESPONSES_HPP_ER_2009
+#define BOOST_MODEL_WRAP_UNARY_RESPONSES_HPP_ER_2009
+#include <boost/model/wrap/unary/detail/base.hpp>
+
+namespace boost{
+namespace model{
+        
+    template<typename Ry>
+    class responses_ : detail::base_<Ry>{
+        typedef detail::base_<Ry> base_;
+    public:
+        typedef Ry                 responses_type;
+        typedef responses_<Ry>     responses_w_;
+            
+        // Construction
+        responses_();
+        responses_(const Ry& x);
+        responses_(const responses_&);
+            
+        // Access
+        const Ry& responses()const;
+    };
+
+    // Implementation //
+            
+    template<typename Ry>
+    responses_<Ry>::responses_() : base_(){}
+        
+    template<typename Ry>
+    responses_<Ry>::responses_( const Ry& ry ) : base_(ry){}
+        
+    template<typename Ry>
+    responses_<Ry>::responses_(const responses_& that)
+    :base_(that){}
+
+    template<typename Ry>
+    const Ry& responses_<Ry>::responses()const{ return (this->value); }
+                
+    // Free functions
+        
+    template<typename Ry>
+    responses_<Ry> 
+    make_responses(const Ry& ry){
+        typedef responses_<Ry> result_type;
+        return result_type(ry);
+    }
+
+}// model    
+}// boost
+
+#endif
Added: sandbox/statistics/model/libs/model/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/model/libs/model/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,112 @@
+//////////////////////////////////////////////////////////////////////////////
+// model::doc::readme                                                       //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+This C++ package contains 
+
+i) Wrappers are individual or bundled references to quantities such as data, 
+parameters and model abstractions, that arise in frequentist or Bayesian 
+modeling. They give explicit meaning to the above quantities and simplify the
+syntax of functions that takes these quantities as arguments.
+
+ii) STL-like algorithms for computing likelihoods or posterior distributions, 
+by aggretating the contributions of data-units in an (for now) iid setting.
+
+Examples can be found in statistics/survival/libs/example
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/ 
+
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/joint_dist/ 
+/sandbox/statistics/binary_op/
+
+[ History ]
+
+July 2009 : Current version
+
+[ Notation ]
+
+LPdf and Model are concepts defined within this package.  
+
+        Type   Object       Abstraction             Concept
+        name   name
+    -   T       t           scalar                  is_scalar
+    -   X       x           covariate               
+    -   Y       y           response                
+    -   P       p           parameter               
+    -   D       d           prior distribution      LPdf 
+    -   M       m           likelihood model        Model
+    -   Rx      rx          covariates              ForwardRange
+    -   Ry      ry          responses               ForwardRange
+    -   O       o                                   OutputIterator
+
+Note that X, Y, P are not retricted to scalars. For example,    
+    X == std::vector<T>
+    Y == survival::data::event<T>
+
+    Class                           Alias   Object name
+    model_parameter_<M,P>           mp_      mp
+    model_dataset_<M,Rx,Ry>         md_      md
+    prior_model_dataset_<D,M,Rx,Ry> pmd_     pmd
+          
+[b_x,e_x) and [b_p,e_p) denote iterator ranges to covariates and
+parameter values, respectively.
+
+[ Concepts ]
+
+- Model
+    m models Model iff
+    Expression                                  Return type
+    log_likelihood(make_model_data(m,x,y),p)    T
+- LPdf
+    d models LPdf iff
+    Expression                                  Returns 
+    log_unnormalized_pdf(d,p)                   T
+
+Those D such that is_scalar_dist<D> or joint_dist<D> evaluates to true model
+LPdf. Check directory unscope in either package.
+
+[ wrap ]
+    Example of wrappers:
+        md_ md(m,rx,ry);
+        md.covariates();
+        
+    Often we only need a temporary, in which case it is preferable to call an 
+    associated creator function that deduces the types of its arguments:
+        make_model_dataset(m,rx,ry);
+
+[ functional ]
+    Functors that support [ algorithm ]
+        
+[ algorithm ]
+    Iterate over a dataset or parameter values to produce a likelihood or
+    set of likelihood (or posterior) values 
+
+    Expression                          Return type
+    log_likelihood(mp,b_x,e_x,b_y)      T
+    log_likelihoods(md,b_p,e_p,o)       O
+    log_posteriors(pmd,b_p,e_p,o)       O
+
+[ TODO ]
+
+- Some simple examples.
+- Check integration with Boost.Probability i.e. T =  boost::log_likelihood 
+- Think about non-iid
+- Think about derivatives.
\ No newline at end of file
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/monomials.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/monomials.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,180 @@
+//////////////////////////////////////////////////////////////////////////////
+//  monomials_horner::monomials.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_MONOMIALS_HORNER_MONOMIALS_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_MONOMIALS_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <boost/assert.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/range.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/bind.hpp>
+#include <boost/monomials_horner/monomials_properties.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    // Background:    
+    // \see http://mathworld.wolfram.com/Polynomial.html
+    // A polynomial is a mathematical expression involving a sum of powers in 
+    // one or more variables  multiplied by coefficients. A polynomial in one 
+    // variable (i.e., a univariate polynomial) with constant coefficients is 
+    // given by 
+    //  a_nx^n+...+a_2x^2+a_1x+a_0. (1)
+    // The individual summands with the coefficients (usually) included are 
+    // called monomials (Becker and Weispfenning 1993, p. 191),
+    // the products of the form x_1^(alpha_1)...x_n^(alpha_n)
+    // in the multivariate case,
+    // i.e., with the coefficients omitted, are called terms
+    // (Becker and Weispfenning 1993, p. 188).
+    // The highest power  in a univariate polynomial is called its order,
+    // or sometimes its degree
+
+
+    // Example :
+    // variables = (a,b,c)
+    //
+    // 1
+    // >a >b >c
+    // >a^2 ab ac >b^2 bc >c^2
+    // >a^3 a^2b a^2 c ab^2 abc ac^2 >b^3 b^2c bc^2 > c^3
+    //
+    // each > above marks the begining of a "read range"
+    // the kth write range on the nth line is obtained by
+    // multiplying the kth read range on the (n-1)th line
+    // by the kth variable in (a,b,c)
+    // For example, (b^3, b^2c, bc^2) = b*(b^2, bc, c^2)
+
+    template<typename Cont = std::vector<double> >
+    class monomials{
+        typedef typename Cont::size_type                size_type;
+        typedef typename range_iterator<Cont>::type     it_;
+        typedef std::vector<it_>                        it_s;
+        typedef monomials_properties<>                  properties;
+    public:
+        typedef typename range_value<Cont>::type        value_type;
+        typedef const Cont&                             result_type;
+        monomials(){}
+        monomials(monomials& that)
+        :degree_(that.degree_),terms_(that.terms_){}
+        monomials& operator=(const monomials& that){
+            if(&that!=this){
+                degree_ = that.degree_;
+                terms_ = that.terms_;
+            }
+            return *this;
+        }
+
+        //degree (also called total degree) is |alpha|=alpha_0+...+alpha_{n-1}
+        unsigned degree()const{return degree_;}
+        result_type operator()()const{return terms_;}
+
+        template<typename R>
+        void operator()(const R& variables,unsigned the_degree){
+            typedef std::vector<it_> it_s;
+            static it_s read_bs;
+            {
+                size_type sz = properties::number_degree_less_than(
+                    the_degree,(unsigned)(size(variables)));
+                terms_.resize(sz);
+            }
+            it_ write_b = begin(terms_);
+
+            *write_b++ = 1;
+            read_bs.clear();
+            std::fill_n(
+                back_inserter(read_bs),
+                size(variables),
+                begin(terms_)
+            );
+
+            unsigned i = 1;
+            unsigned n = the_degree + 1;
+            while(i<n){
+                BOOST_ASSERT(size(read_bs)==size(variables));
+                write_b = for_each(//e=
+                    make_zip_iterator(
+                        make_tuple(
+                            begin(read_bs),
+                            begin(variables)
+                        )
+                    ),
+                    make_zip_iterator(
+                        make_tuple(
+                            end(read_bs),
+                            end(variables)
+                        )
+                    ),
+                    zip_func<R>(write_b)
+                ).write_b;
+
+                ++i;
+            }
+            degree_ = the_degree;
+        }
+
+    private:
+        // keeping terms_ inside spares the client the need to clear it
+        // or keeping track of the number of terms.
+        // using the same Cont for improved memory management
+        unsigned degree_;
+        Cont terms_;
+
+        template<typename R>
+        struct zip_func
+        {
+            typedef typename range_iterator<R>::type              it_1;
+            typedef typename it_1::value_type                    value1_type;
+            typedef const tuple<it_&,const value1_type&>& argument_type;
+            typedef void                                          result_type;
+
+            zip_func(it_ write_b_)
+            :write_b(write_b_),read_e(write_b){}
+
+            zip_func(const zip_func& that)
+            :write_b(that.write_b),read_e(that.read_e){}
+
+            zip_func& operator=(const zip_func& that){
+                if(&that!=this){
+                    write_b = that.write_b;
+                    read_e = that.read_e;
+                }
+                return *this;
+            }
+
+            result_type operator()(argument_type t){
+                typename it_1::value_type x = (t.template get<1>());
+
+                it_ read_b = t.get<0>();
+                t.template get<0>() = write_b;
+
+                write_b =
+                    transform(
+                        read_b,
+                        read_e,
+                        write_b,
+                        bind(
+                            std::multiplies<value_type>(),
+                            _1,
+                            x
+                        )
+                    );
+            }
+
+            it_ write_b;
+            it_ read_e;
+
+        };
+    };
+
+}// monomials_horner
+}// boost
+
+#endif
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/monomials_properties.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/monomials_properties.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,28 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::monomials_properties.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_MONOMIALS_HORNER_MONOMIALS_PROPERTIES_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_MONOMIALS_PROPERTIES_HPP_ER_2009
+#include <boost/math/special_functions/binomial.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    template<typename T = double>
+    struct monomials_properties{
+        static unsigned long number_degree_less_than(
+            unsigned the_degree,unsigned dim){
+                return static_cast<unsigned long>(math::binomial_coefficient<T>(
+                    the_degree+dim,dim));
+        }
+    };
+
+}// monomials_horner
+}// boost
+
+
+#endif
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,280 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::multi_indexes.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_MONOMIALS_HORNER_MULTI_INDEXES_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_MULTI_INDEXES_HPP_ER_2009
+#include <vector>
+#include <functional>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/range.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/bind.hpp>
+#include <boost/assert.hpp>
+#include <boost/matrix_view/iterator/row_iterator.hpp>
+#include <boost/monomials_horner/monomials_properties.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    // Example of multi indexes for N = 3, degree =2
+    // >(0,0,0)
+    // >(1,0,0) >(0,1,0) >(0,0,1)
+    // >(2,0,0) (1,1,0) (1,0,1) >(0,2,0) (0,1,1) >(0,0,2)
+    // Note that
+    // {(2,0,0) (1,1,0) (1,0,1)} = {(1,0,0) (0,1,0) (0,0,1)} + (1,0,0)
+    // {(0,2,0) (0,1,1)} = {(0,1,0) (0,0,1)} + (0,1,0) etc.
+
+    template<unsigned int N>
+    class multi_indexes{
+      public:
+        typedef std::vector<unsigned>                   storage_type;
+        typedef typename storage_type::iterator         base_iter_type;
+        typedef typename storage_type::size_type        size_type;
+        typedef storage_type::value_type                base_value_type;
+
+        typedef matrix_view::row_iterator<base_iter_type>  iter_type;
+        typedef std::vector<iter_type>                  iters_type;
+        typedef typename iter_type::value_type          value_type;
+        typedef iterator_range<iter_type>               iter_range_type;
+        typedef typename iters_type::iterator           iters_iter_type;
+        typedef typename iter_type::difference_type     iter_diff_type;
+        typedef std::vector<iter_diff_type>             iters_diff_type;
+        typedef typename iters_diff_type::iterator      iters_diff_iter_type;
+
+        static iter_range_type get(unsigned int degree){
+            static unsigned max_degree = 0;
+            static storage_type storage(N,(base_value_type)(0));
+            static iters_diff_type read_bs_dists(N,0);
+
+// // keeping read_bs rather than read_bs_dists causes
+// // error 'gliblc detected' at runtime
+//            static iters_type   read_bs(
+//                N,
+//                matrix_view::make_row_iterator(
+//                    begin(storage),
+//                    N
+//            ));
+
+            //e.g. N=3: (1,0,0, 0,1,0, 0,0,1)
+            static storage_type variables = variables_init();
+
+            if(degree>max_degree){
+                unsigned i = max_degree+1;
+                unsigned n = degree+1;
+                size_type sz_old = size(storage)/N;
+                size_type sz_new
+                    = properties::number_degree_less_than(degree,N);
+                storage.resize(sz_new*N);
+                iter_type write_b = matrix_view::make_row_iterator(
+                    begin(storage),
+                    N
+                );
+                std::advance(write_b,sz_old);
+
+                iters_type read_bs;
+
+//old implem, do not uncomment
+//                iters_diff_iter_type b = begin(read_bs_dists);
+//                iters_diff_iter_type e = end(read_bs_dists);
+//                for(iters_diff_iter_type i = b; i<e; i++){
+//                    iter_type it(begin(storage),N);
+//                    std::advance(it,*i);
+//                    read_bs.push_back(it);
+//                }
+
+                transform(
+                    begin(read_bs_dists),
+                    end(read_bs_dists),
+                    back_inserter(read_bs),
+                    unary_op(
+                        matrix_view::make_row_iterator(
+                            begin(storage),
+                            N
+                        )
+                    )
+                );
+
+                while(i<n){
+                    BOOST_ASSERT(size(read_bs_dists)==N);
+                    BOOST_ASSERT(std::distance(
+                        matrix_view::make_row_iterator(
+                            begin(variables),
+                            N
+                        ),
+                        matrix_view::make_end_row_iterator(
+                                begin(variables),
+                                end(variables),
+                                N
+                        )
+                    )==N);
+
+                    //(***) bug
+                    write_b = for_each(
+                        make_zip_iterator(
+                            make_tuple(
+                                begin(read_bs),
+                                matrix_view::make_row_iterator(
+                                    begin(variables),
+                                    N
+                                )
+                            )
+                        ),
+                        make_zip_iterator(
+                            make_tuple(
+                                end(read_bs),
+                                matrix_view::make_end_row_iterator(
+                                    begin(variables),
+                                    end(variables),
+                                    N
+                                )
+                            )
+                        ),
+                        zip_func(write_b)
+                    ).write_b;
+                    ++i;
+                }
+                read_bs_dists.clear();
+                std::transform(
+                    begin(read_bs),
+                    end(read_bs),
+                    back_inserter(read_bs_dists),
+                    bind(
+                        std::distance<iter_type>,
+                        matrix_view::make_row_iterator(
+                            begin(storage),
+                            N
+                        ),
+                        _1
+                    )
+                );
+                max_degree = degree;
+            }//if(degree>max_degree)
+
+            size_type dist
+                = properties::number_degree_less_than(degree,N);
+            iter_type b(begin(storage),N);
+            iter_type e = b;
+            std::advance(e,dist);
+            iter_range_type(b,e);
+            return iter_range_type(b,e);
+        }//get(unsigned degree)
+
+      private:
+        typedef monomials_properties<> properties;
+        multi_indexes(); //do not implement
+
+        static storage_type variables_init(){
+            storage_type variables(N*N,0);
+            for(unsigned i=0; i<N; i++){
+                variables[i*N+i]=1;
+            }
+            return variables;
+        }
+
+        struct unary_op{
+            iter_type b;
+            unary_op(iter_type b_):b(b_){}
+            unary_op(const unary_op& that):b(that.b){}
+            unary_op& operator=(const unary_op& that){
+                if(&that!=this){b=that.b;}
+                return *this;
+            }
+            typedef iter_type                   result_type;
+            typedef const iter_diff_type&       argument_type;
+            result_type operator()(argument_type diff)const{
+                result_type it = b;
+                std::advance(it,diff);
+                return it;
+            }
+        };
+
+        struct zip_func
+        {
+            typedef const tuple<
+                iter_type&,const value_type&>&                  argument_type;
+            typedef void                                        result_type;
+
+            iter_type write_b;
+            iter_type read_e;
+            unsigned cnt;//TODO remove
+
+            zip_func(iter_type write_b_)
+            :write_b(write_b_),read_e(write_b),cnt(0){}
+
+            zip_func(const zip_func& that)
+            :write_b(that.write_b),
+            read_e(that.read_e),
+            cnt(that.cnt){}
+
+            zip_func& operator=(const zip_func& that){
+                if(&that!=this){
+                    write_b = that.write_b;
+                    read_e = that.read_e;
+                    cnt = that.cnt;
+                }
+                return *this;
+            }
+
+            result_type operator()(argument_type t){
+                value_type variable_ir = (t.template get<1>());
+                iter_type read_b = (t.template get<0>());
+                t.template get<0>() = write_b;
+                write_b =
+                    for_each(
+                        read_b,
+                        read_e,
+                        unary_op(write_b,variable_ir)
+                    ).write_b;
+            }
+
+            struct unary_op{
+                unary_op(iter_type write_b_,value_type variable_ir)
+                :write_b(write_b_),variable(variable_ir){}
+
+                unary_op(const unary_op& that)
+                :write_b(that.write_b),variable(that.variable){}
+
+                unary_op& operator=(const unary_op& that)
+                {
+                    if(&that!=this){
+                        write_b = that.write_b;
+                        variable = that.variable;
+                    }
+                    return *this;
+                }
+
+                typedef typename iter_type::value_type     argument_type;
+                typedef void                               result_type;
+                result_type operator()(argument_type ir){
+
+                    BOOST_ASSERT(size(*write_b)==size(ir));
+                    BOOST_ASSERT(size(ir)==size(variable));
+                    std::transform(
+                        begin(ir),
+                        end(ir),
+                        begin(variable),
+                        begin(*write_b),
+                        bind(
+                            std::plus<base_value_type>(),
+                            _1,
+                            _2
+                        )
+                    );
+                    ++write_b;
+                }
+                iter_type   write_b;
+                value_type  variable;
+            };//unary_op
+        };//zip_func
+    };//multi_indexes
+
+}// monomials_horner
+}// boost
+
+
+#endif
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes_derived.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/multi_indexes_derived.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,88 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::multi_indexes_derived.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_MONOMIALS_HORNER_MULTI_INDEXES_DERIVED_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_MULTI_INDEXES_DERIVED_HPP_ER_2009
+#include <numeric>
+#include <cmath>
+#include <boost/monomials_horner/multi_indexes.hpp>
+#include <boost/math/special_functions/factorials.hpp>
+#include <boost/monomials_horner/policy/multi_factorial.hpp>
+#include <boost/monomials_horner/policy/multi_degree.hpp>
+#include <boost/monomials_horner/policy/multi_power2divfact.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    // Functions of multi_indexes
+    // The particular function is controled by a policy:
+    template<unsigned int N,typename Policy>
+    class multi_indexes_derived{
+      public:
+        typedef typename Policy::result_type            value_type;
+        typedef std::vector<value_type>                 storage_type;
+        typedef typename storage_type::iterator         iter_type;
+        typedef iterator_range<iter_type>               iter_range_type;
+        typedef typename storage_type::size_type        size_type;
+
+       static iter_range_type get(unsigned int degree){
+            static unsigned max_degree = 0;
+            static storage_type storage(1,Policy::initial_value);
+            size_type dist
+                = monomials_properties<>::number_degree_less_than(
+                    degree,N);
+            if(max_degree<degree){
+                typedef multi_indexes<N>            mi_type;
+                typedef
+                    typename mi_type::iter_range_type      mi_iter_range_type;
+                mi_iter_range_type ir = mi_type::get(degree);
+                storage.clear();
+                transform(
+                    begin(ir),
+                    end(ir),
+                    back_inserter(storage),
+                    unary_op()
+                );
+                max_degree = degree;
+            }
+
+            iter_type b(begin(storage));
+            iter_type e(b); std::advance(e,dist);
+
+            return iter_range_type(b,e);
+        }
+      private:
+        multi_indexes_derived(); //do not implement
+
+        typedef multi_indexes<N>  mi_type;
+        typedef typename mi_type::iter_range_type       mi_iter_range_type;
+        typedef typename mi_type::iter_type             mi_iter_type;
+        typedef typename mi_type::value_type            mi_value_type;
+        typedef typename mi_type::base_iter_type        mi_base_iter_type;
+        typedef typename mi_type::base_value_type       mi_base_value_type;
+
+        struct unary_op{
+            typedef mi_value_type                       argument_type;
+            typedef value_type                          result_type;
+            unary_op(){}
+            result_type operator()(argument_type ir){
+                return accumulate(
+                    begin(ir),
+                    end(ir),
+                    Policy::initial_value, 
+                    Policy()
+                );
+            }
+            iter_type write_begin;
+        };
+    };
+    
+}// monomials_horner
+}// boost
+
+#endif
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_degree.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_degree.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::policy::multi_degree.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_MONOMIALS_HORNER_POLICY_MULTI_DEGREE_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_POLICY_MULTI_DEGREE_HPP_ER_2009
+#include <functional>
+
+namespace boost{
+namespace monomials_horner{
+
+    // (a,b,c) --> a + b + c (also called total degree)
+    struct multi_degree : public std::plus<unsigned>{
+        static result_type initial_value;
+    };
+    unsigned multi_degree:: initial_value = static_cast<unsigned>(0);
+
+}// monomials_horner
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_factorial.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_factorial.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,36 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::policy::multi_factorial.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_MONOMIALS_HORNER_POLICY_MULTI_FACTORIAL_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_POLICY_MULTI_FACTORIAL_HPP_ER_2009
+#include <boost/math/special_functions/factorials.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    // (a,b,c) --> a! b! c!
+    struct multi_factorial{
+        typedef unsigned                      result_type;
+        typedef unsigned                      first_argument_type;
+        typedef unsigned                      second_argument_type;
+        multi_factorial(){}
+        result_type operator()(
+            first_argument_type a1,
+            second_argument_type a2
+        )const{
+            return a1 * static_cast<result_type>(math::factorial<double>(a2));
+        }
+        static result_type initial_value;
+    };
+    multi_factorial::result_type multi_factorial:: initial_value
+        = static_cast<result_type>(1);
+
+}// monomials_horner
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_power2divfact.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/boost/monomials_horner/policy/multi_power2divfact.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,39 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::policy::power2divfact.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_MONOMIALS_HORNER_POLICY_MULTI_POWER2DIVFACT_HPP_ER_2009
+#define BOOST_MONOMIALS_HORNER_POLICY_MULTI_POWER2DIVFACT_HPP_ER_2009
+#include <boost/math/special_functions/factorials.hpp>
+
+namespace boost{
+namespace monomials_horner{
+
+    // (a,b,c) --> 2^{a+b+c}/(a! b! c!)
+    struct multi_power2divfact{
+        typedef double                      result_type;
+        typedef double                      first_argument_type;
+        typedef unsigned                    second_argument_type;
+        multi_power2divfact(){}
+        result_type operator()(
+            first_argument_type a1,
+            second_argument_type a2
+        )const{
+            result_type d = std::pow(2.0,static_cast<result_type>(a2));
+            result_type f = math::factorial<result_type>(a2);
+            result_type r = d/f;
+            return a1 * static_cast<result_type>(r);
+        }
+        static result_type initial_value;
+    };
+    multi_power2divfact::result_type multi_power2divfact::initial_value
+        = static_cast<result_type>(1);
+
+}// monomials_horner
+}// boost
+
+#endif
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,128 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::doc                                                    //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)	    //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5490)
+
+[Dependencies]
+
+/boost_1_39_0/ 
+/sandbox/statistics/matrix_view/ 
+
+[ Overview  ]
+
+This collection of C++ classes computes multivariate monomials and derived
+quantities using Horner's rule a.k.a. graded lexicographic ordering. 
+
+A possible application is the Fast Gauss Transform.
+
+[ Notation ]
+
+D       dimension
+a       multivariate power
+|a|     total degree of a             |a| = sum{a(d):d=0,...,D-1}
+p       a bound on |a|
+b       coefficient
+x       range of size D
+
+
+[ Output ]
+
+Here's the output from from main.cpp
+
+-> example_monomials
+
+ -> d=1
+  ->p=1
+1 0   <-
+  ->p=2
+1 0 0   <-
+  ->p=3
+1 0 0 0   <-
+  ->p=4
+1 0 0 0 0   <-
+ <-
+ -> d=2
+  ->p=1
+1 0 1   <-
+  ->p=2
+1 0 1 0 0 1   <-
+  ->p=3
+1 0 1 0 0 1 0 0 0 1   <-
+  ->p=4
+1 0 1 0 0 1 0 0 0 1 0 0 0 0 1   <-
+ <-
+ -> d=3
+  ->p=1
+1 0 1 2   <-
+  ->p=2
+1 0 1 2 0 0 0 1 2 4   <-
+  ->p=3
+1 0 1 2 0 0 0 1 2 4 0 0 0 0 0 0 1 2 4 8   <-
+  ->p=4
+1 0 1 2 0 0 0 1 2 4 0 0 0 0 0 0 1 2 4 8 0 0 0 0 0 0 0 0 0 0 1 2 4 8 16   <-
+ <-
+ -> d=4
+  ->p=1
+1 0 1 2 3   <-
+  ->p=2
+1 0 1 2 3 0 0 0 0 1 2 3 4 6 9   <-
+  ->p=3
+1 0 1 2 3 0 0 0 0 1 2 3 4 6 9 0 0 0 0 0 0 0 0 0 0 1 2 3 4 6 9 8 12 18 27   <-
+  ->p=4
+1 0 1 2 3 0 0 0 0 1 2 3 4 6 9 0 0 0 0 0 0 0 0 0 0 1 2 3 4 6 9 8 12 18 27 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 6 9 8 12 18 27 16 24 36 54 81   <-
+ <-
+<-
+-> example_multi_indexes
+0 0 0
+1 0 0
+0 1 0
+0 0 1
+2 0 0
+1 1 0
+1 0 1
+0 2 0
+0 1 1
+0 0 2
+
+0 0 0
+1 0 0
+0 1 0
+0 0 1
+2 0 0
+1 1 0
+1 0 1
+0 2 0
+0 1 1
+0 0 2
+3 0 0
+2 1 0
+2 0 1
+1 2 0
+1 1 1
+1 0 2
+0 3 0
+0 2 1
+0 1 2
+0 0 3
+<-
+-> example_multi_factorial
+ -> multi_factorial<3>::degree(5)
+1 1 1 1 2 1 1 2 1 2 6 2 2 2 1 2 6 2 2 6 24 6 6 4 2 4 6 2 2 6 24 6 4 6 24 120 24 24 12 6 12 12 4 4 12 24 6 4 6 24 120 24 12 12 24 120
+ -> multi_degree<3>::degree(5)
+0 1 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
+ -> multi_p2df<3>::degree(5)
+1 2 2 2 2 4 4 2 4 2 1.33333 4 4 4 8 4 1.33333 4 4 1.33333 0.666667 2.66667 2.66667 4 8 4 2.66667 8 8 2.66667 0.666667 2.66667 4 2.66667 0.666667 0.266667 1.33333 1.33333 2.66667 5.33333 2.66667 2.66667 8 8 2.66667 1.33333 5.33333 8 5.33333 1.33333 0.266667 1.33333 2.66667 2.66667 1.33333 0.266667
+<-
+
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::monomials.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <algorithm>
+#include <boost/math/special_functions/binomial.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/range.hpp>
+#include <boost/monomials_horner/monomials.hpp>
+#include <libs/monomials_horner/example/monomials.h>
+
+void example_monomials(std::ostream& out){
+    out << "-> example_monomials" << std::endl;
+
+    using namespace boost;
+    using namespace monomials_horner;
+
+    typedef std::vector<double> vars_type;
+    typedef monomials<vars_type> monoms_type;
+
+    unsigned max_d = 5;
+    unsigned max_p = 5;    vars_type vars;
+    {
+        using namespace boost::assign; 
+        vars += 0.0,1.0,2.0,3.0,4.0;
+    }
+
+    for(unsigned d = 1; d<max_d; d++){
+        out << " -> d=" << d << std::endl;
+        vars_type::iterator e = boost::begin(vars);
+        std::advance(e,d);
+        vars_type sub;
+        copy(boost::begin(vars),e,back_inserter(sub));
+        BOOST_ASSERT(boost::size(sub)-d==0);
+
+        for(unsigned int p = 1; p<max_p; p++){
+            out << "  ->p=" << p << std::endl;
+            //out << boost::math::binomial_coefficient<double>(p+d,d)
+            //<< std::endl;
+
+            monoms_type monoms;
+
+            monoms(sub,p);
+            copy(
+                boost::begin(monoms()),
+                boost::end(monoms()),
+                std::ostream_iterator<double>(out," ")
+            );
+            out << "  <-" << std::endl;
+        }
+            out << " <-" << std::endl;
+    }
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/monomials.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::monomials.h                                   //
+//                                                                          //
+//  (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 LIBS_MONOMIALS_HORNER_EXAMPLE_MONOMIALS_H_ER_2009
+#define LIBS_MONOMIALS_HORNER_EXAMPLE_MONOMIALS_H_ER_2009
+#include <ostream>
+
+void example_monomials(std::ostream& out);
+
+#endif
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,62 @@
+///////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::multi_factorial.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/monomials_horner/multi_indexes_derived.hpp>
+#include <libs/monomials_horner/example/multi_factorial.h>
+
+void example_multi_factorial(std::ostream& out){
+    out << "-> example_multi_factorial" << std::endl;
+
+    using namespace boost;
+    using namespace monomials_horner;
+
+    const unsigned d = 3;
+    typedef multi_indexes_derived<d,multi_factorial>        mf_type;
+    typedef multi_indexes_derived<d,multi_degree>           md_type;
+    typedef multi_indexes_derived<d,multi_power2divfact>    mp_type;
+    typedef mf_type::iter_range_type            mf_iter_range_type;
+    typedef md_type::iter_range_type            md_iter_range_type;
+    typedef mp_type::iter_range_type            mp_iter_range_type;
+
+    unsigned int degree1 = 5;
+
+    mf_iter_range_type mf_ir = mf_type::get(degree1);
+
+    out << " -> multi_factorial<" << d << ">";
+    out << "::degree(" << degree1 << ")" << std::endl;
+    copy(
+        boost::begin(mf_ir),
+        boost::end(mf_ir),
+        std::ostream_iterator<double>(out," ")
+    ); out << std::endl;
+
+    md_iter_range_type md_ir = md_type::get(degree1);
+
+    out << " -> multi_degree<" << d << ">";
+    out << "::degree(" << degree1 << ")" << std::endl;
+    copy(
+        boost::begin(md_ir),
+        boost::end(md_ir),
+        std::ostream_iterator<double>(out," ")
+    ); out << std::endl;
+    mp_iter_range_type mp_ir = mp_type::get(degree1);
+
+    out << " -> multi_p2df<" << d << ">";
+    out << "::degree(" << degree1 << ")" << std::endl;
+    copy(
+        boost::begin(mp_ir),
+        boost::end(mp_ir),
+        std::ostream_iterator<double>(out," ")
+    ); out << std::endl;
+
+    out << "<-" << std::endl;
+
+};
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_factorial.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::multi_factorial.h                             //
+//                                                                          //
+//  (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 LIBS_MONOMIALS_HORNER_EXAMPLE_MULTI_FACTORIAL_H_ER_2009
+#define LIBS_MONOMIALS_HORNER_EXAMPLE_MULTI_FACTORIAL_H_ER_2009
+#include <ostream>
+
+void example_multi_factorial(std::ostream&);
+
+
+#endif
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,47 @@
+///////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::multi_indexes.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/monomials_horner/multi_indexes.hpp>
+
+void example_multi_indexes(std::ostream& out){
+    out << "-> example_multi_indexes" << std::endl;
+
+    using namespace boost;
+    using namespace monomials_horner;
+
+    typedef multi_indexes<3>      mi_type;
+    typedef mi_type::iter_type          mi_iter_type;
+    typedef mi_type::iter_range_type    mi_iter_range_type;
+
+    unsigned int degree1 = 2;
+
+    mi_iter_range_type ir = mi_type::get(degree1);
+
+    for(mi_iter_type i = boost::begin(ir); i<boost::end(ir); i++){
+        copy(
+            boost::begin(*i),
+            boost::end(*i),
+            std::ostream_iterator<double>(out," ")
+        ); out << std::endl;
+    }out << std::endl;
+
+    ir = mi_type::get(degree1+1);//TODO bug if say get(degree+1)
+
+    for(mi_iter_type i = boost::begin(ir); i<boost::end(ir); i++){
+        copy(
+            boost::begin(*i),
+            boost::end(*i),
+            std::ostream_iterator<double>(out," ")
+        ); out << std::endl;
+    }
+
+    out << "<-" << std::endl;
+};
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/example/multi_indexes.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// monomials_horner::example::multi_indexes.h                               //
+//                                                                          //
+//  (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 LIBS_MONOMIALS_HORNER_EXAMPLE_MULTI_INDEXES_H_ER_2009
+#define LIBS_MONOMIALS_HORNER_EXAMPLE_MULTI_INDEXES_H_ER_2009
+#include <ostream>
+
+void example_multi_indexes(std::ostream&);
+
+#endif
Added: sandbox/statistics/monomials_horner/libs/monomials_horner/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/monomials_horner/libs/monomials_horner/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,21 @@
+//////////////////////////////////////////////////////////////////////////////
+// example/main.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)
+#include <iostream>
+#include <libs/monomials_horner/example/monomials.h>
+#include <libs/monomials_horner/example/multi_indexes.h>
+#include <libs/monomials_horner/example/multi_factorial.h>
+
+int main()
+{
+    
+
+    example_monomials(std::cout);
+    example_multi_indexes(std::cout);
+    example_multi_factorial(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/mpl/boost/mpl/nested_type.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/mpl/boost/mpl/nested_type.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+////////////////////////////////////////////////////////////////////////////////
+// nested_type.hpp                                                            //  
+////////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_MPL_NESTED_TYPE_HPP_ER_2009
+#define BOOST_MPL_NESTED_TYPE_HPP_ER_2009
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/has_xxx.hpp>
+#include <boost/mpl/eval_if.hpp>
+
+namespace boost{
+namespace mpl{
+    BOOST_MPL_HAS_XXX_TRAIT_DEF(type);
+
+// Provided by Steven Watanabe in
+// 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/statistics/nn1/boost/nn1/algorithm/find.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/boost/nn1/algorithm/find.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,65 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::algorithm::find.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_NN1_ALGORITHM_FIND_HPP_ER_2009
+#define BOOST_NN1_ALGORITHM_FIND_HPP_ER_2009
+#include <numeric>
+#include <boost/type_traits.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/mpl/nested_type.hpp>
+#include <boost/nn1/algorithm/min_element.hpp>
+
+namespace boost{
+namespace nn1{
+
+    // Finds the nearest neighbour (nn1) in a sequence, and assigns the corres- 
+    // ponding distance to a variable.
+    //
+    // Requirements:
+    // Let F_x = F<X>, Y an abitrary type, 
+    // F_x f(x);    
+    // f(y)           returns the distance from x to y.
+    //
+    // Operations:
+    // find(b,e,x,m) returns the nn1 to x in [b,e) and its distance
+    // is put in m.
+    template<
+        template<typename> class F,
+        typename It,
+        typename X,
+        typename T
+    >
+    It find(It b, It e, const X& x, T& m){ 
+        typedef typename boost::iterator_value<It>::type value_t;
+        
+        typedef F<X> arg_;
+        typedef typename boost::mpl::nested_type<arg_>::type dist_;
+        dist_ dist(x);
+    
+        return nn1::min_element(
+            make_transform_iterator(b,dist),
+            make_transform_iterator(e,dist),
+            m
+        ).base();
+    }
+
+    template<
+        template<typename> class F,
+        typename It,
+        typename V
+    >
+    It find(It b, It e, const V& x){ 
+        typedef typename iterator_value<It>::type const_val_;
+        typedef typename remove_const<const_val_>::type val_; 
+        val_ m;
+        return find<F>(b,e,x,m);
+    }
+
+}// nn1
+}// boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/boost/nn1/algorithm/find_if.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/boost/nn1/algorithm/find_if.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,49 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::algorithm::find_if.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_NN1_ALGORITHM_FIND_IF_HPP_ER_2009
+#define BOOST_NN1_ALGORITHM_FIND_IF_HPP_ER_2009
+#include <numeric>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/nn1/algorithm/find.hpp>
+
+namespace boost{
+namespace nn1{
+
+    // Same as nn1 with the addition of a threhold, t. If the the distance to
+    // the nearest neighbour (nn1) is less than t, e is returned
+    template<
+        template<typename> class F,
+        typename It,
+        typename X,
+        typename T
+    >
+    It find_if(It b, It e, const X& x, T& m, const T& t){ 
+        It it = find<F>(b,e,x,m);
+        if(m<t){
+            return it;
+        }else{
+            return e;
+        }
+    }       
+
+    template<
+        template<typename> class F,
+        typename It,
+        typename X,
+        typename T
+    >
+    It find_if(It b, It e, const X& x,const T& t){ 
+        typedef typename iterator_value<It>::type cv_val_;
+        typedef typename remove_const<cv_val_>::type val_; 
+        T m;
+        return find_if<F>(b,e,x,m,t);
+    }    
+
+}// nn1
+}// boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/boost/nn1/algorithm/min_element.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/boost/nn1/algorithm/min_element.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::algorithm::min_element.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_NN1_ALGORITHM_MIN_ELEMENT_HPP_ER_2009
+#define BOOST_NN1_ALGORITHM_MIN_ELEMENT_HPP_ER_2009
+#include <limits>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/numeric/conversion/bounds.hpp>
+#include <boost/limits.hpp>
+#include <iostream>
+
+namespace boost{
+namespace nn1{
+
+// This is a rewrite of std::min_element with one additional argument, m, which
+// is assigned the min value of *i over [first,last).
+//
+// This saves one dereferencing operation compared with *std::min_element(
+// first,last) which may be worthwhile if first and last are obtained through
+// costly iterator adaptors.
+
+template <typename It,typename V>
+It min_element(It first, It last,V& min_value) {
+    typedef typename iterator_value<It>::type value_type;
+
+    // TODO see about enable_if/disable_if
+    static bool has_inf = std::numeric_limits<V>::has_infinity;
+    static V inf_if = std::numeric_limits<V>::infinity(); 
+    static V highest = boost::numeric::bounds<V>::highest();
+    static V inf_ = has_inf? inf_if : highest;
+    
+    // TODO concept check
+    // 1) It is ForwardIterator
+    // 2) value_type < V comparable
+    
+    min_value = inf_;
+    value_type value;
+    It result = first;
+    while (first != last){
+        value = (*first);
+        if (value < min_value){
+            min_value = value;
+            result = first;
+        }
+
+        ++first;
+    }
+    return result;
+}
+
+
+}//algorithm
+}//boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/boost/nn1/detail/ui_abs_to.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/boost/nn1/detail/ui_abs_to.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,57 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::detail::ui_abs.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_NN1_DETAIL_UI_ABS_HPP_ER_2009
+#define BOOST_NN1_DETAIL_UI_ABS_HPP_ER_2009
+#include <cmath>
+#include <boost/call_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace nn1{
+namespace detail{
+
+// Functor that computes the distance to an internaly stored variable.
+// Used by examples in this library.
+template<typename T>
+class ui_abs_to{
+    typedef typename remove_reference<T>::type const_t_;
+    public:
+    typedef typename remove_const<const_t_>::type result_type;
+    BOOST_MPL_ASSERT((
+        boost::is_unsigned<result_type>
+    ));
+    
+    ui_abs_to(typename call_traits<T>::param_type x):x_(x){}
+    ui_abs_to& operator=(const ui_abs_to& that){
+        if(&that!=this){
+            typedef is_reference<T> is_ref_;
+            BOOST_MPL_ASSERT(mpl::not_<is_ref_>);
+        }
+        return *this;
+    }
+    
+    template<typename U>
+    result_type operator()(const U& y)const{
+        typedef typename boost::remove_reference<T>::type arg_;
+        BOOST_MPL_ASSERT((
+            boost::is_unsigned<U>
+        ));
+        return (y<x_)? (x_ - y): (y - x_);
+    }
+
+    private:
+    typename call_traits<T>::value_type x_;
+};
+
+        
+}// detail
+}// nn1
+}// boost
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/boost/nn1/functional/find_if.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/boost/nn1/functional/find_if.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,111 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::functional::find_if.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_NN1_FUNCTIONAL_FIND_IF_HPP_ER_2009
+#define BOOST_NN1_FUNCTIONAL_FIND_IF_HPP_ER_2009
+#include <algorithm>
+#include <limits>
+#include <boost/numeric/conversion/bounds.hpp>
+#include <boost/limits.hpp>
+#include <boost/nn1/algorithm/find_if.hpp>
+
+namespace boost{
+namespace nn1{
+namespace functional{ // to avoid ambiguity with algo by the same name
+
+// algorithm::find_if made into a functor
+template<template<typename F> class, typename T>
+class find_if{
+    static bool has_inf;
+    static T inf_if; 
+    static T highest;
+    static T inf_;
+
+    public:
+    
+    // Constructor
+    find_if();
+    find_if(const T& t);
+    find_if(const find_if& that);
+    find_if& operator=(const find_if& that);
+    
+    // Update
+    template<typename It,typename X>
+    It operator()(It b,It e,const X& x)const;
+    
+    // Query
+    const T& min_value()const;
+    const T& threshold()const;
+    
+    private:
+    mutable T m_;
+    T t_;
+};
+
+// Static
+template<template<typename> class F,typename T>
+bool find_if<F,T>::has_inf = std::numeric_limits<T>::has_infinity;
+
+template<template<typename> class F,typename T>
+T find_if<F,T>::inf_if = std::numeric_limits<T>::infinity(); 
+
+template<template<typename> class F,typename T>
+T find_if<F,T>::highest = boost::numeric::bounds<T>::highest();
+
+template<template<typename> class F,typename T>
+T find_if<F,T>::inf_  = find_if<F,T>::has_inf? 
+    find_if<F,T>::inf_if : find_if<F,T>::highest;
+    
+// Constructor
+template<template<typename> class F,typename T>
+find_if<F,T>::find_if():m_(inf_),t_(inf_){}
+
+template<template<typename> class F,typename T>
+find_if<F,T>::find_if(const T& t)
+:m_(inf_),t_(t){}
+
+template<template<typename> class F,typename T>
+find_if<F,T>::find_if(const find_if& that)
+:m_(that.m_),t_(that.t_){}
+
+template<template<typename> class F,typename T>
+typename find_if<F,T>::find_if& 
+find_if<F,T>::operator=(const find_if& that){
+    if(&that!=this){
+        m_ = that.m_;
+        t_ = that.t_;
+    }
+    return *this;
+}
+
+// Update
+
+template<template<typename> class F,typename T>
+template<typename It,typename X>
+It find_if<F,T>::operator()(It b,It e,const X& x)const{
+    return nn1::find_if<F,It,X,T>(
+        b, 
+        e, 
+        x, 
+        m_, 
+        this->threshold()
+    );
+}
+
+// Access
+
+template<template<typename> class F,typename T>
+const T& find_if<F,T>::min_value()const{ return m_; }
+
+template<template<typename> class F,typename T>
+const T& find_if<F,T>::threshold()const{ return t_; }
+
+}// functional
+}// nn1
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/libs/nn1/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/libs/nn1/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// nn1::doc::readme                                                         //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ tools related to finding a nearest neighbor.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/ 
+/sandbox/statistics/mpl/ 
+/sandbox/statistics/functional/
+
+[ History ]
+
+July 2009 : Current version
+
+
Added: sandbox/statistics/nn1/libs/nn1/example/find_if.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/libs/nn1/example/find_if.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,49 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::example::find_if.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 <boost/foreach.hpp>
+//#include <boost/nn1/find_nn1.hpp>//temporary
+#include <boost/nn1/algorithm/find_if.hpp>
+#include <boost/nn1/detail/ui_abs_to.hpp>
+#include <libs/nn1/example/find_if.h>
+
+void nn1_example_find_if(std::ostream& out){
+
+    out << "-> nn1_example_find_if : ";
+    using namespace boost;
+    using namespace nn1;
+    
+    typedef unsigned val_; //Do not change
+    typedef std::vector<val_> vec_;
+    const unsigned n = 2;
+        
+    vec_ vec(n);
+    {
+        for(unsigned i = 0; i<n; i++){
+            vec[i] = i;
+        } 
+    }
+    
+    val_ t = 1;
+    BOOST_FOREACH(val_ i,vec){
+        val_ j = *find_if<nn1::detail::ui_abs_to>(
+            begin(vec),end(vec),i,t);
+        BOOST_ASSERT(j==i);
+    }
+
+    t = 0;
+    BOOST_FOREACH(val_ i,vec){
+        BOOST_ASSERT(
+            find_if<nn1::detail::ui_abs_to>(
+                begin(vec),end(vec),i,t) == end(vec)
+        );
+    }
+    
+    out << "<-" << std::endl;
+
+}
Added: sandbox/statistics/nn1/libs/nn1/example/find_if.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/libs/nn1/example/find_if.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// nn1::example::find_if.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_NN1_EXAMPLE_FIND_IF_HPP_ER_2009
+#define LIBS_NN1_EXAMPLE_FIND_IF_HPP_ER_2009
+#include <ostream>
+
+void nn1_example_find_if(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/nn1/libs/nn1/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/nn1/libs/nn1/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,9 @@
+#include <iostream>
+#include <libs/nn1/example/find_if.h>
+
+int main(){
+
+    nn1_example_find_if(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/non_param/boost/non_param/algorithm/cdf_empirical_cdf_differences.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/boost/non_param/algorithm/cdf_empirical_cdf_differences.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,126 @@
+//////////////////////////////////////////////////////////////////////////////
+// non_param::algorithm::cdf_empirical_cdf_differences.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_NON_PARAM_ALGORITHM_CDF_EMPIRICAL_CDF_DIFFERENCES_HPP_ER_2009
+#define BOOST_NON_PARAM_ALGORITHM_CDF_EMPIRICAL_CDF_DIFFERENCES_HPP_ER_2009
+#include <vector>
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <boost/type_traits/function_traits.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <ext/algorithm>
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/iterator/counting_iterator.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/scalar_dist/fun_wrap/cdf.hpp>
+#include <boost/scalar_dist/meta/bind_delegate.hpp>
+#include <boost/scalar_dist/algorithm/transform.hpp>
+
+namespace boost{
+namespace non_param{
+
+    // Computes {G_i-F_n(x[i]):i=0,...,n-1}, 
+    // sorted sample.
+    //
+    // Requirements:
+    // *[b_cdf,e_cdf) = {F(x[i]): x[i]<=x[i+1], i=0,...,n-1 }
+    template<typename InIt,typename OutIt>
+    OutIt cdf_empirical_cdf_differences(
+        InIt b_cdf, 
+        InIt e_cdf, 
+        OutIt out
+    );
+
+    // Same as cdf_empirical_cdf_differences but computes the cdf on the fly
+    //
+    // Requirements:
+    // *[b_x,e_x) = {x[i]: x[i]<=x[i+1], i=0,...,n-1 }
+    template<typename D,typename InIt,typename OutIt>
+    OutIt cdf_empirical_cdf_differences(
+        const D& dist,
+        InIt b_x,
+        InIt e_x,
+        OutIt out
+    );
+
+    // Implementation //
+
+    template<typename InIt,typename OutIt>
+    OutIt
+    cdf_empirical_cdf_differences(
+        InIt b_cdf,  
+        InIt e_cdf,  
+        OutIt out
+    ){
+        typedef typename iterator_value<InIt>::type value_t;
+        typedef typename iterator_difference<InIt>::type diff_t;
+        diff_t diff = std::distance(b_cdf,e_cdf);
+        value_t n = numeric::converter<value_t,diff_t>::convert(diff);
+        typedef numeric::converter<value_t,unsigned> conv_;
+
+        return std::transform(
+            counting_iterator<unsigned>(0),
+            counting_iterator<unsigned>(diff),
+            b_cdf,
+            out,
+            // TODO lambda expression might be cleaner:
+            bind<value_t>( 
+                &fabs,
+                bind<value_t>(
+                    std::minus<value_t>(),
+                    bind<value_t>(
+                        std::divides<value_t>(),
+                        bind<value_t>(
+                            numeric::converter<value_t,unsigned>(),
+                            _1
+                        ),
+                        n
+                    ),
+                    _2
+                )
+            )
+        );
+    }
+
+    template<typename D,typename InIt,typename OutIt>
+    OutIt
+    cdf_empirical_cdf_differences(
+        const D& dist,
+        InIt b_x,
+        InIt e_x,
+        OutIt out
+    ){
+        if(!is_sorted(b_x,e_x)){
+            static const char* msg 
+                = "cdf_empirical_cdf_differences : [b_x,e_x) not sorted";
+            throw std::runtime_error(
+                msg
+            );
+        }
+        typedef math::bind_delegate<D>                  meta_;
+        typedef typename math::bind_delegate<D>::type   deleg_;
+        deleg_ d = meta_::template make<math::fun_wrap::cdf_>(dist);
+
+        return cdf_empirical_cdf_differences(
+            make_transform_iterator(b_x,d),
+            make_transform_iterator(e_x,d),
+            out
+        );
+    }
+
+}// math
+}// boost
+
+#endif
Added: sandbox/statistics/non_param/boost/non_param/algorithm/kolmogorov_smirnov_distance.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/boost/non_param/algorithm/kolmogorov_smirnov_distance.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,53 @@
+//////////////////////////////////////////////////////////////////////////////
+// non_param::algorithm::kolmogorov_smirnov_distance.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_NON_PARAM_ALGORITHM_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
+#define BOOST_NON_PARAM_ALGORITHM_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
+#include <vector>
+#include <boost/range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+
+namespace boost{
+namespace non_param{
+
+    // *[b_x,e_x) represents a random sample (not necessarily sorted)
+    template<typename D,typename InIt>
+    typename iterator_value<InIt>::type
+    kolmogorov_smirnov_distance(
+        const D& dist,
+        InIt b_x,
+        InIt e_x
+    );
+
+    // Implementation //
+    
+    template<typename D,typename InIt>
+    typename iterator_value<InIt>::type
+    kolmogorov_smirnov_distance(
+        const D& dist,
+        InIt b_x,
+        InIt e_x
+    ){
+        typedef typename iterator_value<InIt>::type val_;
+        typedef std::vector<val_> vals_;
+        vals_ vals(1); 
+        sequential_kolmogorov_smirnov_distance(
+            dist,
+            b_x,
+            e_x,
+            1,
+            boost::begin(vals)
+        );        
+        return vals.back();
+    }
+
+}// non_param
+}// boost
+
+#endif
Added: sandbox/statistics/non_param/boost/non_param/algorithm/proportion_less_than.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/boost/non_param/algorithm/proportion_less_than.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,40 @@
+///////////////////////////////////////////////////////////////////////////////
+// non_param::algorithm::proportion_less_than.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_NON_PARAM_ALGORITHM_PROPORTION_LESS_THAN_HPP_ER_2009
+#define BOOST_NON_PARAM_ALGORITHM_PROPORTION_LESS_THAN_HPP_ER_2009
+#include <numeric>
+#include <functional>
+#include <boost/lambda/lambda.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+
+namespace boost{
+namespace algorithm{
+
+    // Returns the proportions of elements in *[b,e) whose value is less than x
+    //
+    // Was motivated by the Cook-Gelman validation method
+    template<typename InIt>
+    typename iterator_value<InIt>::type
+    proportion_less_than(
+        InIt b,
+        InIt e,
+        typename iterator_value<InIt>::type x
+    ){
+        typedef typename iterator_value<InIt>::type value_type;
+        value_type m = static_cast<value_type>(
+            std::count_if(b, e, (lambda::_1<x))
+        );
+        value_type n = static_cast<value_type>(
+            std::distance(b,e)
+        );
+        return m / n;
+    }
+
+}// algorithm
+}// boost
+#endif
Added: sandbox/statistics/non_param/boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,94 @@
+//////////////////////////////////////////////////////////////////////////////
+// non_param::algorithm::sequential_kolmogorov_smirnov_distance.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_NON_PARAM_ALGORITHM_SEQUENTIAL_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
+#define BOOST_NON_PARAM_ALGORITHM_SEQUENTIAL_KOLMOGOROV_SMIRNOV_DISTANCE_HPP_ER_2009
+#include <vector>
+#include <string>
+#include <stdexcept>
+#include <algorithm>
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+
+#include <boost/non_param/algorithm/cdf_empirical_cdf_differences.hpp>
+
+namespace boost{
+namespace non_param{
+
+    // Computes the ks-distance for each of 
+    // i = 0        i=1                i=k-1
+    // [x[0],x[m]), [x[0],x[2m]), ..., [x[0],x[n]), m = n/k
+    //
+    // Requirements:
+    // [b_x,e_x) is the empirical sample as originally drawn i.e. NOT SORTED
+    template<typename D,typename It,typename ItO>
+    ItO sequential_kolmogorov_smirnov_distance(
+        const D& dist,
+        It b_x,
+        It e_x,
+        typename iterator_difference<It>::type k,
+        ItO i_o
+    );
+
+    // Implementation //
+
+    template<typename D,typename It,typename ItO>
+    ItO sequential_kolmogorov_smirnov_distance(
+        const D& dist,
+        It b_x,
+        It e_x, 
+        typename iterator_difference<It>::type k,
+        ItO i_o
+    ){
+        typedef typename iterator_difference<It>::type  diff_;
+        typedef typename iterator_value<It>::type       val_;
+        typedef std::vector<val_>                       vals_;
+        typedef typename range_iterator<vals_>::type    it_val_;
+        if( b_x == e_x ){ return i_o; }
+        diff_ diff = std::distance( b_x, e_x);
+        if(diff % k != 0){ 
+            static const char* msg = strcpy(
+                "sequential_kolmogorov_smirnov_distance",
+                "diff = %1% not multiple of k = %2%."
+            );
+            format f(msg); f % diff % k;
+            throw std::runtime_error(f.str());  
+        }
+        vals_ cdfs(diff);
+        vals_ r_x; r_x.reserve(diff);
+        diff_ delta = diff / k;
+        
+        It i_x = b_x;
+        while(i_x<e_x){
+            std::advance(i_x,delta);
+            r_x.clear();
+            std::copy(
+                b_x,i_x,std::back_inserter(r_x)
+            );
+            std::sort(boost::begin(r_x),boost::end(r_x));
+            it_val_ e_cdf = cdf_empirical_cdf_differences(
+                dist,boost::begin(r_x),boost::end(r_x),boost::begin(cdfs)
+            );
+            *i_o = (
+                *(
+                    std::max_element(
+                        boost::begin(cdfs),
+                        e_cdf
+                    )
+                )
+            );
+            ++i_o;
+        }
+        return i_o;
+    }
+    
+}// non_par
+}// boost
+
+#endif
Added: sandbox/statistics/non_param/libs/non_param/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/libs/non_param/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,34 @@
+//////////////////////////////////////////////////////////////////////////////
+// non_param::doc::readme                                                   //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ algorithms that compute non-parametric statistics.For example, 
+    kolmogorov_smirnov_distance(
+        dist,
+        b_x,
+        e_x
+    );
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+
+[ History ]
+
+July 2009 : Current version
+
Added: sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,39 @@
+///////////////////////////////////////////////////////////////////////////////
+// non_param::example::algorithm::proportion_less_than.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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#include <vector>
+#include <boost/assign/std/vector.hpp>
+#include <boost/non_param/algorithm/proportion_less_than.hpp>
+#include <libs/non_param/example/proportion_less_than.h>
+
+void example_algorithm_proportion_less_than(std::ostream& out){
+    out << "-> example_algorithm_proportion_less_than : ";
+    using namespace boost;
+
+    // Types
+    typedef unsigned val_;
+    typedef std::vector<val_> vec_;
+
+    // Constants
+    const val_ j = 4; 
+
+    // Initialization
+    vec_ vec;
+    {
+        using namespace assign;
+        vec += 0,1,2,3,4,5,6,7,8,9;
+    }
+
+    // Computations
+    algorithm::proportion_less_than(
+        boost::begin(vec),
+        boost::end(vec),
+        j
+    );
+    
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/libs/non_param/example/proportion_less_than.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// example::algorithm::proportion_less_than.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)         //
+/////////////////////////////////////////////////////////////////////////////// 
+#ifndef LIBS_NON_PARAM_EXAMPLE_ALGORITHM_PROPORTION_LESS_THAN_H_ER_2009
+#define LIBS_NON_PARAM_EXAMPLE_ALGORITHM_PROPORTION_LESS_THAN_H_ER_2009
+#include <ostream>
+
+void example_algorithm_proportion_less_than(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/non_param/libs/non_param/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/non_param/libs/non_param/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,11 @@
+#include <iostream>
+#include <libs/non_param/example/proportion_less_than.h>
+
+int main(){
+
+    example_algorithm_proportion_less_than(std::cout);
+
+    // See sandbox/dist_random for other applications.
+
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/random/boost/random/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,72 @@
+//////////////////////////////////////////////////////////////////////////////
+// random::chi_squared.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_RANDOM_CHI_SQUARED_HPP_ER_2009
+#define BOOST_RANDOM_CHI_SQUARED_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/chi_squared.hpp>
+#include <boost/math/distributions/chi_squared.hpp>
+
+namespace boost{
+namespace random{
+
+    template<typename T>
+    class chi_squared_distribution{
+            typedef boost::normal_distribution<T> nd_t;
+        public:
+            typedef typename nd_t::input_type input_type;
+            typedef typename nd_t::result_type result_type;
+
+        chi_squared_distribution(): df_(2) {}
+        chi_squared_distribution(unsigned df): df_(df) {}
+        chi_squared_distribution(const chi_squared_distribution& that)
+        :df_(that.df_){}
+        chi_squared_distribution&
+        operator=(const chi_squared_distribution& that){
+            if(&that!=this){
+                df_ = that.df_;
+            }
+            return *this;
+        }
+
+        template<typename U>
+        result_type
+        operator()(U& urng){
+            typedef boost::variate_generator<U&,nd_t> vg_t;
+            static nd_t nd(0,1);
+            result_type z;
+            result_type res = static_cast<T>(0);
+            for(unsigned i = 0; i<df(); i++){
+                z = nd(urng);
+                res += (z * z);
+            }
+            return res;
+        }
+
+        result_type min () const { return static_cast<result_type>(0); }
+        result_type max () const { return (nd_t().max)(); }
+        unsigned df()const { return df_; }
+        
+        typedef math::chi_squared_distribution<T> math_dist_;
+        
+        operator math_dist_ (){ return math_dist(this->df()); }
+                
+        private:
+            unsigned df_;
+    };
+
+}
+}
+
+
+#endif // CHI_SQUARE_HPP_INCLUDED
Added: sandbox/statistics/random/boost/random/gen_to_random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/gen_to_random.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,103 @@
+///////////////////////////////////////////////////////////////////////////////
+// random::gen_to_random.hpp                                                 //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_RANDOM_GEN_TO_RANDOM_HPP_ER_2009
+#define BOOST_RANDOM_GEN_TO_RANDOM_HPP_ER_2009
+#include <ostream>
+#include <boost/call_traits.hpp>
+
+namespace boost{
+namespace random{
+
+    // Adds the interface of RandomDistribution to a (non-random) generator
+    template<typename G,typename I = typename G::result_type>
+    struct gen_to_random{
+        public:
+
+        typedef I                       input_type;
+        typedef typename G::result_type result_type;
+
+        //Construction
+        gen_to_random();
+        gen_to_random(typename call_traits<G>::param_type );
+        gen_to_random(const gen_to_random&);
+        gen_to_random& operator=(const gen_to_random&);
+
+        template<typename U> result_type operator()(U& u);
+        template<typename U> result_type operator()(U& u)const;
+        
+        // Access
+        typename call_traits<G>::const_reference generator()const;
+
+        private:
+        result_type impl();
+        typename call_traits<G>::value_type g_;
+    };
+
+    template<typename G,typename I>
+    std::ostream& operator<<(std::ostream& os, const gen_to_random<G,I>& g);
+   
+    // Implementation //
+
+    template<typename G,typename I>
+    std::ostream& operator<<(std::ostream& os, const gen_to_random<G,I>& g)
+    {
+        return (os << "gen_to_random(" << g << ')' );
+    }
+        
+    template<typename G,typename I>
+    gen_to_random<G,I>::gen_to_random(){}
+    
+    template<typename G,typename I>
+    gen_to_random<G,I>::gen_to_random(typename call_traits<G>::param_type g)
+    :g_(g){}
+
+    template<typename G,typename I>
+    gen_to_random<G,I>::gen_to_random(const gen_to_random& that)
+    :g_(that.g_){}
+    
+    template<typename G,typename I>
+    gen_to_random<G,I>& 
+    gen_to_random<G,I>::operator=(const gen_to_random& that){
+        if(&that!=this){
+            g_ = that.g_;
+        }
+        return *this;
+    }
+
+
+    template<typename G,typename I>
+    template<typename U> 
+    typename gen_to_random<G,I>::result_type 
+    gen_to_random<G,I>::operator()(U& u){
+        return (this->impl)();
+    }
+
+    template<typename G,typename I>
+    template<typename U> 
+    typename gen_to_random<G,I>::result_type 
+    gen_to_random<G,I>::operator()(U& u)const{
+        return (this->impl)();
+    }
+
+    template<typename G,typename I>
+    typename call_traits<G>::const_reference 
+    gen_to_random<G,I>::generator()const{
+        return (this->g_);
+    }
+
+    template<typename G,typename I>
+    typename gen_to_random<G,I>::result_type 
+    gen_to_random<G,I>::impl(){
+        return (this->g_)();
+    }
+
+
+}// random
+}// boost
+
+#endif
Added: sandbox/statistics/random/boost/random/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,17 @@
+///////////////////////////////////////////////////////////////////////////////
+// random::include.hpp                                                       //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_RANDOM_INCLUDE_HPP_ER_2009
+#define BOOST_RANDOM_INCLUDE_HPP_ER_2009
+
+#include <boost/random/chi_squared.hpp>
+#include <boost/random/gen_to_random.hpp>
+#include <boost/random/students_t.hpp>
+#include <boost/random/location_scale.hpp>
+#include <boost/random/ref_distribution.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/random/boost/random/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,68 @@
+//////////////////////////////////////////////////////////////////////////////
+// random::location_scale.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_RANDOM_LOCATION_SCALE_HPP_ER_2009
+#define BOOST_RANDOM_LOCATION_SCALE_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+//#include <boost/random/uniform_real.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/chi_squared.hpp>
+namespace boost{
+namespace random{
+
+    // Samples from a location-scale distribution
+    //
+    // X = sigma Z + mu
+    template<typename Z>
+    class location_scale_distribution{
+        public:
+            typedef typename remove_cv<
+                typename remove_reference<Z>::type
+            >::type z_type;
+            typedef typename z_type::input_type input_type;
+            typedef typename z_type::result_type result_type;
+
+        location_scale_distribution(){}
+        location_scale_distribution(
+            typename call_traits<Z>::param_type z,
+            const result_type& mu,
+            const result_type& sigma
+        )
+        :z_(z),mu_(mu),sigma_(sigma){}
+
+        template<typename U>
+        result_type operator()(U& urng){ return (this->impl(urng)); }
+
+        template<typename U>
+        result_type operator()(U& urng)const{ return (this->impl(urng)); }
+
+        const result_type& mu()const{ return mu_; }
+        const result_type& sigma()const{ return sigma_; }
+        const Z& z(){ return z_ ;}
+
+        private:
+        typename call_traits<Z>::value_type z_;
+        result_type mu_;
+        result_type sigma_;
+        template<typename U>
+        result_type impl(U& urng){
+            return (this->mu()) + (this->sigma()) * (this->z_)(urng);
+        }
+            
+    };
+
+
+}// random
+}// boost
+
+#endif
Added: sandbox/statistics/random/boost/random/multinomial_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/multinomial_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,163 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::multinomial_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_RANDOM_MULTINOMIAL_DISTRIBUTION_HPP_ER_2009
+#define BOOST_RANDOM_MULTINOMIAL_DISTRIBUTION_HPP_ER_2009
+#include <algorithm>
+#include <numeric>
+#include <cmath>
+#include <stdexcept>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/random/uniform_real.hpp>
+#include <boost/utility/result_of.hpp>
+
+namespace boost{
+namespace random{
+
+// Usage:
+// typedef multinomial_distribution<> rmult_;
+// typedef rmult_::value_type         value_type;
+// typedef rmult_::result_type        idx_;
+//
+// Let urng model UniformRandomNumberGenerator and weights a sequence whose 
+// elements type is convertible to value_type:
+//
+// rmult_ rmult(weights);
+// idx_ idx = rmult(urng);
+template<typename Ur = uniform_real<double> >
+class multinomial_distribution{
+    typedef Ur                                          unif_t;
+    public:
+    typedef typename unif_t::input_type                 input_type;
+    typedef typename unif_t::result_type                value_type;
+
+    private:
+    typedef std::vector<value_type>                     cont_t;
+
+    public:
+    typedef typename range_difference<cont_t>::type     result_type;
+
+    // Construction
+    multinomial_distribution();
+    
+    // Passing sorted from large to small weights will speed up execution. 
+    template<typename R>
+    multinomial_distribution( const R& unnormalized_weights );
+    multinomial_distribution( const multinomial_distribution& that );
+    multinomial_distribution&
+    operator=(const multinomial_distribution& that);
+
+    // Draw
+    template<typename U> result_type operator()(U& urng)const;
+
+    // Access
+    const cont_t& cumulative_weights()const;
+    value_type normalizing_constant()const;
+
+    // TODO os/is
+
+    private:
+    cont_t cum_sums_;
+    template<typename R>void set(const R& unnormalized_weights);
+};
+
+
+// Implementation //
+
+    // Construction
+    template<typename Ur>
+    multinomial_distribution<Ur>::multinomial_distribution() : cum_sums_(){}
+
+    template<typename Ur>
+    template<typename R>
+    multinomial_distribution<Ur>::multinomial_distribution( 
+        const R& unnormalized_weights 
+    )
+    {
+        set(unnormalized_weights);
+    }
+    
+    template<typename Ur>
+    multinomial_distribution<Ur>::multinomial_distribution( 
+        const multinomial_distribution& that 
+    )
+    :cum_sums_(that.cum_sums_){}
+    
+    template<typename Ur>
+    multinomial_distribution<Ur>&
+    multinomial_distribution<Ur>::operator=(
+        const multinomial_distribution& that
+    ){
+        if(&that!=this){
+            this->cum_sums_ = that.cum_sums_;
+        }
+        return *this;
+    }
+    
+    template<typename Ur>
+    template<typename U>
+    typename multinomial_distribution<Ur>::result_type 
+    multinomial_distribution<Ur>::operator()(U& urng)const{
+        unif_t unif(static_cast<value_type>(0),normalizing_constant());
+        typedef typename range_iterator<const cont_t>::type iter_;
+        value_type u = unif(urng);
+        iter_ i = std::lower_bound(
+            boost::begin(this->cum_sums_),
+            boost::end(this->cum_sums_),
+            u
+        );
+        BOOST_ASSERT(i!=end(cum_sums_));
+        return std::distance(boost::begin(this->cum_sums_),i);
+    }
+    
+    // Access
+    template<typename Ur>
+    const typename multinomial_distribution<Ur>::cont_t&
+    multinomial_distribution<Ur>::cumulative_weights()const{ 
+        return (this->cum_sums_); 
+    }
+    
+    template<typename Ur>
+    typename multinomial_distribution<Ur>::value_type
+    multinomial_distribution<Ur>::normalizing_constant()const{
+        return (this->cum_sums_).back();
+    }
+    
+    template<typename Ur>
+    template<typename R>
+    void multinomial_distribution<Ur>::set(const R& unnormalized_weights){
+        const char* method = "multinormal_distribution::set, error : ";
+        static value_type eps = math::tools::epsilon<value_type>();
+
+        cum_sums_.resize(size(unnormalized_weights));
+        
+        std::partial_sum(
+            boost::begin(unnormalized_weights),
+            boost::end(unnormalized_weights),
+            boost::begin(this->cum_sums_)
+        );
+
+        if(math::isinf(this->normalizing_constant())){
+            std::string str = method;
+            str += "isinf(nc)";  
+            throw std::runtime_error(str);
+        }
+        if(this->normalizing_constant()<eps){
+            std::string str = method;
+            str += "nc = %1% < eps = %2%";
+            format f(str); f%(this->normalizing_constant())%eps;  
+            throw std::runtime_error(f.str());
+        }
+        
+    }
+
+}// random
+}// boost
+
+#endif 
Added: sandbox/statistics/random/boost/random/ref_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/ref_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,124 @@
+///////////////////////////////////////////////////////////////////////////////
+// random::ref_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_RANDOM_REF_RANDOM_DISTRIBUTION_HPP_ER_2009
+#define BOOST_RANDOM_REF_RANDOM_DISTRIBUTION_HPP_ER_2009
+#include <boost/call_traits.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace random{
+
+    // Models RandomDistribution.
+    //
+    // Passing a reference_wrapper as second argument to variate_generator
+    // cannot work because it lacks nested types input_type and result_type.
+    // This class remedies this problem. 
+    //
+    // Rd = T or T& etc. and T must model RandomDistribution
+    template<typename Rd>
+    class ref_distribution{
+        BOOST_MPL_ASSERT((
+            is_reference<Rd>
+        )); //If not, no point in using this class
+        typedef typename remove_reference<Rd>::type  cv_d_;
+        public:
+        typedef typename remove_cv<cv_d_>::type distribution_type;
+    
+        typedef typename distribution_type::input_type input_type;
+        typedef typename distribution_type::result_type result_type;
+
+        ref_distribution(typename call_traits<Rd>::param_type d);
+        ref_distribution(const ref_distribution&);
+        ref_distribution& operator=(const ref_distribution&);
+    
+        template<typename U> result_type operator()(U& urng);
+        template<typename U> result_type operator()(U& urng)const;
+
+        typename call_traits<Rd>::reference distribution();
+        
+        template<typename Rd1>
+        friend std::istream& operator>>(std::ostream&,ref_distribution<Rd1>&);
+
+        private:
+        template<typename U> result_type impl(U& urng);
+        typename call_traits<Rd>::value_type d_;
+    };
+
+    template<typename Rd>
+    std::ostream& operator<<(std::ostream&,const ref_distribution<Rd>&);
+
+    // Implementation //
+
+    template<typename Rd>
+    std::ostream& operator<<(
+        std::ostream& os,const ref_distribution<Rd>& r
+    ){
+        os << r.distribution();
+        return os;
+    }
+
+    template<typename Rd>
+    std::istream& operator>>(
+        std::ostream& is,
+        ref_distribution<Rd>& r
+    ){
+        is >> r.distribution();
+        return is;
+    }
+
+    template<typename Rd>
+    ref_distribution<Rd>::ref_distribution(    
+        typename call_traits<Rd>::param_type d
+    ):d_(d){}
+
+    template<typename Rd>
+    ref_distribution<Rd>::ref_distribution(
+        const ref_distribution& that
+    ):d_(that.d_){}
+
+    template<typename Rd>
+    ref_distribution<Rd>&
+    ref_distribution<Rd>::operator=(const ref_distribution& that){
+        if(&that!=this){
+            d_ = that.d_;
+        }
+        return (*this);
+    }
+    
+    template<typename Rd>
+    template<typename U>
+    typename ref_distribution<Rd>::result_type 
+    ref_distribution<Rd>::operator()(U& urng){
+        return (this->impl(urng));
+    }
+
+    template<typename Rd>
+    template<typename U>
+    typename ref_distribution<Rd>::result_type 
+    ref_distribution<Rd>::operator()(U& urng)const{
+        return (this->impl(urng));
+    }
+
+    template<typename Rd>
+    template<typename U>
+    typename ref_distribution<Rd>::result_type 
+    ref_distribution<Rd>::impl(U& urng){
+        return (this->distribution())(urng);
+    }
+
+
+    template<typename Rd>
+    typename call_traits<Rd>::reference 
+    ref_distribution<Rd>::distribution(){ return d_;}
+        
+    
+
+}// random
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/random/boost/random/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/boost/random/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,56 @@
+//////////////////////////////////////////////////////////////////////////////
+// random::students_t_distribution.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_RANDOM_STUDENTS_T_HPP_ER_2009
+#define BOOST_RANDOM_STUDENTS_T_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <boost/range.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/chi_squared.hpp>
+namespace boost{
+namespace random{
+
+    // Samples from a location-scale distribution
+    template<typename T>
+    class students_t_distribution{
+            typedef boost::normal_distribution<T>           nd_;
+            typedef random::chi_squared_distribution<T>     cs_;
+        public:
+            typedef typename nd_::input_type input_type;
+            typedef typename nd_::result_type result_type;
+
+        students_t_distribution():df_(2){}
+        students_t_distribution(unsigned df):df_(df){}
+
+        template<typename U>
+        result_type
+        operator()(U& urng){
+            static nd_ nd(0,1);
+            static cs_ cs(df_);
+            result_type z = nd(urng);
+            result_type d = cs(urng);
+            d /= static_cast<result_type>(df_);
+            d = sqrt(d);
+            return z / d;
+        }
+
+        unsigned df()const{ return df_; }
+
+        private:
+            unsigned df_;
+    };
+
+
+}// random
+}// boost
+
+#endif
Added: sandbox/statistics/random/libs/random/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/libs/random/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,48 @@
+//////////////////////////////////////////////////////////////////////////////
+// random::doc::readme                                                      //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ that extend the boost::random framework
+
+[ Useful links ]
+
+http://www.boost.org/doc/libs/1_39_0/libs/random/index.html
+
+[ models of RandomDistribution ]
+
+    Let 
+        T           scalar
+        Z, X, U     model RandomDistribution
+
+    Class                           Description
+	chi_squared<T>				
+    students_t_distribution<T>         
+	location_scale<Z>               X = sigma Z + mu
+	multinomial_distribution<U>     Samples indices by their probability
+	ref_distribution<X&>            A reference wrapper
+	gen_to_random<X>                A generator that acts like a RandomDist
+
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+
+[ History ]
+
+July 2009 : Current version
+
Added: sandbox/statistics/random/libs/random/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/random/libs/random/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,11 @@
+
+#include <boost/random/include.hpp>
+
+int main(){
+
+    // Examples can be found in 
+    // sandbox/statistics/dist_random/libs/dist_random/example
+    
+    return 0;
+}
+
Added: sandbox/statistics/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,45 @@
+//////////////////////////////////////////////////////////////////////////////
+// statistics::doc::readme                                                  //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+I welcome feedback including bug reports at erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+    This C++ library provides statistical tools that is intended to integrate 
+    with the STL/Boost framework. 
+    
+[ Themes ]
+
+    It is organized by theme, starting with:
+        adaptive_rejection_sampling
+        arithmetic
+        etc.
+
+[ Inside a theme ]
+        
+     boost/theme/
+     libs/theme/
+     	/doc/readme
+        /example
+        /src/main.cpp
+
+[ Inside boost/theme ]
+
+    Often contains a subset of
+        /algorithm
+        /data
+        /iterator
+        /functional
+    which are named after the STL's subdivisions. 
+                        
+        
+
+                                   
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/accumulate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/accumulate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::algorithm::accumulate.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_SCALAR_DIST_ALGORITHM_ACCUMULATE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_ALGORITHM_ACCUMULATE_HPP_ER_2009
+#include <numeric>
+#include <functional>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/type_traits/function_traits.hpp>
+#include <boost/scalar_dist/meta/has_pdf.hpp>
+
+namespace boost{
+namespace math{
+
+    // Usage
+    // sum_log_pdf = accumulate<std::plus,log_unnormalized_pdf_>(
+    //    dist,begin(vec_x),end(vec_x))
+    template<
+        template<typename> class G, //binary
+        template<typename> class F, //in include.hpp
+        typename D,
+        typename InIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        typename D::value_type
+    >::type
+    accumulate(
+        const D& dist,
+        InIt b,
+        InIt e,
+        typename D::value_type init
+    );
+
+    // Implementation //
+
+    template<
+        template<typename> class G, //binary
+        template<typename> class F, //in include.hpp
+        typename D,
+        typename InIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        typename D::value_type
+    >::type
+    accumulate(
+        const D& dist,
+        InIt b,
+        InIt e,
+        typename D::value_type init
+    ){
+        typedef typename D::value_type val_;
+        return std::accumulate(
+            b,
+            e,
+            init,
+            boost::lambda::bind<val_>(
+                G<val_>(),
+                boost::lambda::_1,
+                boost::lambda::bind<val_>(
+                    F<D>::instance,
+                    dist,
+                    boost::lambda::_2
+                )
+            )
+        );
+    }
+
+}
+}
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::algorithm::transform.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_SCALAR_DIST_ALGORITHM_TRANSFORM_HPP_ER_2009
+#define BOOST_SCALAR_DIST_ALGORITHM_TRANSFORM_HPP_ER_2009
+
+#include <boost/scalar_dist/algorithm/accumulate.hpp>
+#include <boost/scalar_dist/algorithm/transform.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/transform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/algorithm/transform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,141 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::algorithm::transform.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_SCALAR_DIST_ALGORITHM_TRANSFORM_HPP_ER_2009
+#define BOOST_SCALAR_DIST_ALGORITHM_TRANSFORM_HPP_ER_2009
+#include <algorithm>
+#include <boost/bind.hpp>
+#include <boost/type_traits/function_traits.hpp>
+#include <boost/scalar_dist/meta/pointer.hpp>
+#include <boost/scalar_dist/meta/has_pdf.hpp>
+
+namespace boost{
+namespace math{
+
+    // Applies a function (F) to a set of values, whose definition is looked up
+    // in the namespace of the distribution (D)
+    //
+    // Example: F = fun_wrap::log_unnormalized_pdf_
+    template<
+        template<typename> class F,
+        typename D,
+        typename InIt,
+        typename OutIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        OutIt
+    >::type
+    transform(
+        const D& dist,
+        InIt b,
+        InIt e,
+        OutIt i
+    );
+
+    //Example: G = std::plus
+    template<
+        template<typename> class G,
+        template<typename> class F,
+        typename D,
+        typename InIt,
+        typename InIt1,
+        typename OutIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        OutIt
+    >::type
+    transform(
+        const D& dist,
+        InIt b,
+        InIt e,
+        InIt1 b1,
+        OutIt i
+    );
+
+    // Implementation //
+    
+    template<
+        template<typename> class F,
+        typename D,
+        typename InIt,
+        typename OutIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        OutIt
+    >::type
+    transform(
+        const D& dist,
+        InIt b,
+        InIt e,
+        OutIt i
+    ){
+        typedef pointer<D> fp_;
+        typedef typename signature<D>::type sig_;
+        typedef function_traits<sig_> traits_;
+        typedef typename traits_::result_type res_;
+
+        return std::transform(
+            b,
+            e,
+            i,
+            bind<res_>(
+                fp_::template make<F>(),
+                dist,
+                _1
+            )
+        );
+    }
+
+    template<
+        template<typename> class G,
+        template<typename> class F,
+        typename D,
+        typename InIt,
+        typename InIt1,
+        typename OutIt
+    >
+    typename enable_if<
+        has_pdf<D>,
+        OutIt
+    >::type
+    transform(
+        const D& dist,
+        InIt b,
+        InIt e,
+        InIt1 b1,
+        OutIt i
+    ){
+        typedef pointer<D> fp_;
+        typedef typename signature<D>::type sig_;
+        typedef function_traits<sig_> traits_;
+        typedef typename traits_::result_type res_;
+
+        return std::transform(
+            b, //1
+            e,
+            b1,//2
+            i,
+            bind<res_>(
+                G<res_>(),
+                _2,
+                bind<res_>(
+                    fp_::template make<F>(),
+                    dist,
+                    _1
+                )
+            )
+        );
+    }
+
+}
+}
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/cdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/cdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::cdf.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_SCALAR_DIST_FUN_WRAP_CDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_CDF_HPP_ER_2009
+#include <boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace math{
+ 
+    template<typename T,typename D> T cdf(const D& d,const T& x);
+
+    namespace fun_wrap{
+        template<typename D> struct cdf_
+            : detail::fun_wrap<D,math::cdf>{};
+    }
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::detail::fun_wrap.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_SCALAR_DIST_FUN_WRAP_DETAIL_FUN_WRAP_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_DETAIL_FUN_WRAP_HPP_ER_2009
+#include <boost/scalar_dist/meta/pointer.hpp>
+
+namespace boost{
+namespace math{
+namespace detail{
+
+    template<typename D,typename pointer<D>::type f>
+    struct fun_wrap{
+        typedef typename pointer<D>::type type;
+        static type instance;
+    };
+    
+    template<typename D,typename pointer<D>::type f>
+    typename fun_wrap<D,f>::type
+    fun_wrap<D,f>::instance = f;
+    
+}// detail
+}// math
+}// boost
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::include.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_SCALAR_DIST_FUN_WRAP_INCLUDE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_INCLUDE_HPP_ER_2009
+
+#include <boost/scalar_dist/fun_wrap/cdf.hpp>
+#include <boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp>
+#include <boost/scalar_dist/fun_wrap/pdf.hpp>
+#include <boost/scalar_dist/fun_wrap/quantile.hpp>
+#include <boost/scalar_dist/fun_wrap/unnormalized_pdf.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/log_unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,27 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::detail::log_unnormalized_pdf.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_SCALAR_DIST_FUN_WRAP_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#include <boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename D> 
+    T log_unnormalized_pdf(const D& d,const T& x);
+    
+    namespace fun_wrap{    
+        template<typename D>
+        struct log_unnormalized_pdf_ 
+            : detail::fun_wrap<D,math::log_unnormalized_pdf>{};
+    }
+}
+}
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::pdf.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_SCALAR_DIST_FUN_WRAP_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_PDF_HPP_ER_2009
+#include <boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace math{
+        
+    template<typename T,typename D> T pdf(const D& d,const T& x);
+
+    namespace fun_wrap{
+        template<typename D> struct pdf_ : detail::fun_wrap<D,math::pdf>{};
+    }
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/quantile.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/quantile.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::quantile.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_SCALAR_DIST_FUN_WRAP_QUANTILE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_QUANTILE_HPP_ER_2009
+#include <boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename D> T quantile(const D& d,const T& x);
+    
+    namespace fun_wrap{
+        template<typename D> struct quantile_ 
+        : detail::fun_wrap<D,math::quantile>{};
+    }
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/fun_wrap/unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,25 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::fun_wrap::detail::log_unnormalized_pdf.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_SCALAR_DIST_FUN_WRAP_UNNORMALIZED_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_FUN_WRAP_UNNORMALIZED_PDF_HPP_ER_2009
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+#include <boost/scalar_dist/fun_wrap/detail/fun_wrap.hpp>
+
+namespace boost{
+namespace math{
+                
+    namespace fun_wrap{    
+        template<typename D>
+        struct unnormalized_pdf_ 
+            : detail::fun_wrap<D,math::unnormalized_pdf>{};
+    }
+}
+}
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::include.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_SCALAR_DIST_INCLUDE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_INCLUDE_HPP_ER_2009
+
+#include <boost/scalar_dist/unscope/include.hpp>
+#include <boost/scalar_dist/map_pdf/include.hpp>
+#include <boost/scalar_dist/algorithm/include.hpp>
+#include <boost/scalar_dist/fun_wrap/include.hpp>
+#include <boost/scalar_dist/meta/include.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::map_pdf::include.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_SCALAR_DIST_MAP_PDF_INCLUDE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_MAP_PDF_INCLUDE_HPP_ER_2009
+
+#include <boost/scalar_dist/map_pdf/inverse_pdf.hpp>
+#include <boost/scalar_dist/map_pdf/product_pdf.hpp>
+#include <boost/scalar_dist/map_pdf/ratio_pdf.hpp>
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/inverse_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/inverse_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,80 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::map_pdf::inverse_pdf.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_SCALAR_DIST_MAP_PDF_INVERSE_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_MAP_PDF_INVERSE_PDF_HPP_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/utility.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/scalar_dist/meta/has_pdf.hpp>
+
+namespace boost{
+namespace math{
+
+    // Represents the inverse pdf
+    //
+    // D = T or D = T& or D = T*
+    template<typename D>
+    class inverse_pdf{
+        typedef typename remove_reference<
+            typename remove_const<
+                D
+            >::type
+        >::type plain_t;
+    public:
+        typedef typename plain_t::value_type value_type;
+
+        typedef
+            typename call_traits<D>::const_reference
+                result_of_distribution_type;
+
+        explicit inverse_pdf(typename call_traits<D>::param_type d):d_(d){}
+        inverse_pdf(const inverse_pdf& that):d_(that.d_){}
+        inverse_pdf&
+        operator=(const inverse_pdf& that){
+            if(&that!=this){
+                typedef is_reference<D> is_ref_;
+                BOOST_MPL_ASSERT((
+                    mpl::not<is_ref_>
+                ));
+                d_ = that.d_;
+            }
+            return *this;
+        }
+
+        result_of_distribution_type
+        distribution()const{ return d_; }
+
+    private:
+        inverse_pdf();
+        typename call_traits<D>::value_type d_;
+    };
+
+    template<typename D>
+    struct has_pdf< inverse_pdf<D> > : mpl::bool_<true> {};
+
+
+    template<typename D>
+    inverse_pdf<D>
+    make_inverse_pdf(const D& d){ return inverse_pdf<D>(d); }
+
+    template<typename D>
+    typename inverse_pdf<D>::value_type
+    log_unnormalized_pdf(
+        const inverse_pdf<D>& dist,
+        const typename inverse_pdf<D>::value_type& x
+    ){
+        return
+            ( -log_unnormalized_pdf(dist.distribution(),x) );
+    }
+
+}// math
+}// boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/product_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/product_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,92 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::map_pdf::product_pdf.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_SCALAR_DIST_MAP_PDF_PRODUCT_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_MAP_PDF_PRODUCT_PDF_HPP_ER_2009
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/utility.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/scalar_dist/meta/has_pdf.hpp>
+
+namespace boost{
+namespace math{
+
+    // Represents the product of the pdf of two distributions
+    //
+    // A = T or A = T& or A = T*. Likewise for B.
+    template<typename A,typename B>
+    class product_pdf{
+        typedef is_reference<A> is_ref_a_;
+        typedef is_reference<B> is_ref_b_;
+
+        typedef typename remove_reference<
+            typename remove_const<
+                A
+            >::type
+        >::type plain_a_t;
+
+        public:
+        typedef typename plain_a_t::value_type value_type;
+        typedef
+            typename call_traits<A>::const_reference result_of_first_type;
+        typedef
+            typename call_traits<B>::const_reference result_of_second_type;
+
+        product_pdf(){
+            BOOST_MPL_ASSERT(( mpl::not_<is_ref_a_> ));
+            BOOST_MPL_ASSERT(( mpl::not_<is_ref_b_> ));
+        }
+        explicit product_pdf(
+            typename call_traits<A>::param_type a,
+            typename call_traits<B>::param_type b
+        ):a_(a),b_(b){}
+        product_pdf(const product_pdf& that):a_(that.a_),b_(that.b_){}
+
+        product_pdf&
+        operator=(const product_pdf& that){
+            if(&that!=this){
+                BOOST_MPL_ASSERT(( mpl::not_<is_ref_a_> ));
+                BOOST_MPL_ASSERT(( mpl::not_<is_ref_b_> ));
+                a_ = that.a_;
+                b_ = that.b_;
+            }
+            return *this;
+        }
+
+        result_of_first_type first()const{ return a_; }
+        result_of_second_type second()const{ return b_; }
+
+        protected:
+        typename call_traits<A>::value_type a_;
+        typename call_traits<B>::value_type b_;
+    };
+
+    template<typename A,typename B>
+    struct has_pdf< product_pdf<A,B> > : mpl::bool_<true> {};
+
+    template<typename A,typename B>
+    product_pdf<A,B>
+    make_product_pdf(const A& a,const B& b){ return product_pdf<A,B>(a,b); }
+
+    template<typename A,typename B>
+    typename product_pdf<A,B>::value_type
+    log_unnormalized_pdf(
+        const product_pdf<A,B>& dist,
+        const typename product_pdf<A,B>::value_type& x
+    ){
+        return
+            log_unnormalized_pdf(dist.first(),x)
+                + log_unnormalized_pdf(dist.second(),x);
+    }
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/ratio_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/map_pdf/ratio_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,33 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dit::map_pdf::ratio_pdf.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_SCALAR_DIST_MAP_PDF_RATIO_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_MAP_PDF_RATIO_PDF_HPP_ER_2009
+#include <boost/call_traits.hpp>
+#include <boost/scalar_dist/map_pdf/inverse_pdf.hpp>
+#include <boost/scalar_dist/map_pdf/product_pdf.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename A,typename B>
+    struct meta_ratio_pdf{
+        typedef inverse_pdf<B> inv_;
+        typedef product_pdf<A, inv_ > type;
+        static type make(A a,B b){
+            return type(
+                a,
+                inv_(b)
+            );
+         } 
+    };
+
+}
+}
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/bind_delegate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/bind_delegate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,47 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::bind_delegate.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_SCALAR_DIST_META_BIND_DELEGATE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_BIND_DELEGATE_HPP_ER_2009
+#include <boost/function.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/type_traits/function_traits.hpp> 
+#include <boost/scalar_dist/meta/signature.hpp>
+#include <boost/scalar_dist/meta/delegate.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct bind_delegate{
+    
+        typedef math::signature<D>                              sig_;
+        typedef math::delegate<D>                               deleg_;
+        typedef function_traits<typename sig_::type>            traits_;
+        typedef typename traits_::result_type                   result_;
+        typedef typename traits_::arg2_type                     arg2_;
+        typedef result_ sig2_( arg2_ );
+        typedef function<sig2_>                                 type;
+        
+        template<template<typename> class F>
+        static type make(const D& dist){
+            return type(
+                boost::lambda::bind(
+                    deleg_::template make<F>(),
+                    dist,
+                    boost::lambda::_1
+                )
+            );
+        }
+    };
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/delegate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/delegate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::delegate.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_SCALAR_DIST_META_DELEGATE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_DELEGATE_HPP_ER_2009
+#include <boost/function.hpp>
+#include <boost/scalar_dist/meta/signature.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct delegate{
+        typedef typename signature<D>::type     sig_;
+        typedef boost::function<sig_>           type;
+
+        template<template<typename> class F> // F in fun_wrap
+        static type make(){ return type(F<D>::instance); }
+    };
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/distribution_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/distribution_base.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,22 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::distribution_base.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_SCALAR_DIST_META_DISTRIBUTION_BASE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_DISTRIBUTION_BASE_HPP_ER_2009
+#include <boost/mpl/identity.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct distribution_base : mpl::identity<D>{};
+
+}
+}
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/has_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/has_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::is_scalar_dist.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_SCALAR_DIST_META_IS_HAS_PDF_ER_2009
+#define BOOST_SCALAR_DIST_META_IS_HAS_PDF_ER_2009
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D> struct has_pdf 
+        : is_scalar_dist<D> {};
+
+}
+}
+
+#endif
+
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::include.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_SCALAR_DIST_META_INCLUDE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_INCLUDE_HPP_ER_2009
+
+#include <boost/scalar_dist/meta/distribution_base.hpp>
+#include <boost/scalar_dist/meta/delegate.hpp>
+#include <boost/scalar_dist/meta/has_pdf.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/scalar_dist/meta/pointer.hpp>
+#include <boost/scalar_dist/meta/signature.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/is_scalar_dist.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/is_scalar_dist.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+// scalar_dist::is_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_SCALAR_DIST_META_IS_SCALAR_DIST_ER_2009
+#define BOOST_SCALAR_DIST_META_IS_SCALAR_DIST_ER_2009
+#include <boost/mpl/bool.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct is_scalar_dist : mpl::bool_<false> {};
+    // What for? enable_if<is_scalar_dist<D>,T> ..
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/pointer.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/pointer.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::pointer.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_SCALAR_DIST_META_POINTER_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_POINTER_HPP_ER_2009
+#include <boost/scalar_dist/meta/signature.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct pointer{
+        typedef typename signature<D>::type sig_;
+        typedef sig_*                       type;
+
+        template<template<typename> class F>
+        static type make(){ return F<D>::instance; }
+    };
+
+
+}// math
+}// boost
+
+#endif
+
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/meta/signature.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/meta/signature.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::meta::signature.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_SCALAR_DIST_META_SIGNATURE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_META_SIGNATURE_HPP_ER_2009
+
+namespace boost{
+namespace math{
+
+    // Signature for f(dist,x), f = pdf, cdf etc.
+    template<typename D>
+    struct signature{
+        typedef typename D::value_type value_type;
+
+        typedef value_type type(
+            const D&,
+            const value_type&
+        );
+    };
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::unscope::include.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_SCALAR_DIST_UNSCOPE_INCLUDE_HPP_ER_2009
+#define BOOST_SCALAR_DIST_UNSCOPE_INCLUDE_HPP_ER_2009
+
+#include <boost/scalar_dist/unscope/log_unnormalized_pdf.hpp>
+
+#endif
Added: sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/log_unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/boost/scalar_dist/unscope/log_unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,32 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::unscope::log_unnormalized_pdf.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_SCALAR_DIST_UNSCOPE_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#define BOOST_SCALAR_DIST_UNSCOPE_LOG_UNNORMALIZED_PDF_HPP_ER_2009
+#include <boost/utility/enable_if.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+
+namespace boost{
+
+    namespace math{
+        template<typename D,typename T> 
+        T log_unnormalized_pdf(const D& d,const T& x);
+    }
+
+    template<typename D,typename T>
+    typename boost::enable_if<
+        math::is_scalar_dist<D>,
+        T 
+    >
+    log_unnormalized_pdf(const D& d,const T& x){
+        return math::log_unnormalized_pdf<D>(d,x);
+    }
+
+}
+
+#endif
Added: sandbox/statistics/scalar_dist/libs/scalar_dist/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/libs/scalar_dist/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,87 @@
+//////////////////////////////////////////////////////////////////////////////
+// scalar_dist::doc::readme                                                 //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ classes that extend boost/math/distributions by providing 
+
+    - wrappers that decouple the function, such as pdf, from the distribution 
+    to which it is applied.
+    - algorithms that iterate over inputs
+    - mappings of distribution functionals (pdf->1/pdf) 
+
+[ Useful links ]
+
+http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/index.html
+
+[ unscope ]
+
+    pdf, cdf etc. are defined in scope boost::math. Unscope creates a version 
+    defined in scope boost that forwards to that in boost::math. 
+    
+    The rationale for this, is that some function templates in other libraries 
+    in sandbox/statitics apply to scalar distribution and joint distributions 
+    alike, and therefore require a common interface.
+
+[ fun_wrap ]
+
+    Decouples the function, such as pdf, from the distribution D:
+        fun_wrap::cdf_<D>::instance
+
+[ algorithm ]
+
+    Thanks to fun_wrap, we can parameterize algorithms as follows:
+        accumulate<fun_wrap::cdf_>(dist,b_x,e_x);
+        transform<fun_wrap::cdf_>(dist,b_x,e_x,b_f);
+
+[ map_pdf ] 
+
+    Compare a hypothetical function:
+        inverse_pdf(dist,x)
+    to
+        pdf(make_inverse_pdf(dist))
+    The second form, used here, is more economical because we can reuse the 
+    functionality associated with pdf, such as fun_wrap::pdf_. It is also 
+    straightforward to combine mappings:
+        Expression:                 Result type
+        make_ratio_pdf(a,b)         product_pdf<A,inverse_pdf<B> >
+    Usage:
+        pdf(make_ratio_pdf(a,b),x)
+
+
+[ meta ]
+
+    - signature, pointer and delegate are behind fun_wrap's implementation
+    - The meta-functions
+        is_scalar_dist
+        has_pdf
+    distinguish between distributions and objects that aren't but share their
+    functionality (such as those in map_pdf).
+    
+    They are used to manage the overload set non-intrusively (SFINAE), by client
+    libraries, where both scalar and joint dists are valid arguments to 
+    a function template.
+        
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+/sandbox/statistics/standard_distribution/ 
+
+[ History ]
+
+July 2009 : Current version
+
Added: sandbox/statistics/scalar_dist/libs/scalar_dist/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/scalar_dist/libs/scalar_dist/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,7 @@
+int main(){
+
+    // Relevant examples are in 
+    // /sandbox/statistics/standard_distribution/libs/example
+
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::chi_squared.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_CHI_SQUARED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_CHI_SQUARED_HPP_ER_2009
+
+#include <boost/math/distributions/chi_squared.hpp>
+#include <boost/standard_distribution/is_scalar_dist/chi_squared.hpp>
+//#include <boost/standard_distribution/normalizing_constant/chi_squared.hpp>
+#include <boost/standard_distribution/os/chi_squared.hpp>
+#include <boost/standard_distribution/primitives/chi_squared.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/chi_squared.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,21 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::exponential.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_EXPONENTIAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_EXPONENTIAL_HPP_ER_2009
+
+#include <boost/math/distributions/exponential.hpp>
+#include <boost/standard_distribution/is_scalar_dist/exponential.hpp>
+//#include <boost/standard_distribution/normalizing_constant/exponential.hpp>
+#include <boost/standard_distribution/os/exponential.hpp>
+#include <boost/standard_distribution/primitives/exponential.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/exponential.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
+
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::gamma.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_GAMMA_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_GAMMA_HPP_ER_2009
+
+#include <boost/math/distributions/gamma.hpp>
+#include <boost/standard_distribution/is_scalar_dist/gamma.hpp>
+//#include <boost/standard_distribution/normalizing_constant/gamma.hpp>
+#include <boost/standard_distribution/os/gamma.hpp>
+#include <boost/standard_distribution/primitives/gamma.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/gamma.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributons::include.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_INCLUDE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_INCLUDE_HPP_ER_2009
+
+#include <boost/standard_distribution/distributions/chi_squared.hpp>
+#include <boost/standard_distribution/distributions/exponential.hpp>
+#include <boost/standard_distribution/distributions/gamma.hpp>
+#include <boost/standard_distribution/distributions/location_scale.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/standard_distribution/distributions/students_t.hpp>
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,18 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::location_scale.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_LOCATION_SCALE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_LOCATION_SCALE_HPP_ER_2009
+
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+#include <boost/standard_distribution/is_scalar_dist/location_scale.hpp>
+#include <boost/standard_distribution/primitives/location_scale.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::normal.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_NORMAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_NORMAL_HPP_ER_2009
+
+#include <boost/math/distributions/normal.hpp>
+#include <boost/standard_distribution/is_scalar_dist/normal.hpp>
+#include <boost/standard_distribution/normalizing_constant/normal.hpp>
+#include <boost/standard_distribution/os/normal.hpp>
+#include <boost/standard_distribution/primitives/normal.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/normal.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,21 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::students_t.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_STUDENTS_T_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_STUDENTS_T_HPP_ER_2009
+
+#include <boost/math/distributions/students_t.hpp>
+#include <boost/standard_distribution/is_scalar_dist/students_t.hpp>
+//#include <boost/standard_distribution/normalizing_constant/students_t.hpp>
+#include <boost/standard_distribution/os/students_t.hpp>
+#include <boost/standard_distribution/primitives/students_t.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/students_t.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/uniform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/distributions/uniform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::distributions::uniform.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_STANDARD_DISTRIBUTION_DISTRIBUTIONS_UNIFORM_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_DISTRIBUTIONS_UNIFORM_HPP_ER_2009
+
+#include <boost/math/distributions/uniform.hpp>
+#include <boost/standard_distribution/is_scalar_dist/uniform.hpp>
+//#include <boost/standard_distribution/normalizing_constant/uniform.hpp>
+#include <boost/standard_distribution/os/uniform.hpp>
+#include <boost/standard_distribution/primitives/uniform.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/uniform.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::chi_squared.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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_CHI_SQUARED_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_CHI_SQUARED_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/chi_squared.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::chi_squared_distribution<T,P> > 
+        : mpl::bool_<true>{};
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_EXPONENTIAL_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_EXPONENTIAL_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/exponential.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::exponential_distribution<T,P> > 
+        : mpl::bool_<true>{};
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::gamma.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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_GAMMA_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_GAMMA_T_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/gamma.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::gamma_distribution<T,P> > : mpl::bool_<true>{};
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::location_scale.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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_LOCATION_SCALE_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_LOCATION_SCALE_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename D>
+    struct is_scalar_dist< math::location_scale_distribution<D> > 
+        : mpl::bool_<true> {};
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,23 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_NORMAL_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_NORMAL_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/normal.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::normal_distribution<T,P> > 
+        : mpl::bool_<true>{};
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::students_t.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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_STUDENTS_T_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_STUDENTS_T_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/students_t.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::students_t_distribution<T,P> > 
+        : mpl::bool_<true>{};
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/uniform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/is_scalar_dist/uniform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,24 @@
+///////////////////////////////////////////////////////////////////////////////
+// standard_distribution::is_scalar_dist::uniform.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_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_UNIFORM_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_IS_SCALAR_DIST_UNIFORM_ER_2009
+#include <boost/mpl/bool.hpp>
+#include <boost/scalar_dist/meta/is_scalar_dist.hpp>
+#include <boost/math/distributions/uniform.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    struct is_scalar_dist< math::uniform_distribution<T,P> >
+        : mpl::bool_<true>{};
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/normalizing_constant/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/normalizing_constant/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,27 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::normalizing_cosntant::normal.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_STANDARD_DISTRIBUTION_NORMALIZING_CONSTANT_NORMAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_NORMALIZING_CONSTANT_NORMAL_HPP_ER_2009
+#include <cmath>
+#include <boost/math/constants/constants.hpp>
+
+namespace boost{
+namespace math{
+
+template<typename T,typename P>
+T normalizing_constant(const normal_distribution<T,P>& d){
+    static T pi = boost::math::constants::pi<T>;
+    static T two = static_cast<T>(2);
+    return sqrt(two * pi) * d.scale();
+}
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::chi_squared.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_STANDARD_DISTRIBUTION_OS_CHI_SQUARED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_CHI_SQUARED_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/chi_squared.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const chi_squared_distribution<T>& dist)
+    {
+        static const char* msg = "chi_squared(%1%)";
+        format f(msg); f % dist.degrees_of_freedom();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::exponential.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_STANDARD_DISTRIBUTION_OS_EXPONENTIAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_EXPONENTIAL_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/exponential.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const exponential_distribution<T>& dist)
+    {
+        static const char* msg = "exponential(%1%)";
+        format f(msg); f%dist.lambda();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::gamma.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_STANDARD_DISTRIBUTION_OS_GAMMA_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_GAMMA_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/gamma.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const gamma_distribution<T>& dist)
+    {
+        static const char* msg = "gamma(%1%,%2%)";
+        format f(msg); f % dist.shape() % dist.scale();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,20 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::include.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_STANDARD_DISTRIBUTION_OS_CHI_SQUARED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_CHI_SQUARED_HPP_ER_2009
+
+#include <boost/standard_distribution/os/chi_squared.hpp>
+#include <boost/standard_distribution/os/exponential.hpp>
+#include <boost/standard_distribution/os/gamma.hpp>
+#include <boost/standard_distribution/os/normal.hpp>
+#include <boost/standard_distribution/os/students_t.hpp>
+
+// TODO the other distributions
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::normal.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_STANDARD_DISTRIBUTION_OS_NORMAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_NORMAL_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/normal.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const normal_distribution<T>& dist)
+    {
+        static const char* msg = "normal(%1%,%2%)";
+        format f(msg); f % dist.location() % dist.scale();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,31 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::students_t.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_STANDARD_DISTRIBUTION_OS_STUDENTS_T_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_STUDENTS_T_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/students_t.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const students_t_distribution<T>& dist)
+    {
+        static const char* msg = "students_t(%1%)";
+        format f(msg); f%dist.degrees_of_freedom();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/os/uniform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/os/uniform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::os::uniform.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_STANDARD_DISTRIBUTION_OS_UNIFORM_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_OS_UNIFORM_HPP_ER_2009
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/math/distributions/uniform.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T>
+    std::ostream& operator<<(std::ostream& out,
+        const uniform_distribution<T>& dist)
+    {
+        static const char* msg = "uniform(%1%,%2%)";
+        format f(msg); f%dist.lower()%dist.upper();
+        return (out << f.str());
+    }
+    
+}// boost
+}// math
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,122 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::chi_squared.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_STANDARD_DISTRIBUTION_PRIMITIVES_CHI_SQUARED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_CHI_SQUARED_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/chi_squared.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct chi_squared_distribution_primitives 
+        : equality_comparable< chi_squared_distribution_primitives<T> >{
+        T degrees_of_freedom;
+
+        chi_squared_distribution_primitives();
+        template<typename T1,typename P>
+        chi_squared_distribution_primitives(
+            const chi_squared_distribution<T1,P>& that
+        );
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const chi_squared_distribution_primitives&)const;
+
+        template<typename P> operator chi_squared_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< chi_squared_distribution<T,P> >{
+        typedef chi_squared_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    chi_squared_distribution_primitives<T>
+    make_distribution_primitives(const chi_squared_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    chi_squared_distribution_primitives<T>& 
+    operator<<(
+        chi_squared_distribution_primitives<T>& a,
+        const chi_squared_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    chi_squared_distribution_primitives<T>::operator 
+        chi_squared_distribution<T,P> ()const{
+        return chi_squared_distribution<T,P>(this->degrees_of_freedom);
+    }
+
+    template<typename T>
+    chi_squared_distribution_primitives<T>::
+        chi_squared_distribution_primitives()
+    :degrees_of_freedom(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    chi_squared_distribution_primitives<T>::chi_squared_distribution_primitives(
+        const chi_squared_distribution<T1,P>& that
+    )
+    :degrees_of_freedom(that.degrees_of_freedom()){}
+
+    template<typename T>
+    bool chi_squared_distribution_primitives<T>::operator==(
+        const chi_squared_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(
+            this->degrees_of_freedom,
+            b.degrees_of_freedom
+        );
+    }
+
+    template<typename T>
+    template<class A>
+    void chi_squared_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & degrees_of_freedom;
+    }
+
+    template<typename T,typename P>
+    chi_squared_distribution_primitives<T>
+    make_distribution_primitives(const chi_squared_distribution<T,P>& d){
+        return chi_squared_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    chi_squared_distribution_primitives<T>& 
+    operator<<(
+        chi_squared_distribution_primitives<T>& a,
+        const chi_squared_distribution<T1,P>& b
+    ){
+        typedef chi_squared_distribution_primitives<T> a_;
+        a = a_(b.degrees_of_freedom());
+        return a;
+    }
+
+
+}// math
+}// boost
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,121 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::exponential.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_STANDARD_DISTRIBUTION_PRIMITIVES_EXPONENTIAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_EXPONENTIAL_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/exponential.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct exponential_distribution_primitives 
+        : equality_comparable< exponential_distribution_primitives<T> >{
+        T lambda;
+
+        exponential_distribution_primitives();
+        template<typename T1,typename P>
+        exponential_distribution_primitives(
+            const exponential_distribution<T1,P>& that
+        );
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const exponential_distribution_primitives&)const;
+
+        template<typename P> operator exponential_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< exponential_distribution<T,P> >{
+        typedef exponential_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    exponential_distribution_primitives<T>
+    make_distribution_primitives(const exponential_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    exponential_distribution_primitives<T>& 
+    operator<<(
+        exponential_distribution_primitives<T>& a,
+        const exponential_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    exponential_distribution_primitives<T>::operator 
+        exponential_distribution<T,P> ()const{
+        return exponential_distribution<T,P>(this->lambda);
+    }
+
+    template<typename T>
+    exponential_distribution_primitives<T>
+        ::exponential_distribution_primitives()
+    :lambda(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    exponential_distribution_primitives<T>::exponential_distribution_primitives(
+        const exponential_distribution<T1,P>& that
+    )
+    :lambda(that.lambda()){}
+
+    template<typename T>
+    bool exponential_distribution_primitives<T>::operator==(
+        const exponential_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(
+            this->lambda,
+            b.lambda
+        );
+    }
+
+    template<typename T>
+    template<class A>
+    void exponential_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & lambda;
+    }
+
+    template<typename T,typename P>
+    exponential_distribution_primitives<T>
+    make_distribution_primitives(const exponential_distribution<T,P>& d){
+        return exponential_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    exponential_distribution_primitives<T>& 
+    operator<<(
+        exponential_distribution_primitives<T>& a,
+        const exponential_distribution<T1,P>& b
+    ){
+        typedef exponential_distribution_primitives<T> a_;
+        a = a_(b.lambda());
+        return a;
+    }
+
+}// math
+}// boost
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,116 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::gamma.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_STANDARD_DISTRIBUTION_PRIMITIVES_GAMMA_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_GAMMA_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/gamma.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct gamma_distribution_primitives 
+        : equality_comparable< gamma_distribution_primitives<T> >{
+        T shape;
+
+        gamma_distribution_primitives();
+        template<typename T1,typename P>
+        gamma_distribution_primitives(const gamma_distribution<T1,P>& that);
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const gamma_distribution_primitives&)const;
+
+        template<typename P> operator gamma_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< gamma_distribution<T,P> >{
+        typedef gamma_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    gamma_distribution_primitives<T>
+    make_distribution_primitives(const gamma_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    gamma_distribution_primitives<T>& 
+    operator<<(
+        gamma_distribution_primitives<T>& a,
+        const gamma_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    gamma_distribution_primitives<T>::operator 
+        gamma_distribution<T,P> ()const{
+        return gamma_distribution<T,P>(this->shape);
+    }
+
+    template<typename T>
+    gamma_distribution_primitives<T>::gamma_distribution_primitives()
+    :shape(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    gamma_distribution_primitives<T>::gamma_distribution_primitives(
+        const gamma_distribution<T1,P>& that
+    )
+    :shape(that.shape()){}
+
+    template<typename T>
+    bool gamma_distribution_primitives<T>::operator==(
+        const gamma_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(this->shape,b.shape);
+    }
+
+    template<typename T>
+    template<class A>
+    void gamma_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & shape;
+    }
+
+    template<typename T,typename P>
+    gamma_distribution_primitives<T>
+    make_distribution_primitives(const gamma_distribution<T,P>& d){
+        return gamma_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    gamma_distribution_primitives<T>& 
+    operator<<(
+        gamma_distribution_primitives<T>& a,
+        const gamma_distribution<T1,P>& b
+    ){
+        typedef gamma_distribution_primitives<T> a_;
+        a = a_(b.shape());
+        return a;
+    }
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,166 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::location_scale.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_STANDARD_DISTRIBUTION_PRIMITIVES_LOCATION_SCALE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_LOCATION_SCALE_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    // Z is a primitives
+    template<typename Z,typename T>
+    struct location_scale_distribution_primitives 
+        : equality_comparable< location_scale_distribution_primitives<Z,T> >{
+        Z z;
+        T mu;
+        T sigma;
+
+        location_scale_distribution_primitives();
+        
+        // Z1 is a distribution
+        template<typename Z1>
+        location_scale_distribution_primitives(
+            const location_scale_distribution<Z1>& that
+        );
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const location_scale_distribution_primitives&)const;
+        
+        template<typename Z1>
+        operator location_scale_distribution<Z1> ()const;
+
+    };
+
+    template<typename Z1>
+    struct meta_distribution_primitives< location_scale_distribution<Z1> >{
+        typedef typename Z1::value_type val_;
+        typedef typename meta_distribution_primitives<Z1>::type prim_;
+        typedef location_scale_distribution_primitives<prim_,val_> type;
+    };
+
+    template<typename Z,typename T>
+    location_scale_distribution_primitives<Z,T>
+    make_distribution_primitives(const location_scale_distribution<Z>& d);
+    
+    template<typename Z,typename T,typename Z1>
+    location_scale_distribution_primitives<Z,T>& 
+    operator<<(
+        location_scale_distribution_primitives<Z,T>& a,
+        const location_scale_distribution<Z1>& b
+    );
+
+    // Implementation
+
+    template<typename Z,typename T>
+        template<typename Z1>
+    location_scale_distribution_primitives<Z,T>::operator 
+        location_scale_distribution<Z1> ()const{
+        Z1 z1 = this->z; //conversion
+        typedef location_scale_distribution<Z1> res_;
+        return res_(z1,this->mu,this->sigma);
+    }
+
+
+    template<typename Z,typename T>
+    location_scale_distribution_primitives<Z,T>
+        ::location_scale_distribution_primitives()
+    :z(),
+    mu(static_cast<T>(0)),
+    sigma(static_cast<T>(0)){}
+        
+    template<typename Z,typename T>
+    template<typename Z1>
+    location_scale_distribution_primitives<Z,T>
+        ::location_scale_distribution_primitives(
+        const location_scale_distribution<Z1>& that
+    )
+    :z(
+        make_distribution_primitives(
+            that.z()
+        )
+    ),
+    mu(that.mu()),
+    sigma(that.sigma()){ 
+        typedef typename meta_distribution_primitives<Z1>::type prim_;
+        BOOST_MPL_ASSERT((
+            is_same<prim_,Z>
+        ));
+        BOOST_MPL_ASSERT((
+            mpl::not_<
+                is_reference<Z1>
+            >
+        ));
+        BOOST_MPL_ASSERT((
+            mpl::not_<
+                is_pointer<Z1>
+            >
+        ));
+    }
+
+    template<typename Z,typename T>
+    bool location_scale_distribution_primitives<Z,T>::operator==(
+        const location_scale_distribution_primitives& b
+    )const{
+        return (this->z == b.z) &&
+            arithmetic_tools::equal(this->mu,b.mu) &&
+            arithmetic_tools::equal(this->sigma,b.sigma);
+    }
+
+    template<typename Z,typename T>
+    template<class A>
+    void location_scale_distribution_primitives<Z,T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & z;
+        ar & mu;
+        ar & sigma;
+    }
+
+    template<typename Z1>
+    typename meta_distribution_primitives<
+        location_scale_distribution<Z1> 
+    >::type
+    make_distribution_primitives(const location_scale_distribution<Z1>& d){
+        typedef typename meta_distribution_primitives<
+            location_scale_distribution<Z1> 
+        >::type prim_;
+        return prim_(d);
+    }
+
+    template<typename Z,typename T>
+    location_scale_distribution_primitives<Z,T>& 
+    operator<<(
+        location_scale_distribution_primitives<Z,T>& a,
+        const location_scale_distribution<Z>& b
+    ){
+        typedef location_scale_distribution_primitives<Z,T> a_;
+        a = a_(make_distribution_primitives(b.z()),b.mu(),b.sigma());
+        return a;
+    }
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/meta.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/meta.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,22 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::meta.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_STANDARD_DISTRIBUTION_PRIMITIVES_META_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_META_HPP_ER_2009
+
+namespace boost{
+namespace math{
+    
+    // Must specialize by distribution
+    template<typename D>
+    struct meta_distribution_primitives{};
+    
+}
+}
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,119 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::normal.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_STANDARD_DISTRIBUTION_PRIMITIVES_NORMAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_NORMAL_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/normal.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct normal_distribution_primitives 
+        : equality_comparable< normal_distribution_primitives<T> >{
+        T location;
+        T scale; 
+
+        normal_distribution_primitives();
+        template<typename T1,typename P>
+        normal_distribution_primitives(const normal_distribution<T1,P>& that);
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const normal_distribution_primitives&)const;
+        
+        template<typename P> operator normal_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< normal_distribution<T,P> >{
+        typedef normal_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    normal_distribution_primitives<T>
+    make_distribution_primitives(const normal_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    normal_distribution_primitives<T>& 
+    operator<<(
+        normal_distribution_primitives<T>& a,
+        const normal_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    normal_distribution_primitives<T>::operator 
+        normal_distribution<T,P> ()const{
+        return normal_distribution<T,P>(this->location,this->scale);
+    }
+
+    template<typename T>
+    normal_distribution_primitives<T>::normal_distribution_primitives()
+    :location(static_cast<T>(0)),scale(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    normal_distribution_primitives<T>::normal_distribution_primitives(
+        const normal_distribution<T1,P>& that
+    )
+    :location(that.location()),scale(that.scale()){}
+
+    template<typename T>
+    bool normal_distribution_primitives<T>::operator==(
+        const normal_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(this->location,b.location) && 
+            arithmetic_tools::equal(this->scale,b.scale);
+    }
+
+    template<typename T>
+    template<class A>
+    void normal_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & location;
+        ar & scale;
+    }
+
+    template<typename T,typename P>
+    normal_distribution_primitives<T>
+    make_distribution_primitives(const normal_distribution<T,P>& d){
+        return normal_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    normal_distribution_primitives<T>& 
+    operator<<(
+        normal_distribution_primitives<T>& a,
+        const normal_distribution<T1,P>& b
+    ){
+        typedef normal_distribution_primitives<T> a_;
+        a = a_(b.location(),b.scale());
+        return a;
+    }
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,122 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::students_t.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_STANDARD_DISTRIBUTION_PRIMITIVES_STUDENTS_T_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_STUDENTS_T_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/students_t.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct students_t_distribution_primitives 
+        : equality_comparable< students_t_distribution_primitives<T> >{
+        T degrees_of_freedom;
+
+        students_t_distribution_primitives();
+        template<typename T1,typename P>
+        students_t_distribution_primitives(
+            const students_t_distribution<T1,P>& that
+        );
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const students_t_distribution_primitives&)const;
+
+        template<typename P> operator students_t_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< students_t_distribution<T,P> >{
+        typedef students_t_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    students_t_distribution_primitives<T>
+    make_distribution_primitives(const students_t_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    students_t_distribution_primitives<T>& 
+    operator<<(
+        students_t_distribution_primitives<T>& a,
+        const students_t_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    students_t_distribution_primitives<T>::operator 
+        students_t_distribution<T,P> ()const{
+        return students_t_distribution<T,P>(this->degrees_of_freedom);
+    }
+
+
+    template<typename T>
+    students_t_distribution_primitives<T>::students_t_distribution_primitives()
+    :degrees_of_freedom(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    students_t_distribution_primitives<T>::students_t_distribution_primitives(
+        const students_t_distribution<T1,P>& that
+    )
+    :degrees_of_freedom(that.degrees_of_freedom()){}
+
+    template<typename T>
+    bool students_t_distribution_primitives<T>::operator==(
+        const students_t_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(
+            this->degrees_of_freedom,
+            b.degrees_of_freedom
+        );
+    }
+
+    template<typename T>
+    template<class A>
+    void students_t_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & degrees_of_freedom;
+    }
+
+    template<typename T,typename P>
+    students_t_distribution_primitives<T>
+    make_distribution_primitives(const students_t_distribution<T,P>& d){
+        return students_t_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    students_t_distribution_primitives<T>& 
+    operator<<(
+        students_t_distribution_primitives<T>& a,
+        const students_t_distribution<T1,P>& b
+    ){
+        typedef students_t_distribution_primitives<T> a_;
+        a = a_(b.degrees_of_freedom());
+        return a;
+    }
+
+}// math
+}// boost
+
+#endif
+
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/uniform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/primitives/uniform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,119 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::primitives::uniform.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_STANDARD_DISTRIBUTION_PRIMITIVES_UNIFORM_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_PRIMITIVES_UNIFORM_HPP_ER_2009
+#include <boost/arithmetic/equal.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/math/distributions/uniform.hpp>
+#include <boost/standard_distribution/primitives/meta.hpp>
+#include <boost/operators.hpp>
+
+namespace boost {
+namespace math{
+    
+    template<typename T>
+    struct uniform_distribution_primitives 
+        : equality_comparable< uniform_distribution_primitives<T> >{
+        T lower;
+        T upper; 
+
+        uniform_distribution_primitives();
+        template<typename T1,typename P>
+        uniform_distribution_primitives(const uniform_distribution<T1,P>& that);
+
+        template<class A>
+        void serialize(
+            A & ar, 
+            const unsigned int version
+        );
+        
+        bool operator==(const uniform_distribution_primitives&)const;
+
+        template<typename P> operator uniform_distribution<T,P> ()const;
+
+    };
+
+    template<typename T,typename P>
+    struct meta_distribution_primitives< uniform_distribution<T,P> >{
+        typedef uniform_distribution_primitives<T> type;
+    };
+
+    template<typename T,typename P>
+    uniform_distribution_primitives<T>
+    make_distribution_primitives(const uniform_distribution<T,P>& d);
+    
+    template<typename T,typename T1,typename P>
+    uniform_distribution_primitives<T>& 
+    operator<<(
+        uniform_distribution_primitives<T>& a,
+        const uniform_distribution<T1,P>& b
+    );
+
+    // Implementation
+
+    template<typename T>
+    template<typename P>
+    uniform_distribution_primitives<T>::operator 
+        uniform_distribution<T,P> ()const{
+        return uniform_distribution<T,P>(this->lower,this->upper);
+    }
+
+    template<typename T>
+    uniform_distribution_primitives<T>::uniform_distribution_primitives()
+    :lower(static_cast<T>(0)),upper(static_cast<T>(0)){}
+        
+    template<typename T>
+    template<typename T1,typename P>
+    uniform_distribution_primitives<T>::uniform_distribution_primitives(
+        const uniform_distribution<T1,P>& that
+    )
+    :lower(that.lower()),upper(that.upper()){}
+
+    template<typename T>
+    bool uniform_distribution_primitives<T>::operator==(
+        const uniform_distribution_primitives& b
+    )const{
+        return arithmetic_tools::equal(this->lower,b.lower) && 
+            arithmetic_tools::equal(this->upper,b.upper);
+    }
+
+    template<typename T>
+    template<class A>
+    void uniform_distribution_primitives<T>::serialize(
+        A & ar, 
+        const unsigned int version
+    )
+    {
+        ar & lower;
+        ar & upper;
+    }
+
+    template<typename T,typename P>
+    uniform_distribution_primitives<T>
+    make_distribution_primitives(const uniform_distribution<T,P>& d){
+        return uniform_distribution_primitives<T>(d);
+    }
+
+    template<typename T,typename T1,typename P>
+    uniform_distribution_primitives<T>& 
+    operator<<(
+        uniform_distribution_primitives<T>& a,
+        const uniform_distribution<T1,P>& b
+    ){
+        typedef uniform_distribution_primitives<T> a_;
+        a = a_(b.lower(),b.upper());
+        return a;
+    }
+
+
+}// math
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::transformation::include.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_STANDARD_DISTRIBUTION_TRANSFORMATION_INCLUDE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_TRANSFORMATION_INCLUDE_HPP_ER_2009
+
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/location_scale.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/transformation/location_scale.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,224 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::transformation::location_scale.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_STANDARD_DISTRIBUTION_TRANSFORMATION_LOCATION_SCALE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_TRANSFORMATION_LOCATION_SCALE_HPP_ER_2009
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <boost/format.hpp>
+#include <boost/utility.hpp>
+#include <boost/call_traits.hpp>
+
+#include <boost/range.hpp>
+//#include <boost/math/policies/policy.hpp>
+
+namespace boost{
+namespace math{
+
+    // Represents a location scale family
+    //
+    // X = mu + sigma * Z
+    // pdf_X(x) = (1/sigma) pdf_Z((x-mu)/sigma)
+    // cdf_X(x) = cdf_Z((x-mu)/sigma)
+    //
+    // TODO: range and support
+    template<typename Z>
+    class location_scale_distribution{
+        public:
+        typedef typename remove_reference<
+            typename remove_const<
+                Z
+            >::type
+        >::type distribution_type;
+
+        typedef typename distribution_type::value_type value_type;
+        typedef typename distribution_type::policy_type policy_type;
+
+        location_scale_distribution();
+        location_scale_distribution(
+            typename call_traits<Z>::param_type z,
+            value_type mu,
+            value_type sigma
+        );
+
+        location_scale_distribution(const location_scale_distribution& that);
+        
+        location_scale_distribution&
+        operator=(const location_scale_distribution& that);
+        
+        value_type mu()const;
+        value_type sigma()const;
+
+        typename call_traits<Z>::const_reference z()const;
+
+        private:
+            typename call_traits<Z>::value_type z_;
+            value_type mu_;
+            value_type sigma_;
+    };
+
+    template<typename Z>
+    std::ostream& operator<<(
+        std::ostream& out, 
+        const location_scale_distribution<Z>& d
+    );
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    pdf(
+        const location_scale_distribution<Z>& d,
+        const typename 
+            location_scale_distribution<Z>::value_type& x
+    );
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    cdf(
+        const location_scale_distribution<Z>& d,
+        const typename 
+            location_scale_distribution<Z>::value_type& x
+    );
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    log_unnormalized_pdf(
+        const location_scale_distribution<Z>& d,
+        const typename 
+            location_scale_distribution<Z>::value_type& x
+    );
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    variance(
+        const location_scale_distribution<Z>& d
+    );
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    mean(
+        const location_scale_distribution<Z>& d
+    );
+
+    // Implementation // 
+
+    template<typename Z>
+    std::ostream& operator<<(
+        std::ostream& out, 
+        const location_scale_distribution<Z>& d
+    ){
+        const char* msg = "location_scale_distribution( %1% + %2% %3%)";
+        // Warning : os << ls.z() usually not defined (TODO)
+        format f(msg); f % d.mu() % d.sigma() % d.z();
+        return (out << f.str());
+    }
+
+    template<typename Z>
+    location_scale_distribution<Z>::location_scale_distribution()
+    :z_(),mu_(0),sigma_(1){}
+    
+    template<typename Z>
+    location_scale_distribution<Z>::location_scale_distribution(
+        typename call_traits<Z>::param_type z,
+        value_type mu,
+        value_type sigma
+    ):z_(z),mu_(mu),sigma_(sigma){}
+
+    template<typename Z>
+    location_scale_distribution<Z>::location_scale_distribution(
+        const location_scale_distribution& that
+    ):z_(that.z_),mu_(that.mu_),sigma_(that.sigma_){}
+
+    template<typename Z>
+    location_scale_distribution<Z>&
+    location_scale_distribution<Z>::operator=(
+        const location_scale_distribution& that
+    ){
+        if(&that!=this){
+            z_ = that.z_;
+            mu_ = that.mu_;
+            sigma_ = that.sigma_;
+        }
+        return *this;
+    }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type 
+    location_scale_distribution<Z>::mu()const{ return this->mu_; }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type 
+    location_scale_distribution<Z>::sigma()const{ return this->sigma_; }
+
+    template<typename Z>
+    typename call_traits<Z>::const_reference
+    location_scale_distribution<Z>::z()const{ return this->z_; }
+
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    pdf(
+        const location_scale_distribution<Z>& d,
+        const typename 
+            location_scale_distribution<Z>::value_type& x
+    ){
+        typedef typename 
+            location_scale_distribution<Z>::value_type value_t;
+        value_t z = (x-d.mu())/d.sigma();
+        value_t result = pdf(d.z(),z);
+        result /= d.sigma();
+        return result;
+    }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    cdf(
+        const location_scale_distribution<Z>& d,
+        const typename location_scale_distribution<Z>::value_type& x
+    ){
+        typedef typename 
+            location_scale_distribution<Z>::value_type value_t;
+        value_t z = (x-d.mu())/d.sigma();
+        return cdf(
+            d.z(),
+            z
+        );
+    }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    log_unnormalized_pdf(
+        const location_scale_distribution<Z>& d,
+        const typename location_scale_distribution<Z>::value_type& x
+    ){
+        typedef typename location_scale_distribution<Z>::value_type value_t;
+        value_t z = (x-d.mu())/d.sigma();
+        value_t result = math::log_unnormalized_pdf(d.z(),z);
+        // -log ( sigma ) is a constant so it is ignored
+        return result;
+    }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    variance(
+        const location_scale_distribution<Z>& d
+    ){
+        return variance(d.z()) * d.sigma() * d.sigma();
+    }
+
+    template<typename Z>
+    typename location_scale_distribution<Z>::value_type
+    mean(
+        const location_scale_distribution<Z>& d
+    ){
+        return mean(d) + mean(d.z());
+    }
+
+}
+}
+#endif // LOCATION_SCALE_DISTRIBUTION_HPP_INCLUDED
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/chi_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/chi_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::chi_squared.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_CHI_SQUARED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_CHI_SQUARED_HPP_ER_2009
+#include <boost/math/distributions/chi_squared.hpp>
+#include <boost/math/special_functions/log1p.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/math/policies/policy.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename Policy>
+    T
+    log_unnormalized_pdf(
+        const boost::math::chi_squared_distribution<T,Policy>& dist,
+        const T& x
+    ){
+        BOOST_MATH_STD_USING  // for ADL of std functions
+        T degrees_of_freedom = dist.degrees_of_freedom();
+        // Error check:
+        T error_result;
+
+        static const char* function = 
+"boost::math::log_unnormalized_pdf(const chi_squared_distribution<%1%>&, %1%)";
+
+        if(false == detail::check_df(
+            function, degrees_of_freedom, &error_result, Policy()))
+                return error_result;
+
+        if((x <= 0) || !(boost::math::isfinite)(x))
+        {
+            return policies::raise_domain_error<T>(
+            function, "Chi Square parameter was %1%, but must be > 0 !", 
+            x, Policy());
+        }
+
+        // Lumped case x == 0 in x<=0 above
+
+        static T one = static_cast<T>(1);
+        static T two = static_cast<T>(2);
+        return (degrees_of_freedom/two-one) * log(x) - x/two;
+    }
+
+    template<typename T,typename Policy>
+    T
+    derivative_log_unnormalized_pdf(
+        const boost::math::chi_squared_distribution<T,Policy>& dist,
+        const T& x
+    ){
+        BOOST_MATH_STD_USING  // for ADL of std functions
+        T degrees_of_freedom = dist.degrees_of_freedom();
+        // Error check:
+        T error_result;
+
+        static const char* function = 
+"boost::math::log_unnormalized_pdf(const chi_squared_distribution<%1%>&, %1%)";
+
+        if(false == detail::check_df(
+            function, degrees_of_freedom, &error_result, Policy()))
+                return error_result;
+
+        if((x < 0) || !(boost::math::isfinite)(x))
+        {
+            return policies::raise_domain_error<T>(
+            function, "Chi Square parameter was %1%, but must be > 0 !", 
+            x, Policy());
+        }
+
+        // Lumped case x == 0 in x<=0 above
+
+        static T one = static_cast<T>(1);
+        static T two = static_cast<T>(2);
+        return (degrees_of_freedom/two-one) / x - one/two;
+    }
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/exponential.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/exponential.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,69 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::unnormalized_pdf::exponential.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_EXPONENTIAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_EXPONENTIAL_HPP_ER_2009
+#include <string>
+#include <boost/math/distributions/exponential.hpp>
+#include <boost/math/policies/policy.hpp> 
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    T
+    log_unnormalized_pdf(
+        const boost::math::exponential_distribution<T,P>& d,
+        const T& x
+    ){
+
+        BOOST_MATH_STD_USING // for ADL of std functions
+        // to keep width = 80 caracters
+        static const char* function = strcpy(
+            "boost::math::log_unnormalized_pdf(" ,
+            "const exponential_distribution<%1%>&,%1%)"
+        );
+
+        T lambda = d.lambda();
+        T result;
+        if(0 == detail::verify_lambda(function, lambda, &result, P()))
+            return result;
+        if(0 == detail::verify_exp_x(function, x, &result, P()))
+            return result;
+        result = (-lambda * x);
+        return result;
+    }
+
+    template<typename T,typename P>
+    T
+    derivative_log_unnormalized_pdf(
+        const boost::math::exponential_distribution<T,P>& d,
+        const T& x
+    ){
+
+        BOOST_MATH_STD_USING // for ADL of std functions
+        // to keep width = 80 caracters
+        static const char* function = strcpy(
+            "boost::math::derivative_log_unnormalized_pdf(",
+            "const exponential_distribution<%1%>&,%1%)"
+        );
+
+        T lambda = d.lambda();
+        T result;
+        if(0 == detail::verify_lambda(function, lambda, &result, P()))
+            return result;
+        if(0 == detail::verify_exp_x(function, x, &result, P()))
+            return result;
+        result = (-lambda);
+        return result;
+    }
+
+}//math
+}//boost
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/gamma.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/gamma.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,86 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::gamma.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_MATH_UNNORMALIZED_PDF_GAMMA_HPP_ER_2009
+#define BOOST_MATH_UNNORMALIZED_PDF_GAMMA_HPP_ER_2009
+#include <cmath>
+#include <boost/math/distributions/gamma.hpp>
+#include <boost/math/policies/policy.hpp>
+
+namespace boost{
+namespace math{
+
+template <class T, class Policy>
+inline bool is_concave(
+    const gamma_distribution<T, Policy>& dist
+){
+    return ( dist.shape() > static_cast<T>(1) );
+}
+
+template <class T, class Policy>
+inline T log_unnormalized_pdf(
+    const gamma_distribution<T, Policy>& dist,
+    const T& x
+)
+{
+   BOOST_MATH_STD_USING  // for ADL of std functions
+
+   static const char* function
+    = "boost::math::log_unnormalized_pdf(const gamma_distribution<%1%>&, %1%)";
+
+   T shape = dist.shape();
+   T scale = dist.scale();
+
+   T result;
+   if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
+      return result;
+   if(false == detail::check_gamma_x(function, x, &result, Policy()))
+      return result;
+
+   if(x == 0)
+   {
+      return log(0);
+   }
+   static T one_ = static_cast<T>(1);
+   result = (shape - one_) * log(x) - x / scale;
+   return result;
+} // log_unnormalized_pdf
+
+template <class T, class Policy>
+inline T derivative_log_unnormalized_pdf(
+    const gamma_distribution<T, Policy>& dist,
+    const T& x
+)
+{
+   BOOST_MATH_STD_USING  // for ADL of std functions
+
+   static const char* function
+ = "boost::math::log_unnormalized_pdf(const gamma_distribution<%1%>&, %1%)";
+
+   T shape = dist.shape();
+   T scale = dist.scale();
+
+   T result;
+   if(false == detail::check_gamma(function, scale, shape, &result, Policy()))
+      return result;
+   if(false == detail::check_gamma_x(function, x, &result, Policy()))
+      return result;
+
+   if(x == 0)
+   {
+      return log(0);
+   }
+   static T one_ = static_cast<T>(1);
+   result = (shape - one_) / x - one_ / scale;
+   return result;
+} // derivative_log_unnormalized_pdf
+
+}
+}
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,26 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::include.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_INCLUDE_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_INCLUDE_HPP_ER_2009
+
+#include <boost/math/distributions/exponential.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/exponential.hpp>
+
+#include <boost/math/distributions/gamma.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/gamma.hpp>
+
+#include <boost/math/distributions/normal.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/normal.hpp>
+
+#include <boost/math/distributions/students_t.hpp>
+#include <boost/standard_distribution/unnormalized_pdf/students_t.hpp>
+
+#include <boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/normal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/normal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,52 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::normal.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_NORMAL_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_NORMAL_HPP_ER_2009
+#include <boost/math/distributions/normal.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+//#include <boost/math/policies/policy.hpp>//TODO
+
+namespace boost{
+namespace math{
+
+    // If only the unnormalized_pdf is required, this is supposed to
+    // be faster than log(pdf(D,x))
+
+    template<typename T,typename Policy>
+    T
+    log_unnormalized_pdf(
+        const boost::math::normal_distribution<T,Policy>& d,
+        const T& x
+    ){
+        typedef boost::numeric::converter<T,int> int2real_t;
+        T mu = d.location();
+        T sigma = d.scale();
+
+        T z = (x-mu)/sigma;
+        return - z * z / int2real_t::convert(2);
+    }
+
+    template<typename T,typename Policy>
+    T
+    derivative_log_unnormalized_pdf(
+        const boost::math::normal_distribution<T,Policy>& d,
+        const T& x
+    ){
+        typedef boost::numeric::converter<T,int> int2real_t;
+        T mu = d.location();
+        T sigma = d.scale();
+
+        T z = (x-mu)/sigma;
+        T dz = int2real_t::convert(1)/sigma;
+        return (- z) * dz;
+    }
+}
+}
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/students_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/students_t.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,58 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::students_t.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_STUDENTS_T_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_STUDENTS_T_HPP_ER_2009
+#include <boost/math/distributions/students_t.hpp>
+#include <boost/math/special_functions/log1p.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+// #include <boost/math/policies/policy.hpp> // TODO
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename Policy>
+    T
+    log_unnormalized_pdf(
+        const boost::math::students_t_distribution<T,Policy>& d,
+        const T& x
+    ){
+
+        typedef boost::numeric::converter<T,int> int2R_t;
+
+        T r1 = int2R_t::convert(1);
+        T r2 = int2R_t::convert(2);
+
+        T nu = d.degrees_of_freedom();
+        T m = ( nu + r1 ) / r2;
+        T y = ( x * x ) / nu;
+        return (- m ) * math::log1p(y);
+    }
+
+    template<typename T,typename Policy>
+    T
+    derivative_log_unnormalized_pdf(
+        const boost::math::students_t_distribution<T,Policy>& d,
+        const T& x
+    ){
+        typedef boost::numeric::converter<T,int> int2R_t;
+
+        T r1 = int2R_t::convert(1);
+        T r2 = int2R_t::convert(2);
+        T nu = d.degrees_of_freedom();
+        T m = ( nu + r1 ) / r2;
+        T y = ( x * x ) / nu;
+        T dy = int2R_t::convert(2) * x / nu;
+        T dlog1p = int2R_t::convert(1) / ( 1 + y );
+        return (- m ) * dlog1p * dy;
+    }
+
+}
+}
+
+#endif
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/uniform.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/uniform.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,91 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::uniform.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_UNIFORM_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_UNIFORM_HPP_ER_2009
+#include <boost/math/distributions/uniform.hpp>
+#include <boost/math/special_functions/log1p.hpp>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/math/policies/policy.hpp>
+#include <boost/math/tools/precision.hpp>
+
+namespace boost{
+namespace math{
+
+    template<typename T,typename P>
+    T
+    log_unnormalized_pdf(
+        const boost::math::uniform_distribution<T,P>& dist,
+        const T& x
+    )
+    {
+        T lower = dist.lower();
+        T upper = dist.upper();
+        T result; // of checks.
+        if(false == detail::check_uniform(
+            "boost::math::pdf(const uniform_distribution<%1%>&, %1%)", 
+            lower, upper, &result, P()))
+        {
+            return result;
+        }
+        if(false == detail::check_uniform_x(
+            "boost::math::pdf(const uniform_distribution<%1%>&, %1%)",
+             x, &result, P()))
+        {
+            return result;
+        }
+
+        if((x < lower) || (x > upper) )
+        {
+            static T inf = std::numeric_limits<T>::infinity();
+            return (- inf);
+        }
+        else
+        {
+            return static_cast<T>(0);
+        }
+    } 
+
+    template<typename T,typename P>
+    T
+    derivative_log_unnormalized_pdf(
+        const boost::math::uniform_distribution<T,P>& dist,
+        const T& x
+    ){
+        T lower = dist.lower();
+        T upper = dist.upper();
+        T result; // of checks.
+        if(false == detail::check_uniform(
+            "boost::math::pdf(const uniform_distribution<%1%>&, %1%)", 
+            lower, upper, &result, P()))
+        {
+            return result;
+        }
+        if(false == detail::check_uniform_x(
+            "boost::math::pdf(const uniform_distribution<%1%>&, %1%)",
+             x, &result, P()))
+        {
+            return result;
+        }
+
+        if((x < lower) || (x > upper) )
+        {
+            // TODO. Makes sense?
+            static T inf = std::numeric_limits<T>::infinity();
+            return (- inf);
+        }
+        else
+        {
+            return static_cast<T>(0);
+        }
+    }
+
+}
+}
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/boost/standard_distribution/unnormalized_pdf/unnormalized_pdf.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,37 @@
+//////////////////////////////////////////////////////////////////////////////
+// distributions::unnormalized_pdf::unnormalized_pdf.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_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_UNNORMALIZED_HPP_ER_2009
+#define BOOST_STANDARD_DISTRIBUTION_UNNORMALIZED_PDF_UNNORMALIZED_HPP_ER_2009
+#include <cmath>
+
+namespace boost{
+namespace math{
+
+template<typename D>
+typename D::value_type  
+log_unnormalized_pdf( //Fwd Declare
+    const D& d,
+    const typename D::value_type& x
+);
+        
+template<typename D>
+typename D::value_type  
+unnormalized_pdf(
+    const D& d,
+    const typename D::value_type& x
+){
+    typedef typename D::value_type value_type;
+    value_type l = log_unnormalized_pdf(d,x);
+    return exp(l);
+}
+
+}
+}
+#endif
+
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,101 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::doc::readme                                       //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ classes that extend boost/math/distributions.  
+
+[ Useful links ]
+
+http://www.boost.org/doc/libs/1_35_0/libs/math/doc/sf_and_dist/html/index.html
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+boost_1_39_0
+
+/usr/local/boost_1_39_0/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/random/
+/sandbox/statistics/standard_distribution/
+
+Link to libboost_serialization-xgcc42-mt-1_39.a
+
+[ History ]
+
+July 2009 : Current version
+
+[ os ]
+
+    Adds the ostream& operator<<(ostream&, d) to each distribution class
+    
+[ unnormalized_pdf ]
+
+    Implements 
+        log_unnormalized_pdf(dist,x)
+        derivative_log_unnormalized_pdf(dist,x)
+
+    What for?
+    - exp( sum{ log_pdf } ) is often preferable to prod{ pdf }  
+    - The normalizing constant is either unnecessary (Bayesian) or can be
+    cached
+    - The derivative is useful in applications such as derivate-adaptive-
+    rejection sampling (Gilks, 1992).
+
+[ is_scalar_dist ]
+    
+    Implements 
+        is_scalar_dist<D>
+
+[ normalizing_constant ]
+
+    normalizing_constant(dist)
+    
+    Only the normal is implemented right now (TODO).
+
+[ transformation ]
+
+    location_scale implements X = sigma Z + mu
+
+[ primitives ]
+
+    A class such as normal_distribution is associated with 
+    normal_distribution_primitives that is serializable and equality comparable.
+        
+[ Note ]
+
+Exception handling is either copy-pasted from boost/math/distributions, 
+with any change is indicated within the code itself or has yet to be 
+implemented (TODO).
+
+
+[ Output ]
+
+main.cpp:
+
+-> example_math_location_scale->
+log_unnormalized_pdf(mstud,2.132) = -2.0608 
+    deleg(mstud,2.132) = -2.0608
+log_unnormalized_pdf(mls_stud,2.132) = -5.14341 
+    deleg(mls_stud,2.132) = -5.14341
+log_unnormalized_pdf(prod_dist,2.132) = -7.20421 
+    deleg(prod_dist,2.132) = -7.20421
+log_unnormalized_pdf(inv_dist,2.132) = 2.0608 
+    deleg(inv_dist,2.132) = 2.0608
+log_unnormalized_pdf(ratio_dist,2.132) = 3.08261 
+    deleg(ratio_dist,2.132) = 3.08261
+<-
+ -> example_serialize<-
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,156 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::example::location_scale.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <algorithm>
+#include <iterator>
+#include <numeric>
+#include <cmath>
+#include <string>
+#include <boost/mpl/apply.hpp>
+#include <boost/format.hpp>
+#include <boost/bind.hpp>
+#include <boost/function.hpp>
+#include <boost/range.hpp>
+
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/normal_distribution.hpp>
+#include <boost/random/variate_generator.hpp>
+
+#include <boost/scalar_dist/map_pdf/product_pdf.hpp>
+#include <boost/scalar_dist/map_pdf/inverse_pdf.hpp>
+#include <boost/scalar_dist/map_pdf/ratio_pdf.hpp>
+
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/standard_distribution/distributions/students_t.hpp>
+#include <boost/standard_distribution/transformation/location_scale.hpp>
+#include <boost/scalar_dist/algorithm/transform.hpp>
+#include <boost/scalar_dist/meta/include.hpp>
+#include <boost/scalar_dist/fun_wrap/include.hpp>
+
+void example_location_scale(std::ostream& out){
+        out << "-> example_math_location_scale->" << std::endl;
+
+        // Examples of location_scale + fun_wrap + transformation + algorithms
+
+        using namespace boost;
+        using namespace math;
+
+        // Types
+        typedef double                                          val_;
+        typedef std::vector<val_>                               vals_;
+        typedef std::string                                     str_;
+        typedef boost::mt19937                                  urng_;
+        typedef boost::normal_distribution<val_>                rnd_;
+        typedef math::students_t_distribution<val_>             mstud_;
+        typedef math::location_scale_distribution<mstud_>       mls_stud_;
+        typedef boost::variate_generator<urng_&,rnd_>           vg_;
+
+        // Constants
+        const unsigned df   = 10;
+        const val_ mu       = 10;
+        const val_ sigma    = 2;
+        const unsigned n    = 1e1;
+        const val_ x        = 2.132;
+
+        format fl("log_unnormalized_pdf(%2%,%1%) = %3%"); fl%x;
+        format fd("deleg(%2%,%1%) = %3%"); fd%x;
+
+        // Initialization
+        urng_ urng;
+        vals_ range_x;
+
+        // Arbitrary random sample
+        std::generate_n(
+            back_inserter(range_x),
+            n,
+            vg_(urng,rnd_(0,1))
+        );
+        
+        mstud_ mstud(df);
+        mls_stud_ mls_stud(mstud, mu, sigma);
+
+        {   // fun_wrap
+            typedef math::delegate<mstud_>              meta_deleg_;
+            typedef meta_deleg_::type                   deleg_;
+            deleg_ deleg 
+                = meta_deleg_::make<math::fun_wrap::log_unnormalized_pdf_>();
+            format ffl = fl; ffl%"mstud"%log_unnormalized_pdf(mstud,x);
+            format ffd = fd; ffd%"mstud"%deleg(mstud,x);
+            out << ffl.str() << ' ' << ffd.str() << std::endl;
+        }
+        {   // fun_wrap + location_scale_distribution
+
+            typedef math::delegate<mls_stud_>           meta_deleg_;
+            typedef meta_deleg_::type                   deleg_;
+            deleg_ deleg 
+                = meta_deleg_::make<math::fun_wrap::log_unnormalized_pdf_>();
+
+            format ffl = fl; ffl%"mls_stud"%log_unnormalized_pdf(mls_stud,x);
+            format ffd = fd; ffd%"mls_stud"%deleg(mls_stud,x);
+            out << ffl.str() << ' ' << ffd.str() << std::endl;
+        }
+        {   // math::transform + fun_wrap
+            vals_ range_log_pdf;
+            math::transform<math::fun_wrap::log_unnormalized_pdf_>(
+                mstud,
+                begin(range_x),
+                end(range_x),
+                std::back_inserter(range_log_pdf)
+            );
+        }
+        {   // product_pdf + fun_wrap
+            typedef math::product_pdf<mstud_,mls_stud_>    prod_dist_;
+            typedef math::product_pdf<mstud_&,mls_stud_&>  ref_prod_dist_;
+
+            typedef math::delegate<prod_dist_>          meta_deleg_;
+            typedef meta_deleg_::type                   deleg_;
+            deleg_ deleg 
+                = meta_deleg_::make<math::fun_wrap::log_unnormalized_pdf_>();
+
+            prod_dist_ prod_dist(mstud,mls_stud);
+            prod_dist_ prod_dist2(mstud,mls_stud);
+            prod_dist = prod_dist2;
+
+            format ffl = fl; ffl%"prod_dist"%log_unnormalized_pdf(prod_dist,x);
+            format ffd = fd; ffd%"prod_dist"%deleg(prod_dist,x);
+            out << ffl.str() << ' ' << ffd.str() << std::endl;
+            ref_prod_dist_ ref_prod_dist(mstud,mls_stud);
+            ref_prod_dist_ ref_prod_dist2(mstud,mls_stud);
+            // Would cause compile error (as expected):
+            // no matching for call to mpl::void_::operator=
+            // ref_prod_dist = ref_prod_dist2;
+        }
+        {   // inverse_pdf + fun_wrap
+            typedef math::inverse_pdf<mstud_>               inv_dist_;
+            typedef math::delegate<inv_dist_>               meta_deleg_;
+            typedef meta_deleg_::type                       deleg_;
+            deleg_ deleg 
+                = meta_deleg_::make<math::fun_wrap::log_unnormalized_pdf_>();
+            inv_dist_ inv_dist(mstud);
+            format ffl = fl; ffl%"inv_dist"%log_unnormalized_pdf(inv_dist,x);
+            format ffd = fd; ffd%"inv_dist"%deleg(inv_dist,x);
+            out << ffl.str() << ' ' << ffd.str() << std::endl;
+        }
+        {   // ratio_pdf + fun_wrap
+            typedef math::meta_ratio_pdf<mstud_,mls_stud_>      mf_;
+            typedef mf_::type                                   ratio_dist_;
+
+            ratio_dist_ ratio_dist = mf_::make(mstud,mls_stud);
+            typedef math::delegate<ratio_dist_>                 meta_deleg_;
+            typedef meta_deleg_::type                           deleg_;
+            deleg_ deleg 
+                = meta_deleg_::make<math::fun_wrap::log_unnormalized_pdf_>();
+            format ffl = fl; 
+                ffl%"ratio_dist"%log_unnormalized_pdf(ratio_dist,x);
+            format ffd = fd; 
+                ffd%"ratio_dist"%deleg(ratio_dist,x);
+            out << ffl.str() << ' ' << ffd.str() << std::endl;
+        }
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/example/location_scale.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::example::location_scale.h                         //
+//                                                                          //
+//  (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 LIBS_STANDARD_DISTRIBUTION_EXAMPLE_LOCATION_SCALE_H_ER_2009
+#define LIBS_STANDARD_DISTRIBUTION_EXAMPLE_LOCATION_SCALE_H_ER_2009
+#include <ostream>
+
+void example_location_scale(std::ostream&);
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,251 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::example::location_scale.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)        //
+//////////////////////////////////////////////////////////////////////////////
+#include <stdexcept>
+#include <ostream>
+#include <fstream>
+#include <boost/typeof/typeof.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/standard_distribution/distributions/chi_squared.hpp>
+#include <boost/standard_distribution/distributions/exponential.hpp>
+#include <boost/standard_distribution/distributions/gamma.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/standard_distribution/distributions/students_t.hpp>
+#include <boost/standard_distribution/distributions/uniform.hpp>
+#include <boost/standard_distribution/distributions/location_scale.hpp>
+
+void example_serialize(std::ostream& out){
+    using namespace boost;
+    out << " -> example_serialize";
+    const char* msg = "example_serialize : ";
+    
+    typedef std::string                             str_;
+    
+    typedef boost::archive::text_oarchive           oa_;
+    typedef boost::archive::text_iarchive           ia_;
+    typedef std::ofstream                           ofs_;
+    typedef std::ifstream                           ifs_;
+
+    typedef double val_;
+
+    const char* ar_path = "./ar_dist";
+
+    {
+        typedef math::chi_squared_distribution<val_>                dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type   prim_;
+        dist_ dist(2.0);
+        dist_ dist2(4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// chi_squared
+
+    {
+        typedef math::exponential_distribution<val_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist;
+        dist_ dist2(4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim;
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// exponential
+
+    {
+        typedef math::gamma_distribution<val_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist(2.0);
+        dist_ dist2(4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// gamma
+
+    {
+        typedef math::normal_distribution<val_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist;
+        dist_ dist2(4.0, 4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// normal
+
+    {
+        typedef math::students_t_distribution<val_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist(2.0);
+        dist_ dist2(4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// students_t
+
+    {
+        typedef math::uniform_distribution<val_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist;
+        dist_ dist2(-4.0,4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// uniform
+
+    {
+        typedef math::students_t_distribution<val_> zdist_;
+        typedef math::location_scale_distribution<zdist_> dist_;
+        typedef math::meta_distribution_primitives< dist_ >::type prim_;
+        dist_ dist( zdist_(10.0), 1.0, 2.0 );
+        dist_ dist2( zdist_(10.0), -4.0,4.0);
+        BOOST_AUTO(prim,make_distribution_primitives(dist));
+
+        {
+            ofs_ ofs(ar_path);
+            oa_ oa(ofs);
+            oa << prim;        
+        }
+        {
+            ifs_ ifs(ar_path);
+            if(ifs.good()){
+                ia_ ia(ifs);
+                ia >> prim;
+            }else{
+                throw std::runtime_error( msg );
+            }
+        }
+        BOOST_ASSERT(
+            prim != make_distribution_primitives(dist2)
+        );
+        dist2 = prim; //conversion
+        BOOST_ASSERT(
+            prim == make_distribution_primitives(dist2)
+        );
+    }// location_scale
+
+
+    out << "<-";
+}
\ No newline at end of file
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/example/serialize.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+//////////////////////////////////////////////////////////////////////////////
+// standard_distribution::example::location_scale.h                         //
+//                                                                          //
+//  (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 LIBS_STANDARD_DISTRIBUTION_EXAMPLE_SERIALIZE_H_ER_2009
+#define LIBS_STANDARD_DISTRIBUTION_EXAMPLE_SERIALIZE_H_ER_2009
+#include <ostream>
+
+void example_serialize(std::ostream&);
+
+#endif
Added: sandbox/statistics/standard_distribution/libs/standard_distribution/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/standard_distribution/libs/standard_distribution/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,13 @@
+#include <iostream>
+#include <libs/standard_distribution/example/location_scale.h>
+#include <libs/standard_distribution/example/serialize.h>
+
+using namespace std;
+
+int main()
+{
+     example_location_scale(std::cout);
+     example_serialize(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/survival_data/boost/survival/constant.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/constant.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,53 @@
+///////////////////////////////////////////////////////////////////////////////
+// survial::data::constant.hpp                                               //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_CONSTANT_HPP_ER_2009
+#define BOOST_SURVIVAL_CONSTANT_HPP_ER_2009
+#include <limits>
+#include <iostream>
+#include <boost/numeric/conversion/converter.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/type_traits.hpp>
+
+namespace boost{
+namespace survival{
+        
+        template<typename T>
+        struct constant{
+            typedef numeric::converter<T,unsigned> conv_t;
+            static T zero_;
+            static T eps_;
+            static T one_;
+            static T two_;
+            static T lmin_; //exp(lmin_)>eps
+            static T lmax_; //exp(lmax_)<inf
+            static T inf_;
+            static T quiet_nan_;
+            static T sig_nan_;
+        };
+        template<typename T>
+        T constant<T>::zero_ = conv_t::convert(0);
+        template<typename T>
+        T constant<T>::eps_ = boost::math::tools::epsilon<T>();
+        template<typename T>
+        T constant<T>::one_ = conv_t::convert(1);
+        template<typename T>
+        T constant<T>::two_ = conv_t::convert(2);
+        template<typename T>
+        T constant<T>::lmin_ = math::tools::log_min_value<T>();
+        template<typename T>
+        T constant<T>::lmax_ = math::tools::log_max_value<T>();
+        template<typename T>
+        T constant<T>::inf_ = std::numeric_limits<T>::infinity();
+        template<typename T>
+        T constant<T>::quiet_nan_ = std::numeric_limits<T>::quiet_NaN();
+        template<typename T>
+        T constant<T>::sig_nan_ = std::numeric_limits<T>::signaling_NaN();
+        
+}
+}
+#endif
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/detail/log_shift.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/detail/log_shift.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,41 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::log_shift.hpp                                  //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORITHM_DETAIL_LOG_SHIFT_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORITHM_LOG_SHIFT_HPP_ER_2009
+#include <boost/math/special_functions/log1p.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+namespace detail{
+            
+    template<typename T>
+    T log_shift(
+        const T& x,
+        const T& t
+    ){
+        return log(x+t);
+    }
+            
+    template<typename T>
+    T logit_shift(
+        const T& p,
+        const T& t
+    ){
+        // log(p/(1-p)) = log(p)-log(1-p)
+    
+        return log_shift(p,t) - boost::math::log1p(t - p);
+    }
+            
+            
+}// detail
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/events.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/events.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,65 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::events.hpp                                     //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORITHM_EVENTS_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORITHM_EVENTS_HPP_ER_2009
+#include <algorithm>
+#include <ext/algorithm>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/survival/data/data/record.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+    // Converts sorted records to events excluding those that are past 
+    // entry_bound
+    template<typename ItR,typename T,typename ItE>
+    ItE events(
+        ItR b_r,
+        ItR e_r,
+        const T& entry_bound,
+        ItE out
+    ){
+        BOOST_ASSERT(
+            is_sorted(
+                b_r,
+                e_r
+            )
+        );
+        typedef typename iterator_value<ItR>::type      record_;
+        typedef typename record_::value_type            val_;
+        typedef event<val_>                             event_;
+
+        ItR i =  std::lower_bound(
+            b_r,
+            e_r,
+            record_(static_cast<val_>(entry_bound))
+        );
+
+        typedef event_ (*ptr_)(const record_&,val_);
+        ptr_ f = make_event; 
+
+        return std::transform(
+            b_r,
+            i,
+            out,
+            lambda::bind(
+                f, 
+                lambda::_1,
+                entry_bound
+            )
+        );
+    }
+
+}// data
+}// survival
+}// boost
+
+#endif
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,16 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::include.hpp                                    //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORTIHM_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORTIHM_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/data/algorithm/events.hpp>
+#include <boost/survival/data/algorithm/vectorize_events.hpp>
+#include <boost/survival/data/algorithm/logit_log.hpp>
+#include <boost/survival/data/algorithm/mean_events_by_covariate.hpp>
+
+#endif
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/logit_log.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/logit_log.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,48 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::logit_log.hpp                                  //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORITHM_LOGIT_LOG_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORITHM_LOGIT_LOG_HPP_ER_2009
+#include <stdexcept>
+#include <iterator>
+#include <boost/format.hpp>
+#include <boost/survival/data/algorithm/detail/log_shift.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+// Transforms an alternating sequence of (usually mean) failures 
+// and event times to their logit and log, with an offset that prevents nan.
+//
+// The rationale for a logit is that 0<= mean failure <=1
+template<typename It,typename ItO,typename T>
+ItO logit_log(
+    It b,    // Alternating sequence, f[0],t[0],f[1],t[1],...
+    It e,
+    ItO o,   // Output iterator
+    T t0,
+    T t1
+){
+    static const char* str = "logit_log : distance(b,e) = %1% mod 2 !=2";
+
+   if( std::distance(b,e)%2 != 0 ){
+        format f(str); f%distance(b,e);
+        throw std::runtime_error(f.str());
+   }
+   while(b!=e){
+        (*o) = detail::logit_shift((*b),t0); ++b;
+        (*o) = detail::log_shift((*b),t1); ++b;
+    }
+    return o;
+}
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/mean_events_by_covariate.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/mean_events_by_covariate.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,137 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::mean_events_by_covariate.hpp                   //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORITHM_MEAN_EVENTS_BY_COVARIATE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORITHM_MEAN_EVENTS_BY_COVARIATE_HPP_ER_2009
+#include <vector>
+#include <boost/foreach.hpp>
+#include <boost/utility.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/survival/data/data/mean_event.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/functional/find.hpp>
+#include <boost/binary_op/functional/match_accumulator.hpp>
+#include <boost/binary_op/algorithm/for_each.hpp>
+#include <boost/binary_op/algorithm/heads.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+
+    // Updates a collection of mean_events, one for each covariate value.
+    //
+    // Requirements
+    // Let [b_x1,e_x1) denote a sequence of covariate values.
+    // i = f(b_x1,e_x1,x) must be in [b_x1,e_x1]. 
+    //
+    // If i == e_x1, x is put at the end to [b_x1,e_x1)
+    //
+    // Another valid choice for F is nn1::find 
+    template<typename T,typename X,typename F = functional::find>
+    class mean_events_by_covariate{
+        public:
+        typedef mean_event<T> mean_event_;
+        typedef tuple<X,mean_event_> tuple_;
+        typedef std::vector<tuple_> tuples_type;
+        
+        // Construct
+        mean_events_by_covariate();
+        template<typename Rx> mean_events_by_covariate(const Rx&);
+        template<typename Rx> mean_events_by_covariate(const Rx&,const F& f);
+        mean_events_by_covariate(const mean_events_by_covariate&);
+        mean_events_by_covariate& operator=(const mean_events_by_covariate&);
+
+        // Update
+        template<typename ItX,typename ItE>
+        void operator()(ItX b_x, ItX e_x, ItE b_e);
+
+        // Acces
+        const tuples_type& tuples()const;
+        template<typename It> It tails(It out); // copies the mean_events
+
+        private:
+        F finder_;
+        tuples_type tuples_;
+        template<typename Rx>
+        void set_covs(const Rx& rx);
+    };
+
+    // Implementation //
+
+    template<typename T,typename X,typename F>
+    mean_events_by_covariate<T,X,F>::mean_events_by_covariate(){}
+    
+    template<typename T,typename X,typename F>
+    template<typename Rx> 
+    mean_events_by_covariate<T,X,F>::mean_events_by_covariate(const Rx& rx)
+    :finder_(){
+        this->set_covs(rx);
+    }
+
+    template<typename T,typename X,typename F>
+    template<typename Rx>
+    mean_events_by_covariate<T,X,F>::mean_events_by_covariate(
+        const Rx& rx,const F& f)
+    :finder_(f){
+        this->set_covs(rx);
+    }
+
+    template<typename T,typename X,typename F>
+    template<typename Rx>
+    void mean_events_by_covariate<T,X,F>::set_covs(const Rx& rx){
+        typedef typename range_value<Rx>::type x_;
+        mean_event_ me;
+        BOOST_FOREACH(const x_& x,rx){
+            tuple_ t(x,me);
+            tuples_.push_back( t );
+        }
+    }
+        
+    template<typename T,typename X,typename F>
+    template<typename ItX,typename ItE>
+    void mean_events_by_covariate<T,X,F>::operator()(ItX b_x,ItX e_x,ItE b_e)
+    {
+        typedef binary_op::match_accumulator<tuples_type&,F> functor_;
+        std::for_each(
+            make_zip_iterator( make_tuple( b_x, b_e ) ),
+            make_zip_iterator( 
+                make_tuple( 
+                    e_x, 
+                    boost::next(
+                        b_e,
+                        std::distance(b_x,e_x)
+                    ) 
+                ) 
+            ),
+            functor_(this->tuples_)
+        );
+    }
+
+    // Access
+    template<typename T,typename X,typename F>
+    const typename mean_events_by_covariate<T,X,F>::tuples_type& 
+    mean_events_by_covariate<T,X,F>::tuples()const{
+        return (this->tuples_);
+    }
+
+
+    template<typename T,typename X,typename F>
+    template<typename It> 
+    It mean_events_by_covariate<T,X,F>::tails(It out){
+        return binary_op::tails(
+            boost::begin(this->tuples()),
+            boost::end(this->tuples()),
+            out
+        );
+    }
+
+}// data        
+}// survival
+}// boost
+    
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/algorithm/vectorize_events.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/algorithm/vectorize_events.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,54 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::algorithm::make_mean_events.hpp                           //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_ALGORITHM_VECTORIZE_EVENTS_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_ALGORITHM_VECTORIZE_EVENTS_HPP_ER_2009
+#include <boost/iterator/iterator_traits.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+// Copies the failure and event time of each event in a sequence to an
+// output iterator
+template<typename ItE,typename ItO>
+ItO vectorize_events(
+    ItE b,
+    ItE e,
+    ItO o
+);
+    
+    // Implementation //
+    
+template<typename ItE,typename ItO>
+ItO vectorize_events(
+    ItE b,
+    ItE e,
+    ItO o
+){
+    typedef typename iterator_value<ItE>::type event_;
+    typedef typename event_::value_type val_;
+    typedef typename event_::failure_type fail_;
+    BOOST_MPL_ASSERT((
+        is_same<val_,fail_>
+    ));
+    
+    while(b!=e){
+        *o = (b->failure()); ++o;
+        *o = (b->time()); ++o;
+        ++b;
+    }
+    return o;
+}
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/data/event.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/data/event.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,127 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::data::event.hpp                                           //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_DATA_EVENT_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_DATA_EVENT_HPP_ER_2009
+#include <limits>
+#include <ostream>
+#include <boost/format.hpp>
+#include <boost/operators.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/survival/constant.hpp>
+#include <boost/arithmetic/equal.hpp>
+
+namespace boost {
+namespace survival {
+namespace data {
+
+    // Abstraction for failure indicator and event time.
+    //
+    // B == T can be useful to represent a proportion of failures (see
+    // mean_event)
+    template<typename T,typename B = bool>
+    class event : equality_comparable<event<T,B> >{
+        typedef constant<T> const_;
+        public:
+        typedef T value_type;
+        typedef B failure_type;
+        // Construction 
+        event();
+        explicit event(B isf,value_type rt);
+        event(const event&);
+        event& operator=(const event&);
+
+        // Access 
+        B failure()const;
+        value_type time()const;
+    
+        // Operators 
+        bool operator==(const event&);
+        
+        protected:
+        friend class boost::serialization::access;
+        
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version);
+                
+        B failure_;         //!censored
+        value_type time_;   //since entry time
+    };
+
+
+    template<typename T,typename B>
+    std::ostream& operator<<(std::ostream& out,const event<T,B>& e);
+    
+    // Implementation //
+    
+    
+    //Construct
+    template<typename T,typename B>
+    event<T,B>::event():failure_(false),time_(const_::inf_){}
+    
+    template<typename T,typename B>
+    event<T,B>::event(B isf,value_type rt)
+    :failure_(isf),time_(rt){}
+
+    template<typename T,typename B>
+    event<T,B>::event(const event& that)
+    :failure_(that.failure_),time_(that.time_){}
+
+    template<typename T,typename B>
+    event<T,B>& 
+    event<T,B>::operator=(const event& that){
+        if(&that!=this){
+            failure_ = (that.failure_);
+            time_ = (that.time_);            
+        }
+        return *this;
+    }
+
+    template<typename T,typename B>
+    std::ostream& operator<<(std::ostream& out,const event<T,B>& e){
+        static const char* str = "(%1%,%2%)";
+        format f(str);
+        f % e.failure() % e.time();
+        out << f.str();
+        return out;
+    }
+            
+    template<typename T,typename B>
+    B event<T,B>::failure()const{ return failure_; }
+
+    template<typename T,typename B>
+    typename event<T,B>::value_type event<T,B>::time()const{ 
+        return time_;
+    }
+
+    template<typename T,typename B>
+    template<class Archive>
+    void event<T,B>::serialize(Archive & ar, const unsigned int version)
+    {
+        ar & failure_;
+        ar & time_;
+    }
+
+    // Operators
+    template<typename T,typename B>
+    bool event<T,B>::operator==(const event& e){
+        bool eq_1 = arithmetic_tools::equal(
+            e.time(),
+            (this->time())
+        );
+        bool eq_2 = arithmetic_tools::equal(
+            (this->failure_) , (e.failure())
+        );
+        return  (eq_1 && eq_2);    
+    }
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/data/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::data::include.hpp                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_DATA_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/data/data/event.hpp>
+#include <boost/survival/data/data/mean_event.hpp>
+#include <boost/survival/data/data/record.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/data/mean_event.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/data/mean_event.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,184 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data:data::mean_event.hpp                                       //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_DATA_MEAN_EVENT_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_DATA_MEAN_EVENT_HPP_ER_2009
+#include <boost/type_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/format.hpp>
+#include <boost/operators.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/survival/constant.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+
+    // This class can be used to accumulate the proportion of failures and 
+    // mean event time in a sequence of events.
+    //
+    // In the case of the exponential, a collection of mean_events can
+    // form a sufficient statistic,  assuming a discretized domain for
+    // the covariate: domain(x) = {x[k]:k=0,...,K-1}
+    //
+    // $\log L_i(\beta) = \nu_i \eta_i - t_i \exp(\eta_i)$
+    // where $\eta_i = \langle x_i,beta \rangle$
+    // log L(D,\beta) = sum{
+    //    <x[k],\beta> sum{\nu[i]:x[i]==x[k]}
+    //     -exp(<x[k],\beta>) sum{t[i] : x[i]==x[k]}
+    //  :k=1,...,K
+    // }
+    // Sufficient statistic:
+    // {(sum{\nu[i]:x[i]==x[k]},sum{t[i] : x[i]==x[k]}):k=0,...,K-1}
+    template<typename T,typename B = bool>
+    class mean_event : 
+        public event<T,T>, 
+        boost::addable<mean_event<T,B>, addable<event<T,B> > >
+        // TODO equality_comparable<mean_event<T,B> >
+    {
+    public:
+        typedef event<T,B>  event_;
+        typedef event<T,T>  super_;
+        typedef typename super_::value_type value_type;
+        typedef std::size_t                 size_type;
+            
+        // Construction
+        mean_event();
+        mean_event(const event_&);
+        mean_event(const mean_event&);
+        mean_event& operator=(const mean_event&);
+            
+        // Access
+        size_type count()const;
+            
+        // Operators
+        mean_event& operator+=(const mean_event& e);
+        mean_event& operator+=(const event_& e);
+        mean_event& operator()(const event_& e); //same as +=
+        
+        // I/O
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version);
+        
+        private:
+        value_type impl(size_type n_a,value_type a,size_type n_b,value_type b);
+        size_type  count_;
+        static super_ convert(const event_&);
+    };
+
+    template<typename T,typename B>
+    std::ostream& operator<<(std::ostream& out,const mean_event<T,B>& e);
+
+    template<typename E>
+    struct meta_mean_event{
+        typedef typename E::value_type value_type;
+        typedef mean_event<value_type> type;
+    };
+    
+    
+    // Implementation //
+    
+    // Constructor
+    template<typename T,typename B>
+    mean_event<T,B>::mean_event():super_(),count_(0){}
+
+    template<typename T,typename B>
+    mean_event<T,B>::mean_event(const event_& e):super_(convert(e)),count_(1){}
+
+    template<typename T,typename B>
+    mean_event<T,B>::mean_event(const mean_event& that)
+    :super_(that),count_(that.count_){}
+
+    template<typename T,typename B>
+    mean_event<T,B>& 
+    mean_event<T,B>::operator=(const mean_event& that){
+        if(&that!=this){
+            super_::operator=(that);
+            count_ = that.count_;
+        }
+        return *this;
+    }
+    
+    // Access
+    template<typename T,typename B>
+    typename mean_event<T,B>::size_type 
+    mean_event<T,B>::count()const{ return count_; }
+    
+    // Update
+    template<typename T,typename B>
+    mean_event<T,B>& 
+    mean_event<T,B>::operator+=(const event_& e){
+        mean_event other(e);
+        return ( (*this) += other );
+    }
+    
+    template<typename T,typename B>
+    mean_event<T,B>& 
+    mean_event<T,B>::operator+=(const mean_event& other){
+        size_type n_a = this->count();
+        size_type n_b = other.count();
+        (this->failure_) 
+            = (this->impl(n_a,this->failure(),n_b,other.failure()));
+        (this->time_) 
+            = (this->impl(n_a,this->time(),n_b,other.time()));
+        (this->count_) += n_b;
+        return *this;
+    }
+
+    template<typename T,typename B>
+    mean_event<T,B>& 
+    mean_event<T,B>::operator()(const event_& e){
+        return (*this)+=e;
+    }
+    
+    //Private
+    template<typename T,typename B>
+    template<class Archive>
+    void mean_event<T,B>::serialize(Archive & ar, const unsigned int version)
+    {
+        ar & boost::serialization::base_object<super_>(*this);
+        ar & count_;
+    }
+
+    template<typename T,typename B>
+    typename mean_event<T,B>::value_type 
+    mean_event<T,B>::impl(
+            size_type n_a,value_type a,size_type n_b,value_type b){
+        return ( (n_a * a) + (n_b * b) ) / (n_a + n_b);
+    }
+    
+    template<typename T,typename B>
+    std::ostream& operator<<(std::ostream& out,const mean_event<T,B>& that){
+        typedef mean_event<T,B> that_;
+        typedef typename that_::super_ super_;
+        static const char* str = "(%1%,%2%)";
+        format f(str);
+        f % that.count() % static_cast<const super_&>(that) ;
+        out << f.str();
+        return out;
+    }
+
+    template<typename T,typename B>
+    typename mean_event<T,B>::super_ 
+    mean_event<T,B>::convert(const event_& e){
+        static value_type zero = static_cast<value_type>(0);
+        static value_type one = static_cast<value_type>(1);
+        value_type t = e.time();
+        if(e.failure()){
+            return super_(one,t);
+        }else{
+            return super_(zero,t);
+        }
+    }
+
+}// data
+}// survival
+}// boost
+
+#endif
Added: sandbox/statistics/survival_data/boost/survival/data/data/record.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/data/record.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,157 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::record.hpp                                                //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_RECORDER_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RECORDER_HPP_ER_2009
+#include <ostream>
+#include <limits>
+#include <boost/operators.hpp>
+#include <boost/format.hpp>
+#include <boost/math/special_functions/fpclassify.hpp> //isinf
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/survival/constant.hpp>
+#include <boost/survival/data/data/event.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+// Abstraction for entry time (t) and the failure time (rt). 
+//
+// If not set during initialization, the failure time can be set later.
+template<typename T>
+class record : less_than_comparable<record<T> >{
+protected:
+    typedef constant<T> const_;
+public:
+    typedef T value_type;
+    record(); //inf,inf
+    record(value_type t); 
+    record(value_type t, value_type rt);
+    // default copy/assign
+    void set_failure_time(value_type rt);
+    value_type entry_time()const;
+    value_type failure_time()const;
+
+    template<typename Archive>
+    void serialize(Archive & ar, const unsigned int version);
+
+    bool operator<(const record& other);
+    
+protected:
+    value_type entry_time_;     //t
+    value_type failure_time_;   //rt
+};
+
+template<typename T>
+std::ostream& operator<<(std::ostream& out,const record<T>& r);
+
+template<typename T>
+bool operator<(const record<T>& a,const record<T>& b);
+    
+template<typename T>
+typename record<T>::value_type 
+time_since_entry(const record<T>& r, typename record<T>::value_type t);
+        
+// TODO is_at_risk
+    
+template<typename T>    
+event<T>  make_event(const record<T>& r, typename record<T>::value_type t);
+    
+    // Implementation //
+    
+// Construct
+template<typename T> 
+record<T>::record():entry_time_(const_::inf_),failure_time_(const_::inf_){}
+
+template<typename T>
+record<T>::record(value_type t):entry_time_(t),failure_time_(const_::inf_){}
+
+template<typename T>
+record<T>::record(value_type t,value_type rt)
+:entry_time_(t),failure_time_(rt){}
+
+// Assign
+template<typename T>
+void record<T>::set_failure_time(value_type rt){
+    static const char* method = "survival::record::set_failure_time(%1%)";
+    if(math::isinf(this->failure_time_)){
+        this->failure_time_ = rt;
+    }else{
+        static const char* err = " error : overriding failure time";
+        throw exception(
+            format(method,rt).str(),
+            err,
+            *this
+        );
+    }
+}
+
+template<typename T>
+template<typename Archive>
+void record<T>::serialize(Archive & ar, const unsigned int version){
+    ar & entry_time_;
+    ar & failure_time_;
+} 
+    
+// Access
+
+template<typename T>
+typename record<T>::value_type 
+record<T>::entry_time()const{ return entry_time_; }
+
+template<typename T>
+typename record<T>::value_type 
+record<T>::failure_time()const{ return failure_time_; }
+
+template<typename T>
+std::ostream& operator<<(std::ostream& out,const record<T>& r){
+    out << '(' <<  r.entry_time() << ',' << r.failure_time() << ')';
+    return out; 
+}
+    
+template<typename T>
+bool record<T>::operator<(const record<T>& other){
+    return ( (this->entry_time()) < other.entry_time() );
+}
+
+template<typename T>
+typename record<T>::value_type 
+time_since_entry(const record<T>& r, typename record<T>::value_type t)
+{
+    //Warning may be <0
+    return t-r.entry_time();
+}
+
+// TODO is_at_risk
+
+template<typename T>    
+event<T>  make_event(const record<T>& r, typename record<T>::value_type t){
+    static const char* fun = "survival::make_event(%1%,%2)";
+    typedef typename record<T>::value_type value_t;
+    value_t eps = math::tools::epsilon<T>();
+    value_t dt = time_since_entry(r,t); 
+    if(dt>eps){
+        typedef event<T> result_type;
+        bool b = ( r.failure_time() <= dt );
+        value_t rt = b ? r.failure_time() : dt;
+        return result_type(b, rt);
+    }else{
+        static const char* err = "error: time_since_entry = %1%";
+        format f(fun); f%r%t;
+        std::string str = f.str();
+        f = format(err); f%dt; str+= f.str();
+        throw std::runtime_error( str );
+    }
+}    
+
+}// data                
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,17 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::include.hpp                                               //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/constant.hpp>
+#include <boost/survival/data/algorithm/include.hpp>
+#include <boost/survival/data/data/include.hpp>
+#include <boost/survival/data/meta/include.hpp>
+#include <boost/survival/data/random/include.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/meta/failure_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/meta/failure_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,40 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::meta::failure_distribution.hpp                            //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#include <boost/model/wrap/aggregate/model_covariate_parameter.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+    // Model + Covariate + Parameter ---> failure time distribution (such as
+    // defined in boost/math/distributions)
+    //
+    // These are only declarations. The implementation must specialize on M.
+    template<typename M> 
+    struct meta_failure_distribution{
+        // typedef ... type
+    };
+
+    template<typename M,typename X,typename P>
+    typename meta_failure_distribution<M>::type
+    make_failure_distribution(
+        boost::model::model_covariate_parameter_<M,X,P> mcp
+    ){
+        typedef meta_failure_distribution<M> meta_;
+        return meta_::make(
+            mcp
+        );
+    }
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/meta/failure_random.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/meta/failure_random.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,51 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::meta::failure_random.hpp                                  //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_META_FAILURE_RANDOM_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_META_FAILURE_RANDOM_HPP_ER_2009
+#include <boost/dist_random/include.hpp>
+#include <boost/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/survival/data/meta/failure_distribution.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+
+    // Model + Covariate + Parameter --->  RandomDistribution (of failure time)
+    //
+    // These are default implementations that can be overloaded with a 
+    // specialization on M
+
+    template<typename M> 
+    struct meta_failure_random{
+        typedef meta_failure_distribution<M>                        map1_;
+        typedef typename map1_::type                                dist_;
+        typedef boost::dist_random<dist_>                           map2_;
+        typedef typename map2_::type                                type;
+    };
+
+    template<typename M,typename X,typename P>
+    typename meta_failure_random<M>::type 
+    make_failure_random(boost::model::model_covariate_parameter_<M,X,P>);
+
+    // Implementation //
+
+    template<typename M,typename X,typename P>
+    typename meta_failure_random<M>::type 
+    make_failure_random(boost::model::model_covariate_parameter_<M,X,P> mcp){
+        typedef meta_failure_random<M>                              map_;
+        typedef typename map_::map2_                                map2_;
+        return map2_::make(
+            make_failure_distribution(mcp) 
+        );
+    }
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/meta/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/meta/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::meta::include.hpp                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_META_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_META_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/data/meta/failure_distribution.hpp>
+#include <boost/survival/data/meta/failure_random.hpp>
+#include <boost/survival/data/meta/random_input.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/meta/random_input.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/meta/random_input.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,32 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::meta::random_input.hpp                                    //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_META_RANDOM_INPUT_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_META_RANDOM_INPUT_HPP_ER_2009
+#include <boost/survival/data/meta/failure_distribution.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+namespace meta{
+
+    // Model + Covariate + Parameter ---> InputType
+    //
+    // This is a default implementation that can be overriden with a specializ-
+    // ation on M.
+    template<typename M> 
+    struct random_input{
+        typedef typename meta_failure_random<M>::type rdist_;
+        typedef typename rdist_::input_type type;
+    };
+    
+}// meta
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/random/batch.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/random/batch.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,151 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::random::batch.hpp                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_RANDOM_BATCH_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RANDOM_BATCH_HPP_ER_2009
+#include <iostream> // TODO remove
+#include <boost/format.hpp>
+#include <boost/range.hpp>
+#include <boost/random/variate_generator.hpp>
+#include <boost/random/gen_to_random.hpp>
+#include <boost/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/survival/data/data/record.hpp>
+#include <boost/survival/data/random/failure_time.hpp>
+#include <boost/survival/data/meta/random_input.hpp>
+
+#include <boost/iterator/range_cycle.hpp> 
+
+namespace boost{
+namespace survival{
+namespace data{
+namespace random{
+
+    // Given model and parameter, simulates records (et,ft) like this:
+    // et is drawn from a random clock
+    // x random
+    // ft is drawn from the p(ft|x,p,model)
+    //
+    // Models RandomDistribution
+    template<
+        typename T,                                         // float
+        typename M,                                         // model        
+        typename P,                                         // parameter
+        typename RdC,  // RandomDistribution                // clock
+        typename RdX,  // RandomDistribution                // covariate
+        typename I = typename meta::random_input<M>::type
+    >
+    class batch : public model::model_parameter_<M,P>{
+        public:
+        typedef T                                           value_type;
+        typedef I                                           input_type; 
+        typedef record<value_type>                          result_type;
+        typedef typename RdX::result_type                   covariate_type;
+
+        typedef model::model_parameter_<M,P>                model_parameter_;
+        typedef model::model_covariate_parameter_<M,covariate_type,P> 
+                                                model_covariate_parameter_;
+
+        // Constructor
+        batch();
+        batch( const M&, const P&,const RdC&,const RdX& );
+        batch( const batch& );
+        batch& operator=( const batch& );
+
+        // Random generation
+        template<typename U>
+        result_type operator()(U& u);
+
+        // Access
+        const covariate_type& covariate()const; //last generated covariate
+        
+        private:
+        RdC rdc_;
+        RdX rdx_;
+        covariate_type x_;  
+        template<typename U> void gen_x(U&);
+    };
+
+
+    // Implementation //
+
+    //Construction
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    batch<T,M,P,RdC,RdX,I>::batch():model_parameter_(){}
+
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    batch<T,M,P,RdC,RdX,I>::batch( 
+        const M& m,const P& p, const RdC& rdc,const RdX& rdx 
+    ):model_parameter_(m,p),rdc_(rdc),rdx_(rdx),x_(){}
+
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    batch<T,M,P,RdC,RdX,I>::batch( 
+        const batch& that
+    ):model_parameter_(that),rdc_(that.rdc_),rdx_(that.rdx_),x_(that.x_){}
+
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    batch<T,M,P,RdC,RdX,I>&
+    batch<T,M,P,RdC,RdX,I>::operator=( 
+        const batch& that
+    ){
+        if(&that!=this){
+            model_parameter_::operator=( that.model_parameter );
+            rdc_ = (that.rdc_);
+            rdx_ = (that.rdx_);
+            x_ = that.x_;
+        }
+        return (*this);
+    }
+    
+    // Generation
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    template<typename U> 
+    typename batch<T,M,P,RdC,RdX,I>::result_type 
+    batch<T,M,P,RdC,RdX,I>::operator()(U& u){
+        this->gen_x(u);
+        value_type et = (this->rdc_)(u); //entry time
+        BOOST_ASSERT(!( et < static_cast<value_type>(0) ) );
+        const model_parameter_& mp 
+            = static_cast<const model_parameter_&>(*this);
+        value_type ft = random::failure_time<value_type>(
+            boost::model::make_model_covariate_parameter(
+                mp.model(),
+                this->covariate(),
+                mp.parameter()
+            ),  
+            u
+        );
+        return result_type(et,ft);
+    }
+
+    // Access
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    const typename batch<T,M,P,RdC,RdX,I>::covariate_type& 
+    batch<T,M,P,RdC,RdX,I>::covariate()const{ return this->x_; }
+        
+    // Private
+    template<
+        typename T,typename M,typename P, typename RdC,typename RdX,typename I>
+    template<typename U> 
+    void batch<T,M,P,RdC,RdX,I>::gen_x(U& urng){
+        typedef variate_generator<U&,RdX> vg_;
+        // Necessary in the likely case that RdX::input_type != I
+        vg_ vg(urng,rdx_); 
+        this->x_ = vg();
+    }
+    
+}// random    
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/random/default_batch.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/random/default_batch.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::random::default_batch.hpp                                 //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_RANDOM_DEFAULT_BATCH_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RANDOM_DEFAULT_BATCH_HPP_ER_2009
+#include <boost/random/gen_to_random.hpp>
+#include <boost/functional/clock.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/functional/visitor.hpp>
+#include <boost/iterator/range_cycle.hpp> 
+#include <boost/random/ref_distribution.hpp>
+#include <boost/survival/data/random/batch.hpp>
+
+
+namespace boost{
+namespace survival{
+namespace data{
+namespace random{
+
+    template<
+        typename T,
+        typename M,
+        typename P, 
+        typename Rx,    // Range // Covariate values
+        typename I = typename meta::random_input<M>::type
+    >
+    class meta_default_batch{
+        // Covariates
+        typedef range_cycle<>                                   meta_;
+        typedef typename meta_::apply<Rx>::type                 cycle_;
+        typedef typename functional::visitor<cycle_>            gcov_;
+        public:
+        typedef boost::random::gen_to_random<gcov_,I>           rcov_;
+        private:
+        // Necessary in combination with cycle
+        typedef boost::random::ref_distribution<rcov_&>         ref_rcov_;
+        typedef shared_ptr<rcov_> shared_; 
+
+        // Clock
+        typedef functional::clock<T>                            gc_;
+        typedef boost::random::gen_to_random<gc_,I>             rc_;
+
+        public:
+        typedef std::size_t                                     size_type;
+        typedef gc_                                             clock_type;
+    
+        typedef batch<T,M,P,rc_,ref_rcov_,I>  type;
+        
+        typedef typename type::model_parameter_ mp_;
+
+        static rcov_ rcov(
+            Rx& rx,             // Not const Rx&? TODO see range_cycle
+            size_type offset,
+            size_type n
+
+        ){
+            return rcov_(
+                gcov_(
+                    meta_::make(rx,offset,n)
+                )
+            );
+        }
+        
+        // rcov above must be called from outside.
+        static type make(
+            const M& m,
+            const P& p,
+            const clock_type& c,
+            rcov_& rcov
+        ){
+            return type(
+                m,p,
+                rc_(c),
+                ref_rcov_(
+                    rcov
+                )
+            );
+        }
+
+    };
+    
+}// random    
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/random/failure_time.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/random/failure_time.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,44 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::random::failure_time.hpp                                  //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_RANDOM_FAILURE_TIME_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RANDOM_FAILURE_TIME_HPP_ER_2009
+#include <boost/dist_random/include.hpp>
+#include <boost/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/survival/data/meta/failure_distribution.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+namespace random{
+
+    // Model + Covariate + Parameter + URNG ---> failure time
+    // 
+    // This is a default implementaion that relies on meta::failure_random. It
+    // can be overloaded by specializing on M.
+    template<typename T,typename M,typename X,typename P,typename U>
+    T failure_time(
+        boost::model::model_covariate_parameter_<M,X,P> mcp,
+        U& urng
+    ); 
+
+    // Implementation //
+
+    template<typename T,typename M,typename X,typename P,typename U>
+    T failure_time(
+        boost::model::model_covariate_parameter_<M,X,P> mcp,
+        U& urng
+    ){
+        return make_failure_random(mcp)(urng);
+    }
+ 
+}// random
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/boost/survival/data/random/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/boost/survival/data/random/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::random::include.hpp                                       //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_DATA_RANDOM_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_DATA_RANDOM_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/data/random/batch.hpp>
+#include <boost/survival/data/random/default_batch.hpp>
+#include <boost/survival/data/random/failure_time.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/survival/data/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,90 @@
+//////////////////////////////////////////////////////////////////////////////
+// survival::data::doc::readme                                              //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These C++ classes are abstractions for survival data (right censored, staggered 
+entry) and associated tools. See survival_model.
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/ 
+/sandbox/statistics/joint_dist/ 
+/sandbox/statistics/survival_model/ 
+/sandbox/statistics/non_param/ 
+/sandbox/statistics/matrix_view/ 
+/sandbox/statistics/non_param/ 
+/sandbox/statistics/random/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/dist_random/ 
+/sandbox/statistics/binary_op/ 
+/sandbox/statistics/functional/ 
+/sandbox/statistics/arithmetic/ 
+/sandbox/statistics/iterator/ 
+/sandbox/statistics/standard_distribution/ 
+
+Link to : libboost_serialization-xgcc42-mt-1_39.a
+
+[ History ]
+
+July 2009 : Current version
+
+[ Sources ]
+
+http://en.wikipedia.org/wiki/Survival_analysis
+
+[ Notation ]
+
+    Consider, for example, a clinical trial. t is a time measured since the 
+    beginning of the trial. rt is a time relative to a data-unit's entry time 
+    into the trial. 
+
+    Type  Class         Object id       Abstraction                 Concept
+    alias    
+    T                   t, t1, rt                                   is_scalar
+    R     record<T>     r               entry & fail time                      
+    E     event<T>      e               fail indic & event time
+    Me    mean_event<T> me              mean indic & event time
+
+[ data ] 
+
+    R r(t,rt);
+    Me me; 
+    E e0 = make_event(r,t0); me += e0;
+    E e1 = make_event(r,t1); me += e1;
+
+[ algorithm ] 
+
+    Algorithms that iterate over a dataset
+
+[ random ] 
+
+    Classes that simulate data given a model 
+        
+[ meta ]
+
+    A bridge between survival::data and survival::model
+    
+    
+[ Output ]
+
+main.cpp
+
+-> example_data :  records : (0,2) (1,2) (2,2) (3,2)  events : (1,2) (1,2) (0,1)
+ size(x_cycle) = 4
+mean_events : (2,(0,1)) (1,(1,2)) flattened mean_events : 0 1 1 2 <-
+-> example_random : 
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/survival/data/example/data.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/example/data.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,221 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::example::data.cpp                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <vector>
+#include <ostream>
+#include <fstream>
+#include <stdexcept>
+#include <string> //needed?
+#include <algorithm>
+#include <iterator>
+#include <boost/tuple/tuple.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp> 
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <boost/survival/data/include.hpp>
+#include <libs/survival/data/example/data.h>
+
+void example_data(std::ostream& out){
+    out << "-> example_data : ";
+    
+    // Steps shown in this example:
+    //
+    // Records creation
+    // Events creation
+    // I/O
+    // Statistics
+    
+    using namespace boost;
+    namespace surv = survival::data;
+
+    // [ Types ]
+    typedef unsigned val_; // do not modify
+    typedef std::vector<val_> vals_;
+
+    // Records
+    typedef surv::record<val_> record_;
+    typedef std::vector<record_> records_;
+    typedef range_iterator<records_>::type it_record_;
+
+    // Events
+    typedef surv::event<val_> event_;
+    typedef std::vector<event_> events_;
+    typedef range_iterator<events_>::type it_event_;
+
+    // I/O
+    typedef boost::archive::text_oarchive oa_;
+    typedef boost::archive::text_iarchive ia_;
+
+    // Covariates
+    typedef val_                                    x_;
+    typedef vals_                                   r_x_;
+    typedef range_cycle<>                           range_cycle_;
+    typedef range_cycle_::apply<r_x_>::type         x_cycle_;
+
+    // Statistics
+    typedef surv::mean_event<val_>                  me_;
+    typedef std::vector<me_>                        mes_;
+    typedef surv::mean_events_by_covariate<val_,x_> mes_by_x_;
+
+    // [ Constants ]
+    const unsigned n_record = 4; 
+    const val_ entry_bound = n_record - 1;
+    const val_ fail_time = 2;
+
+    // [ Records ]
+    records_ records;
+    events_ events;
+    for(val_ i = 0; i<n_record; i++){
+        val_ entry_t = i;
+        record_ record(entry_t,fail_time);
+        records.push_back(record);
+    }
+
+    out << " records : ";
+    for(val_ i = 0; i<n_record; i++){
+        out << records[i] << ' ';
+    }
+
+    // [ Events ]
+    
+    surv::events(
+        begin(records),
+        end(records),
+        entry_bound,
+        std::back_inserter(events)
+    );
+    
+    // Analysis for n_record = 4 and entry_bound = 3;
+    //      e       ft      dt     ft<=dt  min(ft,dt)
+    //      0       2       3       1       2
+    //      1       2       2       1       2
+    //      2       2       1       0       1
+    //      3       2       0       NA      NA
+
+    BOOST_ASSERT(size(events) == entry_bound);
+    out << " events : ";
+    BOOST_FOREACH(const event_& e,events){
+        out << e << ' ';
+    }
+
+    // [ I/O ]
+    const char* path = "./serialized_events";
+    
+    {
+        // Save events
+        std::ofstream ofs(path);
+        oa_ oa(ofs);
+        BOOST_FOREACH(const event_& e,events){
+            oa << e;
+            ofs.flush();
+        }
+    }
+    val_ n = size(events);
+    events_ events2;
+    {
+        // Recover events
+        event_ tmp;
+        std::ifstream ifs(path);
+        if(ifs.good()){
+            ia_ ia(ifs);
+            val_ j = 0;
+            //while(true){ //TODO
+            while(j<n){
+                ia >> tmp;
+                events2.push_back(tmp);
+                // TODO 
+                //if (ifs.eof()) break; 
+                //if (ifs.fail()){
+                //    throw std::runtime_error("error reading");
+                //}
+                ++j;
+            }
+        }else{
+            std::string str = "error opening : ";
+            str.append( path );
+            throw std::runtime_error(str);
+        }
+    }
+    BOOST_ASSERT(n == size(events2));
+    for(val_ i = 0; i<n; i++){
+        BOOST_ASSERT(events[i] == events2[i]);
+    }
+
+    // [ Statistics ]
+    // Assume the records were generated conditional on the following
+    // covariates:
+    r_x_ r_x;
+    {
+        using namespace boost::assign;
+        r_x += 1, 2;
+    }
+    x_cycle_ x_cycle = range_cycle_::make(r_x,0,n_record);
+    out << "size(x_cycle) = " << size(x_cycle) << std::endl;
+    BOOST_ASSERT( size(x_cycle)>=size(events) );
+    // Resize x_cycle to a size that matches that of events
+    x_cycle.advance_end(
+        - (size(x_cycle) - size(events))
+    );
+    BOOST_ASSERT( size(x_cycle)==size(events) );
+
+    mes_by_x_ mes_by_x(r_x);
+    mes_by_x(
+        boost::begin(x_cycle),
+        boost::end(x_cycle),
+        boost::begin(events)
+    );
+
+    mes_ mes;
+    mes_by_x.tails(std::back_inserter(mes));
+    
+    // Analysis for n_record = 4 and entry_bound = 3;
+    //      x       ft<=dt  min(ft,dt)  
+    //      1       1       2
+    //      2       1       2
+    //      1       0       1
+    // -------------------------------
+    //      1       1/2=0   3/2 = 1         // Remember, val_ = unsigned,
+    //      2       1       2               // not a float
+    
+    out << "mean_events : ";
+    std::copy(
+        boost::begin(mes),
+        boost::end(mes),
+        std::ostream_iterator<me_>(out," ")
+    );
+
+    vals_ flat_mes;
+    surv::vectorize_events(
+        boost::begin(mes),
+        boost::end(mes),
+        std::back_inserter(flat_mes)
+    );
+
+    out << "flattened mean_events : ";
+    std::copy(
+        boost::begin(flat_mes),
+        boost::end(flat_mes),
+        std::ostream_iterator<val_>(out," ")
+    );
+
+// TODO put elsewhere in example/
+// Dont try this here because val_ = unsigned, but you get the idea
+//    surv::algorithm::logit_log(
+//        boost::begin(flat_mean_events),
+//        boost::end(flat_mean_events),
+//        std::back_inserter(flat_mean_events),
+//        0.01,
+//        0.01
+//    );
+    out << "<-" << std::endl;
+}
+
+
Added: sandbox/statistics/survival_data/libs/survival/data/example/data.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/example/data.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::example::data.h                                           //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef LIBS_SURVIVAL_DATA_EXAMPLE_DATA_HPP_ER_2009
+#define LIBS_SURVIVAL_DATA_EXAMPLE_DATA_HPP_ER_2009
+#include <ostream>
+
+void example_data(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/survival/data/example/random.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/example/random.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,235 @@
+//#include <cmath>
+#include <stdexcept>
+#include <fstream>
+#include <ostream>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <algorithm>
+#include <ext/algorithm> // is_sorted
+#include <iterator>
+#include <functional>
+
+#include <boost/typeof/typeof.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
+#include <boost/timer.hpp>
+#include <boost/range.hpp>
+#include <boost/utility.hpp>
+
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/variate_generator.hpp>
+
+#include <boost/math/tools/precision.hpp>
+#include <boost/standard_distribution/distributions/normal.hpp>         //prior
+#include <boost/standard_distribution/distributions/exponential.hpp>    //data
+
+#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+
+#include <boost/matrix_view/algorithm/transform_column.hpp> 
+#include <boost/dist_random/include.hpp>
+
+#include <boost/model/include.hpp>
+#include <boost/survival/data/include.hpp>
+#include <boost/survival/model/models/exponential/include.hpp>
+
+
+void example_random(std::ostream& out){
+    out << "-> example_random : ";
+    
+    using namespace boost;
+    namespace surv = survival;
+
+    // Generates batches of iid random records as follows:
+    // 1) The parameter is generated, for each batch, given a prior.
+    // 2) The covariates are generated in cyclic fashion within each batch
+    // 3) Data is generated given model, parameter, covariate, entry time.
+    // KS distances are computed for each batch of data
+    // Each batch is saved using serialization
+
+    // Types 
+    typedef double                                          val_;
+    typedef std::vector<val_>                               vals_;
+    typedef range_iterator<vals_>::type                     iter_val_;
+    typedef boost::mt19937                                  urng_;
+
+    // Covariates values
+    typedef val_                                            x_;
+    typedef vals_                                           x_vals_;
+    typedef range_cycle<>                                   range_cycle_;
+    typedef range_cycle_::apply<x_vals_>::type              x_cycle_;
+    typedef range_size<x_vals_>::type                       size_;
+
+    // Survival data
+    typedef surv::data::record<val_>                        record_;
+    typedef std::vector<record_>                            records_;
+    typedef std::vector<records_>                           records_batches_;
+
+    // Model
+    typedef math::normal_distribution<val_>                 mprior_;
+    typedef val_                                            par_;
+    typedef std::vector<par_>                               pars_;
+    typedef surv::model::exponential::model<val_>           model_;
+    
+    // Batch
+    typedef surv::data::random::meta_default_batch<
+        val_, model_, par_, x_vals_>                        meta_batch_;
+
+    typedef meta_batch_::clock_type                         clock_;
+    typedef meta_batch_::type                               batch_;
+    typedef batch_::model_covariate_parameter_              mcp_;
+    typedef mcp_::model_parameter_w_                        mp_;
+    typedef variate_generator<urng_&,batch_>                vg_r; //record
+
+    // I/O
+    typedef boost::archive::text_oarchive                   oa_;
+    typedef boost::archive::text_iarchive                   ia_;
+    typedef std::ofstream                                   ofs_;
+
+    // Failure time distribution
+    typedef surv::data::meta_failure_distribution<model_>   meta_fd_;
+    typedef meta_fd_::type                                  fd_;
+
+    // [Constants]
+    const unsigned      k                   = 2;        // # number x values
+    const unsigned      n_record            = 1e2;
+    const unsigned      n_batch             = 1e4;
+    const unsigned      n_ks_data           = n_record/k;
+    const val_          mu                  = 0.0;
+    const val_          sigma               = 5.0;
+    const clock_        clock(0.0,0.0);
+
+    BOOST_ASSERT( n_record % k == 0 );
+    BOOST_ASSERT( n_ks_data % (n_record/k) == 0 );
+    
+    // [ os ]
+    const char* prior_path      = "./prior";
+    const char* x_vals_path     = "./x_vals";
+    const char* ks_path         = "./ks_data";
+    const char* batches_path    = "./batches";
+    const char* pars_path       = "./pars";
+    
+    // [ Covariate values ]
+    vals_ x_vals;
+    {
+        using namespace boost::assign;
+        x_vals += -0.5, 0.5;
+    }
+    BOOST_ASSERT(size(x_vals) == k);
+
+    {
+        ofs_    ofs(x_vals_path);
+        oa_     oa(ofs);
+        oa << x_vals;
+        ofs.flush();
+        ofs.close();
+    }
+
+    // [ Initialization ]
+    model_      model; 
+    mprior_     mprior( mu, sigma ); 
+    urng_       urng;
+    {
+        ofs_    ofs(prior_path);
+        oa_     oa(ofs);
+        BOOST_AUTO(prim,make_distribution_primitives(mprior));
+        oa << prim;
+        ofs.flush();
+        ofs.close();
+    }
+
+    // Buffers
+    records_ records; records.reserve(n_record);
+    pars_ true_pars; true_pars.reserve(n_batch);
+    vals_ kss; 
+    kss.reserve(n_ks_data);                             // kolmogorov-smirnov 
+    vals_ fts; fts.reserve(n_record / k);               // failure times
+    vals_ pars; pars.reserve(n_record);
+    {
+        // Simulate batches of records
+        ofs_    ofs_ks(ks_path);
+        ofs_    ofs_batches(batches_path);
+        ofs_    ofs_pars(pars_path);
+        oa_     oa_batches(ofs_batches);
+        oa_     oa_pars(ofs_pars);
+        ofs_ks << "first and last ks of the failure times : " << std::endl;
+        for(unsigned i = 0; i<n_batch; i++){
+            records.clear();
+            par_ par = boost::sample(mprior,urng);
+            oa_pars << par; 
+            ofs_pars.flush();
+            meta_batch_::rcov_ r = meta_batch_::rcov(
+                x_vals,
+                0,
+                n_record
+            );
+            batch_ batch = meta_batch_::make(
+                model,
+                par,
+                clock, 
+                r
+            );
+            true_pars.push_back( par );
+            vg_r vg_r( urng, batch );
+
+            std::generate_n(
+                std::back_inserter( records ),
+                n_record,
+                vg_r
+            );
+
+            BOOST_ASSERT(
+                is_sorted(
+                    boost::begin( records ),
+                    boost::end( records )
+                )
+            );// clock is supposed to tick forward
+            
+            oa_batches << records;
+            
+            if(n_ks_data>0){   
+                ofs_ks << (format("batch %1%, ")%i).str() << std::endl;
+                for(unsigned i = 0; i<k; i++){
+                    ofs_ks << (format("x[%1%] : ")%i).str();
+                    fts.clear();
+                    matrix_view::transform_column<k>(
+                        boost::begin(records),
+                        boost::end(records),
+                        i,
+                        lambda::bind(&record_::failure_time,lambda::_1),
+                        std::back_inserter(fts)
+                    );
+                    mcp_ mcp(
+                        batch.model(),
+                        x_vals[i],
+                        batch.parameter()
+                    );
+                    fd_ fail_dist = surv::data::make_failure_distribution(mcp);
+
+                    kss.clear();
+                    non_param::sequential_kolmogorov_smirnov_distance(
+                        fail_dist,
+                        boost::begin( fts ),
+                        boost::end( fts ),
+                        n_ks_data,
+                        std::back_inserter( kss )
+                    );
+ 
+                    if(n_ks_data>1){
+                        // Desired result: kss[0] < kss.back();
+                        ofs_ks << kss[0] << ',' << kss.back();
+                    }
+                    ofs_ks << std::endl;
+                    ofs_ks.flush();
+                }
+            }
+        } // batch loop
+        ofs_ks.close();
+        ofs_pars.close();
+        ofs_batches.close();
+    } // records generation
+}
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/survival/data/example/random.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/example/random.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,13 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::data::example::random.h                                         //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
+#define LIBS_SURVIVAL_DATA_EXAMPLE_RANDOM_HPP_ER_2009
+
+void example_random(std::ostream& out);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_data/libs/survival/data/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_data/libs/survival/data/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,19 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::src::main.cpp                                                   //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <fstream>
+#include <libs/survival/data/example/data.h>
+#include <libs/survival/data/example/random.h>
+
+int main(){
+
+    example_data(std::cout);
+    example_random(std::cout);
+
+    return 0;
+}
Added: sandbox/statistics/survival_model/boost/survival/model/algorithm/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/algorithm/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival_model::functional::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_MODEL_FUNCTIONAL_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_FUNCTIONAL_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/model/functional/experiment_simulator.hpp>
+#include <boost/survival/model/functional/prepare_weights.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/algorithm/prepare_weights.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/algorithm/prepare_weights.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,86 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival_model::algorithm::prepare_weights.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_MODEL_FUNCTIONAL_PREPARE_WEIGHTS_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_FUNCTIONAL_PREPARE_WEIGHTS_HPP_ER_2009
+#include <ostream>
+#include <boost/importance_sampling/detail/prepare_weights_impl.hpp> 
+#include <boost/model/wrap/aggregate/prior_model_dataset.hpp>
+#include <boost/model/algorithm/log_posteriors.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{  
+
+    // Maps proposal values and their log_pdfs to importance sampling weights.
+    //
+    // Warning: Elements in [b_p,e_p) will be rearranged
+    template<typename T>
+    class prepare_weights : public is::prepare_weights_impl<T> {
+        typedef is::prepare_weights_impl<T> super_;
+        public:
+        typedef T value_type;
+
+        prepare_weights();
+        prepare_weights(const T& max_log);
+
+        template<
+            typename D,typename M,typename Rx,typename Re,
+            typename ItP, typename ItLw
+        >
+        void operator()(
+            boost::model::prior_model_dataset_<D,M,Rx,Re> pmd,
+            ItP b_p,    // Proposal values
+            ItP e_p,        
+            ItLw b_lw,  // Proposal log pdfs
+            ItLw o_w     // Outputs weights - not back_inserter
+        );
+    };
+
+    // Implementation
+
+    template<typename T>
+    prepare_weights<T>::prepare_weights():super_(){}
+
+    template<typename T>
+    prepare_weights<T>::prepare_weights(const T& max_log):super_(max_log){}
+
+    template<typename T>
+    template<
+        typename D,typename M,typename Rx,typename Re,
+        typename ItP, typename ItLw
+    >
+    void
+    prepare_weights<T>::operator()(
+        boost::model::prior_model_dataset_<D,M,Rx,Re> pmd,
+        ItP b_p,    // Proposal values
+        ItP e_p,        
+        ItLw b_lw,  // Proposal log pdfs
+        ItLw o_w    // Outputs weights
+    ){
+        typedef boost::model::prior_model_dataset_<D,M,Rx,Re>   pmd_;
+        ItLw b_w = o_w;
+        ItLw e_w = boost::model::log_posteriors<value_type>(
+            pmd,
+            b_p,
+            e_p,
+            b_lw,
+            o_w
+        );
+        return super_::impl(
+            b_w,
+            e_w,
+            b_p
+        ); // This affects the ordering of [b_w,e_w) and [b_p,e_p)
+    }
+
+        
+}// model
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::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_MODEL_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/model/meta/wrap.hpp>
+#include <boost/survival/model/functional/prepare_weights.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/meta/data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/meta/data.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::meta::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_SURVIVAL_MODEL_META_DATA_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_META_DATA_HPP_ER_2009
+#include <boost/model/wrap/aggregate/data.hpp>
+#include <boost/survival/data/data/event.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{
+namespace meta{        
+
+    // See statistics/model/libs/doc/readme
+    template<typename T,typename X>
+    struct data{
+        typedef boost::survival::data::event<T> y_;
+        typedef boost::model::data_< X, y_ > type;
+    };
+    
+}// meta
+}// model    
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/meta/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/meta/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::meta::include.hpp                                        //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_MODEL_META_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_META_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/model/meta/data.hpp>
+#include <boost/survival/model/meta/response.hpp>
+#include <boost/survival/model/meta/model_data.hpp>
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/meta/model_data.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/meta/model_data.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::meta::model_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_SURVIVAL_MODEL_META_MODEL_DATA_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_META_MODEL_DATA_HPP_ER_2009
+#include <boost/model/wrap/aggregate/model_data.hpp>
+#include <boost/survival/data/data/event.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{
+namespace meta{        
+
+    // See statistics/model/libs/doc/readme
+    template<typename T,typename M,typename X>
+    struct model_data{
+        typedef boost::survival::data::event<T> y_;
+        typedef boost::model::model_data_< M, X, y_ > type;
+    };
+    
+}// meta
+}// model    
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/meta/response.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/meta/response.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,30 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::meta::response.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_MODEL_META_RESPONSE_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_META_RESPONSE_HPP_ER_2009
+#include <boost/model/wrap/unary/response.hpp>
+#include <boost/survival/data/data/event.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{
+namespace meta{        
+
+    // See statistics/model/libs/doc/readme
+    template<typename T>
+    struct response{
+        typedef survival::data::event<T> y_;
+        typedef boost::model::response_<y_> type;
+    };
+    
+}// meta
+}// model    
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/models/exponential/detail/log_likelihood.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/models/exponential/detail/log_likelihood.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,59 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::models::exponential::detail::log_likelihood.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_MODEL_MODELS_EXPONENTIAL_DETAIL_LOG_LIKELIHOOD_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_MODELS_EXPONENTIAL_DETAIL_LOG_LIKELIHOOD_HPP_ER_2009
+#include <cmath>
+#include <stdexcept>
+#include <boost/format.hpp>
+#include <boost/survival/data/data/event.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{
+namespace exponential{
+namespace detail{                
+                
+    template<typename T>
+    T
+    log_likelihood(
+        const T& log_rate,
+        const data::event<T>& e
+    ){
+        static const char* msg = 
+            "survival::model::exponential::log_unnromalized_pdf(%1%,%2%)";
+        typedef T value_type;
+        value_type result = exp(log_rate);
+        result *= (- e.time());
+        try{
+            if( boost::math::isinf(result) ){
+                throw std::runtime_error("isinf(result)");
+            }
+            if( boost::math::isnan(result) ){
+                throw std::runtime_error("isnan(result)");
+            }
+        }catch(std::exception ex){
+            std::string str = msg;
+            str += ex.what();
+            format f(str); f % log_rate % e;
+            throw std::runtime_error(
+                f.str()
+            );
+        }
+        if(e.failure()){
+            result += log_rate;
+        }
+        return result;
+    }
+            
+}// dlog_rateil
+}// exponential
+}// model
+}// survival
+}// boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/models/exponential/include.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/models/exponential/include.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::models::exponential::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_MODEL_MODELS_EXPONENTIAL_INCLUDE_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_MODELS_EXPONENTIAL_INCLUDE_HPP_ER_2009
+
+#include <boost/survival/model/models/exponential/model.hpp>
+#include <boost/survival/model/models/exponential/log_likelihood.hpp>
+#include <boost/survival/model/models/exponential/meta_failure_distribution.hpp>
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/models/exponential/log_likelihood.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/models/exponential/log_likelihood.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::models::exponential::log_likelihood.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_MODEL_MODELS_EXPONENTIAL_LOG_LIKELIHOOD_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_MODELS_EXPONENTIAL_LOG_LIKELIHOOD_HPP_ER_2009
+#include <boost/survival/model/meta/model_data.hpp>
+#include <boost/survival/model/models/exponential/model.hpp>
+#include <boost/survival/model/models/exponential/detail/log_likelihood.hpp>
+
+namespace boost{
+namespace model{
+    
+    // Models Model (sandbox/statistics/model).
+    //
+    // Intentionally not in namespace survival
+    template<typename T,typename X,typename B>
+    T log_likelihood(
+        typename survival::model::meta::model_data<
+            T,
+            survival::model::exponential::model<T>,
+            X
+        >::type md,
+        const B& beta
+    ){
+        typedef survival::model::exponential::model<T> model_;
+    
+        T lr = model_::log_rate(
+            md.covariate(),
+            beta
+        );
+        return survival::model::exponential::detail::log_likelihood( 
+            lr, 
+            md.response() 
+        );
+    }
+
+    // If B == X we need this overload, or else the compiler cannot find
+    // the above definition
+    template<typename T,typename X>
+    T log_likelihood(
+        typename survival::model::meta::model_data<
+            T,
+            survival::model::exponential::model<T>,
+            X
+        >::type md,
+        const X& beta
+    ){
+        return log_likelihood<T,X,X>(
+            md,
+            beta
+        );
+    }
+
+}// model
+}// boost
+
+#endif 
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/models/exponential/meta_failure_distribution.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/models/exponential/meta_failure_distribution.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,46 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::models::meta_failure_distribution.hpp                    //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#ifndef BOOST_SURVIVAL_MODEL_MODELS_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_MODELS_META_FAILURE_DISTRIBUTION_HPP_ER_2009
+#include <cmath>
+#include <boost/model/wrap/aggregate/model_covariate_parameter.hpp>
+#include <boost/standard_distribution/distributions/exponential.hpp>
+#include <boost/survival/data/meta/failure_distribution.hpp>
+#include <boost/survival/model/models/exponential/model.hpp>
+
+namespace boost{
+namespace survival{
+namespace data{
+    
+    template<typename T>
+    struct meta_failure_distribution< survival::model::exponential::model<T> >{
+        typedef survival::model::exponential::model<T> model_;
+        typedef math::exponential_distribution<T> type;
+        
+        template<typename X,typename P>
+        static type make(
+            boost::model::model_covariate_parameter_<model_,X,P> mcp
+        ){
+            T lambda = model_::log_rate(
+                mcp.covariate(),
+                mcp.parameter()
+            );
+            lambda = exp( lambda );
+            return type(
+                lambda
+            );
+        }        
+    };
+
+
+
+}// data
+}// survival
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/boost/survival/model/models/exponential/model.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/boost/survival/model/models/exponential/model.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,80 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::exponential::model.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_MODEL_MODELS_EXPONENTIAL_MODEL_HPP_ER_2009
+#define BOOST_SURVIVAL_MODEL_MODELS_EXPONENTIAL_MODEL_HPP_ER_2009
+#include <numeric>
+#include <boost/mpl/assert.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/type_traits/is_scalar.hpp>
+#include <boost/utility/enable_if.hpp>
+#include <boost/range.hpp>
+
+namespace boost{
+namespace survival{
+namespace model{
+namespace exponential{
+
+    template<typename T>
+    class model{
+        public:
+        typedef T value_type;
+    
+        model();
+                
+        template<typename X,typename B>
+        static typename boost::enable_if<boost::is_scalar<X>,T>::type
+        log_rate(const X& x,const B& b);
+
+        template<typename X,typename B>
+        static typename boost::disable_if<boost::is_scalar<X>,T>::type
+        log_rate(const X& x,const B& b);
+
+        protected:
+        friend class boost::serialization::access;
+        template<class Archive>
+        void serialize(Archive & ar, const unsigned int version){
+            // no member variables
+        }
+
+    };
+
+    // Implementation //
+    
+    template<typename T>
+    model<T>::model(){}
+
+    template<typename T>
+    template<typename X,typename B>
+    typename boost::enable_if<boost::is_scalar<X>,T>::type
+    model<T>::log_rate(const X& x,const B& b){
+        BOOST_MPL_ASSERT((
+            is_scalar<B>
+        ));
+        return ( static_cast<T>( x ) * static_cast<T>( b ) );
+    }
+
+    template<typename T>
+    template<typename X,typename B>
+    typename boost::disable_if<is_scalar<X>,T>::type
+    model<T>::log_rate(const X& x,const B& b){
+        BOOST_ASSERT(size(x) == size(b));
+        return std::inner_product( 
+            boost::begin(x), 
+            boost::end(x),
+            boost::begin(b),
+            static_cast<T>(0)
+        );
+    }
+
+}// exponential
+}// model    
+}// survival
+}// boost
+
+#endif 
Added: sandbox/statistics/survival_model/libs/survival/model/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,116 @@
+//////////////////////////////////////////////////////////////////////////////
+// survival_model::doc::readme                                              //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+    In this C++ library, we provide models of Model (statistics/model) in the 
+    survival modeling framework.
+
+[ Notation ] 
+
+    See statistics/model/libs/model/doc/readme and the concept Model. Let mcp 
+    denote an instance of model_covariate_parameter_<M, X, P>
+
+[ Bug ]
+
+    See libs/survival/example/posterior_analysis.cpp     
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/boost_1_39_0/ 
+/sandbox/statistics/arithmetic/ 
+/sandbox/statistics/non_par/ 
+/sandbox/statistics/importance_sampling/ 
+/sandbox/statistics/importance_weights/ 
+/sandbox/statistics/joint_dist/ 
+/sandbox/statistics/non_param/ 
+/sandbox/statistics/mpl/ 
+/sandbox/statistics/random/ 
+/sandbox/statistics/binary_op/ 
+/sandbox/statistics/functional/ 
+/sandbox/statistics/arithmetic/ 
+/sandbox/statistics/iterator/ 
+/sandbox/statistics/dist_random/ 
+/sandbox/statistics/scalar_dist/ 
+/sandbox/statistics/standard_distribution/ 
+/sandbox/statistics/survival_data/ 
+/sandbox/statistics/model/
+
+Link to : libboost_serialization-xgcc42-mt-1_39.a
+
+[ History ]
+
+July 2009 : Current version
+
+[ models ]
+
+These are models of [ SurvivalModel ] defined as:
+
+Let U/u denote a type/object modeling UniformaRandomNumberGenerator (see 
+Boost.Random)
+
+M refines SurvivalModel if it models Model with the requirement that
+    Expression                          Returns
+    random::failure_time<T>(mcp,urng)   Object of type T
+
+Modeled by : 
+    model::exponential::model
+
+[ meta ]
+
+    - meta::failure_distribution maps M to a distribution in math/distributions
+    - meta::failure_random maps M to a RandomDistribution in boost/random
+    
+    If these mappings are specified for M, random::failure_time is automatically
+    defined for M. 
+    
+[ Sources ] 
+
+[1] Bayesian survival analysis By Joseph George Ibrahim, Ming-Hui Chen, 
+Debajyoti Sinha
+
+[ Output ]
+-> example_model_exponential : size(x_cycle) = 100
+(-2.48172,-1.87264)
+log(prior,likelihood,posterior)
+(-2,-11.3373,-13.3373)
+(-0.5,-7.28159,-7.78159)
+(-0,-5.08452,-5.08452)
+(-0.5,-4.18529,-4.68529)
+(-2,-4.35436,-6.35436)
+
+log(prior,prior2)
+(-2,-2)
+(-0.5,-0.5)
+(-0,0)
+(-0.5,-0.5)
+(-2,-2)
+<-
+
+-> example_posterior_analysis : 
+i = 0, t = 0.169766, pws = (222.593,1,0.047237,0.5896)
+i = 1000, t = 0.167177, pws = (195.97,1,0.0261956,0.7733)
+i = 2000, t = 0.166789, pws = (190.525,1,0.0163538,0.836)
+i = 3000, t = 0.167136, pws = (197.041,1,0.0519114,0.5842)
+i = 4000, t = 0.168067, pws = (195.495,1,0.05305,0.5729)
+i = 5000, t = 0.171331, pws = (199.301,1,0.0381148,0.6841)
+i = 6000, t = 0.167311, pws = (205.46,1,0.0556848,0.5621)
+i = 7000, t = 0.167732, pws = (182.455,1,0.0639737,0.5192)
+i = 8000, t = 0.166502, pws = (181.937,1,0.0661214,0.5163)
+i = 9000, t = 0.16732, pws = (188.906,1,0.0135898,0.8683)<-
+
+
Added: sandbox/statistics/survival_model/libs/survival/model/example/exponential.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/example/exponential.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,257 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::example::model::exponential.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 <string> //needed?
+#include <vector>
+#include <limits>
+#include <ostream>
+#include <fstream>
+#include <algorithm>
+#include <iterator>
+// #include <boost/archive/binary_oarchive.hpp>
+// #include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <boost/arithmetic/equal.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp> 
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_cycle.hpp>
+
+#include <boost/standard_distribution/distributions/normal.hpp>
+
+#include <boost/survival/data/include.hpp>
+#include <boost/survival/model/models/exponential/include.hpp>
+#include <libs/survival/model/example/exponential.h>
+
+// Must come after the model to be used
+#include <boost/model/include.hpp>
+
+#include <libs/survival/model/example/exponential.h>
+
+void example_exponential(std::ostream& out){
+
+    out << "-> example_model_exponential : ";
+    
+    // Steps shown in this example:
+    //
+    // Loads the first batch of a set of records
+    // Creates events at given time
+    // Evaluates the likelihoods and posteriors
+    
+    using namespace boost;
+    namespace surv = survival;
+
+    // [ Types ]
+    // Value
+    typedef double                                  val_;
+    typedef std::vector<val_>                       vals_;
+    typedef surv::constant<val_>                    const_;
+
+    // I/O
+    typedef boost::archive::text_oarchive oa_;
+    typedef boost::archive::text_iarchive ia_;
+    
+   // Records
+    typedef surv::data::record<val_>                record_;
+    typedef std::vector<record_>                    records_;
+    typedef range_iterator<records_>::type          it_record_;
+    
+    // Events
+    typedef surv::data::event<val_>                 event_;
+    typedef std::vector<event_>                     events_;
+    typedef range_iterator<events_>::type           it_event_;
+
+    // Covariates
+    typedef val_                                    x_;
+    typedef vals_                                   r_x_;
+    typedef range_cycle<>                           range_cycle_;
+    typedef range_cycle_::apply<r_x_>::type         x_cycle_;
+
+    // Model
+    typedef surv::model::exponential::model<val_>   model_;
+    typedef val_                                    par_;
+    typedef vals_                                   pars_;
+
+    // [ Constants ]
+    const val_ entry_bound = const_::inf_;
+    const val_ par = 2.0;
+    const char* batches_path 
+        = "/Users/erwann/projets/2009/Xcode/survival/build/Release/batches";
+
+    // [ Variables ]
+    long n_record;
+
+    // [ Upload first batch of records ]
+    records_ records;
+    {
+        std::ifstream ifs(batches_path);
+        if(ifs.good()){
+            ia_ ia(ifs);
+            ia >> records;
+        }else{
+            std::string str = "error opening : ";
+            str.append( batches_path );
+            throw std::runtime_error(str);
+        }
+        ifs.close();
+    }
+    n_record = boost::size( records );
+    
+    // [ Events ]
+    events_ events; 
+    events.reserve( size(records) );
+    surv::data::events(
+        begin(records),
+        end(records),
+        entry_bound,
+        std::back_inserter(events)
+    );
+    
+    // [ Covariates ] 
+    r_x_ r_x;
+    {
+        using namespace boost::assign;
+        r_x += -0.5, 0.5;
+    }
+    x_cycle_ x_cycle = range_cycle_::make(r_x,0,n_record);
+    out << "size(x_cycle) = " << size(x_cycle) << std::endl;
+    BOOST_ASSERT( size(x_cycle)>=size(events) );
+    // Resize x_cycle to a size that matches that of events
+    x_cycle.advance_end( - (size(x_cycle) - size(events)) );
+    BOOST_ASSERT( size(x_cycle) == size(events) );
+
+    // Model
+    model_ model;
+
+    // Pars
+    pars_ pars;
+    {
+        using namespace assign;
+        pars += -2.0, -1.0, 0.0, 1.0, 2.0; 
+    }
+
+    // [ Likelihood ]
+
+    typedef math::normal_distribution<val_> mprior_;
+    mprior_ mprior;
+
+    out << '(';
+    out << model::log_likelihood<val_>(
+        model::make_model_data(
+            model,
+            r_x[0],
+            events[0]
+        ),
+        par
+    );
+    out << ',';
+    out << model::log_likelihood<val_>(
+        model::make_model_data(
+            model,
+            r_x[1],
+            events[1]
+        ),
+        par
+    ) << ')';
+
+
+    // [ Likelihoods ]
+    vals_ lls;
+    model::log_likelihoods<val_>(
+        model::make_model_dataset(model,r_x,events),
+        boost::begin(pars),
+        boost::end(pars),
+        std::back_inserter(lls)
+    );
+
+    // [ Prior ]
+    vals_ lprs;
+    math::transform<math::fun_wrap::log_unnormalized_pdf_>(
+        mprior,
+        boost::begin(pars),
+        boost::end(pars),
+        std::back_inserter(lprs)
+    );
+
+    // [ Posteriors ]
+
+    vals_ lpos;
+    model::log_posteriors<val_>(
+        model::make_prior_model_dataset(mprior,model,r_x,events),
+        boost::begin(pars),
+        boost::end(pars),
+        std::back_inserter(lpos)
+    );
+
+    // Consistency check
+    typedef range_iterator<vals_>::type it_val_;
+    {
+
+        it_val_ i_lpr = boost::begin(lprs);
+        it_val_ i_lpo = boost::begin(lpos);
+        out << std::endl;
+        out << "log(prior,likelihood,posterior)" << std::endl;
+        for(
+            it_val_ i_ll = boost::begin(lls); 
+            i_ll< boost::end(lls); 
+            i_ll++,i_lpr++,i_lpo++
+        ){
+            out << '(';
+            val_ lpr = *i_lpr;  out << lpr << ',';
+            val_ ll = *i_ll;    out << ll << ',';
+            val_ lpo = *i_lpo;  out << lpo << ')' << std::endl;
+            val_ lpo2 = lpr + ll;
+            BOOST_ASSERT(
+                arithmetic_tools::equal(
+                    lpo,
+                    lpo2
+                )
+            );
+        }
+    }
+    
+    // Consistency check2
+
+    {
+        vals_ lpr2s ( size(pars) );
+        model::log_posteriors<val_>(
+            model::make_prior_model_dataset(mprior,model,r_x,events),
+            boost::begin(pars),
+            boost::end(pars),
+            boost::begin(lls), //subtracted
+            boost::begin(lpr2s)
+        );
+
+        it_val_ i_lpr = boost::begin(lprs);
+        out << std::endl;
+        out << "log(prior,prior2)" << std::endl;
+        for(
+            it_val_ i_lpr2 = boost::begin(lpr2s); 
+            i_lpr2< boost::end(lpr2s); 
+            i_lpr2++,i_lpr++
+        ){
+            out << '(';
+            val_ lpr  = *i_lpr;     out << lpr << ',';
+            val_ lpr2 = *i_lpr2;    out << lpr2 << ')' << std::endl;
+            BOOST_ASSERT(
+                arithmetic_tools::equal(
+                    lpr,
+                    lpr2
+                )
+            );
+        }
+    }
+
+    out << "<-" << std::endl;
+}
Added: sandbox/statistics/survival_model/libs/survival/model/example/exponential.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/example/exponential.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::example::model::exponential.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_EXAMPLE_MODEL_EXPONENTIAL_HPP_ER_2009
+#define LIBS_SURVIVAL_EXAMPLE_MODEL_EXPONENTIAL_HPP_ER_2009
+#include <ostream>
+
+void example_exponential(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,389 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::example::model::posterior_analysis.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 <ostream>
+#include <ostream>
+#include <fstream>
+#include <stdexcept>
+#include <string> //needed?
+#include <vector>
+#include <limits>
+#include <algorithm>
+#include <iterator>
+// #include <boost/archive/binary_oarchive.hpp>
+// #include <boost/archive/binary_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/serialization/vector.hpp>
+
+#include <boost/timer.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/iterator/range_cycle.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp> 
+
+#include <boost/standard_distribution/distributions/normal.hpp>
+#include <boost/math/distributions/uniform.hpp>
+#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+#include <boost/survival/data/include.hpp>
+#include <boost/survival/model/models/exponential/include.hpp>
+
+// Must come after the model to be used
+#include <boost/model/include.hpp>
+
+#include <boost/importance_weights/algorithm/prepare_weights.hpp>
+#include <boost/importance_sampling/include.hpp>
+
+#include <libs/survival/model/example/posterior_analysis.h>
+
+void example_posterior_analysis(std::ostream& out){
+
+    out << "-> example_posterior_analysis : ";
+    out.flush();
+    
+    // Steps shown in this example:
+    //
+    // Samples proposal draws
+    // Successively loads batches of records, and for each
+    // Creates events at a given time
+    // Importance samples from the posterior as the target density
+    // Saves the Cook-Gelman (cg) statistics for each.
+    // Checks the cg data against U[0,1] using Kolmogorov Smirnov
+    
+    using namespace boost;
+    namespace surv = survival;
+    namespace iw = importance_weights;
+
+    // Types
+    typedef std::string                             str_;
+    typedef double                                  val_;
+    typedef std::vector<val_>                       vals_;
+    typedef surv::constant<val_>                    const_;
+
+    // [ Input ]
+    typedef boost::archive::text_iarchive           ia_;
+    typedef std::ifstream                           ifs_;
+
+    const str_ input_path 
+        = "/Users/erwann/projets/2009/Xcode/survival/build/Release/";
+    const str_ prior_path   = input_path + "/prior";
+    const str_ x_vals_path  = input_path + "/x_vals";
+    const str_ pars_path    = input_path + "/pars";
+    const str_ batches_path = input_path + "/batches";
+
+    // Covariates
+    typedef val_                                    x_;
+    typedef vals_                                   x_vals_;
+    typedef range_cycle<>                           range_cycle_;
+    typedef range_cycle_::apply<x_vals_>::type      x_cycle_;
+    x_vals_ x_vals;
+    {
+        ifs_ ifs(x_vals_path.c_str());
+        ia_ ia(ifs);
+        ia >> x_vals;
+    }
+    x_cycle_ x_cycle;
+
+    // Prior
+    typedef math::normal_distribution<val_>         mprior_;
+    mprior_ mprior;
+    {
+        typedef math::meta_distribution_primitives<mprior_>::type  prim_;
+        ifs_ ifs(prior_path.c_str());
+        ia_ ia(ifs);
+        prim_ prim;
+        ia >> prim;
+        mprior = prim;
+    }
+
+    // Records
+    // TODO n_bath should be deduced from input (getline)
+    const long n_batch                              = 1e4; 
+
+    typedef surv::data::record<val_>                record_;
+    typedef std::vector<record_>                    records_;
+    typedef range_size<records_>::type              size_type;
+    typedef range_iterator<records_>::type          it_record_;
+
+    records_ records;
+    ifs_ ifs_batches(batches_path.c_str());
+    if(!ifs_batches.good()){
+        str_ str = "error opening : ";
+        str.append( batches_path );
+        throw std::runtime_error(str);
+    }
+    ia_ ia_batches(ifs_batches);
+
+    // True pars
+    typedef val_                                    par_;
+    typedef vals_                                   pars_;
+    const long n_true_pars_kss = -1;//n_batch; 
+    pars_ true_pars;
+    true_pars.reserve(n_batch);
+    {
+        ifs_ ifs_pars(pars_path.c_str());
+        if(!ifs_pars.good()){
+            str_ str = "error opening : ";
+            str.append( pars_path );
+            throw std::runtime_error(str);
+        }
+        ia_ ia_pars(ifs_pars);
+
+        for(long i = 0; i< n_batch; i++){
+            val_ par;
+            ia_pars >> par;
+            true_pars.push_back(par);
+        }
+    }
+    if(n_true_pars_kss>0){   // Check that F_n(true_pars) agrees with mprior
+        BOOST_ASSERT( n_batch % n_true_pars_kss == 0);
+        vals_ true_pars_kss;
+        true_pars_kss.reserve(n_true_pars_kss);
+        non_param::sequential_kolmogorov_smirnov_distance(
+            mprior,
+            boost::begin(true_pars),
+            boost::end(true_pars),
+            n_true_pars_kss,
+            std::back_inserter(true_pars_kss)
+        );
+        out << "true pars kss : ";
+        std::copy(
+            boost::begin( true_pars_kss ),
+            boost::end( true_pars_kss ),
+            std::ostream_iterator<val_>(out," ")
+        );
+        out << std::endl;
+    }
+
+    // [ Output ]
+    typedef boost::archive::text_oarchive           oa_;
+    typedef std::ofstream                           ofs_;
+
+    const char* t_pars_path = "./t_pars";
+    const char* cg_path     = "./cg";
+    const char* ks_path     = "./kss";
+
+    // Cg
+    ofs_ ofs_cg( cg_path ); 
+    vals_ cgs; cgs.reserve(n_batch);
+
+    // Targets
+    const long n_t_pars = 1e3;
+    pars_ t_pars; 
+    t_pars.reserve( n_t_pars );
+    ofs_ ofs_t_pars(t_pars_path);
+    oa_ oa_t_pars(ofs_t_pars);
+    
+    // [ Local ]
+
+    // Monitoring
+    const long n_batch_mod                          = 1e3;
+
+    // Events
+    const val_ entry_bound                          = const_::inf_;
+    typedef surv::data::event<val_>                 event_;
+    typedef std::vector<event_>                     events_;
+    typedef range_iterator<events_>::type           it_event_;
+
+    // Urng
+    typedef boost::mt19937                          urng_;
+    urng_                                           urng;
+
+    // Unif
+    typedef math::uniform_distribution<val_>        munif_;
+    
+    // Proposal
+    typedef mprior_                                 mproposal_;
+    pars_ p_pars; 
+    const long n_proposal = 1e3; //1e4 recommended but takes longer
+    p_pars.reserve(n_proposal);
+
+    // This one size fits all proposal is likely to result in a small effective
+    // sample size. Check out<<pws below to determine n_proposal.
+    mproposal_  mproposal = mprior; 
+    vals_ p_lpdfs; 
+    p_lpdfs.reserve(n_proposal); 
+
+    // Weights
+    const val_ max_log = 100.0;
+    typedef iw::prepare_weights<val_> pws_;
+    pws_ pws( max_log );
+    vals_ iws; 
+    iws.reserve( n_proposal );
+        
+    // Model
+    typedef surv::model::exponential::model<val_> model_;
+    model_ model;
+    typedef model::prior_model_dataset_<mprior_,model_,x_cycle_,events_> pmd_; 
+
+    {   // [ Proposal sample ]
+        const long n_p_pars_kss = -1;//n_batch; 
+        boost::timer t;
+        p_pars.clear();
+        generate_n(
+            std::back_inserter(p_pars),
+            n_proposal,
+            mproposal,
+            urng
+        );
+
+        if(n_p_pars_kss>0){   // Check that F_n(p_pars) agrees with mproposal
+            BOOST_ASSERT( n_batch % n_p_pars_kss == 0);
+            vals_ p_pars_kss;
+            p_pars_kss.reserve(n_p_pars_kss);
+            non_param::sequential_kolmogorov_smirnov_distance(
+                mproposal,
+                boost::begin(p_pars),
+                boost::end(p_pars),
+                n_p_pars_kss,
+                std::back_inserter(p_pars_kss)
+            );
+            out << "p_pars kss : ";
+            std::copy(
+                boost::begin( p_pars_kss ),
+                boost::end( p_pars_kss ),
+                std::ostream_iterator<val_>(out," ")
+            );
+            out << std::endl;
+        }
+
+        p_lpdfs.clear();
+        math::transform<math::fun_wrap::log_unnormalized_pdf_>(
+            mproposal,
+            boost::begin( p_pars ),
+            boost::end( p_pars ),
+            std::back_inserter( p_lpdfs )
+        );
+        BOOST_ASSERT( size(p_pars) == size(p_lpdfs) );
+    }
+
+    // Loops over batches
+    for(unsigned i = 0; i<n_batch; i++){
+        records.clear();
+        ia_batches >> records;
+        events_ events; 
+        events.reserve( size(records) );
+        surv::data::events(
+            begin(records),
+            end(records),
+            entry_bound,
+            std::back_inserter(events)
+        );
+        size_type n_event = size( events );
+        
+        x_cycle = range_cycle_::make( x_vals, 0, n_event );
+        BOOST_ASSERT( size( x_cycle ) >= n_event );
+        x_cycle.advance_end( - ( size( x_cycle ) - n_event ) );
+        BOOST_ASSERT( size( x_cycle ) == n_event );
+
+        {   // [ Posterior sample ]
+            boost::timer t;
+            pmd_ pmd( mprior, model, x_cycle, events);
+            iws.resize( size( p_pars ) );
+
+            // [Warning: Bug]
+            // The Cook-Gelman statistics come out higher at the ends of the
+            // [0,1] range than in the middle
+            //
+            // model::log_posteriors<val_>(
+            //    pmd,
+            //    boost::begin( p_pars ),
+            //    boost::end( p_pars ),
+            //    boost::begin( p_lpdfs ),   
+            //    boost::begin( iws )  
+            // ); 
+            // out << std::endl << "iws:";
+            // copy(
+            //    boost::begin( iws ),
+            //    boost::next( boost::begin( iws ), 10),
+            //    std::ostream_iterator<val_>(std::cout, " ")
+            // );           
+            // For testing purposes only:
+            // We expect iws2 == iws. But small differences (precision error?)
+            // vals_ iws2 = iws;
+            // model::log_likelihoods<val_>(
+            //    pmd,
+            //    boost::begin( p_pars ),
+            //    boost::end( p_pars ),
+            //    boost::begin( iws2 )  
+            // );            
+            // out << std::endl << "iws2:";
+            // copy(
+            //    boost::begin( iws2 ),
+            //    boost::next( boost::begin( iws2 ), 10),
+            //    std::ostream_iterator<val_>(std::cout, " ")
+            // );           
+
+            // Temporary fix, until bug above is resolved.
+            BOOST_ASSERT(
+                make_distribution_primitives(mprior) ==
+                make_distribution_primitives(mproposal) 
+            );
+            model::log_likelihoods<val_>(
+                pmd,
+                boost::begin( p_pars ),
+                boost::end( p_pars ),
+                boost::begin( iws )  
+            );            
+
+            pws(
+                boost::begin( iws ),
+                boost::end( iws ),
+                boost::begin( p_pars )
+            );
+            t_pars.clear();
+            t_pars.resize( n_t_pars );
+            is::generate(
+                urng,
+                boost::begin( iws ),
+                boost::end( iws ),
+                boost::begin( p_pars ),
+                boost::begin( t_pars ),
+                n_t_pars
+            );
+            oa_t_pars << t_pars;
+            val_ plt =  algorithm::proportion_less_than(
+                boost::begin( t_pars ),
+                boost::end( t_pars ),
+               true_pars[i]
+            );
+            cgs.push_back( plt );
+            ofs_cg << plt << ' ';
+            ofs_cg.flush();
+            const char* str = "i = %1%, t = %2%, pws = %3%";
+            if(i%n_batch_mod == 0){
+                format f(str);
+                f % i  % t.elapsed() % pws; 
+                out << std::endl << f.str();  
+            }
+        }// Proposal sample
+    }// loop over batches
+
+    {   // Kolmorov Smirnov of the cgs
+        long n_ks = n_batch;
+        BOOST_ASSERT( n_batch % n_ks == 0 );
+        vals_ kss;
+        kss.reserve( n_batch );
+        non_param::sequential_kolmogorov_smirnov_distance(
+            munif_(),
+            boost::begin( cgs ),
+            boost::end( cgs ),
+            n_ks,
+            std::back_inserter(kss)
+        );
+        ofs_ ofs_ks(ks_path);
+        std::copy(
+            boost::begin( kss ),
+            boost::end( kss ),
+            std::ostream_iterator<val_>(ofs_ks," ")
+        );
+    }
+
+    out << "<-" << std::endl;
+}
+
Added: sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/example/posterior_analysis.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// survival::model::example::model::posterior_analysis.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_EXAMPLE_MODEL_POSTERIOR_ANALYSIS_HPP_ER_2009
+#define LIBS_SURVIVAL_EXAMPLE_MODEL_POSTERIOR_ANALYSIS_HPP_ER_2009
+#include <ostream>
+
+void example_posterior_analysis(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/survival_model/libs/survival/model/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/survival_model/libs/survival/model/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,11 @@
+#include <iostream>
+#include <libs/survival/model/example/exponential.h>
+#include <libs/survival/model/example/posterior_analysis.h>
+
+int main(){
+
+    example_exponential(std::cout);
+    //example_posterior_analysis(std::cout);
+    
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/tree/boost/tree/node.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/boost/tree/node.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,204 @@
+///////////////////////////////////////////////////////////////////////////////
+// tree::node.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_TREE_NODE_HPP_ER_2009
+#define BOOST_TREE_NODE_HPP_ER_2009
+#include <stdexcept>
+#include <ostream>
+#include <boost/operators.hpp>
+#include <boost/tree/stage.hpp>
+
+namespace boost{
+namespace tree{
+
+//                                             ( 1 )                                          n^0
+//                                         ( 1 , 2 ,3)                                        n^1
+//                    ( 1 , 2 , 3 )        ( 1 ,[2], 3 )            ( 1, 2 , 3 )              n^2
+//            (1,2,3) (1,2,3)(1,2,3)  (1,2,3) (1,2,3) (1,2,3)  (1,2,3) (1,2,3) (1,2,3)        n^3
+
+    template<unsigned n>
+    struct node : 
+        incrementable<
+            node<n>,
+            decrementable<
+                node<n>,
+                less_than_comparable<
+                    node<n>, 
+                    equality_comparable<
+                        node<n> 
+                    >
+                >
+            >
+        >
+    {
+        typedef std::size_t size_type;
+        typedef node<n> this_;
+        typedef dynamic_stage<n> dyna_stage_;
+        unsigned stage;
+        unsigned position_in_stage;
+        
+        node();
+        node(unsigned j,unsigned k);
+        this_& operator++();
+        this_& operator--();
+        bool operator==(const this_&);
+        bool operator<(const this_&);
+
+    };
+
+}//tree
+
+    template<unsigned n> std::ostream& 
+    operator<<(std::ostream& out, const tree::node<n>& that);
+
+    template<unsigned n> typename tree::node<n>::size_type 
+    position(const tree::node<n>& that);
+    template<unsigned n> tree::node<n> root(const tree::node<n>& leaf);
+    template<unsigned n> tree::node<n> leaf(const tree::node<n>& root);
+
+    // To visit all the nodes sharing the same root:
+    // node<n> node = leaf(root);
+    // while(root(node++)!=the_root){...}
+
+    template<unsigned n> 
+    tree::node<n> 
+    first(const tree::node<n>& root,unsigned stage);
+
+    template<unsigned n> 
+    tree::node<n> 
+    back(const tree::node<n>& root,unsigned stage);
+
+    // ++back == last. The reason I don't define last is because the 
+    // for now only a fixed number of stages are available
+
+namespace tree{
+
+    // Implementation
+    template<unsigned n>    
+    node<n>::node():stage(0),position_in_stage(0){}
+
+    template<unsigned n>    
+    node<n>::node(unsigned j,unsigned k)
+    :stage(j),position_in_stage(k){
+        const char* msg = "node(%1%,!(%2%<%3%)),  ";
+        unsigned l = dyna_stage_::position_last(this->stage);
+        if(! (k <  l) ){
+            format f(msg);
+            f % j % k % l;
+            throw std::out_of_range(
+                f.str()
+            );
+        }
+    }
+
+    template<unsigned n>
+    node<n>& 
+    node<n>::operator++(){
+        unsigned m = dyna_stage_::position_last(this->stage);
+        if( 1 + position(*this) < m){
+            ++(this->position_in_stage);
+        }else{
+            ++stage;
+            (this->position_in_stage) = 0;
+        }
+        return (*this);
+    }
+
+    template<unsigned n>
+    node<n>& 
+    node<n>::operator--(){
+        const char* msg = "--node<n> at root";
+        if(this->stage == 0){
+            throw std::out_of_range(
+                msg
+            );
+        }
+        unsigned m = dyna_stage_::position_last(this->stage-1);
+        if( position(*this)-1 >= m){
+            --(this->position_in_stage);
+        }else{
+            --stage;
+            (this->position_in_stage) = m-1;
+        }
+        return (*this);
+    }
+
+    template<unsigned n>
+    bool node<n>::operator==(const this_& that){
+        return (this->position()) == (that.position());
+    }
+
+    template<unsigned n>
+    bool node<n>::operator<(const this_& that){
+        return (this->position()) < (that.position());
+    }
+
+}
+
+    template<unsigned n> 
+    std::ostream& operator<<(std::ostream& out, const tree::node<n>& that){
+        out 
+            << '(' << that.stage 
+            << ',' << that.position_in_stage
+            << ',' << position(that)
+            << ')'; 
+        return out;
+    }
+
+    template<unsigned n>
+    tree::node<n> leaf(const tree::node<n>& that){
+        typedef tree::node<n> node_;
+        node_ node = that;
+        ++node.stage;
+        (node.position_in_stage) *= n;
+        return node;
+    }
+
+    template<unsigned n>
+    tree::node<n> 
+    root(const tree::node<n>& that){
+        typedef tree::node<n> node_;
+        const char* msg = "node<n>::jump_to_root() already at root";
+        if(that.stage == 0 ){
+            throw std::out_of_range(
+                msg
+            );
+        }
+        node_ node = that;
+        --node.stage;
+        node.position_in_stage /= n;
+        return node;
+    }
+
+    template<unsigned n>
+    typename tree::node<n>::size_type
+    position(const tree::node<n>& that){
+        typedef tree::node<n> node_;
+        typedef typename node_::dyna_stage_ dyna_stage_;
+        return dyna_stage_::position_first(that.stage)
+            +(that.position_in_stage);
+    }
+
+    template<unsigned n> tree::node<n> 
+    first(const tree::node<n>& root,unsigned stage){
+        typedef tree::node<n> node_;
+        typedef typename node_::dyna_stage_ dyna_stage_;
+        unsigned idx = dyna_stage_::position_first(stage);
+        return node_(stage,idx);
+    }
+
+    template<unsigned n> tree::node<n> 
+    back(const tree::node<n>& root,unsigned stage){
+        typedef tree::node<n> node_;
+        typedef typename node_::dyna_stage_ dyna_stage_;
+        unsigned idx = dyna_stage_::position_last(stage)-1;
+        return node_(stage,idx);
+    }
+
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/tree/boost/tree/stage.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/boost/tree/stage.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,132 @@
+///////////////////////////////////////////////////////////////////////////////
+// tree::stage.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_TREE_STAGE_HPP_ER_2009
+#define BOOST_TREE_STAGE_HPP_ER_2009
+#include <stdexcept>
+#include <boost/format.hpp>
+
+namespace boost{
+namespace tree{
+
+    // This class maps a position in a tree structure to a position in a vector
+    //
+    // The tree structure has a root node (stage 0) with n adjacent 
+    // nodes (stage 1), each of which have n adjacent nodes (stage 2) etc.
+    // The nodes are stored in a vector, starting with the root node,
+    // followed by those in stage1, then those in stage 2 etc.
+    
+    // i : stage
+    // n : number of branches per node
+    template<unsigned j,unsigned n>
+    struct stage{
+        static unsigned position_first;
+        static unsigned position_last;
+        static unsigned number_nodes;
+    };
+
+    template<unsigned n>
+    struct stage<0,n>{
+        static unsigned position_first;
+        static unsigned position_last;
+        static unsigned number_nodes;
+    };
+
+
+    // Client may ignore this:
+    template<typename T> struct position_first_{ static unsigned get(); };
+    template<typename T> struct position_last_{ static unsigned get(); };
+    template<typename T> struct number_nodes_{ static unsigned get(); };
+
+
+    template<unsigned n>
+    class dynamic_stage{
+        // TODO boost::switch to allow for abitrary # stages?
+        typedef stage<0,n> s0_;
+        typedef stage<1,n> s1_;
+        typedef stage<2,n> s2_;
+        typedef stage<3,n> s3_;
+
+        public:
+        static unsigned position_first(unsigned i);
+        static unsigned position_last(unsigned i);
+        static unsigned number_nodes(unsigned i);
+        
+        private:
+        template<template<typename> class F>
+        static unsigned switch_(unsigned i);
+    };
+
+    // Implementation //
+
+    // Initialization
+    template<unsigned n>
+    unsigned stage<0,n>::position_first = 0;
+
+    template<unsigned n>
+    unsigned stage<0,n>::position_last = 1;
+
+    template<unsigned n>
+    unsigned stage<0,n>::number_nodes = 1;
+
+    // Recursion
+    template<unsigned j,unsigned n>
+    unsigned stage<j,n>::position_first 
+        = stage<j-1,n>::template position_last;
+
+    template<unsigned j,unsigned n>
+    unsigned stage<j,n>::position_last 
+        = stage<j,n>::position_first 
+            + stage<j,n>::number_nodes;
+
+    template<unsigned j,unsigned n>
+    unsigned stage<j,n>::number_nodes 
+        = stage<j-1,n>::number_nodes * n;
+
+    template<typename T>
+    unsigned position_first_<T>::get(){ return T::position_first; }
+    template<typename T>
+    unsigned position_last_<T>::get(){ return T::position_last; }
+    template<typename T>
+    unsigned number_nodes_<T>::get(){ return T::number_nodes; }
+
+    template<unsigned n>
+    template<template<typename> class F>
+    unsigned dynamic_stage<n>::switch_(unsigned j){
+        static const char* msg = "dynamic_stage<n>::switch(%1%)";
+
+        switch(j){
+            case 0 : return F<s0_>::get();
+            case 1 : return F<s1_>::get();
+            case 2 : return F<s2_>::get();
+            case 3 : return F<s3_>::get();
+            default : format f(msg); f % j; 
+            throw std::out_of_range(
+                f.str()
+            );
+        }
+    }
+
+
+    template<unsigned n>
+    unsigned dynamic_stage<n>::position_first(unsigned j){
+        return switch_<position_first_>(j);
+    }
+    template<unsigned n>
+    unsigned dynamic_stage<n>::position_last(unsigned j){
+        return switch_<position_last_>(j);
+    }
+
+    template<unsigned n>
+    unsigned dynamic_stage<n>::number_nodes(unsigned j){
+        return switch_<number_nodes_>(j);
+    }
+
+}// tree_navigation
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/tree/libs/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/libs/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,52 @@
+///////////////////////////////////////////////////////////////////////////////
+// tree::doc::readme.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)         //
+///////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+    Maps a vector to a tree view, where all the nodes share the same number of
+    branches. 
+
+[ Useful links ]
+
+    A comprehensive tree framework that is unrelated to this package:
+        http://raz.or.at/soc2006/doc/html/
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+
+[ History ]
+
+July 2009 : Current version
+
+[ Output ]
+
+main.cpp
+
+-> example_tree (0,1)(1,4)(4,13)
+(0,0,0)
+(1,0,1)(1,1,2)(1,2,3)
+(2,0,4)(2,1,5)(2,2,6)(2,3,7)(2,4,8)(2,5,9)(2,6,10)(2,7,11)(2,8,12)
+(3,0,13)(3,1,14)(3,2,15)(3,3,16)(3,4,17)(3,5,18)(3,6,19)(3,7,20)(3,8,21)(3,9,22)(3,10,23)(3,11,24)(3,12,25)(3,13,26)(3,14,27)(3,15,28)(3,16,29)(3,17,30)(3,18,31)(3,19,32)(3,20,33)(3,21,34)(3,22,35)(3,23,36)(3,24,37)(3,25,38)
+
+(0,0,0)(0,0,0)(0,0,0)
+(1,0,1)(1,0,1)(1,0,1)(1,1,2)(1,1,2)(1,1,2)(1,2,3)(1,2,3)(1,2,3)
+(2,0,4)(2,0,4)(2,0,4)(2,1,5)(2,1,5)(2,1,5)(2,2,6)(2,2,6)(2,2,6)(2,3,7)(2,3,7)(2,3,7)(2,4,8)(2,4,8)(2,4,8)(2,5,9)(2,5,9)(2,5,9)(2,6,10)(2,6,10)(2,6,10)(2,7,11)(2,7,11)(2,7,11)(2,8,12)(2,8,12)
+
+(3,39,52)(3,38,51)(3,37,50)(3,36,49)(3,35,48)(3,34,47)(3,33,46)(3,32,45)(3,31,44)(3,30,43)(3,29,42)(3,28,41)(3,27,40)(3,26,39)(3,25,38)(3,24,37)(3,23,36)(3,22,35)(3,21,34)(3,20,33)(3,19,32)(3,18,31)(3,17,30)(3,16,29)(3,15,28)(3,14,27)(3,13,26)(3,12,25)(3,11,24)(3,10,23)(3,9,22)(3,8,21)(3,7,20)(3,6,19)(3,5,18)(3,4,17)(3,3,16)(3,2,15)(3,1,14)(3,0,13)
+(2,12,16)(2,11,15)(2,10,14)(2,9,13)(2,8,12)(2,7,11)(2,6,10)(2,5,9)(2,4,8)(2,3,7)(2,2,6)(2,1,5)(2,0,4)
+(1,3,4)(1,2,3)(1,1,2)(1,0,1) <- 
+
Added: sandbox/statistics/tree/libs/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/libs/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// example::tree.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)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/tree/example/tree.h>
+
+int main(){
+    example_tree(std::cout);
+    
+    return 0;
+}
\ No newline at end of file
Added: sandbox/statistics/tree/libs/tree/example/tree.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/libs/tree/example/tree.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,82 @@
+///////////////////////////////////////////////////////////////////////////////
+// tree::example::tree.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 <boost/tree/stage.hpp>
+#include <boost/tree/node.hpp>
+#include <libs/tree/example/tree.h>
+
+void example_tree(std::ostream& out){
+    out << "-> example_tree ";
+
+    using namespace boost;
+    
+    const unsigned n = 3;
+    typedef tree::dynamic_stage<n> stage_;
+    typedef tree::node<n> node_;
+
+    using namespace boost;
+    const unsigned n_j = 3;
+    const node_ root_node;
+
+    for(unsigned j = 0; j<n_j; j++){
+        out 
+            << '(' 
+            << stage_::position_first(j)
+            << ',' 
+            << stage_::position_last(j)
+            << ')';
+    }
+    out << std::endl;
+
+    unsigned nn = stage_::position_last(n_j)-1;
+
+    {
+        node_ node = root_node;
+        unsigned old_stage = node.stage;
+        do{
+            if(node.stage != old_stage){
+                out << std::endl;
+                old_stage = node.stage;
+            }
+            out << node;
+        }while(
+            position(++node)<nn    
+        );
+    }
+    out << std::endl << std::endl;
+    {
+        node_ node = root_node;
+        ++node;
+        unsigned old_stage = node.stage;
+        do{
+            if(node.stage != old_stage){
+                out << std::endl;
+                old_stage = node.stage;
+            }
+            out << root(node);
+        }while(
+            position(++node)<nn    
+        );
+    }
+    out << std::endl << std::endl;
+    {
+        node_ node = back(root_node,n_j);
+        
+        unsigned old_stage = node.stage;
+        do{
+            if(node.stage != old_stage){
+                out << std::endl;
+                old_stage = node.stage;
+            }
+            out << node;
+        }while(
+            (--node).stage > 0    
+        );
+    }
+
+    out << " <- ";
+}
\ No newline at end of file
Added: sandbox/statistics/tree/libs/tree/example/tree.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/tree/libs/tree/example/tree.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// tree::example::tree.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_TREE_EXAMPLE_TREE_HPP_ER_2009
+#define LIBS_TREE_EXAMPLE_TREE_HPP_ER_2009
+#include <ostream>
+
+void example_tree(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/boost/vector_space/algorithm/find.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/boost/vector_space/algorithm/find.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,50 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::algorithm::find.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_VECTOR_SPACE_FIND_HPP_ER_2009
+#define BOOST_VECTOR_SPACE_FIND_HPP_ER_2009
+#include <numeric>
+#include <cmath>
+#include <boost/vector_space/functional/equal.hpp>
+
+namespace boost{
+namespace vector_space{
+    
+    // This is a version of find where the elements in *[b,e) are ranges.
+    // The value eps is a minimum proximity distance that if not met
+    // causes the algorithm to return e.
+    template<template<typename> class F,typename In,typename X>
+    In find(
+        In b, // *In is a range
+        In e,
+        const X& x,
+        const typename range_value<X>::type& eps
+    ){
+        return std::find_if(
+            b,
+            e,
+            functional::equal(x,eps)
+        );
+    }
+
+    template<typename In,typename X>
+    In find(
+        In b, 
+        In e,
+        const X& x
+    ){
+        return std::find_if(
+            b,
+            e,
+            functional::equal(x,eps)
+        );
+    }
+    
+}//algorithm
+}//boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/boost/vector_space/data/detail/cref.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/boost/vector_space/data/detail/cref.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,41 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::data::detail::cref.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_VECTOR_SPACE_DATA_DETAIL_CREF_H_ER_2009
+#define BOOST_VECTOR_SPACE_DATA_DETAIL_CREF_H_ER_2009
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/range.hpp>
+
+namespace boost{
+namespace vector_space{
+namespace detail{
+
+// A data structure that keeps a const reference to a range. 
+template<typename X>
+struct cref{
+    typedef is_reference<X> is_ref_x_;
+    typedef is_const<X> is_const_x_;
+    BOOST_MPL_ASSERT((mpl::not_<is_ref_x_>));
+    BOOST_MPL_ASSERT((mpl::not_<is_const_x_>));
+    
+    cref(const X& x):x_(x){}
+    cref(const cref& that):x_(that.x_){}
+    typedef typename range_iterator<const X>::type const_iterator;
+    
+    const_iterator begin()const{ return boost::begin(x_); }
+    const_iterator end()const{ return boost::end(x_); }
+    
+    const X& x_;
+};
+
+}// detail
+}// vector_space
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/boost/vector_space/data/lazy_difference.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/boost/vector_space/data/lazy_difference.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,91 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::data::lazy_difference.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_VECTOR_SPACE_DATA_LAZY_DIFFERENCE_H_ER_2009
+#define BOOST_VECTOR_SPACE_DATA_LAZY_DIFFERENCE_H_ER_2009
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/iterator/zip_iterator.hpp>
+#include <boost/iterator/transform_iterator.hpp>
+#include <boost/tuple/tuple.hpp>
+#include <boost/range.hpp>
+#include <boost/binary_op/functional/untupler.hpp>
+#include <boost/vector_space/data/detail/cref.hpp>
+
+namespace boost{
+namespace vector_space{
+
+// A data structure that offers a lazy (i.e. no copying involved) representation 
+// of an element by element difference between two ranges.
+//
+// Usage:
+// typedef lazy_difference<X,X1> diff_;
+// typedef range_value<diff_> val_;
+// diff_ diff(x,x1);
+// val d0 = const_begin(diff)
+template<typename X,typename X1>
+class lazy_difference{
+    typedef typename range_value<X>::type value_type;
+    typedef std::minus<value_type> minus_;
+    typedef binary_op::untupler<minus_> fun_;
+
+    typedef detail::template cref<X> cref_x_;
+    typedef detail::template cref<X1> cref_x1_;       
+    typedef typename cref_x_::const_iterator it_x_;
+    typedef typename cref_x1_::const_iterator it_x1_;
+    typedef boost::tuple<it_x_,it_x1_> it_tuple_;
+    typedef boost::zip_iterator<it_tuple_> zip_it_;
+    
+    public:
+    lazy_difference(const X& x,const X1& x1)
+    :cref_x(x),cref_x1(x1){}
+    
+    lazy_difference(const lazy_difference& that)
+    :cref_x(that.cref_x),cref_x1(that.cref_x1){}
+
+    typedef boost::transform_iterator<fun_,zip_it_> const_iterator;
+    typedef const_iterator iterator;
+
+    // TODO size etc.
+    const_iterator begin()const{
+        return this->get_iterator(
+            cref_x.begin(),
+            cref_x1.begin()
+        );
+    }
+    const_iterator end()const{
+        return this->get_iterator(
+            cref_x.end(),
+            cref_x1.end()
+        );
+    }
+    
+    //private:
+    cref_x_ cref_x;
+    cref_x1_ cref_x1;
+
+    lazy_difference& operator=(const lazy_difference&);
+    const_iterator get_iterator(it_x_ it_x,it_x1_ it_x1)const{
+        fun_ f;
+        return  make_transform_iterator(
+            make_zip_iterator(
+                make_tuple(
+                    it_x,
+                    it_x1
+                )
+            ),
+            f
+        );
+    }
+    
+};
+
+}// vector_space
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/boost/vector_space/functional/equal.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/boost/vector_space/functional/equal.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,112 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::functional::equal.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_VECTOR_SPACE_FUNCTIONAL_EQUAL_HPP_ER_2009
+#define BOOST_VECTOR_SPACE_FUNCTIONAL_EQUAL_HPP_ER_2009
+#include <boost/call_traits.hpp>
+#include <ostream>
+#include <boost/range.hpp>
+#include <boost/mpl/nested_type.hpp>
+#include <boost/math/special_functions/fpclassify.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/vector_space/functional/l2_distance_squared.hpp>
+
+namespace boost{
+namespace vector_space{
+
+// This predicate implements (x == y) iff (|| x - y || == 0).
+//
+// Requirements:
+// F<R> distance(x);        Construction
+// distance(y)              Returns an object of type range_value<R>::type
+//
+// Usage:
+// functor<R,F> fun(x,eps);
+// fun(y) returns true if distance(y) < eps
+template<typename R, template<typename> class F = l2_distance_squared> 
+class equal{
+    typedef F<R> arg_;
+    typedef typename mpl::nested_type<arg_>::type distance_type;    
+    typedef typename remove_reference<R>::type const_range_type;
+    typedef typename remove_const<const_range_type>::type range_type;
+    typedef typename range_value<range_type>::type value_type;
+public:
+            
+    //Construction
+    equal(typename call_traits<R>::param_type x,value_type eps);
+    equal(typename call_traits<R>::param_type x);
+    equal(const equal& that);
+    equal& operator=(const equal& that);
+            
+    //Evaluate
+    typedef bool result_type;
+
+    template<typename R1> result_type operator()(const R1& y)const;
+    result_type epsilon()const;
+                                               
+//private:
+    equal();
+    distance_type distance_;
+    value_type eps_;
+    static value_type default_eps_;
+};
+
+// 
+template<typename R, template<typename> class F>
+std::ostream& operator<<(std::ostream& out,const equal<R,F>& e){
+    out << '(' <<  e.epsilon() << ')';
+    return out;
+}
+
+// Static members
+template<typename R, template<typename> class F>
+typename equal<R,F>::value_type
+equal<R,F>::default_eps_ 
+    = math::tools::epsilon<typename equal<R,F>::value_type>();
+
+template<typename R, template<typename> class F>
+typename equal<R,F>::result_type 
+equal<R,F>::epsilon()const{
+    return eps_;
+}
+
+//Construction
+
+template<typename R, template<typename> class F>
+equal<R,F>::equal(typename call_traits<R>::param_type x,value_type eps)
+:distance_(x),eps_(eps){}
+
+template<typename R, template<typename> class F>
+equal<R,F>::equal(typename call_traits<R>::param_type x)
+:distance_(x),eps_(default_eps_){}
+
+template<typename R, template<typename> class F>
+equal<R,F>::equal(const equal& that)
+:distance_(that.distance_),eps_(that.eps_){}
+
+template<typename R, template<typename> class F>
+equal<R,F>& 
+equal<R,F>::operator=(const equal& that){
+    if(&that!=this){
+        distance_ = that.distance_;
+        eps_ = that.eps_;
+    }
+    return *this;
+}
+    
+// Evaluate
+template<typename R, template<typename> class F>
+template<typename R1> 
+typename equal<R,F>::result_type 
+equal<R,F>::operator()(const R1& y)const{
+    return (distance_(y)<eps_);
+}
+
+}//vector_space
+}//boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/boost/vector_space/functional/l2_distance_squared.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/boost/vector_space/functional/l2_distance_squared.hpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,102 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::functional::l2_distance_squared.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_VECTOR_SPACE_FUNCTIONAL_l2_DISTANCE_SQUARED_HPP_ER_2009
+#define BOOST_VECTOR_SPACE_FUNCTIONAL_l2_DISTANCE_SQUARED_HPP_ER_2009
+#include <cmath>
+#include <numeric>
+#include <functional>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits.hpp>
+#include <boost/function.hpp>
+#include <boost/call_traits.hpp>
+#include <boost/range.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/bind.hpp>
+#include <boost/math/tools/precision.hpp>
+
+namespace boost{
+namespace vector_space{
+
+    // Stores a range r, and when passed another range r1, computes the squared
+    // Euclidian distance of r-r1.
+    //
+    // Examples: 
+    // R == const std::vector<double>& 
+    // R == iterator_range<std::vector<double> >
+    template<typename R>
+    class l2_distance_squared{
+        typedef typename is_reference<R>::type is_ref_;
+    public:
+        typedef typename remove_reference<R>::type const_range_type;
+        typedef typename remove_const<const_range_type>::type range_type;
+        typedef typename range_value<range_type>::type result_type;
+                    
+        // Constructor
+        l2_distance_squared(typename call_traits<R>::param_type x);
+        l2_distance_squared(const l2_distance_squared& that);
+        l2_distance_squared& operator=(const l2_distance_squared& that);                    
+
+        // Call
+        template<typename R1> 
+        result_type operator()(const R1& y)const;
+                        
+        private:
+        l2_distance_squared();
+        typename call_traits<R>::value_type x_;
+    };
+    
+    template<typename R> 
+    l2_distance_squared<R> 
+    make_l2_distance_squared(const R& x){
+        return l2_distance_squared<R>(x);
+    }
+
+    // Definitions
+    template<typename R>
+    l2_distance_squared<R>::l2_distance_squared(
+        typename call_traits<R>::param_type x
+    ):x_(x){
+        BOOST_MPL_ASSERT((mpl::not<is_ref_>));
+    }
+
+    template<typename R>
+    l2_distance_squared<R>::l2_distance_squared(
+        const l2_distance_squared& that
+    ):x_(that.x_){}
+
+    template<typename R>
+    l2_distance_squared<R>& 
+    l2_distance_squared<R>::operator=(const l2_distance_squared& that){
+        if(&that != this){
+            BOOST_MPL_ASSERT((mpl::not<is_ref_>));
+            x_ = that.x_;
+        }
+        return *this;
+    }
+    
+    template<typename R>
+    template<typename R1> 
+    typename l2_distance_squared<R>::result_type 
+    l2_distance_squared<R>::operator()(const R1& y)const{
+        BOOST_ASSERT( 
+            size(x_) == size(y) 
+        );
+        return std::inner_product(
+            begin(y),
+            end(y),
+            begin(x_),
+            static_cast<result_type>(0),
+            std::plus<result_type>(),
+            (lambda::_1 * lambda::_1)(lambda::_1 - lambda::_2)
+        );
+    };
+
+}// range
+}// boost
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/libs/vector_space/doc/readme.txt
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/doc/readme.txt	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,46 @@
+//////////////////////////////////////////////////////////////////////////////
+// vector_space::doc::readme                                                //
+//                                                                          //
+//  (C) Copyright 2009 Erwann Rogard                                        //
+//  Use, modification and distribution are subject to the                   //
+//  Boost Software License, Version 1.0. (See accompanying file             //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)        //
+//////////////////////////////////////////////////////////////////////////////
+
+[ Contact ]
+
+erwann.rogard_at_[hidden]
+
+[ Overview ]
+
+These are C++ tools for basic vector space operations (e.g. norm) that work
+with STL containers.
+
+For example, let R0/r0 and R1/r1 denote ranges (ForwardRange) of scalar type and
+object pairs. This tests for || r0 - r1 || == 0 :
+
+	equal<R0> eq(r0);
+	bool r0_eq_r1 = eq(r1);
+
+[ Compiler ]
+
+gcc version i686-apple-darwin9-gcc-4.0.1 (GCC) 4.0.1
+
+[ Dependencies ]
+
+/usr/local/boost_1_39_0/ 
+
+[ History ]
+
+July 2009 : Current version
+
+[Output]
+
+main.cpp
+
+-> example_difference : <- 
+-> example_equal : (1)
+0 1 3 
+3 4 6 
+6 7 9 
+<-
\ No newline at end of file
Added: sandbox/statistics/vector_space/libs/vector_space/example/difference.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/example/difference.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,61 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::example::difference.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 <functional>
+#include <iterator>
+#include <boost/bind.hpp>
+#include <boost/range.hpp>
+#include <boost/assert.hpp>
+#include <boost/foreach.hpp>
+#include <boost/assign/std/vector.hpp>
+#include <boost/math/tools/precision.hpp>
+#include <boost/vector_space/data/lazy_difference.hpp>
+
+void example_difference(std::ostream& out){
+    std::cout << "-> example_difference : ";
+    using namespace boost;
+    namespace vs = vector_space;
+    typedef double                          val_;
+    typedef std::vector<val_>               vec_;
+    typedef vs::lazy_difference<vec_,vec_>  range_diff_;
+
+    const val_ eps = math::tools::epsilon<val_>();
+    const val_ delta = eps * static_cast<val_>(2);
+
+    vec_ vec;
+    {
+        using namespace assign;
+        vec += 0.0, 1.1, 2.2, 3.3;
+    }
+    vec_ vec1(vec);
+    std::transform(
+        boost::begin(vec),
+        boost::end(vec),
+        begin(vec1),
+        boost::bind<val_>(
+            std::minus<val_>(),
+            _1,
+            delta
+        )
+    );
+
+    range_diff_ range_diff(vec,vec1);
+    vec_ copy_diff(size(vec));
+    std::copy(
+        const_begin(range_diff),
+        const_end(range_diff),
+        begin(copy_diff)
+    );
+
+   BOOST_FOREACH(const val_& z, copy_diff){
+        BOOST_ASSERT(fabs(z-delta)<eps);
+    }
+
+    out << "<- " << std::endl;
+}
Added: sandbox/statistics/vector_space/libs/vector_space/example/difference.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/example/difference.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,14 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::example::difference.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_VECTOR_SPACE_EXAMPLE_DIFFERENCE_H_ER_2009
+#define BOOST_VECTOR_SPACE_EXAMPLE_DIFFERENCE_H_ER_2009
+#include <ostream>
+
+void example_difference(std::ostream&);
+
+#endif
\ No newline at end of file
Added: sandbox/statistics/vector_space/libs/vector_space/example/equal.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/example/equal.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,55 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::example::equal.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 <iterator>
+#include <boost/assert.hpp>
+#include <boost/vector_space/functional/equal.hpp>
+#include <libs/vector_space/example/equal.h>
+
+void example_equal(std::ostream& out) {
+    out << "-> example_equal : ";
+    using namespace boost;
+    
+    typedef unsigned val_;
+    typedef std::vector<val_> row_;
+    typedef std::vector<row_> mat_;
+    typedef range_iterator<mat_>::type iterator_row_;
+    typedef range_iterator<row_>::type iterator_elem_;
+    typedef range_reference<mat_>::type ref_row_;
+    typedef range_reference<row_>::type ref_elem_;
+    typedef vector_space::equal<row_&> equal_;
+        
+    const unsigned n = 3;
+    const val_ eps = 1; // defaul eps = 0, so |i-j| < 1 need, i,j integers
+    row_ row(n);
+    equal_ equal(row,eps);
+    std::cout << equal << std::endl;
+    mat_ mat(n,row);
+    val_ val = 0;
+    for(unsigned i = 0; i<n; i++){
+        val = i * n;
+        ref_row_ ref_row = mat[i]; 
+        for(unsigned j = 0; j<n; j++){
+            val += j;
+            row[j] = val;
+            ref_row[j] = val;
+        }
+        std::copy(   
+            begin( row ),
+            end( row ),
+            std::ostream_iterator<int>(out," ")
+        ); 
+        out << std::endl;
+        BOOST_ASSERT(
+            equal(ref_row)
+        );
+    }
+
+    out << "<-" << std::endl;
+}
\ No newline at end of file
Added: sandbox/statistics/vector_space/libs/vector_space/example/equal.h
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/example/equal.h	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::example::equal.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_VECTOR_SPACE_EXAMPLE_EQUAL_H_ER_2009
+#define BOOST_VECTOR_SPACE_EXAMPLE_EQUAL_H_ER_2009
+#include <ostream>
+
+void example_equal(std::ostream&);
+
+#endif
+
Added: sandbox/statistics/vector_space/libs/vector_space/src/main.cpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/vector_space/libs/vector_space/src/main.cpp	2009-08-16 01:29:27 EDT (Sun, 16 Aug 2009)
@@ -0,0 +1,18 @@
+///////////////////////////////////////////////////////////////////////////////
+// vector_space::src::main.cpp                                               //
+//                                                                           //
+//  Copyright 2009 Erwann Rogard. Distributed under the Boost                //
+//  Software License, Version 1.0. (See accompanying file                    //
+//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)         //
+///////////////////////////////////////////////////////////////////////////////
+#include <iostream>
+#include <libs/vector_space/example/difference.h>
+#include <libs/vector_space/example/equal.h>
+
+int main(){
+
+    example_difference(std::cout);
+    example_equal(std::cout);
+
+    return 0;
+}