|
ʻOhana
Population structure, admixture history, and selection using learning methods.
|
7 #ifndef JADE_IMPROVER_HPP__
8 #define JADE_IMPROVER_HPP__
10 #include "jade.forced_grouping.hpp"
11 #include "jade.lemke.hpp"
12 #include "jade.verification.hpp"
19 template <
typename TValue>
58 assert(
nullptr == fif || !frb);
64 validate_fif_size(*fif, K, J));
77 for (
size_t j = 0; j < J; j++)
91 const auto a_mat = _create_a_mat(K,
false);
93 auto b_vec = _create_b_vec(f_column, a_mat, shift_vec,
false);
104 for (
size_t k = 0; k < K; k++)
106 b_vec[k + 0] -= frb_delta;
107 b_vec[k + K] -= frb_delta;
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;
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]
132 for (
size_t k = 0; k < K; k++)
133 f_dst(k, j) = f_column[k];
168 for (
size_t i = 0; i < I; i++)
182 const auto a_mat = _create_a_mat(K,
true);
184 auto b_vec = _create_b_vec(q_row, a_mat, shift_vec,
true);
187 for (
size_t k = 0; k < K; k++)
189 b_vec[k + 0] -= fg->
get_min(i, k);
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;
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]
215 for (
size_t k = 0; k < K; k++)
216 q_dst(i, k) = q_row[k];
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;
235 const bool is_padded)
237 matrix_type c_mat (K + K + (is_padded ? 2 : 0), K);
239 for (
size_t k = 0; k < K; k++)
247 for (
size_t k = 0; k < K; k++)
262 const bool is_padded)
264 assert(current_values.is_vector());
266 const auto K = current_values.get_length();
268 matrix_type b_vec (K + K + (is_padded ? 2 : 0), 1);
270 for (
size_t k = 0; k < K; k++)
282 b_vec -= a_mat * current_values.create_transpose();
283 b_vec += a_mat * shift_vec;
290 #endif // JADE_IMPROVER_HPP__
bool solve()
Executes the algorithm until it has completed or has aborted.
A template for a class that performs validation on various types of matrices.
basic_genotype_matrix< value_type > genotype_matrix_type
The genotype matrix type.
value_type get_max(const size_t i, const size_t k) const
A template for a class that implements Lemke's algorithm.
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)
A template for an abstract class implementing operations for a genotype matrix.
value_type get_min(const size_t i, const size_t k) const
TValue value_type
The value type.
static bool validate_f(const matrix_type &f)
Validates the F matrix and throws an exception if validation fails.
basic_verification< value_type > verification_type
The verification type.
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)
size_t get_height() const
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.
void multiply_row(const size_t row, const value_type value)
Multiplies a row by a specified value.
basic_forced_grouping< value_type > forced_grouping_type
The forced grouping type.
basic_matrix< value_type > matrix_type
The matrix type.
static bool validate_q(const matrix_type &q)
Validates the Q matrix and throws an exception if validation fails.
virtual size_t get_height() const =0
basic_lemke< value_type > lemke_type
The Lemke type.
value_type get_row_sum(const size_t row) const
void set_values(const value_type value)
Sets all values of the matrix to the specified value.
virtual void compute_derivatives_q(const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const size_t i, matrix_type &d_vec, matrix_type &h_mat) const =0
Computes the derivative vector and hessian matrix for a specified individual of the Q matrix.
A template for a class that implements the forced grouping feature.
basic_matrix copy_column(const size_t column) const
basic_matrix copy_row(const size_t row) const
virtual void compute_derivatives_f(const matrix_type &q, const matrix_type &fa, const matrix_type &fb, const matrix_type &qfa, const matrix_type &qfb, const size_t j, matrix_type &d_vec, matrix_type &h_mat) const =0
Computes the derivative vector and hessian matrix for a specified marker of the F matrix.
void clamp_row(const size_t row, const value_type min, const value_type max)
Clamps all values in a row to the specified range.
A template for a class that improves the Q and F matrices.