cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::io::sampler_t< PolicyT > Class Template Reference

通用采样器/Generic sampler More...

#include <sampler.hpp>

Public Types

using index_type = std::size_t
 索引类型/Index type
 

Public Member Functions

 sampler_t (const sampler_t &other)
 拷贝构造函数/Copy constructor
 
sampler_toperator= (const sampler_t &other)
 拷贝赋值操作符/Copy assignment operator
 
 sampler_t (std::size_t dataset_size, PolicyT policy=PolicyT {})
 构造函数/Constructor
 
void reset ()
 重置索引并重新应用策略/Reset indices and reapply policy
 
bool has_next () const noexcept
 是否还有下一个索引/Whether there are more indices
 
index_type next ()
 获取下一个索引/Get the next index
 
std::vector< index_typenext_batch (std::size_t batch_size)
 获取批量索引/Get a batch of indices
 

Detailed Description

template<typename PolicyT = sequential_policy_t>
class toolbox::io::sampler_t< PolicyT >

通用采样器/Generic sampler

支持顺序采样和随机采样等策略/Supports sequential and shuffle sampling policies

Template Parameters
PolicyT采样策略类型/Sampling policy type
// 顺序采样/Sequential sampling
while (sampler.has_next()) {
auto idx = sampler.next();
}
// 随机采样/Shuffle sampling
toolbox::io::shuffle_policy_t(123)); shuffle_sampler.reset(); auto batch =
shuffle_sampler.next_batch(2);
通用采样器/Generic sampler
Definition sampler.hpp:96
随机打乱采样策略/Shuffle sampling policy
Definition sampler.hpp:44

Member Typedef Documentation

◆ index_type

template<typename PolicyT = sequential_policy_t>
using toolbox::io::sampler_t< PolicyT >::index_type = std::size_t

索引类型/Index type

Constructor & Destructor Documentation

◆ sampler_t() [1/2]

template<typename PolicyT = sequential_policy_t>
toolbox::io::sampler_t< PolicyT >::sampler_t ( const sampler_t< PolicyT > &  other)
inline

拷贝构造函数/Copy constructor

Parameters
other另一个采样器/Other sampler

◆ sampler_t() [2/2]

template<typename PolicyT = sequential_policy_t>
toolbox::io::sampler_t< PolicyT >::sampler_t ( std::size_t  dataset_size,
PolicyT  policy = PolicyT {} 
)
inlineexplicit

构造函数/Constructor

Parameters
dataset_size数据集大小/Dataset size
policy采样策略/Sampling policy

Member Function Documentation

◆ has_next()

template<typename PolicyT = sequential_policy_t>
bool toolbox::io::sampler_t< PolicyT >::has_next ( ) const
inlinenoexcept

是否还有下一个索引/Whether there are more indices

Returns
如果还有未采样索引则为true/True if there are more indices to sample
while (sampler.has_next()) {
auto idx = sampler.next();
}

◆ next()

template<typename PolicyT = sequential_policy_t>
index_type toolbox::io::sampler_t< PolicyT >::next ( )
inline

获取下一个索引/Get the next index

Returns
下一个索引/Next index
if (sampler.has_next()) {
auto idx = sampler.next();
}

◆ next_batch()

template<typename PolicyT = sequential_policy_t>
std::vector< index_type > toolbox::io::sampler_t< PolicyT >::next_batch ( std::size_t  batch_size)
inline

获取批量索引/Get a batch of indices

Parameters
batch_size批量大小/Batch size
Returns
批量索引数组/Batch of indices
auto batch = sampler.next_batch(4);

◆ operator=()

template<typename PolicyT = sequential_policy_t>
sampler_t & toolbox::io::sampler_t< PolicyT >::operator= ( const sampler_t< PolicyT > &  other)
inline

拷贝赋值操作符/Copy assignment operator

Parameters
other另一个采样器/Other sampler
Returns
当前采样器引用/Reference to this sampler

◆ reset()

template<typename PolicyT = sequential_policy_t>
void toolbox::io::sampler_t< PolicyT >::reset ( )
inline

重置索引并重新应用策略/Reset indices and reapply policy

重新生成索引并应用采样策略/Regenerates indices and applies sampling policy

sampler_t<> sampler(10);
sampler.reset(); // 重新洗牌/Reshuffle or reorder

The documentation for this class was generated from the following file: