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

A template for a class that optimizes the Q and F matrices. More...

#include <jade.optimizer.hpp>

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

Public Types

typedef TValue value_type
 The value type. More...
 
typedef basic_matrix< value_typematrix_type
 The matrix type. More...
 
typedef basic_options< value_typeoptions_type
 The options type. More...
 
typedef basic_settings< value_typesettings_type
 The settings type. More...
 
typedef basic_improver< value_typeimprover_type
 The improver type. More...
 
typedef TValue value_type
 The value type. More...
 
typedef basic_controller< value_typecontroller_type
 The controller type. More...
 
typedef basic_controller_factory< value_typecontroller_factory_type
 The controller factory type. More...
 
typedef basic_settings< value_typesettings_type
 The settings type. More...
 
typedef controller_type::simplex_type simplex_type
 The simplex type. More...
 
typedef simplex_type::container_type container_type
 The container type for the simplex. More...
 
typedef simplex_type::log_args log_args_type
 The log arguments type for the simplex. More...
 
typedef TValue value_type
 The value type. More...
 
typedef basic_matrix< value_typematrix_type
 The matrix type. More...
 
typedef basic_options< value_typeoptions_type
 The options type. More...
 
typedef basic_settings< value_typesettings_type
 The settings type. More...
 
typedef basic_improver< value_typeimprover_type
 The improver type. More...
 

Static Public Member Functions

static void execute (const settings_type &settings, matrix_type &q0, matrix_type &f0)
 Executes the optimization process. More...
 
static void execute (const settings_type &settings)
 Executes the optimizer based on the specified settings. More...
 
static void execute (const settings_type &settings, matrix_type &q0, matrix_type &f0)
 Executes the optimization process. More...
 

Detailed Description

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

A template for a class that optimizes the Q and F matrices.

A template for a class that optimizes specified program settings.

Definition at line 20 of file cpax/jade.optimizer.hpp.

Member Typedef Documentation

◆ container_type

template<typename TValue >
typedef simplex_type::container_type jade::basic_optimizer< TValue >::container_type

The container type for the simplex.

Definition at line 37 of file nemeco/jade.optimizer.hpp.

◆ controller_factory_type

template<typename TValue >
typedef basic_controller_factory<value_type> jade::basic_optimizer< TValue >::controller_factory_type

The controller factory type.

Definition at line 28 of file nemeco/jade.optimizer.hpp.

◆ controller_type

template<typename TValue >
typedef basic_controller<value_type> jade::basic_optimizer< TValue >::controller_type

The controller type.

Definition at line 25 of file nemeco/jade.optimizer.hpp.

◆ improver_type [1/2]

template<typename TValue >
typedef basic_improver<value_type> jade::basic_optimizer< TValue >::improver_type

The improver type.

Definition at line 36 of file cpax/jade.optimizer.hpp.

◆ improver_type [2/2]

template<typename TValue >
typedef basic_improver<value_type> jade::basic_optimizer< TValue >::improver_type

The improver type.

Definition at line 36 of file qpas/jade.optimizer.hpp.

◆ log_args_type

template<typename TValue >
typedef simplex_type::log_args jade::basic_optimizer< TValue >::log_args_type

The log arguments type for the simplex.

Definition at line 40 of file nemeco/jade.optimizer.hpp.

◆ matrix_type [1/2]

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

The matrix type.

Definition at line 27 of file cpax/jade.optimizer.hpp.

◆ matrix_type [2/2]

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

The matrix type.

Definition at line 27 of file qpas/jade.optimizer.hpp.

◆ options_type [1/2]

template<typename TValue >
typedef basic_options<value_type> jade::basic_optimizer< TValue >::options_type

The options type.

Definition at line 30 of file cpax/jade.optimizer.hpp.

◆ options_type [2/2]

template<typename TValue >
typedef basic_options<value_type> jade::basic_optimizer< TValue >::options_type

The options type.

Definition at line 30 of file qpas/jade.optimizer.hpp.

◆ settings_type [1/3]

template<typename TValue >
typedef basic_settings<value_type> jade::basic_optimizer< TValue >::settings_type

The settings type.

Definition at line 33 of file cpax/jade.optimizer.hpp.

◆ settings_type [2/3]

template<typename TValue >
typedef basic_settings<value_type> jade::basic_optimizer< TValue >::settings_type

The settings type.

Definition at line 31 of file nemeco/jade.optimizer.hpp.

◆ settings_type [3/3]

template<typename TValue >
typedef basic_settings<value_type> jade::basic_optimizer< TValue >::settings_type

The settings type.

Definition at line 33 of file qpas/jade.optimizer.hpp.

◆ simplex_type

