40 #include "../network/networknode.h"
41 #include "../network/networkedge.h"
42 #include "../network/network.h"
51 #include <QtConcurrent>
57 #include <unsupported/Eigen/FFT>
63 using namespace CONNECTIVITYLIB;
64 using namespace Eigen;
65 using namespace UTILSLIB;
87 #ifdef EIGEN_FFTW_DEFAULT
88 fftw_make_planner_thread_safe();
93 if(connectivitySettings.isEmpty()) {
94 qDebug() <<
"CrossCorrelation::calculate - Input data is empty";
98 if(AbstractMetric::m_bStorageModeIsActive ==
false) {
99 connectivitySettings.clearIntermediateData();
105 int rows = connectivitySettings.at(0).matData.rows();
106 RowVectorXf rowVert = RowVectorXf::Zero(3);
108 for(
int i = 0; i < rows; ++i) {
109 rowVert = RowVectorXf::Zero(3);
111 if(connectivitySettings.getNodePositions().rows() != 0 && i < connectivitySettings.getNodePositions().rows()) {
112 rowVert(0) = connectivitySettings.getNodePositions().row(i)(0);
113 rowVert(1) = connectivitySettings.getNodePositions().row(i)(1);
114 rowVert(2) = connectivitySettings.getNodePositions().row(i)(2);
121 int iSignalLength = connectivitySettings.at(0).matData.cols();
122 int iNfft = connectivitySettings.getFFTSize();
124 QPair<MatrixXd, VectorXd> tapers = Spectral::generateTapers(iSignalLength, connectivitySettings.getWindowType());
143 QFuture<void> resultMat = QtConcurrent::map(connectivitySettings.getTrialData(),
145 resultMat.waitForFinished();
147 matDist /= connectivitySettings.size();
154 MatrixXd matWeight(1,1);
155 QSharedPointer<NetworkEdge> pEdge;
158 for(
int i = 0; i < matDist.rows(); ++i) {
159 for(j = i; j < matDist.cols(); ++j) {
160 matWeight << matDist(i,j);
162 pEdge = QSharedPointer<NetworkEdge>(
new NetworkEdge(i, j, matWeight));
164 finalNetwork.
getNodeAt(i)->append(pEdge);
165 finalNetwork.
getNodeAt(j)->append(pEdge);
166 finalNetwork.
append(pEdge);
183 const QPair<MatrixXd, VectorXd>& tapers)
190 RowVectorXd vecInputFFT, rowData;
191 RowVectorXcd vecResultFreq;
194 fft.SetFlag(fft.HalfSpectrum);
197 int iNRows = inputData.matData.rows();
201 if(inputData.vecTapSpectra.isEmpty()) {
202 int iNFreqs = int(floor(iNfft / 2.0)) + 1;
203 MatrixXcd matTapSpectrum(tapers.first.rows(), iNFreqs);
205 for (i = 0; i < iNRows; ++i) {
207 rowData.array() = inputData.matData.row(i).array() - inputData.matData.row(i).mean();
210 for(j = 0; j < tapers.first.rows(); j++) {
212 if (rowData.cols() < iNfft) {
213 vecInputFFT.setZero(iNfft);
214 vecInputFFT.block(0,0,1,rowData.cols()) = rowData.cwiseProduct(tapers.first.row(j));;
216 vecInputFFT = rowData.cwiseProduct(tapers.first.row(j));
220 fft.fwd(vecResultFreq, vecInputFFT, iNfft);
221 matTapSpectrum.row(j) = vecResultFreq * tapers.second(j);
224 inputData.vecTapSpectra.append(matTapSpectrum);
234 MatrixXd matDistTrial = MatrixXd::Zero(iNRows, iNRows);
235 RowVectorXcd vecResultXCor;
237 double denom = tapers.second.sum();
239 for(i = 0; i < inputData.vecTapSpectra.size(); ++i) {
240 vecResultFreq = inputData.vecTapSpectra.at(i).colwise().sum() / denom;
242 for(j = i; j < inputData.vecTapSpectra.size(); ++j) {
243 vecResultXCor = vecResultFreq.cwiseProduct(inputData.vecTapSpectra.at(j).colwise().sum() / denom);
245 fft.inv(vecInputFFT, vecResultXCor, iNfft);
247 vecInputFFT.maxCoeff(&idx);
249 matDistTrial(i,j) = vecInputFFT(idx);
260 if(matDist.rows() != matDistTrial.rows() || matDist.cols() != matDistTrial.cols()) {
261 matDist.resize(matDistTrial.rows(), matDistTrial.cols());
265 matDist += matDistTrial;
273 if(!m_bStorageModeIsActive) {
274 inputData.vecTapSpectra.clear();