|
ʻ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.qpas.hpp"
12 #include "jade.verification.hpp"
19 template <
typename TValue>
58 assert(
nullptr == fif || !frb);
64 validate_fif_size(*fif, K, J));
68 static const std::vector<size_t> fixed_active_set;
76 for (
size_t j = 0; j < J; j++)
90 const auto coefficients_mat = _create_coefficients_mat(K, 0);
92 auto b_vec = _create_b_vec(f_column, 0);
103 for (
size_t k = 0; k < K; k++)
105 b_vec[k + 0] -= frb_delta;
106 b_vec[k + K] -= frb_delta;
110 std::vector<size_t> active_set { 0 };
112 delta_vec[0] = -b_vec[0];
123 for (
size_t k = 0; k < K; k++)
124 f_dst(k, j) = f_column[k] + delta_vec[k];
152 const std::vector<size_t> fixed_active_set { K + K };
157 for (
size_t i = 0; i < I; i++)
171 const auto coefficients_mat = _create_coefficients_mat(K, 1);
173 auto b_vec = _create_b_vec(q_row, 1);
176 for (
size_t k = 0; k < K; k++)
178 b_vec[k + 0] -= fg->
get_min(i, k);
183 std::vector<size_t> active_set { 0 };
185 delta_vec[0] = -b_vec[0];
196 for (
size_t k = 0; k < K; k++)
197 q_dst(i, k) = q_row[k] + delta_vec[k];
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;
215 const size_t row_padding)
217 assert(current_values.is_vector());
219 const auto K = current_values.get_length();
223 for (
size_t k = 0; k < K; k++)
225 b_vec[k] = current_values[k];
226 b_vec[k + K] =
value_type(1) - current_values[k];
229 for (
size_t k = K + K; k < b_vec.get_height(); k++)
238 const size_t row_padding)
242 for (
size_t k = 0; k < K; k++)
248 for (
size_t r = K + K; r < c_mat.get_height(); r++)
249 for (
size_t c = 0; c < c_mat.get_width(); c++)
257 #endif // JADE_IMPROVER_HPP__
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
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_qpas< value_type > qpas_type
The QPAS 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
value_type get_row_sum(const size_t row) const
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.
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 implements the Quadratic Programming for Active Set algorithm.