Developer documentation
Version 3.0.3-105-gd3941f44
Sn_scale_estimator.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 __math_Sn_scale_estimator_h__
18#define __math_Sn_scale_estimator_h__
19
20#include "types.h"
21#include "math/median.h"
22
23
24namespace MR {
25 namespace Math {
26
27
28 // Sn robust estimator of scale to get solid estimate of standard deviation:
29 // for details, see: Rousseeuw PJ, Croux C. Alternatives to the Median Absolute Deviation. Journal of the American Statistical Association 1993;88:1273–1283.
30
31 template <typename value_type = default_type>
33 public:
34 template <class VectorType>
35 value_type operator() (const VectorType& vec)
36 {
37 diff.resize (vec.size());
38 med_diff.resize (vec.size());
39 for (ssize_t j = 0; j < vec.size(); ++j) {
40 for (ssize_t i = 0; i < vec.size(); ++i)
41 diff[i] = abs (vec[i] - vec[j]);
43 }
44 return 1.1926 * Math::median (med_diff);
45 }
46
47 protected:
49
50 };
51
52 }
53}
54
55#endif
56
57
vector< value_type > med_diff
value_type operator()(const VectorType &vec)
#define NOMEMALIGN
Definition: memory.h:22
MR::default_type value_type
Definition: typedefs.h:33
Container::value_type median(Container &list)
Definition: median.h:45
Definition: base.h:24
constexpr std::enable_if< std::is_arithmetic< X >::value &&std::is_unsigned< X >::value, X >::type abs(X x)
Definition: types.h:297