Developer documentation
Version 3.0.3-105-gd3941f44
zstatistic.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
18#ifndef __math_zstatistic_h__
19#define __math_zstatistic_h__
20
21#include <map>
22#include <mutex>
23
24#include "math/stats/typedefs.h"
25
26namespace MR
27{
28 namespace Math
29 {
30
31
32
33 default_type t2z (const default_type stat, const default_type dof);
34 default_type F2z (const default_type stat, const size_t rank, const default_type dof);
35
36
37
39 { MEMALIGN(Zstatistic)
40 public:
41 Zstatistic() { }
42
43 // Convert a t-statistic to a z-statistic
44 default_type t2z (const default_type t,
45 const size_t dof);
46
47 // Convert an F-statistic to a z-statistic
48 default_type F2z (const default_type F,
49 const size_t rank,
50 const size_t dof);
51
52 // Convert an Aspin-Welch v to a z-statistic
53 default_type v2z (const default_type v,
54 const default_type dof);
55
56 // Convert a G-statistic to a z-statistic
57 default_type G2z (const default_type G,
58 const size_t rank,
59 const default_type dof);
60
61 protected:
62
64 { MEMALIGN(LookupBase)
65 public:
66 virtual ~LookupBase() { }
67 using array_type = Eigen::Array<default_type, Eigen::Dynamic, 1>;
68 virtual default_type operator() (const default_type) const = 0;
69 protected:
70 // Function that will determine an interpolated value using
71 // the lookup table if the value lies within the pre-calculated
72 // range, or perform an explicit calculation if that is not
73 // the case
75 const default_type offset,
76 const default_type scale,
77 const array_type& data,
78 std::function<default_type(default_type)> func) const;
79 };
80
81 class Lookup_t2z : public LookupBase
83 public:
84 Lookup_t2z (const size_t dof);
85 default_type operator() (const default_type) const override;
86 private:
87 const size_t dof;
88 // Transform an input statistic value to an index location in the lookup table
89 const default_type offset, scale;
90 array_type data;
91 };
92
93 class Lookup_F2z : public LookupBase
95 public:
96 Lookup_F2z (const size_t rank, const size_t dof);
97 default_type operator() (const default_type) const override;
98 private:
99 const size_t rank, dof;
100 const default_type offset_upper, scale_upper;
101 array_type data_upper;
102 const default_type offset_lower, scale_lower;
103 array_type data_lower;
104 };
105
106 std::map<size_t, Lookup_t2z> t2z_data;
107 std::map<std::pair<size_t, size_t>, Lookup_F2z> F2z_data;
108 std::mutex mutex;
109
110 };
111
112
113
114
115 }
116}
117
118
119#endif
default_type interp(const default_type stat, const default_type offset, const default_type scale, const array_type &data, std::function< default_type(default_type)> func) const
std::map< size_t, Lookup_t2z > t2z_data
Definition: zstatistic.h:106
std::map< std::pair< size_t, size_t >, Lookup_F2z > F2z_data
Definition: zstatistic.h:107
index_type offset
Definition: loop.h:33
size_t rank(const MatrixType &M)
Definition: least_squares.h:48
mat4 scale(float x, float y, float z)
default_type F2z(const default_type stat, const size_t rank, const default_type dof)
default_type t2z(const default_type stat, const default_type dof)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
#define MEMALIGN(...)
Definition: types.h:185