![]() |
fpmas 1.6
|
Classes | |
class | ConstantDistribution |
class | DiscreteDistribution |
class | DistributedGenerator |
class | DistributedGenerator< random_device > |
class | Distribution |
class | Generator |
class | Generator< std::random_device > |
class | Index |
class | UniformRandomBitGenerator |
Typedefs | |
template<typename IntType = int> | |
using | UniformIntDistribution = Distribution< std::uniform_int_distribution< IntType > > |
template<typename FloatType = double> | |
using | UniformRealDistribution = Distribution< std::uniform_real_distribution< FloatType > > |
typedef Distribution< std::bernoulli_distribution > | BernoulliDistribution |
template<typename IntType = unsigned int> | |
using | BinomialDistribution = Distribution< std::binomial_distribution< IntType > > |
template<typename FloatType = double> | |
using | NormalDistribution = Distribution< std::normal_distribution< FloatType > > |
template<typename IntType = int> | |
using | PoissonDistribution = Distribution< std::poisson_distribution< IntType > > |
typedef Generator< std::mt19937 > | mt19937 |
typedef Generator< std::mt19937_64 > | mt19937_64 |
typedef Generator< std::minstd_rand > | minstd_rand |
typedef Generator< std::random_device > | random_device |
typedef Index< int > | DistributedIndex |
Functions | |
template<typename Gen , class CharT , class Traits > | |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &ost, const Generator< Gen > &g) |
template<typename Gen , class CharT , class Traits > | |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &ost, Generator< Gen > &g) |
template<class CharT , class Traits > | |
std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &ost, const Generator< std::random_device > &) |
template<class CharT , class Traits > | |
std::basic_istream< CharT, Traits > & | operator>> (std::basic_istream< CharT, Traits > &ost, Generator< std::random_device > &) |
template<typename T , typename Generator_t > | |
std::vector< T > | local_choices (const std::vector< T > &local_items, std::size_t n, Generator_t &gen) |
template<typename T > | |
std::vector< T > | local_choices (const std::vector< T > &local_items, std::size_t n) |
template<typename T > | |
std::vector< std::vector< T > > | distributed_choices (api::communication::MpiCommunicator &comm, const std::vector< T > &local_items, std::size_t n) |
template<typename T > | |
std::vector< T > | split_choices (api::communication::MpiCommunicator &comm, const std::vector< T > &local_items, std::size_t n) |
template<typename T , typename Generator_t > | |
std::vector< T > | local_sample (const std::vector< T > &local_items, std::size_t n, Generator_t &gen) |
template<typename T > | |
std::vector< T > | local_sample (const std::vector< T > &local_items, std::size_t n) |
template<typename Index_t , typename Generator_t > | |
std::vector< Index_t > | sample_indexes (Index_t begin, Index_t end, std::size_t n, Generator_t &gen) |
template<typename T > | |
std::vector< std::vector< T > > | distributed_sample (api::communication::MpiCommunicator &comm, const std::vector< T > &local_items, std::size_t n) |
template<typename T > | |
std::vector< T > | split_sample (api::communication::MpiCommunicator &comm, const std::vector< T > &local_items, std::size_t n) |
Variables | |
DistributedGenerator | rd_choices |
const std::mt19937::result_type | default_seed {std::mt19937::default_seed} |
mt19937::result_type | seed {default_seed} |
fpmas::api::random implementations
using fpmas::random::UniformIntDistribution = typedef Distribution<std::uniform_int_distribution<IntType> > |
Predefined UniformIntDistribution.
using fpmas::random::UniformRealDistribution = typedef Distribution<std::uniform_real_distribution<FloatType> > |
Predefined UniformRealDistribution.
typedef Distribution<std::bernoulli_distribution> fpmas::random::BernoulliDistribution |
Predefined BernoulliDistribution.
using fpmas::random::BinomialDistribution = typedef Distribution<std::binomial_distribution<IntType> > |
Predefined BinomialDistribution.
using fpmas::random::NormalDistribution = typedef Distribution<std::normal_distribution<FloatType> > |
Predefined NormalDistribution.
using fpmas::random::PoissonDistribution = typedef Distribution<std::poisson_distribution<IntType> > |
Predefined PoissonDistribution.
typedef Generator<std::mt19937> fpmas::random::mt19937 |
Predefined mt19937 engine.
typedef Generator<std::mt19937_64> fpmas::random::mt19937_64 |
Predefined mt19937_64 engine.
typedef Generator<std::minstd_rand> fpmas::random::minstd_rand |
Predefined minstd_rand engine.
typedef Generator<std::random_device> fpmas::random::random_device |
Predefined random_device engine.
typedef Index<int> fpmas::random::DistributedIndex |
Represents a continuous index distributed across processes.
A distributed index is represented as a (process, local_offset)
pair. Processes are indexed from 0
to p-1
. Each process is assigned to a given number of items n_p
.
The sequence of values iterated by the index is as all processes items were iterated in a single sequence, from process 0
to p-1
:
The interest of this structure is that local offsets associated to a process p
can for exemple be used as indexes in a vector hosted by the process p
.
std::basic_ostream< CharT, Traits > & fpmas::random::operator<< | ( | std::basic_ostream< CharT, Traits > & | ost, |
const Generator< Gen > & | g | ||
) |
Serializes the specified generator to an output stream.
The implementation is directly based on the C++11 standard RandomNumberEngine operator<< specification.
std::basic_istream< CharT, Traits > & fpmas::random::operator>> | ( | std::basic_istream< CharT, Traits > & | ost, |
Generator< Gen > & | g | ||
) |
Unserializes a generator from an input stream.
The produced generator continues to generate its random number sequence from the state it had when serialized.
The implementation is directly based on the C++11 standard RandomNumberEngine operator>> specification.
std::basic_ostream< CharT, Traits > & fpmas::random::operator<< | ( | std::basic_ostream< CharT, Traits > & | ost, |
const Generator< std::random_device > & | |||
) |
random_device specialization of the generator output stream operator.
Does not need to serialize anything.
std::basic_istream< CharT, Traits > & fpmas::random::operator>> | ( | std::basic_istream< CharT, Traits > & | ost, |
Generator< std::random_device > & | |||
) |
random_device specialization of the generator input stream operator.
Does not need to unserialize anything.
std::vector< T > fpmas::random::local_choices | ( | const std::vector< T > & | local_items, |
std::size_t | n, | ||
Generator_t & | gen | ||
) |
Randomly selects n
elements from the local_items
, with replacement. In consequence, n
can be greater than the number of elements of local_items
.
A case of interest occurs when the local_items
are the same on all processes. If the provided random number generator is sequential, the same choices are performed on all processes (provided that generators are in the same state on each process). If the generator is distributed, different choices are performed on each process.
local_items | local items from which random choices should be made |
n | number of items to chose |
gen | random number generator |
std::vector< T > fpmas::random::local_choices | ( | const std::vector< T > & | local_items, |
std::size_t | n | ||
) |
Same as local_choices(const std::vector<T>&, std::size_t, Generator_t), but uses the predefined rd_choices distributed generator instead.
Different choices are performed on all processes, even if the local_items are the same.
The rd_choices instance can be seeded with the fpmas::seed() method.
std::vector< std::vector< T > > fpmas::random::distributed_choices | ( | api::communication::MpiCommunicator & | comm, |
const std::vector< T > & | local_items, | ||
std::size_t | n | ||
) |
Randomly selects n
items from all local_items
specified on all processes, with replacement.
A set of n
choices is built independently on each process.
Distinct local_items
lists of any size can be specified on each process. n
items are returned independently on each process, so different values of n
can be specified on each process.
The elements are selected as if choices where performed locally on a list representing the concatenation of all local_items
specified on all processes.
This method performs collective communications within the specified MPI communicator. In consequence, the method must be called from all processes.
The complete item list is never centralized, in order to limit communications and memory usage.
Results are returned in an std::vector v
of size comm.getSize()
, such that v[i]
contains items selected from process i
.
std::vector<T> choices = std::accumulate(v.begin(), v.end(), std::vector<T>(), fpmas::utils::Concat())
.comm | MPI communicator |
local_items | local items provided by the current process |
n | local number of items to select from all items (might be different on all processes) |
n
, selected from all the processes. std::vector< T > fpmas::random::split_choices | ( | api::communication::MpiCommunicator & | comm, |
const std::vector< T > & | local_items, | ||
std::size_t | n | ||
) |
Randomly selects n
items from all local_items
specified on all processes, with replacement.
Contrary to distributed_choices(), a single choices list of size n
is built across processes. Return values correspond to the subset of values selected on the current process, so that all returned items are contained in local_items
and n
items are chosen in total.
In consequence, the specified n
must be the same on all processes.
This method performs collective communications within the specified MPI communicator. In consequence, the method must be called from all processes.
The complete item list is never centralized, in order to limit communications and memory usage.
comm | MPI communicator |
local_items | local items provided by the current process |
n | local number of items to select from all items (must be the same on all processes) |
n
selected from all local_items
. std::vector< T > fpmas::random::local_sample | ( | const std::vector< T > & | local_items, |
std::size_t | n, | ||
Generator_t & | gen | ||
) |
Randomly selects n
elements from the local_items
, without replacement. If n
is greater that the number of elements of local_items
, all items are returned (and the size of the sample is less than n
).
A case of interest occurs when the local_items
are the same on all processes. If the provided random number generator is sequential, the same sample is built on all processes (provided that generators are in the same state on each process). If the generator is distributed, different samples are built on each process.
local_items | local items from which random choices should be made |
n | number of items to chose |
gen | random number generator |
std::vector< T > fpmas::random::local_sample | ( | const std::vector< T > & | local_items, |
std::size_t | n | ||
) |
Same as local_sample(const std::vector<T>&, std::size_t, Generator_t), but uses the predefined rd_choices distributed generator instead.
Different samples are built on all processes, even if the local_items are the same.
The rd_choices instance can be seeded with the fpmas::seed() method.
std::vector< Index_t > fpmas::random::sample_indexes | ( | Index_t | begin, |
Index_t | end, | ||
std::size_t | n, | ||
Generator_t & | gen | ||
) |
Algorithm used to build a sample of generic indexes, without replacement.
Index_t
can be anything that fulfill the following requirements:
Index_t
is CopyConstructibleindex
, index++
and ++index
are valid expressions and correspond to the expected behaviors.i1
and i2
, i1!=i2
and i1==i2
is valid.index=begin
, successively applying index++
necessarily reaches a point were index!=end
is false
(and index==end
is true
). The behavior of applying index++ when index==end
is however not specified.Indexes are randomly selected in the range [begin, end)
. n
is assumed to be less than or equal to the number of items in the [begin, end)
range.
This algorithm can be used to generate the same sample on all processes if n
and the specified [begin, end)
range are the same on all processes, and the specified sequential random number generator is in the same state on all processes.
begin | range start, included in the selection |
end | range end, not included in the selection |
n | sample size (must be the same on all processes) |
gen | random number generator |
n
Index_t | (automatically deduced) an abstract index type that support increment. Returned indexes are a sample of indexes selected in [begin, end) . Such indexes can for example be used to retrieve items in a local vector to actually build a sample from the selected indexes. Index_t could also represent some discrete grid coordinates for example. |
Generator_t | (automatically deduced) type of random generator |
std::vector< std::vector< T > > fpmas::random::distributed_sample | ( | api::communication::MpiCommunicator & | comm, |
const std::vector< T > & | local_items, | ||
std::size_t | n | ||
) |
Randomly selects n
items from all local_items
specified on all processes, without replacement.
A sample of size n
is built independently on each process.
Distinct local_items
lists of any size can be specified on each process. n
items are returned independently on each process, so different values of n
can be specified on each process.
The elements are selected as if the sample was built locally from a list representing the concatenation of all local_items
specified on all processes.
This method performs collective communications within the specified MPI communicator. In consequence, the method must be called from all processes.
The complete item list is never centralized, in order to limit communications and memory usage.
Results are returned in an std::vector v
of size comm.getSize()
, such that v[i]
contains items selected from process i
.
std::vector<T> sample = std::accumulate(v.begin(), v.end(), std::vector<T>(), fpmas::utils::Concat())
.comm | MPI communicator |
local_items | local items provided by the current process |
n | local number of items to select from all items (might be different on all processes) |
n
, selected from all the processes. std::vector< T > fpmas::random::split_sample | ( | api::communication::MpiCommunicator & | comm, |
const std::vector< T > & | local_items, | ||
std::size_t | n | ||
) |
Randomly selects n
items from all local_items
specified on all processes, without replacement.
Contrary to distributed_sample(), a single sample of size n
is built across processes. Returned values correspond to the subset of values selected on the current process, so that all returned items are contained in local_items
and n
items are chosen in total.
In consequence, the specified n
must be the same on all processes. If n
is greater than the total count of items on all processes, all items are selected, so all items from the local_items
list are returned on each process in this context.
This can be useful in the Agent context to build a global agent sample:
This method performs collective communications within the specified MPI communicator. In consequence, the method must be called from all processes.
The complete item list is never centralized, in order to limit communications and memory usage.
comm | MPI communicator |
local_items | local items provided by the current process |
n | number of items to select from all items (must be the same on all processes) |
n
selected from all local_items
. DistributedGenerator fpmas::random::rd_choices |
A predefined distributed random number generator used by choice and sampling algorithms.
const std::mt19937::result_type fpmas::random::default_seed {std::mt19937::default_seed} |
The default seed passed to fpmas::seed() when fpmas::init() is called.
fpmas::random::mt19937::result_type fpmas::random::seed {default_seed} |
The seed currently in use by FPMAS.
Must be initialized by fpmas::seed(), otherwise default_seed is used.