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

A template for a class that implements the Quadratic Programming for Active Set algorithm. More...

#include <jade.qpas.hpp>

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

Public Types

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

Static Public Member Functions

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. More...
 

Detailed Description

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

A template for a class that implements the Quadratic Programming for Active Set algorithm.

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

Member Typedef Documentation

◆ matrix_type

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

The matrix type.

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

◆ value_type

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

The value type.

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

Member Function Documentation

◆ loop_over_active_set()

template<typename TValue >
static void jade::basic_qpas< TValue >::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 
)
inlinestatic

Loops over the active set and computes a delta vector and a new active set.

Parameters
b_vecThe B vector.
coefficients_matThe coefficients matrix.
hessian_matThe Hessian matrix.
derivative_vecThe derivative vector.
fixed_active_setThe fixed active set.
active_setThe active set.
delta_vecThe delta vector.

Definition at line 40 of file jade.qpas.hpp.

48  {
49  assert(!fixed_active_set.empty() || !active_set.empty());
50 
51  const auto K = hessian_mat.get_height();
52  assert(K > 0);
53 
54  const auto inequality_constraint_count =
55  b_vec.get_length() - fixed_active_set.size();
56 
57  assert(b_vec.is_vector());
58  assert(coefficients_mat.get_height() == b_vec.get_length());
59  assert(fixed_active_set.size() <= K);
60  assert(delta_vec.is_vector());
61  assert(delta_vec.get_height() == K);
62 
63  std::set<unsigned long> visited_sets;
64 
65  const auto insert_key = [&visited_sets, &active_set]() -> bool
66  {
67  auto key = 0UL;
68  for (const auto i : active_set)
69  key |= 1UL << i;
70  if (visited_sets.find(key) != visited_sets.end())
71  return false;
72  visited_sets.insert(key);
73  return true;
74  };
75 
76  while (insert_key())
77  {
78  std::vector<size_t> merged_active_set;
79  merged_active_set.insert(
80  merged_active_set.end(),
81  active_set.begin(),
82  active_set.end());
83  merged_active_set.insert(
84  merged_active_set.end(),
85  fixed_active_set.begin(),
86  fixed_active_set.end());
87 
88  matrix_type lagrangian_vec (
89  merged_active_set.size(),
90  merged_active_set.empty() ? 0 : 1);
91 
92  matrix_type try_delta_vec (K, 1);
93 
94  _kkt(b_vec,
95  coefficients_mat,
96  hessian_mat,
97  derivative_vec,
98  merged_active_set,
99  try_delta_vec,
100  lagrangian_vec);
101 
102  std::vector<size_t> violated_indices;
103 
104  if (active_set.size() < K - fixed_active_set.size())
105  {
106  for (size_t i = 0; i < inequality_constraint_count; i++)
107  {
108  if (merged_active_set.end() != std::find(
109  merged_active_set.begin(),
110  merged_active_set.end(),
111  i))
112  continue;
113 
114  const auto lhs = coefficients_mat
115  .multiply_row(i, try_delta_vec);
116 
117  if (lhs > b_vec[i])
118  violated_indices.push_back(i);
119  }
120  }
121 
122  if (violated_indices.empty())
123  {
124  delta_vec = try_delta_vec;
125 
126  auto lagrangian_index = index_not_found;
127  for (size_t i = 0; i < active_set.size(); i++)
128  {
129  const auto lms_i = lagrangian_vec[i];
130  if (lms_i < value_type(0))
131  continue;
132  if (lagrangian_index == index_not_found ||
133  lms_i > lagrangian_vec[lagrangian_index])
134  lagrangian_index = i;
135  }
136 
137  if (lagrangian_index == index_not_found)
138  return;
139 
140  active_set.erase(
141  active_set.begin() +
142  int(lagrangian_index));
143  }
144  else
145  {
146  const auto k_violated = _backtrack(
147  b_vec,
148  coefficients_mat,
149  delta_vec,
150  try_delta_vec,
151  violated_indices,
152  delta_vec);
153 
154  if (k_violated == index_not_found)
155  continue;
156 
157  assert(std::none_of(
158  active_set.begin(),
159  active_set.end(),
160  [k_violated](const size_t index) -> bool
161  {
162  return index == k_violated;
163  }));
164 
165  assert(k_violated != index_not_found);
166  assert(k_violated < b_vec.get_length());
167  active_set.push_back(k_violated);
168  }
169  }
170  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

The documentation for this class was generated from the following file:
jade::basic_qpas::value_type
TValue value_type
The value type.
Definition: jade.qpas.hpp:23
jade::basic_qpas::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.qpas.hpp:26