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

A template for a class that performs validation on various types of matrices. More...

#include <jade.verification.hpp>

+ Collaboration diagram for jade::basic_verification< TValue >:

Public Types

typedef TValue value_type
 The value type. More...
 
typedef basic_matrix< value_typematrix_type
 The matrix type. More...
 
typedef basic_genotype_matrix< value_typegenotype_matrix_type
 The genotype matrix type. More...
 

Static Public Member Functions

static bool validate_c (const matrix_type &c)
 Validates the C matrix and throws an exception if validation fails. More...
 
static bool validate_f (const matrix_type &f)
 Validates the F matrix and throws an exception if validation fails. More...
 
static bool validate_fc_sizes (const matrix_type &f, const matrix_type &c)
 Validates the sizes of the F and C matrices and throws an exception if validation fails. More...
 
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. More...
 
static bool validate_g (const genotype_matrix_type &g)
 Validates the G matrix and throws an exception if validation fails. More...
 
static bool validate_gf_sizes (const genotype_matrix_type &g, const matrix_type &f)
 Validates the sizes of the G and F matrices and throws an exception if validation fails. More...
 
static bool validate_gq_sizes (const genotype_matrix_type &g, const matrix_type &q)
 Validates the sizes of the G and Q matrices and throws an exception if validation fails. More...
 
static bool validate_gqf_sizes (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &f)
 Validates the sizes of the G, Q, and F matrices and throws an exception if validation fails. More...
 
static bool validate_q (const matrix_type &q)
 Validates the Q matrix and throws an exception if validation fails. More...
 
static bool validate_qf_sizes (const matrix_type &q, const matrix_type &f)
 Validates the sizes of the Q and F matrices and throws an exception if validation fails. More...
 

Static Public Attributes

static constexpr value_type epsilon = value_type(0.000001)
 The epsilon value. More...
 

Detailed Description

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

A template for a class that performs validation on various types of matrices.

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

Member Typedef Documentation

◆ genotype_matrix_type

template<typename TValue >
typedef basic_genotype_matrix<value_type> jade::basic_verification< TValue >::genotype_matrix_type

The genotype matrix type.

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

◆ matrix_type

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

The matrix type.

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

◆ value_type

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

The value type.

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

Member Function Documentation

◆ validate_c()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_c ( const matrix_type c)
inlinestatic

Validates the C matrix and throws an exception if validation fails.

Returns
True.
Parameters
cThe C matrix to validate.

Definition at line 38 of file jade.verification.hpp.

