A template for a class that implements the forced grouping feature.
More...
#include <jade.forced_grouping.hpp>
template<typename TValue>
class jade::basic_forced_grouping< TValue >
A template for a class that implements the forced grouping feature.
Definition at line 18 of file cpax/jade.forced_grouping.hpp.
◆ matrix_type [1/2]
template<typename TValue >
◆ matrix_type [2/2]
template<typename TValue >
◆ randomizer_type [1/2]
template<typename TValue >
◆ randomizer_type [2/2]
template<typename TValue >
◆ value_type [1/2]
template<typename TValue >
◆ value_type [2/2]
template<typename TValue >
◆ basic_forced_grouping() [1/6]
template<typename TValue >
◆ basic_forced_grouping() [2/6]
template<typename TValue >
Initializes a new instance of the class based on values from the specified file.
- Parameters
-
path | The path to the file. |
Definition at line 45 of file cpax/jade.forced_grouping.hpp.
52 assert(path !=
nullptr);
55 std::istringstream in (_strip_comments(path));
57 if (!(in >> _i) || _i == 0)
59 <<
"error parsing number of individuals";
61 if (!(in >> _k) || _k == 0)
63 <<
"error parsing number of components";
67 for (
size_t i = 0; i < _i; i++)
73 <<
"error parsing component assignment "
74 <<
"for individual " << i+1;
79 const auto P = 1 + *std::max_element(_a.begin(), _a.end());
83 for (
size_t p = 0; p < P; p++)
89 catch (
const std::exception & e)
92 <<
"error reading B vector for population index "
93 << p <<
": " << e.what();
99 catch (
const std::exception & e)
101 throw error() <<
"failed to read forced-grouping file '"
102 << path <<
"': " << e.what();
◆ basic_forced_grouping() [3/6]
template<typename TValue >
Initializes a new instance of the class based on values from the specified file.
- Parameters
-
path | The path to the file. |
Definition at line 110 of file cpax/jade.forced_grouping.hpp.
◆ basic_forced_grouping() [4/6]
template<typename TValue >
◆ basic_forced_grouping() [5/6]
template<typename TValue >
Initializes a new instance of the class based on values from the specified file.
- Parameters
-
path | The path to the file. |
Definition at line 45 of file qpas/jade.forced_grouping.hpp.
52 assert(path !=
nullptr);
55 std::istringstream in (_strip_comments(path));
57 if (!(in >> _i) || _i == 0)
59 <<
"error parsing number of individuals";
61 if (!(in >> _k) || _k == 0)
63 <<
"error parsing number of components";
67 for (
size_t i = 0; i < _i; i++)
73 <<
"error parsing component assignment "
74 <<
"for individual " << i+1;
79 const auto P = 1 + *std::max_element(_a.begin(), _a.end());
83 for (
size_t p = 0; p < P; p++)
89 catch (
const std::exception & e)
92 <<
"error reading B vector for population index "
93 << p <<
": " << e.what();
99 catch (
const std::exception & e)
101 throw error() <<
"failed to read forced-grouping file '"
102 << path <<
"': " << e.what();
◆ basic_forced_grouping() [6/6]
template<typename TValue >
Initializes a new instance of the class based on values from the specified file.
- Parameters
-
path | The path to the file. |
Definition at line 110 of file qpas/jade.forced_grouping.hpp.
◆ get_i() [1/2]
template<typename TValue >
◆ get_i() [2/2]
template<typename TValue >
◆ get_k() [1/2]
template<typename TValue >
◆ get_k() [2/2]
template<typename TValue >
◆ get_max() [1/2]
template<typename TValue >
- Returns
- The maximum value for a specified individual and component.
- Parameters
-
i | The individual index. |
k | The component index. |
Definition at line 135 of file cpax/jade.forced_grouping.hpp.
142 return _b[_a[i]].get_value(k + _k);
◆ get_max() [2/2]
template<typename TValue >
- Returns
- The maximum value for a specified individual and component.
- Parameters
-
i | The individual index. |
k | The component index. |
Definition at line 135 of file qpas/jade.forced_grouping.hpp.
142 return _b[_a[i]].get_value(k + _k);
◆ get_min() [1/2]
template<typename TValue >
- Returns
- The minimim value for a specified individual and component.
- Parameters
-
i | The individual index. |
k | The component index. |
Definition at line 148 of file cpax/jade.forced_grouping.hpp.
155 return _b[_a[i]].get_value(k);
◆ get_min() [2/2]
template<typename TValue >
- Returns
- The minimim value for a specified individual and component.
- Parameters
-
i | The individual index. |
k | The component index. |
Definition at line 148 of file qpas/jade.forced_grouping.hpp.
155 return _b[_a[i]].get_value(k);
◆ randomize_q() [1/2]
template<typename TValue >
- Returns
- A new Q matrix from random values.
- Parameters
-
Definition at line 161 of file cpax/jade.forced_grouping.hpp.
165 static const auto epsilon =
value_type(0.000001);
169 for (
size_t k = 0; k < _k; k++)
170 for (
size_t i = 0; i < _i; i++)
173 typedef std::uniform_int_distribution<size_t> k_dist_type;
174 typedef std::uniform_real_distribution<value_type> q_dist_type;
176 k_dist_type k_dist (0, _k - 1);
178 auto & engine = rnd.get_engine();
180 for (
size_t i = 0; i < _i; i++)
184 const auto row_sum = q.get_row_sum(i);
185 if (std::fabs(
value_type(1) - row_sum) < epsilon)
188 const auto k = k_dist(engine);
189 const auto q_ik = q(i, k);
193 const auto min_ik =
get_min(i, k);
194 const auto distance = row_sum -
value_type(1);
195 const auto boundary = std::max(min_ik, q_ik - distance);
197 q_dist_type q_dist (boundary, q_ik);
198 q(i, k) = q_dist(engine);
202 const auto max_ik =
get_max(i, k);
203 const auto distance =
value_type(1) - row_sum;
204 const auto boundary = std::min(q_ik + distance, max_ik);
206 q_dist_type q_dist (q_ik, boundary);
207 q(i, k) = q_dist(engine);
◆ randomize_q() [2/2]
template<typename TValue >
- Returns
- A new Q matrix from random values.
- Parameters
-
Definition at line 161 of file qpas/jade.forced_grouping.hpp.
165 static const auto epsilon =
value_type(0.000001);
169 for (
size_t k = 0; k < _k; k++)
170 for (
size_t i = 0; i < _i; i++)
173 typedef std::uniform_int_distribution<size_t> k_dist_type;
174 typedef std::uniform_real_distribution<value_type> q_dist_type;
176 k_dist_type k_dist (0, _k - 1);
178 auto & engine = rnd.get_engine();
180 for (
size_t i = 0; i < _i; i++)
184 const auto row_sum = q.get_row_sum(i);
185 if (std::fabs(
value_type(1) - row_sum) < epsilon)
188 const auto k = k_dist(engine);
189 const auto q_ik = q(i, k);
193 const auto min_ik =
get_min(i, k);
194 const auto distance = row_sum -
value_type(1);
195 const auto boundary = std::max(min_ik, q_ik - distance);
197 q_dist_type q_dist (boundary, q_ik);
198 q(i, k) = q_dist(engine);
202 const auto max_ik =
get_max(i, k);
203 const auto distance =
value_type(1) - row_sum;
204 const auto boundary = std::min(q_ik + distance, max_ik);
206 q_dist_type q_dist (q_ik, boundary);
207 q(i, k) = q_dist(engine);
◆ validate_q() [1/2]
template<typename TValue >
Validates the Q matrix and throws an exception if validation fails.
- Returns
- True.
- Parameters
-
Definition at line 219 of file cpax/jade.forced_grouping.hpp.
223 if (_k != q.get_width())
225 <<
"inconsistent number of components specified in "
226 <<
"forced-grouping file (" << _k <<
") and "
227 << q.get_size_str() <<
" Q matrix";
229 if (_i != q.get_height())
231 <<
"inconsistent number of individuals specified in "
232 <<
"forced-grouping file (" << _i <<
") and "
233 << q.get_size_str() <<
" Q matrix";
235 for (
size_t i = 0; i < _i; i++)
237 for (
size_t k = 0; k < _k; k++)
239 const auto q_ik = q(i, k);
240 const auto min =
get_min(i, k);
241 const auto max =
get_max(i, k);
242 if (q_ik >= min && q_ik <= max)
246 <<
"inconsistent Q matrix cell [" << i+1 <<
"," << k+1
247 <<
"] (" << q_ik <<
") is outside the range specified "
248 <<
"in the forced-grouping file " << min <<
" to "
◆ validate_q() [2/2]
template<typename TValue >
Validates the Q matrix and throws an exception if validation fails.
- Returns
- True.
- Parameters
-
Definition at line 219 of file qpas/jade.forced_grouping.hpp.
223 if (_k != q.get_width())
225 <<
"inconsistent number of components specified in "
226 <<
"forced-grouping file (" << _k <<
") and "
227 << q.get_size_str() <<
" Q matrix";
229 if (_i != q.get_height())
231 <<
"inconsistent number of individuals specified in "
232 <<
"forced-grouping file (" << _i <<
") and "
233 << q.get_size_str() <<
" Q matrix";
235 for (
size_t i = 0; i < _i; i++)
237 for (
size_t k = 0; k < _k; k++)
239 const auto q_ik = q(i, k);
240 const auto min =
get_min(i, k);
241 const auto max =
get_max(i, k);
242 if (q_ik >= min && q_ik <= max)
246 <<
"inconsistent Q matrix cell [" << i+1 <<
"," << k+1
247 <<
"] (" << q_ik <<
") is outside the range specified "
248 <<
"in the forced-grouping file " << min <<
" to "
The documentation for this class was generated from the following file: