|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55982 - in sandbox/statistics/importance_sampling: boost/importance_sampling libs/importance_sampling/doc libs/importance_sampling/example
From: erwann.rogard_at_[hidden]
Date: 2009-09-02 21:50:28
Author: e_r
Date: 2009-09-02 21:50:27 EDT (Wed, 02 Sep 2009)
New Revision: 55982
URL: http://svn.boost.org/trac/boost/changeset/55982
Log:
m
Text files modified:
sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp | 2 +-
sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt | 27 +++++++++++++++++++++------
sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp | 36 +++++++++++++++---------------------
3 files changed, 37 insertions(+), 28 deletions(-)
Modified: sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp
==============================================================================
--- sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp (original)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp 2009-09-02 21:50:27 EDT (Wed, 02 Sep 2009)
@@ -13,7 +13,7 @@
#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/statistics/empirical_cdf/algorithm/proportion_less_than.hpp>
#include <boost/importance_sampling/sampler.hpp>
#include <boost/random/ref_distribution.hpp>
Modified: sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt
==============================================================================
--- sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt (original)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt 2009-09-02 21:50:27 EDT (Wed, 02 Sep 2009)
@@ -16,7 +16,17 @@
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
+
+[ Advice ]
+
+To compute the appropriate weights, we recommend using prepare_weights defined
+in the package sandbox/statistics/importance_weights
+
+To ensure that the draws are from the desired target distribution, we recommend
+monitoring
+a) The effective sample size (ESS)
+b) The uniformity of the Cook-Gelman statistics. The latter may be violated by
+either i) too small a ESS ii) incorrect computations
[ Compiler ]
@@ -25,11 +35,18 @@
[ Dependencies ]
/usr/local/boost_1_39_0/
-/sandbox/statistics/utility/
+
+/sandbox/statistics/arithmetic/
+/sandbox/statistics/dist_random/
+/sandbox/statistics/random/
+/sandbox/statistics/functional/
+/sandbox/statistics/binary_op/
+/sandbox/statistics/importance_weights/
+/sandbox/statistics/scalar_dist/
+/sandbox/statistics/empirical_cdf/
/sandbox/statistics/standard_distribution/
-/sandbox/statistics/stl/
+/sandbox/statistics/importance_sampling/
-Link to libboost_serialization-gcc40-mt-1_37.a
[ Models RandomDistribution ]
Let R denote a range of values (not restricted to scalars) representing
@@ -65,8 +82,6 @@
->example_sampler :
-->example_sampler :
-
Initial sample :
(offset,scaling_factor,pc_ess,pc_lt_eps)
(-1,1,0.438938,0)
Modified: sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp
==============================================================================
--- sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp (original)
+++ sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp 2009-09-02 21:50:27 EDT (Wed, 02 Sep 2009)
@@ -10,15 +10,16 @@
#include <algorithm>
#include <iterator>
#include <boost/bind.hpp>
-#include <boost/random.hpp>
+#include <boost/random/mersenne_twister.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:
+// Must come before empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance:
#include <boost/standard_distribution/distributions/normal.hpp>
-#include <boost/non_param/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
+#include <boost/statistics/empirical_cdf/algorithm/sequential_kolmogorov_smirnov_distance.hpp>
#include <boost/scalar_dist/include.hpp>
+#include <boost/dist_random/distributions/normal.hpp>
+#include <boost/dist_random/random/generate_n.hpp>
#include <boost/importance_weights/algorithm/prepare_weights.hpp>
#include <boost/importance_sampling/include.hpp>
@@ -37,9 +38,7 @@
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_;
@@ -57,25 +56,20 @@
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_ proposals( 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)
+ vec_ is_weights( n_p );
+
+ generate_function_n<math::fun_wrap::log_unnormalized_pdf_>(
+ boost::begin( proposals ),
+ boost::begin( is_weights ),
+ n_p,
+ md_proposal,
+ urng
);
prepare_weights(
@@ -100,7 +94,7 @@
{
// i 0 1 ... n-1
// [b,e) [0,m) [m,2m) ... [(n-1)m,n m)
- boost::non_param::sequential_kolmogorov_smirnov_distance(
+ statistics::empirical_cdf::sequential_kolmogorov_smirnov_distance(
md_target,
boost::begin(targets),
boost::end(targets),
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk