32 #ifndef VSMC_CORE_PARTICLE_HPP
33 #define VSMC_CORE_PARTICLE_HPP
57 typedef typename rng_set_type::rng_type
rng_type;
61 typedef cxx11::function<void (std::size_t, std::size_t,
70 weight_set_(static_cast<typename
71 traits::SizeTypeTrait<weight_set_type>::
type>(N)),
72 rng_set_(static_cast<typename
73 traits::SizeTypeTrait<rng_set_type>::
type>(N)),
74 resample_rng_(
Seed::instance().
get()) {}
100 #if VSMC_HAS_CXX11_RVALUE_REFERENCES
102 resample_rng_type rrng(
cxx11::move(resample_rng_));
109 rng_set_type rset(0);
110 swap(rset, rng_set_);
111 resample_rng_type rrng(resample_rng_);
113 swap(rset, rng_set_);
114 resample_rng_ = rrng;
116 rng_set_.resize(other.
size());
125 #if VSMC_HAS_CXX11_RVALUE_REFERENCES
128 if (
this != &other) {
131 resample_rng_type rrng(
cxx11::move(resample_rng_));
135 rng_set_.resize(other.size());
146 size_type
size ()
const {
return size_;}
149 value_type &
value () {
return value_;}
152 const value_type &
value ()
const {
return value_;}
158 const weight_set_type &
weight_set ()
const {
return weight_set_;}
164 const rng_set_type &
rng_set ()
const {
return rng_set_;}
167 rng_type &
rng (size_type
id) {
return rng_set_[id];}
173 csp_type
sp (size_type
id)
const {
return csp_type(
id,
this);}
234 bool resample (
const resample_type &op,
double threshold)
236 std::size_t N =
static_cast<std::size_t
>(weight_set_.resample_size());
237 bool resampled = weight_set_.ess() < threshold * N;
240 const double *wptr = weight_set_.resample_weight_data();
242 resample_copy_from_.resize(N);
243 resample_replication_.resize(N);
244 cptr = &resample_copy_from_[0];
245 size_type *rptr = &resample_replication_[0];
246 op(N, N, resample_rng_, wptr, rptr);
247 resample_copy_from_replication_(N, N, rptr, cptr);
249 value_.copy(N, cptr);
250 resample_post_copy_(weight_set_);
260 weight_set_type weight_set_;
261 rng_set_type rng_set_;
262 resample_rng_type resample_rng_;
264 std::vector<size_type, AlignedAllocator<size_type> > resample_copy_from_;
265 std::vector<size_type, AlignedAllocator<size_type> > resample_replication_;
272 #endif // VSMC_CORE_PARTICLE_HPP
static SeedGenerator< ID, ResultType > & instance()
Particle class representing the whole particle set.
sp_type sp(size_type id)
Get a SingleParticle.
internal::RngSetTypeDispatch< T, value >::type type
ConstSingleParticle< T > csp_type
csp_type sp(size_type id) const
Get a ConstSingleParticle.
Particle< T > clone(bool new_rng) const
Clone the particle system except the RNG engines.
value_type & value()
Read and write access to the value collection object.
traits::RngSetTypeTrait< T >::type rng_set_type
traits::ResampleRngTypeTrait< T >::type resample_rng_type
traits::ResamplePostCopyTypeTrait< T >::type resample_post_copy_type
const weight_set_type & weight_set() const
Read only access to the weight collection object.
internal::ResampleRngTypeDispatch< T, value >::type type
cxx11::function< void(std::size_t, std::size_t, resample_rng_type &, const double *, size_type *)> resample_type
const value_type & value() const
Read only access to the value collection object.
Particle< T > & clone(const Particle< T > &other, bool retain_rng)
Clone another particle system except the RNG engines.
bool resample(const resample_type &op, double threshold)
Performing resampling if ESS/N < threshold.
SingleParticle< T > sp_type
traits::ResampleCopyFromReplicationTypeTrait< T >::type resample_copy_from_replication_type
T & get(Array< T, N > &ary)
Array ADL of get.
csp_type csp(size_type id)
Get a ConstSingleParticle.
rng_set_type::rng_type rng_type
internal::WeightSetTypeDispatch< T, value >::type type
Particle< T > & clone(Particle< T > &&other, bool retain_rng)
internal::ResamplePostCopyTypeDispatch< T, value >::type type
remove_reference< T >::type && move(T &&t) noexcept
resample_rng_type & resample_rng()
Get the (sequential) RNG used stream for resampling.
rng_type & rng(size_type id)
Get an (parallel) RNG stream for a given particle.
#define VSMC_NULLPTR
nullptr
void swap(Array< T, N > &ary1, Array< T, N > &ary2)
Array ADL of swap.
rng_set_type & rng_set()
Read and write access to the RNG collection object.
traits::SizeTypeTrait< T >::type size_type
internal::SizeTypeDispatch< T, value >::type type
internal::ResampleCopyFromReplicationTypeDispatch< T, value >::type type
traits::WeightSetTypeTrait< T >::type weight_set_type
size_type size() const
Number of particles.
A thin wrapper over a complete Particle.
csp_type csp(size_type id) const
Get a ConstSingleParticle.
weight_set_type & weight_set()
Read and write access to the weight collection object.
A const variant to SingleParticle.
const rng_set_type & rng_set() const
Read only access to the RNG collection object.