40  {
41  if (!c.is_square())
42  throw error() << "invalid C matrix size " << c.get_size_str()
43  << " is not square";
44 
45  const auto rk = c.get_height();
46  if (0 == rk)
47  throw error() << "invalid C matrix size " << c.get_size_str()
48  << " does not contain any components";
49 
50  for (size_t y = 0; y < rk; y++)
51  for (size_t x = y + 1; x < rk; x++)
52  if (std::fabs(c(y, x) - c(x, y)) > epsilon)
53  throw error()
54  << "invalid C matrix cell [" << y+1 << ","
55  << x+1 << "] (" << c(y, x)
56  << ") is not equal to symmetric cell ["
57  << x+1 << "," << y+1 << "] (" << c(x, y) << ")";
58 
59 
60  // Create a copy of C before LAPACK replaces it with the
61  // Cholesky square root and then its inverse.
62  matrix_type cholesky (c);
63  if (!cholesky.potrf_lower() || !cholesky.potri_lower())
64  throw error("invalid C matrix is not positive semidefinite");
65 
66  return true;
67  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_f()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_f ( const matrix_type f)
inlinestatic

Validates the F matrix and throws an exception if validation fails.

Returns
True.
Parameters
fThe F matrix to validate.

Definition at line 73 of file jade.verification.hpp.

75  {
76  static const auto epsilon = value_type(1.0e-6);
77  static const auto min = value_type(0.0) + epsilon;
78  static const auto max = value_type(1.0) - epsilon;
79 
80  const auto K = f.get_height();
81  const auto J = f.get_width();
82 
83  if (0 == K)
84  throw error() << "invalid F matrix size " << f.get_size_str()
85  << " does not contain any components";
86 
87  if (0 == J)
88  throw error() << "invalid F matrix size " << f.get_size_str()
89  << " does not contain any markers";
90 
91  for (size_t k = 0; k < K; k++)
92  {
93  for (size_t j = 0; j < J; j++)
94  {
95  const auto f_kj = f(k, j);
96 
97  if (f_kj >= min && f_kj <= max)
98  continue;
99 
100  throw error()
101  << "invalid F matrix cell [" << k+1 << "," << j+1
102  << "] (" << f_kj << ") is not between 0 and 1";
103  }
104  }
105 
106  return true;
107  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_fc_sizes()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_fc_sizes ( const matrix_type f,
const matrix_type c 
)
inlinestatic

Validates the sizes of the F and C matrices and throws an exception if validation fails.

Returns
True.
Parameters
fThe F matrix to validate.
cThe C matrix to validate.

Definition at line 114 of file jade.verification.hpp.

117  {
118  if (f.get_height() != c.get_height() + 1)
119  throw error()
120  << "inconsistent F matrix size " << f.get_size_str()
121  << " and C matrix size " << c.get_size_str();
122 
123  return true;
124  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_fif_size()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_fif_size ( const matrix_type fif,
const size_t  k,
const size_t  j 
)
inlinestatic

Validates the size of the Fin-force matrix and throws an exception if validation fails.

Returns
True.
Parameters
fifThe Fin-force matrix.
kThe component count.
jThe marker count.

Definition at line 131 of file jade.verification.hpp.

135  {
136  const auto fif_height = fif.get_height();
137  const auto fif_width = fif.get_width();
138 
139  if (fif_width != j)
140  throw error()
141  << "inconsistent marker count (" << j
142  << ") and width of matrix specified for --fin-force "
143  << "option (" << fif_width << ")";
144 
145  if (fif_height >= k)
146  throw error()
147  << "inconsistent component count (" << k << ") and "
148  << "height of matrix specified for --fin-force "
149  << "option (" << fif_height << ")";
150 
151  return true;
152  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_g()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_g ( const genotype_matrix_type g)
inlinestatic

Validates the G matrix and throws an exception if validation fails.

Returns
True.
Parameters
gThe G matrix to validate.

Definition at line 158 of file jade.verification.hpp.

160  {
161  if (0 == g.get_height())
162  throw error() << "invalid G matrix size " << g.get_size_str()
163  << " does not contain any individuals";
164 
165  if (0 == g.get_width())
166  throw error() << "invalid G matrix size " << g.get_size_str()
167  << " does not contain any markers";
168 
169  return true;
170  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_gf_sizes()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_gf_sizes ( const genotype_matrix_type g,
const matrix_type f 
)
inlinestatic

Validates the sizes of the G and F matrices and throws an exception if validation fails.

Returns
True.
Parameters
gThe G matrix to validate.
fThe F matrix to validate.

Definition at line 177 of file jade.verification.hpp.

180  {
181  if (g.get_width() != f.get_width())
182  throw error()
183  << "inconsistent G matrix size " << g.get_size_str()
184  << " and F matrix size " << f.get_size_str();
185 
186  return true;
187  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_gq_sizes()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_gq_sizes ( const genotype_matrix_type g,
const matrix_type q 
)
inlinestatic

Validates the sizes of the G and Q matrices and throws an exception if validation fails.

Returns
True.
Parameters
gThe G matrix to validate.
qThe Q matrix to validate.

Definition at line 194 of file jade.verification.hpp.

197  {
198  if (g.get_height() != q.get_height())
199  throw error()
200  << "inconsistent G matrix size " << g.get_size_str()
201  << " and Q matrix size " << q.get_size_str();
202 
203  return true;
204  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_gqf_sizes()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_gqf_sizes ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type f 
)
inlinestatic

Validates the sizes of the G, Q, and F matrices and throws an exception if validation fails.

Returns
True.
Parameters
gThe G matrix to validate.
qThe Q matrix to validate.
fThe F matrix to validate.

Definition at line 211 of file jade.verification.hpp.

215  {
216  return validate_gq_sizes(g, q)
217  && validate_gf_sizes(g, f)
218  && validate_qf_sizes(q, f);
219  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_q()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_q ( const matrix_type q)
inlinestatic

Validates the Q matrix and throws an exception if validation fails.

Returns
True.
Parameters
qThe Q matrix to validate.

Definition at line 225 of file jade.verification.hpp.

227  {
228  const auto I = q.get_height();
229  const auto K = q.get_width();
230 
231  if (0 == I)
232  throw error() << "invalid Q matrix size " << q.get_size_str()
233  << " does not contain any individuals";
234 
235  if (0 == K)
236  throw error() << "invalid Q matrix size " << q.get_size_str()
237  << " does not contain any components";
238 
239  for (size_t i = 0; i < I; i++)
240  {
241  auto sum = value_type(0);
242 
243  for (size_t k = 0; k < K; k++)
244  {
245  const auto q_ik = q(i, k);
246 
247  if (q_ik < value_type(0) || q_ik > value_type(1))
248  throw error()
249  << "invalid Q matrix cell [" << i+1 << "," << k+1
250  << "] (" << q_ik << ") is not between 0 and 1";
251 
252  sum += q_ik;
253  }
254 
255  if (std::fabs(sum - value_type(1)) > epsilon)
256  throw error() << "invalid Q matrix row " << i+1
257  << " does not sum to 1 (" << sum << ")";
258  }
259 
260  return true;
261  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ validate_qf_sizes()

template<typename TValue >
static bool jade::basic_verification< TValue >::validate_qf_sizes ( const matrix_type q,
const matrix_type f 
)
inlinestatic

Validates the sizes of the Q and F matrices and throws an exception if validation fails.

Returns
True.
Parameters
qThe Q matrix to validate.
fThe F matrix to validate.

Definition at line 268 of file jade.verification.hpp.

271  {
272  if (q.get_width() != f.get_height())
273  throw error()
274  << "inconsistent Q matrix size " << q.get_size_str()
275  << " and F matrix size " << f.get_size_str();
276 
277  return true;
278  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ epsilon

template<typename TValue >
constexpr value_type jade::basic_verification< TValue >::epsilon = value_type(0.000001)
staticconstexpr

The epsilon value.

Definition at line 32 of file jade.verification.hpp.


The documentation for this class was generated from the following file:
jade::basic_verification::epsilon
static constexpr value_type epsilon
The epsilon value.
Definition: jade.verification.hpp:32
jade::basic_verification::value_type
TValue value_type
The value type.
Definition: jade.verification.hpp:23
jade::basic_verification::validate_qf_sizes
static bool validate_qf_sizes(const matrix_type &q, const matrix_type &f)
Validates the sizes of the Q and F matrices and throws an exception if validation fails.
Definition: jade.verification.hpp:268
jade::basic_verification::validate_gf_sizes
static bool validate_gf_sizes(const genotype_matrix_type &g, const matrix_type &f)
Validates the sizes of the G and F matrices and throws an exception if validation fails.
Definition: jade.verification.hpp:177
jade::basic_verification::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.verification.hpp:26
jade::basic_verification::validate_gq_sizes
static bool validate_gq_sizes(const genotype_matrix_type &g, const matrix_type &q)
Validates the sizes of the G and Q matrices and throws an exception if validation fails.
Definition: jade.verification.hpp:194