Developer documentation
Version 3.0.3-105-gd3941f44
shuffle.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_stats_shuffle_h__
19#define __math_stats_shuffle_h__
20
21#include "app.h"
22#include "progressbar.h"
23#include "types.h"
24
25#include "misc/bitset.h"
26
27#include "math/stats/typedefs.h"
28
29
30#define DEFAULT_NUMBER_SHUFFLES 5000
31#define DEFAULT_NUMBER_SHUFFLES_NONSTATIONARITY 5000
32
33
34namespace MR
35{
36 namespace Math
37 {
38 namespace Stats
39 {
40
41
42
43 // Generic command-line options:
44 // - Set nature of errors
45 // - Set number of shuffles (actual & nonstationarity correction)
46 // - Import permutations (actual & nonstationarity correction)
47 // - (future) Set exchangeability blocks
48
49 extern const char* error_types[];
50 App::OptionGroup shuffle_options (const bool include_nonstationarity, const default_type default_skew = 1.0);
51
52
53
54 class Shuffle
56 public:
57 size_t index;
59 };
60
61
62
65 public:
67 enum class error_t { EE, ISE, BOTH };
68
69 // First version reads command-line options in order to determine parameters prior to running initialise();
70 // second and third versions more-or-less call initialise() directly
71 Shuffler (const size_t num_rows,
72 const bool is_nonstationarity,
73 const std::string msg = "");
74
75 Shuffler (const size_t num_rows,
76 const size_t num_shuffles,
77 const error_t error_types,
78 const bool is_nonstationarity,
79 const std::string msg = "");
80
81 Shuffler (const size_t num_rows,
82 const size_t num_shuffles,
83 const error_t error_types,
84 const bool is_nonstationarity,
85 const index_array_type& eb_within,
86 const index_array_type& eb_whole,
87 const std::string msg = "");
88
89 // Don't store the full set of shuffling matrices;
90 // generate each as it is required, based on the more compressed representations
91 bool operator() (Shuffle& output);
92
93 size_t size() const { return nshuffles; }
94
95 // Go back to the first permutation
96 void reset();
97
98
99 private:
100 const size_t rows;
101 vector<PermuteLabels> permutations;
102 vector<BitSet> signflips;
103 size_t nshuffles, counter;
104 std::unique_ptr<ProgressBar> progress;
105
106
107 void initialise (const error_t error_types,
108 const bool nshuffles_explicit,
109 const bool is_nonstationarity,
110 const index_array_type& eb_within,
111 const index_array_type& eb_whole);
112
113
114
115 // For exchangeability blocks (either within or whole)
116 index_array_type load_blocks (const std::string& filename, const bool equal_sizes);
117
118
119 // For generating unique permutations
120 bool is_duplicate (const PermuteLabels&, const PermuteLabels&) const;
121 bool is_duplicate (const PermuteLabels&) const;
122
123 // Note that this function does not take into account identical rows and therefore generated
124 // permutations are not guaranteed to be unique wrt the computed test statistic.
125 // Providing the number of rows is large then the likelihood of generating duplicates is low.
126 void generate_random_permutations (const size_t num_perms,
127 const size_t num_rows,
128 const index_array_type& eb_within,
129 const index_array_type& eb_whole,
130 const bool include_default,
131 const bool permit_duplicates);
132
133 void generate_all_permutations (const size_t num_rows,
134 const index_array_type& eb_within,
135 const index_array_type& eb_whole);
136
137 void load_permutations (const std::string& filename);
138
139 // Similar functions required for sign-flipping
140 bool is_duplicate (const BitSet&) const;
141
142 void generate_random_signflips (const size_t num_signflips,
143 const size_t num_rows,
144 const index_array_type& blocks,
145 const bool include_default,
146 const bool permit_duplicates);
147
148 void generate_all_signflips (const size_t num_rows,
149 const index_array_type& blocks);
150
151
152 vector<vector<size_t>> indices2blocks (const index_array_type&) const;
153
154 };
155
156
157
158 }
159 }
160}
161
162#endif
a class to hold a named list of Option's
a class for storing bitwise information
Definition: bitset.h:43
matrix_type data
Definition: shuffle.h:58
Shuffler(const size_t num_rows, const size_t num_shuffles, const error_t error_types, const bool is_nonstationarity, const std::string msg="")
Shuffler(const size_t num_rows, const size_t num_shuffles, const error_t error_types, const bool is_nonstationarity, const index_array_type &eb_within, const index_array_type &eb_whole, const std::string msg="")
vector< size_t > PermuteLabels
Definition: shuffle.h:66
bool operator()(Shuffle &output)
Shuffler(const size_t num_rows, const bool is_nonstationarity, const std::string msg="")
size_t size() const
Definition: shuffle.h:93
#define NOMEMALIGN
Definition: memory.h:22
Eigen::Array< size_t, Eigen::Dynamic, 1 > index_array_type
Definition: typedefs.h:36
Eigen::Matrix< value_type, Eigen::Dynamic, Eigen::Dynamic > matrix_type
Definition: typedefs.h:34
const char * error_types[]
App::OptionGroup shuffle_options(const bool include_nonstationarity, const default_type default_skew=1.0)
Definition: base.h:24
double default_type
the default type used throughout MRtrix
Definition: types.h:228