CEBL  2.1
DataProcess.cpp
Go to the documentation of this file.
1 #include <cppR/cppR.hpp>
2 using namespace cppR;
3 
4 #include "DataProcess.hpp"
5 #include "../CEBLModel.hpp"
6 #include "ChannelsConfig.hpp"
7 #include "FilterConfig.hpp"
8 
9 
10 //----------------------------------------------------------------------
11 // CONSTRUCTORS / DESTRUCTORS
12 
13 
15 {
16  this->model = model;
17  this->remove_disabled = true;
18  this->reference = false;
19  this->filter = false;
20 }
21 
23 {}
24 
25 
26 
27 //----------------------------------------------------------------------
28 // PROCESS DATA
29 
31 {
32  EEGTrainingData processed_data;
33  EEGData temp;
34  processed_data.reserve(data.numClasses(),data.numSequences());
35  for(int cls = 0; cls < data.numClasses(); cls++)
36  {
37  for(int seq = 0; seq < data.numSequences(cls); seq++)
38  {
39  temp = data.get(cls,seq);
40  temp = process(temp);
41  processed_data.set(cls,seq,temp);
42  }
43  }
44  return processed_data;
45 }
46 
48 {
49  return process(data, remove_disabled, reference, filter);
50 }
51 
53  bool remove_disabled,
54  bool reference,
55  bool filter)
56 {
57  if(data.size1()==0 || data.size2()==0)
58  return data;
59 
60  if(remove_disabled)
61  {
62  //if the number of channels in data is equal to max,
63  // then we can simply mask off rows
64  if(data.nrow() == model->getChannelsConfig()->getMaxNumChannels())
65  {
66  data = cppR::rowMask(data.getMatrix(),
67  model->getChannelsConfig()->getEnabledMask());
68  }
69  //otherwise just return the first n rows
70  // where n is the number of enabled channels
71  else
72  {
73  int num_rows = model->getChannelsConfig()->getNumEnabled();
74  //make sure we aren't trying to select too many rows
75  if(data.size1() < num_rows)
76  num_rows = data.size1();
77  data = EEGData(cppR::submatrix(data.getMatrix(),0,num_rows-1,0,0));
78  }
79  }
80 
81  if(filter)
82  {
83 
84  //check if filter is even trained
85  if(model->getFilterConfig()->isTrained())
86  {
87  //do the filtering
88  try
89  {
90  data = model->getFilterConfig()->apply(data);
91  }
92  catch(const char *e)
93  {
94  throw DataProcessException("Failed to apply filter.");
95  }
96  }
97  else
98  {
99  throw DataProcessException("Filter cannot be applied because the"
100  + string(" ") +
101  "selected filter has not been trained.");
102  }
103  }
104 
105  return data;
106 }
107 
108 
109 
110