55 using namespace UTILSLIB;
56 using namespace FIFFLIB;
57 using namespace Eigen;
75 : kind(p_FiffProj.kind)
76 , active(p_FiffProj.active)
77 , desc(p_FiffProj.desc)
78 , data(p_FiffProj.data)
106 QList<FiffProj>::Iterator it;
107 for(it = p_qListFiffProj.begin(); it != p_qListFiffProj.end(); ++it)
110 printf(
"\t%lld projection items activated.\n", p_qListFiffProj.size());
115 fiff_int_t
FiffProj::make_projector(
const QList<FiffProj>& projs,
const QStringList& ch_names, MatrixXd& proj,
const QStringList& bads, MatrixXd& U)
117 fiff_int_t nchan = ch_names.size();
120 printf(
"No channel names specified\n");
126 proj = MatrixXd::Identity(nchan,nchan);
127 fiff_int_t nproj = 0;
133 if (projs.size() == 0)
138 for (
k = 0;
k < projs.size(); ++
k)
143 nvec += projs[
k].data->nrow;
148 printf(
"FiffProj::make_projector - No projectors nproj=0\n");
153 printf(
"FiffProj::make_projector - No rows in projector matrices found nvec<=0\n");
160 MatrixXd vecs = MatrixXd::Zero(nchan,nvec);
162 fiff_int_t nonzero = 0;
163 qint32 p, c, i, j, v;
166 RowVectorXi sel(nchan);
167 RowVectorXi vecSel(nchan);
169 vecSel.setConstant(-1);
170 for (
k = 0;
k < projs.size(); ++
k)
176 QMap<QString, int> uniqueMap;
177 for(l = 0; l < one.
data->col_names.size(); ++l)
178 uniqueMap[one.
data->col_names[l] ] = 0;
180 if (one.
data->col_names.size() != uniqueMap.keys().size())
182 printf(
"Channel name list in projection item %d contains duplicate items",
k);
191 vecSel.resize(nchan);
193 vecSel.setConstant(-1);
195 for (c = 0; c < nchan; ++c)
197 for (i = 0; i < one.
data->col_names.size(); ++i)
199 if (QString::compare(ch_names.at(c),one.
data->col_names[i]) == 0)
202 for (j = 0; j < bads.size(); ++j)
204 if (QString::compare(ch_names.at(c),bads.at(j)) == 0)
210 if (!isBad && sel[p] != c)
220 sel.conservativeResize(p);
221 vecSel.conservativeResize(p);
226 for (v = 0; v < one.
data->nrow; ++v)
227 for (i = 0; i < p; ++i)
228 vecs(sel[i],nvec+v) = one.
data->data(v,vecSel[i]);
233 for (v = 0; v < one.
data->nrow; ++v)
235 onesize = sqrt((vecs.col(nvec+v).transpose()*vecs.col(nvec+v))(0,0));
238 vecs.col(nvec+v) = vecs.col(nvec+v)/onesize;
242 nvec += one.
data->nrow;
254 JacobiSVD<MatrixXd> svd(vecs.block(0,0,vecs.rows(),nvec), ComputeFullU);
256 VectorXd S = svd.singularValues();
257 MatrixXd t_U = svd.matrixU();
258 MNEMath::sort<double>(S, t_U);
264 for(
k = 0;
k < S.size(); ++
k)
265 if (S[
k]/S[0] > 1e-2)
268 U = t_U.block(0, 0, t_U.rows(), nproj);
273 proj -= U*U.transpose();