Skip to content

File misc.hpp

FileList > epiworld > misc.hpp

Go to the source code of this file

Classes

Type Name
struct vecHasher <typename T>
Vector hasher.

Public Types

Type Name
typedef std::unordered_map< std::vector< Ta >, Tb, vecHasher< Ta > > MapVec_type

Public Functions

Type Name
bool IN (const Ta & a, const std::vector< Ta > & b) noexcept
Check whether a is included inb __
TSeq default_sequence (int seq_count)
bool default_sequence (int seq_count)
int default_sequence (int seq_count)
epiworld_double default_sequence (int seq_count)
std::vector< bool > default_sequence (int seq_count)
std::vector< int > default_sequence (int seq_count)
std::vector< epiworld_double > default_sequence (int seq_count)
To * model_cast (Model< TSeq > * m)
std::map< std::string, T > read_yaml (std::string fn)
Read parameters from a yaml file.
int roulette (const std::vector< TDbl > & probs, Model< TSeq > * m)
Conditional Weighted Sampling.
int roulette (std::vector< double > & probs, Model< TSeq > * m)
int roulette (std::vector< float > & probs, Model< TSeq > * m)
int roulette (epiworld_fast_uint nelements, Model< TSeq > * m)

Macros

Type Name
define EPI_ASSUME (cond) ((void)0)
Cast a Model pointer to a specific model type.

Public Types Documentation

typedef MapVec_type

using MapVec_type =  std::unordered_map< std::vector< Ta >, Tb, vecHasher<Ta> >;

Public Functions Documentation

function IN

Check whether a is included inb __

template<typename Ta>
inline bool IN (
    const Ta & a,
    const std::vector< Ta > & b
) noexcept

Template parameters:

  • Ta Type of a. Could be int, epiworld_double, etc.

Parameters:

  • a Scalar of class Ta.
  • b Vector std::vector of class Ta.

Returns:

true if a in b, and false otherwise.


function default_sequence

template<typename TSeq>
inline TSeq default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline bool default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline int default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline epiworld_double default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline std::vector< bool > default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline std::vector< int > default_sequence (
    int seq_count
) 

function default_sequence

template<>
inline std::vector< epiworld_double > default_sequence (
    int seq_count
) 

function model_cast

template<class To, class TSeq>
inline To * model_cast (
    Model < TSeq > * m
) 

function read_yaml

Read parameters from a yaml file.

template<typename T>
inline std::map< std::string, T > read_yaml (
    std::string fn
) 

The file should have the following structure:

# Comment
[name of parameter 1]: [value in T]
[name of parameter 2]: [value in T]
...

Template parameters:

  • T Type of the parameter

Parameters:

  • fn Path to the file containing the parameters

Returns:

std::map<std::string, T>


function roulette

Conditional Weighted Sampling.

template<typename TSeq, typename TDbl>
inline int roulette (
    const std::vector< TDbl > & probs,
    Model < TSeq > * m
) 

The sampling function will draw one of {-1, 0,...,probs.size() - 1} in a weighted fashion. The probabilities are drawn given that either one or none of the cases is drawn; in the latter returns -1.

Parameters:

  • probs Vector of probabilities.
  • m A Model. This is used to draw random uniform numbers.

Returns:

int If -1 then it means that none got sampled, otherwise the index of the entry that got drawn.


function roulette

template<typename TSeq>
inline int roulette (
    std::vector< double > & probs,
    Model < TSeq > * m
) 

function roulette

template<typename TSeq>
inline int roulette (
    std::vector< float > & probs,
    Model < TSeq > * m
) 

function roulette

template<typename TSeq>
inline int roulette (
    epiworld_fast_uint nelements,
    Model < TSeq > * m
) 

Macro Definition Documentation

define EPI_ASSUME

Cast a Model pointer to a specific model type.

#define EPI_ASSUME (
    cond
) `((void)0)`



The documentation for this class was generated from the following file epiworld-src/include/epiworld/misc.hpp