32 #ifndef VSMC_CORE_PATH_HPP
33 #define VSMC_CORE_PATH_HPP
38 #define VSMC_RUNTIME_ASSERT_CORE_PATH_ITER(func) \
39 VSMC_RUNTIME_ASSERT((iter < iter_size()), \
40 ("**Path::"#func"** INVALID ITERATION NUMBER ARGUMENT"))
42 #define VSMC_RUNTIME_ASSERT_CORE_PATH_FUNCTOR(func, caller, name) \
43 VSMC_RUNTIME_ASSERT(static_cast<bool>(func), \
44 ("**Path::"#caller"** INVALID "#name" OBJECT")) \
56 typedef cxx11::function<double (
90 explicit Path (
const eval_type &
eval,
bool record_only =
false) :
91 eval_(eval), recording_(true), record_only_(record_only),
97 std::size_t
iter_size ()
const {
return index_.size();}
103 integrand_.reserve(num);
108 bool empty ()
const {
return !
static_cast<bool>(eval_);}
114 std::size_t
index (std::size_t iter)
const
126 return integrand_[iter];
130 double grid (std::size_t iter)
const
144 const std::size_t *
grid_data ()
const {
return &grid_[0];}
149 template <
typename OutputIter>
151 {std::copy(index_.begin(), index_.end(), first);}
154 template <
typename OutputIter>
156 {std::copy(integrand_.begin(), integrand_.end(), first);}
159 template <
typename OutputIter>
161 {std::copy(grid_.begin(), grid_.end(), first);}
164 void set_eval (
const eval_type &new_eval,
bool record_only =
false)
165 {eval_ = new_eval; record_only_ = record_only;}
179 double grid = eval_(iter, particle, &integrand);
180 push_back(iter, grid, integrand);
185 const std::size_t N =
static_cast<std::size_t
>(particle.
size());
187 double *
const bptr = &buffer_[0];
188 const double *
const wptr = particle.
weight_set().weight_data();
189 double grid = eval_(iter, particle, bptr);
191 push_back(iter, grid, integrand);
195 double zconst ()
const {
return std::exp(log_zconst_);}
224 std::vector<std::size_t> index_;
225 std::vector<double, AlignedAllocator<double> > integrand_;
226 std::vector<double, AlignedAllocator<double> > grid_;
227 std::vector<double, AlignedAllocator<double> > buffer_;
229 void push_back (std::size_t iter,
double grid,
double integrand)
231 index_.push_back(iter);
232 grid_.push_back(grid);
233 integrand_.push_back(integrand);
236 log_zconst_ += 0.5 * (grid_[i] - grid_[i - 1]) *
237 (integrand_[i] + integrand_[i - 1]);
244 #endif // VSMC_CORE_PATH_HPP
cxx11::function< double(std::size_t, const Particle< T > &, double *)> eval_type
const std::size_t * integrand_data() const
Read only access to the raw data of the integrand vector.
Particle class representing the whole particle set.
void reserve(std::size_t num)
Reserve space for a specified number of iterations.
double log_zconst() const
Get the logarithm nomralizing constants ratio estimates.
double grid(std::size_t iter) const
Get the Path sampling grid value of a given Path iteration.
void eval(std::size_t iter, const Particle< T > &particle)
void turn_on()
Turn on the recording.
std::size_t index(std::size_t iter) const
Get the iteration index of the sampler of a given monitor iteration.
double zconst() const
Get the nomralizing constants ratio estimates.
const std::size_t * grid_data() const
Read only access to the raw data of the grid vector.
const std::size_t * index_data() const
Read only access to the raw data of the index vector.
bool recording() const
Whether the Path is actively recording restuls.
bool empty() const
Whether the evaluation object is valid.
#define VSMC_RUNTIME_ASSERT_CORE_PATH_ITER(func)
T dot(std::size_t n, const T *x, const T *y)
The dot product.
void clear()
Clear all records of the index and integrations.
Path(const eval_type &eval, bool record_only=false)
Construct a Path with an evaluation object.
Monitor for Path sampling.
std::size_t iter_size() const
The number of iterations has been recorded.
void turn_off()
Turn off the recording.
double integrand(std::size_t iter) const
Get the Path sampling integrand of a given Path iteration.
void set_eval(const eval_type &new_eval, bool record_only=false)
Set a new evaluation object of type eval_type.
void read_integrand(OutputIter first) const
Read the integrand history through an output iterator.
#define VSMC_RUNTIME_ASSERT_CORE_PATH_FUNCTOR(func, caller, name)
size_type size() const
Number of particles.
void read_grid(OutputIter first) const
Read the grid history through an output iterator.
void read_index(OutputIter first) const
Read the index history through an output iterator.
weight_set_type & weight_set()
Read and write access to the weight collection object.