|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r55745 - in sandbox/statistics/importance_sampling: boost/importance_sampling libs/importance_sampling/doc libs/importance_sampling/example
From: erwann.rogard_at_[hidden]
Date: 2009-08-23 20:35:12
Author: e_r
Date: 2009-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
New Revision: 55745
URL: http://svn.boost.org/trac/boost/changeset/55745
Log:
is update
Added:
sandbox/statistics/importance_sampling/boost/importance_sampling/sampler_deprecated.hpp (contents, props changed)
Text files modified:
sandbox/statistics/importance_sampling/boost/importance_sampling/generate.hpp | 3 +
sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp | 75 ++++++++++++++++++++-------------------
sandbox/statistics/importance_sampling/libs/importance_sampling/doc/readme.txt | 3 +
sandbox/statistics/importance_sampling/libs/importance_sampling/example/sampler.cpp | 2
4 files changed, 44 insertions(+), 39 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-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
@@ -43,7 +43,8 @@
){
typedef boost::iterator_range<ItW> range_w_;
typedef boost::iterator_range<ItP> range_p_;
- typedef boost::is::sampler<range_p_> iss_;
+ typedef typename boost::iterator_value<ItW>::type w_;
+ typedef boost::is::sampler<range_p_,w_> iss_;
typedef boost::random::ref_distribution<iss_&> ref_iss_;
typedef boost::variate_generator<U&,ref_iss_> gen_iss_;
Modified: sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp
==============================================================================
--- sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp (original)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/sampler.hpp 2009-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
@@ -16,34 +16,34 @@
#include <boost/range.hpp>
#include <boost/random/variate_generator.hpp>
#include <boost/random/uniform_real.hpp>
-#include <boost/random/categorical_distribution.hpp>
+// TODO #include <boost/random/discrete_distributionhpp> when becomes avail
+#include <boost/random/discrete_distribution_sw_2009.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)
+// R1: range type of the values
+// W: type of the weights
//
// 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>
+template<typename R1,typename W>
class sampler{
- typedef typename remove_reference<R1>::type const_values_;
- typedef is_reference<R1> is_ref_;
+ typedef typename remove_reference<R1>::type const_values_;
+ typedef typename remove_cv<const_values_>::type values_t;
+ typedef typename range_size<values_t>::type size_;
+ typedef is_reference<R1> is_ref_;
public:
- typedef typename range_value<const_values_>::type result_type;
+ typedef typename range_value<const_values_>::type result_type;
private:
- typedef Ur<result_type> unif_;
- typedef random::categorical_distribution<unif_> mult_dist_t;
+ typedef random::discrete_distribution<size_,W> discr_dist_t;
public:
- typedef typename mult_dist_t::input_type input_type;
+ typedef typename discr_dist_t::input_type input_type;
sampler();
template<typename R0>
@@ -55,69 +55,70 @@
sampler& operator=(const sampler& that);
template<typename U> result_type operator()(U& urng)const;
- const mult_dist_t& categorical_distribution()const;
+ const discr_dist_t& discrete_distribution()const;
// TODO os/is
private:
- mult_dist_t mult_dist_;
+ discr_dist_t discr_dist_;
typename call_traits<R1>::value_type values_;
};
// Definition //
-template<typename R1, template<typename> class Ur>
-sampler<R1,Ur>::sampler(){
+template<typename R1, typename W>
+sampler<R1,W>::sampler(){
BOOST_MPL_ASSERT((
mpl::not_<is_ref_>
));
}
-template<typename R1, template<typename> class Ur>
+template<typename R1, typename W>
template<typename R0>
-sampler<R1,Ur>::sampler(
+sampler<R1,W>::sampler(
const R0& unnormalized_weights,
typename call_traits<R1>::param_type values
-):mult_dist_(unnormalized_weights),values_(values){
+):discr_dist_(
+ boost::begin(unnormalized_weights),
+ boost::end(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){
+template<typename R1, typename W>
+sampler<R1,W>::sampler( const sampler& that )
+:discr_dist_(that.discr_dist_),values_(that.values_){}
+
+template<typename R1, typename W>
+sampler<R1,W>&
+sampler<R1,W>::operator=(const sampler& that){
if(&that!=this){
BOOST_MPL_ASSERT((
mpl::not_<is_ref_>
));
- mult_dist_ = that.mult_dist_;
+ discr_dist_ = that.discr_dist_;
values_ = that.values_;
}
return (*this);
}
// Random
-template<typename R1, template<typename> class Ur>
+template<typename R1, typename W>
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);
+typename sampler<R1,W>::result_type
+sampler<R1,W>::operator()(U& urng)const{
+ typedef typename discr_dist_t::result_type k_t;
+ k_t k = discr_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>::categorical_distribution()const{ return mult_dist_; }
+template<typename R1, typename W>
+const typename sampler<R1,W>::discr_dist_t&
+sampler<R1,W>::discrete_distribution()const{ return discr_dist_; }
}//random
}//boost
Added: sandbox/statistics/importance_sampling/boost/importance_sampling/sampler_deprecated.hpp
==============================================================================
--- (empty file)
+++ sandbox/statistics/importance_sampling/boost/importance_sampling/sampler_deprecated.hpp 2009-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
@@ -0,0 +1,128 @@
+///////////////////////////////////////////////////////////////////////////////
+// is::sampler_deprecated.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_DEPRECATED_HPP_ER_2009
+#define BOOST_IMPORTANCE_SAMPLING_SAMPLER_DEPRECATED_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>
+// TODO #include <boost/random/discrete_distributionhpp> when becomes avail
+#include <boost/random/discrete_distribution_sw_2009.hpp>
+
+namespace boost{
+namespace is{
+
+// Deprecated because uses categorical_distribution rather than discrete
+//
+// 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_deprecated{
+ 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::categorical_distribution<unif_> mult_dist_t;
+ public:
+ typedef typename mult_dist_t::input_type input_type;
+
+ sampler_deprecated();
+ template<typename R0>
+ sampler_deprecated(
+ const R0& unnormalized_weights,
+ typename call_traits<R1>::param_type values
+ );
+ sampler_deprecated(const sampler_deprecated& that);
+ sampler_deprecated& operator=(const sampler_deprecated& that);
+
+ template<typename U> result_type operator()(U& urng)const;
+ const mult_dist_t& categorical_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_deprecated<R1,Ur>::sampler_deprecated(){
+ BOOST_MPL_ASSERT((
+ mpl::not_<is_ref_>
+ ));
+}
+
+template<typename R1, template<typename> class Ur>
+template<typename R0>
+sampler_deprecated<R1,Ur>::sampler_deprecated(
+ 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_deprecated<R1,Ur>::sampler_deprecated(
+ const sampler_deprecated& that
+)
+:mult_dist_(that.mult_dist_),values_(that.values_){}
+
+template<typename R1, template<typename> class Ur>
+sampler_deprecated<R1,Ur>&
+sampler_deprecated<R1,Ur>::operator=(const sampler_deprecated& 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_deprecated<R1,Ur>::result_type
+sampler_deprecated<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_deprecated<R1,Ur>::mult_dist_t&
+sampler_deprecated<R1,Ur>::categorical_distribution()const{ return mult_dist_; }
+
+}//random
+}//boost
+
+#endif
\ No newline at end of file
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-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
@@ -54,6 +54,9 @@
[ History ]
+August 18 2009 : refactored sampler to use discrete_distribution, no longer
+ categorical_distribution
+
July 2009 : Current version
[Output]
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-08-23 20:35:10 EDT (Sun, 23 Aug 2009)
@@ -30,7 +30,7 @@
// 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 std::string str_;
typedef double val_;
typedef std::vector<val_> vec_;
typedef range_iterator<vec_>::type it_val_;
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