ʻOhana
Population structure, admixture history, and selection using learning methods.
jade.likelihood_genotype_matrix.hpp
1 /* -------------------------------------------------------------------------
2  Ohana
3  Copyright (c) 2015-2020 Jade Cheng (\___/)
4  Jade Cheng <info@jade-cheng.com> (='.'=)
5  ------------------------------------------------------------------------- */
6 
7 #ifndef JADE_LIKELIHOOD_GENOTYPE_MATRIX_HPP__
8 #define JADE_LIKELIHOOD_GENOTYPE_MATRIX_HPP__
9 
10 #include "jade.genotype_matrix.hpp"
11 
12 namespace jade
13 {
14  ///
15  /// A template class implementing operations for a likelihood genotype
16  /// matrix type.
17  ///
18  template <typename TValue>
20  : public basic_genotype_matrix<TValue>
21  {
22  public:
23  /// The value type.
24  typedef TValue value_type;
25 
26  /// The matrix type.
28 
29  ///
30  /// Initializes a new instance of the class.
31  ///
33  : _g_aa ()
34  , _g_Aa ()
35  , _g_AA ()
36  {
37  }
38 
39  ///
40  /// Initializes a new instance of the class based on values from the
41  /// specified input stream.
42  ///
44  std::istream & in) ///< The input stream.
45  : _g_aa (in)
46  , _g_Aa (in)
47  , _g_AA (in)
48  {
49  _validate_sizes();
50  }
51 
52  ///
53  /// Initializes a new instance of the class based on values from the
54  /// specified file.
55  ///
57  const std::string & path) ///< The path to the file.
58  : basic_likelihood_genotype_matrix(path.c_str())
59  {
60  }
61 
62  ///
63  /// Initializes a new instance of the class based on values from the
64  /// specified file.
65  ///
67  char const * const path) ///< The path to the file.
69  {
70  assert(path != nullptr);
71 
72  try
73  {
74  std::ifstream in (path);
75  if (!in.good())
76  throw error("error reading file");
77 
79  _g_aa.swap(tmp._g_aa);
80  _g_Aa.swap(tmp._g_Aa);
81  _g_AA.swap(tmp._g_AA);
82  }
83  catch (const std::exception & e)
84  {
85  throw error()
86  << "error reading likelihood genotype matrix '"
87  << path << "': " << e.what();
88  }
89  }
90 
91  ///
92  /// Initializes a new instance of the class based on values from the
93  /// specified matrices.
94  ///
96  const matrix_type & g_aa, ///< The minor-minor matrix.
97  const matrix_type & g_Aa, ///< The major-minor matrix.
98  const matrix_type & g_AA) ///< The major-major matrix.
99  : _g_aa (g_aa)
100  , _g_Aa (g_Aa)
101  , _g_AA (g_AA)
102  {
103  _validate_sizes();
104  }
105 
106  ///
107  /// \return This instance.
108  ///
109  inline const basic_likelihood_genotype_matrix * as_lgm() const override
110  {
111  return this;
112  }
113 
114  ///
115  /// \return This instance.
116  ///
118  {
119  return this;
120  }
121 
122  ///
123  /// Computes the derivative vector and hessian matrix for a specified
124  /// marker of the F matrix.
125  ///
126  virtual void compute_derivatives_f(
127  const matrix_type & q, ///< The Q matrix.
128  const matrix_type & , ///< The F matrix.
129  const matrix_type & , ///< The 1-F matrix.
130  const matrix_type & qfa, ///< The Q*F product.
131  const matrix_type & qfb, ///< The Q*(1-F) product.
132  const size_t j, ///< The marker.
133  matrix_type & d_vec, ///< The derivative vector.
134  matrix_type & h_mat) ///< The hessian matrix.
135  const override
136  {
137  const auto J = get_width();
138  const auto K = d_vec.get_height();
139 
140  #ifndef NDEBUG
141  const auto I = get_height();
142  assert(q.is_size(I, K));
143  assert(qfa.is_size(I, J));
144  assert(qfb.is_size(I, J));
145  assert(j < J);
146  assert(d_vec.is_size(K, 1));
147  assert(h_mat.is_size(K, K));
148  #endif // NDEBUG
149 
150  d_vec.set_values(0);
151  h_mat.set_values(0);
152 
153  //
154  // for (size_t i = 0; i < I; i++)
155  // g_ij --> g(i, j)
156  // q_i0 --> q(i, 0)
157  // qfa_ij --> qfa(i, j)
158  // qfb_ij --> qfb(i, j)
159  //
160  auto g_aa_ij_ptr = _g_aa.get_data() + j;
161  auto g_Aa_ij_ptr = _g_Aa.get_data() + j;
162  auto g_AA_ij_ptr = _g_AA.get_data() + j;
163  auto q_i0_ptr = q.get_data();
164  auto qfa_ij_ptr = qfa.get_data() + j;
165  auto qfb_ij_ptr = qfb.get_data() + j;
166  const auto g_aa_ij_end = g_aa_ij_ptr + _g_aa.get_length();
167  const auto g_step = J;
168  const auto q_step = K;
169  const auto qf_step = J;
170  while (g_aa_ij_ptr != g_aa_ij_end)
171  {
172  const auto g_AA_ij = *g_AA_ij_ptr;
173  const auto g_Aa_ij = *g_Aa_ij_ptr;
174  const auto g_aa_ij = *g_aa_ij_ptr;
175  const auto qfa_ij = *qfa_ij_ptr;
176  const auto qfb_ij = *qfb_ij_ptr;
177 
178  const auto alpha = value_type(1) / (
179  g_AA_ij * qfa_ij * qfa_ij +
180  g_aa_ij * qfb_ij * qfb_ij +
181  g_Aa_ij * qfa_ij * qfb_ij * 2);
182 
183  const auto theta = 2 * (
184  g_AA_ij * qfa_ij -
185  g_aa_ij * qfb_ij +
186  g_Aa_ij * qfb_ij -
187  g_Aa_ij * qfa_ij);
188 
189  //
190  // for (size_t k1 = 0; k1 < K; k1++)
191  // d --> d_vec[k1]
192  // h --> h_mat(k1, ...)
193  // q_ik1 --> q(i, k1)
194  //
195  auto d_ptr = d_vec.get_data();
196  auto h_ptr = h_mat.get_data();
197  auto q_ik1_ptr = q_i0_ptr;
198  const auto q_ik1_end = q_i0_ptr + K;
199  const auto q_ik2_end = q_i0_ptr + K;
200  while (q_ik1_ptr != q_ik1_end)
201  {
202  const auto q_ik1 = *q_ik1_ptr;
203 
204  *d_ptr += theta * alpha * q_ik1;
205 
206  //
207  // for (size_t k2 = 0; k2 < K; k2++)
208  // q_ik2 --> q(i, k2)
209  //
210  auto q_ik2_ptr = q_i0_ptr;
211  while (q_ik2_ptr != q_ik2_end)
212  {
213  const auto q_ik2 = *q_ik2_ptr;
214  const auto term = 2 * (g_AA_ij + g_aa_ij
215  - (2 * g_Aa_ij));
216 
217  *h_ptr += alpha * q_ik1 * q_ik2 * (
218  term - (theta * theta * alpha));
219 
220  h_ptr++;
221  q_ik2_ptr++;
222  }
223 
224  d_ptr++;
225  q_ik1_ptr++;
226  }
227 
228  g_AA_ij_ptr += g_step;
229  g_Aa_ij_ptr += g_step;
230  g_aa_ij_ptr += g_step;
231  qfa_ij_ptr += qf_step;
232  qfb_ij_ptr += qf_step;
233  q_i0_ptr += q_step;
234  }
235  }
236 
237  ///
238  /// Computes the derivative vector and hessian matrix for a specified
239  /// individual of the Q matrix.
240  ///
241  virtual void compute_derivatives_q(
242  const matrix_type & , ///< The Q matrix.
243  const matrix_type & fa, ///< The F matrix.
244  const matrix_type & fb, ///< The 1-F matrix.
245  const matrix_type & qfa, ///< The Q*F product.
246  const matrix_type & qfb, ///< The Q*(1-F) product.
247  const size_t i, ///< The individual.
248  matrix_type & d_vec, ///< The derivative vector.
249  matrix_type & h_mat) ///< The hessian matrix.
250  const override
251  {
252  const auto J = get_width();
253 
254  #ifndef NDEBUG
255  const auto I = get_height();
256  const auto K = d_vec.get_height();
257  assert(fa.is_size(K, J));
258  assert(fb.is_size(K, J));
259  assert(qfa.is_size(I, J));
260  assert(qfb.is_size(I, J));
261  assert(i < I);
262  assert(d_vec.is_size(K, 1));
263  assert(h_mat.is_size(K, K));
264  #endif // NDEBUG
265 
266  d_vec.set_values(0);
267  h_mat.set_values(0);
268 
269  //
270  // for (size_t j = 0; j < J; j++)
271  // g_ij --> g(i, j)
272  // q_fa_ij --> q_fa(i, j)
273  // q_fb_ij --> q_fb(i, j)
274  // fa_0j --> q_fa(0, j)
275  // fb_0j --> q_fb(0, j)
276  //
277  auto g_AA_ij_ptr = _g_AA.get_data(i, 0);
278  auto g_Aa_ij_ptr = _g_Aa.get_data(i, 0);
279  auto g_aa_ij_ptr = _g_aa.get_data(i, 0);
280  const auto g_aa_ij_end = g_aa_ij_ptr + J;
281  auto qfa_ij_ptr = qfa.get_data(i, 0);
282  auto qfb_ij_ptr = qfb.get_data(i, 0);
283  auto fa_0j_ptr = fa.get_data();
284  auto fb_0j_ptr = fb.get_data();
285  auto f_step = J;
286  while (g_aa_ij_ptr != g_aa_ij_end)
287  {
288  const auto g_AA_ij = *g_AA_ij_ptr;
289  const auto g_Aa_ij = *g_Aa_ij_ptr;
290  const auto g_aa_ij = *g_aa_ij_ptr;
291  const auto qfa_ij = *qfa_ij_ptr;
292  const auto qfb_ij = *qfb_ij_ptr;
293 
294  const auto alpha = value_type(1) / (
295  g_AA_ij * qfa_ij * qfa_ij +
296  g_aa_ij * qfb_ij * qfb_ij +
297  g_Aa_ij * qfa_ij * qfb_ij * 2);
298 
299  const auto theta = 2 * (
300  (g_AA_ij * qfa_ij) +
301  (g_Aa_ij * qfb_ij));
302 
303  const auto gamma = 2 * (
304  (g_aa_ij * qfb_ij) +
305  (g_Aa_ij * qfa_ij));
306 
307  //
308  // for (size_t k1 = 0; k1 < K; k1++)
309  // fa_k1j --> fa(k1, j)
310  // fb_k1j --> fb(k1, j)
311  // d --> d_vec[k1]
312  // h --> h_mat(k1, ...)
313  //
314  auto fa_k1j_ptr = fa_0j_ptr;
315  auto fb_k1j_ptr = fb_0j_ptr;
316  auto d_ptr = d_vec.get_data();
317  auto h_ptr = h_mat.get_data();
318  const auto h_end = h_ptr + h_mat.get_length();
319  while (h_ptr != h_end)
320  {
321  const auto fa_k1j = *fa_k1j_ptr;
322  const auto fb_k1j = *fb_k1j_ptr;
323 
324  *d_ptr += alpha * ((theta * fa_k1j) + (gamma * fb_k1j));
325 
326  //
327  // for (size_t k2 = 0; k2 < K; k2++)
328  // fa_k2j --> fa(k2, j)
329  // fb_k2j --> fb(k2, j)
330  //
331  auto fa_k2j_ptr = fa_0j_ptr;
332  auto fb_k2j_ptr = fb_0j_ptr;
333  const auto fa_k2j_end = fa_k2j_ptr + fa.get_length();
334  while (fa_k2j_ptr != fa_k2j_end)
335  {
336  const auto fa_k2j = *fa_k2j_ptr;
337  const auto fb_k2j = *fb_k2j_ptr;
338 
339  const auto term1 = 2 * (
340  (g_AA_ij * fa_k1j * fa_k2j) +
341  (g_aa_ij * fb_k1j * fb_k2j));
342 
343  const auto term2 = 2 * g_Aa_ij * (
344  (fa_k1j * fb_k2j) +
345  (fb_k1j * fa_k2j));
346 
347  const auto term3 =
348  (theta * theta * fa_k1j * fa_k2j) +
349  (gamma * gamma * fb_k1j * fb_k2j);
350 
351  const auto term4 = theta * gamma * (
352  (fa_k1j * fb_k2j) +
353  (fb_k1j * fa_k2j));
354 
355  *h_ptr += alpha * (term1 + term2
356  - alpha * (term3 + term4));
357 
358  fa_k2j_ptr += f_step;
359  fb_k2j_ptr += f_step;
360  h_ptr++;
361  }
362 
363  fa_k1j_ptr += f_step;
364  fb_k1j_ptr += f_step;
365  d_ptr++;
366  }
367 
368  g_AA_ij_ptr++;
369  g_Aa_ij_ptr++;
370  g_aa_ij_ptr++;
371  qfa_ij_ptr++;
372  qfb_ij_ptr++;
373  fa_0j_ptr++;
374  fb_0j_ptr++;
375  }
376  }
377 
378  ///
379  /// \return The log of the likelihood function.
380  ///
382  const matrix_type & , ///< The Q matrix.
383  const matrix_type & , ///< The F matrix for major alleles.
384  const matrix_type & , ///< The F matrix for minor alleles.
385  const matrix_type & qfa, ///< The Q*Fa product.
386  const matrix_type & qfb) ///< The Q*Fb product.
387  const override
388  {
389  assert(qfa.is_size(qfb));
390  assert(qfa.is_size(get_height(), get_width()));
391 
392  auto g_aa_ij_ptr = _g_aa.get_data();
393  auto g_Aa_ij_ptr = _g_Aa.get_data();
394  auto g_AA_ij_ptr = _g_AA.get_data();
395  auto qfa_ij_ptr = qfa.get_data();
396  auto qfb_ij_ptr = qfb.get_data();
397  const auto qfb_ij_end = qfb_ij_ptr + qfb.get_length();
398 
399  auto sum = value_type(0);
400 
401  while (qfb_ij_ptr != qfb_ij_end) // loop over all of Q x F (G)
402  {
403  const auto qfa_ij = *qfa_ij_ptr;
404  const auto qfb_ij = *qfb_ij_ptr;
405 
406  sum += std::log(
407  (*g_AA_ij_ptr * qfa_ij * qfa_ij) +
408  (*g_aa_ij_ptr * qfb_ij * qfb_ij) +
409  (*g_Aa_ij_ptr * qfa_ij * qfb_ij * value_type(2)));
410 
411  g_AA_ij_ptr++;
412  g_Aa_ij_ptr++;
413  g_aa_ij_ptr++;
414  qfa_ij_ptr++;
415  qfb_ij_ptr++;
416  }
417 
418  return sum;
419  }
420 
421  ///
422  /// \return A new mu matrix.
423  ///
425  const value_type f_epsilon) ///< The F matrix boundary epsilon.
426  const override
427  {
428  static const auto em_iterations = size_t(100);
429  static const auto em_epsilon = value_type(1.0e-6);
430 
431  const auto f_min = value_type(0.0) + f_epsilon;
432  const auto f_max = value_type(1.0) - f_epsilon;
433 
434  const auto I = get_height();
435  const auto J = get_width();
436 
437  matrix_type mu (J, 1);
438 
439  for (size_t j = 0; j < J; j++)
440  {
441  auto & mu_j = mu[j] = value_type(0.5);
442 
443  for (auto iter = em_iterations; iter > 0; iter--)
444  {
445  const auto wu_j = value_type(1.0) - mu_j;
446  auto sum = value_type(0.0);
447 
448  for (size_t i = 0; i < I; i++)
449  {
450  const auto AA = _g_AA(i, j) * mu_j * mu_j;
451  const auto aa = _g_aa(i, j) * wu_j * wu_j;
452  const auto Aa = _g_Aa(i, j) * mu_j * wu_j
453  * value_type(2.0);
454 
455  sum += (value_type(2.0) * AA + Aa)
456  / (value_type(2.0) * (AA + Aa + aa));
457  }
458 
459  const auto previous_mu_j = mu_j;
460  mu_j = std::min(std::max(
461  f_min,
462  sum / value_type(I)),
463  f_max);
464 
465  if (std::fabs(previous_mu_j - mu_j) <= em_epsilon)
466  break;
467  }
468  }
469 
470  return mu;
471  }
472 
473  ///
474  /// \return The height of the matrix.
475  ///
476  inline virtual size_t get_height() const override
477  {
478  return _g_aa.get_height();
479  }
480 
481  ///
482  /// \return The major-major base matrix.
483  ///
484  inline const matrix_type & get_major_major_matrix() const
485  {
486  return _g_AA;
487  }
488 
489  ///
490  /// \return The major-minor base matrix.
491  ///
492  inline const matrix_type & get_major_minor_matrix() const
493  {
494  return _g_Aa;
495  }
496 
497  ///
498  /// \return The minor-minor base matrix.
499  ///
500  inline const matrix_type & get_minor_minor_matrix() const
501  {
502  return _g_aa;
503  }
504 
505  ///
506  /// \return The string representation of the size of the matrix.
507  ///
508  inline virtual std::string get_size_str() const override
509  {
510  return _g_aa.get_size_str();
511  }
512 
513  ///
514  /// \return The width of the matrix.
515  ///
516  inline virtual size_t get_width() const override
517  {
518  return _g_aa.get_width();
519  }
520 
521  ///
522  /// \return The string representation of the matrix.
523  ///
524  inline virtual std::string str() const override
525  {
526  std::ostringstream out;
527  out << _g_aa << '\n' << _g_Aa << '\n' << _g_AA;
528  return out.str();
529  }
530 
531  private:
532  matrix_type _g_aa; // minor-minor
533  matrix_type _g_Aa; // major-minor
534  matrix_type _g_AA; // major-major
535 
536  // --------------------------------------------------------------------
537  inline void _validate_sizes()
538  {
539  const auto h = _g_AA.get_height();
540  const auto w = _g_AA.get_width();
541 
542  const auto is_size_mismatch = false
543  || h != _g_Aa.get_height()
544  || h != _g_aa.get_height()
545  || w != _g_Aa.get_width()
546  || w != _g_aa.get_width();
547 
548  if (is_size_mismatch)
549  throw error("inconsistent matrix_type sizes in "
550  "likelihood genotype matrix_type.");
551  }
552 
553  // --------------------------------------------------------------------
554  struct qf_pair
555  {
556  value_type qfa_ij; // Q * F at i,j
557  value_type qfb_ij; // Q * (1-F) at i,j
558 
559  // ----------------------------------------------------------------
560  inline qf_pair(
561  const value_type qfa_ij_,
562  const value_type qfb_ij_)
563  : qfa_ij (qfa_ij_)
564  , qfb_ij (qfb_ij_)
565  {
566  }
567 
568  // ----------------------------------------------------------------
569  qf_pair(
570  const size_t i, // individual
571  const size_t j, // marker
572  const matrix_type & q,
573  const matrix_type & fa,
574  const matrix_type & fb)
575  : qfa_ij (0)
576  , qfb_ij (0)
577  {
578  assert(q.get_width() == fa.get_height());
579  assert(fa.is_size(fb));
580  assert(i < q.get_height());
581  assert(j < fa.get_width());
582 
583  const auto J = fa.get_width();
584  const auto K = fa.get_height();
585 
586  auto fa_mj_ptr = fa.get_data(0, j);
587  auto fb_mj_ptr = fb.get_data(0, j);
588  auto q_im_ptr = q.get_data(i, 0);
589  const auto q_im_end = q_im_ptr + K;
590 
591  while (q_im_ptr != q_im_end) // loop over m (0 < m < K)
592  {
593  const auto q_im = *q_im_ptr;
594  const auto fa_mj = *fa_mj_ptr;
595  const auto fb_mj = *fb_mj_ptr;
596 
597  qfa_ij += q_im * fa_mj;
598  qfb_ij += q_im * fb_mj;
599 
600  fa_mj_ptr += J; // stride is J across column of F
601  fb_mj_ptr += J;
602  q_im_ptr++; // stride is 1 across rows of Q
603  }
604  }
605 
606  // ----------------------------------------------------------------
607  value_type compute_f_ij(
608  const value_type g_aa_ij,
609  const value_type g_Aa_ij,
610  const value_type g_AA_ij)
611  const
612  {
613  auto f_ij = value_type(0);
614 
615  f_ij += g_AA_ij * qfa_ij * qfa_ij;
616  f_ij += g_aa_ij * qfb_ij * qfb_ij;
617  f_ij += g_Aa_ij * qfa_ij * qfb_ij * value_type(2);
618 
619  return f_ij;
620  }
621 
622  // ----------------------------------------------------------------
623  value_type compute_g_f_ijk(
624  const value_type g_aa_ij,
625  const value_type g_Aa_ij,
626  const value_type g_AA_ij,
627  const value_type q_ik)
628  const
629  {
630  auto g_f_ijk = value_type(0);
631 
632  g_f_ijk += value_type(2) * g_AA_ij * q_ik * qfa_ij;
633  g_f_ijk -= value_type(2) * g_aa_ij * q_ik * qfb_ij;
634  g_f_ijk += value_type(2) * g_Aa_ij * (
635  (qfb_ij * q_ik) - (qfa_ij * q_ik));
636 
637  return g_f_ijk;
638  }
639 
640  // ----------------------------------------------------------------
641  value_type compute_g_q_ijk(
642  const value_type g_aa_ij,
643  const value_type g_Aa_ij,
644  const value_type g_AA_ij,
645  const value_type fa_kj,
646  const value_type fb_kj)
647  const
648  {
649  auto g_q_ijk = value_type(0);
650 
651  g_q_ijk += value_type(2) * g_AA_ij * fa_kj * qfa_ij;
652  g_q_ijk += value_type(2) * g_aa_ij * fb_kj * qfb_ij;
653  g_q_ijk += value_type(2) * g_Aa_ij * (
654  (qfa_ij * fb_kj) + (qfb_ij * fa_kj));
655 
656  return g_q_ijk;
657  }
658  };
659  };
660 }
661 
662 #endif // JADE_LIKELIHOOD_GENOTYPE_MATRIX_HPP__
jade::basic_likelihood_genotype_matrix::basic_likelihood_genotype_matrix
basic_likelihood_genotype_matrix(const std::string &path)
Initializes a new instance of the class based on values from the specified file.
Definition: jade.likelihood_genotype_matrix.hpp:56
jade::basic_likelihood_genotype_matrix::get_major_minor_matrix
const matrix_type & get_major_minor_matrix() const
Definition: jade.likelihood_genotype_matrix.hpp:492
jade::basic_likelihood_genotype_matrix::get_size_str
virtual std::string get_size_str() const override
Definition: jade.likelihood_genotype_matrix.hpp:508
jade::basic_matrix::get_data
const value_type * get_data() const
Definition: jade.matrix.hpp:542
jade::basic_matrix::get_length
size_t get_length() const
Definition: jade.matrix.hpp:624
jade::basic_likelihood_genotype_matrix
A template class implementing operations for a likelihood genotype matrix type.
Definition: jade.likelihood_genotype_matrix.hpp:21
jade::basic_matrix::get_width
size_t get_width() const
Definition: jade.matrix.hpp:757
jade::basic_likelihood_genotype_matrix::matrix_type
basic_matrix< value_type > matrix_type
The matrix type.
Definition: jade.likelihood_genotype_matrix.hpp:27
jade::basic_likelihood_genotype_matrix::value_type
TValue value_type
The value type.
Definition: jade.likelihood_genotype_matrix.hpp:24
jade::basic_likelihood_genotype_matrix::get_width
virtual size_t get_width() const override
Definition: jade.likelihood_genotype_matrix.hpp:516
jade::basic_genotype_matrix
A template for an abstract class implementing operations for a genotype matrix.
Definition: jade.genotype_matrix.hpp:26
jade::basic_error::what
virtual const char * what() const
jade::basic_matrix::swap
void swap(basic_matrix &other)
Swaps this matrix and another matrix.
Definition: jade.matrix.hpp:1209
jade::basic_likelihood_genotype_matrix::basic_likelihood_genotype_matrix
basic_likelihood_genotype_matrix(const matrix_type &g_aa, const matrix_type &g_Aa, const matrix_type &g_AA)
Initializes a new instance of the class based on values from the specified matrices.
Definition: jade.likelihood_genotype_matrix.hpp:95
jade::basic_likelihood_genotype_matrix::str
virtual std::string str() const override
Definition: jade.likelihood_genotype_matrix.hpp:524
jade::basic_matrix::str
std::string str() const
Definition: jade.matrix.hpp:1199
jade::basic_matrix::get_size_str
std::string get_size_str() const
Definition: jade.matrix.hpp:735
jade::basic_likelihood_genotype_matrix::get_major_major_matrix
const matrix_type & get_major_major_matrix() const
Definition: jade.likelihood_genotype_matrix.hpp:484
jade::basic_matrix::is_size
bool is_size(const basic_matrix &other) const
Definition: jade.matrix.hpp:896
jade::basic_likelihood_genotype_matrix::compute_lle
virtual value_type compute_lle(const matrix_type &, const matrix_type &, const matrix_type &, const matrix_type &qfa, const matrix_type &qfb) const override
Definition: jade.likelihood_genotype_matrix.hpp:381
jade::basic_likelihood_genotype_matrix::basic_likelihood_genotype_matrix
basic_likelihood_genotype_matrix()
Initializes a new instance of the class.
Definition: jade.likelihood_genotype_matrix.hpp:32
jade::basic_matrix::get_height
size_t get_height() const
Definition: jade.matrix.hpp:603
jade::basic_likelihood_genotype_matrix::create_mu
virtual matrix_type create_mu(const value_type f_epsilon) const override
Definition: jade.likelihood_genotype_matrix.hpp:424
jade::basic_likelihood_genotype_matrix::get_minor_minor_matrix
const matrix_type & get_minor_minor_matrix() const
Definition: jade.likelihood_genotype_matrix.hpp:500
jade::basic_likelihood_genotype_matrix::as_lgm
basic_likelihood_genotype_matrix * as_lgm() override
Definition: jade.likelihood_genotype_matrix.hpp:117
jade::basic_likelihood_genotype_matrix::get_height
virtual size_t get_height() const override
Definition: jade.likelihood_genotype_matrix.hpp:476
jade::basic_likelihood_genotype_matrix::basic_likelihood_genotype_matrix
basic_likelihood_genotype_matrix(char const *const path)
Initializes a new instance of the class based on values from the specified file.
Definition: jade.likelihood_genotype_matrix.hpp:66
jade::basic_likelihood_genotype_matrix::as_lgm
const basic_likelihood_genotype_matrix * as_lgm() const override
Definition: jade.likelihood_genotype_matrix.hpp:109
jade::basic_likelihood_genotype_matrix::compute_derivatives_f
virtual void compute_derivatives_f(const matrix_type &q, const matrix_type &, const matrix_type &, const matrix_type &qfa, const matrix_type &qfb, const size_t j, matrix_type &d_vec, matrix_type &h_mat) const override
Computes the derivative vector and hessian matrix for a specified marker of the F matrix.
Definition: jade.likelihood_genotype_matrix.hpp:126
jade::basic_error
A template for a class representing an exception thrown from this namespace.
Definition: jade.error.hpp:20
jade::basic_matrix::set_values
void set_values(const value_type value)
Sets all values of the matrix to the specified value.
Definition: jade.matrix.hpp:1189
jade::basic_likelihood_genotype_matrix::compute_derivatives_q
virtual void compute_derivatives_q(const matrix_type &, 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 override
Computes the derivative vector and hessian matrix for a specified individual of the Q matrix.
Definition: jade.likelihood_genotype_matrix.hpp:241
jade::basic_matrix< value_type >
jade::basic_likelihood_genotype_matrix::basic_likelihood_genotype_matrix
basic_likelihood_genotype_matrix(std::istream &in)
Initializes a new instance of the class based on values from the specified input stream.
Definition: jade.likelihood_genotype_matrix.hpp:43