Developer documentation
Version 3.0.3-105-gd3941f44
permtest.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 __stats_permtest_h__
18#define __stats_permtest_h__
19
20#include <memory>
21#include <mutex>
22
23#include "app.h"
24#include "progressbar.h"
25#include "thread.h"
26#include "thread_queue.h"
27#include "types.h"
28#include "math/math.h"
29#include "math/stats/glm.h"
30#include "math/stats/shuffle.h"
31#include "math/stats/typedefs.h"
32
33#include "stats/enhance.h"
34
35
36#define DEFAULT_NUMBER_PERMUTATIONS 5000
37#define DEFAULT_NUMBER_PERMUTATIONS_NONSTATIONARITY 5000
38
39
40namespace MR
41{
42 namespace Stats
43 {
44 namespace PermTest
45 {
46
47
48
52 using count_matrix_type = Eigen::Array<uint32_t, Eigen::Dynamic, Eigen::Dynamic>;
53
54
55
58 public:
59 PreProcessor (const std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator,
60 const std::shared_ptr<EnhancerBase> enhancer,
61 const default_type skew,
64
66
67 bool operator() (const Math::Stats::Shuffle&);
68
69 protected:
70 std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator;
71 std::shared_ptr<EnhancerBase> enhancer;
79 std::shared_ptr<std::mutex> mutex;
80 };
81
82
83
84
87 public:
88 Processor (const std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator,
89 const std::shared_ptr<EnhancerBase> enhancer,
95
96 ~Processor();
97
98 bool operator() (const Math::Stats::Shuffle&);
99
100 protected:
101 std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator;
102 std::shared_ptr<EnhancerBase> enhancer;
112 std::shared_ptr<std::mutex> mutex;
113 };
114
115
116
117
118 // Precompute the empircal test statistic for non-stationarity adjustment
119 void precompute_empirical_stat (const std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator,
120 const std::shared_ptr<EnhancerBase> enhancer,
121 const default_type skew,
122 matrix_type& empirical_statistic);
123
124
125
126
127 // Precompute the default statistic image and enhanced statistic. We need to precompute this for calculating the uncorrected p-values.
128 void precompute_default_permutation (const std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator,
129 const std::shared_ptr<EnhancerBase> enhancer,
130 const matrix_type& empirical_enhanced_statistic,
131 matrix_type& output_statistics,
132 matrix_type& output_zstats,
133 matrix_type& output_enhanced);
134
135
136
137 // Functions for running a large number of permutations
138 void run_permutations (const std::shared_ptr<Math::Stats::GLM::TestBase> stats_calculator,
139 const std::shared_ptr<EnhancerBase> enhancer,
140 const matrix_type& empirical_enhanced_statistic,
141 const matrix_type& default_enhanced_statistics,
142 const bool fwe_strong,
143 matrix_type& perm_dist,
144 count_matrix_type& perm_dist_contributions,
145 matrix_type& uncorrected_pvalues);
146
148
149 }
150 }
151}
152
153#endif
count_matrix_type enhanced_count
Definition: permtest.h:76
count_matrix_type & global_enhanced_count
Definition: permtest.h:74
const default_type skew
Definition: permtest.h:72
std::shared_ptr< EnhancerBase > enhancer
Definition: permtest.h:71
std::shared_ptr< Math::Stats::GLM::TestBase > stats_calculator
Definition: permtest.h:70
std::shared_ptr< std::mutex > mutex
Definition: permtest.h:79
matrix_type & global_enhanced_sum
Definition: permtest.h:73
count_matrix_type & global_uncorrected_pvalue_counter
Definition: permtest.h:110
std::shared_ptr< EnhancerBase > enhancer
Definition: permtest.h:102
count_matrix_type null_dist_contribution_counter
Definition: permtest.h:109
const matrix_type & empirical_enhanced_statistics
Definition: permtest.h:103
std::shared_ptr< std::mutex > mutex
Definition: permtest.h:112
const matrix_type & default_enhanced_statistics
Definition: permtest.h:104
count_matrix_type uncorrected_pvalue_counter
Definition: permtest.h:111
std::shared_ptr< Math::Stats::GLM::TestBase > stats_calculator
Definition: permtest.h:101
count_matrix_type & global_null_dist_contributions
Definition: permtest.h:108
MR::default_type value_type
Definition: typedefs.h:33
Eigen::Array< value_type, Eigen::Dynamic, 1 > vector_type
Definition: typedefs.h:35
Eigen::Matrix< value_type, Eigen::Dynamic, Eigen::Dynamic > matrix_type
Definition: typedefs.h:34
void precompute_default_permutation(const std::shared_ptr< Math::Stats::GLM::TestBase > stats_calculator, const std::shared_ptr< EnhancerBase > enhancer, const matrix_type &empirical_enhanced_statistic, matrix_type &output_statistics, matrix_type &output_zstats, matrix_type &output_enhanced)
Math::Stats::matrix_type matrix_type
Definition: permtest.h:51
Math::Stats::vector_type vector_type
Definition: permtest.h:50
Eigen::Array< uint32_t, Eigen::Dynamic, Eigen::Dynamic > count_matrix_type
Definition: permtest.h:52
Math::Stats::value_type value_type
Definition: permtest.h:49
void precompute_empirical_stat(const std::shared_ptr< Math::Stats::GLM::TestBase > stats_calculator, const std::shared_ptr< EnhancerBase > enhancer, const default_type skew, matrix_type &empirical_statistic)
void run_permutations(const std::shared_ptr< Math::Stats::GLM::TestBase > stats_calculator, const std::shared_ptr< EnhancerBase > enhancer, const matrix_type &empirical_enhanced_statistic, const matrix_type &default_enhanced_statistics, const bool fwe_strong, matrix_type &perm_dist, count_matrix_type &perm_dist_contributions, matrix_type &uncorrected_pvalues)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228
#define MEMALIGN(...)
Definition: types.h:185