Developer documentation
Version 3.0.3-105-gd3941f44
regularisation.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#ifndef __dwi_tractography_sift2_regularisation_h__
18#define __dwi_tractography_sift2_regularisation_h__
19
20
22
23
24namespace MR
25{
26 namespace DWI
27 {
28 namespace Tractography
29 {
30 namespace SIFT2
31 {
32
33
34
35 template <typename value_type>
36 inline value_type tvreg (const value_type coeff, const value_type base)
37 {
38 return ((coeff <= base) ?
39 (Math::pow2(coeff - base)) :
40 (Math::pow2(std::exp(coeff) - std::exp(base))));
41 }
42 template <typename value_type>
43 inline value_type dtvreg_dcoeff (const value_type coeff, const value_type base)
44 {
45 return ((coeff <= base) ?
46 (value_type(2.0) * (coeff - base)) :
47 (value_type(2.0) * std::exp(coeff) * (std::exp(coeff) - std::exp(base))));
48 }
49 template <typename value_type>
50 inline value_type d2tvreg_dcoeff2 (const value_type coeff, const value_type base)
51 {
52 return ((coeff <= base) ?
53 (value_type(2.0)) :
54 (value_type(2.0) * std::exp(coeff) * ((value_type(2.0) * std::exp(coeff)) - std::exp(base))));
55 }
56 template <typename value_type>
57 inline value_type d3tvreg_dcoeff3 (const value_type coeff, const value_type base)
58 {
59 return ((coeff <= base) ?
60 (value_type(0.0)) :
61 (value_type(2.0) * std::exp(coeff) * ((value_type(4.0) * std::exp(coeff)) - std::exp(base))));
62 }
63 // A convenience function for LineSearchFunctor to reduce Math::exp() calls
64 inline void dxtvreg_dcoeffx (LineSearchFunctor::Result& result, const double coeff, const double expcoeff, const double multiplier, const double base, const double expbase)
65 {
66 if (coeff <= base) {
67 result.cost += multiplier * Math::pow2 (coeff - base);
68 result.first_deriv += multiplier * 2.0 * (coeff - base);
69 result.second_deriv += multiplier * 2.0;
70 } else {
71 result.cost += multiplier * Math::pow2 (expcoeff - expbase);
72 result.first_deriv += multiplier * 2.0 * expcoeff * (expcoeff - expbase);
73 result.second_deriv += multiplier * 2.0 * expcoeff * ((2.0*expcoeff) - expbase);
74 result.third_deriv += multiplier * 2.0 * expcoeff * ((4.0*expcoeff) - expbase);
75 }
76 }
77
78
79
80 }
81 }
82 }
83}
84
85
86#endif
87
88
constexpr T pow2(const T &v)
Definition: math.h:53
value_type dtvreg_dcoeff(const value_type coeff, const value_type base)
value_type d3tvreg_dcoeff3(const value_type coeff, const value_type base)
value_type tvreg(const value_type coeff, const value_type base)
value_type d2tvreg_dcoeff2(const value_type coeff, const value_type base)
void dxtvreg_dcoeffx(LineSearchFunctor::Result &result, const double coeff, const double expcoeff, const double multiplier, const double base, const double expbase)
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24