CEBL  2.1
CEBLModel.hpp
Go to the documentation of this file.
1 /*
2 * CEBL : CSU EEG Brain-Computer Interface Lab
3 *
4 * Author: Jeshua Bratman - jeshuabratman@gmail.com
5 *
6 * This file is part of CEBL.
7 *
8 * CEBL is free software; you can redistribute it and/or modify it.
9 * We only ask that if you use our code that you cite the source in
10 * your project or publication.
11 *
12 * EEG Group (www.cs.colostate.edu/eeg)
13 * Department of Computer Science
14 * Colorado State University
15 *
16 */
17 
25 #ifndef CEBLMODEL_H
26 #define CEBLMODEL_H
27 
28 #include "CEBLIncludes.hpp"
29 #include "model/EEGData.hpp"
31 #include "Param.hpp"
32 
33 
34 //forward declarations of model internals
35 class ChannelsConfig;
36 class FilterConfig;
37 class FeaturesConfig;
38 class DecisionConfig;
39 class ClassifiersConfig;
40 class Training;
42 class DeviceConfig;
44 class DataSource;
45 class DataProcess;
46 class SessionManager;
47 class StringTable;
48 class Preferences;
49 
50 
51 class CEBLModel
52 {
53 private:
54  ChannelsConfig * channels;
55  DeviceConfig * device;
56  FileDataStreamConfig * file_data_stream_config;
57  FilterConfig * filters;
58  FeaturesConfig * features;
59  DecisionConfig * decisions;
60  ClassifiersConfig * classifiers;
61  Training * training;
62  RealTimeClassification * realtime;
63  DataSource *data_source;
64  DataProcess *data_process;
65  SessionManager * session_manager;
66  Preferences * preferences;
67  StringTable * string_table;
68 
69  //flags
70  bool initialized_successfully;
71 
72 public:
73  CEBLModel();
74  void InitModel(int ac, char **av);
75  ~CEBLModel();
76  bool initializedSuccessfully() {return initialized_successfully;}
77 
78  ChannelsConfig *getChannelsConfig() { return channels; }
79  DeviceConfig *getDeviceConfig() { return device; }
80  FileDataStreamConfig *getFileDataStreamConfig() { return file_data_stream_config; }
81  DataSource *getDataSource() { return data_source; }
82  DataProcess *getDataProcess() { return data_process; }
83  FilterConfig *getFilterConfig() { return filters; }
84  FeaturesConfig *getFeaturesConfig() { return features; }
85  DecisionConfig *getDecisionConfig() { return decisions; }
86  ClassifiersConfig *getClassifiersConfig() { return classifiers; }
87  Preferences *getPreferences() { return preferences; }
88  Training *getTraining() { return training; }
89 
90  //preferences
91  void preferencesProcessCL(int ac, char ** av);
92  void preferencesInitCEBL();
93  std::vector<std::string> preferencesGetPaths();
94 
100  void preferencesAddOption(string name,
101  string description,
102  char short_name='\0');
103 
104 
110  string preferencesGetOption(string name);
111 
112  //string table
113  const char *getString(string name);
114 
115  //======================================================================
116  // DATA SOURCE
117 
118  //----------------------------------------
119  //GETTING OPERATIONS
120 
126  EEGData dataReadRaw(int samples);
127 
133  EEGData dataRead(int samples);
134 
140 
146 
151  int dataSamplesAvailable();
152 
157  std::vector<string> dataGetSources();
158 
159 
164  int dataGetSource();
165 
170  bool dataSourceReady();
171 
176  bool dataIsStarted();
177 
182  bool dataGetStoreFlag();
183 
189 
195 
196 
197  //----------------------------------------
198  //SETTING OPERATIONS
199 
202  void dataClearStoredData();
203 
207  void dataSetStoreFlag(bool flag);
208 
212  void dataSetSource(int n);
213 
217  void dataSetSource(string source);
218 
221  void dataClearSamples();
222 
225  void dataStart();
226 
229  void dataStop();
230 
231  //======================================================================
232  //CHANNELS
233 
234  //----------------------------------------
235  //GETTING OPERATIONS
240  string channelsGetConfigFilename();
241 
247  bool channelsConfigFileExists(string filename);
248 
254  string channelsGetElectrodeName(int electrode);
255 
261  bool channelsGetElectrodeReference(int electrode);
262 
268  bool channelsGetElectrodeEnabled(int electrode);
269 
275 
281 
286  std::vector<string> channelsGetEnabledNames();
287 
293 
299 
305 
311 
312 
313 
314  //----------------------------------------
315  //SETTING OPERATIONS
316 
320  void channelsLoadFile(string filename);
321 
325  void channelsSaveFile(string filename);
326 
331  void channelsSetElectrodeName(int electrode, string name);
332 
337  void channelsSetElectrodeReference(int electrode, bool reference);
338 
343  void channelsSetElectrodeEnabled(int electrode, bool enabled);
344 
348  void channelsSetConfigurationFromString(string config);
349 
353  void processSetReferenceEnabled(bool enabled);
354 
358  void processSetRemoveEnabled(bool enabled);
359 
363  void processSetFilterEnabled(bool enabled);
364 
365  //----------------------------------------
366  //PROCESS DATA
367 
374 
380  EEGData& processData(EEGData &data);
381 
390  EEGData& processData(EEGData &data, bool remove_disabled, bool reference, bool filter);
391 
392  //======================================================================
393  //DEVICE
394 
395  //----------------------------------------
396  //GETTING OPERATIONS
397 
402  string deviceGetLocation();
403 
408  bool deviceIsReady();
409 
414  bool deviceExists();
415 
420  string deviceGetError();
421 
426  string deviceGetInquiry();
427 
432  int deviceGetSampleRate();
433 
438  int deviceGetBlockSize();
439 
440  //----------------------------------------
441  //SETTING OPERATIONS
442 
446  void deviceSetDeviceLocation(string filename);
447 
451  void deviceSetSampleRate(int sample_rate);
452 
456  void deviceSetBlockSize(int block_size);
457 
460  void deviceSearch();
461 
462  //======================================================================
463  //File Data Stream
464 
465  //----------------------------------------
466  //GETTING OPERATIONS
467 
473  string fileStreamGetFilename();
474 
479  bool fileStreamIsReady();
480 
486 
492 
498 
504 
510 
516 
522 
523 
524  //----------------------------------------
525  //SETTING OPERATIONS
526 
530  void fileStreamOpenFile(string filename);
531 
535  void fileStreamSetSampleRate(int sample_rate);
536 
537 
538  //======================================================================
539  //FILTER
540 
541  //----------------------------------------
542  //GETTING OPERATIONS
543 
548  std::vector<string> filterGetNameList();
549 
554  std::vector<string> filterGetPathList();
555 
563  bool filterIsTrained(string filter = "");
564 
569  int filterGetNumLags();
570 
575  string filterGetSelected();
576 
581  std::vector<int> filterGetSelectedComponents();
582 
588 
594 
595 
601  EEGData filterGetComponents(EEGData training_data);
602 
609 
615 
620  ublas::matrix<double> filterGetFilterMatrix();
621 
622  //----------------------------------------
623  //SETTING OPERATIONS
624 
630  void filterSetSelectedComponentsString(string components);
631 
635  void filterSetSelected(string filter = "");
636 
640  void filterTrain(EEGData training_data, string filter = "");
641 
645  void filterSetNumLags(int n);
646 
647 
648  //======================================================================
649  //FEATURES
650 
651  //----------------------------------------
652  //GETTING OPERATIONS
653 
658  std::vector<string> featuresGetNameList();
659 
664  std::vector<string> featuresGetPathList();
665 
672  bool featureIsTrained(string feature = "");
673 
678  string featuresGetSelected();
679 
685  std::map<std::string, CEBL::Param> featureGetParams(string feature = "");
686 
687  //----------------------------------------
688  //SETTING OPERATIONS
689 
693  void featuresSetSelected(string feature = "");
694 
698  void featureTrain(string feature = "");
699 
703  void featureReset(string feature = "");
704 
709  void featureSetParams(std::map<std::string, CEBL::Param> params, string feature = "");
710 
711  //USE FEATURE
712 
713 
714 
724 
731 
739  void featuresHalt();
740 
741  //======================================================================
742  //DECISION
743 
744  //----------------------------------------
745  //GETTING OPERATIONS
746 
751  std::vector<string> decisionGetNameList();
752 
757  std::vector<string> decisionGetPathList();
758 
759 
764  string decisionGetSelected();
765 
771  std::map<std::string, CEBL::Param> decisionGetParams(string decision = "");
772 
773  //----------------------------------------
774  //SETTING OPERATIONS
775 
779  void decisionSetSelected(string decision = "");
780 
785  void decisionSetParams(std::map<std::string, CEBL::Param> params, string decision="");
786 
787  //----------------------------------------
788  //DECISION OPERATIONS
789 
795  void decisionUpdateWithProbabilities(std::vector<std::vector<double> >probs);
796 
800  void decisionUpdateWithProbabilities(std::vector<double> probs);
801 
802 
807  void decisionUpdateWithClassification(ublas::vector<int> classes);
808 
809 
813  void decisionUpdateWithClassification(int cls);
814 
815 
819  void decisionInit(int num_classes);
820 
827  std::vector<double> decisionDecideClasses();
828 
829  //======================================================================
830  //CLASSIFIER
831 
832  //----------------------------------------
833  //GETTING OPERATIONS
834  std::vector<string> classifiersGetNameList();
835  std::vector<string> classifiersGetPathList();
836  bool classifierIsTrained(string classifier = "");
837  string classifiersGetSelected();
838  std::map<std::string, CEBL::Param> classifierGetParams(string feature = "");
839  bool classifierGetUseProbs();
842 
843  //----------------------------------------
844  //SETTING OPERATIONS
845  void classifierReset(CEBL::Param params, string classifier = "");
846  void classifiersSetSelected(string classifier = "");
847  void classifierTrain(EEGTrainingData &training_data, string classifier = "");
848  void classifierHaltTrain();
849  void classifierSetParams(std::map<std::string, CEBL::Param> params, string classifier = "");
850  void classifierSetUseProbs(bool flag);
851 
852  //USE CLASSIFIER
854  ublas::vector<int> classifierUse(EEGData &data);
855  std::vector<std::vector<double> > classifierGetLastProbs();
856 
857 
858  //======================================================================
859  // Training
860 
861  //----------------------------------------
862  //GETTING OPERATIONS
863 
868  std::vector<string> trainingGetClassLabels();
869 
875  string trainingGetClassLabel(int class_num);
876 
881  int trainingGetNumClasses();
882 
888 
894 
900 
906 
911  bool trainingDataIsLoaded();
912 
918 
923  string trainingGetDataFilename();
924 
929  bool trainingIsActive();
930 
935  bool trainingFailed();
936 
941  string trainingGetFailureMessage();
942 
947  bool trainingIsPaused();
948 
954 
960 
961 
967 
968 
969 
975 
976 
981  std::vector<double> trainingGetClassProportions();
982 
983  //----------------------------------------
984  //SETTING OPERATIONS
987  void trainingStart();
988 
991  void trainingStop();
992 
996  void trainingSetNumClasses(int n);
997 
1001  void trainingSetNumSequences(int n);
1002 
1006  void trainingSetSequenceLength(int n);
1007 
1011  void trainingSetPauseLength(int n);
1012 
1016  void trainingSetClassLabels(std::vector<string> labels);
1017 
1022  void trainingSetClassLabel(int class_number, string label);
1023 
1027  void trainingLoadData(string filename);
1028 
1031  void trainingClearData();
1032 
1036  void trainingSaveData(string filename);
1037 
1038 
1042  void trainingSetFeedbackEnabled(bool flag);
1043 
1044  //======================================================================
1045  // Real-Time Classification
1046 
1047  //----------------------------------------
1048  //GETTING OPERATIONS
1053  bool realtimeIsReady();
1054 
1059  bool realtimeLastTrainFailed();
1060 
1065  bool realtimeIsClassifying();
1066 
1071  std::vector<int> realtimeReadClassificationQueue();
1072 
1077  std::vector<double> realtimeGetClassProportions();
1078 
1083  std::vector<int> realtimePeekClassificationQueue() const;
1084 
1089  int realtimeGetSelectedClass() const;
1090 
1091 
1092  //----------------------------------------
1093  //SETTING OPERATIONS
1094 
1098 
1099  //CONTROL CLASSIFICATION
1102  void realtimeTrainClassifier();
1103 
1106  void realtimeStartClassifying();
1107 
1110  void realtimeStopClassifying();
1111 
1115 
1119 
1125 
1129 
1130  //======================================================================
1131  // SESSION SAVING and LOADING
1132 
1133  //----------------------------------------
1134  //GETTING OPERATIONS
1135 
1141  bool sessionShouldSaveAs();
1142 
1143 
1144  //----------------------------------------
1145  //SETTING OPERATIONS
1146 
1149  void sessionSave();
1150 
1154  void sessionSaveAs(string filename);
1155 
1159  void sessionLoad(string filename);
1160 
1161 
1162 
1163  //======================================================================
1164  // DATA FUNCTIONS
1171  EEGTrainingData dataLoadTrainingDataFile(string filename);
1172 
1173 
1174 };
1175 #endif
1176