fastglmm
Massively scalable generalized linear mixed models
Toggle main menu visibility
Loading...
Searching...
No Matches
inst
include
glmmFitFeatures.h
Go to the documentation of this file.
1
#ifndef GLMM_FIT_FEATURES_H_
2
#define GLMM_FIT_FEATURES_H_
3
4
#include "
fastglmm_fit.h
"
5
#include "
spectralDecomp.h
"
6
7
using namespace
arma;
8
using namespace
std;
9
using namespace
fastglmmLib
;
10
11
namespace
fastglmmLib
{
12
13
// Order of template variables
14
// T1 Y
15
// T2 X
16
// T3 Z
17
template
<
typename
T1,
typename
T2,
typename
T3>
18
class
glmmFitFeatures
{
19
20
public
:
21
glmmFitFeatures
(
22
const
T1 &y,
23
const
T2 &X,
24
const
string
&family,
25
const
spectralDecomp<T3>
&dcmp,
26
const
vec &weights = {},
27
const
vec &offset = {},
28
const
double
&delta = -1,
29
const
double
&left = -10,
30
const
double
&right = 10,
31
const
double
&tol = 1e-5,
32
const
double
&tol_eta = 1e-7,
33
const
int
&maxit = 100,
34
const
double
&lambda = 0,
35
const
int
&nthreads = 1,
36
const
ModelDetail
md =
LOW
);
37
38
ModelFitGLMMList
eval
(
39
const
T2 &X_add_,
40
const
vector<string> &ids);
41
42
private
:
43
T1 y;
44
T2 X_shared;
45
string
family;
46
spectralDecomp<T3>
dcmp;
47
T3 U;
48
vec s, weights, offset;
49
double
delta, left, right, tol, tol_eta, lambda;
50
int
maxit, nthreads;
51
ModelDetail
md;
52
};
53
54
55
56
// constructor
57
template
<
typename
T1,
typename
T2,
typename
T3>
58
glmmFitFeatures<T1, T2, T3>::glmmFitFeatures
(
59
const
T1 &y,
60
const
T2 &X,
61
const
string
&family,
62
const
spectralDecomp<T3>
&dcmp,
63
const
vec &weights,
64
const
vec &offset,
65
const
double
&delta,
66
const
double
&left,
67
const
double
&right,
68
const
double
&tol,
69
const
double
&tol_eta,
70
const
int
&maxit,
71
const
double
&lambda,
72
const
int
&nthreads,
73
const
ModelDetail
md) :
74
y(y),
75
X_shared(X),
76
family(family),
77
dcmp(dcmp),
78
weights(weights),
79
offset(offset),
80
delta(delta),
81
left(left),
82
right(right),
83
tol(tol),
84
tol_eta(tol_eta),
85
maxit(maxit),
86
lambda(lambda),
87
nthreads(nthreads),
88
md(md)
89
{}
90
91
92
93
template
<
typename
T1,
typename
T2,
typename
T3>
94
ModelFitGLMMList
95
glmmFitFeatures<T1, T2, T3>::eval
(
const
T2 &X_add_,
96
const
vector<string> &ids){
97
98
int
n_tests = X_add_.n_cols;
99
100
// store results
101
ModelFitGLMMList
result(n_tests,
ModelFitGLMM
());
102
103
// Parallel part using Thread Building Blocks
104
tbb::task_arena limited_arena(nthreads);
105
limited_arena.execute([&] {
106
tbb::parallel_for(
107
tbb::blocked_range<int>(0, n_tests, 100),
108
[&](
const
tbb::blocked_range<int>& r){
109
110
disable_parallel_blas();
111
112
// iterate through responses
113
for
(
int
j = r.begin(); j != r.end(); ++j) {
114
115
// currently, only 1 cbind'd
116
mat X_combined = join_horiz(X_shared, X_add_.col(j));
117
118
// fits full model each time,
119
// for speed, need to save Y, X, scaled by U and s
120
fastglmm
fit =
fastglmm
(y, X_combined, dcmp, weights, offset, family, md, tol, tol_eta, maxit, lambda);
121
122
result.at(j) = fit.
get_result
();
123
result.at(j).
ID
= ids[j];
124
}
125
}); });
126
127
return
result;
128
}
129
130
131
132
}
// end namespace
133
134
135
136
#endif
fastglmmLib::ModelFitGLMM
Definition
ModelFit.h:355
fastglmmLib::ModelFit::ID
string ID
Definition
ModelFit.h:44
fastglmmLib::fastglmm
Definition
fastglmm_fit.h:37
fastglmmLib::fastglmm::get_result
ModelFitGLMM get_result()
Definition
fastglmm_fit.h:296
fastglmmLib::glmmFitFeatures::eval
ModelFitGLMMList eval(const T2 &X_add_, const vector< string > &ids)
Definition
glmmFitFeatures.h:95
fastglmmLib::glmmFitFeatures::glmmFitFeatures
glmmFitFeatures(const T1 &y, const T2 &X, const string &family, const spectralDecomp< T3 > &dcmp, const vec &weights={}, const vec &offset={}, const double &delta=-1, const double &left=-10, const double &right=10, const double &tol=1e-5, const double &tol_eta=1e-7, const int &maxit=100, const double &lambda=0, const int &nthreads=1, const ModelDetail md=LOW)
Definition
glmmFitFeatures.h:58
fastglmmLib::spectralDecomp
Definition
spectralDecomp.h:29
fastglmm_fit.h
fastglmmLib
Definition
CleanData.h:17
fastglmmLib::ModelDetail
ModelDetail
Definition
ModelFit.h:26
fastglmmLib::LOW
@ LOW
Definition
ModelFit.h:28
fastglmmLib::ModelFitGLMMList
vector< ModelFitGLMM > ModelFitGLMMList
Definition
ModelFit.h:396
spectralDecomp.h
Generated by
1.17.0