Developer documentation
Version 3.0.3-105-gd3941f44
convergence_check.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#include <iterator>
18#include <deque>
19#include <iterator>
20// #include <algorithm> // std::min_element
21#include "math/math.h"
22#include "math/median.h"
23// #include "math/gradient_descent.h"
24
25
26namespace MR
27{
28 using namespace MR::Math;
29 namespace Registration
30 {
31 namespace Transform
32 {
33 // convergence check using linear trend of each parameter during gradient descent
34 // we use double exponential smoothing to get rid of small oscillations
36 { MEMALIGN (DoubleExpSmoothSlopeCheck)
37 public:
39 stop_cnt (0),
40 iter_count (0),
41 len (0),
42 is_initialised (false) { }
43
44 void set_parameters (const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& slope_threshold,
45 default_type alpha_in,
46 default_type beta_in,
47 size_t buffer_length,
48 size_t min_iter_in);
49
50 bool go_on (const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& element);
51
52 bool last_b (Eigen::Matrix<default_type, Eigen::Dynamic, 1>& b) const;
53
54 bool last_s (Eigen::Matrix<default_type, Eigen::Dynamic, 1>& s) const;
55
56 void debug (const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& vec) const;
57
58 private:
59 size_t stop_cnt;
60 default_type alpha, beta;
61 Eigen::Matrix<default_type, Eigen::Dynamic, 1> thresh;
62 Eigen::Matrix<default_type, Eigen::Dynamic, 1> x0;
63 size_t buffer_len, min_iter;
64 size_t iter_count, len;
65 std::deque<Eigen::Matrix<default_type, Eigen::Dynamic, 1>> ds, db;
66 bool is_initialised;
67
68 inline bool check_all (const Eigen::Matrix<default_type, Eigen::Dynamic, 1>& vec) {
69 return (vec.array().abs() < thresh.array()).all();
70 }
71
72 };
73 }
74 }
75}
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228