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