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

A template for a class that improves the Q and F matrices. More...

#include <jade.improver.hpp>

+ Collaboration diagram for jade::basic_improver< 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...
 
typedef basic_forced_grouping< value_typeforced_grouping_type
 The forced grouping type. More...
 
typedef basic_verification< value_typeverification_type
 The verification type. More...
 
typedef basic_lemke< value_typelemke_type
 The Lemke type. More...
 
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...
 
typedef basic_forced_grouping< value_typeforced_grouping_type
 The forced grouping type. More...
 
typedef basic_verification< value_typeverification_type
 The verification type. More...
 
typedef basic_qpas< value_typeqpas_type
 The QPAS type. More...
 

Static Public Member Functions

static matrix_type improve_f (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const matrix_type *fif, const bool frb)
 
static matrix_type improve_q (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const forced_grouping_type *fg)
 
static matrix_type improve_f (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const matrix_type *fif, const bool frb)
 
static matrix_type improve_q (const genotype_matrix_type &g, const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const forced_grouping_type *fg)
 

Detailed Description

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

A template for a class that improves the Q and F matrices.

Definition at line 20 of file cpax/jade.improver.hpp.

Member Typedef Documentation

◆ forced_grouping_type [1/2]

template<typename TValue >
typedef basic_forced_grouping<value_type> jade::basic_improver< TValue >::forced_grouping_type

The forced grouping type.

Definition at line 33 of file cpax/jade.improver.hpp.

◆ forced_grouping_type [2/2]

template<typename TValue >
typedef basic_forced_grouping<value_type> jade::basic_improver< TValue >::forced_grouping_type

The forced grouping type.

Definition at line 33 of file qpas/jade.improver.hpp.

◆ genotype_matrix_type [1/2]

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

The genotype matrix type.

Definition at line 30 of file cpax/jade.improver.hpp.

◆ genotype_matrix_type [2/2]

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

The genotype matrix type.

Definition at line 30 of file qpas/jade.improver.hpp.

◆ lemke_type

template<typename TValue >
typedef basic_lemke<value_type> jade::basic_improver< TValue >::lemke_type

The Lemke type.

Definition at line 39 of file cpax/jade.improver.hpp.

◆ matrix_type [1/2]

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

The matrix type.

Definition at line 27 of file cpax/jade.improver.hpp.

◆ matrix_type [2/2]

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

The matrix type.

Definition at line 27 of file qpas/jade.improver.hpp.

◆ qpas_type

template<typename TValue >
typedef basic_qpas<value_type> jade::basic_improver< TValue >::qpas_type

The QPAS type.

Definition at line 39 of file qpas/jade.improver.hpp.

◆ value_type [1/2]

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

The value type.

Definition at line 24 of file cpax/jade.improver.hpp.

◆ value_type [2/2]

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

The value type.

Definition at line 24 of file qpas/jade.improver.hpp.

◆ verification_type [1/2]

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

The verification type.

Definition at line 36 of file cpax/jade.improver.hpp.

◆ verification_type [2/2]

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

The verification type.

Definition at line 36 of file qpas/jade.improver.hpp.

Member Function Documentation

◆ improve_f() [1/2]

template<typename TValue >
static matrix_type jade::basic_improver< TValue >::improve_f ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type fa,
const matrix_type fb,
const matrix_type qfa,
const matrix_type qfb,
const matrix_type fif,
const bool  frb 
)
inlinestatic
Returns
A new-and-improved F matrix.
Parameters
gThe G matrix.
qThe Q matrix.
faThe F matrix.
fbThe 1-F matrix.
qfaThe Q*F matrix.
qfbThe Q*(1-F) matrix.
fifThe Fin-force matrix.
frbUsing frequency-bounds.

Definition at line 44 of file cpax/jade.improver.hpp.

