32 #ifndef VSMC_CORE_PATH_HPP 33 #define VSMC_CORE_PATH_HPP 37 #define VSMC_RUNTIME_ASSERT_CORE_PATH_ITER(func) \ 38 VSMC_RUNTIME_ASSERT((iter < iter_size()), \ 39 "**Path::" #func "** INVALID ITERATION NUMBER ARGUMENT") 41 #define VSMC_RUNTIME_ASSERT_CORE_PATH_EVAL \ 42 VSMC_RUNTIME_ASSERT( \ 43 static_cast<bool>(eval_), "**Path::eval** INVALID EVALUAITON OBJECT") 56 std::function<double(std::size_t, Particle<T> &,
double *)>;
98 , record_only_(record_only)
112 integrand_.reserve(num);
117 bool empty()
const {
return !
static_cast<bool>(eval_); }
123 std::size_t
index(std::size_t iter)
const 135 return integrand_[iter];
139 double grid(std::size_t iter)
const 147 const std::size_t *
index_data()
const {
return index_.data(); }
153 const std::size_t *
grid_data()
const {
return grid_.data(); }
158 template <
typename OutputIter>
161 std::copy(index_.begin(), index_.end(), first);
165 template <
typename OutputIter>
168 std::copy(integrand_.begin(), integrand_.end(), first);
172 template <
typename OutputIter>
175 std::copy(grid_.begin(), grid_.end(), first);
182 record_only_ = record_only;
197 double grid = eval_(iter, particle, &integrand);
198 push_back(iter, grid, integrand);
203 const std::size_t N =
static_cast<std::size_t
>(particle.
size());
205 double grid = eval_(iter, particle, buffer_.data());
207 dot(N, particle.
weight().data(), 1, buffer_.data(), 1);
208 push_back(iter, grid, integrand);
245 void push_back(std::size_t iter,
double grid,
double integrand)
247 index_.push_back(iter);
248 grid_.push_back(grid);
249 integrand_.push_back(integrand);
252 log_zconst_ += 0.5 * (grid_[i] - grid_[i - 1]) *
253 (integrand_[i] + integrand_[i - 1]);
260 #endif // VSMC_CORE_PATH_HPP T dot(std::size_t n, const T *x, std::size_t incx, const T *y, std::size_t incy)
Computes a vector-vector dot product.
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.
#define VSMC_RUNTIME_ASSERT_CORE_PATH_EVAL
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, Particle< T > &particle)
#define VSMC_RUNTIME_ASSERT_CORE_PATH_ITER(func)
typename std::conditional< std::is_scalar< T >::value, std::vector< T, AlignedAllocator< T >>, std::vector< T >>::type Vector
AlignedVector for scalar type and std::vector for others.
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.
weight_type & weight()
Read and write access to the weight collection object.
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.
std::function< double(std::size_t, Particle< T > &, double *)> eval_type
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.
void copy(std::size_t n, const T *x, std::size_t incx, T *y, std::size_t incy)
Copies vector to another vector.
bool empty() const
Whether the evaluation object is valid.
void exp(std::size_t n, const float *a, float *y)
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.
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.