File: BrainModelSurfaceMetricCorrelationMatrix.h

package info (click to toggle)
caret 5.6.4~dfsg.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 31,904 kB
  • ctags: 28,901
  • sloc: cpp: 378,050; python: 6,718; ansic: 5,507; makefile: 333; sh: 46
file content (137 lines) | stat: -rw-r--r-- 4,150 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

#ifndef __BRAIN_MODEL_SURFACE_METRIC_CORRELATION_MATRIX_H__
#define __BRAIN_MODEL_SURFACE_METRIC_CORRELATION_MATRIX_H__

#include <cstdio>

#include "BrainModelAlgorithm.h"
#include "GiftiDataArrayReadListener.h"

class GiftiDataArray;
class GiftiDataArrayFile;
class MetricFile;

/**
 * Compute correlation of each metric column with all other metric columns.
 */
class BrainModelSurfaceMetricCorrelationMatrix : public BrainModelAlgorithm,
                                                        GiftiDataArrayReadListener {
   public:
      // constructor for files that have already been read
      BrainModelSurfaceMetricCorrelationMatrix(
           BrainSet* bs,
           MetricFile* inputMetricFileIn,
           const bool applyFisherZTransformFlagIn,
           const bool outputGiftiFlagIn,
           const bool parallelFlagIn);
      
      // create instance for processing that reads and writes files incrementally
      // in order to minimize memory usage
      BrainModelSurfaceMetricCorrelationMatrix(
                  const QString& inputMetricFileName,
                  const QString& outputMetricFileName,
                  const bool applyFisherZTransformFlagIn,
                  const bool outputGiftiFlagIn,
                  const bool parallelFlagIn);

      // destructor
      ~BrainModelSurfaceMetricCorrelationMatrix();
      
      // execute the algorithm                                                                                                   
      void execute() throw (BrainModelAlgorithmException);                                                
         
      // get the output metric file (if called caller is reponsible for DELETING
      // returned metric file.
      MetricFile* getOutputMetricFile();
      
      // get the output gifti file (if called caller is reponsible for DELETING
      // returned gifti file.
      GiftiDataArrayFile* getOutputGiftiFile();
      
      /// called for incremental reads
      QString dataArrayWasRead(GiftiDataArray* gda,
                            const int dataArrayIndex,
                            const int numberOfDataArrays);

   private:
      // constructor for i
      enum Mode {
         MODE_FILES_IN_MEMORY,
         MODE_METRIC_INCREMENTAL
      };

      // initialize variables
      void initialize();
      
      // load the data values
      void loadDataValues();
      
      // load the data values by incrementally reading the input metric file
      void loadDataValuesMetricIncremental() throw (BrainModelAlgorithmException);

      // create output metric file
      void createOutputMetricFile();
      
      // create output gifti file
      void createOutputGiftiFile();
      
      // compute the means
      void computeMeans();
      
      // compute the sum-squared
      void computeSumSquared();
      
      // compute the correlations
      void computeCorrelations(const Mode currentMode);
      
      // compute correlations for rows until there are no more rows to process
      void computeCorrelationsForRows();
      
      // compute correlations for rows until there are no more rows to process
      void computeCorrelationsForRowsMetricIncremental(FILE* file);

      const Mode mode;

      QString inputMetricFileName;

      MetricFile* inputMetricFile;
      
      GiftiDataArrayFile* outputGiftiFile;
      
      QString outputMetricFileName;

      MetricFile* outputMetricFile;
      
      float** outputDataArrayColumns;
      
      long inputNumRows;
      
      long inputNumColumns;
      
      long outputDimension;
      
      // All values in one-dim array
      float* dataValues;
      
      // mean of all column values for each row
      float* rowMeans;
      
      // sum-squared of all column values for each row
      double* rowSumSquared;
      
      const bool applyFisherZTransformFlag;
      
      bool deleteOutputMetricFlag;
      
      bool deleteOutputGiftiFlag;
      
      long nextRowToProcess;
      
      const bool outputGiftiFlag;

      const bool parallelFlag;
      
};

#endif //  __BRAIN_MODEL_SURFACE_METRIC_CORRELATION_MATRIX_H__