7 #ifndef JADE_SELSCAN_HPP__
8 #define JADE_SELSCAN_HPP__
10 #include "jade.args.hpp"
11 #include "jade.genotype_matrix_factory.hpp"
18 template <
typename TValue>
44 : steps (a.read(
"--steps",
"-s", size_t(100)))
45 , f_epsilon (_read_f_epsilon(a))
48 , fa (a.pop<std::string>())
49 , c1 (a.pop<std::string>())
50 , c2 (_init_scaling_matrix(a, c1))
53 , mu (g.create_mu(f_epsilon))
54 , rooted_fa (_compute_rooted_fa(fa))
59 throw error() <<
"invalid value for --steps option ("
60 << steps <<
"); expected at least two steps";
80 std::cout <<
"step\tlle-ratio\tglobal-lle\tlocal-lle";
82 for (
size_t k = 0; k < K; k++)
83 std::cout <<
"\t" <<
"f-pop" << k;
85 std::cout << std::endl;
87 std::vector<record> records;
89 for (
size_t j = 0; j < J; j++)
90 records.emplace_back(j, _compute_score(0, j));
92 for (
size_t si = 0; si < steps; si++)
93 for (
auto & r : records)
94 r.update(si, _compute_score(si, r.get_j()));
96 for (
const auto & r : records)
98 std::cout << r.get_step() <<
'\t'
99 << _format(r.get_lle_ratio()) <<
'\t'
100 << _format(r.get_score()) <<
'\t'
101 << _format(r.get_best_score());
103 for (
size_t k = 0; k < K; k++)
104 std::cout <<
'\t' << _format(fa(k, r.get_j()));
106 std::cout << std::endl;
111 typedef std::unique_ptr<genotype_matrix_type> genotype_matrix_ptr;
117 const size_t J = fa.get_width();
123 for (
size_t k = 0; k + 1 < K; k++)
124 for (
size_t j = 0; j < J; j++)
125 rooted_fa(k, j) = fa(k + 1, j) - fa(0, j);
135 typedef std::numeric_limits<value_type> limits_type;
136 static const auto lowest = limits_type::lowest();
141 for (
size_t i = 0; i < RK * RK; i++)
142 c_inv[i] = c1[i] + percent * (c2[i] - c1[i]);
150 if (!c_inv.
invert(log_c_det))
183 const auto dot = blas_type::dot(
190 static const auto pi =
value_type(std::acos(-1.0));
194 const auto mu_j = mu[j];
195 const auto c_j = mu_j * (
value_type(1) - mu_j);
196 const auto term = (rk * std::log(tau * c_j)) + (dot / c_j);
201 static std::string _format(
const value_type value)
203 std::ostringstream out;
205 out << std::showpos << value;
214 const auto path = a.
read<std::string>(
"--c-scale",
"-cs");
221 const auto out = a.read(
"--f-epsilon",
"-fe",
value_type(1.0e-6));
225 <<
"invalid value for --f-epsilon option: "
236 inline record(
const size_t j,
const value_type score)
237 : _best_score (std::numeric_limits<
value_type>::lowest())
239 , _lle_ratio (std::numeric_limits<
value_type>::quiet_NaN())
241 , _step (std::numeric_limits<size_t>::max())
252 inline size_t get_j()
const
270 inline size_t get_step()
const
276 inline void update(
const size_t step,
const value_type score)
278 if (score <= _best_score)
283 _lle_ratio =
value_type(2) * (score - _score);
296 const genotype_matrix_ptr g_ptr;
310 #endif // JADE_SELSCAN_HPP__