template<typename TValue >
typedef controller_type::simplex_type jade::basic_optimizer< TValue >::simplex_type

The simplex type.

Definition at line 34 of file nemeco/jade.optimizer.hpp.

◆ value_type [1/3]

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

The value type.

Definition at line 24 of file cpax/jade.optimizer.hpp.

◆ value_type [2/3]

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

The value type.

Definition at line 22 of file nemeco/jade.optimizer.hpp.

◆ value_type [3/3]

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

The value type.

Definition at line 24 of file qpas/jade.optimizer.hpp.

Member Function Documentation

◆ execute() [1/3]

template<typename TValue >
static void jade::basic_optimizer< TValue >::execute ( const settings_type settings)
inlinestatic

Executes the optimizer based on the specified settings.

Parameters
settingsThe settings used to optimize.

Definition at line 45 of file nemeco/jade.optimizer.hpp.

47  {
48  std::cout << "iter\tduration\tdelta-lle\tlog-likelihood\n";
49 
50  const auto & opts = settings.get_options();
51 
52  //
53  // Depending upon whether or not the user specified a Newick tree,
54  // construct the appropriate controller for the Nelder-Mead
55  // algorithm, and use it to compute the objective function.
56  //
57  std::unique_ptr< controller_type > ctrl (
59  const auto objfunc = [&](const container_type & params)
60  -> value_type { return ctrl->compute_objfunc(params); };
61 
62  //
63  // Initialize the Nelder-Mead algorithm.
64  //
65  typedef typename simplex_type::options options_type;
66  options_type options (ctrl->init_parameters());
67  simplex_type simplex (objfunc, options);
68 
69  //
70  // Instruct the Nelder-Mead algorithm to use the settings based on
71  // supplied program options.
72  //
73  typedef typename simplex_type::execute_args execute_args_type;
74  execute_args_type execute_args;
75  execute_args.user = ctrl.get();
76  execute_args.logfunc = _logfunc;
77  if (opts.is_max_iterations_specified())
78  execute_args.max_iterations = opts.get_max_iterations();
79  if (opts.is_max_time_specified())
80  execute_args.max_seconds = opts.get_max_time();
81  if (opts.is_epsilon_specified())
82  execute_args.min_epsilon = opts.get_epsilon();
83 
84  //
85  // Perform the minimization.
86  //
87  const auto condition = simplex.execute(objfunc, execute_args);
88 
89  //
90  // Emit results.
91  //
92  ctrl->emit_results(opts, simplex, condition);
93  }
+ Here is the call graph for this function:

◆ execute() [2/3]

template<typename TValue >
static void jade::basic_optimizer< TValue >::execute ( const settings_type settings,
matrix_type q0,
matrix_type f0 
)
inlinestatic

Executes the optimization process.

Parameters
settingsThe settings.
q0The initial Q matrix.
f0The initial F matrix.

Definition at line 41 of file cpax/jade.optimizer.hpp.

45  {
46  //
47  // Release memory for the initial Q and F matrices.
48  //
49  matrix_type q, fa;
50  q0.swap(q);
51  f0.swap(fa);
52 
53  _clamp_f(settings, fa);
54 
55  const auto & opts = settings.get_options();
56  const auto fg = settings.get_fg();
57  const auto fif = settings.get_fif();
58  const auto & g = settings.get_g();
59  const auto frb = opts.is_frb();
60 
61  const stopwatch sw1;
62 
63  matrix_type fb (fa.get_height(), fa.get_width());
64  _compute_fb(fa, fb);
65 
66  matrix_type qfa = q * fa;
67  matrix_type qfb = q * fb;
68 
69  auto lle = g.compute_lle(q, fa, fb, qfa, qfb);
70  _emit_header(settings, sw1, lle);
71 
72  for (size_t iter = 1;; iter++)
73  {
74  if (opts.is_max_iterations_specified())
75  if (iter > opts.get_max_iterations())
76  break;
77 
78  if (opts.is_max_time_specified())
79  if (sw1 > opts.get_max_time())
80  break;
81 
82  const stopwatch sw2;
83 
84  if (!opts.is_fixed_q())
85  {
86  q = improver_type::improve_q(g, q, fa, fb, qfa, qfb, fg);
87  matrix_type::gemm(q, fa, qfa);
88  matrix_type::gemm(q, fb, qfb);
89  }
90 
91  if (!opts.is_fixed_f())
92  {
93  fa = improver_type::improve_f(g, q, fa, fb, qfa, qfb, fif, frb);
94  _clamp_f(settings, fa);
95  _compute_fb(fa, fb);
96  matrix_type::gemm(q, fa, qfa);
97  matrix_type::gemm(q, fb, qfb);
98  }
99 
100  const auto lle_prime = g.compute_lle(q, fa, fb, qfa, qfb);
101  const auto dlle = lle_prime - lle;
102 
103  _emit_line(settings, sw2, iter, lle_prime, dlle);
104 
105  lle = lle_prime;
106 
107  if (opts.is_epsilon_specified())
108  if (dlle >= value_type(0) && dlle <= opts.get_epsilon())
109  break;
110  }
111 
112  _emit_results(settings, q, fa);
113  }
+ Here is the call graph for this function:

◆ execute() [3/3]

template<typename TValue >
static void jade::basic_optimizer< TValue >::execute ( const settings_type settings,
matrix_type q0,
matrix_type f0 
)
inlinestatic

Executes the optimization process.

Parameters
settingsThe settings.
q0The initial Q matrix.
f0The initial F matrix.

Definition at line 41 of file qpas/jade.optimizer.hpp.

45  {
46  //
47  // Release memory for the initial Q and F matrices.
48  //
49  matrix_type q, fa;
50  q0.swap(q);
51  f0.swap(fa);
52 
53  _clamp_f(settings, fa);
54 
55  const auto & opts = settings.get_options();
56  const auto fg = settings.get_fg();
57  const auto fif = settings.get_fif();
58  const auto & g = settings.get_g();
59  const auto frb = opts.is_frb();
60 
61  const stopwatch sw1;
62 
63  matrix_type fb (fa.get_height(), fa.get_width());
64  _compute_fb(fa, fb);
65 
66  matrix_type qfa = q * fa;
67  matrix_type qfb = q * fb;
68 
69  auto lle = g.compute_lle(q, fa, fb, qfa, qfb);
70  _emit_header(settings, sw1, lle);
71 
72  for (size_t iter = 1;; iter++)
73  {
74  if (opts.is_max_iterations_specified())
75  if (iter > opts.get_max_iterations())
76  break;
77 
78  if (opts.is_max_time_specified())
79  if (sw1 > opts.get_max_time())
80  break;
81 
82  const stopwatch sw2;
83 
84  if (!opts.is_fixed_q())
85  {
86  q = improver_type::improve_q(g, q, fa, fb, qfa, qfb, fg);
87  matrix_type::gemm(q, fa, qfa);
88  matrix_type::gemm(q, fb, qfb);
89  }
90 
91  if (!opts.is_fixed_f())
92  {
93  fa = improver_type::improve_f(g, q, fa, fb, qfa, qfb, fif, frb);
94  _clamp_f(settings, fa);
95  _compute_fb(fa, fb);
96  matrix_type::gemm(q, fa, qfa);
97  matrix_type::gemm(q, fb, qfb);
98  }
99 
100  const auto lle_prime = g.compute_lle(q, fa, fb, qfa, qfb);
101  const auto dlle = lle_prime - lle;
102 
103  _emit_line(settings, sw2, iter, lle_prime, dlle);
104 
105  lle = lle_prime;
106 
107  if (opts.is_epsilon_specified())
108  if (dlle >= value_type(0) && dlle <= opts.get_epsilon())
109  break;
110  }
111 
112  _emit_results(settings, q, fa);
113  }
+ Here is the call graph for this function:

The documentation for this class was generated from the following file:
jade::basic_improver::improve_f
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)
Definition: cpax/jade.improver.hpp:44
jade::basic_matrix::swap
void swap(basic_matrix &other)
Swaps this matrix and another matrix.
Definition: jade.matrix.hpp:1209
jade::basic_controller_factory::create
static controller_type * create(const settings_type &settings)
Definition: jade.controller_factory.hpp:48
jade::basic_optimizer::container_type
simplex_type::container_type container_type
The container type for the simplex.
Definition: nemeco/jade.optimizer.hpp:37
jade::basic_optimizer::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: cpax/jade.optimizer.hpp:27
jade::basic_improver::improve_q
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)
Definition: cpax/jade.improver.hpp:143
jade::basic_optimizer::simplex_type
controller_type::simplex_type simplex_type
The simplex type.
Definition: nemeco/jade.optimizer.hpp:34
jade::basic_optimizer::value_type
TValue value_type
The value type.
Definition: cpax/jade.optimizer.hpp:24
jade::basic_optimizer::options_type
basic_options< value_type > options_type
The options type.
Definition: cpax/jade.optimizer.hpp:30
jade::basic_matrix< value_type >::gemm
static void gemm(const basic_matrix &lhs, const basic_matrix &rhs, basic_matrix &dst, const value_type alpha=value_type(1), const value_type beta=value_type(0))
Multiplies a left matrix by a right matrix and stores the result into a destination matrix....
Definition: jade.matrix.hpp:459