Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/* MELODIC - Multivariate exploratory linear optimized decomposition into
independent components
melhlprfns.cc - misc functions
Christian F. Beckmann, FMRIB Analysis Group
Copyright (C) 1999-2013 University of Oxford */
/* CCOPYRIGHT */
#ifndef __MELODICHLPR_h
#define __MELODICHLPR_h
#include "newimage/newimageall.h"
#ifdef __APPLE__
#include <mach/mach.h>
#define mmsg(msg) { \
struct task_basic_info t_info; \
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; \
if (KERN_SUCCESS == task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t) &t_info, &t_info_count)) \
{ \
cout << " MEM: " << msg << " res: " << t_info.resident_size/1000000 << " virt: " << t_info.virtual_size/1000000 << "\n"; \
} \
}
#else
#define mmsg(msg) { \
cout << msg; \
}
#endif
using namespace NEWIMAGE;
namespace Melodic{
void update_mask(volume<float>& mask, Matrix& Data);
void del_vols(volume4D<float>& in, int howmany);
Matrix smoothColumns(const Matrix& inp);
Matrix calc_FFT(const Matrix& Mat, const bool logpwr = 0);
Matrix convert_to_pbsc(Matrix& Mat);
RowVector varnorm(Matrix& in, int dim = 30, float level = 1.6, int econ = 20000);
void varnorm(Matrix& in, const RowVector& vars);
RowVector varnorm(Matrix& in, SymmetricMatrix& Corr, int dim = 30, float level = 1.6, int econ = 20000);
Matrix SP2(const Matrix& in, const Matrix& weights, int econ = 20000);
void SP3(Matrix& in, const Matrix& weights);
RowVector Feta(int n1,int n2);
RowVector cumsum(const RowVector& Inp);
Matrix corrcoef(const Matrix& in1, const Matrix& in2);
Matrix corrcoef(const Matrix& in1, const Matrix& in2, const Matrix& part);
float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite);
float calc_white(const Matrix& tmpE, const RowVector& tmpD, const RowVector& PercEV, int dim, Matrix& white, Matrix& dewhite);
void calc_white(const Matrix& tmpE, const RowVector& tmpD, int dim, Matrix& param, Matrix& paramS, Matrix& white, Matrix& dewhite);
void calc_white(const Matrix& tmpE, const RowVector& tmpD, int dim, Matrix& white, Matrix& dewhite);
void calc_white(const SymmetricMatrix& Corr, int dim, Matrix& white, Matrix& dewhite);
void std_pca(const Matrix& Mat, SymmetricMatrix& Corr, Matrix& evecs, RowVector& evals, int econ = 20000);
void std_pca(const Matrix& Mat, const Matrix& weights, SymmetricMatrix& Corr, Matrix& evecs, RowVector& evals, int econ = 20000);
void em_pca(const Matrix& Mat, Matrix& evecs, RowVector& evals, int num_pc = 1, int iter = 20);
void em_pca(const Matrix& Mat, Matrix& guess, Matrix& evecs, RowVector& evals, int num_pc = 1, int iter = 20);
float rankapprox(const Matrix& Mat, Matrix& cols, Matrix& rows, int dim = 1);
RowVector krfact(const Matrix& Mat, Matrix& cols, Matrix& rows);
RowVector krfact(const Matrix& Mat, int colnum, Matrix& cols, Matrix& rows);
Matrix krprod(const Matrix& cols, const Matrix& rows);
Matrix krapprox(const Matrix& Mat, int size_col, int dim = 1);
void adj_eigspec(const RowVector& in, RowVector& out1, RowVector& out2, RowVector& out3, int& out4, int num_vox, float resels);
void adj_eigspec(const RowVector& in, RowVector& out1, RowVector& out2);
int ppca_dim(const Matrix& in, const Matrix& weights, Matrix& PPCA, RowVector& AdjEV, RowVector& PercEV, SymmetricMatrix& Corr, Matrix& tmpE, RowVector &tmpD, float resels, string which);
int ppca_dim(const Matrix& in, const Matrix& weights, Matrix& PPCA, RowVector& AdjEV, RowVector& PercEV, float resels, string which);
int ppca_dim(const Matrix& in, const Matrix& weights, float resels, string which);
ColumnVector ppca_select(Matrix& PPCAest, int& dim, int maxEV, string which);
Matrix ppca_est(const RowVector& eigenvalues, const int N1, const float N2);
Matrix ppca_est(const RowVector& eigenvalues, const int N);
ColumnVector acf(const ColumnVector& in, int order);
ColumnVector pacf(const ColumnVector& in, int maxorder = 1);
Matrix est_ar(const Matrix& Mat, int maxorder);
ColumnVector gen_ar(const ColumnVector& in, int maxorder = 1);
Matrix gen_ar(const Matrix& in, int maxorder);
Matrix gen_arCorr(const Matrix& in, int maxorder);
class basicGLM{
public:
//constructor
basicGLM(){}
//destructor
~basicGLM(){}
void olsfit(const Matrix& data, const Matrix& design,
const Matrix& contrasts, int DOFadjust = -1);
inline Matrix& get_t(){return t;}
inline Matrix& get_z(){return z;}
inline Matrix& get_p(){return p;}
inline Matrix& get_f_fmf(){return f_fmf;}
inline Matrix& get_pf_fmf(){return pf_fmf;}
inline Matrix& get_cbeta(){return cbeta;}
inline Matrix& get_beta(){return beta;}
inline Matrix& get_varcb(){return varcb;}
inline Matrix& get_sigsq(){return sigsq;}
inline Matrix& get_residu(){return residu;}
inline int get_dof(){return dof;}
private:
Matrix beta;
Matrix residu;
Matrix sigsq;
Matrix varcb;
Matrix cbeta;
Matrix f_fmf, pf_fmf;
int dof;
Matrix t;
Matrix z;
Matrix p;
};
// Matrix glm_ols(const Matrix& dat, const Matrix& design);
}
#endif