|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r60144 - in sandbox/statistics/adaptive_rejection_sampling: boost/ars boost/ars/test libs/ars/doc libs/ars/example
From: erwann.rogard_at_[hidden]
Date: 2010-03-03 22:24:23
Author: e_r
Date: 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
New Revision: 60144
URL: http://svn.boost.org/trac/boost/changeset/60144
Log:
m
Text files modified:
sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp | 2
sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp | 2
sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp | 70 +++++++++++++++++++++++++--------------
sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp | 2
sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp | 6 +-
sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp | 14 ++-----
sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt | 2
sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp | 4 +-
8 files changed, 57 insertions(+), 45 deletions(-)
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/error.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -47,7 +47,7 @@
const str_t& b,
const str_t& c
){
- format f("Call : %1%, error: %2%, state : %3%");
+ boost::format f("Call : %1%, error: %2%, state : %3%");
f % a % b % c;
return f.str();
}
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/parameter.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -38,7 +38,7 @@
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;
+template<typename T> unsigned parameter<T>::n_max_reject = 100;
}// ars
}// detail
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/proposal_sampler.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -25,16 +25,15 @@
#include <boost/mpl/empty.hpp>
#include <boost/type_traits/is_base_of.hpp>
+#include <boost/lambda/lambda.hpp>
+#include <boost/lambda/bind.hpp>
#include <boost/bind.hpp>
#include <boost/random.hpp>
#include <boost/range.hpp>
#include <boost/iterator/transform_iterator.hpp>
#include <boost/function.hpp>
-//#include <boost/variant.hpp> // what for?
#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>
@@ -175,7 +174,7 @@
{
typedef data<T> data_t;
//TODO any other relevant info?
- format f("x_min = %1%, t_min = %2%|");
+ boost::format f("x_min = %1%, t_min = %2%|");
f%x_min()%t_min_;
out << f.str();
std::copy(
@@ -329,7 +328,7 @@
static vec_t vec;
if(!has_function_){
- format f(method); f%x_0%x_1;
+ boost::format f(method); f%x_0%x_1;
throw exception(
f.str(),
"no func",
@@ -381,7 +380,7 @@
){
throw exception(
method,
- (format("!dy = %1%>0")%dy).str(),
+ (boost::format("!dy = %1%>0")%dy).str(),
*this
);
}
@@ -430,7 +429,7 @@
if(
!(dy < const_::zero_)
){
- format f("!dy = %1% <0"); f%dy;
+ boost::format f("!dy = %1% <0"); f%dy;
throw exception(method,f.str(),*this);
}
back_ti = tang_t(const_::quiet_nan_,const_::quiet_nan_);
@@ -449,7 +448,7 @@
if(size_data()>max_data_count()){
throw exception(
method,
- (format("size_data() = > max_data_count() = %2%")
+ (boost::format("size_data() = > max_data_count() = %2%")
%size_data()%max_data_count()).str(),
*this
);
@@ -577,7 +576,7 @@
if(a<const_::lmax_){
T sign = boost::math::sign(dy);
a = exp(a);
- q = lz + log1p( sign * a ) / dy;
+ q = lz + boost::math::log1p( sign * a ) / dy;
}else{
q = lz + a / dy;
}
@@ -726,7 +725,7 @@
area = area_segment_safeguarded(a,*iter,offset());
}
if(area<const_::zero_){
- format f("area[%1%] = %2% <0");
+ boost::format f("area[%1%] = %2% <0");
f%std::distance(begin(datas_),iter)%area;
throw exception(method,f.str(),*this);
}
@@ -741,7 +740,7 @@
while(iter!=j){
T area = area_segment_safeguarded(a,*iter,offset());
if(area<const_::zero_){
- format f("area[%1%] = %2% < 0");
+ boost::format f("area[%1%] = %2% < 0");
f%std::distance(begin(datas_),iter)%area;
throw exception(method,f.str(),*this);
}
@@ -759,7 +758,7 @@
area = area_segment_safeguarded(a,*iter,offset());
}
if(area<const_::zero_){
- format f("area[n] = %1%<0");
+ boost::format f("area[n] = %1%<0");
f%area;
throw exception(method,f.str(),*this);
}
@@ -852,7 +851,7 @@
}
};
- if(iter!=begin(datas_)){
+ if(iter!=boost::begin(datas_)){
T t = local::impl(*boost::prior(iter),*iter,*this);
m = (m<t)? t : m;
}else{
@@ -877,24 +876,43 @@
if(max_tangent()<m){
max_tangent_ = m;
- iter = begin(datas_);
+ iter = boost::begin(datas_);
}else{
- if(iter!=begin(datas_)){
+ if(iter!=boost::begin(datas_)){
iter = boost::prior(iter);
}
}
- BOOST_ASSERT(
- is_sorted(
- begin(datas_),
- boost::end(datas_),
- bind<bool>(
- std::less<point_t>(),
- _1,
- _2
- )
- )
- );
+
+ {
+ // Replaces version below to accomodate MSVC
+ //http://stackoverflow.com/questions/262000/c-best-algorithm-to-check-if-a-vector-is-sorted
+ using namespace boost::lambda;
+ BOOST_ASSERT(
+ std::adjacent_find(
+ boost::begin(datas_),
+ boost::end(datas_),
+ boost::lambda::bind(
+ std::less<point_t>(),
+ _2,
+ _1
+ )
+ ) == boost::end(datas_)
+ );
+ }
+
+ // Previously:
+ // BOOST_ASSERT(
+ // is_sorted(
+ // boost::begin(datas_),
+ // boost::end(datas_),
+ // boost::bind<bool>(
+ // std::less<point_t>(),
+ // _1,
+ // _2
+ // )
+ // )
+ //);
update_cum_sums(iter);
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/sampler.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -52,7 +52,7 @@
return draw;
}
}
- format f(method); f%n_max_reject();
+ boost::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_; }
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/search_reflection.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -59,7 +59,7 @@
(!(ok_0 && ok_1))
){
if(n>n_max){
- format f(function);
+ boost::format f(function);
f % x_min % x_max;
throw ars::exception(f.str(),"n>n_max",p_0,p_1);
}
@@ -67,7 +67,7 @@
if(!ok_0){
T delta = (new_x_1-new_x_0);
if(delta < const_::eps_ ){
- format f(function);
+ boost::format f(function);
f % x_min % x_max;
throw ars::exception(
f.str(),
@@ -83,7 +83,7 @@
if(!ok_1){
T delta = (new_x_1-new_x_0);
if( delta < const_::eps_){
- format f(function);
+ boost::format f(function);
f % x_min % x_max;
throw ars::exception(
f.str(),
Modified: sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/boost/ars/test/standard_distribution.hpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -15,12 +15,8 @@
#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/accumulators/accumulators.hpp>
#include <boost/statistics/detail/distribution_common/meta/random/generator.hpp>
@@ -45,10 +41,10 @@
struct standard_distribution{
static void header(std::ostream& os){
- os << "(a,b,c)" << std::endl;
+ os << "This test outputs a sequence {(a,b,c)} where" << std::endl;
os << "a : sample size" << std::endl
<< "b : kolmogorov-smirnov statistic" << std::endl
- << "c : number of rejections" << std::endl;
+ << "c : avg number of rejections" << std::endl;
}
// Samples from distribution D using adaptive rejection sampling and outputs
@@ -72,8 +68,6 @@
// The ars is re-initialized after each n3 sample.
// n3 * n4 is the total size of the sample over which a KS is computed
- using namespace boost;
- using namespace math;
namespace dist = boost::statistics::detail::distribution;
namespace ks = boost::statistics::detail::kolmogorov_smirnov;
typedef std::string str_;
@@ -96,7 +90,7 @@
{
static const str_ str
= "Initialized every %1% draw(s) with x1 = %2% and x2 = %3%";
- format f(str);
+ boost::format f(str);
f%n3%init_0%init_1;
os << f.str() << std::endl;
os << description(mdist) << std::endl;
@@ -121,7 +115,7 @@
(vg_ars.distribution()).distribution()
).n_reject();
}catch(std::exception& e){
- format f("at i1 = %1%, i2 = %2% : %3%");
+ boost::format f("at i1 = %1%, i2 = %2% : %3%");
f % i1 % i2 % e.what();
throw std::runtime_error(f.str());
}
Modified: sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt (original)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/doc/readme.txt 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -40,7 +40,7 @@
March 3rd, 2010
- Fixed an apparent slow convergence in the output from
standard_distribution.cpp which was in fact due to a formatting defect.
- - Added MSVC workaround in proposal_sampler.hpp bec ext/algorithm not found
+ - Added MSVC workarounds in proposal_sampler.hpp
Jan 20 2010 : small changes to test functions to adapt to the new
non_parametric::kolmogorov_smirnov functionality.
Modified: sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp
==============================================================================
--- sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp (original)
+++ sandbox/statistics/adaptive_rejection_sampling/libs/ars/example/search_reflection.cpp 2010-03-03 22:24:22 EST (Wed, 03 Mar 2010)
@@ -29,7 +29,7 @@
const point_t& p_0,
const point_t& p_1
){
- format f("x_0 = %1%, x_1 = %2%, ");
+ boost::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;
@@ -50,7 +50,7 @@
const value_t mu = 0.0;
const value_t sigma = 2.0;
mdist_t mdist(mu,sigma);
- out << (format("N(%1%,%2%)")%mu%sigma);
+ out << (boost::format("N(%1%,%2%)")%mu%sigma);
{
x_0 = 100.0;
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk