ʻOhana
Population structure, admixture history, and selection using learning methods.
Public Types | Public Member Functions
jade::basic_randomizer< TValue > Class Template Reference

A template for a class that randomizes matrices. More...

#include <jade.randomizer.hpp>

+ Inheritance diagram for jade::basic_randomizer< TValue >:
+ Collaboration diagram for jade::basic_randomizer< TValue >:

Public Types

typedef TValue value_type
 The value type. More...
 
typedef basic_matrix< value_typematrix_type
 The matrix type. More...
 
typedef basic_verification< value_typeverification_type
 The verification type. More...
 

Public Member Functions

 basic_randomizer ()
 Initializes a new instance of the class. More...
 
std::default_random_engine & get_engine ()
 
matrix_type randomize_f (const size_t K, const matrix_type &mu)
 
matrix_type randomize_f (const size_t K, const matrix_type &mu, const matrix_type &fif)
 
matrix_type randomize_q (const size_t I, const size_t K)
 

Detailed Description

template<typename TValue>
class jade::basic_randomizer< TValue >

A template for a class that randomizes matrices.

Definition at line 19 of file jade.randomizer.hpp.

Member Typedef Documentation

◆ matrix_type

template<typename TValue >
typedef basic_matrix<value_type> jade::basic_randomizer< TValue >::matrix_type

The matrix type.

Definition at line 26 of file jade.randomizer.hpp.

◆ value_type

template<typename TValue >
typedef TValue jade::basic_randomizer< TValue >::value_type

The value type.

Definition at line 23 of file jade.randomizer.hpp.

◆ verification_type

template<typename TValue >
typedef basic_verification<value_type> jade::basic_randomizer< TValue >::verification_type

The verification type.

Definition at line 29 of file jade.randomizer.hpp.

Constructor & Destructor Documentation

◆ basic_randomizer()

template<typename TValue >
jade::basic_randomizer< TValue >::basic_randomizer ( )
inline

Initializes a new instance of the class.

Definition at line 34 of file jade.randomizer.hpp.

35  : _engine ()
36  {
37  }

Member Function Documentation

◆ get_engine()

template<typename TValue >
std::default_random_engine& jade::basic_randomizer< TValue >::get_engine ( )
inline
Returns
The random number engine.

Definition at line 42 of file jade.randomizer.hpp.

43  {
44  return _engine;
45  }
+ Here is the caller graph for this function:

◆ randomize_f() [1/2]

template<typename TValue >
matrix_type jade::basic_randomizer< TValue >::randomize_f ( const size_t  K,
const matrix_type mu 
)
inline
Returns
A random F matrix.
Parameters
KThe component count.
muThe mu vector.

Definition at line 50 of file jade.randomizer.hpp.

53  {
54  static const auto sigma = value_type(0.1);
55  static const auto epsilon = value_type(1.0e-6);
56  static const auto min = value_type(0.0) + epsilon;
57  static const auto max = value_type(1.0) - epsilon;
58 
59  assert(K > 0);
60  assert(mu.is_column_vector());
61  assert(mu.all_of([](const value_type n)
62  { return n >= min && n <= max; }));
63 
64  const auto J = mu.get_length();
65 
66  matrix_type f (K, J);
67 
68  for (size_t j = 0; j < J; j++)
69  {
70  static std::normal_distribution<value_type>
71  dist (mu[j], sigma);
72 
73  for (size_t k = 0; k < K; k++)
74  f(k, j) = std::min(std::max(
75  min, dist(_engine)), max);
76  }
77 
78  return f;
79  }
+ Here is the caller graph for this function:

◆ randomize_f() [2/2]

template<typename TValue >
matrix_type jade::basic_randomizer< TValue >::randomize_f ( const size_t  K,
const matrix_type mu,
const matrix_type fif 
)
inline
Returns
A random F matrix.
Parameters
KThe component count.
muThe mu vector.
fifThe fin-force matrix.

Definition at line 84 of file jade.randomizer.hpp.

88  {
89  static const auto sigma = value_type(0.1);
90  static const auto epsilon = value_type(1.0e-6);
91  static const auto min = value_type(0.0) + epsilon;
92  static const auto max = value_type(1.0) - epsilon;
93 
94  assert(K > 0);
95  assert(mu.is_column_vector());
96  assert(mu.all_of([](const value_type n)
97  { return n >= min && n <= max; }));
98 
99  const auto J = mu.get_length();
100  assert(verification_type::validate_fif_size(fif, K, J));
101 
102  matrix_type f (K, J);
103 
104  for (size_t j = 0; j < J; j++)
105  {
106  static std::normal_distribution<value_type>
107  dist (mu[j], sigma);
108 
109  for (size_t k = 0; k < fif.get_height(); k++)
110  f(k, j) = fif(k, j);
111 
112  for (size_t k = fif.get_height(); k < K; k++)
113  f(k, j) = std::min(std::max(
114  min, dist(_engine)), max);
115  }
116 
117  return f;
118  }

◆ randomize_q()

template<typename TValue >
matrix_type jade::basic_randomizer< TValue >::randomize_q ( const size_t  I,
const size_t  K 
)
inline
Returns
A random Q matrix.
Parameters
IThe number of individuals.
KThe number of components.

Definition at line 123 of file jade.randomizer.hpp.

126  {
127  static const auto K_0 = value_type(0);
128  static const auto K_1 = value_type(1);
129 
130  static std::uniform_real_distribution<value_type>
131  distribution (K_0, K_1);
132 
133  matrix_type q (I, K);
134 
135  for (size_t i = 0; i < I; i++)
136  {
137  auto sum = K_0;
138  for (size_t k = 0; k < K; k++)
139  sum += (q(i, k) = distribution(_engine));
140 
141  const auto factor = K_1 / sum;
142  for (size_t k = 0; k < K; k++)
143  q(i, k) *= factor;
144  }
145 
146  return q;
147  }
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file:
jade::basic_randomizer::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.randomizer.hpp:26
jade::basic_randomizer::value_type
TValue value_type
The value type.
Definition: jade.randomizer.hpp:23
jade::basic_verification::validate_fif_size
static bool validate_fif_size(const matrix_type &fif, const size_t k, const size_t j)
Validates the size of the Fin-force matrix and throws an exception if validation fails.
Definition: jade.verification.hpp:131