53  {
54  assert(verification_type::validate_gqf_sizes(g, q, fa));
55  assert(verification_type::validate_gqf_sizes(g, q, fb));
58  assert(nullptr == fif || !frb);
59 
60  const auto I = g.get_height();
61  const auto K = fa.get_height();
62  const auto J = fa.get_width();
63  assert(nullptr == fif || verification_type::
64  validate_fif_size(*fif, K, J));
65 
66  matrix_type f_dst (K, J);
67 
68  matrix_type shift_vec (K, 1);
69  shift_vec.set_values(1);
70 
71  matrix_type derivative_vec (K, 1);
72  matrix_type hessian_mat (K, K);
73 
74  const auto frb_delta = value_type(1.0) /
75  (value_type(2 * I) + value_type(1.0));
76 
77  for (size_t j = 0; j < J; j++)
78  {
79  const auto f_column = fa.copy_column(j);
80 
81  g.compute_derivatives_f(
82  q,
83  fa,
84  fb,
85  qfa,
86  qfb,
87  j,
88  derivative_vec,
89  hessian_mat);
90 
91  const auto a_mat = _create_a_mat(K, false);
92 
93  auto b_vec = _create_b_vec(f_column, a_mat, shift_vec, false);
94  if (nullptr != fif)
95  {
96  for (size_t k = 0; k < fif->get_height(); k++)
97  {
98  b_vec[k + 0] = value_type(0);
99  b_vec[k + K] = value_type(0);
100  }
101  }
102  else if (frb)
103  {
104  for (size_t k = 0; k < K; k++)
105  {
106  b_vec[k + 0] -= frb_delta;
107  b_vec[k + K] -= frb_delta;
108  }
109  }
110 
111  const auto sqp_q = -hessian_mat;
112  const auto sqp_a = -a_mat;
113  const auto sqp_c = (hessian_mat * shift_vec) - derivative_vec;
114  const auto sqp_b = -b_vec;
115 
116  matrix_type shifted_delta_vec;
117  if (lemke_type::solve(
118  shifted_delta_vec,
119  sqp_q, // shifted QP's "Q" matrix
120  sqp_a, // shifted QP's "A" matrix
121  sqp_c, // shifted QP's "c" vector
122  sqp_b)) // shifted QP's "b" vector
123  {
124  assert(shifted_delta_vec.get_height() == 3 * K);
125  for (size_t k = 0; k < K; k++)
126  f_dst(k, j) = f_column[k]
127  + shifted_delta_vec[k]
128  - value_type(1);
129  }
130  else
131  {
132  for (size_t k = 0; k < K; k++)
133  f_dst(k, j) = f_column[k];
134  }
135  }
136 
137  return f_dst;
138  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ improve_f() [2/2]

template<typename TValue >
static matrix_type jade::basic_improver< TValue >::improve_f ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type fa,
const matrix_type fb,
const matrix_type qfa,
const matrix_type qfb,
const matrix_type fif,
const bool  frb 
)
inlinestatic
Returns
A new-and-improved F matrix.
Parameters
gThe G matrix.
qThe Q matrix.
faThe F matrix.
fbThe 1-F matrix.
qfaThe Q*F matrix.
qfbThe Q*(1-F) matrix.
fifThe Fin-force matrix.
frbUsing frequency-bounds.

Definition at line 44 of file qpas/jade.improver.hpp.

53  {
54  assert(verification_type::validate_gqf_sizes(g, q, fa));
55  assert(verification_type::validate_gqf_sizes(g, q, fb));
58  assert(nullptr == fif || !frb);
59 
60  const auto I = g.get_height();
61  const auto K = fa.get_height();
62  const auto J = fa.get_width();
63  assert(nullptr == fif || verification_type::
64  validate_fif_size(*fif, K, J));
65 
66  matrix_type f_dst (K, J);
67 
68  static const std::vector<size_t> fixed_active_set;
69 
70  matrix_type derivative_vec (K, 1);
71  matrix_type hessian_mat (K, K);
72 
73  const auto frb_delta = value_type(1.0) /
74  (value_type(2 * I) + value_type(1.0));
75 
76  for (size_t j = 0; j < J; j++)
77  {
78  const auto f_column = fa.copy_column(j);
79 
80  g.compute_derivatives_f(
81  q,
82  fa,
83  fb,
84  qfa,
85  qfb,
86  j,
87  derivative_vec,
88  hessian_mat);
89 
90  const auto coefficients_mat = _create_coefficients_mat(K, 0);
91 
92  auto b_vec = _create_b_vec(f_column, 0);
93  if (nullptr != fif)
94  {
95  for (size_t k = 0; k < fif->get_height(); k++)
96  {
97  b_vec[k + 0] = value_type(0);
98  b_vec[k + K] = value_type(0);
99  }
100  }
101  else if (frb)
102  {
103  for (size_t k = 0; k < K; k++)
104  {
105  b_vec[k + 0] -= frb_delta;
106  b_vec[k + K] -= frb_delta;
107  }
108  }
109 
110  std::vector<size_t> active_set { 0 };
111  matrix_type delta_vec (K, 1);
112  delta_vec[0] = -b_vec[0];
113 
115  b_vec,
116  coefficients_mat,
117  hessian_mat,
118  derivative_vec,
119  fixed_active_set,
120  active_set,
121  delta_vec);
122 
123  for (size_t k = 0; k < K; k++)
124  f_dst(k, j) = f_column[k] + delta_vec[k];
125  }
126 
127  return f_dst;
128  }
+ Here is the call graph for this function:

