MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
correlation.cpp
Go to the documentation of this file.
1//=============================================================================================================
35//=============================================================================================================
36// INCLUDES
37//=============================================================================================================
38
39#include "correlation.h"
40#include "../network/networknode.h"
41#include "../network/networkedge.h"
42#include "../network/network.h"
43
44//=============================================================================================================
45// QT INCLUDES
46//=============================================================================================================
47
48#include <QDebug>
49#include <QElapsedTimer>
50#include <QtConcurrent>
51
52//=============================================================================================================
53// EIGEN INCLUDES
54//=============================================================================================================
55
56#include <unsupported/Eigen/FFT>
57
58//=============================================================================================================
59// USED NAMESPACES
60//=============================================================================================================
61
62using namespace CONNECTIVITYLIB;
63using namespace Eigen;
64
65//=============================================================================================================
66// DEFINE GLOBAL METHODS
67//=============================================================================================================
68
69//=============================================================================================================
70// DEFINE MEMBER METHODS
71//=============================================================================================================
72
76
77//=============================================================================================================
78
80{
81// QElapsedTimer timer;
82// qint64 iTime = 0;
83// timer.start();
84
85 Network finalNetwork("COR");
86
87 if(connectivitySettings.isEmpty()) {
88 qDebug() << "Correlation::calculate - Input data is empty";
89 return finalNetwork;
90 }
91
92 finalNetwork.setSamplingFrequency(connectivitySettings.getSamplingFrequency());
93
94 //Create nodes
95 int rows = connectivitySettings.at(0).matData.rows();
96 RowVectorXf rowVert = RowVectorXf::Zero(3);
97
98 for(int i = 0; i < rows; ++i) {
99 rowVert = RowVectorXf::Zero(3);
100
101 if(connectivitySettings.getNodePositions().rows() != 0 && i < connectivitySettings.getNodePositions().rows()) {
102 rowVert(0) = connectivitySettings.getNodePositions().row(i)(0);
103 rowVert(1) = connectivitySettings.getNodePositions().row(i)(1);
104 rowVert(2) = connectivitySettings.getNodePositions().row(i)(2);
105 }
106
107 finalNetwork.append(NetworkNode::SPtr(new NetworkNode(i, rowVert)));
108 }
109
110// iTime = timer.elapsed();
111// qWarning() << "Preparation" << iTime;
112// timer.restart();
113
114 // Calculate connectivity matrix over epochs and average afterwards
115// double dScalingStep = 1.0/matDataList.size();
116// dataTemp.matInputData = dScalingStep * (i+1) * matDataList.at(i);
117
118 QFuture<MatrixXd> resultMat = QtConcurrent::mappedReduced(connectivitySettings.getTrialData(),
119 compute,
120 reduce);
121 resultMat.waitForFinished();
122
123 MatrixXd matDist = resultMat.result();
124
125// MatrixXd matDist;
126
127// for(int i = 0; i < connectivitySettings.getTrialData().size(); ++i) {
128// reduce(matDist, compute(connectivitySettings.getTrialData().at(i)));
129// }
130
131// matDist /= connectivitySettings.size();
132
133// iTime = timer.elapsed();
134// qWarning() << "ComputeSpectraPSDCSD" << iTime;
135// timer.restart();
136
137 //Add edges to network
138 MatrixXd matWeight(1,1);
139 QSharedPointer<NetworkEdge> pEdge;
140 int j;
141
142 for(int i = 0; i < matDist.rows(); ++i) {
143 for(j = i; j < matDist.cols(); ++j) {
144 matWeight << matDist(i,j);
145
146 pEdge = QSharedPointer<NetworkEdge>(new NetworkEdge(i, j, matWeight));
147
148 finalNetwork.getNodeAt(i)->append(pEdge);
149 finalNetwork.getNodeAt(j)->append(pEdge);
150 finalNetwork.append(pEdge);
151 }
152 }
153
154// iTime = timer.elapsed();
155// qWarning() << "Compute" << iTime;
156// timer.restart();
157
158 return finalNetwork;
159}
160
161//=============================================================================================================
162
164{
165 MatrixXd matDist = MatrixXd::Zero(inputData.matData.rows(), inputData.matData.rows());
166 RowVectorXd vecRow;
167 int j;
168
169 matDist = inputData.matData * inputData.matData.transpose();
170
171// for(int i = 0; i < inputData.matData.rows(); ++i) {
172// vecRow = inputData.matData.row(i);
173
174// for(j = i; j < inputData.matData.rows(); ++j) {
175// matDist(i,j) += (vecRow.dot(inputData.matData.row(j))/vecRow.cols());
176// }
177// }
178
179 return matDist;
180}
181
182//=============================================================================================================
183
184void Correlation::reduce(MatrixXd &resultData,
185 const MatrixXd &data)
186{
187 if(resultData.rows() != data.rows() || resultData.cols() != data.cols()) {
188 resultData.resize(data.rows(), data.cols());
189 resultData.setZero();
190 }
191
192 resultData += data;
193}
Correlation class declaration.
This class is a container for connectivity settings.
static Eigen::MatrixXd compute(const ConnectivitySettings::IntermediateTrialData &inputData)
static Network calculate(ConnectivitySettings &connectivitySettings)
static void reduce(Eigen::MatrixXd &resultData, const Eigen::MatrixXd &data)
This class holds information about a network, can compute a distance table and provide network metric...
Definition network.h:89
void append(QSharedPointer< NetworkEdge > newEdge)
void setSamplingFrequency(float fSFreq)
Definition network.cpp:492
QSharedPointer< NetworkNode > getNodeAt(int i)
Definition network.cpp:163
This class holds an object to describe the edge of a network.
Definition networkedge.h:80
This class holds an object to describe the node of a network.
Definition networknode.h:82
QSharedPointer< NetworkNode > SPtr
Definition networknode.h:85