◆ improve_q() [1/2]

template<typename TValue >
static matrix_type jade::basic_improver< TValue >::improve_q ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type fa,
const matrix_type fb,
const matrix_type qfa,
const matrix_type qfb,
const forced_grouping_type fg 
)
inlinestatic
Returns
A new-and-improved Q matrix.
Parameters
gThe G matrix.
qThe Q matrix.
faThe F matrix.
fbThe 1-F matrix.
qfaThe Q*F matrix.
qfbThe Q*(1-F) matrix.
fgThe force-grouping.

Definition at line 143 of file cpax/jade.improver.hpp.

151  {
152  assert(verification_type::validate_gqf_sizes(g, q, fa));
153  assert(verification_type::validate_gqf_sizes(g, q, fb));
155  assert(verification_type::validate_f(fa));
156 
157  const auto I = q.get_height();
158  const auto K = q.get_width();
159 
160  matrix_type q_dst (I, K);
161 
162  matrix_type shift_vec (K, 1);
163  shift_vec.set_values(1);
164 
165  matrix_type derivative_vec (K, 1);
166  matrix_type hessian_mat (K, K);
167 
168  for (size_t i = 0; i < I; i++)
169  {
170  const auto q_row = q.copy_row(i);
171 
172  g.compute_derivatives_q(
173  q,
174  fa,
175  fb,
176  qfa,
177  qfb,
178  i,
179  derivative_vec,
180  hessian_mat);
181 
182  const auto a_mat = _create_a_mat(K, true);
183 
184  auto b_vec = _create_b_vec(q_row, a_mat, shift_vec, true);
185  if (nullptr != fg)
186  {
187  for (size_t k = 0; k < K; k++)
188  {
189  b_vec[k + 0] -= fg->get_min(i, k);
190  b_vec[k + K] += fg->get_max(i, k) - value_type(1);
191  }
192  }
193 
194  const auto sqp_q = -hessian_mat;
195  const auto sqp_a = -a_mat;
196  const auto sqp_c = (hessian_mat * shift_vec) - derivative_vec;
197  const auto sqp_b = -b_vec;
198 
199  matrix_type shifted_delta_vec;
200  if (lemke_type::solve(
201  shifted_delta_vec,
202  sqp_q, // shifted QP's "Q" matrix
203  sqp_a, // shifted QP's "A" matrix
204  sqp_c, // shifted QP's "c" vector
205  sqp_b)) // shifted QP's "b" vector
206  {
207  assert(shifted_delta_vec.get_height() == 3 * K);
208  for (size_t k = 0; k < K; k++)
209  q_dst(i, k) = q_row[k]
210  + shifted_delta_vec[k]
211  - value_type(1);
212  }
213  else
214  {
215  for (size_t k = 0; k < K; k++)
216  q_dst(i, k) = q_row[k];
217  }
218 
219  static const auto epsilon = value_type(1.0e-6);
220  static const auto min = value_type(0.0) + epsilon;
221  static const auto max = value_type(1.0) - epsilon;
222  q_dst.clamp_row(i, min, max);
223 
224  const auto sum = q_dst.get_row_sum(i);
225  q_dst.multiply_row(i, value_type(1) / sum);
226  }
227 
228  return q_dst;
229  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ improve_q() [2/2]

template<typename TValue >
static matrix_type jade::basic_improver< TValue >::improve_q ( const genotype_matrix_type g,
const matrix_type q,
const matrix_type fa,
const matrix_type fb,
const matrix_type qfa,
const matrix_type qfb,
const forced_grouping_type fg 
)
inlinestatic
Returns
A new-and-improved Q matrix.
Parameters
gThe G matrix.
qThe Q matrix.
faThe F matrix.
fbThe 1-F matrix.
qfaThe Q*F matrix.
qfbThe Q*(1-F) matrix.
fgThe force-grouping.

Definition at line 133 of file qpas/jade.improver.hpp.

141  {
142  assert(verification_type::validate_gqf_sizes(g, q, fa));
143  assert(verification_type::validate_gqf_sizes(g, q, fb));
145  assert(verification_type::validate_f(fa));
146 
147  const auto I = q.get_height();
148  const auto K = q.get_width();
149 
150  matrix_type q_dst (I, K);
151 
152  const std::vector<size_t> fixed_active_set { K + K };
153 
154  matrix_type derivative_vec (K, 1);
155  matrix_type hessian_mat (K, K);
156 
157  for (size_t i = 0; i < I; i++)
158  {
159  const auto q_row = q.copy_row(i);
160 
161  g.compute_derivatives_q(
162  q,
163  fa,
164  fb,
165  qfa,
166  qfb,
167  i,
168  derivative_vec,
169  hessian_mat);
170 
171  const auto coefficients_mat = _create_coefficients_mat(K, 1);
172 
173  auto b_vec = _create_b_vec(q_row, 1);
174  if (nullptr != fg)
175  {
176  for (size_t k = 0; k < K; k++)
177  {
178  b_vec[k + 0] -= fg->get_min(i, k);
179  b_vec[k + K] += fg->get_max(i, k) - value_type(1);
180  }
181  }
182 
183  std::vector<size_t> active_set { 0 };
184  matrix_type delta_vec (K, 1);
185  delta_vec[0] = -b_vec[0];
186 
188  b_vec,
189  coefficients_mat,
190  hessian_mat,
191  derivative_vec,
192  fixed_active_set,
193  active_set,
194  delta_vec);
195 
196  for (size_t k = 0; k < K; k++)
197  q_dst(i, k) = q_row[k] + delta_vec[k];
198 
199  static const auto epsilon = value_type(1.0e-6);
200  static const auto min = value_type(0.0) + epsilon;
201  static const auto max = value_type(1.0) - epsilon;
202  q_dst.clamp_row(i, min, max);
203 
204  const auto sum = q_dst.get_row_sum(i);
205  q_dst.multiply_row(i, value_type(1) / sum);
206  }
207 
208  return q_dst;
209  }
+ Here is the call graph for this function:

The documentation for this class was generated from the following file:
jade::basic_lemke::solve
bool solve()
Executes the algorithm until it has completed or has aborted.
Definition: jade.lemke.hpp:256
jade::basic_improver::value_type
TValue value_type
The value type.
Definition: cpax/jade.improver.hpp:24
jade::basic_verification::validate_f
static bool validate_f(const matrix_type &f)
Validates the F matrix and throws an exception if validation fails.
Definition: jade.verification.hpp:73
jade::basic_improver::verification_type
basic_verification< value_type > verification_type
The verification type.
Definition: cpax/jade.improver.hpp:36
jade::basic_verification::validate_gqf_sizes
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.
Definition: jade.verification.hpp:211
jade::basic_improver::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: cpax/jade.improver.hpp:27
jade::basic_verification::validate_q
static bool validate_q(const matrix_type &q)
Validates the Q matrix and throws an exception if validation fails.
Definition: jade.verification.hpp:225
jade::basic_qpas::loop_over_active_set
static void loop_over_active_set(const matrix_type &b_vec, const matrix_type &coefficients_mat, const matrix_type &hessian_mat, const matrix_type &derivative_vec, const std::vector< size_t > &fixed_active_set, std::vector< size_t > &active_set, matrix_type &delta_vec)
Loops over the active set and computes a delta vector and a new active set.
Definition: jade.qpas.hpp:40