diff --git a/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m b/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m index 8edc02e..031a77f 100644 --- a/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m +++ b/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m @@ -1,3 +1,23 @@ +% Abstract class for aggregation. Implement the functions for any +% fusion methodology (e.g. late fusion, VLAD, channel concatenation, etc.) +% +% Properties: +% featextractors: cell array with the the feature extractors to be used on +% the trials. Each cell contains a featextraction object, and the trials +% are given to each of the objects within the Experimenter class +% instanceSet: output - the aggregated features. Can be a simple +% InstanceSet or the extended FusionInstanceSet +% +% Functions: +%Implement this function to process the trials of each featextraction +%object in the cell array featextractors. It should store in the +%instanceSet property the features. +% obj.aggregate(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + classdef (Abstract) AggregatorBase < handle properties diff --git a/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m b/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m new file mode 100644 index 0000000..97e9faf --- /dev/null +++ b/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m @@ -0,0 +1,184 @@ +classdef CSPFilterBankWrapper < eegtoolkit.classification.ClassifierBase; + properties (Constant) + + end + properties + baseClassifier; + channel; + cspFilters; + filterBanks; + samplingRate; + end + + methods (Access = public) + function CSPFB = CSPFilterBankWrapper(filterBanks, samplingRate) + CSPFB.cspFilters = {}; + CSPFB.filterBanks = filterBanks; + CSPFB.samplingRate = samplingRate; + %filter_banks=[8 12; 12 16; 16 20;20 24;24 28]; +% if(isa(instanceSet,'eegtoolkit.util.RawSignalSet') +% CSP.instanceSet = instanceSet; +% else +% error('RawSignal extractor should be used with CSPWrapper'); +% end + end + + + function CSPFB = build(CSPFB) + % Builds the classification models + CSPFB.learnCSPMatrix(CSPFB.instanceSet.sMatrix,CSPFB.instanceSet.labels); + instanceLocal = CSPFB.extract(CSPFB.instanceSet.sMatrix); + CSPFB.baseClassifier.instanceSet = eegtoolkit.util.InstanceSet(instanceLocal,CSPFB.instanceSet.labels); + CSPFB.baseClassifier.build; + CSPFB.reset; + end + + function [output, probabilities, ranking] = classifyInstance(CSPFB,instance) + +% instance = CSP.extract + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + testInstances = CSPFB.extract(instance); + [output, probabilities, ranking] = CSPFB.baseClassifier.classifyInstance(testInstances); +% numModels = length(LSVM.models); +% [numinstance, ~] = size(testInstances); +% scores = zeros(numModels,numinstance); +% for i=1:numModels +% %predict using the stored models +% [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = t(:,1); +% end +% output = zeros(numinstance,1); +% probabilities = zeros(numinstance,1); +% ranking = scores; +% for i=1:numinstance +% %select the class with the highest probability +% [prob, idx] = max(scores(:,i)); +% uniqueLabels = unique(LSVM.instanceSet.getLabels); +% %output the label with highest probability +% output(i,1) = uniqueLabels(idx); +% %return the probability for the output label +% probabilities(i,1) = prob; +% end + end + + function CSPFB = reset(CSPFB) + % 'Resets' the classifier. +% CSP.models = {}; + end + + function configInfo = getConfigInfo(CSPFB) + configInfo = '\n'; + end + + + function time = getTime(CSPFB) + time = 0; + end + end + methods (Access = private) + function [] = learnCSPMatrix(CSPFB, sMatrix, labels) + %[trialsMat,labels] = ssveptoolkit.util.Trial.trialsCellToMat(in); + [numTrials,numChannels,numSamples] = size(sMatrix); +% numTrials = length(CSPFB.trials); +% [numChannels,numSamples] = size(CSPFB.trials{1}.signal); +% samplingRate = CSPFB.trials{1}.samplingRate; + filter_banks= CSPFB.filterBanks; + [nfb, mfb] = size(filter_banks); + + for iter_fb=1:nfb + + [b,a]=butter(3,filter_banks(iter_fb)/(CSPFB.samplingRate/2)); +% labels = zeros(numTrials,1); + %numTrials X numChannels X numSamples + trialsMat = permute(sMatrix,[2,3,1]); +% trialsMat = zeros(numChannels,numSamples,numTrials); +% for i = 1 : length(CSP_Feat.trials) +% for i_ch = 1:numChannels +% trialsMat(i_ch,:,i) = filtfilt(b,a,CSP_Feat.trials{i}.signal(i_ch,:)); +% end +% labels(i) = CSP_Feat.trials{i}.label; +% end + + trialsMat = permute(trialsMat,[2 1 3]); + [N1, Nch1, Ntr1] = size(trialsMat); + for i = 1:Nch1 + for j = 1:Ntr1 + trialsMat(:,i,j) = (trialsMat(:,i,j) - mean(trialsMat(:,i,j))); + end + end + x_train = trialsMat;%(:,:,CSP_Feat.trainIdx); + y_train = labels;%(CSP_Feat.trainIdx); + [N, Nch, Ntr] = size(x_train); + trialCov=zeros(Nch,Nch,Ntr); + for t=1:length(y_train) + E = x_train(:,:,t)'; + EE = E * E'; + trialCov(:,:,t) = EE ./ trace(EE); + end + for c=1:2 + covMat{c} = mean(trialCov(:,:,y_train == c),3); + end + [U, D] = eig(covMat{1},covMat{2},'qz'); + eigenvalues = diag(D); + [~, ind] = sort(eigenvalues, 'descend'); + U = U(:,ind); + CSPFB.cspFilters{iter_fb} = U'; +% CSP_Filter = U'; + end + %trialsMat2=zeros(N,3,Ntr); + + end + + function instances = extract(CSPFB,sMatrix) + trialsMat = permute(sMatrix,[2,3,1]); + trialsMat = permute(trialsMat,[2,1,3]); + [numTrials,numChannels,~] = size(sMatrix); + final_instances = zeros(numTrials, numChannels*length(CSPFB.filterBanks)); + for iter_fb=1:length(CSPFB.cspFilters) + for j = 1:size(trialsMat,3) + trialsMat(:,:,j) = (CSPFB.cspFilters{iter_fb}*trialsMat(:,:,j)')'; + end + + instances = zeros(numTrials, numChannels); + %labels = zeros(numTrials,1); + + for i=1:numTrials + + projectedTrial = trialsMat(:,:,i);%Filter * CSP_Feat.trials{i}.signal(:,i);% EEGSignals.x(:,:,t)'; + %generating the features as the log variance of the projected signals + variances = var(projectedTrial,0,1); + instances(i,:) = log(variances)'; + %labels(i,1) = floor(CSP_Feat.trials{i}.label); + end + final_instances(:,numChannels*(iter_fb-1)+1:numChannels*iter_fb) = instances; + % CSP_Feat.avgTime = toc/numTrials; +% CSP_Feat.instanceSet = ssveptoolkit.util.InstanceSet(final_instances,labels); + end + instances = final_instances; + end + + + + end + % [numTrials,numChannels,~] = size(sMatrix); + % sMatrix = permute(sMatrix,[3,2,1]); + % for i=1:size(sMatrix,3); + % sMatrix(:,:,i) = (CSPFB.cspFilter*sMatrix(:,:,i)')'; + % end + % instances = zeros(numTrials,numChannels); + % for i=1:numTrials + % projectedTrial = sMatrix(:,:,i); + % variances = var(projectedTrial,0,1); + % instances(i,:) = log(variances)'; + % end + % % instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + % end + %end +end + diff --git a/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m b/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m index db4f636..531957d 100644 --- a/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m +++ b/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m @@ -1,3 +1,30 @@ +% Abstract class for classification. Implement the functions for any +% classifier (e.g. LibSVM, LDA, MLR, RFs, Adaboost, etc.) +% +% Properties: +% instanceSet: the training/test set in an InstanceSet structure +% +% Functions: +%Implement this function to train the classification models. Each +%implementation should define the type of models that are to be trained by +%the build function. +% obj = obj.build(); +%Implement this function to apply the classification models to the provided +%instance, where instance is a matrix #instances x #features including the +%instances. The function should return the following three outputs; 1) +%output, the classified labels of the instances (#instances x 1), 2) +%probabilities, the probabilities for the output label (instances x 1) and +%3) ranking, a matrix #instances x #classes with the probabilities of each +%instance for each class (used for multiclass classification). +% [output, probabilities, ranking] = obj.classifyInstance(instance); +%Implement this function to reset the classifier (e.g. delete the stored +%classification models +% obj.reset(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + classdef (Abstract) ClassifierBase < handle properties @@ -5,7 +32,7 @@ end methods (Abstract = true) - obj = classifyInstance(obj); + [output, probabilities, ranking] = classifyInstance(obj,instance); obj = build(obj); obj = reset(obj); configInfo = getConfigInfo(obj); diff --git a/+eegtoolkit/+experiment/@Experimenter/Experimenter.m b/+eegtoolkit/+experiment/@Experimenter/Experimenter.m index ffb7846..9b28677 100644 --- a/+eegtoolkit/+experiment/@Experimenter/Experimenter.m +++ b/+eegtoolkit/+experiment/@Experimenter/Experimenter.m @@ -3,20 +3,22 @@ %Before running an experiment all the required properties must be set. % Required: % - session -% - transformer +% - featextraction % - evalMethod -% - classifier +% - classification % Optional: -% - extractor +% - featselection +% - aggregator +% - preprocessing % % to run the experiment execute the "run()" method. % Example: % experiment = eegtoolkit.experiment.Experimenter; % experiment.session = eegtoolkit.util.Session; % experiment.session.loadSubject(1); -% experiment.transformer = eegtoolkit.transformer.PWelchTransformer; -% experiment.extractor = eegtoolkit.extractor.FEASTFilter; -% experiment.classifier = eegtoolkit.classifier.LIBSVMClassifier; +% experiment.transformer = eegtoolkit.featextraction.PWelch; +% experiment.extractor = eegtoolkit.featselection.FEAST; +% experiment.classification = eegtoolkit.classification.LIBSVM; % experiment.evalMethod = experiment.evalMethod.EVAL_METHOD_LOSO; % experiment.run; % results = experiment.results; diff --git a/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m b/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m index 7e93bbf..647966b 100644 --- a/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m +++ b/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m @@ -1,3 +1,20 @@ +% Abstract class for feature extraction. Implement the functions for any +% feature extractor (e.g. PWelch, FFT, DWT, PYAR, etc.) +% +% Properties: +% instanceSet: Output - the features in an InstanceSet structure +% trials: Input - the signals in a cell of Trial structures +% +% Functions: +%Implement this function to extract the features from the input Trials +%and return the features in an instanceSet +% out = obj.extract(in); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + + classdef (Abstract) FeatureExtractionBase < handle %Base class for a feature transformer %For writing your own FeatureTransformer extend this class and diff --git a/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m b/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m index 3a77365..7101cc1 100644 --- a/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m +++ b/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m @@ -1,6 +1,21 @@ +% Abstract class for feature selection. Implement the functions for any +% feature selection method (e.g. PCA, SVD, FEAST, etc.) +% +% Properties: +% originalInstanceSet: Input - the original instanceSet with the features +% filteredInstanceSet: Output - the filtered instanceSet +% +% Functions: +%Implement this function to process the originalInstanceSet trials and +%return the filteredInstanceSet +% obj.compute(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + classdef (Abstract) FeatureSelectionBase < handle - %Base class for a FeatureExtractor - %Subclasses must implement the filter method + properties originalInstanceSet; % Input: The original dataset filteredInstanceSet; % Output: The filtered dataset diff --git a/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m b/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m index e426bd3..9abae63 100644 --- a/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m +++ b/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m @@ -1,3 +1,20 @@ +% Abstract class for preprocessing. Implement the functions for any +% preprocessing step (e.g. filtering, artifact removal, sub-sampling, +% rereferencing, etc. +% +% Properties: +% originalTrials: cell array with the trials to be processed +% processedTrials: the processed trials to be returned +% +% Functions: +%Implement this function to process the in trials and return the processed +%trials (out) +% out = obj.process(in); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + classdef PreprocessingBase < handle properties diff --git a/+eegtoolkit/+util/@InstanceSet/InstanceSet.m b/+eegtoolkit/+util/@InstanceSet/InstanceSet.m index 5e88dbd..fbe2fc4 100644 --- a/+eegtoolkit/+util/@InstanceSet/InstanceSet.m +++ b/+eegtoolkit/+util/@InstanceSet/InstanceSet.m @@ -1,6 +1,45 @@ +% A class for describing a set of instances and labels +% +% Properties: +% -instances : a m x n matrix where m = # instances and n = +% # features +% -labels: a m x 1 matrix containing the labels for each +% instance +% -K: a m x m matrix containing the kernel of the instances +% required only for the Fast vesrion of LibSVM +% +% Functions: +%Construct an instanceSet +% IS = eegtoolkit.util.InstanceSet(instances, labels) +%Compute the kernel +% K = IS.computeKernel(kernel, gamma, maxlag, scaleopt) +% kernel can be one of 'linear' (default),'rbf','chi','xcorr','spearman', +% 'correlation','cosine','euclidean','seuclidean','mahalanobis' +%Get the training kernel with indexes in the trainidx vector +% Ktrain = IS.getTrainKernel(trainidx) +%Get the test kernel with test indexes testidx and train indexes trainidx +% Ktest = IS.getTestKernel(trainidx, testidx) +%Get instances of specific indices in vector idx +% instance = IS.getInstancesWithIndices(idx) +%Get the instances of a specific label +% instances = IS.getInstancesForLabel(label) +%Get the indices corresponding to a specific label +% indices = IS.getInstanceIndicesForLabel(label) +%Get the instances including the labels as the last row +% dataset = getDataset(IS) +%Get the instances with specific indices. The last column of the matrix +%will contain the label. +% dataset = IS.getDatasetWithIndices(idx) +%Remove instances with specific indices. A new InstanceSet object is +%returned by this function without the specified instances +% IS = IS.removeInstancesWithIndices(idx) +% Write the dataset to a csv file +% IS.writeCSV(csvname) +%Write the dataset to a weka-readable file (arff). The whole dataset is +%written if the indices are not given (function called with 1 argument) +% IS.writeArff(fname, indices) + classdef InstanceSet - % A class for describing a set of instances and labels - properties (Access = public) instances; % the instances labels; % the labels @@ -10,10 +49,7 @@ methods function IS = InstanceSet(instances, labels) % obj = InstanceSet(instances, labels) - % -instances : a m x n matrix where m = instances and n = - % features - % -labels: a m x 1 matrix containing the labels for each - % instance + if nargin == 1 [~, cols] = size(instances); IS.instances = instances(:,1:cols-1); @@ -48,13 +84,13 @@ n = size(IS.instances,1); mOnes = ones(1,m); D = zeros(m,n); for i=1:n - yi = IS.instances(i,:); yiRep = yi( mOnes, : ); - s = yiRep + IS.instances; d = yiRep - IS.instances; - D(:,i) = sum( d.^2 ./ (s+eps), 2 ); + yi = IS.instances(i,:); yiRep = yi( mOnes, : ); + s = yiRep + IS.instances; d = yiRep - IS.instances; + D(:,i) = sum( d.^2 ./ (s+eps), 2 ); end D = D/2; K = exp(-gamma.*D); -% error('chi kernel not implemented yet'); + % error('chi kernel not implemented yet'); case 'xcorr' K = zeros(size(IS.instances,1)); if size(IS.instances,2) < 500 % if memory allows it go for the vectorized version @@ -169,7 +205,7 @@ function writeArff(IS, fname, indices) is1.writeArff(sprintf('test%s', fname)); is2.writeArff(sprintf('train%s',fname)); return; - else + else data = IS.getDataset(); end % data = horzcat(IS.instances,floor(IS.labels)); diff --git a/+eegtoolkit/+util/@Session/Session.m b/+eegtoolkit/+util/@Session/Session.m index bc532fa..eb89757 100644 --- a/+eegtoolkit/+util/@Session/Session.m +++ b/+eegtoolkit/+util/@Session/Session.m @@ -1,10 +1,17 @@ % SESSION class % Session I/O, splitting sessions into trials and applying filters % -% Usage: +% Properties: +% trials: A cell array with the Trials of the loaded sessions. +% filt: Filter to be applied when data is loaded +% sessions: Cell array with the filenames of the dataset +% subjectids: Vector with the subject ids corresponding to the loaded trials +% sessionids: Vector with the session ids corresponding to the loaded trials +% +% Functions: %init a session % session = eegtoolkit.util.Session(); -%init a session with a filter (created with 'filterbuilder' function) +%init a session with a filter (created with 'filterbuilder') % session = eegtoolkit.util.Session(filt); %load trials for a subject % session.loadSubject(subjectid); @@ -18,6 +25,14 @@ % session.applyFilter(filt); % % +%DATASETS +%1. SSVEP Dataset I (SINGLE) +%2. SSVEP Dataset II (MULTI) +%3. SSVEP Dataset III (EPOC-MULTI) +%4. SSVEP Dataset SCCN +%5. ERRP Dataset +%6. MI Dataset + classdef Session < handle properties (Constant) @@ -31,13 +46,7 @@ sessionids; end - %DATASETS - %1. SSVEP Dataset I (SINGLE) - %2. SSVEP Dataset II (MULTI) - %3. SSVEP Dataset III (EPOC-MULTI) - %4. SSVEP Dataset SCCN - %5. ERRP Dataset - %6. MI Dataset + methods (Access = public) function S = Session() %S = eegtoolkit.util.Session(); @@ -209,7 +218,7 @@ S.sessions{3,11,3} = 'U011c'; S.sessions{3,11,4} = 'U011d'; S.sessions{3,11,5} = 'U011e'; - + %SCCN dataset S.sessions{4,1,1} = 's1'; S.sessions{4,2,1} = 's2'; @@ -254,7 +263,7 @@ S.sessions{7,9,2} = 'B09T.mat'; %MI dataset -% S.sessions{6,1,1} = ; + % S.sessions{6,1,1} = ; S.subjectids = []; @@ -360,7 +369,7 @@ end case 5 %ERRP Dataset - SAMPLING_RATE = 256; + SAMPLING_RATE = 256; %range of trial in milliseconds based on the stimulus %event range = [200,800]; diff --git a/+eegtoolkit/+util/@Trial/Trial.m b/+eegtoolkit/+util/@Trial/Trial.m index de32cd1..f3a4b06 100644 --- a/+eegtoolkit/+util/@Trial/Trial.m +++ b/+eegtoolkit/+util/@Trial/Trial.m @@ -1,5 +1,20 @@ +% A class that defines a Trial +% +% Properties: +% signal: the signal of the trial, matrix m x n, where m is the channels +% and n the samples +% label: a label for the trial (typically assigned with the frequency that is calculated using DIN data) +% duration: the duration of the trial in seconds +% samplingRate: the samling rate used to capture the signal +% subjectid: the subject from whom the trial was recorded +% sessionid: the session id +% type: the type of the trial. Supported types of trials: +% SSVEP = 1; +% ERRP = 2; +% MI = 3; + classdef Trial < handle - %A class that defines a Trial + properties (Constant) %Type of trial diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.html b/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.html new file mode 100644 index 0000000..f4dcd71 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.html @@ -0,0 +1,101 @@ + + + + Description of AggregatorBase + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @AggregatorBase > AggregatorBase.m
+ + + +

AggregatorBase +

+ +

PURPOSE ^

+
Abstract class for aggregation. Implement the functions for any
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Abstract class for aggregation. Implement the functions for any
+ fusion methodology (e.g. late fusion, VLAD, channel concatenation, etc.)
+ 
+ Properties:
+ featextractors: cell array with the the feature extractors to be used on
+ the trials. Each cell contains a featextraction object, and the trials
+ are given to each of the objects within the Experimenter class
+ instanceSet: output - the aggregated features. Can be a simple
+ InstanceSet or the extended FusionInstanceSet
+ 
+ Functions:
+Implement this function to process the trials of each featextraction
+object in the cell array featextractors. It should store in the
+instanceSet property the features.
+   obj.aggregate();
+Info & run time so that the experiments are easily documented. configInfo
+is a string with the configuration information and time is of type double.
+   configInfo = obj.getConfigInfo();
+   time = obj.getTime();
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + + +

DOWNLOAD ^

+

AggregatorBase.m

+

SOURCE CODE ^

+
0001 % Abstract class for aggregation. Implement the functions for any
+0002 % fusion methodology (e.g. late fusion, VLAD, channel concatenation, etc.)
+0003 %
+0004 % Properties:
+0005 % featextractors: cell array with the the feature extractors to be used on
+0006 % the trials. Each cell contains a featextraction object, and the trials
+0007 % are given to each of the objects within the Experimenter class
+0008 % instanceSet: output - the aggregated features. Can be a simple
+0009 % InstanceSet or the extended FusionInstanceSet
+0010 %
+0011 % Functions:
+0012 %Implement this function to process the trials of each featextraction
+0013 %object in the cell array featextractors. It should store in the
+0014 %instanceSet property the features.
+0015 %   obj.aggregate();
+0016 %Info & run time so that the experiments are easily documented. configInfo
+0017 %is a string with the configuration information and time is of type double.
+0018 %   configInfo = obj.getConfigInfo();
+0019 %   time = obj.getTime();
+0020 
+0021 classdef (Abstract) AggregatorBase < handle
+0022     
+0023     properties
+0024         featextractors;
+0025         instanceSet;
+0026     end
+0027     
+0028     methods (Abstract = true)
+0029         obj = aggregate(obj);
+0030         configInfo = getConfigInfo(obj);
+0031         time = getTime(obj);
+0032     end
+0033     
+0034 end
+0035
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m b/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m new file mode 100644 index 0000000..031a77f --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/AggregatorBase.m @@ -0,0 +1,35 @@ +% Abstract class for aggregation. Implement the functions for any +% fusion methodology (e.g. late fusion, VLAD, channel concatenation, etc.) +% +% Properties: +% featextractors: cell array with the the feature extractors to be used on +% the trials. Each cell contains a featextraction object, and the trials +% are given to each of the objects within the Experimenter class +% instanceSet: output - the aggregated features. Can be a simple +% InstanceSet or the extended FusionInstanceSet +% +% Functions: +%Implement this function to process the trials of each featextraction +%object in the cell array featextractors. It should store in the +%instanceSet property the features. +% obj.aggregate(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + +classdef (Abstract) AggregatorBase < handle + + properties + featextractors; + instanceSet; + end + + methods (Abstract = true) + obj = aggregate(obj); + configInfo = getConfigInfo(obj); + time = getTime(obj); + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.dot b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.dot new file mode 100644 index 0000000..ed68ee0 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + AggregatorBase -> AggregatorBase; + + AggregatorBase [URL="AggregatorBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.html b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.html new file mode 100644 index 0000000..4fd7b72 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@AggregatorBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@AggregatorBase >
+

Dependency Graph for +eegtoolkit/+aggregation/@AggregatorBase

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@AggregatorBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.map b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.map new file mode 100644 index 0000000..7ed2ecc --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.png b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.png new file mode 100644 index 0000000..f61dccb Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@AggregatorBase/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@AggregatorBase/index.html b/doc/+eegtoolkit/+aggregation/@AggregatorBase/index.html new file mode 100644 index 0000000..ddd7858 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@AggregatorBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@AggregatorBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@AggregatorBase >
+ +

Index for +eegtoolkit/+aggregation/@AggregatorBase

+ +

Matlab files in this directory:

+ +
 AggregatorBaseAbstract class for aggregation. Implement the functions for any
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.html b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.html new file mode 100644 index 0000000..663856b --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.html @@ -0,0 +1,83 @@ + + + + Description of ChannelAveraging + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @ChannelAveraging > ChannelAveraging.m
+ + + +

ChannelAveraging +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ChannelAveraging.m

+

SOURCE CODE ^

+
0001 classdef ChannelAveraging < eegtoolkit.aggregation.AggregatorBase;
+0002     
+0003     properties
+0004     end
+0005     
+0006     methods
+0007         
+0008         function CA = ChannelAveraging(CA)
+0009         end
+0010         
+0011         function CA = aggregate(CA)
+0012             numExtr = length(CA.featextractors);
+0013             numInstances = CA.featextractors{1}.getInstanceSet.getNumInstances;
+0014             numFeatures = CA.featextractors{1}.getInstanceSet.getNumFeatures;
+0015             fused = zeros(numInstances,numFeatures,numExtr);
+0016             for i=1:numExtr
+0017                 fused(:,:,i) = CA.featextractors{i}.getInstances;
+0018             end
+0019             fusedMean = mean(fused,3);
+0020             CA.instanceSet = eegtoolkit.util.InstanceSet(fusedMean,CA.featextractors{1}.getLabels);
+0021         end
+0022         
+0023         function configInfo = getConfigInfo(CA)
+0024             configInfo = 'ChannelAveraging';
+0025         end
+0026         
+0027         function time = getTime(CA)
+0028             time = 0;
+0029         end
+0030     end
+0031     
+0032 end
+0033
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.m b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.m new file mode 100644 index 0000000..70025af --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/ChannelAveraging.m @@ -0,0 +1,33 @@ +classdef ChannelAveraging < eegtoolkit.aggregation.AggregatorBase; + + properties + end + + methods + + function CA = ChannelAveraging(CA) + end + + function CA = aggregate(CA) + numExtr = length(CA.featextractors); + numInstances = CA.featextractors{1}.getInstanceSet.getNumInstances; + numFeatures = CA.featextractors{1}.getInstanceSet.getNumFeatures; + fused = zeros(numInstances,numFeatures,numExtr); + for i=1:numExtr + fused(:,:,i) = CA.featextractors{i}.getInstances; + end + fusedMean = mean(fused,3); + CA.instanceSet = eegtoolkit.util.InstanceSet(fusedMean,CA.featextractors{1}.getLabels); + end + + function configInfo = getConfigInfo(CA) + configInfo = 'ChannelAveraging'; + end + + function time = getTime(CA) + time = 0; + end + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.dot b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.dot new file mode 100644 index 0000000..361dae9 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ChannelAveraging -> ChannelAveraging; + + ChannelAveraging [URL="ChannelAveraging.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.html b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.html new file mode 100644 index 0000000..af77ae6 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@ChannelAveraging + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelAveraging >
+

Dependency Graph for +eegtoolkit/+aggregation/@ChannelAveraging

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@ChannelAveraging + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.map b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.map new file mode 100644 index 0000000..a81e902 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.png b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.png new file mode 100644 index 0000000..eea5702 Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@ChannelAveraging/index.html b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/index.html new file mode 100644 index 0000000..0ba6bd3 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelAveraging/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@ChannelAveraging + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelAveraging >
+ +

Index for +eegtoolkit/+aggregation/@ChannelAveraging

+ +

Matlab files in this directory:

+ +
 ChannelAveraging
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.html b/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.html new file mode 100644 index 0000000..10b2ede --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.html @@ -0,0 +1,84 @@ + + + + Description of ChannelConcat + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @ChannelConcat > ChannelConcat.m
+ + + +

ChannelConcat +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ChannelConcat.m

+

SOURCE CODE ^

+
0001 classdef ChannelConcat < eegtoolkit.aggregation.AggregatorBase;
+0002     
+0003     properties
+0004     end
+0005     
+0006     methods
+0007         
+0008         function CC = ChannelConcat(CC)
+0009         end
+0010         
+0011         function CC = aggregate(CC)
+0012             numExtract = length(CC.featextractors);
+0013             fused = [];
+0014             for i=1:numExtract
+0015                 fused = horzcat(fused,CC.featextractors{i}.getInstances);
+0016             end
+0017 %             [~,y] = size(fused);
+0018 %             ind = randperm(y);
+0019 %             fused = fused(:,ind);
+0020             CC.instanceSet = eegtoolkit.util.InstanceSet(fused,CC.featextractors{1}.getLabels);
+0021         end
+0022         
+0023         function configInfo = getConfigInfo(CC)
+0024             configInfo = 'ChannelConcat';
+0025         end
+0026         
+0027                 
+0028         function time = getTime(CC)
+0029             time = 0;
+0030         end
+0031     end
+0032     
+0033 end
+0034
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.m b/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.m new file mode 100644 index 0000000..dacd315 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/ChannelConcat.m @@ -0,0 +1,34 @@ +classdef ChannelConcat < eegtoolkit.aggregation.AggregatorBase; + + properties + end + + methods + + function CC = ChannelConcat(CC) + end + + function CC = aggregate(CC) + numExtract = length(CC.featextractors); + fused = []; + for i=1:numExtract + fused = horzcat(fused,CC.featextractors{i}.getInstances); + end +% [~,y] = size(fused); +% ind = randperm(y); +% fused = fused(:,ind); + CC.instanceSet = eegtoolkit.util.InstanceSet(fused,CC.featextractors{1}.getLabels); + end + + function configInfo = getConfigInfo(CC) + configInfo = 'ChannelConcat'; + end + + + function time = getTime(CC) + time = 0; + end + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.dot b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.dot new file mode 100644 index 0000000..12c8d7e --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ChannelConcat -> ChannelConcat; + + ChannelConcat [URL="ChannelConcat.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.html b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.html new file mode 100644 index 0000000..c193196 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@ChannelConcat + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelConcat >
+

Dependency Graph for +eegtoolkit/+aggregation/@ChannelConcat

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@ChannelConcat + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.map b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.map new file mode 100644 index 0000000..50dc87b --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.png b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.png new file mode 100644 index 0000000..f487ec7 Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@ChannelConcat/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@ChannelConcat/index.html b/doc/+eegtoolkit/+aggregation/@ChannelConcat/index.html new file mode 100644 index 0000000..35ef929 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelConcat/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@ChannelConcat + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelConcat >
+ +

Index for +eegtoolkit/+aggregation/@ChannelConcat

+ +

Matlab files in this directory:

+ +
 ChannelConcat
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.html b/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.html new file mode 100644 index 0000000..a4fb8e1 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.html @@ -0,0 +1,83 @@ + + + + Description of ChannelRatio + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @ChannelRatio > ChannelRatio.m
+ + + +

ChannelRatio +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ChannelRatio.m

+

SOURCE CODE ^

+
0001 classdef ChannelRatio < eegtoolkit.aggregation.AggregatorBase;
+0002     
+0003     properties
+0004     end
+0005     
+0006     methods
+0007         
+0008         function CR = ChannelRatio(CR)
+0009         end
+0010         
+0011         function CR = aggregate(CR)
+0012             numExtract = length(CR.featextractors);
+0013             if numExtract ~=2
+0014                 error ('ChannelRatio: Number of transformers should be 2');
+0015             end
+0016             in1 = CR.featextractors{1}.getInstances;
+0017             in2 = CR.featextractors{2}.getInstances;
+0018             ratio = in1./in2;
+0019             CR.instanceSet = eegtoolkit.util.InstanceSet(ratio,CR.featextractors{1}.getLabels);
+0020         end
+0021         
+0022         function configInfo = getConfigInfo(CR)
+0023             configInfo = 'ChannelRatio';
+0024         end
+0025         
+0026                 
+0027         function time = getTime(CR)
+0028             time = 0;
+0029         end
+0030     end
+0031     
+0032 end
+0033
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.m b/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.m new file mode 100644 index 0000000..3ac766a --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/ChannelRatio.m @@ -0,0 +1,33 @@ +classdef ChannelRatio < eegtoolkit.aggregation.AggregatorBase; + + properties + end + + methods + + function CR = ChannelRatio(CR) + end + + function CR = aggregate(CR) + numExtract = length(CR.featextractors); + if numExtract ~=2 + error ('ChannelRatio: Number of transformers should be 2'); + end + in1 = CR.featextractors{1}.getInstances; + in2 = CR.featextractors{2}.getInstances; + ratio = in1./in2; + CR.instanceSet = eegtoolkit.util.InstanceSet(ratio,CR.featextractors{1}.getLabels); + end + + function configInfo = getConfigInfo(CR) + configInfo = 'ChannelRatio'; + end + + + function time = getTime(CR) + time = 0; + end + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.dot b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.dot new file mode 100644 index 0000000..90f4631 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ChannelRatio -> ChannelRatio; + + ChannelRatio [URL="ChannelRatio.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.html b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.html new file mode 100644 index 0000000..d131d3b --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@ChannelRatio + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelRatio >
+

Dependency Graph for +eegtoolkit/+aggregation/@ChannelRatio

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@ChannelRatio + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.map b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.map new file mode 100644 index 0000000..872ffb5 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.png b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.png new file mode 100644 index 0000000..b78a950 Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@ChannelRatio/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@ChannelRatio/index.html b/doc/+eegtoolkit/+aggregation/@ChannelRatio/index.html new file mode 100644 index 0000000..0a24b4a --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@ChannelRatio/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@ChannelRatio + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@ChannelRatio >
+ +

Index for +eegtoolkit/+aggregation/@ChannelRatio

+ +

Matlab files in this directory:

+ +
 ChannelRatio
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.html b/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.html new file mode 100644 index 0000000..ce84828 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.html @@ -0,0 +1,147 @@ + + + + Description of Fisher + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @Fisher > Fisher.m
+ + + +

Fisher +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Fisher.m

+

SOURCE CODE ^

+
0001 classdef Fisher < eegtoolkit.aggregation.AggregatorBase
+0002     properties
+0003         codebookInfo;
+0004         numClusters;
+0005         means;
+0006         covariances;
+0007         priors;
+0008         pcanum;
+0009     end
+0010     
+0011     methods
+0012         function FA = Fisher(codebookfilename,pcanum)
+0013             load(codebookfilename);
+0014             FA.means = means;
+0015             FA.covariances = covariances;
+0016             FA.priors = priors;
+0017             FA.numClusters = length(priors);
+0018             FA.codebookInfo = codebookInfo;
+0019             FA.pcanum = pcanum;
+0020         end
+0021         
+0022         function FA = aggregate(FA)
+0023             numExtract = length(FA.featextractors);
+0024             numFeatures = FA.featextractors{1}.instanceSet.getNumFeatures;
+0025             numTrials = length(FA.featextractors{1}.trials);
+0026             instances = zeros(numTrials,numExtract,numFeatures);
+0027             pcainstances = zeros(numTrials,numExtract,FA.pcanum);
+0028             if FA.pcanum > 0
+0029                 fishers = zeros(numTrials, FA.numClusters * FA.pcanum *2);
+0030             else
+0031                 fishers = zeros(numTrials,FA.numClusters*numFeatures*2);
+0032             end
+0033             for i=1:numExtract
+0034                 instances(:,i,:) = FA.featextractors{i}.getInstances;
+0035                 if FA.pcanum > 0
+0036                     [~,pcainstances(:,i,:),~,~,~] = pca(squeeze(instances(:,i,:)),'NumComponents',FA.pcanum);
+0037                 end
+0038             end
+0039             for i=1:numTrials
+0040                 if FA.pcanum > 0
+0041                     dataToBeEncoded = squeeze(pcainstances(i,:,:));
+0042                 else
+0043                     dataToBeEncoded = squeeze(instances(i,:,:));
+0044                 end
+0045                 fishers(i,:) =  vl_fisher(dataToBeEncoded', FA.means, FA.covariances, FA.priors);
+0046             end
+0047             FA.instanceSet = eegtoolkit.util.InstanceSet(fishers,FA.featextractors{1}.getLabels);
+0048         end
+0049         
+0050         function configInfo = getConfigInfo(FA)
+0051             configInfo = sprintf('Fisher:\tcodebook:%s',FA.codebookInfo);
+0052         end
+0053                         
+0054         function time = getTime(FA)
+0055             time = 0;
+0056         end
+0057     end
+0058     
+0059     methods (Static)
+0060         function [] = trainCodebook(session, channels, numCenters, codebookfilename,pcanum)
+0061             nfft = 512;
+0062             extractors = {};
+0063             numChannels = length(channels);
+0064             numTrials = length(session.trials);
+0065             numFeatures = nfft/2+1;
+0066             instances = zeros(numTrials,numChannels,numFeatures);
+0067             h = waitbar(0,'message');
+0068             for i=1:length(channels)
+0069                 waitbar(i/(length(channels)+10),h,sprintf('Computing channel:%d',channels(i)));
+0070                 extractors{i} = eegtoolkit.featextraction.PWelch;
+0071                 extractors{i}.trials = session.trials;
+0072                 extractors{i}.channel = channels(i);
+0073                 extractors{i}.nfft = nfft;
+0074                 extractors{i}.seconds = 5;
+0075                 extractors{i}.extract;
+0076                 instances(:,i,:) = extractors{i}.getInstances;
+0077             end
+0078             instances = reshape(instances,numTrials*numChannels,numFeatures);
+0079             waitbar(i/(length(channels)+10),h,'Computing gmm..');
+0080             if(pcanum > 0)
+0081                 [~,instances,~,~,~] = pca(instances,'NumComponents',pcanum);
+0082             end
+0083             [means, covariances, priors] = vl_gmm(instances', numCenters);
+0084             waitbar(i+5/(length(channels)+10),h,'Saving variables..');
+0085             codebookInfo = sprintf('filename:%s\tnumClusters:%d\tnumPCA:%d\tchannels:',codebookfilename, numCenters, pcanum);
+0086             for i=1:length(channels)
+0087                 codebookInfo = sprintf('%s%d ',codebookInfo,channels(i));
+0088             end
+0089             save(codebookfilename,'means','covariances','priors','codebookInfo');
+0090             close(h);
+0091         end
+0092         
+0093 
+0094     end
+0095     
+0096 end
+0097
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.m b/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.m new file mode 100644 index 0000000..8c6ffe0 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/Fisher.m @@ -0,0 +1,97 @@ +classdef Fisher < eegtoolkit.aggregation.AggregatorBase + properties + codebookInfo; + numClusters; + means; + covariances; + priors; + pcanum; + end + + methods + function FA = Fisher(codebookfilename,pcanum) + load(codebookfilename); + FA.means = means; + FA.covariances = covariances; + FA.priors = priors; + FA.numClusters = length(priors); + FA.codebookInfo = codebookInfo; + FA.pcanum = pcanum; + end + + function FA = aggregate(FA) + numExtract = length(FA.featextractors); + numFeatures = FA.featextractors{1}.instanceSet.getNumFeatures; + numTrials = length(FA.featextractors{1}.trials); + instances = zeros(numTrials,numExtract,numFeatures); + pcainstances = zeros(numTrials,numExtract,FA.pcanum); + if FA.pcanum > 0 + fishers = zeros(numTrials, FA.numClusters * FA.pcanum *2); + else + fishers = zeros(numTrials,FA.numClusters*numFeatures*2); + end + for i=1:numExtract + instances(:,i,:) = FA.featextractors{i}.getInstances; + if FA.pcanum > 0 + [~,pcainstances(:,i,:),~,~,~] = pca(squeeze(instances(:,i,:)),'NumComponents',FA.pcanum); + end + end + for i=1:numTrials + if FA.pcanum > 0 + dataToBeEncoded = squeeze(pcainstances(i,:,:)); + else + dataToBeEncoded = squeeze(instances(i,:,:)); + end + fishers(i,:) = vl_fisher(dataToBeEncoded', FA.means, FA.covariances, FA.priors); + end + FA.instanceSet = eegtoolkit.util.InstanceSet(fishers,FA.featextractors{1}.getLabels); + end + + function configInfo = getConfigInfo(FA) + configInfo = sprintf('Fisher:\tcodebook:%s',FA.codebookInfo); + end + + function time = getTime(FA) + time = 0; + end + end + + methods (Static) + function [] = trainCodebook(session, channels, numCenters, codebookfilename,pcanum) + nfft = 512; + extractors = {}; + numChannels = length(channels); + numTrials = length(session.trials); + numFeatures = nfft/2+1; + instances = zeros(numTrials,numChannels,numFeatures); + h = waitbar(0,'message'); + for i=1:length(channels) + waitbar(i/(length(channels)+10),h,sprintf('Computing channel:%d',channels(i))); + extractors{i} = eegtoolkit.featextraction.PWelch; + extractors{i}.trials = session.trials; + extractors{i}.channel = channels(i); + extractors{i}.nfft = nfft; + extractors{i}.seconds = 5; + extractors{i}.extract; + instances(:,i,:) = extractors{i}.getInstances; + end + instances = reshape(instances,numTrials*numChannels,numFeatures); + waitbar(i/(length(channels)+10),h,'Computing gmm..'); + if(pcanum > 0) + [~,instances,~,~,~] = pca(instances,'NumComponents',pcanum); + end + [means, covariances, priors] = vl_gmm(instances', numCenters); + waitbar(i+5/(length(channels)+10),h,'Saving variables..'); + codebookInfo = sprintf('filename:%s\tnumClusters:%d\tnumPCA:%d\tchannels:',codebookfilename, numCenters, pcanum); + for i=1:length(channels) + codebookInfo = sprintf('%s%d ',codebookInfo,channels(i)); + end + save(codebookfilename,'means','covariances','priors','codebookInfo'); + close(h); + end + + + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/graph.dot b/doc/+eegtoolkit/+aggregation/@Fisher/graph.dot new file mode 100644 index 0000000..b9da3e5 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Fisher -> Fisher; + + Fisher [URL="Fisher.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/graph.html b/doc/+eegtoolkit/+aggregation/@Fisher/graph.html new file mode 100644 index 0000000..9373562 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@Fisher + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@Fisher >
+

Dependency Graph for +eegtoolkit/+aggregation/@Fisher

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@Fisher + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/graph.map b/doc/+eegtoolkit/+aggregation/@Fisher/graph.map new file mode 100644 index 0000000..09f0a4e --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/graph.png b/doc/+eegtoolkit/+aggregation/@Fisher/graph.png new file mode 100644 index 0000000..4f3fa9d Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@Fisher/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@Fisher/index.html b/doc/+eegtoolkit/+aggregation/@Fisher/index.html new file mode 100644 index 0000000..3549bfc --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@Fisher/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@Fisher + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@Fisher >
+ +

Index for +eegtoolkit/+aggregation/@Fisher

+ +

Matlab files in this directory:

+ +
 Fisher
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.html b/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.html new file mode 100644 index 0000000..e379c0a --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.html @@ -0,0 +1,81 @@ + + + + Description of LateFusion + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @LateFusion > LateFusion.m
+ + + +

LateFusion +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

LateFusion.m

+

SOURCE CODE ^

+
0001 classdef LateFusion < eegtoolkit.aggregation.AggregatorBase;
+0002     
+0003     properties
+0004     end
+0005     
+0006     methods
+0007         
+0008         function LFA = LateFusion(LFA)
+0009         end
+0010         
+0011         function LFA = aggregate(LFA)
+0012             numTransf = length(LFA.featextractors);
+0013             LFA.instanceSet = eegtoolkit.util.FusionInstanceSet(LFA.featextractors{1}.instanceSet);
+0014             
+0015             for i=1:numTransf
+0016                 LFA.instanceSet = LFA.instanceSet.addInstanceSet(LFA.featextractors{i}.instanceSet);
+0017             end
+0018         end
+0019         
+0020         function configInfo = getConfigInfo(LFA)
+0021             configInfo = 'LateFusion';
+0022         end
+0023         
+0024                 
+0025         function time = getTime(LFA)
+0026             time = 0;
+0027         end
+0028     end
+0029     
+0030 end
+0031
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.m b/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.m new file mode 100644 index 0000000..c3aa6c7 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/LateFusion.m @@ -0,0 +1,31 @@ +classdef LateFusion < eegtoolkit.aggregation.AggregatorBase; + + properties + end + + methods + + function LFA = LateFusion(LFA) + end + + function LFA = aggregate(LFA) + numTransf = length(LFA.featextractors); + LFA.instanceSet = eegtoolkit.util.FusionInstanceSet(LFA.featextractors{1}.instanceSet); + + for i=1:numTransf + LFA.instanceSet = LFA.instanceSet.addInstanceSet(LFA.featextractors{i}.instanceSet); + end + end + + function configInfo = getConfigInfo(LFA) + configInfo = 'LateFusion'; + end + + + function time = getTime(LFA) + time = 0; + end + end + +end + diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/graph.dot b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.dot new file mode 100644 index 0000000..41a4220 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + LateFusion -> LateFusion; + + LateFusion [URL="LateFusion.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/graph.html b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.html new file mode 100644 index 0000000..6326c57 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@LateFusion + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@LateFusion >
+

Dependency Graph for +eegtoolkit/+aggregation/@LateFusion

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@LateFusion + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/graph.map b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.map new file mode 100644 index 0000000..ab3767d --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/graph.png b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.png new file mode 100644 index 0000000..7b85f0a Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@LateFusion/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@LateFusion/index.html b/doc/+eegtoolkit/+aggregation/@LateFusion/index.html new file mode 100644 index 0000000..1fa3958 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@LateFusion/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@LateFusion + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@LateFusion >
+ +

Index for +eegtoolkit/+aggregation/@LateFusion

+ +

Matlab files in this directory:

+ +
 LateFusion
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.html b/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.html new file mode 100644 index 0000000..e6fcc5d --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.html @@ -0,0 +1,133 @@ + + + + Description of VLAD + + + + + + + + + +
Home > +eegtoolkit > +aggregation > @VLAD > VLAD.m
+ + + +

VLAD +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

VLAD.m

+

SOURCE CODE ^

+
0001 classdef VLAD < eegtoolkit.aggregation.AggregatorBase;
+0002     
+0003     properties
+0004         kdtree;
+0005         centers;
+0006         codebookInfo;
+0007         numClusters;
+0008     end
+0009     
+0010     methods
+0011         
+0012         function VA = VLAD(codebookfilename)
+0013             load(codebookfilename);
+0014             VA.kdtree = kdtree;
+0015             VA.centers = centers;
+0016             VA.codebookInfo = codebookInfo;
+0017             [~,VA.numClusters] = size(centers);
+0018         end
+0019         
+0020         function VA = aggregate(VA)
+0021             numExtract = length(VA.transformers);
+0022             numFeatures = VA.featextractors{1}.instanceSet.getNumFeatures;
+0023             numTrials = length(VA.featextractors{1}.trials);
+0024             instances = zeros(numTrials,numExtract,numFeatures);
+0025             vlads = zeros(numTrials,VA.kdtree.numData*numFeatures);
+0026             for i=1:numExtract
+0027                 instances(:,i,:) = VA.featextractors{i}.getInstances;
+0028             end
+0029             for i=1:numTrials
+0030                 dataToBeEncoded = squeeze(instances(i,:,:));
+0031                 nn = vl_kdtreequery(VA.kdtree, VA.centers, dataToBeEncoded');
+0032                 assignments = zeros(VA.numClusters, numExtract);
+0033                 assignments(sub2ind(size(assignments), nn, 1:length(nn))) = 1;
+0034                 vlads(i,:) = vl_vlad(dataToBeEncoded',VA.centers,assignments);
+0035             end
+0036             VA.instanceSet = eegtoolkit.util.InstanceSet(vlads,VA.featextractors{1}.getLabels);
+0037         end
+0038         
+0039         function configInfo = getConfigInfo(VA)
+0040             configInfo = sprintf('VLAD:\tcodebook:%s',VA.codebookInfo);
+0041         end
+0042         
+0043                 
+0044         function time = getTime(VA)
+0045             time = 0;
+0046         end
+0047     end
+0048     
+0049     methods (Static)
+0050         function [] = trainCodebook(session, channels, numCenters, codebookfilename)
+0051             nfft = 512;
+0052             extractors = {};
+0053             numChannels = length(channels);
+0054             numTrials = length(session.trials);
+0055             numFeatures = nfft/2+1;
+0056             instances = zeros(numTrials,numChannels,numFeatures);
+0057             h = waitbar(0,'message');
+0058             for i=1:length(channels)
+0059                 waitbar(i/(length(channels)+10),h,sprintf('Computing channel:%d',channels(i)));
+0060                 extractors{i} = eegtoolkit.transformer.PWelchTransformer;
+0061                 extractors{i}.trials = session.trials;
+0062                 extractors{i}.channel = channels(i);
+0063                 extractors{i}.nfft = nfft;
+0064                 extractors{i}.seconds = 5;
+0065                 extractors{i}.transform;
+0066                 instances(:,i,:) = extractors{i}.getInstances;
+0067             end
+0068             instances = reshape(instances,numTrials*numChannels,numFeatures);
+0069             waitbar(i/(length(channels)+10),h,'Clustering..');
+0070             centers = vl_kmeans(instances',numCenters);
+0071             waitbar(i+4/(length(channels)+10),h,'Building kdtree..');
+0072             kdtree = vl_kdtreebuild(centers);
+0073             waitbar(i+5/(length(channels)+10),h,'Saving variables..');
+0074             codebookInfo = sprintf('filename:%s\tnumClusters:%d\tchannels:',codebookfilename, numCenters);
+0075             for i=1:length(channels)
+0076                 codebookInfo = sprintf('%s%d ',codebookInfo,channels(i));
+0077             end
+0078             save(codebookfilename,'centers','kdtree','codebookInfo');
+0079             close(h);
+0080         end
+0081     end
+0082 end
+0083
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.m b/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.m new file mode 100644 index 0000000..7657d89 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/VLAD.m @@ -0,0 +1,83 @@ +classdef VLAD < eegtoolkit.aggregation.AggregatorBase; + + properties + kdtree; + centers; + codebookInfo; + numClusters; + end + + methods + + function VA = VLAD(codebookfilename) + load(codebookfilename); + VA.kdtree = kdtree; + VA.centers = centers; + VA.codebookInfo = codebookInfo; + [~,VA.numClusters] = size(centers); + end + + function VA = aggregate(VA) + numExtract = length(VA.transformers); + numFeatures = VA.featextractors{1}.instanceSet.getNumFeatures; + numTrials = length(VA.featextractors{1}.trials); + instances = zeros(numTrials,numExtract,numFeatures); + vlads = zeros(numTrials,VA.kdtree.numData*numFeatures); + for i=1:numExtract + instances(:,i,:) = VA.featextractors{i}.getInstances; + end + for i=1:numTrials + dataToBeEncoded = squeeze(instances(i,:,:)); + nn = vl_kdtreequery(VA.kdtree, VA.centers, dataToBeEncoded'); + assignments = zeros(VA.numClusters, numExtract); + assignments(sub2ind(size(assignments), nn, 1:length(nn))) = 1; + vlads(i,:) = vl_vlad(dataToBeEncoded',VA.centers,assignments); + end + VA.instanceSet = eegtoolkit.util.InstanceSet(vlads,VA.featextractors{1}.getLabels); + end + + function configInfo = getConfigInfo(VA) + configInfo = sprintf('VLAD:\tcodebook:%s',VA.codebookInfo); + end + + + function time = getTime(VA) + time = 0; + end + end + + methods (Static) + function [] = trainCodebook(session, channels, numCenters, codebookfilename) + nfft = 512; + extractors = {}; + numChannels = length(channels); + numTrials = length(session.trials); + numFeatures = nfft/2+1; + instances = zeros(numTrials,numChannels,numFeatures); + h = waitbar(0,'message'); + for i=1:length(channels) + waitbar(i/(length(channels)+10),h,sprintf('Computing channel:%d',channels(i))); + extractors{i} = eegtoolkit.transformer.PWelchTransformer; + extractors{i}.trials = session.trials; + extractors{i}.channel = channels(i); + extractors{i}.nfft = nfft; + extractors{i}.seconds = 5; + extractors{i}.transform; + instances(:,i,:) = extractors{i}.getInstances; + end + instances = reshape(instances,numTrials*numChannels,numFeatures); + waitbar(i/(length(channels)+10),h,'Clustering..'); + centers = vl_kmeans(instances',numCenters); + waitbar(i+4/(length(channels)+10),h,'Building kdtree..'); + kdtree = vl_kdtreebuild(centers); + waitbar(i+5/(length(channels)+10),h,'Saving variables..'); + codebookInfo = sprintf('filename:%s\tnumClusters:%d\tchannels:',codebookfilename, numCenters); + for i=1:length(channels) + codebookInfo = sprintf('%s%d ',codebookInfo,channels(i)); + end + save(codebookfilename,'centers','kdtree','codebookInfo'); + close(h); + end + end +end + diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/graph.dot b/doc/+eegtoolkit/+aggregation/@VLAD/graph.dot new file mode 100644 index 0000000..a7489f3 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + VLAD -> VLAD; + + VLAD [URL="VLAD.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/graph.html b/doc/+eegtoolkit/+aggregation/@VLAD/graph.html new file mode 100644 index 0000000..d8f213e --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+aggregation/@VLAD + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@VLAD >
+

Dependency Graph for +eegtoolkit/+aggregation/@VLAD

+ +
+Dependency Graph for +eegtoolkit/+aggregation/@VLAD + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/graph.map b/doc/+eegtoolkit/+aggregation/@VLAD/graph.map new file mode 100644 index 0000000..06ab2bd --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/graph.png b/doc/+eegtoolkit/+aggregation/@VLAD/graph.png new file mode 100644 index 0000000..29937e2 Binary files /dev/null and b/doc/+eegtoolkit/+aggregation/@VLAD/graph.png differ diff --git a/doc/+eegtoolkit/+aggregation/@VLAD/index.html b/doc/+eegtoolkit/+aggregation/@VLAD/index.html new file mode 100644 index 0000000..ef943b4 --- /dev/null +++ b/doc/+eegtoolkit/+aggregation/@VLAD/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+aggregation/@VLAD + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+aggregation/@VLAD >
+ +

Index for +eegtoolkit/+aggregation/@VLAD

+ +

Matlab files in this directory:

+ +
 VLAD
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.html b/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.html new file mode 100644 index 0000000..77e9e11 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.html @@ -0,0 +1,181 @@ + + + + Description of Adaboost + + + + + + + + + +
Home > +eegtoolkit > +classification > @Adaboost > Adaboost.m
+ + + +

Adaboost +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Adaboost.m

+

SOURCE CODE ^

+
0001 classdef Adaboost < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties
+0008         Method % AdaboostM2 (default), TotalBoost, LPBoost, Subspace, etc
+0009         NLearn % Number of learners (default 100)
+0010         Learners % Tree (default), KNN (only for Subspace), Discriminant(recommended for subspace), Custom
+0011         models;
+0012         totalTime;
+0013         totalCount;
+0014     end
+0015     
+0016     methods (Access = public)
+0017         function BOOST = Adaboost(instanceSet, Method, NLearn, Learners)
+0018             %set default parameters
+0019             BOOST.Method = 'AdaBoostM2';
+0020             BOOST.NLearn=100;
+0021             BOOST.Learners = 'Tree';
+0022             if nargin > 0
+0023                 BOOST.instanceSet = instanceSet;
+0024             end
+0025             if nargin > 1
+0026                 BOOST.Method = Method;
+0027             end
+0028             if nargin > 2 
+0029                 BOOST.NLearn=NLearn;
+0030             end
+0031             if nargin > 3
+0032                 BOOST.Learners = Learners;
+0033             end
+0034             BOOST.totalTime = 0;
+0035             BOOST.totalCount = 0;
+0036         end
+0037         
+0038         function BOOST = build(BOOST)
+0039             %clear all from previous calls to "build"
+0040             BOOST.reset;
+0041             numLabels = BOOST.instanceSet.getNumLabels;
+0042             uniqueLabels = unique(BOOST.instanceSet.getLabels);
+0043             
+0044             % ---- Multi-Class ----- %
+0045             instances=BOOST.instanceSet.instances;
+0046             labels=BOOST.instanceSet.labels;
+0047             
+0048             BOOST.models{1} = fitensemble(instances,labels,BOOST.Method, BOOST.NLearn, BOOST.Learners,...
+0049                 'Type','Classification');
+0050 
+0051 %             for i=1:numLabels
+0052 %                 currentLabel = uniqueLabels(i);
+0053 %                 labels = zeros(BOOST.instanceSet.getNumInstances,1)-1;
+0054 %                 labels(BOOST.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1;
+0055 %                 instances = sparse(BOOST.instanceSet.getInstances);
+0056 %                 N = length(labels); % X training labels
+0057 %                 W = 1/N * ones(N,1); %Weights initialization
+0058 %                 M = 10; % Number of boosting iterations
+0059 %                 for m=1:M
+0060 %                     C = 1; %The cost parameters of the linear SVM, you can...
+0061 %                     % perform a grid search for the optimal value as well
+0062 %
+0063 %                     %Calculate the error and alpha in adaBoost with cross validation
+0064 %                     cmd = ['-c ', num2str(C), ' -b 1'];
+0065 %                     model = svmtrain(W,labels, instances, cmd);
+0066 %                     [Xout, acc, ~] = svmpredict(labels, instances,model);
+0067 %
+0068 %                     err = sum(.5 * W .* acc * N)/sum(W);
+0069 %                     alpha = log( (1-err)/err );
+0070 %
+0071 %                     % update the weight
+0072 %                     W = W.*exp( - alpha.*Xout.*X );
+0073 %                     W = W/norm(W);
+0074 %                 end
+0075 %                 BOOST.models{i} = model;
+0076 %
+0077 %             end
+0078             
+0079         end
+0080         
+0081         function [output, probabilities, ranking] = classifyInstance(BOOST,instance)
+0082             %input = instance matrix rows = instances, cols = attributes
+0083             %output = predicted class
+0084             %probabilities = probability for predicted class
+0085             %ranking = propabilities for all classes (e.g. to use with mAP)
+0086             
+0087             
+0088             %TODO:should print an error if 'build' has not been called
+0089             numModels = length(BOOST.models);
+0090             [numinstance, ~] = size(instance);
+0091             scores = zeros(numModels,numinstance);
+0092              
+0093             % ---- Multi-class ----- %
+0094             tic
+0095             [label,scores] = predict(BOOST.models{1},instance); 
+0096             BOOST.totalTime = BOOST.totalTime + toc;
+0097             BOOST.totalCount = BOOST.totalCount + numinstance;
+0098 
+0099              output = zeros(numinstance,1);
+0100              probabilities = zeros(numinstance,1);
+0101              %we need these for ranking metrics (e.g. mAP)
+0102              ranking = scores;
+0103              for i=1:numinstance
+0104                  %select the class with the highest probability
+0105                  [prob, idx] = max(scores(i,:));
+0106                  uniqueLabels = unique(BOOST.instanceSet.getLabels);
+0107                  %output the label with highest probability
+0108                  output(i,1) = uniqueLabels(idx);
+0109                  %return the probability for the output label
+0110                  probabilities(i,1) = prob;
+0111              end
+0112         end
+0113         
+0114         function BOOST = reset(BOOST)
+0115             %delete all stored models
+0116             BOOST.models = {};
+0117         end
+0118         
+0119         function configInfo = getConfigInfo(BOOST)
+0120             configInfo = sprintf('Adaboost: Method: %s NLearn: %d Learners: %s',...
+0121                 BOOST.Method, BOOST.NLearn, BOOST.Learners);
+0122         end
+0123         
+0124                         
+0125         function time = getTime(BOOST)
+0126             time = BOOST.totalTime / BOOST.totalCount;
+0127         end
+0128                 
+0129     end
+0130 end
+0131
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.m b/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.m new file mode 100644 index 0000000..cd27623 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/Adaboost.m @@ -0,0 +1,131 @@ +classdef Adaboost < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + Method % AdaboostM2 (default), TotalBoost, LPBoost, Subspace, etc + NLearn % Number of learners (default 100) + Learners % Tree (default), KNN (only for Subspace), Discriminant(recommended for subspace), Custom + models; + totalTime; + totalCount; + end + + methods (Access = public) + function BOOST = Adaboost(instanceSet, Method, NLearn, Learners) + %set default parameters + BOOST.Method = 'AdaBoostM2'; + BOOST.NLearn=100; + BOOST.Learners = 'Tree'; + if nargin > 0 + BOOST.instanceSet = instanceSet; + end + if nargin > 1 + BOOST.Method = Method; + end + if nargin > 2 + BOOST.NLearn=NLearn; + end + if nargin > 3 + BOOST.Learners = Learners; + end + BOOST.totalTime = 0; + BOOST.totalCount = 0; + end + + function BOOST = build(BOOST) + %clear all from previous calls to "build" + BOOST.reset; + numLabels = BOOST.instanceSet.getNumLabels; + uniqueLabels = unique(BOOST.instanceSet.getLabels); + + % ---- Multi-Class ----- % + instances=BOOST.instanceSet.instances; + labels=BOOST.instanceSet.labels; + + BOOST.models{1} = fitensemble(instances,labels,BOOST.Method, BOOST.NLearn, BOOST.Learners,... + 'Type','Classification'); + +% for i=1:numLabels +% currentLabel = uniqueLabels(i); +% labels = zeros(BOOST.instanceSet.getNumInstances,1)-1; +% labels(BOOST.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1; +% instances = sparse(BOOST.instanceSet.getInstances); +% N = length(labels); % X training labels +% W = 1/N * ones(N,1); %Weights initialization +% M = 10; % Number of boosting iterations +% for m=1:M +% C = 1; %The cost parameters of the linear SVM, you can... +% % perform a grid search for the optimal value as well +% +% %Calculate the error and alpha in adaBoost with cross validation +% cmd = ['-c ', num2str(C), ' -b 1']; +% model = svmtrain(W,labels, instances, cmd); +% [Xout, acc, ~] = svmpredict(labels, instances,model); +% +% err = sum(.5 * W .* acc * N)/sum(W); +% alpha = log( (1-err)/err ); +% +% % update the weight +% W = W.*exp( - alpha.*Xout.*X ); +% W = W/norm(W); +% end +% BOOST.models{i} = model; +% +% end + + end + + function [output, probabilities, ranking] = classifyInstance(BOOST,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + + %TODO:should print an error if 'build' has not been called + numModels = length(BOOST.models); + [numinstance, ~] = size(instance); + scores = zeros(numModels,numinstance); + + % ---- Multi-class ----- % + tic + [label,scores] = predict(BOOST.models{1},instance); + BOOST.totalTime = BOOST.totalTime + toc; + BOOST.totalCount = BOOST.totalCount + numinstance; + + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + %we need these for ranking metrics (e.g. mAP) + ranking = scores; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(i,:)); + uniqueLabels = unique(BOOST.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function BOOST = reset(BOOST) + %delete all stored models + BOOST.models = {}; + end + + function configInfo = getConfigInfo(BOOST) + configInfo = sprintf('Adaboost: Method: %s NLearn: %d Learners: %s',... + BOOST.Method, BOOST.NLearn, BOOST.Learners); + end + + + function time = getTime(BOOST) + time = BOOST.totalTime / BOOST.totalCount; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@Adaboost/graph.dot b/doc/+eegtoolkit/+classification/@Adaboost/graph.dot new file mode 100644 index 0000000..3b7d0bf --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Adaboost -> Adaboost; + + Adaboost [URL="Adaboost.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@Adaboost/graph.html b/doc/+eegtoolkit/+classification/@Adaboost/graph.html new file mode 100644 index 0000000..abc259f --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@Adaboost + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@Adaboost >
+

Dependency Graph for +eegtoolkit/+classification/@Adaboost

+ +
+Dependency Graph for +eegtoolkit/+classification/@Adaboost + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@Adaboost/graph.map b/doc/+eegtoolkit/+classification/@Adaboost/graph.map new file mode 100644 index 0000000..7cb3dd1 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@Adaboost/graph.png b/doc/+eegtoolkit/+classification/@Adaboost/graph.png new file mode 100644 index 0000000..d6f260a Binary files /dev/null and b/doc/+eegtoolkit/+classification/@Adaboost/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@Adaboost/index.html b/doc/+eegtoolkit/+classification/@Adaboost/index.html new file mode 100644 index 0000000..8cf6af8 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@Adaboost/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@Adaboost + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@Adaboost >
+ +

Index for +eegtoolkit/+classification/@Adaboost

+ +

Matlab files in this directory:

+ +
 Adaboost
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.html b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.html new file mode 100644 index 0000000..83519fa --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.html @@ -0,0 +1,234 @@ + + + + Description of CSPFilterBankWrapper + + + + + + + + + +
Home > +eegtoolkit > +classification > @CSPFilterBankWrapper > CSPFilterBankWrapper.m
+ + + +

CSPFilterBankWrapper +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

CSPFilterBankWrapper.m

+

SOURCE CODE ^

+
0001 classdef CSPFilterBankWrapper < eegtoolkit.classification.ClassifierBase;
+0002     properties (Constant)
+0003         
+0004     end
+0005     properties
+0006         baseClassifier;
+0007         channel;
+0008         cspFilters;
+0009         filterBanks;
+0010         samplingRate;
+0011     end
+0012     
+0013     methods (Access = public)
+0014         function CSPFB = CSPFilterBankWrapper(filterBanks, samplingRate)
+0015             CSPFB.cspFilters = {};
+0016             CSPFB.filterBanks = filterBanks;
+0017             CSPFB.samplingRate = samplingRate;
+0018             %filter_banks=[8 12; 12 16; 16 20;20 24;24 28];
+0019 %             if(isa(instanceSet,'eegtoolkit.util.RawSignalSet')
+0020 %                 CSP.instanceSet = instanceSet;
+0021 %             else
+0022 %                 error('RawSignal extractor should be used with CSPWrapper');
+0023 %             end
+0024         end
+0025         
+0026         
+0027         function CSPFB = build(CSPFB)
+0028             % Builds the classification models
+0029             CSPFB.learnCSPMatrix(CSPFB.instanceSet.sMatrix,CSPFB.instanceSet.labels);
+0030             instanceLocal = CSPFB.extract(CSPFB.instanceSet.sMatrix);
+0031             CSPFB.baseClassifier.instanceSet = eegtoolkit.util.InstanceSet(instanceLocal,CSPFB.instanceSet.labels);
+0032             CSPFB.baseClassifier.build;
+0033             CSPFB.reset;
+0034         end
+0035         
+0036         function [output, probabilities, ranking] = classifyInstance(CSPFB,instance)
+0037             
+0038 %             instance = CSP.extract
+0039             %input = instance matrix rows = instances, cols = attributes
+0040             %output = predicted class
+0041             %probabilities = probability for predicted class
+0042             %ranking = propabilities for all classes (e.g. to use with mAP)
+0043             
+0044             %TODO:should print an error if 'build' has not been called
+0045             testInstances = CSPFB.extract(instance);
+0046             [output, probabilities, ranking] = CSPFB.baseClassifier.classifyInstance(testInstances);
+0047 %             numModels = length(LSVM.models);
+0048 %             [numinstance, ~] = size(testInstances);
+0049 %             scores = zeros(numModels,numinstance);
+0050 %             for i=1:numModels
+0051 %                 %predict using the stored models
+0052 %                 [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q');
+0053 %                 %store probability for each class
+0054 %                 scores(i,:) = t(:,1);
+0055 %             end
+0056 %             output = zeros(numinstance,1);
+0057 %             probabilities = zeros(numinstance,1);
+0058 %             ranking = scores;
+0059 %             for i=1:numinstance
+0060 %                 %select the class with the highest probability
+0061 %                 [prob, idx] = max(scores(:,i));
+0062 %                 uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0063 %                 %output the label with highest probability
+0064 %                 output(i,1) = uniqueLabels(idx);
+0065 %                 %return the probability for the output label
+0066 %                 probabilities(i,1) = prob;
+0067 %             end
+0068         end
+0069         
+0070         function CSPFB = reset(CSPFB)
+0071             % 'Resets' the classifier.
+0072 %             CSP.models = {};
+0073         end
+0074         
+0075         function configInfo = getConfigInfo(CSPFB)
+0076             configInfo = '\n';
+0077         end
+0078         
+0079                         
+0080         function time = getTime(CSPFB)
+0081             time = 0;
+0082         end
+0083     end
+0084     methods (Access = private)
+0085         function [] = learnCSPMatrix(CSPFB, sMatrix, labels)
+0086                        %[trialsMat,labels] = ssveptoolkit.util.Trial.trialsCellToMat(in);
+0087             [numTrials,numChannels,numSamples] = size(sMatrix);
+0088 %             numTrials = length(CSPFB.trials);
+0089 %             [numChannels,numSamples] = size(CSPFB.trials{1}.signal);
+0090 %             samplingRate = CSPFB.trials{1}.samplingRate;
+0091             filter_banks= CSPFB.filterBanks;
+0092             [nfb, mfb] = size(filter_banks);
+0093 
+0094             for iter_fb=1:nfb
+0095                 
+0096                 [b,a]=butter(3,filter_banks(iter_fb)/(CSPFB.samplingRate/2));
+0097 %                 labels = zeros(numTrials,1);
+0098                 %numTrials X numChannels X numSamples
+0099                 trialsMat = permute(sMatrix,[2,3,1]);
+0100 %                 trialsMat = zeros(numChannels,numSamples,numTrials);
+0101 %                 for i = 1 : length(CSP_Feat.trials)
+0102 %                     for i_ch = 1:numChannels
+0103 %                         trialsMat(i_ch,:,i) = filtfilt(b,a,CSP_Feat.trials{i}.signal(i_ch,:));
+0104 %                     end
+0105 %                     labels(i) = CSP_Feat.trials{i}.label;
+0106 %                 end
+0107                 
+0108                 trialsMat = permute(trialsMat,[2 1 3]);
+0109                 [N1, Nch1, Ntr1] = size(trialsMat);
+0110                 for i = 1:Nch1
+0111                     for j = 1:Ntr1
+0112                         trialsMat(:,i,j) = (trialsMat(:,i,j) - mean(trialsMat(:,i,j)));
+0113                     end
+0114                 end
+0115                 x_train = trialsMat;%(:,:,CSP_Feat.trainIdx);
+0116                 y_train = labels;%(CSP_Feat.trainIdx);
+0117                 [N, Nch, Ntr] = size(x_train);
+0118                 trialCov=zeros(Nch,Nch,Ntr);
+0119                 for t=1:length(y_train)
+0120                     E = x_train(:,:,t)';
+0121                     EE = E * E';
+0122                     trialCov(:,:,t) = EE ./ trace(EE);
+0123                 end
+0124                 for c=1:2
+0125                     covMat{c} = mean(trialCov(:,:,y_train == c),3);
+0126                 end
+0127                 [U, D] = eig(covMat{1},covMat{2},'qz');
+0128                 eigenvalues = diag(D);
+0129                 [~, ind] = sort(eigenvalues, 'descend');
+0130                 U = U(:,ind);
+0131                 CSPFB.cspFilters{iter_fb} = U';
+0132 %                 CSP_Filter = U';
+0133             end
+0134                 %trialsMat2=zeros(N,3,Ntr);
+0135                
+0136         end
+0137         
+0138         function instances = extract(CSPFB,sMatrix)
+0139             trialsMat = permute(sMatrix,[2,3,1]);
+0140             trialsMat = permute(trialsMat,[2,1,3]);
+0141             [numTrials,numChannels,~] = size(sMatrix);
+0142             final_instances = zeros(numTrials, numChannels*length(CSPFB.filterBanks));
+0143             for iter_fb=1:length(CSPFB.cspFilters)
+0144                 for j = 1:size(trialsMat,3)
+0145                     trialsMat(:,:,j) = (CSPFB.cspFilters{iter_fb}*trialsMat(:,:,j)')';
+0146                 end
+0147                 
+0148                 instances = zeros(numTrials, numChannels);
+0149                 %labels = zeros(numTrials,1);
+0150                 
+0151                 for i=1:numTrials
+0152                     
+0153                     projectedTrial = trialsMat(:,:,i);%Filter * CSP_Feat.trials{i}.signal(:,i);% EEGSignals.x(:,:,t)';
+0154                     %generating the features as the log variance of the projected signals
+0155                     variances = var(projectedTrial,0,1);
+0156                     instances(i,:) = log(variances)';
+0157                     %labels(i,1) = floor(CSP_Feat.trials{i}.label);
+0158                 end
+0159                 final_instances(:,numChannels*(iter_fb-1)+1:numChannels*iter_fb) = instances;
+0160                 %            CSP_Feat.avgTime = toc/numTrials;
+0161 %                 CSP_Feat.instanceSet = ssveptoolkit.util.InstanceSet(final_instances,labels);
+0162             end
+0163             instances = final_instances;
+0164         end
+0165     
+0166     
+0167     
+0168     end
+0169     %             [numTrials,numChannels,~] = size(sMatrix);
+0170     %             sMatrix = permute(sMatrix,[3,2,1]);
+0171     %             for i=1:size(sMatrix,3);
+0172     %                 sMatrix(:,:,i) = (CSPFB.cspFilter*sMatrix(:,:,i)')';
+0173     %             end
+0174     %             instances = zeros(numTrials,numChannels);
+0175     %             for i=1:numTrials
+0176     %                 projectedTrial = sMatrix(:,:,i);
+0177     %                 variances = var(projectedTrial,0,1);
+0178     %                 instances(i,:) = log(variances)';
+0179     %             end
+0180     % %             instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0181     %         end
+0182     %end
+0183 end
+0184
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m new file mode 100644 index 0000000..97e9faf --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/CSPFilterBankWrapper.m @@ -0,0 +1,184 @@ +classdef CSPFilterBankWrapper < eegtoolkit.classification.ClassifierBase; + properties (Constant) + + end + properties + baseClassifier; + channel; + cspFilters; + filterBanks; + samplingRate; + end + + methods (Access = public) + function CSPFB = CSPFilterBankWrapper(filterBanks, samplingRate) + CSPFB.cspFilters = {}; + CSPFB.filterBanks = filterBanks; + CSPFB.samplingRate = samplingRate; + %filter_banks=[8 12; 12 16; 16 20;20 24;24 28]; +% if(isa(instanceSet,'eegtoolkit.util.RawSignalSet') +% CSP.instanceSet = instanceSet; +% else +% error('RawSignal extractor should be used with CSPWrapper'); +% end + end + + + function CSPFB = build(CSPFB) + % Builds the classification models + CSPFB.learnCSPMatrix(CSPFB.instanceSet.sMatrix,CSPFB.instanceSet.labels); + instanceLocal = CSPFB.extract(CSPFB.instanceSet.sMatrix); + CSPFB.baseClassifier.instanceSet = eegtoolkit.util.InstanceSet(instanceLocal,CSPFB.instanceSet.labels); + CSPFB.baseClassifier.build; + CSPFB.reset; + end + + function [output, probabilities, ranking] = classifyInstance(CSPFB,instance) + +% instance = CSP.extract + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + testInstances = CSPFB.extract(instance); + [output, probabilities, ranking] = CSPFB.baseClassifier.classifyInstance(testInstances); +% numModels = length(LSVM.models); +% [numinstance, ~] = size(testInstances); +% scores = zeros(numModels,numinstance); +% for i=1:numModels +% %predict using the stored models +% [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = t(:,1); +% end +% output = zeros(numinstance,1); +% probabilities = zeros(numinstance,1); +% ranking = scores; +% for i=1:numinstance +% %select the class with the highest probability +% [prob, idx] = max(scores(:,i)); +% uniqueLabels = unique(LSVM.instanceSet.getLabels); +% %output the label with highest probability +% output(i,1) = uniqueLabels(idx); +% %return the probability for the output label +% probabilities(i,1) = prob; +% end + end + + function CSPFB = reset(CSPFB) + % 'Resets' the classifier. +% CSP.models = {}; + end + + function configInfo = getConfigInfo(CSPFB) + configInfo = '\n'; + end + + + function time = getTime(CSPFB) + time = 0; + end + end + methods (Access = private) + function [] = learnCSPMatrix(CSPFB, sMatrix, labels) + %[trialsMat,labels] = ssveptoolkit.util.Trial.trialsCellToMat(in); + [numTrials,numChannels,numSamples] = size(sMatrix); +% numTrials = length(CSPFB.trials); +% [numChannels,numSamples] = size(CSPFB.trials{1}.signal); +% samplingRate = CSPFB.trials{1}.samplingRate; + filter_banks= CSPFB.filterBanks; + [nfb, mfb] = size(filter_banks); + + for iter_fb=1:nfb + + [b,a]=butter(3,filter_banks(iter_fb)/(CSPFB.samplingRate/2)); +% labels = zeros(numTrials,1); + %numTrials X numChannels X numSamples + trialsMat = permute(sMatrix,[2,3,1]); +% trialsMat = zeros(numChannels,numSamples,numTrials); +% for i = 1 : length(CSP_Feat.trials) +% for i_ch = 1:numChannels +% trialsMat(i_ch,:,i) = filtfilt(b,a,CSP_Feat.trials{i}.signal(i_ch,:)); +% end +% labels(i) = CSP_Feat.trials{i}.label; +% end + + trialsMat = permute(trialsMat,[2 1 3]); + [N1, Nch1, Ntr1] = size(trialsMat); + for i = 1:Nch1 + for j = 1:Ntr1 + trialsMat(:,i,j) = (trialsMat(:,i,j) - mean(trialsMat(:,i,j))); + end + end + x_train = trialsMat;%(:,:,CSP_Feat.trainIdx); + y_train = labels;%(CSP_Feat.trainIdx); + [N, Nch, Ntr] = size(x_train); + trialCov=zeros(Nch,Nch,Ntr); + for t=1:length(y_train) + E = x_train(:,:,t)'; + EE = E * E'; + trialCov(:,:,t) = EE ./ trace(EE); + end + for c=1:2 + covMat{c} = mean(trialCov(:,:,y_train == c),3); + end + [U, D] = eig(covMat{1},covMat{2},'qz'); + eigenvalues = diag(D); + [~, ind] = sort(eigenvalues, 'descend'); + U = U(:,ind); + CSPFB.cspFilters{iter_fb} = U'; +% CSP_Filter = U'; + end + %trialsMat2=zeros(N,3,Ntr); + + end + + function instances = extract(CSPFB,sMatrix) + trialsMat = permute(sMatrix,[2,3,1]); + trialsMat = permute(trialsMat,[2,1,3]); + [numTrials,numChannels,~] = size(sMatrix); + final_instances = zeros(numTrials, numChannels*length(CSPFB.filterBanks)); + for iter_fb=1:length(CSPFB.cspFilters) + for j = 1:size(trialsMat,3) + trialsMat(:,:,j) = (CSPFB.cspFilters{iter_fb}*trialsMat(:,:,j)')'; + end + + instances = zeros(numTrials, numChannels); + %labels = zeros(numTrials,1); + + for i=1:numTrials + + projectedTrial = trialsMat(:,:,i);%Filter * CSP_Feat.trials{i}.signal(:,i);% EEGSignals.x(:,:,t)'; + %generating the features as the log variance of the projected signals + variances = var(projectedTrial,0,1); + instances(i,:) = log(variances)'; + %labels(i,1) = floor(CSP_Feat.trials{i}.label); + end + final_instances(:,numChannels*(iter_fb-1)+1:numChannels*iter_fb) = instances; + % CSP_Feat.avgTime = toc/numTrials; +% CSP_Feat.instanceSet = ssveptoolkit.util.InstanceSet(final_instances,labels); + end + instances = final_instances; + end + + + + end + % [numTrials,numChannels,~] = size(sMatrix); + % sMatrix = permute(sMatrix,[3,2,1]); + % for i=1:size(sMatrix,3); + % sMatrix(:,:,i) = (CSPFB.cspFilter*sMatrix(:,:,i)')'; + % end + % instances = zeros(numTrials,numChannels); + % for i=1:numTrials + % projectedTrial = sMatrix(:,:,i); + % variances = var(projectedTrial,0,1); + % instances(i,:) = log(variances)'; + % end + % % instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + % end + %end +end + diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.dot b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.dot new file mode 100644 index 0000000..de486f9 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + CSPFilterBankWrapper -> CSPFilterBankWrapper; + + CSPFilterBankWrapper [URL="CSPFilterBankWrapper.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.html b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.html new file mode 100644 index 0000000..8be66bf --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@CSPFilterBankWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CSPFilterBankWrapper >
+

Dependency Graph for +eegtoolkit/+classification/@CSPFilterBankWrapper

+ +
+Dependency Graph for +eegtoolkit/+classification/@CSPFilterBankWrapper + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.map b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.map new file mode 100644 index 0000000..daaf177 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.png b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.png new file mode 100644 index 0000000..a736a31 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/index.html b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/index.html new file mode 100644 index 0000000..812d0bc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPFilterBankWrapper/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@CSPFilterBankWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CSPFilterBankWrapper >
+ +

Index for +eegtoolkit/+classification/@CSPFilterBankWrapper

+ +

Matlab files in this directory:

+ +
 CSPFilterBankWrapper
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.html b/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.html new file mode 100644 index 0000000..155589b --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.html @@ -0,0 +1,183 @@ + + + + Description of CSPWrapper + + + + + + + + + +
Home > +eegtoolkit > +classification > @CSPWrapper > CSPWrapper.m
+ + + +

CSPWrapper +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

CSPWrapper.m

+

SOURCE CODE ^

+
0001 classdef CSPWrapper < eegtoolkit.classification.ClassifierBase;
+0002     properties (Constant)
+0003         
+0004     end
+0005     properties
+0006         baseClassifier;
+0007         channel;
+0008         cspFilter;
+0009     end
+0010     
+0011     methods (Access = public)
+0012         function CSP = CSPWrapper(instanceSet)
+0013 %             if(isa(instanceSet,'eegtoolkit.util.RawSignalSet')
+0014 %                 CSP.instanceSet = instanceSet;
+0015 %             else
+0016 %                 error('RawSignal extractor should be used with CSPWrapper');
+0017 %             end
+0018         end
+0019         
+0020         
+0021         function CSP = build(CSP)
+0022             % Builds the classification models
+0023             CSP.learnCSPMatrix(CSP.instanceSet.sMatrix,CSP.instanceSet.labels);
+0024             instanceLocal = CSP.extract(CSP.instanceSet.sMatrix);
+0025             CSP.baseClassifier.instanceSet = eegtoolkit.util.InstanceSet(instanceLocal,CSP.instanceSet.labels);
+0026             CSP.baseClassifier.build;
+0027             CSP.reset;
+0028         end
+0029         
+0030         function [output, probabilities, ranking] = classifyInstance(CSP,instance)
+0031 %             instance = CSP.extract
+0032             %input = instance matrix rows = instances, cols = attributes
+0033             %output = predicted class
+0034             %probabilities = probability for predicted class
+0035             %ranking = propabilities for all classes (e.g. to use with mAP)
+0036             
+0037             %TODO:should print an error if 'build' has not been called
+0038             testInstances = CSP.extract(instance);
+0039             [output, probabilities, ranking] = CSP.baseClassifier.classifyInstance(testInstances);
+0040 %             numModels = length(LSVM.models);
+0041 %             [numinstance, ~] = size(testInstances);
+0042 %             scores = zeros(numModels,numinstance);
+0043 %             for i=1:numModels
+0044 %                 %predict using the stored models
+0045 %                 [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q');
+0046 %                 %store probability for each class
+0047 %                 scores(i,:) = t(:,1);
+0048 %             end
+0049 %             output = zeros(numinstance,1);
+0050 %             probabilities = zeros(numinstance,1);
+0051 %             ranking = scores;
+0052 %             for i=1:numinstance
+0053 %                 %select the class with the highest probability
+0054 %                 [prob, idx] = max(scores(:,i));
+0055 %                 uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0056 %                 %output the label with highest probability
+0057 %                 output(i,1) = uniqueLabels(idx);
+0058 %                 %return the probability for the output label
+0059 %                 probabilities(i,1) = prob;
+0060 %             end
+0061         end
+0062         
+0063         function CSP = reset(CSP)
+0064             % 'Resets' the classifier.
+0065 %             CSP.models = {};
+0066         end
+0067         
+0068         function configInfo = getConfigInfo(CSP)
+0069             configInfo = '\n';
+0070         end
+0071         
+0072                         
+0073         function time = getTime(CSP)
+0074             time = 0;
+0075         end
+0076     end
+0077     methods (Access = private)
+0078         function [] = learnCSPMatrix(CSP, sMatrix, labels)
+0079             [numTrials,numChannels,~] = size(sMatrix);
+0080 %             labels = CSP.instanceSet.getLabels;
+0081 %             sMatrix = permute(sMatrix,[2,3,1]);
+0082 %             sMatrix = permute(sMatrix,[2 1 3]);
+0083             sMatrix = permute(sMatrix,[3,2,1]);
+0084             for i=1:numChannels
+0085                 for j=1:numTrials
+0086                     sMatrix(:,i,j) = (sMatrix(:,i,j) - mean(sMatrix(:,i,j)));
+0087                 end
+0088             end
+0089             trialCov = zeros(numChannels,numChannels,numTrials);
+0090             for t=1:length(labels)
+0091                 E = sMatrix(:,:,t)';
+0092                 EE = E * E';
+0093                 trialCov(:,:,t) = EE ./trace(EE);
+0094             end
+0095             %TODO: works only for 2 labels, [1,2]
+0096             for c=1:2
+0097                 covMat{c} = mean(trialCov(:,:,labels == c),3);
+0098             end
+0099             [U, D] = eig(covMat{1},covMat{2},'qz');
+0100             eigenvalues = diag(D);
+0101             [~,ind] = sort(eigenvalues,'descend');
+0102             U = U(:,ind);
+0103             CSP.cspFilter = U';
+0104 %             for i=1:size(sMatrix,3);
+0105 %                 sMatrix(:,:,i) = (cspFilter*sMatrix(:,:,i)')';
+0106 %             end
+0107 %             instances = zeros(numTrials,numChannels);
+0108 %             for i=1:numTrials
+0109 %                 projectedTrial = sMatrix(:,:,i);
+0110 %                 variances = var(projectedTrial,0,1);
+0111 %                 instances(i,:) = log(variances)';
+0112 %             end
+0113 %             instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0114         end
+0115         
+0116         function instances = extract(CSP,sMatrix)
+0117             
+0118             [numTrials,numChannels,~] = size(sMatrix);
+0119             sMatrix = permute(sMatrix,[3,2,1]);
+0120             for i=1:size(sMatrix,3);
+0121                 sMatrix(:,:,i) = (CSP.cspFilter*sMatrix(:,:,i)')';
+0122             end
+0123             instances = zeros(numTrials,numChannels);
+0124             for i=1:numTrials
+0125                 projectedTrial = sMatrix(:,:,i);
+0126                 variances = var(projectedTrial,0,1);
+0127                 instances(i,:) = log(variances)';
+0128             end
+0129 %             instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0130         end
+0131     end
+0132 end
+0133
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.m b/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.m new file mode 100644 index 0000000..e9765cc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/CSPWrapper.m @@ -0,0 +1,133 @@ +classdef CSPWrapper < eegtoolkit.classification.ClassifierBase; + properties (Constant) + + end + properties + baseClassifier; + channel; + cspFilter; + end + + methods (Access = public) + function CSP = CSPWrapper(instanceSet) +% if(isa(instanceSet,'eegtoolkit.util.RawSignalSet') +% CSP.instanceSet = instanceSet; +% else +% error('RawSignal extractor should be used with CSPWrapper'); +% end + end + + + function CSP = build(CSP) + % Builds the classification models + CSP.learnCSPMatrix(CSP.instanceSet.sMatrix,CSP.instanceSet.labels); + instanceLocal = CSP.extract(CSP.instanceSet.sMatrix); + CSP.baseClassifier.instanceSet = eegtoolkit.util.InstanceSet(instanceLocal,CSP.instanceSet.labels); + CSP.baseClassifier.build; + CSP.reset; + end + + function [output, probabilities, ranking] = classifyInstance(CSP,instance) +% instance = CSP.extract + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + testInstances = CSP.extract(instance); + [output, probabilities, ranking] = CSP.baseClassifier.classifyInstance(testInstances); +% numModels = length(LSVM.models); +% [numinstance, ~] = size(testInstances); +% scores = zeros(numModels,numinstance); +% for i=1:numModels +% %predict using the stored models +% [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = t(:,1); +% end +% output = zeros(numinstance,1); +% probabilities = zeros(numinstance,1); +% ranking = scores; +% for i=1:numinstance +% %select the class with the highest probability +% [prob, idx] = max(scores(:,i)); +% uniqueLabels = unique(LSVM.instanceSet.getLabels); +% %output the label with highest probability +% output(i,1) = uniqueLabels(idx); +% %return the probability for the output label +% probabilities(i,1) = prob; +% end + end + + function CSP = reset(CSP) + % 'Resets' the classifier. +% CSP.models = {}; + end + + function configInfo = getConfigInfo(CSP) + configInfo = '\n'; + end + + + function time = getTime(CSP) + time = 0; + end + end + methods (Access = private) + function [] = learnCSPMatrix(CSP, sMatrix, labels) + [numTrials,numChannels,~] = size(sMatrix); +% labels = CSP.instanceSet.getLabels; +% sMatrix = permute(sMatrix,[2,3,1]); +% sMatrix = permute(sMatrix,[2 1 3]); + sMatrix = permute(sMatrix,[3,2,1]); + for i=1:numChannels + for j=1:numTrials + sMatrix(:,i,j) = (sMatrix(:,i,j) - mean(sMatrix(:,i,j))); + end + end + trialCov = zeros(numChannels,numChannels,numTrials); + for t=1:length(labels) + E = sMatrix(:,:,t)'; + EE = E * E'; + trialCov(:,:,t) = EE ./trace(EE); + end + %TODO: works only for 2 labels, [1,2] + for c=1:2 + covMat{c} = mean(trialCov(:,:,labels == c),3); + end + [U, D] = eig(covMat{1},covMat{2},'qz'); + eigenvalues = diag(D); + [~,ind] = sort(eigenvalues,'descend'); + U = U(:,ind); + CSP.cspFilter = U'; +% for i=1:size(sMatrix,3); +% sMatrix(:,:,i) = (cspFilter*sMatrix(:,:,i)')'; +% end +% instances = zeros(numTrials,numChannels); +% for i=1:numTrials +% projectedTrial = sMatrix(:,:,i); +% variances = var(projectedTrial,0,1); +% instances(i,:) = log(variances)'; +% end +% instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + + function instances = extract(CSP,sMatrix) + + [numTrials,numChannels,~] = size(sMatrix); + sMatrix = permute(sMatrix,[3,2,1]); + for i=1:size(sMatrix,3); + sMatrix(:,:,i) = (CSP.cspFilter*sMatrix(:,:,i)')'; + end + instances = zeros(numTrials,numChannels); + for i=1:numTrials + projectedTrial = sMatrix(:,:,i); + variances = var(projectedTrial,0,1); + instances(i,:) = log(variances)'; + end +% instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/graph.dot b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.dot new file mode 100644 index 0000000..e4db5e4 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + CSPWrapper -> CSPWrapper; + + CSPWrapper [URL="CSPWrapper.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/graph.html b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.html new file mode 100644 index 0000000..941232d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@CSPWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CSPWrapper >
+

Dependency Graph for +eegtoolkit/+classification/@CSPWrapper

+ +
+Dependency Graph for +eegtoolkit/+classification/@CSPWrapper + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/graph.map b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.map new file mode 100644 index 0000000..04ea233 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/graph.png b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.png new file mode 100644 index 0000000..8007750 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@CSPWrapper/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@CSPWrapper/index.html b/doc/+eegtoolkit/+classification/@CSPWrapper/index.html new file mode 100644 index 0000000..4cb7dcf --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CSPWrapper/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@CSPWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CSPWrapper >
+ +

Index for +eegtoolkit/+classification/@CSPWrapper

+ +

Matlab files in this directory:

+ +
 CSPWrapper
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.html b/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.html new file mode 100644 index 0000000..a7010e7 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.html @@ -0,0 +1,115 @@ + + + + Description of ClassifierBase + + + + + + + + + +
Home > +eegtoolkit > +classification > @ClassifierBase > ClassifierBase.m
+ + + +

ClassifierBase +

+ +

PURPOSE ^

+
Abstract class for classification. Implement the functions for any
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Abstract class for classification. Implement the functions for any
+ classifier (e.g. LibSVM, LDA, MLR, RFs, Adaboost, etc.)
+ 
+ Properties:
+ instanceSet: the training/test set in an InstanceSet structure
+ 
+ Functions:
+Implement this function to train the classification models. Each
+implementation should define the type of models that are to be trained by
+the build function.
+   obj = obj.build();
+Implement this function to apply the classification models to the provided
+instance, where instance is a matrix #instances x #features including the
+instances. The function should return the following three outputs; 1)
+output, the classified labels of the instances (#instances x 1), 2)
+probabilities, the probabilities for the output label (instances x 1) and
+3) ranking, a matrix #instances x #classes with the probabilities of each
+instance for each class (used for multiclass classification).
+   [output, probabilities, ranking] = obj.classifyInstance(instance);
+Implement this function to reset the classifier (e.g. delete the stored
+classification models
+   obj.reset();
+Info & run time so that the experiments are easily documented. configInfo
+is a string with the configuration information and time is of type double.
+   configInfo = obj.getConfigInfo();
+   time = obj.getTime();
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + + +

DOWNLOAD ^

+

ClassifierBase.m

+

SOURCE CODE ^

+
0001 % Abstract class for classification. Implement the functions for any
+0002 % classifier (e.g. LibSVM, LDA, MLR, RFs, Adaboost, etc.)
+0003 %
+0004 % Properties:
+0005 % instanceSet: the training/test set in an InstanceSet structure
+0006 %
+0007 % Functions:
+0008 %Implement this function to train the classification models. Each
+0009 %implementation should define the type of models that are to be trained by
+0010 %the build function.
+0011 %   obj = obj.build();
+0012 %Implement this function to apply the classification models to the provided
+0013 %instance, where instance is a matrix #instances x #features including the
+0014 %instances. The function should return the following three outputs; 1)
+0015 %output, the classified labels of the instances (#instances x 1), 2)
+0016 %probabilities, the probabilities for the output label (instances x 1) and
+0017 %3) ranking, a matrix #instances x #classes with the probabilities of each
+0018 %instance for each class (used for multiclass classification).
+0019 %   [output, probabilities, ranking] = obj.classifyInstance(instance);
+0020 %Implement this function to reset the classifier (e.g. delete the stored
+0021 %classification models
+0022 %   obj.reset();
+0023 %Info & run time so that the experiments are easily documented. configInfo
+0024 %is a string with the configuration information and time is of type double.
+0025 %   configInfo = obj.getConfigInfo();
+0026 %   time = obj.getTime();
+0027 
+0028 classdef (Abstract) ClassifierBase < handle
+0029     
+0030     properties
+0031         instanceSet;
+0032     end
+0033     
+0034     methods (Abstract = true)
+0035         [output, probabilities, ranking] = classifyInstance(obj,instance);
+0036         obj = build(obj);
+0037         obj = reset(obj);
+0038         configInfo = getConfigInfo(obj);
+0039         time = getTime(obj);
+0040     end
+0041     
+0042 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m b/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m new file mode 100644 index 0000000..531957d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/ClassifierBase.m @@ -0,0 +1,42 @@ +% Abstract class for classification. Implement the functions for any +% classifier (e.g. LibSVM, LDA, MLR, RFs, Adaboost, etc.) +% +% Properties: +% instanceSet: the training/test set in an InstanceSet structure +% +% Functions: +%Implement this function to train the classification models. Each +%implementation should define the type of models that are to be trained by +%the build function. +% obj = obj.build(); +%Implement this function to apply the classification models to the provided +%instance, where instance is a matrix #instances x #features including the +%instances. The function should return the following three outputs; 1) +%output, the classified labels of the instances (#instances x 1), 2) +%probabilities, the probabilities for the output label (instances x 1) and +%3) ranking, a matrix #instances x #classes with the probabilities of each +%instance for each class (used for multiclass classification). +% [output, probabilities, ranking] = obj.classifyInstance(instance); +%Implement this function to reset the classifier (e.g. delete the stored +%classification models +% obj.reset(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + +classdef (Abstract) ClassifierBase < handle + + properties + instanceSet; + end + + methods (Abstract = true) + [output, probabilities, ranking] = classifyInstance(obj,instance); + obj = build(obj); + obj = reset(obj); + configInfo = getConfigInfo(obj); + time = getTime(obj); + end + +end diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/graph.dot b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.dot new file mode 100644 index 0000000..83eb9bc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ClassifierBase -> ClassifierBase; + + ClassifierBase [URL="ClassifierBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/graph.html b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.html new file mode 100644 index 0000000..408b325 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@ClassifierBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@ClassifierBase >
+

Dependency Graph for +eegtoolkit/+classification/@ClassifierBase

+ +
+Dependency Graph for +eegtoolkit/+classification/@ClassifierBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/graph.map b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.map new file mode 100644 index 0000000..d23b2fe --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/graph.png b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.png new file mode 100644 index 0000000..d388ebd Binary files /dev/null and b/doc/+eegtoolkit/+classification/@ClassifierBase/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@ClassifierBase/index.html b/doc/+eegtoolkit/+classification/@ClassifierBase/index.html new file mode 100644 index 0000000..70e6013 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ClassifierBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@ClassifierBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@ClassifierBase >
+ +

Index for +eegtoolkit/+classification/@ClassifierBase

+ +

Matlab files in this directory:

+ +
 ClassifierBaseAbstract class for classification. Implement the functions for any
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.html b/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.html new file mode 100644 index 0000000..cf87380 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.html @@ -0,0 +1,223 @@ + + + + Description of CombiCCA + + + + + + + + + +
Home > +eegtoolkit > +classification > @CombiCCA > CombiCCA.m
+ + + +

CombiCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

CombiCCA.m

+

SOURCE CODE ^

+
0001 classdef CombiCCA < eegtoolkit.classification.ClassifierBase;
+0002     %COMBICCA Summary of this class goes here
+0003     %   Detailed explanation goes here
+0004     %     fprintf('CombitCCA Processing TW %fs, No.crossvalidation %d \n',TW(tw_length),run);
+0005     %                         it=cell(12,1);
+0006     %                         for iN = 1:nClasses
+0007     %                             it{iN} = mean(SSVEPdata(chan_used,1:TW_p(tw_length),idx_traindata,iN),3);
+0008     %                         end
+0009     %                         % recognize SSVEP
+0010     properties
+0011         individualTemplates;
+0012         refSignals;
+0013         %         sti_f;
+0014         baseClassifier;
+0015     end
+0016     
+0017     methods
+0018         function CoCCA = CombiCCA( sti_f, numHarmonics, sampleLength, samplingRate)
+0019             %             CoCCA.sti_f = sti_f;
+0020             %             CoCCA.numHarmonics = numHarmonics;
+0021             CoCCA.refSignals = CoCCA.ck_signalTrans(sti_f,sampleLength, samplingRate, numHarmonics);
+0022         end
+0023         
+0024         function CoCCA = build(CoCCA)
+0025             numLabels = length(unique(CoCCA.instanceSet.labels));
+0026             CoCCA.individualTemplates = cell(numLabels,1);
+0027             unLabels = unique(CoCCA.instanceSet.labels);
+0028             for i=1:numLabels
+0029                 trialsIndices = CoCCA.instanceSet.labels==unLabels(i);
+0030                 CoCCA.individualTemplates{i} = squeeze(mean(CoCCA.instanceSet.sMatrix(trialsIndices,:,:),1));
+0031             end
+0032             
+0033         end
+0034         
+0035         function [output, probabilities, ranking] = classifyInstance(CoCCA,instance)
+0036             testInstances = CoCCA.extract(instance);
+0037             [output, probabilities, ranking] = CoCCA.baseClassifier.classifyInstance(testInstances);
+0038         end
+0039         
+0040         function CSP = reset(CSP)
+0041             % 'Resets' the classifier.
+0042             %             CSP.models = {};
+0043         end
+0044         
+0045         function configInfo = getConfigInfo(CSP)
+0046             configInfo = '\n';
+0047         end
+0048         
+0049         
+0050         function time = getTime(CSP)
+0051             time = 0;
+0052         end
+0053         
+0054     end
+0055     methods (Access = private)
+0056         
+0057         function [Wx, Wy, r] = cca(CCA,X,Y)
+0058             %
+0059             % CCA calculate canonical correlations
+0060             %
+0061             % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation
+0062             
+0063             % vectors as columns and r is a vector with corresponding canonical
+0064             % correlations. The correlations are sorted in descending order. X and Y
+0065             % are matrices where each column is a sample. Hence, X and Y must have
+0066             % the same number of columns.
+0067             %
+0068             % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is
+0069             % then M*L, Wy is N*L and r is L*1.
+0070             %
+0071             %
+0072             % ?? 2000 Magnus Borga, Link?pings universitet
+0073             
+0074             % --- Calculate covariance matrices ---??????????????
+0075             
+0076             z = [X;Y];
+0077             C = cov(z.');
+0078             sx = size(X,1);   %X??????(??),
+0079             sy = size(Y,1);
+0080             Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx);
+0081             Cxy = C(1:sx, sx+1:sx+sy);
+0082             Cyx = Cxy';
+0083             Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()????????
+0084             invCyy = inv(Cyy);
+0085             
+0086             % --- Calcualte Wx and r ---
+0087             
+0088             [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig????????????
+0089             r = sqrt(real(r));      % Canonical correlations
+0090             
+0091             % --- Sort correlations ---
+0092             
+0093             V = fliplr(Wx);        % reverse order of eigenvectors??????????????????????i??????????i??????
+0094             r = flipud(diag(r));    % extract eigenvalues and reverse their order
+0095             [r,I]= sort((real(r)));    % sort reversed eigenvalues in ascending order
+0096             r = flipud(r);        % restore sorted eigenvalues into descending order??????????????
+0097             for j = 1:length(I)
+0098                 Wx(:,j) = V(:,I(j));  % sort reversed eigenvectors in ascending order
+0099             end
+0100             Wx = fliplr(Wx);    % restore sorted eigenvectors into descending order
+0101             
+0102             % --- Calcualte Wy  ---
+0103             
+0104             Wy = invCyy*Cyx*Wx;     % Basis in Y
+0105             % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy
+0106             
+0107         end
+0108         function instancesOutput = extract(CoCCA,sMatrix)
+0109             numClasses = length(CoCCA.individualTemplates);
+0110             numInstances = size(sMatrix,1);
+0111             instancesOutput = zeros(numInstances,numClasses);
+0112             for i=1:numInstances
+0113                 for j=1:numClasses
+0114                     [wxit,wyit,rit] = CoCCA.cca(squeeze(sMatrix(i,:,:)),CoCCA.individualTemplates{j});
+0115                     [wxref,wyref,rref] = CoCCA.cca(squeeze(sMatrix(i,:,:)),CoCCA.refSignals(:,:,j));
+0116                     [wxitref,wyitref,ritref] = CoCCA.cca(CoCCA.individualTemplates{j},CoCCA.refSignals(:,:,j));
+0117                     q1 = squeeze(sMatrix(i,:,:))'*wxref;
+0118                     q2 = CoCCA.refSignals(:,:,j)'*wyref;
+0119                     q3 = squeeze(sMatrix(i,:,:))'*wxit;
+0120                     q4 = CoCCA.individualTemplates{j}'*wxit;
+0121                     q5 = q1;
+0122                     q6 = CoCCA.individualTemplates{j}'*wxref;
+0123                     q7 = squeeze(sMatrix(i,:,:))'*wxitref;
+0124                     q8 = CoCCA.individualTemplates{j}'*wxitref;
+0125                     r_n = [corr(q1(:),q2(:)) corr(q3(:),q4(:)) corr(q5(:),q6(:)) corr(q7(:), q8(:))];
+0126                     rho_n = sum(sign(r_n).*r_n.^2);
+0127                     instancesOutput(i,j) = rho_n;
+0128                 end
+0129             end
+0130         end
+0131         %                         for j=1:nClasses
+0132         %                             tempvec=zeros(nClasses,1);
+0133         %                             for jj=1:nClasses
+0134         %                                 [wxit,wyit,rit ]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length)));
+0135         %                                 [wxref,wyref,rref ]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),sc{jj}(:,1:TW_p(tw_length)));
+0136         %                                 [wxitref,wyitref,ritref ]=cca(it{jj}(:,1:TW_p(tw_length)),sc{jj}(:,1:TW_p(tw_length)));
+0137         %                                 q1 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxref;
+0138         %                                 q2 = sc{jj}(:,1:TW_p(tw_length))'*wyref;
+0139         %                                 q3 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxit;
+0140         %                                 q4 = it{jj}(:,1:TW_p(tw_length))'*wxit;
+0141         %                                 q5 = q1;
+0142         %                                 q6 = it{jj}(:,1:TW_p(tw_length))'*wxref;
+0143         %                                 q7 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxitref;
+0144         %                                 q8 = it{jj}(:,1:TW_p(tw_length))'*wxitref;
+0145         %                                 r_n = [corr(q1(:),q2(:)) corr(q3(:),q4(:)) corr(q5(:),q6(:)) corr(q7(:),q8(:))];
+0146         %                                 rho_n = sum(sign(r_n).*r_n.^2);
+0147         %                                 tempvec(jj) = rho_n;%max(r1);
+0148         %                             end
+0149         %
+0150         %                             [v,idx]=max(tempvec);
+0151         %                             sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx;
+0152         %                             if idx==j
+0153         %                                 n_correct(tw_length,mth)=n_correct(tw_length,mth)+1;
+0154         %                             end
+0155         %                         end
+0156         function refSignal=ck_signalTrans(CCA,f,mLen,FreqSamp,NumHarm)
+0157             
+0158             p=mLen;%1250;
+0159             fs=FreqSamp;%250;
+0160             TP=1/fs:1/fs:p/fs;
+0161             for j=1:length(f)
+0162                 tempComp=[];
+0163                 for k=1:NumHarm
+0164                     Sinh1=sin(2*pi*k*f(j)*TP);
+0165                     Cosh1=cos(2*pi*k*f(j)*TP);
+0166                     tempComp = [tempComp; Sinh1;Cosh1;];
+0167                 end
+0168                 refSignal(:,:,j)=tempComp;
+0169             end
+0170         end
+0171     end
+0172 end
+0173
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.m b/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.m new file mode 100644 index 0000000..585d5a0 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/CombiCCA.m @@ -0,0 +1,173 @@ +classdef CombiCCA < eegtoolkit.classification.ClassifierBase; + %COMBICCA Summary of this class goes here + % Detailed explanation goes here + % fprintf('CombitCCA Processing TW %fs, No.crossvalidation %d \n',TW(tw_length),run); + % it=cell(12,1); + % for iN = 1:nClasses + % it{iN} = mean(SSVEPdata(chan_used,1:TW_p(tw_length),idx_traindata,iN),3); + % end + % % recognize SSVEP + properties + individualTemplates; + refSignals; + % sti_f; + baseClassifier; + end + + methods + function CoCCA = CombiCCA( sti_f, numHarmonics, sampleLength, samplingRate) + % CoCCA.sti_f = sti_f; + % CoCCA.numHarmonics = numHarmonics; + CoCCA.refSignals = CoCCA.ck_signalTrans(sti_f,sampleLength, samplingRate, numHarmonics); + end + + function CoCCA = build(CoCCA) + numLabels = length(unique(CoCCA.instanceSet.labels)); + CoCCA.individualTemplates = cell(numLabels,1); + unLabels = unique(CoCCA.instanceSet.labels); + for i=1:numLabels + trialsIndices = CoCCA.instanceSet.labels==unLabels(i); + CoCCA.individualTemplates{i} = squeeze(mean(CoCCA.instanceSet.sMatrix(trialsIndices,:,:),1)); + end + + end + + function [output, probabilities, ranking] = classifyInstance(CoCCA,instance) + testInstances = CoCCA.extract(instance); + [output, probabilities, ranking] = CoCCA.baseClassifier.classifyInstance(testInstances); + end + + function CSP = reset(CSP) + % 'Resets' the classifier. + % CSP.models = {}; + end + + function configInfo = getConfigInfo(CSP) + configInfo = '\n'; + end + + + function time = getTime(CSP) + time = 0; + end + + end + methods (Access = private) + + function [Wx, Wy, r] = cca(CCA,X,Y) + % + % CCA calculate canonical correlations + % + % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation + + % vectors as columns and r is a vector with corresponding canonical + % correlations. The correlations are sorted in descending order. X and Y + % are matrices where each column is a sample. Hence, X and Y must have + % the same number of columns. + % + % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is + % then M*L, Wy is N*L and r is L*1. + % + % + % ?? 2000 Magnus Borga, Link?pings universitet + + % --- Calculate covariance matrices ---?????????????? + + z = [X;Y]; + C = cov(z.'); + sx = size(X,1); %X??????(??), + sy = size(Y,1); + Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx); + Cxy = C(1:sx, sx+1:sx+sy); + Cyx = Cxy'; + Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()???????? + invCyy = inv(Cyy); + + % --- Calcualte Wx and r --- + + [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig???????????? + r = sqrt(real(r)); % Canonical correlations + + % --- Sort correlations --- + + V = fliplr(Wx); % reverse order of eigenvectors??????????????????????i??????????i?????? + r = flipud(diag(r)); % extract eigenvalues and reverse their order + [r,I]= sort((real(r))); % sort reversed eigenvalues in ascending order + r = flipud(r); % restore sorted eigenvalues into descending order?????????????? + for j = 1:length(I) + Wx(:,j) = V(:,I(j)); % sort reversed eigenvectors in ascending order + end + Wx = fliplr(Wx); % restore sorted eigenvectors into descending order + + % --- Calcualte Wy --- + + Wy = invCyy*Cyx*Wx; % Basis in Y + % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy + + end + function instancesOutput = extract(CoCCA,sMatrix) + numClasses = length(CoCCA.individualTemplates); + numInstances = size(sMatrix,1); + instancesOutput = zeros(numInstances,numClasses); + for i=1:numInstances + for j=1:numClasses + [wxit,wyit,rit] = CoCCA.cca(squeeze(sMatrix(i,:,:)),CoCCA.individualTemplates{j}); + [wxref,wyref,rref] = CoCCA.cca(squeeze(sMatrix(i,:,:)),CoCCA.refSignals(:,:,j)); + [wxitref,wyitref,ritref] = CoCCA.cca(CoCCA.individualTemplates{j},CoCCA.refSignals(:,:,j)); + q1 = squeeze(sMatrix(i,:,:))'*wxref; + q2 = CoCCA.refSignals(:,:,j)'*wyref; + q3 = squeeze(sMatrix(i,:,:))'*wxit; + q4 = CoCCA.individualTemplates{j}'*wxit; + q5 = q1; + q6 = CoCCA.individualTemplates{j}'*wxref; + q7 = squeeze(sMatrix(i,:,:))'*wxitref; + q8 = CoCCA.individualTemplates{j}'*wxitref; + r_n = [corr(q1(:),q2(:)) corr(q3(:),q4(:)) corr(q5(:),q6(:)) corr(q7(:), q8(:))]; + rho_n = sum(sign(r_n).*r_n.^2); + instancesOutput(i,j) = rho_n; + end + end + end + % for j=1:nClasses + % tempvec=zeros(nClasses,1); + % for jj=1:nClasses + % [wxit,wyit,rit ]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length))); + % [wxref,wyref,rref ]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),sc{jj}(:,1:TW_p(tw_length))); + % [wxitref,wyitref,ritref ]=cca(it{jj}(:,1:TW_p(tw_length)),sc{jj}(:,1:TW_p(tw_length))); + % q1 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxref; + % q2 = sc{jj}(:,1:TW_p(tw_length))'*wyref; + % q3 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxit; + % q4 = it{jj}(:,1:TW_p(tw_length))'*wxit; + % q5 = q1; + % q6 = it{jj}(:,1:TW_p(tw_length))'*wxref; + % q7 = SSVEPdata(chan_used,1:TW_p(tw_length),run,j)'*wxitref; + % q8 = it{jj}(:,1:TW_p(tw_length))'*wxitref; + % r_n = [corr(q1(:),q2(:)) corr(q3(:),q4(:)) corr(q5(:),q6(:)) corr(q7(:),q8(:))]; + % rho_n = sum(sign(r_n).*r_n.^2); + % tempvec(jj) = rho_n;%max(r1); + % end + % + % [v,idx]=max(tempvec); + % sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx; + % if idx==j + % n_correct(tw_length,mth)=n_correct(tw_length,mth)+1; + % end + % end + function refSignal=ck_signalTrans(CCA,f,mLen,FreqSamp,NumHarm) + + p=mLen;%1250; + fs=FreqSamp;%250; + TP=1/fs:1/fs:p/fs; + for j=1:length(f) + tempComp=[]; + for k=1:NumHarm + Sinh1=sin(2*pi*k*f(j)*TP); + Cosh1=cos(2*pi*k*f(j)*TP); + tempComp = [tempComp; Sinh1;Cosh1;]; + end + refSignal(:,:,j)=tempComp; + end + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/graph.dot b/doc/+eegtoolkit/+classification/@CombiCCA/graph.dot new file mode 100644 index 0000000..9da7469 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + CombiCCA -> CombiCCA; + + CombiCCA [URL="CombiCCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/graph.html b/doc/+eegtoolkit/+classification/@CombiCCA/graph.html new file mode 100644 index 0000000..6144892 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@CombiCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CombiCCA >
+

Dependency Graph for +eegtoolkit/+classification/@CombiCCA

+ +
+Dependency Graph for +eegtoolkit/+classification/@CombiCCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/graph.map b/doc/+eegtoolkit/+classification/@CombiCCA/graph.map new file mode 100644 index 0000000..4f27966 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/graph.png b/doc/+eegtoolkit/+classification/@CombiCCA/graph.png new file mode 100644 index 0000000..33e680a Binary files /dev/null and b/doc/+eegtoolkit/+classification/@CombiCCA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@CombiCCA/index.html b/doc/+eegtoolkit/+classification/@CombiCCA/index.html new file mode 100644 index 0000000..d3eef45 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@CombiCCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@CombiCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@CombiCCA >
+ +

Index for +eegtoolkit/+classification/@CombiCCA

+ +

Matlab files in this directory:

+ +
 CombiCCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.html b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.html new file mode 100644 index 0000000..553b9e1 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.html @@ -0,0 +1,121 @@ + + + + Description of FusionClassifierWrapper + + + + + + + + + +
Home > +eegtoolkit > +classification > @FusionClassifierWrapper > FusionClassifierWrapper.m
+ + + +

FusionClassifierWrapper +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FusionClassifierWrapper.m

+

SOURCE CODE ^

+
0001 classdef FusionClassifierWrapper < eegtoolkit.classification.ClassifierBase & eegtoolkit.experiment.Experimenter;
+0002     
+0003     properties
+0004         baseClassifier;
+0005         classifiers;
+0006     end
+0007     
+0008     methods
+0009         function FCW = FusionClassifierWrapper(baseClassifier, fusionInstanceSet)
+0010             if nargin>0
+0011                 FCW.baseClassifier = baseClassifier;
+0012             end
+0013             if nargin>1
+0014                 FCW.instanceSet = fusionInstanceSet;
+0015             end
+0016         end
+0017         
+0018         function FCW = build(FCW)
+0019             numFusion = FCW.instanceSet.numFusion;
+0020             FCW.reset;
+0021             if ~isa(FCW.baseClassifier,'eegtoolkit.classification.LIBSVM')
+0022                 error ('Only LIBSVMClassifier supported as base classifier');
+0023             else
+0024                 for i=1:numFusion
+0025                     FCW.classifiers{i} = FCW.baseClassifier.copy;
+0026                     FCW.classifiers{i} = eegtoolkit.classification.LIBSVM;
+0027                     FCW.classifiers{i}.instanceSet = FCW.instanceSet.instanceSets{i};
+0028                     FCW.classifiers{i}.build;
+0029                 end
+0030             end
+0031         end
+0032         
+0033         function [output, probabilities, ranking]  = classifyInstance(FCW,instance)
+0034             [numInstances,~] = size(instance);
+0035             numClass = length(FCW.classifiers);
+0036             out = zeros(numInstances,numClass);
+0037             output = zeros(numInstances,1);
+0038             for i=1:length(FCW.classifiers)
+0039                 [out(:,i), probabilities, ranking] = FCW.classifiers{i}.classifyInstance(instance(:,:,i));
+0040             end
+0041             for i=1:numInstances
+0042                 x = out(i,:);
+0043                 [a,b] = hist(x,unique(x));
+0044                 [~,idx] = max(a);
+0045                 output(i,:) = b(idx);
+0046             end
+0047             probabilities = [];
+0048             ranking = [];
+0049             %TODO:*****
+0050             
+0051         end
+0052         
+0053         function configInfo = getConfigInfo(FCW)
+0054             configInfo = 'FusionClassifierWrapper';
+0055         end
+0056         
+0057                         
+0058         function time = getTime(FCW)
+0059             time = 0;
+0060         end
+0061         
+0062         function FCW = reset(FCW)
+0063             FCW.classifiers = {};
+0064         end
+0065         
+0066         
+0067         
+0068     end
+0069     
+0070 end
+0071
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.m b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.m new file mode 100644 index 0000000..6da94ff --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/FusionClassifierWrapper.m @@ -0,0 +1,71 @@ +classdef FusionClassifierWrapper < eegtoolkit.classification.ClassifierBase & eegtoolkit.experiment.Experimenter; + + properties + baseClassifier; + classifiers; + end + + methods + function FCW = FusionClassifierWrapper(baseClassifier, fusionInstanceSet) + if nargin>0 + FCW.baseClassifier = baseClassifier; + end + if nargin>1 + FCW.instanceSet = fusionInstanceSet; + end + end + + function FCW = build(FCW) + numFusion = FCW.instanceSet.numFusion; + FCW.reset; + if ~isa(FCW.baseClassifier,'eegtoolkit.classification.LIBSVM') + error ('Only LIBSVMClassifier supported as base classifier'); + else + for i=1:numFusion + FCW.classifiers{i} = FCW.baseClassifier.copy; + FCW.classifiers{i} = eegtoolkit.classification.LIBSVM; + FCW.classifiers{i}.instanceSet = FCW.instanceSet.instanceSets{i}; + FCW.classifiers{i}.build; + end + end + end + + function [output, probabilities, ranking] = classifyInstance(FCW,instance) + [numInstances,~] = size(instance); + numClass = length(FCW.classifiers); + out = zeros(numInstances,numClass); + output = zeros(numInstances,1); + for i=1:length(FCW.classifiers) + [out(:,i), probabilities, ranking] = FCW.classifiers{i}.classifyInstance(instance(:,:,i)); + end + for i=1:numInstances + x = out(i,:); + [a,b] = hist(x,unique(x)); + [~,idx] = max(a); + output(i,:) = b(idx); + end + probabilities = []; + ranking = []; + %TODO:***** + + end + + function configInfo = getConfigInfo(FCW) + configInfo = 'FusionClassifierWrapper'; + end + + + function time = getTime(FCW) + time = 0; + end + + function FCW = reset(FCW) + FCW.classifiers = {}; + end + + + + end + +end + diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.dot b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.dot new file mode 100644 index 0000000..14ffcbc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FusionClassifierWrapper -> FusionClassifierWrapper; + + FusionClassifierWrapper [URL="FusionClassifierWrapper.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.html b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.html new file mode 100644 index 0000000..7bfce6d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@FusionClassifierWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@FusionClassifierWrapper >
+

Dependency Graph for +eegtoolkit/+classification/@FusionClassifierWrapper

+ +
+Dependency Graph for +eegtoolkit/+classification/@FusionClassifierWrapper + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.map b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.map new file mode 100644 index 0000000..edb3bf2 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.png b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.png new file mode 100644 index 0000000..6c7dd89 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/index.html b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/index.html new file mode 100644 index 0000000..316070d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@FusionClassifierWrapper/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@FusionClassifierWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@FusionClassifierWrapper >
+ +

Index for +eegtoolkit/+classification/@FusionClassifierWrapper

+ +

Matlab files in this directory:

+ +
 FusionClassifierWrapper
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.html b/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.html new file mode 100644 index 0000000..55929cd --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.html @@ -0,0 +1,256 @@ + + + + Description of ITCCA + + + + + + + + + +
Home > +eegtoolkit > +classification > @ITCCA > ITCCA.m
+ + + +

ITCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ITCCA.m

+

SOURCE CODE ^

+
0001 classdef ITCCA < eegtoolkit.classification.ClassifierBase;
+0002     %                 instanceStruct = struct('sMatrix',sMatrix, 'labels', labels);
+0003     %     it=cell(12,1);
+0004     %                         for iN = 1:nClasses
+0005     %                             it{iN} = mean(SSVEPdata(chan_used,1:TW_p(tw_length),idx_traindata,iN),3);
+0006     %                         end
+0007     %                         % recognize SSVEP
+0008     %                         for j=1:nClasses
+0009     %                             tempvec=zeros(nClasses,1);
+0010     %                             for jj=1:nClasses
+0011     %                                 [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length)));
+0012     %                                 tempvec(jj) = max(r1);
+0013     %                             end
+0014     %
+0015     %                             [v,idx]=max(tempvec);
+0016     %                             sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx;
+0017     %                             if idx==j
+0018     %                                 n_correct(tw_length,mth)=n_correct(tw_length,mth)+1;
+0019     %                             end
+0020     %                         end
+0021     properties (Constant)
+0022         
+0023     end
+0024     properties
+0025         baseClassifier;
+0026         individualTemplates;
+0027     end
+0028     
+0029     methods (Access = public)
+0030         function IT = ITCCA(instanceSet)
+0031             %             if(isa(instanceSet,'eegtoolkit.util.RawSignalSet')
+0032             %                 CSP.instanceSet = instanceSet;
+0033             %             else
+0034             %                 error('RawSignal extractor should be used with CSPWrapper');
+0035             %             end
+0036         end
+0037         
+0038         
+0039         function IT = build(IT)
+0040             % Builds the classification models
+0041             %             IT.learnCSPMatrix(IT.instanceSet.sMatrix,IT.instanceSet.labels);
+0042             numLabels = length(unique(IT.instanceSet.labels));
+0043             IT.individualTemplates = cell(numLabels,1);
+0044             unLabels = unique(IT.instanceSet.labels);
+0045             for i = 1:numLabels
+0046                 trialsIndices = IT.instanceSet.labels==unLabels(i);
+0047                 IT.individualTemplates{i} = squeeze(mean(IT.instanceSet.sMatrix(trialsIndices,:,:),1));
+0048             end
+0049             %             instances = IT.extract(IT.instanceSet.sMatrix);
+0050             %             instanceSet = eegtoolkit.util.InstanceSet(instances,IT.instanceSet.labels);
+0051             %             IT.baseClassifier.instanceSet = instanceSet;
+0052             %             IT.baseClassifier.build();
+0053         end
+0054         
+0055         function [output, probabilities, ranking] = classifyInstance(CSP,instance)
+0056             %                         for j=1:nClasses
+0057             %                             tempvec=zeros(nClasses,1);
+0058             %                             for jj=1:nClasses
+0059             %                                 [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length)));
+0060             %                                 tempvec(jj) = max(r1);
+0061             %                             end
+0062             %
+0063             %                             [v,idx]=max(tempvec);
+0064             %                             sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx;
+0065             %                             if idx==j
+0066             %                                 n_correct(tw_length,mth)=n_correct(tw_length,mth)+1;
+0067             %                             end
+0068             %                         end
+0069             %             instance = CSP.extract
+0070             %input = instance matrix rows = instances, cols = attributes
+0071             %output = predicted class
+0072             %probabilities = probability for predicted class
+0073             %ranking = propabilities for all classes (e.g. to use with mAP)
+0074             
+0075             %TODO:should print an error if 'build' has not been called
+0076             testInstances = CSP.extract(instance);
+0077             [output, probabilities, ranking] = CSP.baseClassifier.classifyInstance(testInstances);
+0078             %             numModels = length(LSVM.models);
+0079             %             [numinstance, ~] = size(testInstances);
+0080             %             scores = zeros(numModels,numinstance);
+0081             %             for i=1:numModels
+0082             %                 %predict using the stored models
+0083             %                 [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q');
+0084             %                 %store probability for each class
+0085             %                 scores(i,:) = t(:,1);
+0086             %             end
+0087             %             output = zeros(numinstance,1);
+0088             %             probabilities = zeros(numinstance,1);
+0089             %             ranking = scores;
+0090             %             for i=1:numinstance
+0091             %                 %select the class with the highest probability
+0092             %                 [prob, idx] = max(scores(:,i));
+0093             %                 uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0094             %                 %output the label with highest probability
+0095             %                 output(i,1) = uniqueLabels(idx);
+0096             %                 %return the probability for the output label
+0097             %                 probabilities(i,1) = prob;
+0098             %             end
+0099         end
+0100         
+0101         function CSP = reset(CSP)
+0102             % 'Resets' the classifier.
+0103             %             CSP.models = {};
+0104         end
+0105         
+0106         function configInfo = getConfigInfo(CSP)
+0107             configInfo = '\n';
+0108         end
+0109         
+0110         
+0111         function time = getTime(CSP)
+0112             time = 0;
+0113         end
+0114     end
+0115     
+0116     
+0117     methods (Access = private)
+0118         function [Wx, Wy, r] = cca(CCA,X,Y)
+0119             %
+0120             % CCA calculate canonical correlations
+0121             %
+0122             % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation
+0123             
+0124             % vectors as columns and r is a vector with corresponding canonical
+0125             % correlations. The correlations are sorted in descending order. X and Y
+0126             % are matrices where each column is a sample. Hence, X and Y must have
+0127             % the same number of columns.
+0128             %
+0129             % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is
+0130             % then M*L, Wy is N*L and r is L*1.
+0131             %
+0132             %
+0133             % ?? 2000 Magnus Borga, Link?pings universitet
+0134             
+0135             % --- Calculate covariance matrices ---??????????????
+0136             
+0137             z = [X;Y];
+0138             C = cov(z.');
+0139             sx = size(X,1);   %X??????(??),
+0140             sy = size(Y,1);
+0141             Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx);
+0142             Cxy = C(1:sx, sx+1:sx+sy);
+0143             Cyx = Cxy';
+0144             Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()????????
+0145             invCyy = inv(Cyy);
+0146             
+0147             % --- Calcualte Wx and r ---
+0148             
+0149             [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig????????????
+0150             r = sqrt(real(r));      % Canonical correlations
+0151             
+0152             % --- Sort correlations ---
+0153             
+0154             V = fliplr(Wx);        % reverse order of eigenvectors??????????????????????i??????????i??????
+0155             r = flipud(diag(r));    % extract eigenvalues and reverse their order
+0156             [r,I]= sort((real(r)));    % sort reversed eigenvalues in ascending order
+0157             r = flipud(r);        % restore sorted eigenvalues into descending order??????????????
+0158             for j = 1:length(I)
+0159                 Wx(:,j) = V(:,I(j));  % sort reversed eigenvectors in ascending order
+0160             end
+0161             Wx = fliplr(Wx);    % restore sorted eigenvectors into descending order
+0162             
+0163             % --- Calcualte Wy  ---
+0164             
+0165             Wy = invCyy*Cyx*Wx;     % Basis in Y
+0166             % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy
+0167             
+0168         end
+0169         
+0170         
+0171         function instancesOutput = extract(IT,sMatrix)
+0172             
+0173             numClasses = length(IT.individualTemplates);
+0174             numInstances = size(sMatrix,1);
+0175             tempvec=zeros(numClasses,1);
+0176             instancesOutput = zeros(numInstances,numClasses);
+0177             for i=1:numInstances
+0178                 for j=1:numClasses
+0179                     [~,~,r1] = IT.cca(squeeze(sMatrix(i,:,:)),IT.individualTemplates{j});
+0180                     %                     [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),IT.individualTemplates{j});
+0181                     instancesOutput(i,j) = max(r1);
+0182                 end
+0183             end
+0184             
+0185             %             [v,idx]=max(tempvec);
+0186             %             sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx;
+0187             %             if idx==j
+0188             %                 n_correct(tw_length,mth)=n_correct(tw_length,mth)+1;
+0189             %             end
+0190             %
+0191             %             [numTrials,numChannels,~] = size(sMatrix);
+0192             %             sMatrix = permute(sMatrix,[3,2,1]);
+0193             %             for i=1:size(sMatrix,3);
+0194             %                 sMatrix(:,:,i) = (CSP.cspFilter*sMatrix(:,:,i)')';
+0195             %             end
+0196             %             instances = zeros(numTrials,numChannels);
+0197             %             for i=1:numTrials
+0198             %                 projectedTrial = sMatrix(:,:,i);
+0199             %                 variances = var(projectedTrial,0,1);
+0200             %                 instances(i,:) = log(variances)';
+0201             %             end
+0202             %             instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0203         end
+0204     end
+0205 end
+0206
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.m b/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.m new file mode 100644 index 0000000..2ff83dd --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/ITCCA.m @@ -0,0 +1,206 @@ +classdef ITCCA < eegtoolkit.classification.ClassifierBase; + % instanceStruct = struct('sMatrix',sMatrix, 'labels', labels); + % it=cell(12,1); + % for iN = 1:nClasses + % it{iN} = mean(SSVEPdata(chan_used,1:TW_p(tw_length),idx_traindata,iN),3); + % end + % % recognize SSVEP + % for j=1:nClasses + % tempvec=zeros(nClasses,1); + % for jj=1:nClasses + % [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length))); + % tempvec(jj) = max(r1); + % end + % + % [v,idx]=max(tempvec); + % sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx; + % if idx==j + % n_correct(tw_length,mth)=n_correct(tw_length,mth)+1; + % end + % end + properties (Constant) + + end + properties + baseClassifier; + individualTemplates; + end + + methods (Access = public) + function IT = ITCCA(instanceSet) + % if(isa(instanceSet,'eegtoolkit.util.RawSignalSet') + % CSP.instanceSet = instanceSet; + % else + % error('RawSignal extractor should be used with CSPWrapper'); + % end + end + + + function IT = build(IT) + % Builds the classification models + % IT.learnCSPMatrix(IT.instanceSet.sMatrix,IT.instanceSet.labels); + numLabels = length(unique(IT.instanceSet.labels)); + IT.individualTemplates = cell(numLabels,1); + unLabels = unique(IT.instanceSet.labels); + for i = 1:numLabels + trialsIndices = IT.instanceSet.labels==unLabels(i); + IT.individualTemplates{i} = squeeze(mean(IT.instanceSet.sMatrix(trialsIndices,:,:),1)); + end + % instances = IT.extract(IT.instanceSet.sMatrix); + % instanceSet = eegtoolkit.util.InstanceSet(instances,IT.instanceSet.labels); + % IT.baseClassifier.instanceSet = instanceSet; + % IT.baseClassifier.build(); + end + + function [output, probabilities, ranking] = classifyInstance(CSP,instance) + % for j=1:nClasses + % tempvec=zeros(nClasses,1); + % for jj=1:nClasses + % [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),it{jj}(:,1:TW_p(tw_length))); + % tempvec(jj) = max(r1); + % end + % + % [v,idx]=max(tempvec); + % sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx; + % if idx==j + % n_correct(tw_length,mth)=n_correct(tw_length,mth)+1; + % end + % end + % instance = CSP.extract + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + testInstances = CSP.extract(instance); + [output, probabilities, ranking] = CSP.baseClassifier.classifyInstance(testInstances); + % numModels = length(LSVM.models); + % [numinstance, ~] = size(testInstances); + % scores = zeros(numModels,numinstance); + % for i=1:numModels + % %predict using the stored models + % [~, ~, t] = svmpredict(eye(numinstance,1),testInstances, LSVM.models{i},'-b 1 -q'); + % %store probability for each class + % scores(i,:) = t(:,1); + % end + % output = zeros(numinstance,1); + % probabilities = zeros(numinstance,1); + % ranking = scores; + % for i=1:numinstance + % %select the class with the highest probability + % [prob, idx] = max(scores(:,i)); + % uniqueLabels = unique(LSVM.instanceSet.getLabels); + % %output the label with highest probability + % output(i,1) = uniqueLabels(idx); + % %return the probability for the output label + % probabilities(i,1) = prob; + % end + end + + function CSP = reset(CSP) + % 'Resets' the classifier. + % CSP.models = {}; + end + + function configInfo = getConfigInfo(CSP) + configInfo = '\n'; + end + + + function time = getTime(CSP) + time = 0; + end + end + + + methods (Access = private) + function [Wx, Wy, r] = cca(CCA,X,Y) + % + % CCA calculate canonical correlations + % + % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation + + % vectors as columns and r is a vector with corresponding canonical + % correlations. The correlations are sorted in descending order. X and Y + % are matrices where each column is a sample. Hence, X and Y must have + % the same number of columns. + % + % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is + % then M*L, Wy is N*L and r is L*1. + % + % + % ?? 2000 Magnus Borga, Link?pings universitet + + % --- Calculate covariance matrices ---?????????????? + + z = [X;Y]; + C = cov(z.'); + sx = size(X,1); %X??????(??), + sy = size(Y,1); + Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx); + Cxy = C(1:sx, sx+1:sx+sy); + Cyx = Cxy'; + Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()???????? + invCyy = inv(Cyy); + + % --- Calcualte Wx and r --- + + [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig???????????? + r = sqrt(real(r)); % Canonical correlations + + % --- Sort correlations --- + + V = fliplr(Wx); % reverse order of eigenvectors??????????????????????i??????????i?????? + r = flipud(diag(r)); % extract eigenvalues and reverse their order + [r,I]= sort((real(r))); % sort reversed eigenvalues in ascending order + r = flipud(r); % restore sorted eigenvalues into descending order?????????????? + for j = 1:length(I) + Wx(:,j) = V(:,I(j)); % sort reversed eigenvectors in ascending order + end + Wx = fliplr(Wx); % restore sorted eigenvectors into descending order + + % --- Calcualte Wy --- + + Wy = invCyy*Cyx*Wx; % Basis in Y + % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy + + end + + + function instancesOutput = extract(IT,sMatrix) + + numClasses = length(IT.individualTemplates); + numInstances = size(sMatrix,1); + tempvec=zeros(numClasses,1); + instancesOutput = zeros(numInstances,numClasses); + for i=1:numInstances + for j=1:numClasses + [~,~,r1] = IT.cca(squeeze(sMatrix(i,:,:)),IT.individualTemplates{j}); + % [wx1,wy1,r1]=cca(SSVEPdata(chan_used,1:TW_p(tw_length),run,j),IT.individualTemplates{j}); + instancesOutput(i,j) = max(r1); + end + end + + % [v,idx]=max(tempvec); + % sub_lab(mth,(run-1)*nClasses+j,tw_length)=idx; + % if idx==j + % n_correct(tw_length,mth)=n_correct(tw_length,mth)+1; + % end + % + % [numTrials,numChannels,~] = size(sMatrix); + % sMatrix = permute(sMatrix,[3,2,1]); + % for i=1:size(sMatrix,3); + % sMatrix(:,:,i) = (CSP.cspFilter*sMatrix(:,:,i)')'; + % end + % instances = zeros(numTrials,numChannels); + % for i=1:numTrials + % projectedTrial = sMatrix(:,:,i); + % variances = var(projectedTrial,0,1); + % instances(i,:) = log(variances)'; + % end + % instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@ITCCA/graph.dot b/doc/+eegtoolkit/+classification/@ITCCA/graph.dot new file mode 100644 index 0000000..c21624b --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ITCCA -> ITCCA; + + ITCCA [URL="ITCCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ITCCA/graph.html b/doc/+eegtoolkit/+classification/@ITCCA/graph.html new file mode 100644 index 0000000..7bf21c6 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@ITCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@ITCCA >
+

Dependency Graph for +eegtoolkit/+classification/@ITCCA

+ +
+Dependency Graph for +eegtoolkit/+classification/@ITCCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@ITCCA/graph.map b/doc/+eegtoolkit/+classification/@ITCCA/graph.map new file mode 100644 index 0000000..3226b8d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@ITCCA/graph.png b/doc/+eegtoolkit/+classification/@ITCCA/graph.png new file mode 100644 index 0000000..ec55bcf Binary files /dev/null and b/doc/+eegtoolkit/+classification/@ITCCA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@ITCCA/index.html b/doc/+eegtoolkit/+classification/@ITCCA/index.html new file mode 100644 index 0000000..6506a0a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@ITCCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@ITCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@ITCCA >
+ +

Index for +eegtoolkit/+classification/@ITCCA

+ +

Matlab files in this directory:

+ +
 ITCCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.html b/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.html new file mode 100644 index 0000000..5022b3f --- /dev/null +++ b/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.html @@ -0,0 +1,289 @@ + + + + Description of L1MCCA + + + + + + + + + +
Home > +eegtoolkit > +classification > @L1MCCA > L1MCCA.m
+ + + +

L1MCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

L1MCCA.m

+

SOURCE CODE ^

+
0001 classdef L1MCCA< eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004         
+0005     end
+0006     properties
+0007         samplingRate;
+0008         numHarmonics;
+0009         numSeconds;
+0010         stimulusFrequencies;
+0011         models;
+0012         maxIterations;
+0013         nProjectionComponents;
+0014         lambda;
+0015     end
+0016     
+0017     properties (Access = private)
+0018         referenceSignals;
+0019         optimalReferenceSignals;
+0020         projections;
+0021     end
+0022     
+0023     methods (Access = public)
+0024         function L1MCCA = L1MCCA(samplingRate,numSeconds,numHarmonics,stimulusFrequencies)
+0025             L1MCCA.samplingRate = samplingRate;
+0026             L1MCCA.numSeconds = numSeconds;
+0027             L1MCCA.numHarmonics = numHarmonics;
+0028             L1MCCA.stimulusFrequencies = stimulusFrequencies;
+0029             
+0030             L1MCCA.maxIterations = 200;
+0031             L1MCCA.nProjectionComponents = 1;
+0032             L1MCCA.lambda = 0.02;
+0033             
+0034             L1MCCA.referenceSignals = {};
+0035             L1MCCA.projections = {};
+0036             L1MCCA.optimalReferenceSignals = {};
+0037             
+0038         end
+0039         
+0040         function L1MCCA = build(L1MCCA)
+0041             L1MCCA.reset;
+0042             n_sti = length(L1MCCA.stimulusFrequencies);
+0043             TW = 0.5:0.5:L1MCCA.numSeconds;
+0044             TW_p = round(TW*L1MCCA.samplingRate);
+0045             
+0046             for i=1:n_sti
+0047                 L1MCCA.referenceSignals{i} = L1MCCA.squarewave(L1MCCA.stimulusFrequencies(i)...
+0048                     ,L1MCCA.samplingRate,L1MCCA.numSeconds*L1MCCA.samplingRate,L1MCCA.numHarmonics);
+0049             end
+0050             for i=1:n_sti
+0051                 a = L1MCCA.instanceSet.matrix4D(:,:,L1MCCA.instanceSet.labelss==i);
+0052                 [~,~,numIns] = size(a);
+0053                 iniw3 = ones(numIns,1);
+0054                 L1MCCA.projections{i} = {};
+0055                 [L1MCCA.projections{i}{1},L1MCCA.projections{i}{2},L1MCCA.projections{i}{3}] = L1MCCA.smcca(L1MCCA.referenceSignals{i},...
+0056                     a,L1MCCA.maxIterations,iniw3,L1MCCA.nProjectionComponents,L1MCCA.lambda);
+0057             end
+0058             for i=1:n_sti
+0059                 L1MCCA.optimalReferenceSignals{i} = ttm(tensor(L1MCCA.instanceSet.matrix4D(:,:,L1MCCA.instanceSet.labelss==i)),L1MCCA.projections{i}{2}',3);
+0060                 L1MCCA.optimalReferenceSignals{i} = tenmat(L1MCCA.optimalReferenceSignals{i},1);
+0061                 L1MCCA.optimalReferenceSignals{i} = L1MCCA.optimalReferenceSignals{i}.data;
+0062                 L1MCCA.optimalReferenceSignals{i} = L1MCCA.projections{i}{1}'*L1MCCA.optimalReferenceSignals{i};
+0063             end
+0064         end
+0065         
+0066         function [output, probabilities, ranking] = classifyInstance(L1MCCA,instance)
+0067             %input = instance matrix rows = instances, cols = attributes
+0068             %output = predicted class
+0069             %probabilities = probability for predicted class
+0070             %ranking = propabilities for all classes (e.g. to use with mAP)
+0071             
+0072             %TODO:should print an error if 'build' has not been called
+0073             [~, ~,numInstance] = size(instance);
+0074             numLabels = length(L1MCCA.optimalReferenceSignals);
+0075             output = zeros(numInstance,1);
+0076             scores = zeros(numLabels,numInstance);
+0077             for i=1:numInstance
+0078                 for j=1:numLabels
+0079                     [~,~,r] = L1MCCA.cca(instance(:,:,i),L1MCCA.optimalReferenceSignals{j});
+0080                     scores(j,i) = max(r);
+0081                     
+0082                 end
+0083                 [~,output(i,1)] = max(scores(:,i));
+0084             end
+0085             ranking = scores;
+0086             probabilities = max(scores);
+0087         end
+0088         
+0089         function L1MCCA = reset(L1MCCA)
+0090 %             'Resets' the classifier.
+0091             L1MCCA.referenceSignals = {};
+0092             L1MCCA.projections = {};
+0093             L1MCCA.optimalReferenceSignals = {};
+0094         end
+0095         
+0096         function configInfo = getConfigInfo(L1MCCA)
+0097             % Prints the parameters of the classifier
+0098             configInfo = 'L1MCCA';
+0099         end
+0100         
+0101         function [Wx, Wy, r] = cca(L1MCCA,X,Y)
+0102             
+0103             % CCA calculate canonical correlations
+0104             %
+0105             % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation
+0106             % vectors as columns and r is a vector with corresponding canonical
+0107             % correlations. The correlations are sorted in descending order. X and Y
+0108             % are matrices where each column is a sample. Hence, X and Y must have
+0109             % the same number of columns.
+0110             %
+0111             % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is
+0112             % then M*L, Wy is N*L and r is L*1.
+0113             %
+0114             %
+0115             % ?? 2000 Magnus Borga, Link?pings universitet
+0116             
+0117             % --- Calculate covariance matrices ---
+0118             
+0119             z = [X;Y];
+0120             C = cov(z.');
+0121             sx = size(X,1);
+0122             sy = size(Y,1);
+0123             Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx);
+0124             Cxy = C(1:sx, sx+1:sx+sy);
+0125             Cyx = Cxy';
+0126             Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);
+0127             invCyy = inv(Cyy);
+0128             
+0129             % --- Calcualte Wx and r ---
+0130             
+0131             [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X
+0132             r = sqrt(real(r));      % Canonical correlations
+0133             
+0134             % --- Sort correlations ---
+0135             
+0136             V = fliplr(Wx);        % reverse order of eigenvectors
+0137             r = flipud(diag(r));    % extract eigenvalues and reverse their order
+0138             [r,I]= sort((real(r)));    % sort reversed eigenvalues in ascending order
+0139             r = flipud(r);        % restore sorted eigenvalues into descending order
+0140             for j = 1:length(I)
+0141                 Wx(:,j) = V(:,I(j));  % sort reversed eigenvectors in ascending order
+0142             end
+0143             Wx = fliplr(Wx);    % restore sorted eigenvectors into descending order
+0144             
+0145             % --- Calcualte Wy  ---
+0146             
+0147             Wy = invCyy*Cyx*Wx;     % Basis in Y
+0148             % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy
+0149         end
+0150         function  [w1,w3,v1] = smcca(L1MCCA,refdata,traindata,max_iter,iniw3,n_comp,lmbda)
+0151             % L1-regualrized (Sparse) Multiway CCA
+0152             % traindata:    channel x time x trial
+0153             % refdata:      references by sine-cosine waveforms
+0154             %
+0155             % Rerefence:
+0156             % [1] Y. Zhang, G. Zhou, J. Jin, M. Wang, X. Wang, A. Cichocki.
+0157             %     L1-regularized multiway canonical correlation analysis for SSVEP-based BCI.
+0158             %     IEEE Trans. Neural Syst. Rehabil. Eng., 21(6): 887-896 (2013)
+0159             % [2] T.K. Kim, R. Cipolla. Canonical correlation analysis of video volume tensor for
+0160             %     action categorization and detection. IEEE Trans. PAMI, 31(8): 1415-1428 (2009)
+0161             %
+0162             %
+0163             % by Yu Zhang, ECUST, 2014.4.29
+0164             %
+0165             
+0166             iter=1;
+0167             w3=iniw3;
+0168             w3=w3./norm(w3);
+0169             traindata=tensor(traindata);
+0170             refdata=tensor(refdata);
+0171             
+0172             er=0.00001;     % error for iteration stop
+0173             
+0174             while iter<max_iter
+0175                 projx3=ttm(traindata,w3',3);
+0176                 projx3=tenmat(projx3,1);                        % unfolding each trial tensor into i-mode matrix
+0177                 projx3=projx3.data;
+0178                 [v1,w1,r1]=L1MCCA.cca(refdata.data,projx3);
+0179                 v1=v1(:,1:n_comp); w1=w1(:,1:n_comp);
+0180                 v1=v1./norm(v1); w1=w1./norm(w1);
+0181                 projx1=ttm(traindata,w1',1);
+0182                 projx1=tenmat(projx1,3);                        % unfolding each trial tensor into i-mode matrix
+0183                 projx1=projx1.data;
+0184                 projref1=ttm(refdata,v1',1);
+0185                 projref1=projref1.data(:)';
+0186                 w3=lasso(projx1',projref1','Lambda',lmbda);
+0187                 w3=w3./norm(w3);
+0188                 if iter>1
+0189                     if all(sign(w1)==-sign(prew1))
+0190                         errw(1,iter-1)=norm(w1+prew1);
+0191                     else
+0192                         errw(1,iter-1)=norm(w1-prew1);
+0193                     end
+0194                     if all(sign(w3)==-sign(prew3))
+0195                         errw(2,iter-1)=norm(w3+prew3);
+0196                     else
+0197                         errw(2,iter-1)=norm(w3-prew3);
+0198                     end
+0199                     if all(sign(v1)==-sign(prev1))
+0200                         errw(3,iter-1)=norm(v1+prev1);
+0201                     else
+0202                         errw(3,iter-1)=norm(v1-prev1);
+0203                     end
+0204                     if errw(1,iter-1)<er && errw(2,iter-1)<er && errw(3,iter-1)<er
+0205                         break
+0206                     end
+0207                 end
+0208                 prew1=w1;
+0209                 prew3=w3;
+0210                 prev1=v1;
+0211                 iter=iter+1;
+0212             end
+0213             
+0214             fprintf('L1MCCA Iteration is %d \n',iter);
+0215         end
+0216         
+0217         
+0218         function y=squarewave(L1MCCA,f, S, T, H)
+0219             
+0220             % f-- the fundermental frequency
+0221             % S-- the sampling rate
+0222             % T-- the number of sampling points
+0223             % H-- the number of harmonics
+0224             
+0225             
+0226             for i=1:H
+0227                 for j=1:T
+0228                     t= j/S;
+0229                     y(2*i-1,j)=sin(2*pi*(i*f)*t);
+0230                     y(2*i,j)=cos(2*pi*(i*f)*t);
+0231                 end
+0232             end
+0233         end
+0234         
+0235         function time = getTime(L1MCCA)
+0236             time = 0;
+0237         end
+0238     end
+0239 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.m b/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.m new file mode 100644 index 0000000..3c65968 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@L1MCCA/L1MCCA.m @@ -0,0 +1,239 @@ +classdef L1MCCA< eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + properties + samplingRate; + numHarmonics; + numSeconds; + stimulusFrequencies; + models; + maxIterations; + nProjectionComponents; + lambda; + end + + properties (Access = private) + referenceSignals; + optimalReferenceSignals; + projections; + end + + methods (Access = public) + function L1MCCA = L1MCCA(samplingRate,numSeconds,numHarmonics,stimulusFrequencies) + L1MCCA.samplingRate = samplingRate; + L1MCCA.numSeconds = numSeconds; + L1MCCA.numHarmonics = numHarmonics; + L1MCCA.stimulusFrequencies = stimulusFrequencies; + + L1MCCA.maxIterations = 200; + L1MCCA.nProjectionComponents = 1; + L1MCCA.lambda = 0.02; + + L1MCCA.referenceSignals = {}; + L1MCCA.projections = {}; + L1MCCA.optimalReferenceSignals = {}; + + end + + function L1MCCA = build(L1MCCA) + L1MCCA.reset; + n_sti = length(L1MCCA.stimulusFrequencies); + TW = 0.5:0.5:L1MCCA.numSeconds; + TW_p = round(TW*L1MCCA.samplingRate); + + for i=1:n_sti + L1MCCA.referenceSignals{i} = L1MCCA.squarewave(L1MCCA.stimulusFrequencies(i)... + ,L1MCCA.samplingRate,L1MCCA.numSeconds*L1MCCA.samplingRate,L1MCCA.numHarmonics); + end + for i=1:n_sti + a = L1MCCA.instanceSet.matrix4D(:,:,L1MCCA.instanceSet.labelss==i); + [~,~,numIns] = size(a); + iniw3 = ones(numIns,1); + L1MCCA.projections{i} = {}; + [L1MCCA.projections{i}{1},L1MCCA.projections{i}{2},L1MCCA.projections{i}{3}] = L1MCCA.smcca(L1MCCA.referenceSignals{i},... + a,L1MCCA.maxIterations,iniw3,L1MCCA.nProjectionComponents,L1MCCA.lambda); + end + for i=1:n_sti + L1MCCA.optimalReferenceSignals{i} = ttm(tensor(L1MCCA.instanceSet.matrix4D(:,:,L1MCCA.instanceSet.labelss==i)),L1MCCA.projections{i}{2}',3); + L1MCCA.optimalReferenceSignals{i} = tenmat(L1MCCA.optimalReferenceSignals{i},1); + L1MCCA.optimalReferenceSignals{i} = L1MCCA.optimalReferenceSignals{i}.data; + L1MCCA.optimalReferenceSignals{i} = L1MCCA.projections{i}{1}'*L1MCCA.optimalReferenceSignals{i}; + end + end + + function [output, probabilities, ranking] = classifyInstance(L1MCCA,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + [~, ~,numInstance] = size(instance); + numLabels = length(L1MCCA.optimalReferenceSignals); + output = zeros(numInstance,1); + scores = zeros(numLabels,numInstance); + for i=1:numInstance + for j=1:numLabels + [~,~,r] = L1MCCA.cca(instance(:,:,i),L1MCCA.optimalReferenceSignals{j}); + scores(j,i) = max(r); + + end + [~,output(i,1)] = max(scores(:,i)); + end + ranking = scores; + probabilities = max(scores); + end + + function L1MCCA = reset(L1MCCA) +% 'Resets' the classifier. + L1MCCA.referenceSignals = {}; + L1MCCA.projections = {}; + L1MCCA.optimalReferenceSignals = {}; + end + + function configInfo = getConfigInfo(L1MCCA) + % Prints the parameters of the classifier + configInfo = 'L1MCCA'; + end + + function [Wx, Wy, r] = cca(L1MCCA,X,Y) + + % CCA calculate canonical correlations + % + % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation + % vectors as columns and r is a vector with corresponding canonical + % correlations. The correlations are sorted in descending order. X and Y + % are matrices where each column is a sample. Hence, X and Y must have + % the same number of columns. + % + % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is + % then M*L, Wy is N*L and r is L*1. + % + % + % ?? 2000 Magnus Borga, Link?pings universitet + + % --- Calculate covariance matrices --- + + z = [X;Y]; + C = cov(z.'); + sx = size(X,1); + sy = size(Y,1); + Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx); + Cxy = C(1:sx, sx+1:sx+sy); + Cyx = Cxy'; + Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy); + invCyy = inv(Cyy); + + % --- Calcualte Wx and r --- + + [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X + r = sqrt(real(r)); % Canonical correlations + + % --- Sort correlations --- + + V = fliplr(Wx); % reverse order of eigenvectors + r = flipud(diag(r)); % extract eigenvalues and reverse their order + [r,I]= sort((real(r))); % sort reversed eigenvalues in ascending order + r = flipud(r); % restore sorted eigenvalues into descending order + for j = 1:length(I) + Wx(:,j) = V(:,I(j)); % sort reversed eigenvectors in ascending order + end + Wx = fliplr(Wx); % restore sorted eigenvectors into descending order + + % --- Calcualte Wy --- + + Wy = invCyy*Cyx*Wx; % Basis in Y + % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy + end + function [w1,w3,v1] = smcca(L1MCCA,refdata,traindata,max_iter,iniw3,n_comp,lmbda) + % L1-regualrized (Sparse) Multiway CCA + % traindata: channel x time x trial + % refdata: references by sine-cosine waveforms + % + % Rerefence: + % [1] Y. Zhang, G. Zhou, J. Jin, M. Wang, X. Wang, A. Cichocki. + % L1-regularized multiway canonical correlation analysis for SSVEP-based BCI. + % IEEE Trans. Neural Syst. Rehabil. Eng., 21(6): 887-896 (2013) + % [2] T.K. Kim, R. Cipolla. Canonical correlation analysis of video volume tensor for + % action categorization and detection. IEEE Trans. PAMI, 31(8): 1415-1428 (2009) + % + % + % by Yu Zhang, ECUST, 2014.4.29 + % + + iter=1; + w3=iniw3; + w3=w3./norm(w3); + traindata=tensor(traindata); + refdata=tensor(refdata); + + er=0.00001; % error for iteration stop + + while iter1 + if all(sign(w1)==-sign(prew1)) + errw(1,iter-1)=norm(w1+prew1); + else + errw(1,iter-1)=norm(w1-prew1); + end + if all(sign(w3)==-sign(prew3)) + errw(2,iter-1)=norm(w3+prew3); + else + errw(2,iter-1)=norm(w3-prew3); + end + if all(sign(v1)==-sign(prev1)) + errw(3,iter-1)=norm(v1+prev1); + else + errw(3,iter-1)=norm(v1-prev1); + end + if errw(1,iter-1) L1MCCA; + + L1MCCA [URL="L1MCCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/graph.html b/doc/+eegtoolkit/+classification/@L1MCCA/graph.html new file mode 100644 index 0000000..07dcc62 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@L1MCCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@L1MCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@L1MCCA >
+

Dependency Graph for +eegtoolkit/+classification/@L1MCCA

+ +
+Dependency Graph for +eegtoolkit/+classification/@L1MCCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/graph.map b/doc/+eegtoolkit/+classification/@L1MCCA/graph.map new file mode 100644 index 0000000..55100c7 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@L1MCCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/graph.png b/doc/+eegtoolkit/+classification/@L1MCCA/graph.png new file mode 100644 index 0000000..99fba29 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@L1MCCA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@L1MCCA/index.html b/doc/+eegtoolkit/+classification/@L1MCCA/index.html new file mode 100644 index 0000000..69e5065 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@L1MCCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@L1MCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@L1MCCA >
+ +

Index for +eegtoolkit/+classification/@L1MCCA

+ +

Matlab files in this directory:

+ +
 L1MCCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LDA/LDA.html b/doc/+eegtoolkit/+classification/@LDA/LDA.html new file mode 100644 index 0000000..90ebdfa --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/LDA.html @@ -0,0 +1,131 @@ + + + + Description of LDA + + + + + + + + + +
Home > +eegtoolkit > +classification > @LDA > LDA.m
+ + + +

LDA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

LDA.m

+

SOURCE CODE ^

+
0001 classdef LDA < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties (Access = public)
+0008       W_LDA;
+0009       PCA_mat;
+0010       trainFeat;
+0011     end
+0012     
+0013     methods (Access = public)
+0014         function LDA = LDA(instanceSet)
+0015             if nargin > 0
+0016                 LDA.instanceSet = instanceSet;
+0017             end
+0018            
+0019         end
+0020         
+0021         function LDA = build(LDA)
+0022             LDA.reset();
+0023             data = LDA.instanceSet.getInstances;
+0024             data = data';  
+0025             labels = LDA.instanceSet.getLabels;   
+0026             unique(labels)           
+0027             numTrials = length(labels);
+0028 
+0029             PCA_W=pca_func(data);
+0030 %             PCA_W=eye(8000);
+0031             train_Data=PCA_W'*data; 
+0032             
+0033             Par.mode = 'LDA';
+0034             dim = length(unique(labels))-1;
+0035             [W,Wp] = SGE_GraphConstruct(labels,Par);
+0036             [TransMatrix,~] = SGE_Mapping(train_Data,dim,W,Wp);
+0037             LDA.W_LDA = TransMatrix;
+0038             LDA.PCA_mat=PCA_W;
+0039             mtrainFeat=SGE_Projection(train_Data,1:dim,TransMatrix);
+0040             LDA.trainFeat=mtrainFeat;                       
+0041 %             figure,gplotmatrix(mtrainFeat',[],labels)
+0042         end
+0043         
+0044         function [output, probabilities, ranking] = classifyInstance(LDA,instance)
+0045             
+0046             N = size(instance,1);            
+0047             instance = instance'; 
+0048 
+0049             test_Data=LDA.PCA_mat'*instance;               
+0050 %             test_Data=[ones(1,N);test_Data];
+0051 
+0052             testFeat=LDA.W_LDA'*test_Data;  
+0053             X = LDA.trainFeat;
+0054             y = LDA.instanceSet.getLabels;
+0055             [~,output] = SGE_Classification(X,y',testFeat,0,'euc');
+0056             output = output(1,:)';
+0057             probabilities=zeros(N,1);
+0058             ranking=zeros(N,1);
+0059 %             figure,gplotmatrix(testFeat',[],output)
+0060           
+0061         end
+0062         
+0063         function LDA = reset(LDA)
+0064             %delete all stored models
+0065             LDA.W_LDA=[];
+0066             LDA.PCA_mat=[];
+0067             LDA.trainFeat=[];
+0068         end
+0069         
+0070         function configInfo = getConfigInfo(LDA)
+0071             configInfo = sprintf('MLR_Classifier');
+0072         end
+0073         
+0074                         
+0075         function time = getTime(LDA)
+0076             
+0077         end
+0078                 
+0079     end
+0080 end
+0081
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LDA/LDA.m b/doc/+eegtoolkit/+classification/@LDA/LDA.m new file mode 100644 index 0000000..f5e762a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/LDA.m @@ -0,0 +1,81 @@ +classdef LDA < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties (Access = public) + W_LDA; + PCA_mat; + trainFeat; + end + + methods (Access = public) + function LDA = LDA(instanceSet) + if nargin > 0 + LDA.instanceSet = instanceSet; + end + + end + + function LDA = build(LDA) + LDA.reset(); + data = LDA.instanceSet.getInstances; + data = data'; + labels = LDA.instanceSet.getLabels; + unique(labels) + numTrials = length(labels); + + PCA_W=pca_func(data); +% PCA_W=eye(8000); + train_Data=PCA_W'*data; + + Par.mode = 'LDA'; + dim = length(unique(labels))-1; + [W,Wp] = SGE_GraphConstruct(labels,Par); + [TransMatrix,~] = SGE_Mapping(train_Data,dim,W,Wp); + LDA.W_LDA = TransMatrix; + LDA.PCA_mat=PCA_W; + mtrainFeat=SGE_Projection(train_Data,1:dim,TransMatrix); + LDA.trainFeat=mtrainFeat; +% figure,gplotmatrix(mtrainFeat',[],labels) + end + + function [output, probabilities, ranking] = classifyInstance(LDA,instance) + + N = size(instance,1); + instance = instance'; + + test_Data=LDA.PCA_mat'*instance; +% test_Data=[ones(1,N);test_Data]; + + testFeat=LDA.W_LDA'*test_Data; + X = LDA.trainFeat; + y = LDA.instanceSet.getLabels; + [~,output] = SGE_Classification(X,y',testFeat,0,'euc'); + output = output(1,:)'; + probabilities=zeros(N,1); + ranking=zeros(N,1); +% figure,gplotmatrix(testFeat',[],output) + + end + + function LDA = reset(LDA) + %delete all stored models + LDA.W_LDA=[]; + LDA.PCA_mat=[]; + LDA.trainFeat=[]; + end + + function configInfo = getConfigInfo(LDA) + configInfo = sprintf('MLR_Classifier'); + end + + + function time = getTime(LDA) + + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@LDA/graph.dot b/doc/+eegtoolkit/+classification/@LDA/graph.dot new file mode 100644 index 0000000..89a5dcc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + LDA -> LDA; + + LDA [URL="LDA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LDA/graph.html b/doc/+eegtoolkit/+classification/@LDA/graph.html new file mode 100644 index 0000000..4b01ec7 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@LDA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LDA >
+

Dependency Graph for +eegtoolkit/+classification/@LDA

+ +
+Dependency Graph for +eegtoolkit/+classification/@LDA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LDA/graph.map b/doc/+eegtoolkit/+classification/@LDA/graph.map new file mode 100644 index 0000000..85fcbaf --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@LDA/graph.png b/doc/+eegtoolkit/+classification/@LDA/graph.png new file mode 100644 index 0000000..14d442d Binary files /dev/null and b/doc/+eegtoolkit/+classification/@LDA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@LDA/index.html b/doc/+eegtoolkit/+classification/@LDA/index.html new file mode 100644 index 0000000..07526f5 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LDA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@LDA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LDA >
+ +

Index for +eegtoolkit/+classification/@LDA

+ +

Matlab files in this directory:

+ +
 LDA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.html b/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.html new file mode 100644 index 0000000..493502a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.html @@ -0,0 +1,166 @@ + + + + Description of LIBSVM + + + + + + + + + +
Home > +eegtoolkit > +classification > @LIBSVM > LIBSVM.m
+ + + +

LIBSVM +

+ +

PURPOSE ^

+
LIBSVMCLASSIFIER class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 LIBSVMCLASSIFIER class
+ Wrapper class of the libsvm library (libsvm) .mex files must be added to
+ your matlab path before using this class
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

LIBSVM.m

+

SOURCE CODE ^

+
0001 
+0002 % LIBSVMCLASSIFIER class
+0003 % Wrapper class of the libsvm library (libsvm) .mex files must be added to
+0004 % your matlab path before using this class
+0005 classdef LIBSVM < eegtoolkit.classification.ClassifierBase
+0006     
+0007     properties (Constant)
+0008         KERNEL_LINEAR = 0; 
+0009 %         KERNEL_POLYNOMIAL = 1; not supported yet
+0010         KERNEL_RBF = 2;
+0011 %         KERNEL_SIGMOID = 3; not supported yet
+0012     end
+0013     properties
+0014         kernel; % The svm kernel
+0015         cost; % The cost parameter
+0016         gamma; % The gamma parameter (used only with rbf kernel)
+0017         models; % The trained models
+0018     end
+0019     
+0020     methods (Access = public)
+0021         function LSVM = LIBSVM(instanceSet)
+0022             if nargin > 0
+0023                 LSVM.kernel = LSVM.KERNEL_LINEAR;
+0024                 LSVM.cost = 1.0;
+0025                 LSVM.instanceSet = instanceSet;
+0026                 LSVM.gamma = 1/instanceSet.getNumFeatures;
+0027             else
+0028                 LSVM.kernel = LSVM.KERNEL_LINEAR;
+0029                 LSVM.cost = 1.0;
+0030                 LSVM.gamma = 1;
+0031             end
+0032         end
+0033         
+0034         function LSVM = build(LSVM)
+0035             % Builds the classification models
+0036             LSVM.reset;
+0037             numLabels = LSVM.instanceSet.getNumLabels;
+0038             uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0039             for i=1:numLabels
+0040                 currentLabel = uniqueLabels(i);
+0041                 labels = zeros(LSVM.instanceSet.getNumInstances,1)-1;
+0042                 labels(LSVM.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1;
+0043                 instances = sparse(LSVM.instanceSet.getInstances);
+0044                 if LSVM.kernel == LSVM.KERNEL_LINEAR;
+0045                     %store the models in an instance variable
+0046                     LSVM.models{i} = svmtrain(labels, instances, sprintf('-t %d -c %f  -q', LSVM.kernel, LSVM.cost));
+0047                 elseif LSVM.kernel == LSVM.KERNEL_RBF;
+0048                     LSVM.models{i} = svmtrain(labels, instances, sprintf('-t %d -c %f -g %f  -q', LSVM.kernel, LSVM.cost, LSVM.gamma));
+0049                 else
+0050                     error('invalid kernel parameter');
+0051                 end
+0052             end
+0053         end
+0054         
+0055         function [output, probabilities, ranking] = classifyInstance(LSVM,instance)
+0056             %input = instance matrix rows = instances, cols = attributes
+0057             %output = predicted class
+0058             %probabilities = probability for predicted class
+0059             %ranking = propabilities for all classes (e.g. to use with mAP)
+0060             
+0061             %TODO:should print an error if 'build' has not been called
+0062             numModels = length(LSVM.models);
+0063             [numinstance, ~] = size(instance);
+0064             scores = zeros(numModels,numinstance);
+0065             for i=1:numModels
+0066                 %predict using the stored models
+0067                 [~, ~, t] = svmpredict(eye(numinstance,1),instance, LSVM.models{i},' -q');
+0068                 %store probability for each class
+0069                 scores(i,:) = t(:,1);
+0070             end
+0071             output = zeros(numinstance,1);
+0072             probabilities = zeros(numinstance,1);
+0073             ranking = scores';
+0074             for i=1:numinstance
+0075                 %select the class with the highest probability
+0076                 [prob, idx] = max(scores(:,i));
+0077                 uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0078                 %output the label with highest probability
+0079                 output(i,1) = uniqueLabels(idx);
+0080                 %return the probability for the output label
+0081                 probabilities(i,1) = prob;
+0082             end
+0083         end
+0084         
+0085         function LSVM = reset(LSVM)
+0086             % 'Resets' the classifier.
+0087             LSVM.models = {};
+0088         end
+0089         
+0090         function configInfo = getConfigInfo(LSVM)
+0091             % Prints the parameters of the classifier
+0092             switch LSVM.kernel
+0093                 case LSVM.KERNEL_LINEAR
+0094                     configInfo = sprintf('LIBSVM\tkernel:linear\tcost:%d', LSVM.cost);
+0095                 case LSVM.KERNEL_RBF
+0096                     configInfo = sprintf('LIBSVM\tkernel:rbf\tcost:%d\tgamma:%d', LSVM.cost, LSVM.gamma);
+0097                 otherwise 
+0098                     configInfo = 'Error in configuration (only linear and rbf kernels supported for now)';
+0099             end
+0100         end
+0101         
+0102         function newLSVM = copy(LSVM)
+0103             newLSVM = eegtoolkit.classification.LIBSVM;
+0104             newLSVM.kernel = LSVM.kernel;
+0105             newLSVM.cost = LSVM.cost;
+0106             newLSVM.gamma = LSVM.gamma;
+0107         end
+0108         
+0109                         
+0110         function time = getTime(LSVM)
+0111             time = 0;
+0112         end
+0113     end
+0114 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.m b/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.m new file mode 100644 index 0000000..1db8ec3 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/LIBSVM.m @@ -0,0 +1,114 @@ + +% LIBSVMCLASSIFIER class +% Wrapper class of the libsvm library (libsvm) .mex files must be added to +% your matlab path before using this class +classdef LIBSVM < eegtoolkit.classification.ClassifierBase + + properties (Constant) + KERNEL_LINEAR = 0; +% KERNEL_POLYNOMIAL = 1; not supported yet + KERNEL_RBF = 2; +% KERNEL_SIGMOID = 3; not supported yet + end + properties + kernel; % The svm kernel + cost; % The cost parameter + gamma; % The gamma parameter (used only with rbf kernel) + models; % The trained models + end + + methods (Access = public) + function LSVM = LIBSVM(instanceSet) + if nargin > 0 + LSVM.kernel = LSVM.KERNEL_LINEAR; + LSVM.cost = 1.0; + LSVM.instanceSet = instanceSet; + LSVM.gamma = 1/instanceSet.getNumFeatures; + else + LSVM.kernel = LSVM.KERNEL_LINEAR; + LSVM.cost = 1.0; + LSVM.gamma = 1; + end + end + + function LSVM = build(LSVM) + % Builds the classification models + LSVM.reset; + numLabels = LSVM.instanceSet.getNumLabels; + uniqueLabels = unique(LSVM.instanceSet.getLabels); + for i=1:numLabels + currentLabel = uniqueLabels(i); + labels = zeros(LSVM.instanceSet.getNumInstances,1)-1; + labels(LSVM.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1; + instances = sparse(LSVM.instanceSet.getInstances); + if LSVM.kernel == LSVM.KERNEL_LINEAR; + %store the models in an instance variable + LSVM.models{i} = svmtrain(labels, instances, sprintf('-t %d -c %f -q', LSVM.kernel, LSVM.cost)); + elseif LSVM.kernel == LSVM.KERNEL_RBF; + LSVM.models{i} = svmtrain(labels, instances, sprintf('-t %d -c %f -g %f -q', LSVM.kernel, LSVM.cost, LSVM.gamma)); + else + error('invalid kernel parameter'); + end + end + end + + function [output, probabilities, ranking] = classifyInstance(LSVM,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + numModels = length(LSVM.models); + [numinstance, ~] = size(instance); + scores = zeros(numModels,numinstance); + for i=1:numModels + %predict using the stored models + [~, ~, t] = svmpredict(eye(numinstance,1),instance, LSVM.models{i},' -q'); + %store probability for each class + scores(i,:) = t(:,1); + end + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + ranking = scores'; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(:,i)); + uniqueLabels = unique(LSVM.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function LSVM = reset(LSVM) + % 'Resets' the classifier. + LSVM.models = {}; + end + + function configInfo = getConfigInfo(LSVM) + % Prints the parameters of the classifier + switch LSVM.kernel + case LSVM.KERNEL_LINEAR + configInfo = sprintf('LIBSVM\tkernel:linear\tcost:%d', LSVM.cost); + case LSVM.KERNEL_RBF + configInfo = sprintf('LIBSVM\tkernel:rbf\tcost:%d\tgamma:%d', LSVM.cost, LSVM.gamma); + otherwise + configInfo = 'Error in configuration (only linear and rbf kernels supported for now)'; + end + end + + function newLSVM = copy(LSVM) + newLSVM = eegtoolkit.classification.LIBSVM; + newLSVM.kernel = LSVM.kernel; + newLSVM.cost = LSVM.cost; + newLSVM.gamma = LSVM.gamma; + end + + + function time = getTime(LSVM) + time = 0; + end + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/graph.dot b/doc/+eegtoolkit/+classification/@LIBSVM/graph.dot new file mode 100644 index 0000000..94bc240 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + LIBSVM -> LIBSVM; + + LIBSVM [URL="LIBSVM.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/graph.html b/doc/+eegtoolkit/+classification/@LIBSVM/graph.html new file mode 100644 index 0000000..e95632a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@LIBSVM + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LIBSVM >
+

Dependency Graph for +eegtoolkit/+classification/@LIBSVM

+ +
+Dependency Graph for +eegtoolkit/+classification/@LIBSVM + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/graph.map b/doc/+eegtoolkit/+classification/@LIBSVM/graph.map new file mode 100644 index 0000000..01d58f1 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/graph.png b/doc/+eegtoolkit/+classification/@LIBSVM/graph.png new file mode 100644 index 0000000..bc3bc60 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@LIBSVM/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@LIBSVM/index.html b/doc/+eegtoolkit/+classification/@LIBSVM/index.html new file mode 100644 index 0000000..2891574 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVM/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@LIBSVM + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LIBSVM >
+ +

Index for +eegtoolkit/+classification/@LIBSVM

+ +

Matlab files in this directory:

+ +
 LIBSVMLIBSVMCLASSIFIER class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.html b/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.html new file mode 100644 index 0000000..e09035b --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.html @@ -0,0 +1,174 @@ + + + + Description of LIBSVMFast + + + + + + + + + +
Home > +eegtoolkit > +classification > @LIBSVMFast > LIBSVMFast.m
+ + + +

LIBSVMFast +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

LIBSVMFast.m

+

SOURCE CODE ^

+
0001 classdef LIBSVMFast < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     properties
+0007         kernel;
+0008         cost;
+0009         gamma;
+0010         models;
+0011         Ktrain;
+0012         Ktest;
+0013         maxlag;
+0014         scaleopt;
+0015         predictTotalTime;
+0016         predictCount;
+0017     end
+0018     
+0019     methods (Access = public)
+0020         function LSVM = LIBSVMFast (instanceSet,kernel,cost,gamma,maxlag,scaleopt)
+0021             %set default parameters
+0022             LSVM.predictTotalTime = 0;
+0023             LSVM.predictCount = 0;
+0024             LSVM.kernel = 'linear';
+0025             LSVM.cost = 1.0;
+0026             LSVM.gamma = 0.01;
+0027             LSVM.maxlag = 150;
+0028             LSVM.scaleopt = 'coeff';
+0029             if nargin > 0
+0030                 LSVM.instanceSet = instanceSet;
+0031                 LSVM.gamma = 1/instanceSet.getNumFeatures;
+0032             end
+0033             if nargin > 1
+0034                 LSVM.kernel = kernel;
+0035             end
+0036             if nargin > 2
+0037                 LSVM.cost = cost;
+0038             end
+0039             if nargin > 3
+0040                 LSVM.gamma = gamma;
+0041             end
+0042             if nargin > 4
+0043                 LSVM.maxlag = maxlag;
+0044             end
+0045             if nargin > 5
+0046                 LSVM.scaleopt = scaleopt;
+0047             end
+0048         end
+0049         
+0050         function LSVM = build(LSVM)
+0051             %clear all from previous calls to "build"
+0052             LSVM.reset;
+0053             numLabels = LSVM.instanceSet.getNumLabels;
+0054             uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0055             for i=1:numLabels
+0056                 currentLabel = uniqueLabels(i);
+0057                 labels = zeros(LSVM.instanceSet.getNumInstances,1)-1;
+0058                 labels(LSVM.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1;
+0059                 LSVM.models{i} = svmtrain(labels, [(1:size(LSVM.Ktrain,1))', ...
+0060                     LSVM.Ktrain+eye(size(LSVM.Ktrain,1))*realmin], ...
+0061                     sprintf(' -t 4 -c %f -b 1 -q', LSVM.cost));
+0062             end
+0063         end
+0064         
+0065         function [output, probabilities, ranking] = classifyInstance(LSVM)
+0066             %input = instance matrix rows = instances, cols = attributes
+0067             %output = predicted class
+0068             %probabilities = probability for predicted class
+0069             %ranking = propabilities for all classes (e.g. to use with mAP)
+0070             
+0071             %TODO:should print an error if 'build' has not been called
+0072             numModels = length(LSVM.models);
+0073             [numinstance, ~] = size(LSVM.Ktest);
+0074             scores = zeros(numModels,numinstance);
+0075             for i=1:numModels
+0076                 %predict using the stored models
+0077                 tic
+0078                 [~, ~, t] = svmpredict(eye(numinstance,1),...
+0079                     [(1:numinstance)', LSVM.Ktest], LSVM.models{i},'-b 1 -q');
+0080                 LSVM.predictTotalTime = LSVM.predictTotalTime + toc;
+0081                 LSVM.predictCount = LSVM.predictCount + numinstance;
+0082                 %svmpredict(labels(~idx), [(1:sum(~idx))', K(~idx,idx)], model);
+0083                 %store probability for each class
+0084                 scores(i,:) = t(:,1);
+0085             end
+0086             output = zeros(numinstance,1);
+0087             probabilities = zeros(numinstance,1);
+0088             %we need these for ranking metrics (e.g. mAP)
+0089             ranking = scores;
+0090             for i=1:numinstance
+0091                 %select the class with the highest probability
+0092                 [prob, idx] = max(scores(:,i));
+0093                 uniqueLabels = unique(LSVM.instanceSet.getLabels);
+0094                 %output the label with highest probability
+0095                 output(i,1) = uniqueLabels(idx);
+0096                 %return the probability for the output label
+0097                 probabilities(i,1) = prob;
+0098             end
+0099         end
+0100         
+0101         function LSVM = reset(LSVM)
+0102             %delete all stored models
+0103             LSVM.models = {};
+0104         end
+0105         
+0106         function configInfo = getConfigInfo(LSVM)
+0107             switch LSVM.kernel
+0108                 case {'linear','spearman','correlation','cosine'}
+0109                     configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d', LSVM.kernel, LSVM.cost);
+0110                 case 'xcorr'
+0111                     configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d\tgamma:%d\tmaxlag:%d\tscaleopt:%s', LSVM.kernel, LSVM.cost, LSVM.maxlag,LSVM.scaleopt);
+0112                 otherwise
+0113                     configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d\tgamma:%d', LSVM.kernel, LSVM.cost, LSVM.gamma);
+0114 %                 otherwise
+0115 %                     configInfo = 'Error in configuration (only linear and rbf kernels supported for now)';
+0116             end
+0117         end
+0118         
+0119         function time = getTime(LSVM)
+0120             time = LSVM.predictTotalTime/LSVM.predictCount;
+0121         end
+0122     end
+0123 end
+0124
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.m b/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.m new file mode 100644 index 0000000..429d32f --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/LIBSVMFast.m @@ -0,0 +1,124 @@ +classdef LIBSVMFast < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + properties + kernel; + cost; + gamma; + models; + Ktrain; + Ktest; + maxlag; + scaleopt; + predictTotalTime; + predictCount; + end + + methods (Access = public) + function LSVM = LIBSVMFast (instanceSet,kernel,cost,gamma,maxlag,scaleopt) + %set default parameters + LSVM.predictTotalTime = 0; + LSVM.predictCount = 0; + LSVM.kernel = 'linear'; + LSVM.cost = 1.0; + LSVM.gamma = 0.01; + LSVM.maxlag = 150; + LSVM.scaleopt = 'coeff'; + if nargin > 0 + LSVM.instanceSet = instanceSet; + LSVM.gamma = 1/instanceSet.getNumFeatures; + end + if nargin > 1 + LSVM.kernel = kernel; + end + if nargin > 2 + LSVM.cost = cost; + end + if nargin > 3 + LSVM.gamma = gamma; + end + if nargin > 4 + LSVM.maxlag = maxlag; + end + if nargin > 5 + LSVM.scaleopt = scaleopt; + end + end + + function LSVM = build(LSVM) + %clear all from previous calls to "build" + LSVM.reset; + numLabels = LSVM.instanceSet.getNumLabels; + uniqueLabels = unique(LSVM.instanceSet.getLabels); + for i=1:numLabels + currentLabel = uniqueLabels(i); + labels = zeros(LSVM.instanceSet.getNumInstances,1)-1; + labels(LSVM.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1; + LSVM.models{i} = svmtrain(labels, [(1:size(LSVM.Ktrain,1))', ... + LSVM.Ktrain+eye(size(LSVM.Ktrain,1))*realmin], ... + sprintf(' -t 4 -c %f -b 1 -q', LSVM.cost)); + end + end + + function [output, probabilities, ranking] = classifyInstance(LSVM) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + %TODO:should print an error if 'build' has not been called + numModels = length(LSVM.models); + [numinstance, ~] = size(LSVM.Ktest); + scores = zeros(numModels,numinstance); + for i=1:numModels + %predict using the stored models + tic + [~, ~, t] = svmpredict(eye(numinstance,1),... + [(1:numinstance)', LSVM.Ktest], LSVM.models{i},'-b 1 -q'); + LSVM.predictTotalTime = LSVM.predictTotalTime + toc; + LSVM.predictCount = LSVM.predictCount + numinstance; + %svmpredict(labels(~idx), [(1:sum(~idx))', K(~idx,idx)], model); + %store probability for each class + scores(i,:) = t(:,1); + end + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + %we need these for ranking metrics (e.g. mAP) + ranking = scores; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(:,i)); + uniqueLabels = unique(LSVM.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function LSVM = reset(LSVM) + %delete all stored models + LSVM.models = {}; + end + + function configInfo = getConfigInfo(LSVM) + switch LSVM.kernel + case {'linear','spearman','correlation','cosine'} + configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d', LSVM.kernel, LSVM.cost); + case 'xcorr' + configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d\tgamma:%d\tmaxlag:%d\tscaleopt:%s', LSVM.kernel, LSVM.cost, LSVM.maxlag,LSVM.scaleopt); + otherwise + configInfo = sprintf('LIBSVMFast\tkernel:%s\tcost:%d\tgamma:%d', LSVM.kernel, LSVM.cost, LSVM.gamma); +% otherwise +% configInfo = 'Error in configuration (only linear and rbf kernels supported for now)'; + end + end + + function time = getTime(LSVM) + time = LSVM.predictTotalTime/LSVM.predictCount; + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.dot b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.dot new file mode 100644 index 0000000..d41268e --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + LIBSVMFast -> LIBSVMFast; + + LIBSVMFast [URL="LIBSVMFast.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.html b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.html new file mode 100644 index 0000000..ec17d91 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@LIBSVMFast + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LIBSVMFast >
+

Dependency Graph for +eegtoolkit/+classification/@LIBSVMFast

+ +
+Dependency Graph for +eegtoolkit/+classification/@LIBSVMFast + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.map b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.map new file mode 100644 index 0000000..e20b900 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.png b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.png new file mode 100644 index 0000000..173a524 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@LIBSVMFast/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@LIBSVMFast/index.html b/doc/+eegtoolkit/+classification/@LIBSVMFast/index.html new file mode 100644 index 0000000..bd9d72e --- /dev/null +++ b/doc/+eegtoolkit/+classification/@LIBSVMFast/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@LIBSVMFast + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@LIBSVMFast >
+ +

Index for +eegtoolkit/+classification/@LIBSVMFast

+ +

Matlab files in this directory:

+ +
 LIBSVMFast
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLDA/MLDA.html b/doc/+eegtoolkit/+classification/@MLDA/MLDA.html new file mode 100644 index 0000000..3be604d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/MLDA.html @@ -0,0 +1,183 @@ + + + + Description of MLDA + + + + + + + + + +
Home > +eegtoolkit > +classification > @MLDA > MLDA.m
+ + + +

MLDA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MLDA.m

+

SOURCE CODE ^

+
0001 classdef MLDA < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties
+0008        DiscrimType; % 'linear' (default) | 'quadratic' | 'diagLinear' | 'diagQuadratic' | 'pseudoLinear' | 'pseudoQuadratic'
+0009        Delta % 0 (default) | nonnegative scalar value that acts as a linear coefficient threshold. Delta must be 0 for quadratic discriminant models.
+0010        Gamma % scalar value in the range [0,1]. Parameter for regularizing the correlation matrix of predictors.
+0011        FillCoeffs % on (default) Coeffs property flag, specified as the comma-separated pair consisting of 'FillCoeffs' and 'on' or 'off
+0012        ScoreTransform % 'none' (default). Score transform function. Check http://www.mathworks.com/help/stats/fitcdiscr.html
+0013        Prior % 'empirical' (default) or 'uniform'.  Prior probabilities for each class.
+0014        models;
+0015        totalTime;
+0016        totalCount;
+0017     end
+0018     
+0019     methods (Access = public)
+0020         function MLDA = MLDA(instanceSet, discrimType, delta, gamma, fillCoeffs, scoreTransform,prior)
+0021             %set default parameters
+0022             if nargin > 0
+0023                 MLDA.instanceSet = instanceSet;
+0024             end
+0025             if nargin > 1
+0026                 MLDA.DiscrimType = discrimType;
+0027             end
+0028             if nargin > 2 
+0029                 MLDA.Delta=delta;
+0030             end
+0031             if nargin > 3
+0032                 MLDA.Gamma = gamma;
+0033             end
+0034             if nargin > 4
+0035                 MLDA.FillCoeffs = fillCoeffs;
+0036             end
+0037             if nargin > 5
+0038                 MLDA.ScoreTransform = scoreTransform;
+0039             end
+0040             if nargin > 6
+0041                 MLDA.Prior = prior;
+0042             end
+0043         end
+0044         
+0045         function MLDA = build(MLDA)
+0046             %clear all from previous calls to "build"
+0047             MLDA.reset;
+0048             numLabels = MLDA.instanceSet.getNumLabels;
+0049             uniqueLabels = unique(MLDA.instanceSet.getLabels);
+0050            
+0051             % ---- Multi-Class ----- %
+0052             instances=MLDA.instanceSet.instances;
+0053             labels=MLDA.instanceSet.labels;
+0054             
+0055             %LDA.models{1}=fitcecoc(instances,labels,'Coding','ternarycomplete');
+0056             MLDA.models{1} = fitcdiscr(instances,labels,'DiscrimType',MLDA.DiscrimType,'Delta',MLDA.Delta,'Gamma',MLDA.Gamma,'FillCoeffs',MLDA.FillCoeffs,'ScoreTransform',MLDA.ScoreTransform, 'Prior',MLDA.Prior);
+0057             
+0058             % ---- One (vs) All ----- %
+0059 %             for i=1:numLabels
+0060 %                 currentLabel = uniqueLabels(i);
+0061 %                 labels = zeros(LDA.instanceSet.getNumInstances,1)-1;
+0062 %                 labels(LDA.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1;
+0063 %                 instances = sparse(LDA.instanceSet.getInstances);
+0064 %                 LDA.models{i} = libsvmtrain(labels,instances, '-t 0 -c 1 -b 1');
+0065 %                 if LDA.kernel == LDA.KERNEL_LINEAR;
+0066 %                    %store the models in an instance variable
+0067 %                    LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -b 1 -q', LDA.kernel, LDA.cost));
+0068 %                 elseif LDA.kernel == LDA.KERNEL_RBF;
+0069 %                    LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -g %f -b 1 -q', LDA.kernel, LDA.cost, LDA.gamma));
+0070 %                 else
+0071 %                    error('invalid kernel parameter');
+0072 %                 end
+0073 %             end
+0074         end
+0075         
+0076         function [output, probabilities, ranking] = classifyInstance(MLDA,instance)
+0077             %input = instance matrix rows = instances, cols = attributes
+0078             %output = predicted class
+0079             %probabilities = probability for predicted class
+0080             %ranking = propabilities for all classes (e.g. to use with mAP)
+0081             
+0082             
+0083             %TODO:should print an error if 'build' has not been called
+0084             numModels = length(MLDA.models);
+0085             [numinstance, ~] = size(instance);
+0086             scores = zeros(numModels,numinstance);
+0087              
+0088             % ---- Multi-class ----- %
+0089             tic
+0090             [label,scores,cost] = predict(MLDA.models{1},instance); 
+0091             MLDA.totalTime = MLDA.totalTime + toc;
+0092             MLDA.totalCount = MLDA.totalCount  + numinstance;
+0093             % ---- One (vs) All -----%
+0094 %              for i=1:numModels
+0095 %                  %predict using the stored models
+0096 %                  [label,score,cost] = predict(LDA.models{i},instance);
+0097 %                  %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q');
+0098 %                 %store probability for each class
+0099 %                 scores(i,:) = score(:,1);
+0100 %             end
+0101 
+0102              output = zeros(numinstance,1);
+0103              probabilities = zeros(numinstance,1);
+0104              %we need these for ranking metrics (e.g. mAP)
+0105              ranking = scores;
+0106              for i=1:numinstance
+0107                  %select the class with the highest probability
+0108                  [prob, idx] = max(scores(i,:));
+0109                  uniqueLabels = unique(MLDA.instanceSet.getLabels);
+0110                  %output the label with highest probability
+0111                  output(i,1) = uniqueLabels(idx);
+0112                  %return the probability for the output label
+0113                  probabilities(i,1) = prob;
+0114              end
+0115         end
+0116         
+0117         function MLDA = reset(MLDA)
+0118             %delete all stored models
+0119             MLDA.models = {};
+0120         end
+0121         
+0122         function configInfo = getConfigInfo(MLDA)
+0123             configInfo = sprintf('MLDA\tdiscrimtype:%s\tdelta:%f\tgamma:%f\tfillcoeffs:%d\tscoretransform:%s\tprior:%s',MLDA.DiscrimType, MLDA.Delta, MLDA.Gamma, MLDA.FillCoeffs, MLDA.ScoreTransform, MLDA.Prior);
+0124         end
+0125         
+0126                         
+0127         function time = getTime(MLDA)
+0128             time = MLDA.totalTime/MLDA.totalCount;
+0129         end
+0130                 
+0131     end
+0132 end
+0133
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLDA/MLDA.m b/doc/+eegtoolkit/+classification/@MLDA/MLDA.m new file mode 100644 index 0000000..92261f4 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/MLDA.m @@ -0,0 +1,133 @@ +classdef MLDA < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + DiscrimType; % 'linear' (default) | 'quadratic' | 'diagLinear' | 'diagQuadratic' | 'pseudoLinear' | 'pseudoQuadratic' + Delta % 0 (default) | nonnegative scalar value that acts as a linear coefficient threshold. Delta must be 0 for quadratic discriminant models. + Gamma % scalar value in the range [0,1]. Parameter for regularizing the correlation matrix of predictors. + FillCoeffs % on (default) Coeffs property flag, specified as the comma-separated pair consisting of 'FillCoeffs' and 'on' or 'off + ScoreTransform % 'none' (default). Score transform function. Check http://www.mathworks.com/help/stats/fitcdiscr.html + Prior % 'empirical' (default) or 'uniform'. Prior probabilities for each class. + models; + totalTime; + totalCount; + end + + methods (Access = public) + function MLDA = MLDA(instanceSet, discrimType, delta, gamma, fillCoeffs, scoreTransform,prior) + %set default parameters + if nargin > 0 + MLDA.instanceSet = instanceSet; + end + if nargin > 1 + MLDA.DiscrimType = discrimType; + end + if nargin > 2 + MLDA.Delta=delta; + end + if nargin > 3 + MLDA.Gamma = gamma; + end + if nargin > 4 + MLDA.FillCoeffs = fillCoeffs; + end + if nargin > 5 + MLDA.ScoreTransform = scoreTransform; + end + if nargin > 6 + MLDA.Prior = prior; + end + end + + function MLDA = build(MLDA) + %clear all from previous calls to "build" + MLDA.reset; + numLabels = MLDA.instanceSet.getNumLabels; + uniqueLabels = unique(MLDA.instanceSet.getLabels); + + % ---- Multi-Class ----- % + instances=MLDA.instanceSet.instances; + labels=MLDA.instanceSet.labels; + + %LDA.models{1}=fitcecoc(instances,labels,'Coding','ternarycomplete'); + MLDA.models{1} = fitcdiscr(instances,labels,'DiscrimType',MLDA.DiscrimType,'Delta',MLDA.Delta,'Gamma',MLDA.Gamma,'FillCoeffs',MLDA.FillCoeffs,'ScoreTransform',MLDA.ScoreTransform, 'Prior',MLDA.Prior); + + % ---- One (vs) All ----- % +% for i=1:numLabels +% currentLabel = uniqueLabels(i); +% labels = zeros(LDA.instanceSet.getNumInstances,1)-1; +% labels(LDA.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1; +% instances = sparse(LDA.instanceSet.getInstances); +% LDA.models{i} = libsvmtrain(labels,instances, '-t 0 -c 1 -b 1'); +% if LDA.kernel == LDA.KERNEL_LINEAR; +% %store the models in an instance variable +% LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -b 1 -q', LDA.kernel, LDA.cost)); +% elseif LDA.kernel == LDA.KERNEL_RBF; +% LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -g %f -b 1 -q', LDA.kernel, LDA.cost, LDA.gamma)); +% else +% error('invalid kernel parameter'); +% end +% end + end + + function [output, probabilities, ranking] = classifyInstance(MLDA,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + + %TODO:should print an error if 'build' has not been called + numModels = length(MLDA.models); + [numinstance, ~] = size(instance); + scores = zeros(numModels,numinstance); + + % ---- Multi-class ----- % + tic + [label,scores,cost] = predict(MLDA.models{1},instance); + MLDA.totalTime = MLDA.totalTime + toc; + MLDA.totalCount = MLDA.totalCount + numinstance; + % ---- One (vs) All -----% +% for i=1:numModels +% %predict using the stored models +% [label,score,cost] = predict(LDA.models{i},instance); +% %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = score(:,1); +% end + + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + %we need these for ranking metrics (e.g. mAP) + ranking = scores; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(i,:)); + uniqueLabels = unique(MLDA.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function MLDA = reset(MLDA) + %delete all stored models + MLDA.models = {}; + end + + function configInfo = getConfigInfo(MLDA) + configInfo = sprintf('MLDA\tdiscrimtype:%s\tdelta:%f\tgamma:%f\tfillcoeffs:%d\tscoretransform:%s\tprior:%s',MLDA.DiscrimType, MLDA.Delta, MLDA.Gamma, MLDA.FillCoeffs, MLDA.ScoreTransform, MLDA.Prior); + end + + + function time = getTime(MLDA) + time = MLDA.totalTime/MLDA.totalCount; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@MLDA/graph.dot b/doc/+eegtoolkit/+classification/@MLDA/graph.dot new file mode 100644 index 0000000..4680b13 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MLDA -> MLDA; + + MLDA [URL="MLDA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLDA/graph.html b/doc/+eegtoolkit/+classification/@MLDA/graph.html new file mode 100644 index 0000000..6ec1521 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@MLDA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLDA >
+

Dependency Graph for +eegtoolkit/+classification/@MLDA

+ +
+Dependency Graph for +eegtoolkit/+classification/@MLDA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLDA/graph.map b/doc/+eegtoolkit/+classification/@MLDA/graph.map new file mode 100644 index 0000000..42801a4 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@MLDA/graph.png b/doc/+eegtoolkit/+classification/@MLDA/graph.png new file mode 100644 index 0000000..77d0c31 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@MLDA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@MLDA/index.html b/doc/+eegtoolkit/+classification/@MLDA/index.html new file mode 100644 index 0000000..d029684 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLDA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@MLDA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLDA >
+ +

Index for +eegtoolkit/+classification/@MLDA

+ +

Matlab files in this directory:

+ +
 MLDA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLR/MLR.html b/doc/+eegtoolkit/+classification/@MLR/MLR.html new file mode 100644 index 0000000..68e7081 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/MLR.html @@ -0,0 +1,165 @@ + + + + Description of MLR + + + + + + + + + +
Home > +eegtoolkit > +classification > @MLR > MLR.m
+ + + +

MLR +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MLR.m

+

SOURCE CODE ^

+
0001 classdef MLR < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004         
+0005     end
+0006     
+0007     properties
+0008         W_mlr;
+0009         PCA_mat;
+0010         trainFeat;
+0011     end
+0012     
+0013     methods (Access = public)
+0014         function MLR = MLR(instanceSet)
+0015             if nargin > 0
+0016                 MLR.instanceSet = instanceSet;
+0017             end
+0018             
+0019         end
+0020         
+0021         function MLR = build(MLR)
+0022             MLR.reset();
+0023             data = MLR.instanceSet.getInstances;
+0024             data = data';
+0025             labels = MLR.instanceSet.getLabels;
+0026             numTrials = length(labels);
+0027             train_Y = zeros(length(unique(labels)),numTrials);
+0028             for i = 1 : numTrials
+0029                 train_Y(labels(i),i) = 1;
+0030             end
+0031             [Ydim,Num]=size(train_Y);
+0032             PCA_W=MLR.pca_func(data);
+0033             train_Data=PCA_W'*data;
+0034             train_Data=[ones(1,numTrials);train_Data];
+0035             MLR.W_mlr = MLR.MultiLR(train_Data,train_Y);%inv(train_Data*train_Data')*train_Data*train_Y';%(train_Data'*train_Data)\train_Data'*train_Y;%MultiLR(train_Data,train_Y);
+0036             MLR.PCA_mat=PCA_W;
+0037             mtrainFeat=MLR.W_mlr'*train_Data;
+0038             MLR.trainFeat=mtrainFeat;
+0039         end
+0040         
+0041         function [output, probabilities, ranking] = classifyInstance(MLR,instance)
+0042             
+0043             N = size(instance,1);
+0044             instance = instance';
+0045             test_Data=MLR.PCA_mat'*instance;
+0046             test_Data=[ones(1,N);test_Data];
+0047             testFeat=MLR.W_mlr'*test_Data;
+0048             output=knnclassify(testFeat',MLR.trainFeat',MLR.instanceSet.getLabels,5,'euclidean');
+0049             probabilities=zeros(N,1);
+0050             ranking=zeros(N,1);
+0051             
+0052         end
+0053         
+0054         function MLR = reset(MLR)
+0055             %delete all stored models
+0056             MLR.W_mlr=[];
+0057             MLR.PCA_mat=[];
+0058             MLR.trainFeat=[];
+0059         end
+0060         
+0061         function configInfo = getConfigInfo(MLR)
+0062             configInfo = sprintf('MLR');
+0063         end
+0064         
+0065         
+0066         function time = getTime(MLR)
+0067             time = 0;
+0068         end
+0069         
+0070     end
+0071     
+0072     methods (Access = private)
+0073         function Proj_W=pca_func(MLR,data)
+0074             Proj_W=[];
+0075             meanData=mean(data,2);
+0076             data=data-repmat(meanData,1,size(data,2));
+0077             % stdVar=std(data')';
+0078             % staData=(data-repmat(meanData,1,size(data,2)))./repmat(stdVar,1,size(data,2));
+0079             % data=staData;
+0080             [V,S]=eig(data'*data);
+0081             [sorted_diagS,sorted_rank]=sort(diag(S),'descend');
+0082             sorted_S=diag(sorted_diagS);
+0083             V=V(:,sorted_rank);
+0084             r=rank(sorted_S);
+0085             S1=sorted_S(1:r,1:r);
+0086             V1=V(:,1:r);
+0087             U=data*V1*S1^(-0.5);
+0088             %[sorted_S,sorted_rank]=sort(diag(S),'descend');
+0089             All_energy=sum(diag(S1));
+0090             sorted_energy=diag(S1);
+0091             for j=1:r
+0092                 if (sum(sorted_energy(1:j))/All_energy)>0.99
+0093                     break
+0094                 end
+0095             end
+0096             Proj_W=U(:,1:j);
+0097         end
+0098         function W_mlr=MultiLR(MLR,train_Feat,train_Y)
+0099             
+0100             % Multiple linear regression
+0101             % train_Feat: training samples
+0102             % train_Y: label matrix
+0103             
+0104             [U,Sigma,V]=svd(train_Feat,'econ');
+0105             r=rank(Sigma);
+0106             U1=U(:,1:r);
+0107             V1=V(:,1:r);
+0108             Sigma_r=diag(Sigma(1:r, 1:r));
+0109             W_mlr=U1*diag(1./Sigma_r)*V1'*train_Y';
+0110             
+0111             
+0112         end
+0113     end
+0114 end
+0115
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLR/MLR.m b/doc/+eegtoolkit/+classification/@MLR/MLR.m new file mode 100644 index 0000000..a9eb9b5 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/MLR.m @@ -0,0 +1,115 @@ +classdef MLR < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + W_mlr; + PCA_mat; + trainFeat; + end + + methods (Access = public) + function MLR = MLR(instanceSet) + if nargin > 0 + MLR.instanceSet = instanceSet; + end + + end + + function MLR = build(MLR) + MLR.reset(); + data = MLR.instanceSet.getInstances; + data = data'; + labels = MLR.instanceSet.getLabels; + numTrials = length(labels); + train_Y = zeros(length(unique(labels)),numTrials); + for i = 1 : numTrials + train_Y(labels(i),i) = 1; + end + [Ydim,Num]=size(train_Y); + PCA_W=MLR.pca_func(data); + train_Data=PCA_W'*data; + train_Data=[ones(1,numTrials);train_Data]; + MLR.W_mlr = MLR.MultiLR(train_Data,train_Y);%inv(train_Data*train_Data')*train_Data*train_Y';%(train_Data'*train_Data)\train_Data'*train_Y;%MultiLR(train_Data,train_Y); + MLR.PCA_mat=PCA_W; + mtrainFeat=MLR.W_mlr'*train_Data; + MLR.trainFeat=mtrainFeat; + end + + function [output, probabilities, ranking] = classifyInstance(MLR,instance) + + N = size(instance,1); + instance = instance'; + test_Data=MLR.PCA_mat'*instance; + test_Data=[ones(1,N);test_Data]; + testFeat=MLR.W_mlr'*test_Data; + output=knnclassify(testFeat',MLR.trainFeat',MLR.instanceSet.getLabels,5,'euclidean'); + probabilities=zeros(N,1); + ranking=zeros(N,1); + + end + + function MLR = reset(MLR) + %delete all stored models + MLR.W_mlr=[]; + MLR.PCA_mat=[]; + MLR.trainFeat=[]; + end + + function configInfo = getConfigInfo(MLR) + configInfo = sprintf('MLR'); + end + + + function time = getTime(MLR) + time = 0; + end + + end + + methods (Access = private) + function Proj_W=pca_func(MLR,data) + Proj_W=[]; + meanData=mean(data,2); + data=data-repmat(meanData,1,size(data,2)); + % stdVar=std(data')'; + % staData=(data-repmat(meanData,1,size(data,2)))./repmat(stdVar,1,size(data,2)); + % data=staData; + [V,S]=eig(data'*data); + [sorted_diagS,sorted_rank]=sort(diag(S),'descend'); + sorted_S=diag(sorted_diagS); + V=V(:,sorted_rank); + r=rank(sorted_S); + S1=sorted_S(1:r,1:r); + V1=V(:,1:r); + U=data*V1*S1^(-0.5); + %[sorted_S,sorted_rank]=sort(diag(S),'descend'); + All_energy=sum(diag(S1)); + sorted_energy=diag(S1); + for j=1:r + if (sum(sorted_energy(1:j))/All_energy)>0.99 + break + end + end + Proj_W=U(:,1:j); + end + function W_mlr=MultiLR(MLR,train_Feat,train_Y) + + % Multiple linear regression + % train_Feat: training samples + % train_Y: label matrix + + [U,Sigma,V]=svd(train_Feat,'econ'); + r=rank(Sigma); + U1=U(:,1:r); + V1=V(:,1:r); + Sigma_r=diag(Sigma(1:r, 1:r)); + W_mlr=U1*diag(1./Sigma_r)*V1'*train_Y'; + + + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@MLR/graph.dot b/doc/+eegtoolkit/+classification/@MLR/graph.dot new file mode 100644 index 0000000..a73f6b1 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MLR -> MLR; + + MLR [URL="MLR.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLR/graph.html b/doc/+eegtoolkit/+classification/@MLR/graph.html new file mode 100644 index 0000000..9a78505 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@MLR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLR >
+

Dependency Graph for +eegtoolkit/+classification/@MLR

+ +
+Dependency Graph for +eegtoolkit/+classification/@MLR + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLR/graph.map b/doc/+eegtoolkit/+classification/@MLR/graph.map new file mode 100644 index 0000000..68a65dc --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@MLR/graph.png b/doc/+eegtoolkit/+classification/@MLR/graph.png new file mode 100644 index 0000000..6ced205 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@MLR/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@MLR/index.html b/doc/+eegtoolkit/+classification/@MLR/index.html new file mode 100644 index 0000000..76a460a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLR/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@MLR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLR >
+ +

Index for +eegtoolkit/+classification/@MLR

+ +

Matlab files in this directory:

+ +
 MLR
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.html b/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.html new file mode 100644 index 0000000..52ccecd --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.html @@ -0,0 +1,190 @@ + + + + Description of MLTREE + + + + + + + + + +
Home > +eegtoolkit > +classification > @MLTREE > MLTREE.m
+ + + +

MLTREE +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MLTREE.m

+

SOURCE CODE ^

+
0001 classdef MLTREE < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties
+0008        AlgorithmForCategorical; % Algorithm for best categorical predictor split 'Exact' | 'PullLeft' | 'PCA' | 'OVAbyClass'
+0009        MaxNumSplits; % Maximal number of decision splits. size(X,1) - 1 (default) | positive integer
+0010        MinLeafSize; % Minimum number of leaf node observations 1 (default) | positive integer value
+0011        MinParentSize; % Minimum number of branch node observations 10 (default) | positive integer value
+0012        NumVariablesToSample; % Number of predictors to select at random for each split 'all' | positive integer value
+0013        ScoreTransform % 'none' (default). Score transform function. Check http://www.mathworks.com/help/stats/fitcdiscr.html
+0014        Prior; % Prior probabilities 'empirical' (default) | 'uniform' | vector of scalar values | structure
+0015        models;
+0016        totalTime;
+0017        totalCount;
+0018     end
+0019     
+0020     methods (Access = public)
+0021         function MLTREE = MLTREE(instanceSet, algorithmForCategorical, maxNumSplits, minLeafSize, minParentSize, numVariablesToSample, scoreTransform, prior)
+0022             %set default parameters
+0023             if nargin > 0
+0024                 MLTREE.instanceSet = instanceSet;
+0025             end
+0026             if nargin > 1
+0027                 MLTREE.AlgorithmForCategorical = algorithmForCategorical;
+0028             end
+0029             if nargin > 2 
+0030                 MLTREE.MaxNumSplits=maxNumSplits;
+0031             end
+0032             if nargin > 3
+0033                 MLTREE.MinLeafSize = minLeafSize;
+0034             end
+0035             if nargin > 4
+0036                 MLTREE.MinParentSize = minParentSize;
+0037             end
+0038             if nargin > 5
+0039                 MLTREE.NumVariablesToSample = numVariablesToSample;
+0040             end
+0041             if nargin > 6
+0042                 MLTREE.ScoreTransform = scoreTransform;
+0043             end
+0044             if nargin > 7
+0045                 MLTREE.Prior = prior;
+0046             end
+0047             MLTREE.totalTime = 0;
+0048             MLTREE.totalCount = 0;
+0049         end
+0050         
+0051         function MLTREE = build(MLTREE)
+0052             %clear all from previous calls to "build"
+0053             MLTREE.reset;
+0054             numLabels = MLTREE.instanceSet.getNumLabels;
+0055             uniqueLabels = unique(MLTREE.instanceSet.getLabels);
+0056            
+0057             % ---- Multi-Class ----- %
+0058             instances=MLTREE.instanceSet.instances;
+0059             labels=MLTREE.instanceSet.labels;
+0060             
+0061             %LDA.models{1}=fitcecoc(instances,labels,'Coding','ternarycomplete');
+0062             MLTREE.models{1} = fitctree(instances,labels,'AlgorithmForCategorical',MLTREE.AlgorithmForCategorical,'MaxNumSplits',MLTREE.MaxNumSplits,'MinLeafSize',MLTREE.MinLeafSize,'MinParentSize',MLTREE.MinParentSize,'NumVariablesToSample', MLTREE.NumVariablesToSample,'ScoreTransform',MLTREE.ScoreTransform, 'Prior',MLTREE.Prior);
+0063      
+0064             
+0065             % ---- One (vs) All ----- %
+0066 %             for i=1:numLabels
+0067 %                 currentLabel = uniqueLabels(i);
+0068 %                 labels = zeros(LDA.instanceSet.getNumInstances,1)-1;
+0069 %                 labels(LDA.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1;
+0070 %                 instances = sparse(LDA.instanceSet.getInstances);
+0071 %                 LDA.models{i} = libsvmtrain(labels,instances, '-t 0 -c 1 -b 1');
+0072 %                 if LDA.kernel == LDA.KERNEL_LINEAR;
+0073 %                    %store the models in an instance variable
+0074 %                    LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -b 1 -q', LDA.kernel, LDA.cost));
+0075 %                 elseif LDA.kernel == LDA.KERNEL_RBF;
+0076 %                    LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -g %f -b 1 -q', LDA.kernel, LDA.cost, LDA.gamma));
+0077 %                 else
+0078 %                    error('invalid kernel parameter');
+0079 %                 end
+0080 %             end
+0081         end
+0082         
+0083         function [output, probabilities, ranking] = classifyInstance(MLTREE,instance)
+0084             %input = instance matrix rows = instances, cols = attributes
+0085             %output = predicted class
+0086             %probabilities = probability for predicted class
+0087             %ranking = propabilities for all classes (e.g. to use with mAP)
+0088             
+0089             
+0090             %TODO:should print an error if 'build' has not been called
+0091             numModels = length(MLTREE.models);
+0092             [numinstance, ~] = size(instance);
+0093             scores = zeros(numModels,numinstance);
+0094              
+0095             % ---- Multi-class ----- %
+0096             tic
+0097             [label,scores,cost] = predict(MLTREE.models{1},instance); 
+0098             MLTREE.totalTime = MLTREE.totalTime + toc;
+0099             MLTREE.totalCount = MLTREE.totalCount + numinstance;
+0100             % ---- One (vs) All -----%
+0101 %              for i=1:numModels
+0102 %                  %predict using the stored models
+0103 %                  [label,score,cost] = predict(LDA.models{i},instance);
+0104 %                  %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q');
+0105 %                 %store probability for each class
+0106 %                 scores(i,:) = score(:,1);
+0107 %             end
+0108 
+0109              output = zeros(numinstance,1);
+0110              probabilities = zeros(numinstance,1);
+0111              %we need these for ranking metrics (e.g. mAP)
+0112              ranking = scores;
+0113              for i=1:numinstance
+0114                  %select the class with the highest probability
+0115                  [prob, idx] = max(scores(i,:));
+0116                  uniqueLabels = unique(MLTREE.instanceSet.getLabels);
+0117                  %output the label with highest probability
+0118                  output(i,1) = uniqueLabels(idx);
+0119                  %return the probability for the output label
+0120                  probabilities(i,1) = prob;
+0121              end
+0122         end
+0123         
+0124         function MLTREE = reset(MLTREE)
+0125             %delete all stored models
+0126             MLTREE.models = {};
+0127         end
+0128         
+0129         function configInfo = getConfigInfo(MLTREE)
+0130             configInfo = 'MLTREE (Config info not supported yet)';
+0131         end
+0132         
+0133                         
+0134         function time = getTime(MLTREE)
+0135             time = MLTREE.totalTime/MLTREE.totalCount;
+0136         end
+0137                 
+0138     end
+0139 end
+0140
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.m b/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.m new file mode 100644 index 0000000..e1cd769 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/MLTREE.m @@ -0,0 +1,140 @@ +classdef MLTREE < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + AlgorithmForCategorical; % Algorithm for best categorical predictor split 'Exact' | 'PullLeft' | 'PCA' | 'OVAbyClass' + MaxNumSplits; % Maximal number of decision splits. size(X,1) - 1 (default) | positive integer + MinLeafSize; % Minimum number of leaf node observations 1 (default) | positive integer value + MinParentSize; % Minimum number of branch node observations 10 (default) | positive integer value + NumVariablesToSample; % Number of predictors to select at random for each split 'all' | positive integer value + ScoreTransform % 'none' (default). Score transform function. Check http://www.mathworks.com/help/stats/fitcdiscr.html + Prior; % Prior probabilities 'empirical' (default) | 'uniform' | vector of scalar values | structure + models; + totalTime; + totalCount; + end + + methods (Access = public) + function MLTREE = MLTREE(instanceSet, algorithmForCategorical, maxNumSplits, minLeafSize, minParentSize, numVariablesToSample, scoreTransform, prior) + %set default parameters + if nargin > 0 + MLTREE.instanceSet = instanceSet; + end + if nargin > 1 + MLTREE.AlgorithmForCategorical = algorithmForCategorical; + end + if nargin > 2 + MLTREE.MaxNumSplits=maxNumSplits; + end + if nargin > 3 + MLTREE.MinLeafSize = minLeafSize; + end + if nargin > 4 + MLTREE.MinParentSize = minParentSize; + end + if nargin > 5 + MLTREE.NumVariablesToSample = numVariablesToSample; + end + if nargin > 6 + MLTREE.ScoreTransform = scoreTransform; + end + if nargin > 7 + MLTREE.Prior = prior; + end + MLTREE.totalTime = 0; + MLTREE.totalCount = 0; + end + + function MLTREE = build(MLTREE) + %clear all from previous calls to "build" + MLTREE.reset; + numLabels = MLTREE.instanceSet.getNumLabels; + uniqueLabels = unique(MLTREE.instanceSet.getLabels); + + % ---- Multi-Class ----- % + instances=MLTREE.instanceSet.instances; + labels=MLTREE.instanceSet.labels; + + %LDA.models{1}=fitcecoc(instances,labels,'Coding','ternarycomplete'); + MLTREE.models{1} = fitctree(instances,labels,'AlgorithmForCategorical',MLTREE.AlgorithmForCategorical,'MaxNumSplits',MLTREE.MaxNumSplits,'MinLeafSize',MLTREE.MinLeafSize,'MinParentSize',MLTREE.MinParentSize,'NumVariablesToSample', MLTREE.NumVariablesToSample,'ScoreTransform',MLTREE.ScoreTransform, 'Prior',MLTREE.Prior); + + + % ---- One (vs) All ----- % +% for i=1:numLabels +% currentLabel = uniqueLabels(i); +% labels = zeros(LDA.instanceSet.getNumInstances,1)-1; +% labels(LDA.instanceSet.getInstanceIndicesForLabel(currentLabel)) = 1; +% instances = sparse(LDA.instanceSet.getInstances); +% LDA.models{i} = libsvmtrain(labels,instances, '-t 0 -c 1 -b 1'); +% if LDA.kernel == LDA.KERNEL_LINEAR; +% %store the models in an instance variable +% LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -b 1 -q', LDA.kernel, LDA.cost)); +% elseif LDA.kernel == LDA.KERNEL_RBF; +% LDA.models{i} = libsvmtrain(labels, instances, sprintf('-t %d -c %f -g %f -b 1 -q', LDA.kernel, LDA.cost, LDA.gamma)); +% else +% error('invalid kernel parameter'); +% end +% end + end + + function [output, probabilities, ranking] = classifyInstance(MLTREE,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + + %TODO:should print an error if 'build' has not been called + numModels = length(MLTREE.models); + [numinstance, ~] = size(instance); + scores = zeros(numModels,numinstance); + + % ---- Multi-class ----- % + tic + [label,scores,cost] = predict(MLTREE.models{1},instance); + MLTREE.totalTime = MLTREE.totalTime + toc; + MLTREE.totalCount = MLTREE.totalCount + numinstance; + % ---- One (vs) All -----% +% for i=1:numModels +% %predict using the stored models +% [label,score,cost] = predict(LDA.models{i},instance); +% %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = score(:,1); +% end + + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + %we need these for ranking metrics (e.g. mAP) + ranking = scores; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(i,:)); + uniqueLabels = unique(MLTREE.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function MLTREE = reset(MLTREE) + %delete all stored models + MLTREE.models = {}; + end + + function configInfo = getConfigInfo(MLTREE) + configInfo = 'MLTREE (Config info not supported yet)'; + end + + + function time = getTime(MLTREE) + time = MLTREE.totalTime/MLTREE.totalCount; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@MLTREE/graph.dot b/doc/+eegtoolkit/+classification/@MLTREE/graph.dot new file mode 100644 index 0000000..4ad5e85 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MLTREE -> MLTREE; + + MLTREE [URL="MLTREE.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTREE/graph.html b/doc/+eegtoolkit/+classification/@MLTREE/graph.html new file mode 100644 index 0000000..f1bb958 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@MLTREE + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLTREE >
+

Dependency Graph for +eegtoolkit/+classification/@MLTREE

+ +
+Dependency Graph for +eegtoolkit/+classification/@MLTREE + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTREE/graph.map b/doc/+eegtoolkit/+classification/@MLTREE/graph.map new file mode 100644 index 0000000..ff76d66 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@MLTREE/graph.png b/doc/+eegtoolkit/+classification/@MLTREE/graph.png new file mode 100644 index 0000000..952a5e7 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@MLTREE/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@MLTREE/index.html b/doc/+eegtoolkit/+classification/@MLTREE/index.html new file mode 100644 index 0000000..50e3482 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTREE/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@MLTREE + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLTREE >
+ +

Index for +eegtoolkit/+classification/@MLTREE

+ +

Matlab files in this directory:

+ +
 MLTREE
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.html b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.html new file mode 100644 index 0000000..19c3099 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.html @@ -0,0 +1,154 @@ + + + + Description of MLTboxMulticlass + + + + + + + + + +
Home > +eegtoolkit > +classification > @MLTboxMulticlass > MLTboxMulticlass.m
+ + + +

MLTboxMulticlass +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MLTboxMulticlass.m

+

SOURCE CODE ^

+
0001 classdef MLTboxMulticlass < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004         
+0005     end
+0006     
+0007     properties
+0008         Learners; %'discriminant': Discriminant analysis. | 'knn': k-nearest neighbors. | 'naivebayes': Naive Bayes.
+0009         % 'svm': SVM. | 'tree': Classification trees. | any Matlab template classifier
+0010         Coding; % Coding design 'onevsall' (default) | 'allpairs' | 'binarycomplete' | 'denserandom' | 'onevsone' | 'ordinal' | 'sparserandom' | 'ternarycomplete' | numeric matrix
+0011         FitPosterior; % Flag indicating whether to transform scores to posterior probabilities false or 0 (default) | true or 1
+0012         Prior % 'empirical' (default) or 'uniform'.  Prior probabilities for each class.
+0013         models;
+0014         totalTime;
+0015         totalCount;
+0016     end
+0017     
+0018     methods (Access = public)
+0019         function MLC = MLTboxMulticlass(instanceSet, learners, coding, fitPosterior, prior)
+0020             %set default parameters
+0021             MLC.Learners = 'svm';
+0022             MLC.Coding='onevsall';
+0023             MLC.FitPosterior='off';
+0024             MLC.Prior='empirical';
+0025             
+0026             if nargin > 0
+0027                 MLC.instanceSet = instanceSet;
+0028             end
+0029             if nargin > 1
+0030                 MLC.Learners = learners;
+0031             end
+0032             if nargin > 2
+0033                 MLC.Coding=coding;
+0034             end
+0035             if nargin > 3
+0036                 MLC.FitPosterior=fitPosterior;
+0037             end
+0038             if nargin > 4
+0039                 MLC.Prior=prior;
+0040             end
+0041             MLC.totalTime = 0;
+0042             MLC.totalCount = 0;
+0043         end
+0044         
+0045         function MLC = build(MLC)
+0046             %clear all from previous calls to "build"
+0047             MLC.reset;
+0048             numLabels = MLC.instanceSet.getNumLabels;
+0049             uniqueLabels = unique(MLC.instanceSet.getLabels);
+0050             
+0051             % ---- Multi-Class ----- %
+0052             instances=MLC.instanceSet.instances;
+0053             labels=MLC.instanceSet.labels;
+0054             
+0055             %t=templateSVM('KernelFunction','linear');
+0056             MLC.models{1}=fitcecoc(instances,labels,'Coding', MLC.Coding,'FitPosterior', MLC.FitPosterior,'Prior',MLC.Prior,'Learners',MLC.Learners);
+0057         end
+0058         
+0059         function [output, probabilities, ranking] = classifyInstance(MLC,instance)
+0060 
+0061             %TODO:should print an error if 'build' has not been called
+0062             numModels = length(MLC.models);
+0063             [numinstance, ~] = size(instance);
+0064             %scores = zeros(numModels,numinstance);
+0065             
+0066             % ---- Multi-class ----- %
+0067             tic
+0068             [label,scores,loss] = predict(MLC.models{1},instance);
+0069             MLC.totalTime = MLC.totalTime + toc;
+0070             MLC.totalCount = MLC.totalCount + numinstance;
+0071             output = zeros(numinstance,1);
+0072             probabilities = zeros(numinstance,1);
+0073             %we need these for ranking metrics (e.g. mAP)
+0074             ranking = scores;
+0075             for i=1:numinstance
+0076                 %select the class with the highest probability
+0077                 [prob, idx] = max(scores(i,:));
+0078                 uniqueLabels = unique(MLC.instanceSet.getLabels);
+0079                 %output the label with highest probability
+0080                 output(i,1) = uniqueLabels(idx);
+0081                 %return the probability for the output label
+0082                 probabilities(i,1) = prob;
+0083             end
+0084         end
+0085         
+0086         function MLC = reset(MLC)
+0087             %delete all stored models
+0088             MLC.models = {};
+0089         end
+0090         
+0091         function configInfo = getConfigInfo(MLC)
+0092             configInfo=sprintf('MLTboxMulticlass\tCoding:%s\tFitPosterior:%s\tPrior:%s\n\tLearners:', MLC.Coding, MLC.FitPosterior,MLC.Prior);
+0093             disp(MLC.Learners)
+0094             %configInfo = 'MLSVMClassifier (Config info not supported yet)';
+0095         end
+0096         
+0097                         
+0098         function time = getTime(MLC)
+0099             time = MLC.totalTime/MLC.totalCount;
+0100         end
+0101         
+0102     end
+0103 end
+0104
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.m b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.m new file mode 100644 index 0000000..07c37e3 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/MLTboxMulticlass.m @@ -0,0 +1,104 @@ +classdef MLTboxMulticlass < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + Learners; %'discriminant': Discriminant analysis. | 'knn': k-nearest neighbors. | 'naivebayes': Naive Bayes. + % 'svm': SVM. | 'tree': Classification trees. | any Matlab template classifier + Coding; % Coding design 'onevsall' (default) | 'allpairs' | 'binarycomplete' | 'denserandom' | 'onevsone' | 'ordinal' | 'sparserandom' | 'ternarycomplete' | numeric matrix + FitPosterior; % Flag indicating whether to transform scores to posterior probabilities false or 0 (default) | true or 1 + Prior % 'empirical' (default) or 'uniform'. Prior probabilities for each class. + models; + totalTime; + totalCount; + end + + methods (Access = public) + function MLC = MLTboxMulticlass(instanceSet, learners, coding, fitPosterior, prior) + %set default parameters + MLC.Learners = 'svm'; + MLC.Coding='onevsall'; + MLC.FitPosterior='off'; + MLC.Prior='empirical'; + + if nargin > 0 + MLC.instanceSet = instanceSet; + end + if nargin > 1 + MLC.Learners = learners; + end + if nargin > 2 + MLC.Coding=coding; + end + if nargin > 3 + MLC.FitPosterior=fitPosterior; + end + if nargin > 4 + MLC.Prior=prior; + end + MLC.totalTime = 0; + MLC.totalCount = 0; + end + + function MLC = build(MLC) + %clear all from previous calls to "build" + MLC.reset; + numLabels = MLC.instanceSet.getNumLabels; + uniqueLabels = unique(MLC.instanceSet.getLabels); + + % ---- Multi-Class ----- % + instances=MLC.instanceSet.instances; + labels=MLC.instanceSet.labels; + + %t=templateSVM('KernelFunction','linear'); + MLC.models{1}=fitcecoc(instances,labels,'Coding', MLC.Coding,'FitPosterior', MLC.FitPosterior,'Prior',MLC.Prior,'Learners',MLC.Learners); + end + + function [output, probabilities, ranking] = classifyInstance(MLC,instance) + + %TODO:should print an error if 'build' has not been called + numModels = length(MLC.models); + [numinstance, ~] = size(instance); + %scores = zeros(numModels,numinstance); + + % ---- Multi-class ----- % + tic + [label,scores,loss] = predict(MLC.models{1},instance); + MLC.totalTime = MLC.totalTime + toc; + MLC.totalCount = MLC.totalCount + numinstance; + output = zeros(numinstance,1); + probabilities = zeros(numinstance,1); + %we need these for ranking metrics (e.g. mAP) + ranking = scores; + for i=1:numinstance + %select the class with the highest probability + [prob, idx] = max(scores(i,:)); + uniqueLabels = unique(MLC.instanceSet.getLabels); + %output the label with highest probability + output(i,1) = uniqueLabels(idx); + %return the probability for the output label + probabilities(i,1) = prob; + end + end + + function MLC = reset(MLC) + %delete all stored models + MLC.models = {}; + end + + function configInfo = getConfigInfo(MLC) + configInfo=sprintf('MLTboxMulticlass\tCoding:%s\tFitPosterior:%s\tPrior:%s\n\tLearners:', MLC.Coding, MLC.FitPosterior,MLC.Prior); + disp(MLC.Learners) + %configInfo = 'MLSVMClassifier (Config info not supported yet)'; + end + + + function time = getTime(MLC) + time = MLC.totalTime/MLC.totalCount; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.dot b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.dot new file mode 100644 index 0000000..7256ede --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MLTboxMulticlass -> MLTboxMulticlass; + + MLTboxMulticlass [URL="MLTboxMulticlass.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.html b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.html new file mode 100644 index 0000000..406b756 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@MLTboxMulticlass + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLTboxMulticlass >
+

Dependency Graph for +eegtoolkit/+classification/@MLTboxMulticlass

+ +
+Dependency Graph for +eegtoolkit/+classification/@MLTboxMulticlass + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.map b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.map new file mode 100644 index 0000000..f63cb88 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.png b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.png new file mode 100644 index 0000000..521c0eb Binary files /dev/null and b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@MLTboxMulticlass/index.html b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/index.html new file mode 100644 index 0000000..d77cbd0 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MLTboxMulticlass/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@MLTboxMulticlass + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MLTboxMulticlass >
+ +

Index for +eegtoolkit/+classification/@MLTboxMulticlass

+ +

Matlab files in this directory:

+ +
 MLTboxMulticlass
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.html b/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.html new file mode 100644 index 0000000..d4cf7f1 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.html @@ -0,0 +1,104 @@ + + + + Description of MaxChooser + + + + + + + + + +
Home > +eegtoolkit > +classification > @MaxChooser > MaxChooser.m
+ + + +

MaxChooser +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MaxChooser.m

+

SOURCE CODE ^

+
0001 classdef MaxChooser < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties
+0008       
+0009     end
+0010     
+0011     methods (Access = public)
+0012         function MaxChooser =MaxChooser(instanceSet)
+0013             if nargin > 0
+0014                 MaxChooser.instanceSet = instanceSet;
+0015             end
+0016            
+0017         end
+0018         
+0019         function MaxChooser = build(MaxChooser)
+0020             
+0021         end
+0022         
+0023         function [output, probabilities, ranking] = classifyInstance(MaxChooser,instance)
+0024             
+0025             dd_ins=instance;
+0026             N = size(instance,1);
+0027             pred_lab=zeros(N,1);
+0028             for i=1:N
+0029                 [v,idx]=max(dd_ins(i,:));                
+0030                 pred_lab(i)=idx;   
+0031                 ranking(i,:) = dd_ins(i,:);
+0032             end
+0033             
+0034             output = pred_lab;%sum(pred_lab)/length(pred_lab)
+0035             probabilities=zeros(N,1);
+0036 %             ranking=zeros(N,1);
+0037         end
+0038         
+0039         function MaxChooser = reset(MaxChooser)
+0040             %delete all stored models
+0041         end
+0042         
+0043         function configInfo = getConfigInfo(MaxChooser)
+0044             configInfo = sprintf('MaxChooser');
+0045         end
+0046         
+0047                         
+0048         function time = getTime(MaxChooser)
+0049             time = 0;
+0050         end
+0051                 
+0052     end
+0053 end
+0054
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.m b/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.m new file mode 100644 index 0000000..4d90bd9 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/MaxChooser.m @@ -0,0 +1,54 @@ +classdef MaxChooser < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + + end + + methods (Access = public) + function MaxChooser =MaxChooser(instanceSet) + if nargin > 0 + MaxChooser.instanceSet = instanceSet; + end + + end + + function MaxChooser = build(MaxChooser) + + end + + function [output, probabilities, ranking] = classifyInstance(MaxChooser,instance) + + dd_ins=instance; + N = size(instance,1); + pred_lab=zeros(N,1); + for i=1:N + [v,idx]=max(dd_ins(i,:)); + pred_lab(i)=idx; + ranking(i,:) = dd_ins(i,:); + end + + output = pred_lab;%sum(pred_lab)/length(pred_lab) + probabilities=zeros(N,1); +% ranking=zeros(N,1); + end + + function MaxChooser = reset(MaxChooser) + %delete all stored models + end + + function configInfo = getConfigInfo(MaxChooser) + configInfo = sprintf('MaxChooser'); + end + + + function time = getTime(MaxChooser) + time = 0; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/graph.dot b/doc/+eegtoolkit/+classification/@MaxChooser/graph.dot new file mode 100644 index 0000000..9227aa8 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MaxChooser -> MaxChooser; + + MaxChooser [URL="MaxChooser.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/graph.html b/doc/+eegtoolkit/+classification/@MaxChooser/graph.html new file mode 100644 index 0000000..461293a --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@MaxChooser + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MaxChooser >
+

Dependency Graph for +eegtoolkit/+classification/@MaxChooser

+ +
+Dependency Graph for +eegtoolkit/+classification/@MaxChooser + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/graph.map b/doc/+eegtoolkit/+classification/@MaxChooser/graph.map new file mode 100644 index 0000000..36ff2c4 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/graph.png b/doc/+eegtoolkit/+classification/@MaxChooser/graph.png new file mode 100644 index 0000000..0ddd75a Binary files /dev/null and b/doc/+eegtoolkit/+classification/@MaxChooser/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@MaxChooser/index.html b/doc/+eegtoolkit/+classification/@MaxChooser/index.html new file mode 100644 index 0000000..a59140d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@MaxChooser/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@MaxChooser + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@MaxChooser >
+ +

Index for +eegtoolkit/+classification/@MaxChooser

+ +

Matlab files in this directory:

+ +
 MaxChooser
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SBLR/SBLR.html b/doc/+eegtoolkit/+classification/@SBLR/SBLR.html new file mode 100644 index 0000000..1d7a595 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/SBLR.html @@ -0,0 +1,138 @@ + + + + Description of SBLR + + + + + + + + + +
Home > +eegtoolkit > +classification > @SBLR > SBLR.m
+ + + +

SBLR +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

SBLR.m

+

SOURCE CODE ^

+
0001 classdef SBLR < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties
+0008        %Coding; % Coding design 'onevsall' (default) | 'allpairs' | 'binarycomplete' | 'denserandom' | 'onevsone' | 'ordinal' | 'sparserandom' | 'ternarycomplete' | numeric matrix
+0009        %FitPosterior; % Flag indicating whether to transform scores to posterior probabilities false or 0 (default) | true or 1
+0010        %Prior % 'empirical' (default) or 'uniform'.  Prior probabilities for each class.
+0011        models;
+0012        Wmatrix;
+0013     end
+0014     
+0015     methods (Access = public)
+0016         function SBLR = SBLR(instanceSet)
+0017             %set default parameters
+0018             if nargin > 0
+0019                 SBLR.instanceSet = instanceSet;
+0020             end                   
+0021         end
+0022         
+0023         function SBLR = build(SBLR)
+0024             %clear all from previous calls to "build"
+0025             SBLR.reset;
+0026             numLabels = SBLR.instanceSet.getNumLabels;
+0027             uniqueLabels = unique(SBLR.instanceSet.getLabels);
+0028            
+0029             % ---- Multi-Class ----- %
+0030             instances=SBLR.instanceSet.instances;
+0031             labels=SBLR.instanceSet.labels;
+0032             [~,Nfeat] = size(instances)
+0033             size(instances)
+0034             %X = instances*instances;
+0035           %[w, ix_eff, W, AX] = slr_learning_var2(labels, instances,'nlearn', 100, 'nstep', 10);
+0036           [w, ix_eff, W, AXall] = smlr_learning(labels, instances, Nfeat,'nlearn', 0,'gamma0', 0);%,...
+0037               %'wdisp_mode', 'off', 'nlearn',10,'mean_mode', 'none', 'scale_mode', 'none');%, ...
+0038             %'wdisplay', wdisp_mode, 'wmaxiter', wmaxiter', 'nlearn', Nlearn, 'nstep', Nstep,...
+0039             %'amax', AMAX, 'isplot', isplot', 'gamma0', gamma0);
+0040         
+0041           SBLR.Wmatrix = reshape(w, [Nfeat, 5]);           
+0042         
+0043         end
+0044         
+0045         function [output, probabilities, ranking] = classifyInstance(SBLR,instance)
+0046             %input = instance matrix rows = instances, cols = attributes
+0047             %output = predicted class
+0048             %probabilities = probability for predicted class
+0049             %ranking = propabilities for all classes (e.g. to use with mAP)
+0050             
+0051             
+0052             %TODO:should print an error if 'build' has not been called
+0053 %             numModels = length(MLSVM.models);
+0054             [numinstance, ~] = size(instance);
+0055             %scores = zeros(numModels,numinstance);
+0056             
+0057             [output, Pte] = calc_label(instance, SBLR.Wmatrix);
+0058             % ---- One (vs) All -----%
+0059 %              for i=1:numModels
+0060 %                  %predict using the stored models
+0061 %                  [label,score,cost] = predict(LDA.models{i},instance);
+0062 %                  %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q');
+0063 %                 %store probability for each class
+0064 %                 scores(i,:) = score(:,1);
+0065 %             end
+0066 
+0067             ranking=zeros(5,1)';
+0068             probabilities=0;          
+0069         end
+0070         
+0071         function SBLR = reset(SBLR)
+0072             %delete all stored models
+0073             SBLR.models = {};
+0074             SBLR.Wmatrix=[];
+0075         end
+0076         
+0077         function configInfo = getConfigInfo(SBLR)
+0078            
+0079             configInfo = 'SBLR_Classifier (Config info not supported yet)';
+0080         end
+0081         
+0082         function time = getTime(MLR_Classifier)
+0083             time = 0;
+0084         end
+0085                 
+0086     end
+0087 end
+0088
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SBLR/SBLR.m b/doc/+eegtoolkit/+classification/@SBLR/SBLR.m new file mode 100644 index 0000000..30f315d --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/SBLR.m @@ -0,0 +1,88 @@ +classdef SBLR < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties + %Coding; % Coding design 'onevsall' (default) | 'allpairs' | 'binarycomplete' | 'denserandom' | 'onevsone' | 'ordinal' | 'sparserandom' | 'ternarycomplete' | numeric matrix + %FitPosterior; % Flag indicating whether to transform scores to posterior probabilities false or 0 (default) | true or 1 + %Prior % 'empirical' (default) or 'uniform'. Prior probabilities for each class. + models; + Wmatrix; + end + + methods (Access = public) + function SBLR = SBLR(instanceSet) + %set default parameters + if nargin > 0 + SBLR.instanceSet = instanceSet; + end + end + + function SBLR = build(SBLR) + %clear all from previous calls to "build" + SBLR.reset; + numLabels = SBLR.instanceSet.getNumLabels; + uniqueLabels = unique(SBLR.instanceSet.getLabels); + + % ---- Multi-Class ----- % + instances=SBLR.instanceSet.instances; + labels=SBLR.instanceSet.labels; + [~,Nfeat] = size(instances) + size(instances) + %X = instances*instances; + %[w, ix_eff, W, AX] = slr_learning_var2(labels, instances,'nlearn', 100, 'nstep', 10); + [w, ix_eff, W, AXall] = smlr_learning(labels, instances, Nfeat,'nlearn', 0,'gamma0', 0);%,... + %'wdisp_mode', 'off', 'nlearn',10,'mean_mode', 'none', 'scale_mode', 'none');%, ... + %'wdisplay', wdisp_mode, 'wmaxiter', wmaxiter', 'nlearn', Nlearn, 'nstep', Nstep,... + %'amax', AMAX, 'isplot', isplot', 'gamma0', gamma0); + + SBLR.Wmatrix = reshape(w, [Nfeat, 5]); + + end + + function [output, probabilities, ranking] = classifyInstance(SBLR,instance) + %input = instance matrix rows = instances, cols = attributes + %output = predicted class + %probabilities = probability for predicted class + %ranking = propabilities for all classes (e.g. to use with mAP) + + + %TODO:should print an error if 'build' has not been called +% numModels = length(MLSVM.models); + [numinstance, ~] = size(instance); + %scores = zeros(numModels,numinstance); + + [output, Pte] = calc_label(instance, SBLR.Wmatrix); + % ---- One (vs) All -----% +% for i=1:numModels +% %predict using the stored models +% [label,score,cost] = predict(LDA.models{i},instance); +% %libsvmpredict(eye(numinstance,1),instance, LSVM.models{i},'-b 1 -q'); +% %store probability for each class +% scores(i,:) = score(:,1); +% end + + ranking=zeros(5,1)'; + probabilities=0; + end + + function SBLR = reset(SBLR) + %delete all stored models + SBLR.models = {}; + SBLR.Wmatrix=[]; + end + + function configInfo = getConfigInfo(SBLR) + + configInfo = 'SBLR_Classifier (Config info not supported yet)'; + end + + function time = getTime(MLR_Classifier) + time = 0; + end + + end +end + diff --git a/doc/+eegtoolkit/+classification/@SBLR/graph.dot b/doc/+eegtoolkit/+classification/@SBLR/graph.dot new file mode 100644 index 0000000..6ecd254 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + SBLR -> SBLR; + + SBLR [URL="SBLR.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SBLR/graph.html b/doc/+eegtoolkit/+classification/@SBLR/graph.html new file mode 100644 index 0000000..e9fe593 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@SBLR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@SBLR >
+

Dependency Graph for +eegtoolkit/+classification/@SBLR

+ +
+Dependency Graph for +eegtoolkit/+classification/@SBLR + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SBLR/graph.map b/doc/+eegtoolkit/+classification/@SBLR/graph.map new file mode 100644 index 0000000..bc7b84e --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@SBLR/graph.png b/doc/+eegtoolkit/+classification/@SBLR/graph.png new file mode 100644 index 0000000..eb58da1 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@SBLR/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@SBLR/index.html b/doc/+eegtoolkit/+classification/@SBLR/index.html new file mode 100644 index 0000000..9fc6896 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SBLR/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@SBLR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@SBLR >
+ +

Index for +eegtoolkit/+classification/@SBLR

+ +

Matlab files in this directory:

+ +
 SBLR
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SMFA/SMFA.html b/doc/+eegtoolkit/+classification/@SMFA/SMFA.html new file mode 100644 index 0000000..84c4827 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/SMFA.html @@ -0,0 +1,193 @@ + + + + Description of SMFA + + + + + + + + + +
Home > +eegtoolkit > +classification > @SMFA > SMFA.m
+ + + +

SMFA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

SMFA.m

+

SOURCE CODE ^

+
0001 classdef SMFA < eegtoolkit.classification.ClassifierBase
+0002     
+0003     properties (Constant)
+0004 
+0005     end
+0006     
+0007     properties (Access = public)
+0008       W_SMFA;
+0009       PCA_mat;
+0010       trainFeat;
+0011       NumSubclasses;
+0012       SigmaCoeff;
+0013       kInt;
+0014       kPen;
+0015     end
+0016     
+0017     methods (Access = public)
+0018         function SMFA = SMFA(instanceSet,NumS,S,kInt,kPen)%,NumSubclasses,SigmaCoeff,kInt,kPen)
+0019             if nargin == 1
+0020                 SMFA.instanceSet = instanceSet;
+0021             else
+0022                 SMFA.NumSubclasses = NumS;
+0023                 SMFA.SigmaCoeff = S;
+0024                 SMFA.kInt = kInt;
+0025                 SMFA.kPen = kPen;
+0026             end
+0027            
+0028         end
+0029             
+0030         
+0031         function SMFA = build(SMFA)
+0032             SMFA.reset();
+0033             data = SMFA.instanceSet.getInstances;
+0034             data = data';  
+0035             labels = SMFA.instanceSet.getLabels;    
+0036             unique(labels)           
+0037             numTrials = length(labels);
+0038 
+0039             PCA_W=SMFA.pca_func(data);
+0040 %             PCA_W=eye(size(data,1));
+0041             train_Data=PCA_W'*data; 
+0042             
+0043 %             Sigma = SMFA_Classifier.SigmaCoeff;
+0044             NSubClasses = SMFA.NumSubclasses;
+0045             D=pdist2(train_Data',train_Data');
+0046 %             STrain = SGE_GramMatrix(train_Data,'gau',Sigma*mean(D(:)));
+0047             STrain = 1-(D/max(D(:)));
+0048             
+0049             pt=0;
+0050             ct=0;
+0051             ClustersOfClasses = SGE_SubclassExtract(train_Data,labels,NSubClasses,pt,ct);
+0052             [yyTrain,~,~] = SGE_SubclassLabels(ClustersOfClasses,labels);
+0053            
+0054             
+0055             Par.mode = 'SMFA';
+0056             Par.SimilMatrix = STrain;
+0057             Par.kInt = SMFA.kInt;
+0058             Par.kPen = SMFA.kPen;
+0059             dim = min([Par.kPen,size(train_Data,1)]);
+0060             
+0061             [W,Wp] = SGE_GraphConstruct(yyTrain,Par);
+0062             [TransMatrix,~] = SGE_Mapping(train_Data,dim,W,Wp);
+0063             SMFA.W_SMFA = TransMatrix;
+0064             SMFA.PCA_mat=PCA_W;
+0065             mtrainFeat=SGE_Projection(train_Data,1:dim,TransMatrix);
+0066             SMFA.trainFeat=mtrainFeat;                       
+0067 %             figure,gplotmatrix(mtrainFeat',[],labels)
+0068         end
+0069         
+0070         function [output, probabilities, ranking] = classifyInstance(SMFA,instance)
+0071             
+0072             N = size(instance,1);            
+0073             instance = instance'; 
+0074             
+0075             test_Data=SMFA.PCA_mat'*instance;               
+0076 %             test_Data=[ones(1,N);test_Data];
+0077             testFeat=SMFA.W_SMFA'*test_Data;
+0078 %             output=knnclassify(testFeat',SMFA_Classifier.trainFeat',SMFA_Classifier.instanceSet.getLabels,5,'euclidean');
+0079             X = SMFA.trainFeat;
+0080             y = SMFA.instanceSet.getLabels;
+0081             
+0082             %Nearest Centroid
+0083             [~,output] = SGE_Classification(X,y',testFeat,0,'euc');
+0084             
+0085 %             %SVM Linear
+0086 %             [~,output] = SGE_Classification(X,y',testFeat,[1,1,1,0,1],'euc');
+0087 
+0088 %             %SVM RBF
+0089 %             [~,output] = SGE_Classification(X,y',testFeat,[2,3,2/size(X,1),0,1],'euc');
+0090             
+0091             output = output(1,:)';
+0092             probabilities=zeros(N,1);
+0093             ranking=zeros(N,1);
+0094 %             figure,gplotmatrix(testFeat',[],output)
+0095           
+0096         end
+0097         
+0098         function SMFA = reset(SMFA)
+0099             %delete all stored models
+0100             SMFA.W_SMFA=[];
+0101             SMFA.PCA_mat=[];
+0102             SMFA.trainFeat=[];
+0103         end
+0104         
+0105         function configInfo = getConfigInfo(SMFA)
+0106             configInfo = sprintf('MLR_Classifier');
+0107         end
+0108         
+0109                         
+0110         function time = getTime(SMFA)
+0111             
+0112         end
+0113                 
+0114     end
+0115     methods (Access = private)
+0116         function Proj_W=pca_func(MLR,data)
+0117             Proj_W=[];
+0118             meanData=mean(data,2);
+0119             data=data-repmat(meanData,1,size(data,2));
+0120             % stdVar=std(data')';
+0121             % staData=(data-repmat(meanData,1,size(data,2)))./repmat(stdVar,1,size(data,2));
+0122             % data=staData;
+0123             [V,S]=eig(data'*data);
+0124             [sorted_diagS,sorted_rank]=sort(diag(S),'descend');
+0125             sorted_S=diag(sorted_diagS);
+0126             V=V(:,sorted_rank);
+0127             r=rank(sorted_S);
+0128             S1=sorted_S(1:r,1:r);
+0129             V1=V(:,1:r);
+0130             U=data*V1*S1^(-0.5);
+0131             %[sorted_S,sorted_rank]=sort(diag(S),'descend');
+0132             All_energy=sum(diag(S1));
+0133             sorted_energy=diag(S1);
+0134             for j=1:r
+0135                 if (sum(sorted_energy(1:j))/All_energy)>0.99
+0136                     break
+0137                 end
+0138             end
+0139             Proj_W=U(:,1:j);
+0140         end
+0141     end
+0142 end
+0143
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SMFA/SMFA.m b/doc/+eegtoolkit/+classification/@SMFA/SMFA.m new file mode 100644 index 0000000..f16f2c7 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/SMFA.m @@ -0,0 +1,143 @@ +classdef SMFA < eegtoolkit.classification.ClassifierBase + + properties (Constant) + + end + + properties (Access = public) + W_SMFA; + PCA_mat; + trainFeat; + NumSubclasses; + SigmaCoeff; + kInt; + kPen; + end + + methods (Access = public) + function SMFA = SMFA(instanceSet,NumS,S,kInt,kPen)%,NumSubclasses,SigmaCoeff,kInt,kPen) + if nargin == 1 + SMFA.instanceSet = instanceSet; + else + SMFA.NumSubclasses = NumS; + SMFA.SigmaCoeff = S; + SMFA.kInt = kInt; + SMFA.kPen = kPen; + end + + end + + + function SMFA = build(SMFA) + SMFA.reset(); + data = SMFA.instanceSet.getInstances; + data = data'; + labels = SMFA.instanceSet.getLabels; + unique(labels) + numTrials = length(labels); + + PCA_W=SMFA.pca_func(data); +% PCA_W=eye(size(data,1)); + train_Data=PCA_W'*data; + +% Sigma = SMFA_Classifier.SigmaCoeff; + NSubClasses = SMFA.NumSubclasses; + D=pdist2(train_Data',train_Data'); +% STrain = SGE_GramMatrix(train_Data,'gau',Sigma*mean(D(:))); + STrain = 1-(D/max(D(:))); + + pt=0; + ct=0; + ClustersOfClasses = SGE_SubclassExtract(train_Data,labels,NSubClasses,pt,ct); + [yyTrain,~,~] = SGE_SubclassLabels(ClustersOfClasses,labels); + + + Par.mode = 'SMFA'; + Par.SimilMatrix = STrain; + Par.kInt = SMFA.kInt; + Par.kPen = SMFA.kPen; + dim = min([Par.kPen,size(train_Data,1)]); + + [W,Wp] = SGE_GraphConstruct(yyTrain,Par); + [TransMatrix,~] = SGE_Mapping(train_Data,dim,W,Wp); + SMFA.W_SMFA = TransMatrix; + SMFA.PCA_mat=PCA_W; + mtrainFeat=SGE_Projection(train_Data,1:dim,TransMatrix); + SMFA.trainFeat=mtrainFeat; +% figure,gplotmatrix(mtrainFeat',[],labels) + end + + function [output, probabilities, ranking] = classifyInstance(SMFA,instance) + + N = size(instance,1); + instance = instance'; + + test_Data=SMFA.PCA_mat'*instance; +% test_Data=[ones(1,N);test_Data]; + testFeat=SMFA.W_SMFA'*test_Data; +% output=knnclassify(testFeat',SMFA_Classifier.trainFeat',SMFA_Classifier.instanceSet.getLabels,5,'euclidean'); + X = SMFA.trainFeat; + y = SMFA.instanceSet.getLabels; + + %Nearest Centroid + [~,output] = SGE_Classification(X,y',testFeat,0,'euc'); + +% %SVM Linear +% [~,output] = SGE_Classification(X,y',testFeat,[1,1,1,0,1],'euc'); + +% %SVM RBF +% [~,output] = SGE_Classification(X,y',testFeat,[2,3,2/size(X,1),0,1],'euc'); + + output = output(1,:)'; + probabilities=zeros(N,1); + ranking=zeros(N,1); +% figure,gplotmatrix(testFeat',[],output) + + end + + function SMFA = reset(SMFA) + %delete all stored models + SMFA.W_SMFA=[]; + SMFA.PCA_mat=[]; + SMFA.trainFeat=[]; + end + + function configInfo = getConfigInfo(SMFA) + configInfo = sprintf('MLR_Classifier'); + end + + + function time = getTime(SMFA) + + end + + end + methods (Access = private) + function Proj_W=pca_func(MLR,data) + Proj_W=[]; + meanData=mean(data,2); + data=data-repmat(meanData,1,size(data,2)); + % stdVar=std(data')'; + % staData=(data-repmat(meanData,1,size(data,2)))./repmat(stdVar,1,size(data,2)); + % data=staData; + [V,S]=eig(data'*data); + [sorted_diagS,sorted_rank]=sort(diag(S),'descend'); + sorted_S=diag(sorted_diagS); + V=V(:,sorted_rank); + r=rank(sorted_S); + S1=sorted_S(1:r,1:r); + V1=V(:,1:r); + U=data*V1*S1^(-0.5); + %[sorted_S,sorted_rank]=sort(diag(S),'descend'); + All_energy=sum(diag(S1)); + sorted_energy=diag(S1); + for j=1:r + if (sum(sorted_energy(1:j))/All_energy)>0.99 + break + end + end + Proj_W=U(:,1:j); + end + end +end + diff --git a/doc/+eegtoolkit/+classification/@SMFA/graph.dot b/doc/+eegtoolkit/+classification/@SMFA/graph.dot new file mode 100644 index 0000000..125d60e --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + SMFA -> SMFA; + + SMFA [URL="SMFA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SMFA/graph.html b/doc/+eegtoolkit/+classification/@SMFA/graph.html new file mode 100644 index 0000000..fa2356b --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+classification/@SMFA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@SMFA >
+

Dependency Graph for +eegtoolkit/+classification/@SMFA

+ +
+Dependency Graph for +eegtoolkit/+classification/@SMFA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+classification/@SMFA/graph.map b/doc/+eegtoolkit/+classification/@SMFA/graph.map new file mode 100644 index 0000000..d632bbb --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+classification/@SMFA/graph.png b/doc/+eegtoolkit/+classification/@SMFA/graph.png new file mode 100644 index 0000000..edb8b27 Binary files /dev/null and b/doc/+eegtoolkit/+classification/@SMFA/graph.png differ diff --git a/doc/+eegtoolkit/+classification/@SMFA/index.html b/doc/+eegtoolkit/+classification/@SMFA/index.html new file mode 100644 index 0000000..8876e92 --- /dev/null +++ b/doc/+eegtoolkit/+classification/@SMFA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+classification/@SMFA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+classification/@SMFA >
+ +

Index for +eegtoolkit/+classification/@SMFA

+ +

Matlab files in this directory:

+ +
 SMFA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.html b/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.html new file mode 100644 index 0000000..c131c90 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.html @@ -0,0 +1,455 @@ + + + + Description of Experimenter + + + + + + + + + +
Home > +eegtoolkit > +experiment > @Experimenter > Experimenter.m
+ + + +

Experimenter +

+ +

PURPOSE ^

+
EXPERIMENTER class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 EXPERIMENTER class
+ Wraps all the necessary objects for performing an experiment. 
+Before running an experiment all the required properties must be set.
+ Required:
+ - session
+ - featextraction
+ - evalMethod
+ - classification
+ Optional:
+ - featselection
+ - aggregator
+ - preprocessing
+
+ to run the experiment execute the "run()" method.
+ Example:
+ experiment = eegtoolkit.experiment.Experimenter;
+ experiment.session = eegtoolkit.util.Session;
+ experiment.session.loadSubject(1);
+ experiment.transformer = eegtoolkit.featextraction.PWelch;
+ experiment.extractor = eegtoolkit.featselection.FEAST;
+ experiment.classification = eegtoolkit.classification.LIBSVM;
+ experiment.evalMethod = experiment.evalMethod.EVAL_METHOD_LOSO;
+ experiment.run;
+ results = experiment.results;
+ confmatrix = results{1}.getConfusionMatrix;
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Experimenter.m

+

SOURCE CODE ^

+
0001 % EXPERIMENTER class
+0002 % Wraps all the necessary objects for performing an experiment.
+0003 %Before running an experiment all the required properties must be set.
+0004 % Required:
+0005 % - session
+0006 % - featextraction
+0007 % - evalMethod
+0008 % - classification
+0009 % Optional:
+0010 % - featselection
+0011 % - aggregator
+0012 % - preprocessing
+0013 %
+0014 % to run the experiment execute the "run()" method.
+0015 % Example:
+0016 % experiment = eegtoolkit.experiment.Experimenter;
+0017 % experiment.session = eegtoolkit.util.Session;
+0018 % experiment.session.loadSubject(1);
+0019 % experiment.transformer = eegtoolkit.featextraction.PWelch;
+0020 % experiment.extractor = eegtoolkit.featselection.FEAST;
+0021 % experiment.classification = eegtoolkit.classification.LIBSVM;
+0022 % experiment.evalMethod = experiment.evalMethod.EVAL_METHOD_LOSO;
+0023 % experiment.run;
+0024 % results = experiment.results;
+0025 % confmatrix = results{1}.getConfusionMatrix;
+0026 classdef Experimenter < handle
+0027     properties (Constant)
+0028         EVAL_METHOD_LOOCV = 0; % Leave One Out Cross-Validation
+0029         EVAL_METHOD_LOSO = 1; % Leave One Subject Out
+0030         EVAL_METHOD_LOBO = 2;
+0031         EVAL_METHOD_SPLIT = 3;
+0032         EVAL_METHOD_XFOLD_CV = 4;
+0033         EVAL_METHOD_LOSO_LOBO = 5;
+0034     end
+0035     
+0036     properties (Access = public)
+0037         session; % The Session object. Trials must be loaded before run() is executed
+0038         preprocessing;
+0039         featextraction; % A transformer object
+0040         aggregator;
+0041         featselection; % An extractor object
+0042         evalMethod; % The evaluation method
+0043         classification; % A classifier object
+0044         results; % A cell array containing objects of the 'ResultEvaluator' class.
+0045         trainresults;
+0046         subjectids;
+0047         sessionids;
+0048     end
+0049     
+0050     methods
+0051         function E = Experimenter(evalMethod)
+0052             if nargin > 0
+0053                 E.evalMethod = evalMethod;
+0054             else E.evalMethod = 0;
+0055             end
+0056             E.results = {};
+0057         end
+0058         function E = run(E,varargin)
+0059             if(length(varargin)==1)
+0060                 numFolds = varargin{1};
+0061             elseif(length(varargin)==2)
+0062                 trainIDx = varargin{1};
+0063                 testIDx = varargin{2};
+0064             end
+0065             % Runs an experiment
+0066             E.checkCompatibility;
+0067             E.subjectids = E.session.subjectids;
+0068             E.sessionids = E.session.sessionids;
+0069             trials = {};
+0070             for i=1:length(E.session.trials)
+0071                 trials{i} = eegtoolkit.util.Trial(E.session.trials{i}.signal,...
+0072                             E.session.trials{i}.label,E.session.trials{i}.samplingRate,E.session.trials{i}.subjectid,E.session.trials{i}.sessionid,E.session.trials{i}.type);
+0073             end
+0074             if ~isempty(E.preprocessing)
+0075                 for i=1:length(E.preprocessing)
+0076                     if isa(E.preprocessing{i},'eegtoolkit.preprocessing.Windsorize')
+0077                         E.preprocessing{i}.subjectids = E.subjectids;
+0078                     end
+0079                     trials = E.preprocessing{i}.process(trials);
+0080                 end
+0081             end
+0082             disp('feature extraction ...');
+0083             if iscell(E.featextraction)
+0084                 numExtract = length(E.featextraction);
+0085                 for i=1:numExtract
+0086                     E.featextraction{i}.trials = trials;
+0087                     E.featextraction{i}.extract;    
+0088                 end
+0089                 E.aggregator.featextractors = E.featextraction;
+0090                 E.aggregator.aggregate;
+0091                 instanceSet = E.aggregator.instanceSet;
+0092             else
+0093                 E.featextraction.trials = trials;
+0094                 E.featextraction.extract;
+0095                 instanceSet = E.featextraction.getInstanceSet;
+0096             end
+0097             if ~isempty(E.featselection)
+0098                 E.featselection.originalInstanceSet = instanceSet;
+0099                 disp('feature selection ...');
+0100                 E.featselection.compute;
+0101                 E.classification.instanceSet = E.featselection.filteredInstanceSet;
+0102             else
+0103                 E.classification.instanceSet = instanceSet;
+0104             end
+0105             disp('evaluating..');
+0106             switch E.evalMethod
+0107                 case E.EVAL_METHOD_LOOCV
+0108                     E.leaveOneOutCV();
+0109                 case E.EVAL_METHOD_LOSO
+0110                     subjects = unique(E.subjectids);
+0111                     instanceSet = E.classification.instanceSet;
+0112                     if isa(E.classification,'eegtoolkit.classification.LIBSVMFast')
+0113                         instanceSet.K = instanceSet.computeKernel(E.classification.kernel,E.classification.gamma,E.classification.maxlag,E.classification.scaleopt);
+0114                     end
+0115                     for i=1:length(subjects)
+0116                         fprintf('leaving subject #%d out\n', i);
+0117                         if isa(E.classification,'eegtoolkit.classification.LIBSVMFast')
+0118                             E.leaveOneSubjectOutFast(subjects(i), instanceSet);
+0119                         else
+0120                             
+0121                             E.leaveOneSubjectOut(subjects(i), instanceSet);
+0122                         end
+0123                         
+0124                     end
+0125                 case E.EVAL_METHOD_LOBO
+0126                     sessions = unique(E.sessionids);
+0127                     instanceSet = E.classification.instanceSet;
+0128                     for i=1:length(sessions)
+0129                         fprintf('leaving session #%d out\n', i);
+0130                         E.leaveOneSessionOut(sessions(i), instanceSet);
+0131                     end
+0132                 case E.EVAL_METHOD_SPLIT
+0133                     instanceSet = E.classification.instanceSet;
+0134                     E.splitTest(trainIDx,testIDx,instanceSet);
+0135                 case E.EVAL_METHOD_XFOLD_CV
+0136                     instanceSet = E.classification.instanceSet;
+0137                     E.kfoldCrossValidation(instanceSet,numFolds);
+0138                 case E.EVAL_METHOD_LOSO_LOBO
+0139                     instanceSet = E.classification.instanceSet;
+0140                     E.leaveOneSubjectOutLeaveOneBlockOut(instanceSet);
+0141                 otherwise
+0142                     error ('eval method not set or invalid');
+0143             end
+0144         end
+0145         
+0146         function itrs = getITR(E)
+0147             for i=1:length(E.preprocessing)
+0148                 if isa(E.preprocessing{i},'eegtoolkit.preprocessing.SampleSelection')
+0149                     %T = time in seconds;
+0150                     T = (E.preprocessing{i}.sampleRange(2)-E.preprocessing{i}.sampleRange(1)+1)/E.preprocessing{i}.samplingRate;
+0151                 end
+0152             end
+0153             if isempty(T)
+0154                 error('to calculate ITR the SampleSelection preprocessing step must be added to the experiment');
+0155             end
+0156             for i=1:length(E.results)
+0157                 itrs(i) = E.results{i}.getITR(T);
+0158             end
+0159         end
+0160         function time = getTime(E)
+0161             info = 'Average time elapsed for trial:\n';
+0162             total = 0;
+0163             if ~isempty(E.preprocessing)
+0164                 info = strcat(info, 'Preprocessing:\n');
+0165                 for i=1:length(E.preprocessing)
+0166                     info = strcat(info, num2str(E.preprocessing{i}.getTime));
+0167                     total = total + E.preprocessing{i}.getTime;
+0168                     info = strcat(info, '\n');
+0169                 end
+0170             end
+0171             if ~isempty(E.featextraction)
+0172                 info = strcat(info, 'Feature Extraction:\n');
+0173                 if ~iscell(E.featextraction)
+0174                     info = strcat(info, num2str(E.featextraction.getTime));
+0175                     total = total + E.featextraction.getTime;
+0176                     info = strcat(info, '\n');
+0177                 else
+0178                     for i=1:length(E.featextraction)
+0179                         info = strcat(info, num2str(E.featextraction{i}.getTime));
+0180                         total = total + E.featextraction{i}.getTime;
+0181                         info = strcat(info,'\n');
+0182                     end
+0183                 end
+0184             end
+0185             if ~isempty(E.aggregator)
+0186                 info = strcat(info, 'Aggregation:\n');
+0187                 info = strcat(info, num2str(E.aggregator.getTime));
+0188                 total = total + E.aggregator.getTime;
+0189                 info = strcat(info, '\n');
+0190             end
+0191             if ~isempty(E.featselection)
+0192                 info = strcat(info, 'FeatureSelection:\n');
+0193                 info = strcat(info, num2str(E.featselection.getTime));
+0194                 total = total + E.featselection.getTime;
+0195                 info = strcat(info, '\n');
+0196             end
+0197             if ~isempty(E.classification)
+0198                 info = strcat(info, 'Classification (Prediction):\n');
+0199                 info = strcat(info, num2str(E.classification.getTime));
+0200                 total = total + E.classification.getTime;
+0201                 info = strcat(info, '\n');
+0202             end
+0203             info = strcat(info, 'Total:\n');
+0204             info = strcat(info, num2str(total));
+0205             time = sprintf(info);
+0206         end
+0207         
+0208         function info = getExperimentInfo(E)
+0209             % Prints the configuration info of the experiment
+0210             info = 'Experiment Configuration:\n';
+0211             if ~isempty(E.preprocessing)
+0212                 for i=1:length(E.preprocessing)
+0213                     info = strcat(info, E.preprocessing{i}.getConfigInfo);
+0214                     info = strcat(info,'\n');
+0215                 end
+0216             end
+0217             if ~isempty(E.featextraction)
+0218                 if ~iscell(E.featextraction)
+0219                     info = strcat(info, E.featextraction.getConfigInfo);
+0220                     info = strcat(info,'\n');
+0221                 else
+0222                     for i=1:length(E.featextraction)
+0223                         info = strcat(info, E.featextraction{i}.getConfigInfo);
+0224                         info = strcat(info,'\n');
+0225                     end
+0226                 end
+0227             end
+0228             if ~isempty(E.aggregator)
+0229                 info = strcat(info, E.aggregator.getConfigInfo);
+0230                 info = strcat(info, '\n');
+0231             end
+0232             if ~isempty(E.featselection)
+0233                 info = strcat(info, E.featselection.getConfigInfo);
+0234                 info = strcat(info, '\n');
+0235             end
+0236             if ~isempty(E.classification)
+0237                 info = strcat(info, E.classification.getConfigInfo);
+0238                 info = strcat(info, '\n');
+0239             end
+0240             info = sprintf(info);
+0241         end
+0242         
+0243     end
+0244     
+0245     methods (Access = private)
+0246         
+0247         function E = checkCompatibility(E)
+0248             if iscell(E.featextraction)
+0249                 if isempty(E.aggregator)
+0250                     error ('Provided many feature extractors but not an Aggregator');
+0251                 end
+0252             end
+0253             if isa(E.classification,'eegtoolkit.classification.LIBSVMFast') && E.evalMethod == 0
+0254                 error('LIBSVMFast not supported for LOOCV eval method');
+0255             end
+0256         end
+0257             
+0258         function E = leaveOneOutCV(E)
+0259             %leave one out cross validation
+0260             instanceSet = E.classification.instanceSet;
+0261             numInstances = instanceSet.getNumInstances;
+0262             outputLabels = zeros(numInstances,1);
+0263             outputScores = zeros(numInstances,1);
+0264             outputRanking = zeros(numInstances, instanceSet.getNumLabels);
+0265             h = waitbar(0,'Cross-validating..');
+0266             for i=1:numInstances
+0267                 waitbar(i/numInstances,h,sprintf('Cross-validating fold: %d/%d', i, numInstances));
+0268                 %train the classifier without 1 instance
+0269                 E.classification.instanceSet = instanceSet.removeInstancesWithIndices(i);
+0270                 E.classification.build();
+0271                 %predict the label of the omitted instance
+0272                 [outputLabels(i,1), outputScores(i,1), outputRanking(i,:)] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(i));
+0273             end
+0274             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDataset, outputLabels, outputScores, outputRanking);
+0275             E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0276             close(h);
+0277         end
+0278         
+0279         function E = kfoldCrossValidation(E,instanceSet,numFolds)
+0280             numInstances = instanceSet.getNumInstances;
+0281             indices = crossvalind('Kfold', numInstances, numFolds);
+0282             outputLabels = zeros(numInstances,1);
+0283             outputScores = zeros(numInstances,1);
+0284             outputRanking = zeros(numInstances,instanceSet.getNumLabels);
+0285             h = waitbar(0,'Cross-validating..');
+0286             for i=1:numFolds
+0287                 waitbar(i/numFolds,h,sprintf('Cross-validating fold: %d/%d',i,numFolds));
+0288                 testSet = find(indices==i);
+0289                 E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testSet);
+0290                 E.classification.build();
+0291                 
+0292                 [outputLabels(testSet,1), outputScores(testSet,1), outputRanking(testSet,:)] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testSet));
+0293             end
+0294             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDataset, outputLabels, outputScores, outputRanking);
+0295             E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0296             close(h);
+0297         end
+0298         
+0299         function resultSet = leaveOneSubjectOut(E, subjectid, instanceSet)
+0300             testingset = find(E.subjectids == subjectid);
+0301             E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset);
+0302             E.classification.build();
+0303             [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset));
+0304             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking);
+0305             E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0306         end
+0307         
+0308                 
+0309         function resultSet = leaveOneSubjectOutLeaveOneBlockOut(E, instanceSet)
+0310             subjects = unique(E.subjectids);
+0311             sessions = unique(E.sessionids);
+0312             for i=1:length(subjects)
+0313                 numInstancesForSubject = sum(E.subjectids==subjects(i));
+0314                 outputLabels = zeros(numInstancesForSubject,1);
+0315                 outputScores = zeros(numInstancesForSubject,1);
+0316                 outputRanking = zeros(numInstancesForSubject,instanceSet.getNumLabels());
+0317                 for j=1:length(sessions)
+0318 %                     tempResults{j} = E.leaveOneSessionOut(sessions(j),tempInstanceSet);
+0319                     sessionidsSubset = E.sessionids(E.subjectids==subjects(i));
+0320                     testIndices = sessionidsSubset==sessions(j);
+0321                     numInstancesForSession = sum(E.sessionids==sessions(j)&E.subjectids==subjects(i));
+0322                     testingset = find(E.sessionids==sessions(j)&E.subjectids==subjects(i));
+0323                     nottrainset = find(E.sessionids==sessions(j)|E.subjectids~=subjects(i));
+0324                     E.classification.instanceSet = instanceSet.removeInstancesWithIndices(nottrainset);
+0325                     E.classification.build();
+0326                     [outputLabels(testIndices,:), outputScores(testIndices,:), outputRanking(testIndices,:)] = ...
+0327                         E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset));
+0328                     
+0329                 end
+0330                 sIndices = find(E.subjectids==subjects(i));
+0331                 resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(sIndices),outputLabels,outputScores,outputRanking);
+0332                 E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0333                 %merge the results
+0334             end
+0335         end
+0336         
+0337         
+0338         function resultSet = leaveOneSessionOut(E, sessionId, instanceSet)
+0339             testingset = find(E.sessionids == sessionId);
+0340             trainset = find(E.sessionids ~= sessionId);
+0341             E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset);
+0342             E.classification.build();
+0343             [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset));
+0344             [trainoutputLabels, trainoutputScores, trainoutputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(trainset));
+0345             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking);
+0346             trainresultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(trainset), trainoutputLabels, trainoutputScores, trainoutputRanking);
+0347             E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0348             E.trainresults{length(E.trainresults)+1} = eegtoolkit.experiment.ResultEvaluator(trainresultSet);
+0349         end
+0350         
+0351         function resultSet = leaveOneSubjectOutFast(E, subjectid, instanceSet)
+0352             testingset = E.subjectids == subjectid;
+0353             E.classification.Ktrain = instanceSet.getTrainKernel(~testingset);
+0354             E.classification.Ktest = instanceSet.getTestKernel(~testingset,testingset);
+0355             testingset = find(E.subjectids == subjectid);
+0356             E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset);
+0357             E.classification.build();
+0358             [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance();
+0359             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking);
+0360             resultEvaluator = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0361             resultEvaluator.subjectid = E.subjectids(E.subjectids==subjectid);
+0362             resultEvaluator.sessionid = E.session.sessionids(E.subjectids==subjectid);
+0363             E.results{length(E.results)+1} = resultEvaluator;
+0364         end
+0365 
+0366         function resultSet = splitTest(E,trainIDx,testIDx, instanceSet)
+0367             E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testIDx);
+0368             E.classification.build();
+0369             [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testIDx));
+0370             resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testIDx), outputLabels, outputScores, outputRanking);
+0371             resultEvaluator = eegtoolkit.experiment.ResultEvaluator(resultSet);
+0372             E.results{length(E.results) + 1} = resultEvaluator;
+0373         end
+0374         
+0375 
+0376                 
+0377             
+0378     end
+0379     
+0380 end
+0381
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.m b/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.m new file mode 100644 index 0000000..9b28677 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/Experimenter.m @@ -0,0 +1,381 @@ +% EXPERIMENTER class +% Wraps all the necessary objects for performing an experiment. +%Before running an experiment all the required properties must be set. +% Required: +% - session +% - featextraction +% - evalMethod +% - classification +% Optional: +% - featselection +% - aggregator +% - preprocessing +% +% to run the experiment execute the "run()" method. +% Example: +% experiment = eegtoolkit.experiment.Experimenter; +% experiment.session = eegtoolkit.util.Session; +% experiment.session.loadSubject(1); +% experiment.transformer = eegtoolkit.featextraction.PWelch; +% experiment.extractor = eegtoolkit.featselection.FEAST; +% experiment.classification = eegtoolkit.classification.LIBSVM; +% experiment.evalMethod = experiment.evalMethod.EVAL_METHOD_LOSO; +% experiment.run; +% results = experiment.results; +% confmatrix = results{1}.getConfusionMatrix; +classdef Experimenter < handle + properties (Constant) + EVAL_METHOD_LOOCV = 0; % Leave One Out Cross-Validation + EVAL_METHOD_LOSO = 1; % Leave One Subject Out + EVAL_METHOD_LOBO = 2; + EVAL_METHOD_SPLIT = 3; + EVAL_METHOD_XFOLD_CV = 4; + EVAL_METHOD_LOSO_LOBO = 5; + end + + properties (Access = public) + session; % The Session object. Trials must be loaded before run() is executed + preprocessing; + featextraction; % A transformer object + aggregator; + featselection; % An extractor object + evalMethod; % The evaluation method + classification; % A classifier object + results; % A cell array containing objects of the 'ResultEvaluator' class. + trainresults; + subjectids; + sessionids; + end + + methods + function E = Experimenter(evalMethod) + if nargin > 0 + E.evalMethod = evalMethod; + else E.evalMethod = 0; + end + E.results = {}; + end + function E = run(E,varargin) + if(length(varargin)==1) + numFolds = varargin{1}; + elseif(length(varargin)==2) + trainIDx = varargin{1}; + testIDx = varargin{2}; + end + % Runs an experiment + E.checkCompatibility; + E.subjectids = E.session.subjectids; + E.sessionids = E.session.sessionids; + trials = {}; + for i=1:length(E.session.trials) + trials{i} = eegtoolkit.util.Trial(E.session.trials{i}.signal,... + E.session.trials{i}.label,E.session.trials{i}.samplingRate,E.session.trials{i}.subjectid,E.session.trials{i}.sessionid,E.session.trials{i}.type); + end + if ~isempty(E.preprocessing) + for i=1:length(E.preprocessing) + if isa(E.preprocessing{i},'eegtoolkit.preprocessing.Windsorize') + E.preprocessing{i}.subjectids = E.subjectids; + end + trials = E.preprocessing{i}.process(trials); + end + end + disp('feature extraction ...'); + if iscell(E.featextraction) + numExtract = length(E.featextraction); + for i=1:numExtract + E.featextraction{i}.trials = trials; + E.featextraction{i}.extract; + end + E.aggregator.featextractors = E.featextraction; + E.aggregator.aggregate; + instanceSet = E.aggregator.instanceSet; + else + E.featextraction.trials = trials; + E.featextraction.extract; + instanceSet = E.featextraction.getInstanceSet; + end + if ~isempty(E.featselection) + E.featselection.originalInstanceSet = instanceSet; + disp('feature selection ...'); + E.featselection.compute; + E.classification.instanceSet = E.featselection.filteredInstanceSet; + else + E.classification.instanceSet = instanceSet; + end + disp('evaluating..'); + switch E.evalMethod + case E.EVAL_METHOD_LOOCV + E.leaveOneOutCV(); + case E.EVAL_METHOD_LOSO + subjects = unique(E.subjectids); + instanceSet = E.classification.instanceSet; + if isa(E.classification,'eegtoolkit.classification.LIBSVMFast') + instanceSet.K = instanceSet.computeKernel(E.classification.kernel,E.classification.gamma,E.classification.maxlag,E.classification.scaleopt); + end + for i=1:length(subjects) + fprintf('leaving subject #%d out\n', i); + if isa(E.classification,'eegtoolkit.classification.LIBSVMFast') + E.leaveOneSubjectOutFast(subjects(i), instanceSet); + else + + E.leaveOneSubjectOut(subjects(i), instanceSet); + end + + end + case E.EVAL_METHOD_LOBO + sessions = unique(E.sessionids); + instanceSet = E.classification.instanceSet; + for i=1:length(sessions) + fprintf('leaving session #%d out\n', i); + E.leaveOneSessionOut(sessions(i), instanceSet); + end + case E.EVAL_METHOD_SPLIT + instanceSet = E.classification.instanceSet; + E.splitTest(trainIDx,testIDx,instanceSet); + case E.EVAL_METHOD_XFOLD_CV + instanceSet = E.classification.instanceSet; + E.kfoldCrossValidation(instanceSet,numFolds); + case E.EVAL_METHOD_LOSO_LOBO + instanceSet = E.classification.instanceSet; + E.leaveOneSubjectOutLeaveOneBlockOut(instanceSet); + otherwise + error ('eval method not set or invalid'); + end + end + + function itrs = getITR(E) + for i=1:length(E.preprocessing) + if isa(E.preprocessing{i},'eegtoolkit.preprocessing.SampleSelection') + %T = time in seconds; + T = (E.preprocessing{i}.sampleRange(2)-E.preprocessing{i}.sampleRange(1)+1)/E.preprocessing{i}.samplingRate; + end + end + if isempty(T) + error('to calculate ITR the SampleSelection preprocessing step must be added to the experiment'); + end + for i=1:length(E.results) + itrs(i) = E.results{i}.getITR(T); + end + end + function time = getTime(E) + info = 'Average time elapsed for trial:\n'; + total = 0; + if ~isempty(E.preprocessing) + info = strcat(info, 'Preprocessing:\n'); + for i=1:length(E.preprocessing) + info = strcat(info, num2str(E.preprocessing{i}.getTime)); + total = total + E.preprocessing{i}.getTime; + info = strcat(info, '\n'); + end + end + if ~isempty(E.featextraction) + info = strcat(info, 'Feature Extraction:\n'); + if ~iscell(E.featextraction) + info = strcat(info, num2str(E.featextraction.getTime)); + total = total + E.featextraction.getTime; + info = strcat(info, '\n'); + else + for i=1:length(E.featextraction) + info = strcat(info, num2str(E.featextraction{i}.getTime)); + total = total + E.featextraction{i}.getTime; + info = strcat(info,'\n'); + end + end + end + if ~isempty(E.aggregator) + info = strcat(info, 'Aggregation:\n'); + info = strcat(info, num2str(E.aggregator.getTime)); + total = total + E.aggregator.getTime; + info = strcat(info, '\n'); + end + if ~isempty(E.featselection) + info = strcat(info, 'FeatureSelection:\n'); + info = strcat(info, num2str(E.featselection.getTime)); + total = total + E.featselection.getTime; + info = strcat(info, '\n'); + end + if ~isempty(E.classification) + info = strcat(info, 'Classification (Prediction):\n'); + info = strcat(info, num2str(E.classification.getTime)); + total = total + E.classification.getTime; + info = strcat(info, '\n'); + end + info = strcat(info, 'Total:\n'); + info = strcat(info, num2str(total)); + time = sprintf(info); + end + + function info = getExperimentInfo(E) + % Prints the configuration info of the experiment + info = 'Experiment Configuration:\n'; + if ~isempty(E.preprocessing) + for i=1:length(E.preprocessing) + info = strcat(info, E.preprocessing{i}.getConfigInfo); + info = strcat(info,'\n'); + end + end + if ~isempty(E.featextraction) + if ~iscell(E.featextraction) + info = strcat(info, E.featextraction.getConfigInfo); + info = strcat(info,'\n'); + else + for i=1:length(E.featextraction) + info = strcat(info, E.featextraction{i}.getConfigInfo); + info = strcat(info,'\n'); + end + end + end + if ~isempty(E.aggregator) + info = strcat(info, E.aggregator.getConfigInfo); + info = strcat(info, '\n'); + end + if ~isempty(E.featselection) + info = strcat(info, E.featselection.getConfigInfo); + info = strcat(info, '\n'); + end + if ~isempty(E.classification) + info = strcat(info, E.classification.getConfigInfo); + info = strcat(info, '\n'); + end + info = sprintf(info); + end + + end + + methods (Access = private) + + function E = checkCompatibility(E) + if iscell(E.featextraction) + if isempty(E.aggregator) + error ('Provided many feature extractors but not an Aggregator'); + end + end + if isa(E.classification,'eegtoolkit.classification.LIBSVMFast') && E.evalMethod == 0 + error('LIBSVMFast not supported for LOOCV eval method'); + end + end + + function E = leaveOneOutCV(E) + %leave one out cross validation + instanceSet = E.classification.instanceSet; + numInstances = instanceSet.getNumInstances; + outputLabels = zeros(numInstances,1); + outputScores = zeros(numInstances,1); + outputRanking = zeros(numInstances, instanceSet.getNumLabels); + h = waitbar(0,'Cross-validating..'); + for i=1:numInstances + waitbar(i/numInstances,h,sprintf('Cross-validating fold: %d/%d', i, numInstances)); + %train the classifier without 1 instance + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(i); + E.classification.build(); + %predict the label of the omitted instance + [outputLabels(i,1), outputScores(i,1), outputRanking(i,:)] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(i)); + end + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDataset, outputLabels, outputScores, outputRanking); + E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet); + close(h); + end + + function E = kfoldCrossValidation(E,instanceSet,numFolds) + numInstances = instanceSet.getNumInstances; + indices = crossvalind('Kfold', numInstances, numFolds); + outputLabels = zeros(numInstances,1); + outputScores = zeros(numInstances,1); + outputRanking = zeros(numInstances,instanceSet.getNumLabels); + h = waitbar(0,'Cross-validating..'); + for i=1:numFolds + waitbar(i/numFolds,h,sprintf('Cross-validating fold: %d/%d',i,numFolds)); + testSet = find(indices==i); + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testSet); + E.classification.build(); + + [outputLabels(testSet,1), outputScores(testSet,1), outputRanking(testSet,:)] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testSet)); + end + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDataset, outputLabels, outputScores, outputRanking); + E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet); + close(h); + end + + function resultSet = leaveOneSubjectOut(E, subjectid, instanceSet) + testingset = find(E.subjectids == subjectid); + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset); + E.classification.build(); + [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset)); + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking); + E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet); + end + + + function resultSet = leaveOneSubjectOutLeaveOneBlockOut(E, instanceSet) + subjects = unique(E.subjectids); + sessions = unique(E.sessionids); + for i=1:length(subjects) + numInstancesForSubject = sum(E.subjectids==subjects(i)); + outputLabels = zeros(numInstancesForSubject,1); + outputScores = zeros(numInstancesForSubject,1); + outputRanking = zeros(numInstancesForSubject,instanceSet.getNumLabels()); + for j=1:length(sessions) +% tempResults{j} = E.leaveOneSessionOut(sessions(j),tempInstanceSet); + sessionidsSubset = E.sessionids(E.subjectids==subjects(i)); + testIndices = sessionidsSubset==sessions(j); + numInstancesForSession = sum(E.sessionids==sessions(j)&E.subjectids==subjects(i)); + testingset = find(E.sessionids==sessions(j)&E.subjectids==subjects(i)); + nottrainset = find(E.sessionids==sessions(j)|E.subjectids~=subjects(i)); + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(nottrainset); + E.classification.build(); + [outputLabels(testIndices,:), outputScores(testIndices,:), outputRanking(testIndices,:)] = ... + E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset)); + + end + sIndices = find(E.subjectids==subjects(i)); + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(sIndices),outputLabels,outputScores,outputRanking); + E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet); + %merge the results + end + end + + + function resultSet = leaveOneSessionOut(E, sessionId, instanceSet) + testingset = find(E.sessionids == sessionId); + trainset = find(E.sessionids ~= sessionId); + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset); + E.classification.build(); + [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testingset)); + [trainoutputLabels, trainoutputScores, trainoutputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(trainset)); + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking); + trainresultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(trainset), trainoutputLabels, trainoutputScores, trainoutputRanking); + E.results{length(E.results)+1} = eegtoolkit.experiment.ResultEvaluator(resultSet); + E.trainresults{length(E.trainresults)+1} = eegtoolkit.experiment.ResultEvaluator(trainresultSet); + end + + function resultSet = leaveOneSubjectOutFast(E, subjectid, instanceSet) + testingset = E.subjectids == subjectid; + E.classification.Ktrain = instanceSet.getTrainKernel(~testingset); + E.classification.Ktest = instanceSet.getTestKernel(~testingset,testingset); + testingset = find(E.subjectids == subjectid); + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testingset); + E.classification.build(); + [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(); + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testingset), outputLabels, outputScores, outputRanking); + resultEvaluator = eegtoolkit.experiment.ResultEvaluator(resultSet); + resultEvaluator.subjectid = E.subjectids(E.subjectids==subjectid); + resultEvaluator.sessionid = E.session.sessionids(E.subjectids==subjectid); + E.results{length(E.results)+1} = resultEvaluator; + end + + function resultSet = splitTest(E,trainIDx,testIDx, instanceSet) + E.classification.instanceSet = instanceSet.removeInstancesWithIndices(testIDx); + E.classification.build(); + [outputLabels, outputScores, outputRanking] = E.classification.classifyInstance(instanceSet.getInstancesWithIndices(testIDx)); + resultSet = eegtoolkit.util.ResultSet(instanceSet.getDatasetWithIndices(testIDx), outputLabels, outputScores, outputRanking); + resultEvaluator = eegtoolkit.experiment.ResultEvaluator(resultSet); + E.results{length(E.results) + 1} = resultEvaluator; + end + + + + + end + +end + diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/graph.dot b/doc/+eegtoolkit/+experiment/@Experimenter/graph.dot new file mode 100644 index 0000000..c2a7d3c --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Experimenter -> Experimenter; + + Experimenter [URL="Experimenter.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/graph.html b/doc/+eegtoolkit/+experiment/@Experimenter/graph.html new file mode 100644 index 0000000..22f2970 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+experiment/@Experimenter + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+experiment/@Experimenter >
+

Dependency Graph for +eegtoolkit/+experiment/@Experimenter

+ +
+Dependency Graph for +eegtoolkit/+experiment/@Experimenter + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/graph.map b/doc/+eegtoolkit/+experiment/@Experimenter/graph.map new file mode 100644 index 0000000..1e7afc3 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/graph.png b/doc/+eegtoolkit/+experiment/@Experimenter/graph.png new file mode 100644 index 0000000..58fd336 Binary files /dev/null and b/doc/+eegtoolkit/+experiment/@Experimenter/graph.png differ diff --git a/doc/+eegtoolkit/+experiment/@Experimenter/index.html b/doc/+eegtoolkit/+experiment/@Experimenter/index.html new file mode 100644 index 0000000..0fd74bf --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@Experimenter/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+experiment/@Experimenter + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+experiment/@Experimenter >
+ +

Index for +eegtoolkit/+experiment/@Experimenter

+ +

Matlab files in this directory:

+ +
 ExperimenterEXPERIMENTER class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.html b/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.html new file mode 100644 index 0000000..490d093 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.html @@ -0,0 +1,136 @@ + + + + Description of ResultEvaluator + + + + + + + + + +
Home > +eegtoolkit > +experiment > @ResultEvaluator > ResultEvaluator.m
+ + + +

ResultEvaluator +

+ +

PURPOSE ^

+
RESULTEVALUATOR class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 RESULTEVALUATOR class
+ Parses the results of an experiment and calculates various metrics
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ResultEvaluator.m

+

SOURCE CODE ^

+
0001 % RESULTEVALUATOR class
+0002 % Parses the results of an experiment and calculates various metrics
+0003 classdef  ResultEvaluator < handle
+0004     properties
+0005         resultSet; % A 'ResultSet' object containing the results of an experiment
+0006         subjectid; % The subject ids corresponding
+0007         sessionid;
+0008     end
+0009     
+0010     methods 
+0011         function RE = ResultEvaluator(resultSet)
+0012             if nargin > 0
+0013                 RE.resultSet = resultSet;
+0014             end
+0015         end
+0016         
+0017         function acc = getAccuracy(RE)
+0018             conf = RE.resultSet.confusionMatrix;
+0019             acc = sum(diag(conf))/sum(sum(conf))*100;
+0020         end
+0021         
+0022         function confusionMatrix = getConfusionMatrix(RE)
+0023             %Returns the confusion matrix with labels as the last row
+0024             %if you want the confusion matrix without labels then
+0025             %access the confusionMatrix property of the resultSet directly
+0026             labels = unique(RE.resultSet.getLabels);
+0027             confusionMatrix = horzcat(RE.resultSet.confusionMatrix, labels);
+0028         end
+0029         
+0030         function acc = getAccuracyForSession(RE,session)
+0031             conf = RE.resultSet.subset(RE.sessionid==session).confusionMatrix;
+0032             acc = sum(diag(conf))/sum(sum(conf))*100;
+0033         end
+0034         
+0035         function accuracies = getAccuracyBySession(RE)
+0036             unsessions = unique(RE.sessionid);
+0037             for i=1:length(unsessions)
+0038                 accuracies(i) = RE.getAccuracyForSession(unsessions(i));
+0039             end
+0040         end
+0041         
+0042         function accuracies = getAccuracyByLabel(RE)
+0043             [rows,~] = size(RE.resultSet.confusionMatrix);
+0044             for i=1:rows
+0045                 accuracies(i) = RE.resultSet.confusionMatrix(i,i)/sum(RE.resultSet.confusionMatrix(i,:))*100;
+0046             end
+0047         end
+0048         
+0049         
+0050         function ITR = getITR(RE,T)
+0051             P = RE.getAccuracy/100;
+0052             M = RE.resultSet.getNumLabels;
+0053 %             fprintf('T = %f',T);
+0054 %             fprintf('P = %f',P);
+0055 %             fprintf('M = %f',M);
+0056 %             fprintf('\n');
+0057             ITR = (log2(M) + P*log2(P)+(1-P)*log2((1-P)/(M-1)))/T;
+0058         end
+0059         
+0060 %         function TP = getNumTruePositives(RE)
+0061 %             conf = RE.resultSet.confusionMatrix;
+0062 %             TP = diag(conf)';
+0063 %         end
+0064 %
+0065 %         function TN = getNumTrueNegatives(RE)
+0066 %             numInstances = RE.resultSet.getNumInstances;
+0067 %             FN = RE.getNumFalseNegatives;
+0068 %             TP = RE.getNumTruePositives;
+0069 %             FP = RE.getNumFalsePositives;
+0070 %             TN = numInstances - FN - TP - FP;
+0071 %         end
+0072 %
+0073 %         function FP = getNumFalsePositives(RE)
+0074 %             conf = RE.resultSet.confusionMatrix;
+0075 %             FP = sum(conf') - diag(conf)';
+0076 %         end
+0077 %
+0078 %         function FN = getNumFalseNegatives(RE)
+0079 %             conf = RE.resultSet.confusionMatrix;
+0080 %             FN = sum(conf) - diag(conf)';
+0081 %         end
+0082         
+0083     end
+0084 end
+0085
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.m b/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.m new file mode 100644 index 0000000..95999bd --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/ResultEvaluator.m @@ -0,0 +1,85 @@ +% RESULTEVALUATOR class +% Parses the results of an experiment and calculates various metrics +classdef ResultEvaluator < handle + properties + resultSet; % A 'ResultSet' object containing the results of an experiment + subjectid; % The subject ids corresponding + sessionid; + end + + methods + function RE = ResultEvaluator(resultSet) + if nargin > 0 + RE.resultSet = resultSet; + end + end + + function acc = getAccuracy(RE) + conf = RE.resultSet.confusionMatrix; + acc = sum(diag(conf))/sum(sum(conf))*100; + end + + function confusionMatrix = getConfusionMatrix(RE) + %Returns the confusion matrix with labels as the last row + %if you want the confusion matrix without labels then + %access the confusionMatrix property of the resultSet directly + labels = unique(RE.resultSet.getLabels); + confusionMatrix = horzcat(RE.resultSet.confusionMatrix, labels); + end + + function acc = getAccuracyForSession(RE,session) + conf = RE.resultSet.subset(RE.sessionid==session).confusionMatrix; + acc = sum(diag(conf))/sum(sum(conf))*100; + end + + function accuracies = getAccuracyBySession(RE) + unsessions = unique(RE.sessionid); + for i=1:length(unsessions) + accuracies(i) = RE.getAccuracyForSession(unsessions(i)); + end + end + + function accuracies = getAccuracyByLabel(RE) + [rows,~] = size(RE.resultSet.confusionMatrix); + for i=1:rows + accuracies(i) = RE.resultSet.confusionMatrix(i,i)/sum(RE.resultSet.confusionMatrix(i,:))*100; + end + end + + + function ITR = getITR(RE,T) + P = RE.getAccuracy/100; + M = RE.resultSet.getNumLabels; +% fprintf('T = %f',T); +% fprintf('P = %f',P); +% fprintf('M = %f',M); +% fprintf('\n'); + ITR = (log2(M) + P*log2(P)+(1-P)*log2((1-P)/(M-1)))/T; + end + +% function TP = getNumTruePositives(RE) +% conf = RE.resultSet.confusionMatrix; +% TP = diag(conf)'; +% end +% +% function TN = getNumTrueNegatives(RE) +% numInstances = RE.resultSet.getNumInstances; +% FN = RE.getNumFalseNegatives; +% TP = RE.getNumTruePositives; +% FP = RE.getNumFalsePositives; +% TN = numInstances - FN - TP - FP; +% end +% +% function FP = getNumFalsePositives(RE) +% conf = RE.resultSet.confusionMatrix; +% FP = sum(conf') - diag(conf)'; +% end +% +% function FN = getNumFalseNegatives(RE) +% conf = RE.resultSet.confusionMatrix; +% FN = sum(conf) - diag(conf)'; +% end + + end +end + diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.dot b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.dot new file mode 100644 index 0000000..9eaf551 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ResultEvaluator -> ResultEvaluator; + + ResultEvaluator [URL="ResultEvaluator.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.html b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.html new file mode 100644 index 0000000..4a0970f --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+experiment/@ResultEvaluator + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+experiment/@ResultEvaluator >
+

Dependency Graph for +eegtoolkit/+experiment/@ResultEvaluator

+ +
+Dependency Graph for +eegtoolkit/+experiment/@ResultEvaluator + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.map b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.map new file mode 100644 index 0000000..34331ac --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.png b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.png new file mode 100644 index 0000000..5a636b3 Binary files /dev/null and b/doc/+eegtoolkit/+experiment/@ResultEvaluator/graph.png differ diff --git a/doc/+eegtoolkit/+experiment/@ResultEvaluator/index.html b/doc/+eegtoolkit/+experiment/@ResultEvaluator/index.html new file mode 100644 index 0000000..2fef9c7 --- /dev/null +++ b/doc/+eegtoolkit/+experiment/@ResultEvaluator/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+experiment/@ResultEvaluator + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+experiment/@ResultEvaluator >
+ +

Index for +eegtoolkit/+experiment/@ResultEvaluator

+ +

Matlab files in this directory:

+ +
 ResultEvaluatorRESULTEVALUATOR class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@CCA/CCA.html b/doc/+eegtoolkit/+featextraction/@CCA/CCA.html new file mode 100644 index 0000000..510fc15 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/CCA.html @@ -0,0 +1,195 @@ + + + + Description of CCA + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @CCA > CCA.m
+ + + +

CCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

CCA.m

+

SOURCE CODE ^

+
0001 classdef CCA < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase
+0002     %
+0003     % works only on our datasets, for other datasets needs modifications
+0004     %
+0005     properties (Access = public)
+0006         channel;
+0007         avgTime;
+0008         stimulus_freqs;
+0009         FreqSamp;
+0010         NumHarm;
+0011         allFeatures;
+0012     end
+0013     methods (Access = public)
+0014         function CCA = CCA(sti_f,chans,fs,numH)
+0015             if ( nargin ~= 4 )
+0016                 error('It is needed to define the simulus freqs, the channels, frequency sampling and number of harmonics');
+0017             else
+0018                 CCA.stimulus_freqs = sti_f;
+0019                 CCA.channel = chans;
+0020                 CCA.FreqSamp = fs;
+0021                 CCA.NumHarm = numH;
+0022                 CCA.allFeatures = 0;
+0023             end
+0024         end
+0025         
+0026         function extract(CCA)
+0027             sti_f = CCA.stimulus_freqs;
+0028             mLen=size(CCA.trials{1}.signal,2);
+0029             refSignals=CCA.ck_signalTrans(sti_f,mLen,CCA.FreqSamp,CCA.NumHarm);
+0030             NumStim = size(refSignals,3);
+0031             numTrials = length(CCA.trials);
+0032             for i=1:numTrials
+0033                 data = CCA.trials{i}.signal(CCA.channel,:);
+0034                 if(CCA.allFeatures == 1)
+0035                     features=NaN*ones(NumStim,min(rank(data),CCA.NumHarm*2));
+0036                     for j=1:NumStim
+0037                         [wx1,wy1,r1] = canoncorr(data',refSignals(:,:,j)');
+0038                         features(j,:) = r1;
+0039                     end
+0040                     tempfeatures = features(1,:);
+0041                     for j=2:NumStim
+0042                         tempfeatures = horzcat(tempfeatures,features(j,:));
+0043                     end
+0044                     instances(i,:) = tempfeatures(:);
+0045                     labels(i,1) = floor(CCA.trials{i}.label);
+0046                 else
+0047                     features=NaN*ones(NumStim,1);
+0048                     for j=1:NumStim
+0049                         %                     [wx1,wy1,r1] = CCA.cca(data,refSignals(:,:,j));
+0050                         [wx1,wy1,r1] = canoncorr(data',refSignals(:,:,j)');
+0051                         features(j) = max(r1);
+0052                     end
+0053                     instances(i,:) = features(:);
+0054                     labels(i,1) = floor(CCA.trials{i}.label);
+0055                 end
+0056             end
+0057 %             unique(labels)
+0058             if (sum(unique(labels)) == 41)
+0059                 labels(labels==6)=1;
+0060                 labels(labels==7)=2;
+0061                 labels(labels==8)=3;
+0062                 labels(labels==9)=4;
+0063                 labels(labels==11)=5;
+0064             end
+0065 %             unique(labels)
+0066             CCA.instanceSet = eegtoolkit.util.InstanceSet(instances, labels);
+0067         end
+0068         
+0069         function configInfo = getConfigInfo(CCA)
+0070             configInfo = sprintf('CCA');
+0071         end
+0072         
+0073 %         function [Wx, Wy, r] = cca(CCA,X,Y)
+0074 %
+0075 %             % CCA calculate canonical correlations
+0076 %             %
+0077 %             % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation
+0078 %
+0079 %             % vectors as columns and r is a vector with corresponding canonical
+0080 %             % correlations. The correlations are sorted in descending order. X and Y
+0081 %             % are matrices where each column is a sample. Hence, X and Y must have
+0082 %             % the same number of columns.
+0083 %             %
+0084 %             % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is
+0085 %             % then M*L, Wy is N*L and r is L*1.
+0086 %             %
+0087 %             %
+0088 %             % ?? 2000 Magnus Borga, Link?pings universitet
+0089 %
+0090 %             % --- Calculate covariance matrices ---??????????????
+0091 %
+0092 %             z = [X;Y];
+0093 %             C = cov(z.');
+0094 %             sx = size(X,1);   %X??????(??),
+0095 %             sy = size(Y,1);
+0096 %             Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx);
+0097 %             Cxy = C(1:sx, sx+1:sx+sy);
+0098 %             Cyx = Cxy';
+0099 %             Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()????????
+0100 %             invCyy = inv(Cyy);
+0101 %
+0102 %             % --- Calcualte Wx and r ---
+0103 %
+0104 %             [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig????????????
+0105 %             r = sqrt(real(r));      % Canonical correlations
+0106 %
+0107 %             % --- Sort correlations ---
+0108 %
+0109 %             V = fliplr(Wx);        % reverse order of eigenvectors??????????????????????i??????????i??????
+0110 %             r = flipud(diag(r));    % extract eigenvalues and reverse their order
+0111 %             [r,I]= sort((real(r)));    % sort reversed eigenvalues in ascending order
+0112 %             r = flipud(r);        % restore sorted eigenvalues into descending order??????????????
+0113 %             for j = 1:length(I)
+0114 %                 Wx(:,j) = V(:,I(j));  % sort reversed eigenvectors in ascending order
+0115 %             end
+0116 %             Wx = fliplr(Wx);    % restore sorted eigenvectors into descending order
+0117 %
+0118 %             % --- Calcualte Wy  ---
+0119 %
+0120 %             Wy = invCyy*Cyx*Wx;     % Basis in Y
+0121 %             % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy
+0122 %
+0123 %         end
+0124         
+0125         function refSignal=ck_signalTrans(CCA,f,mLen,FreqSamp,NumHarm)
+0126             
+0127             p=mLen;%1250;
+0128             fs=FreqSamp;%250;
+0129             TP=1/fs:1/fs:p/fs;
+0130             for j=1:length(f)
+0131                 tempComp=[];
+0132                 for k=1:NumHarm
+0133                     Sinh1=sin(2*pi*k*f(j)*TP);
+0134                     Cosh1=cos(2*pi*k*f(j)*TP);
+0135                     tempComp = [tempComp; Sinh1;Cosh1;];
+0136                 end
+0137                 refSignal(:,:,j)=tempComp;
+0138             end
+0139         end
+0140         function time = getTime(CCA)
+0141             time = CCA.avgTime;
+0142         end
+0143     end
+0144     
+0145 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@CCA/CCA.m b/doc/+eegtoolkit/+featextraction/@CCA/CCA.m new file mode 100644 index 0000000..fae91b4 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/CCA.m @@ -0,0 +1,145 @@ +classdef CCA < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase + % + % works only on our datasets, for other datasets needs modifications + % + properties (Access = public) + channel; + avgTime; + stimulus_freqs; + FreqSamp; + NumHarm; + allFeatures; + end + methods (Access = public) + function CCA = CCA(sti_f,chans,fs,numH) + if ( nargin ~= 4 ) + error('It is needed to define the simulus freqs, the channels, frequency sampling and number of harmonics'); + else + CCA.stimulus_freqs = sti_f; + CCA.channel = chans; + CCA.FreqSamp = fs; + CCA.NumHarm = numH; + CCA.allFeatures = 0; + end + end + + function extract(CCA) + sti_f = CCA.stimulus_freqs; + mLen=size(CCA.trials{1}.signal,2); + refSignals=CCA.ck_signalTrans(sti_f,mLen,CCA.FreqSamp,CCA.NumHarm); + NumStim = size(refSignals,3); + numTrials = length(CCA.trials); + for i=1:numTrials + data = CCA.trials{i}.signal(CCA.channel,:); + if(CCA.allFeatures == 1) + features=NaN*ones(NumStim,min(rank(data),CCA.NumHarm*2)); + for j=1:NumStim + [wx1,wy1,r1] = canoncorr(data',refSignals(:,:,j)'); + features(j,:) = r1; + end + tempfeatures = features(1,:); + for j=2:NumStim + tempfeatures = horzcat(tempfeatures,features(j,:)); + end + instances(i,:) = tempfeatures(:); + labels(i,1) = floor(CCA.trials{i}.label); + else + features=NaN*ones(NumStim,1); + for j=1:NumStim + % [wx1,wy1,r1] = CCA.cca(data,refSignals(:,:,j)); + [wx1,wy1,r1] = canoncorr(data',refSignals(:,:,j)'); + features(j) = max(r1); + end + instances(i,:) = features(:); + labels(i,1) = floor(CCA.trials{i}.label); + end + end +% unique(labels) + if (sum(unique(labels)) == 41) + labels(labels==6)=1; + labels(labels==7)=2; + labels(labels==8)=3; + labels(labels==9)=4; + labels(labels==11)=5; + end +% unique(labels) + CCA.instanceSet = eegtoolkit.util.InstanceSet(instances, labels); + end + + function configInfo = getConfigInfo(CCA) + configInfo = sprintf('CCA'); + end + +% function [Wx, Wy, r] = cca(CCA,X,Y) +% +% % CCA calculate canonical correlations +% % +% % [Wx Wy r] = cca(X,Y) where Wx and Wy contains the canonical correlation +% +% % vectors as columns and r is a vector with corresponding canonical +% % correlations. The correlations are sorted in descending order. X and Y +% % are matrices where each column is a sample. Hence, X and Y must have +% % the same number of columns. +% % +% % Example: If X is M*K and Y is N*K there are L=MIN(M,N) solutions. Wx is +% % then M*L, Wy is N*L and r is L*1. +% % +% % +% % ?? 2000 Magnus Borga, Link?pings universitet +% +% % --- Calculate covariance matrices ---?????????????? +% +% z = [X;Y]; +% C = cov(z.'); +% sx = size(X,1); %X??????(??), +% sy = size(Y,1); +% Cxx = C(1:sx, 1:sx) + 10^(-8)*eye(sx); +% Cxy = C(1:sx, sx+1:sx+sy); +% Cyx = Cxy'; +% Cyy = C(sx+1:sx+sy, sx+1:sx+sy) + 10^(-8)*eye(sy);%eye()???????? +% invCyy = inv(Cyy); +% +% % --- Calcualte Wx and r --- +% +% [Wx,r] = eig(inv(Cxx)*Cxy*invCyy*Cyx); % Basis in X eig???????????? +% r = sqrt(real(r)); % Canonical correlations +% +% % --- Sort correlations --- +% +% V = fliplr(Wx); % reverse order of eigenvectors??????????????????????i??????????i?????? +% r = flipud(diag(r)); % extract eigenvalues and reverse their order +% [r,I]= sort((real(r))); % sort reversed eigenvalues in ascending order +% r = flipud(r); % restore sorted eigenvalues into descending order?????????????? +% for j = 1:length(I) +% Wx(:,j) = V(:,I(j)); % sort reversed eigenvectors in ascending order +% end +% Wx = fliplr(Wx); % restore sorted eigenvectors into descending order +% +% % --- Calcualte Wy --- +% +% Wy = invCyy*Cyx*Wx; % Basis in Y +% % Wy = Wy./repmat(sqrt(sum(abs(Wy).^2)),sy,1); % Normalize Wy +% +% end + + function refSignal=ck_signalTrans(CCA,f,mLen,FreqSamp,NumHarm) + + p=mLen;%1250; + fs=FreqSamp;%250; + TP=1/fs:1/fs:p/fs; + for j=1:length(f) + tempComp=[]; + for k=1:NumHarm + Sinh1=sin(2*pi*k*f(j)*TP); + Cosh1=cos(2*pi*k*f(j)*TP); + tempComp = [tempComp; Sinh1;Cosh1;]; + end + refSignal(:,:,j)=tempComp; + end + end + function time = getTime(CCA) + time = CCA.avgTime; + end + end + +end diff --git a/doc/+eegtoolkit/+featextraction/@CCA/graph.dot b/doc/+eegtoolkit/+featextraction/@CCA/graph.dot new file mode 100644 index 0000000..d44325c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + CCA -> CCA; + + CCA [URL="CCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@CCA/graph.html b/doc/+eegtoolkit/+featextraction/@CCA/graph.html new file mode 100644 index 0000000..0020769 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@CCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@CCA >
+

Dependency Graph for +eegtoolkit/+featextraction/@CCA

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@CCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@CCA/graph.map b/doc/+eegtoolkit/+featextraction/@CCA/graph.map new file mode 100644 index 0000000..e39843d --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@CCA/graph.png b/doc/+eegtoolkit/+featextraction/@CCA/graph.png new file mode 100644 index 0000000..c6b3372 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@CCA/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@CCA/index.html b/doc/+eegtoolkit/+featextraction/@CCA/index.html new file mode 100644 index 0000000..872a2ba --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@CCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@CCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@CCA >
+ +

Index for +eegtoolkit/+featextraction/@CCA

+ +

Matlab files in this directory:

+ +
 CCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@DWT/DWT.html b/doc/+eegtoolkit/+featextraction/@DWT/DWT.html new file mode 100644 index 0000000..77bcf6a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/DWT.html @@ -0,0 +1,171 @@ + + + + Description of DWT + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @DWT > DWT.m
+ + + +

DWT +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

DWT.m

+

SOURCE CODE ^

+
0001 classdef DWT < eegtoolkit.featextraction.FeatureExtractionBase
+0002     
+0003     properties (Access = public)
+0004         channel;
+0005         seconds;
+0006         levelWT;
+0007         WavFamily;
+0008         avgTime;
+0009     end
+0010     
+0011     methods (Access = public)
+0012         function mDWT = DWT(trials, seconds, channel,levWT,WavFam)
+0013             if nargin == 0
+0014                 mDWT.seconds = 0;
+0015                 mDWT.channel = 1;
+0016                 mDWT.levelWT = 5;
+0017                 mDWT.WavFamily = 'db1';
+0018             elseif nargin == 1
+0019                 mDWT.trials = trials;
+0020                 mDWT.seconds = 0;
+0021                 mDWT.channel = 1;
+0022                 mDWT.levelWT = 5;
+0023                 mDWT.WavFamily = 'db1';
+0024             elseif nargin == 2
+0025                 mDWT.trials = trials;
+0026                 mDWT.channel = 1;
+0027                 mDWT.seconds = seconds;
+0028                 mDWT.levelWT = 5;
+0029                 mDWT.WavFamily = 'db1';
+0030             elseif nargin == 3
+0031                 mDWT.trials = trials;
+0032                 mDWT.channel = channel;
+0033                 mDWT.seconds = seconds;
+0034                 mDWT.levelWT = 5;
+0035                 mDWT.WavFamily = 'db1';
+0036             elseif nargin == 4
+0037                 mDWT.trials = trials;
+0038                 mDWT.channel = channel;
+0039                 mDWT.seconds = seconds;
+0040                 mDWT.levelWT = levWT;
+0041                 mDWT.WavFamily = 'db1';
+0042             elseif nargin ==5
+0043                 mDWT.trials = trials;
+0044                 mDWT.channel = channel;
+0045                 mDWT.seconds = seconds;
+0046                 mDWT.levelWT = levWT;
+0047                 mDWT.WavFamily = WavFam;
+0048             else
+0049                 error('invalid number of arguments');
+0050             end
+0051             mDWT.avgTime = 0;
+0052         end
+0053         
+0054         function extract(mDWT)
+0055             if length(mDWT.seconds)==1
+0056                 numsamples = mDWT.trials{1}.samplingRate * mDWT.seconds;
+0057                 if (numsamples == 0)
+0058                     numsamples = size(mDWT.trials{1}.signal(mDWT.channel,:),2);
+0059                 end
+0060                 numTrials = length(mDWT.trials);
+0061                 
+0062                 [C L] = wavedec(mDWT.trials{1}.signal(mDWT.channel, 1:numsamples),mDWT.levelWT,mDWT.WavFamily);
+0063                 instances = zeros(numTrials, length(C));
+0064                 labels = zeros(numTrials,1);
+0065             elseif length(mDWT.seconds) == 2
+0066                 sampleA = mDWT.trials{1}.samplingRate * mDWT.seconds(1) + 1;
+0067                 sampleB = mDWT.trials{1}.samplingRate * mDWT.seconds(2);
+0068                 numTrials = length(mDWT.trials);
+0069                 [C L] = wavedec(mDWT.trials{1}.signal(mDWT.channel, sampleA:sampleB),mDWT.levelWT,mDWT.WavFamily);
+0070                 instances = zeros(numTrials, length(C));
+0071                 labels = zeros(numTrials,1);
+0072             else
+0073                 error('invalid seconds parameter');
+0074             end
+0075             tic
+0076             for i=1:numTrials
+0077                 if length(mDWT.seconds) == 1
+0078                     numsamples = mDWT.trials{i}.samplingRate * mDWT.seconds;
+0079                     if(numsamples == 0)
+0080                         y = mDWT.trials{i}.signal(mDWT.channel,:);
+0081                     else
+0082                         y = mDWT.trials{i}.signal(mDWT.channel, 1:numsamples);
+0083                     end
+0084                     % zero padding to nearest power of 2
+0085                     if isa(mDWT.filter,'dfilt.df2sos')
+0086                         y = filter(mDWT.filter,y);
+0087                     elseif isa(mDWT.filter,'dfilt.dffir')
+0088                         y = filtfilt(mDWT.filter.Numerator,1,y);
+0089                     end
+0090                     [C L] = wavedec(y,mDWT.levelWT,mDWT.WavFamily);%pwelch(y,[],[],512,mDWT.trials{i}.samplingRate,'onesided');
+0091                 elseif length(mDWT.seconds) == 2
+0092                     sampleA = mDWT.trials{i}.samplingRate * mDWT.seconds(1) + 1;
+0093                     sampleB = mDWT.trials{i}.samplingRate * mDWT.seconds(2);
+0094                     y = mDWT.trials{i}.signal(mDWT.channel,sampleA:sampleB);
+0095                     if isa(mDWT.filter,'dfilt.df2sos') || isa(mDWT.filter,'dfilt.df2')
+0096                         y = filter(mDWT.filter,y);
+0097                     elseif isa(mDWT.filter,'dfilt.dffir')
+0098                         y = filtfilt(mDWT.filter.Numerator,1,y);
+0099                     end
+0100                     [C L] = wavedec(y,mDWT.levelWT,mDWT.WavFamily);%pwelch(y,[],[],512,mDWT.trials{i}.samplingRate,'onesided');
+0101                 else
+0102                     error('invalid seconds parameter');
+0103                 end
+0104                 instances(i,:) = C;
+0105                 labels(i,1) = floor(mDWT.trials{i}.label);
+0106             end
+0107             mDWT.avgTime = toc/numTrials;
+0108             mDWT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0109         end
+0110         
+0111         function configInfo = getConfigInfo(mDWT)
+0112             configInfo = sprintf('DWT\tchannel:%d\tseconds:%d\tlevelWT:%d\tWavFamily:%s',mDWT.channel,mDWT.seconds,mDWT.levelWT,mDWT.WavFamily);
+0113         end
+0114         
+0115                         
+0116         function time = getTime(mDWT)
+0117             time = mDWT.avgTime;
+0118         end
+0119     end
+0120     
+0121 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@DWT/DWT.m b/doc/+eegtoolkit/+featextraction/@DWT/DWT.m new file mode 100644 index 0000000..6918d53 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/DWT.m @@ -0,0 +1,121 @@ +classdef DWT < eegtoolkit.featextraction.FeatureExtractionBase + + properties (Access = public) + channel; + seconds; + levelWT; + WavFamily; + avgTime; + end + + methods (Access = public) + function mDWT = DWT(trials, seconds, channel,levWT,WavFam) + if nargin == 0 + mDWT.seconds = 0; + mDWT.channel = 1; + mDWT.levelWT = 5; + mDWT.WavFamily = 'db1'; + elseif nargin == 1 + mDWT.trials = trials; + mDWT.seconds = 0; + mDWT.channel = 1; + mDWT.levelWT = 5; + mDWT.WavFamily = 'db1'; + elseif nargin == 2 + mDWT.trials = trials; + mDWT.channel = 1; + mDWT.seconds = seconds; + mDWT.levelWT = 5; + mDWT.WavFamily = 'db1'; + elseif nargin == 3 + mDWT.trials = trials; + mDWT.channel = channel; + mDWT.seconds = seconds; + mDWT.levelWT = 5; + mDWT.WavFamily = 'db1'; + elseif nargin == 4 + mDWT.trials = trials; + mDWT.channel = channel; + mDWT.seconds = seconds; + mDWT.levelWT = levWT; + mDWT.WavFamily = 'db1'; + elseif nargin ==5 + mDWT.trials = trials; + mDWT.channel = channel; + mDWT.seconds = seconds; + mDWT.levelWT = levWT; + mDWT.WavFamily = WavFam; + else + error('invalid number of arguments'); + end + mDWT.avgTime = 0; + end + + function extract(mDWT) + if length(mDWT.seconds)==1 + numsamples = mDWT.trials{1}.samplingRate * mDWT.seconds; + if (numsamples == 0) + numsamples = size(mDWT.trials{1}.signal(mDWT.channel,:),2); + end + numTrials = length(mDWT.trials); + + [C L] = wavedec(mDWT.trials{1}.signal(mDWT.channel, 1:numsamples),mDWT.levelWT,mDWT.WavFamily); + instances = zeros(numTrials, length(C)); + labels = zeros(numTrials,1); + elseif length(mDWT.seconds) == 2 + sampleA = mDWT.trials{1}.samplingRate * mDWT.seconds(1) + 1; + sampleB = mDWT.trials{1}.samplingRate * mDWT.seconds(2); + numTrials = length(mDWT.trials); + [C L] = wavedec(mDWT.trials{1}.signal(mDWT.channel, sampleA:sampleB),mDWT.levelWT,mDWT.WavFamily); + instances = zeros(numTrials, length(C)); + labels = zeros(numTrials,1); + else + error('invalid seconds parameter'); + end + tic + for i=1:numTrials + if length(mDWT.seconds) == 1 + numsamples = mDWT.trials{i}.samplingRate * mDWT.seconds; + if(numsamples == 0) + y = mDWT.trials{i}.signal(mDWT.channel,:); + else + y = mDWT.trials{i}.signal(mDWT.channel, 1:numsamples); + end + % zero padding to nearest power of 2 + if isa(mDWT.filter,'dfilt.df2sos') + y = filter(mDWT.filter,y); + elseif isa(mDWT.filter,'dfilt.dffir') + y = filtfilt(mDWT.filter.Numerator,1,y); + end + [C L] = wavedec(y,mDWT.levelWT,mDWT.WavFamily);%pwelch(y,[],[],512,mDWT.trials{i}.samplingRate,'onesided'); + elseif length(mDWT.seconds) == 2 + sampleA = mDWT.trials{i}.samplingRate * mDWT.seconds(1) + 1; + sampleB = mDWT.trials{i}.samplingRate * mDWT.seconds(2); + y = mDWT.trials{i}.signal(mDWT.channel,sampleA:sampleB); + if isa(mDWT.filter,'dfilt.df2sos') || isa(mDWT.filter,'dfilt.df2') + y = filter(mDWT.filter,y); + elseif isa(mDWT.filter,'dfilt.dffir') + y = filtfilt(mDWT.filter.Numerator,1,y); + end + [C L] = wavedec(y,mDWT.levelWT,mDWT.WavFamily);%pwelch(y,[],[],512,mDWT.trials{i}.samplingRate,'onesided'); + else + error('invalid seconds parameter'); + end + instances(i,:) = C; + labels(i,1) = floor(mDWT.trials{i}.label); + end + mDWT.avgTime = toc/numTrials; + mDWT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + + function configInfo = getConfigInfo(mDWT) + configInfo = sprintf('DWT\tchannel:%d\tseconds:%d\tlevelWT:%d\tWavFamily:%s',mDWT.channel,mDWT.seconds,mDWT.levelWT,mDWT.WavFamily); + end + + + function time = getTime(mDWT) + time = mDWT.avgTime; + end + end + +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@DWT/graph.dot b/doc/+eegtoolkit/+featextraction/@DWT/graph.dot new file mode 100644 index 0000000..f950fda --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + DWT -> DWT; + + DWT [URL="DWT.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@DWT/graph.html b/doc/+eegtoolkit/+featextraction/@DWT/graph.html new file mode 100644 index 0000000..fe7f7a6 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@DWT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@DWT >
+

Dependency Graph for +eegtoolkit/+featextraction/@DWT

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@DWT + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@DWT/graph.map b/doc/+eegtoolkit/+featextraction/@DWT/graph.map new file mode 100644 index 0000000..a91e458 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@DWT/graph.png b/doc/+eegtoolkit/+featextraction/@DWT/graph.png new file mode 100644 index 0000000..312c911 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@DWT/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@DWT/index.html b/doc/+eegtoolkit/+featextraction/@DWT/index.html new file mode 100644 index 0000000..d16fe35 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@DWT/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@DWT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@DWT >
+ +

Index for +eegtoolkit/+featextraction/@DWT

+ +

Matlab files in this directory:

+ +
 DWT
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.html b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.html new file mode 100644 index 0000000..8b43877 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.html @@ -0,0 +1,86 @@ + + + + Description of ERRPFeatures + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @ERRPFeatures > ERRPFeatures.m
+ + + +

ERRPFeatures +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ERRPFeatures.m

+

SOURCE CODE ^

+
0001 classdef ERRPFeatures < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase
+0002     properties (Access = public)
+0003         channel;
+0004         avgTime;
+0005 %         downSampleFactor;
+0006     end
+0007     methods (Access = public)
+0008         function ERRP = ERRPFeatures()
+0009 %             ERRP.downSampleFactor = 8;
+0010             ERRP.channel = 1;
+0011         end
+0012         
+0013         function extract(ERRP)
+0014             
+0015             numTrials = length(ERRP.trials);
+0016             [~,numSamples]  =  size(ERRP.trials{1}.signal(ERRP.channel,:));
+0017 %             numFeatures = floor(numSamples/ERRP.downSampleFactor);
+0018             instances = zeros(numTrials,numSamples);
+0019             labels = zeros(numTrials,1);
+0020             for i=1:numTrials
+0021                 instances(i,:) = ERRP.trials{i}.signal(ERRP.channel,:);
+0022                 labels(i) = ERRP.trials{i}.label;
+0023             end
+0024             ERRP.instanceSet = eegtoolkit.util.InstanceSet(instances, labels);
+0025         end
+0026         
+0027         function configInfo = getConfigInfo(ERRP)
+0028             configInfo = sprintf('ERRP features');
+0029         end
+0030         
+0031         function time = getTime(ERRP)
+0032             time = ERRP.avgTime;
+0033         end
+0034     end
+0035     
+0036 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.m b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.m new file mode 100644 index 0000000..11474dc --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/ERRPFeatures.m @@ -0,0 +1,36 @@ +classdef ERRPFeatures < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase + properties (Access = public) + channel; + avgTime; +% downSampleFactor; + end + methods (Access = public) + function ERRP = ERRPFeatures() +% ERRP.downSampleFactor = 8; + ERRP.channel = 1; + end + + function extract(ERRP) + + numTrials = length(ERRP.trials); + [~,numSamples] = size(ERRP.trials{1}.signal(ERRP.channel,:)); +% numFeatures = floor(numSamples/ERRP.downSampleFactor); + instances = zeros(numTrials,numSamples); + labels = zeros(numTrials,1); + for i=1:numTrials + instances(i,:) = ERRP.trials{i}.signal(ERRP.channel,:); + labels(i) = ERRP.trials{i}.label; + end + ERRP.instanceSet = eegtoolkit.util.InstanceSet(instances, labels); + end + + function configInfo = getConfigInfo(ERRP) + configInfo = sprintf('ERRP features'); + end + + function time = getTime(ERRP) + time = ERRP.avgTime; + end + end + +end diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.dot b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.dot new file mode 100644 index 0000000..1fef1ce --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ERRPFeatures -> ERRPFeatures; + + ERRPFeatures [URL="ERRPFeatures.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.html b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.html new file mode 100644 index 0000000..8da2cec --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@ERRPFeatures + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@ERRPFeatures >
+

Dependency Graph for +eegtoolkit/+featextraction/@ERRPFeatures

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@ERRPFeatures + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.map b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.map new file mode 100644 index 0000000..41fb9c2 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.png b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.png new file mode 100644 index 0000000..c8f00fc Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@ERRPFeatures/index.html b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/index.html new file mode 100644 index 0000000..6e0c501 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@ERRPFeatures/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@ERRPFeatures + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@ERRPFeatures >
+ +

Index for +eegtoolkit/+featextraction/@ERRPFeatures

+ +

Matlab files in this directory:

+ +
 ERRPFeatures
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FFT/FFT.html b/doc/+eegtoolkit/+featextraction/@FFT/FFT.html new file mode 100644 index 0000000..54c5b83 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/FFT.html @@ -0,0 +1,139 @@ + + + + Description of FFT + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @FFT > FFT.m
+ + + +

FFT +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FFT.m

+

SOURCE CODE ^

+
0001 classdef FFT < eegtoolkit.featextraction.FeatureExtractionBase
+0002     
+0003     properties (Access = public)
+0004         channel;
+0005         seconds;
+0006         nfft;
+0007         avgTime;
+0008     end
+0009     
+0010     methods (Access = public)
+0011         function mFFT = FFT(trials, seconds, channel,nfft)
+0012             if nargin == 0
+0013                 mFFT.seconds = 0;
+0014                 mFFT.channel = 1;
+0015                 mFFT.nfft = 512;
+0016             elseif nargin == 1
+0017                 mFFT.trials = trials;
+0018                 mFFT.seconds = 0;
+0019                 mFFT.channel = 1;
+0020                 mFFT.nfft = 512;
+0021             elseif nargin == 2
+0022                 mFFT.trials = trials;
+0023                 mFFT.channel = 1;
+0024                 mFFT.seconds = seconds;
+0025                 mFFT.nfft = 512;
+0026             elseif nargin == 3
+0027                 mFFT.trials = trials;
+0028                 mFFT.channel = channel;
+0029                 mFFT.seconds = seconds;
+0030                 mFFT.nfft = 512;
+0031             elseif nargin == 4
+0032                 mFFT.trials = trials;
+0033                 mFFT.channel = channel;
+0034                 mFFT.seconds = seconds;
+0035                 mFFT.nfft = nfft;
+0036                 error('invalid number of arguments');
+0037             end
+0038         end
+0039         
+0040         function extract(mFFT)
+0041             NUM_FEATURES = mFFT.nfft/2+1;
+0042             numTrials = length(mFFT.trials);
+0043             instances = zeros(numTrials, NUM_FEATURES);
+0044             labels = zeros(numTrials,1);
+0045             tic
+0046             for i=1:numTrials
+0047                 if length(mFFT.seconds) == 1
+0048                 numsamples = mFFT.trials{i}.samplingRate * mFFT.seconds;
+0049                 if(numsamples == 0)
+0050                     y = mFFT.trials{i}.signal(mFFT.channel,:);
+0051                 else
+0052                     y = mFFT.trials{i}.signal(mFFT.channel, 1:numsamples);
+0053                 end
+0054                 elseif length(mFFT.seconds) == 2
+0055                     sampleA = mFFT.trials{i}.samplingRate * mFFT.seconds(1) + 1;
+0056                     sampleB = mFFT.trials{i}.samplingRate * mFFT.seconds(2);
+0057                     y = mFFT.trials{i}.signal(mFFT.channel, sampleA:sampleB);
+0058                 else
+0059                     
+0060                     error ('invalid seconds parameter');
+0061                 end
+0062                 if isa(mFFT.filter,'dfilt.df2sos') || isa(mFFT.filter,'dfilt.df2')
+0063                     y = filter(mFFT.filter,y);
+0064                 elseif isa(mFFT.filter,'dfilt.dffir')
+0065                     y = filtfilt(mFFT.filter.Numerator,1,y);
+0066                 end
+0067                 %Y = fft(y,(NUM_FEATURES-1)*2)/((NUM_FEATURES-1)*2);
+0068                 %f = Fs/2*linspace(0,1,NFFT/2+1);
+0069                 %pyy = abs(Y(1:(NUM_FEATURES-1)*2/2+1)).^2;
+0070                 [pyy,f] = periodogram(y,[],mFFT.nfft,mFFT.trials{i}.samplingRate);
+0071                 instances(i,:) = pyy;
+0072                 labels(i,1) = floor(mFFT.trials{i}.label);
+0073             end
+0074             mFFT.avgTime = toc/numTrials;
+0075             mFFT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0076         end
+0077         
+0078         function configInfo = getConfigInfo(mFFT)
+0079             configInfo = sprintf('FFT\tchannel:%d\tseconds:%d\tnfft:%d',mFFT.channel,mFFT.seconds,mFFT.nfft);
+0080         end
+0081         
+0082                         
+0083         function time = getTime(mFFT)
+0084             time = mFFT.avgTime;
+0085         end
+0086     end
+0087    
+0088 end
+0089
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FFT/FFT.m b/doc/+eegtoolkit/+featextraction/@FFT/FFT.m new file mode 100644 index 0000000..f0f986f --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/FFT.m @@ -0,0 +1,89 @@ +classdef FFT < eegtoolkit.featextraction.FeatureExtractionBase + + properties (Access = public) + channel; + seconds; + nfft; + avgTime; + end + + methods (Access = public) + function mFFT = FFT(trials, seconds, channel,nfft) + if nargin == 0 + mFFT.seconds = 0; + mFFT.channel = 1; + mFFT.nfft = 512; + elseif nargin == 1 + mFFT.trials = trials; + mFFT.seconds = 0; + mFFT.channel = 1; + mFFT.nfft = 512; + elseif nargin == 2 + mFFT.trials = trials; + mFFT.channel = 1; + mFFT.seconds = seconds; + mFFT.nfft = 512; + elseif nargin == 3 + mFFT.trials = trials; + mFFT.channel = channel; + mFFT.seconds = seconds; + mFFT.nfft = 512; + elseif nargin == 4 + mFFT.trials = trials; + mFFT.channel = channel; + mFFT.seconds = seconds; + mFFT.nfft = nfft; + error('invalid number of arguments'); + end + end + + function extract(mFFT) + NUM_FEATURES = mFFT.nfft/2+1; + numTrials = length(mFFT.trials); + instances = zeros(numTrials, NUM_FEATURES); + labels = zeros(numTrials,1); + tic + for i=1:numTrials + if length(mFFT.seconds) == 1 + numsamples = mFFT.trials{i}.samplingRate * mFFT.seconds; + if(numsamples == 0) + y = mFFT.trials{i}.signal(mFFT.channel,:); + else + y = mFFT.trials{i}.signal(mFFT.channel, 1:numsamples); + end + elseif length(mFFT.seconds) == 2 + sampleA = mFFT.trials{i}.samplingRate * mFFT.seconds(1) + 1; + sampleB = mFFT.trials{i}.samplingRate * mFFT.seconds(2); + y = mFFT.trials{i}.signal(mFFT.channel, sampleA:sampleB); + else + + error ('invalid seconds parameter'); + end + if isa(mFFT.filter,'dfilt.df2sos') || isa(mFFT.filter,'dfilt.df2') + y = filter(mFFT.filter,y); + elseif isa(mFFT.filter,'dfilt.dffir') + y = filtfilt(mFFT.filter.Numerator,1,y); + end + %Y = fft(y,(NUM_FEATURES-1)*2)/((NUM_FEATURES-1)*2); + %f = Fs/2*linspace(0,1,NFFT/2+1); + %pyy = abs(Y(1:(NUM_FEATURES-1)*2/2+1)).^2; + [pyy,f] = periodogram(y,[],mFFT.nfft,mFFT.trials{i}.samplingRate); + instances(i,:) = pyy; + labels(i,1) = floor(mFFT.trials{i}.label); + end + mFFT.avgTime = toc/numTrials; + mFFT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + + function configInfo = getConfigInfo(mFFT) + configInfo = sprintf('FFT\tchannel:%d\tseconds:%d\tnfft:%d',mFFT.channel,mFFT.seconds,mFFT.nfft); + end + + + function time = getTime(mFFT) + time = mFFT.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@FFT/graph.dot b/doc/+eegtoolkit/+featextraction/@FFT/graph.dot new file mode 100644 index 0000000..8f0dec4 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FFT -> FFT; + + FFT [URL="FFT.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FFT/graph.html b/doc/+eegtoolkit/+featextraction/@FFT/graph.html new file mode 100644 index 0000000..94af0a7 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@FFT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@FFT >
+

Dependency Graph for +eegtoolkit/+featextraction/@FFT

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@FFT + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FFT/graph.map b/doc/+eegtoolkit/+featextraction/@FFT/graph.map new file mode 100644 index 0000000..a5a5801 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@FFT/graph.png b/doc/+eegtoolkit/+featextraction/@FFT/graph.png new file mode 100644 index 0000000..7c701ee Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@FFT/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@FFT/index.html b/doc/+eegtoolkit/+featextraction/@FFT/index.html new file mode 100644 index 0000000..6468ef3 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FFT/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@FFT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@FFT >
+ +

Index for +eegtoolkit/+featextraction/@FFT

+ +

Matlab files in this directory:

+ +
 FFT
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.html b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.html new file mode 100644 index 0000000..e201f3c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.html @@ -0,0 +1,132 @@ + + + + Description of FeatureExtractionBase + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @FeatureExtractionBase > FeatureExtractionBase.m
+ + + +

FeatureExtractionBase +

+ +

PURPOSE ^

+
Abstract class for feature extraction. Implement the functions for any
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Abstract class for feature extraction. Implement the functions for any
+ feature extractor (e.g. PWelch, FFT, DWT, PYAR, etc.)
+ 
+ Properties:
+ instanceSet: Output - the features in an InstanceSet structure
+ trials: Input - the signals in a cell of Trial structures
+ 
+ Functions:
+Implement this function to extract the features from the input Trials 
+and return the features in an instanceSet
+   out = obj.extract(in);
+Info & run time so that the experiments are easily documented. configInfo
+is a string with the configuration information and time is of type double.
+   configInfo = obj.getConfigInfo();
+   time = obj.getTime();
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FeatureExtractionBase.m

+

SOURCE CODE ^

+
0001 % Abstract class for feature extraction. Implement the functions for any
+0002 % feature extractor (e.g. PWelch, FFT, DWT, PYAR, etc.)
+0003 %
+0004 % Properties:
+0005 % instanceSet: Output - the features in an InstanceSet structure
+0006 % trials: Input - the signals in a cell of Trial structures
+0007 %
+0008 % Functions:
+0009 %Implement this function to extract the features from the input Trials
+0010 %and return the features in an instanceSet
+0011 %   out = obj.extract(in);
+0012 %Info & run time so that the experiments are easily documented. configInfo
+0013 %is a string with the configuration information and time is of type double.
+0014 %   configInfo = obj.getConfigInfo();
+0015 %   time = obj.getTime();
+0016 
+0017 
+0018 classdef (Abstract) FeatureExtractionBase < handle
+0019     %Base class for a feature transformer
+0020     %For writing your own FeatureTransformer extend this class and
+0021     %implement the 'transform' function
+0022     properties (Access = public)
+0023         instanceSet; % Output: The dataset
+0024         trials;% Input: The trial signals
+0025         filter;
+0026     end
+0027     
+0028     methods (Abstract = true)
+0029         obj = extract(obj);
+0030         configInfo = getConfigInfo(obj);
+0031         time = getTime(obj);
+0032     end
+0033     
+0034     methods (Access = public)
+0035         function instances = getInstances(obj)
+0036             %Get the instances (no class labels)
+0037             instances = obj.instanceSet.getInstances;
+0038         end
+0039         function labels = getLabels(obj)
+0040             %Get the labels
+0041             labels = obj.instanceSet.getLabels;
+0042         end
+0043         
+0044         function dataset = getDataset(obj)
+0045             % same with getInstances but includes the labels as the last
+0046             % row
+0047             dataset = obj.instanceSet.getDataset;
+0048         end
+0049         
+0050         function instanceSet = getInstanceSet(obj)
+0051             % Get the dataset as an 'InstanceSet' class object
+0052             instanceSet = obj.instanceSet;
+0053         end
+0054         function writeCSV(obj, csvname)
+0055             % write the dataset to a csv file
+0056             % Example:
+0057             %   obj.writeCSV('data.csv');
+0058             obj.instanceSet.writeCSV(csvname);
+0059         end
+0060         function writeArff(obj, fname)
+0061             % write the dataset to a weka-readable file (arff)
+0062             % Caution: filename without extension
+0063             % Example:
+0064             %   obj.writeArff('data')
+0065             obj.instanceSet.writeArff(fname);
+0066         end
+0067     end
+0068 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m new file mode 100644 index 0000000..647966b --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/FeatureExtractionBase.m @@ -0,0 +1,68 @@ +% Abstract class for feature extraction. Implement the functions for any +% feature extractor (e.g. PWelch, FFT, DWT, PYAR, etc.) +% +% Properties: +% instanceSet: Output - the features in an InstanceSet structure +% trials: Input - the signals in a cell of Trial structures +% +% Functions: +%Implement this function to extract the features from the input Trials +%and return the features in an instanceSet +% out = obj.extract(in); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + + +classdef (Abstract) FeatureExtractionBase < handle + %Base class for a feature transformer + %For writing your own FeatureTransformer extend this class and + %implement the 'transform' function + properties (Access = public) + instanceSet; % Output: The dataset + trials;% Input: The trial signals + filter; + end + + methods (Abstract = true) + obj = extract(obj); + configInfo = getConfigInfo(obj); + time = getTime(obj); + end + + methods (Access = public) + function instances = getInstances(obj) + %Get the instances (no class labels) + instances = obj.instanceSet.getInstances; + end + function labels = getLabels(obj) + %Get the labels + labels = obj.instanceSet.getLabels; + end + + function dataset = getDataset(obj) + % same with getInstances but includes the labels as the last + % row + dataset = obj.instanceSet.getDataset; + end + + function instanceSet = getInstanceSet(obj) + % Get the dataset as an 'InstanceSet' class object + instanceSet = obj.instanceSet; + end + function writeCSV(obj, csvname) + % write the dataset to a csv file + % Example: + % obj.writeCSV('data.csv'); + obj.instanceSet.writeCSV(csvname); + end + function writeArff(obj, fname) + % write the dataset to a weka-readable file (arff) + % Caution: filename without extension + % Example: + % obj.writeArff('data') + obj.instanceSet.writeArff(fname); + end + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.dot b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.dot new file mode 100644 index 0000000..699ad24 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FeatureExtractionBase -> FeatureExtractionBase; + + FeatureExtractionBase [URL="FeatureExtractionBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.html b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.html new file mode 100644 index 0000000..da06c80 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@FeatureExtractionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@FeatureExtractionBase >
+

Dependency Graph for +eegtoolkit/+featextraction/@FeatureExtractionBase

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@FeatureExtractionBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.map b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.map new file mode 100644 index 0000000..374407a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.png b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.png new file mode 100644 index 0000000..c008c8b Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/index.html b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/index.html new file mode 100644 index 0000000..58a591b --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@FeatureExtractionBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@FeatureExtractionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@FeatureExtractionBase >
+ +

Index for +eegtoolkit/+featextraction/@FeatureExtractionBase

+ +

Matlab files in this directory:

+ +
 FeatureExtractionBaseAbstract class for feature extraction. Implement the functions for any
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.html b/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.html new file mode 100644 index 0000000..7fd3955 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.html @@ -0,0 +1,150 @@ + + + + Description of Goertzel + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @Goertzel > Goertzel.m
+ + + +

Goertzel +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Goertzel.m

+

SOURCE CODE ^

+
0001 classdef Goertzel < eegtoolkit.featextraction.FeatureExtractionBase
+0002 %Computes the psd using the welch method
+0003 %Usage:
+0004 %   session = eegtoolkit.util.Session();
+0005 %   session.loadSubject(1);
+0006 %   pwt = ssveptolkit.transform.PWelchTransformer(session.trials);
+0007 %Specify the channel to be used (default = 126)
+0008 %   pwt.channel = 150;
+0009 %Specify the number of seconds to be used (default = 0, use all signal)
+0010 %   pwt.seconds = 3;
+0011 %Specify the nfft parameter (default = 512, computes 257 features)
+0012 %   pwt.nfft = 512;
+0013 %Transform the signal
+0014 %   pwt.transform();
+0015     properties (Access = public)
+0016         channel;
+0017         seconds;
+0018         nfft;
+0019         pff;
+0020         avgTime;
+0021     end
+0022     
+0023     methods (Access = public)
+0024         function GT = Goertzel(trials, seconds, channel, nfft)
+0025 %             if ~iscell(trials)
+0026 %                 error('trials must be cell array of Trial object');
+0027 %             end
+0028             if nargin == 0
+0029                 GT.trials = {};
+0030                 GT.seconds = 0;
+0031                 GT.channel = 1;
+0032                 GT.nfft = 512;
+0033             elseif nargin == 1
+0034                 GT.trials = trials;
+0035                 GT.seconds = 0;
+0036                 GT.channel = 1;
+0037                 GT.nfft = 512;
+0038             elseif nargin == 2
+0039                 GT.trials = trials;
+0040                 GT.channel = 1;
+0041                 GT.seconds = seconds;
+0042                 GT.nfft = 512;
+0043             elseif nargin == 3
+0044                 GT.trials = trials;
+0045                 GT.channel = channel;
+0046                 GT.seconds = seconds;
+0047                 GT.nfft = 512;
+0048             elseif nargin == 4
+0049                 GT.trials = trials;
+0050                 GT.channel = channel;
+0051                 GT.seconds = seconds;
+0052                 GT.nfft = nfft;
+0053             else
+0054 %                 error('invalid number of arguments');
+0055             end
+0056         end
+0057         
+0058         function extract(GT)
+0059            
+0060             numFeatures = length(GT.nfft);
+0061             numTrials = length(GT.trials);
+0062             instances = zeros(numTrials, numFeatures);
+0063             labels = zeros(numTrials,1);
+0064 %             PWT.instances = zeros(numTrials, numFeatures);
+0065 %             PWT.labels = zeros(numTrials,1);
+0066             tic;
+0067             for i=1:numTrials
+0068                 numsamples = GT.trials{i}.samplingRate * GT.seconds;
+0069                 if(numsamples == 0)
+0070                     y = GT.trials{i}.signal(GT.channel,:);
+0071                 else
+0072                     y = GT.trials{i}.signal(GT.channel, 1:numsamples);
+0073                 end
+0074 %                 N = (length(y)+1)/2;
+0075 %                 f = (PWT.trials{i}.samplingRate/2)/N*(0:N-1);
+0076 %                 indxs = find(f>1.2e3 & f<1.3e3);
+0077 %                 X = goertzel(x,indxs);
+0078                 freq_indices = round(GT.nfft/GT.trials{i}.samplingRate*length(y)) + 1;
+0079 %                 ff = [0:1/512:1/2]*250;
+0080 %                 freq_indices = round(ff/PWT.trials{i}.samplingRate*length(y))+1
+0081                 dft_data = goertzel(y,freq_indices);%goertzel(y,freq_indices); general_shortened
+0082                 instances(i,:) = abs(dft_data) ./ length(y);
+0083                 labels(i,1) = floor(GT.trials{i}.label);
+0084             end
+0085             GT.avgTime = toc/numTrials;
+0086             GT.instanceSet = eegtoolkit.util.InstanceSet(instances, labels);
+0087             GT.pff = GT.nfft;
+0088         end
+0089         
+0090         function configInfo = getConfigInfo(GT)
+0091             configInfo = sprintf('Goertzel\tchannel:%d\tseconds:%d\tfreq range:%.3f to %.3f',GT.channel,GT.seconds,GT.nfft(1),GT.nfft(end));
+0092         end
+0093         
+0094         function time = getTime(GT)
+0095             time = GT.avgTime;
+0096         end
+0097     end
+0098    
+0099 end
+0100
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.m b/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.m new file mode 100644 index 0000000..09e61a4 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/Goertzel.m @@ -0,0 +1,100 @@ +classdef Goertzel < eegtoolkit.featextraction.FeatureExtractionBase +%Computes the psd using the welch method +%Usage: +% session = eegtoolkit.util.Session(); +% session.loadSubject(1); +% pwt = ssveptolkit.transform.PWelchTransformer(session.trials); +%Specify the channel to be used (default = 126) +% pwt.channel = 150; +%Specify the number of seconds to be used (default = 0, use all signal) +% pwt.seconds = 3; +%Specify the nfft parameter (default = 512, computes 257 features) +% pwt.nfft = 512; +%Transform the signal +% pwt.transform(); + properties (Access = public) + channel; + seconds; + nfft; + pff; + avgTime; + end + + methods (Access = public) + function GT = Goertzel(trials, seconds, channel, nfft) +% if ~iscell(trials) +% error('trials must be cell array of Trial object'); +% end + if nargin == 0 + GT.trials = {}; + GT.seconds = 0; + GT.channel = 1; + GT.nfft = 512; + elseif nargin == 1 + GT.trials = trials; + GT.seconds = 0; + GT.channel = 1; + GT.nfft = 512; + elseif nargin == 2 + GT.trials = trials; + GT.channel = 1; + GT.seconds = seconds; + GT.nfft = 512; + elseif nargin == 3 + GT.trials = trials; + GT.channel = channel; + GT.seconds = seconds; + GT.nfft = 512; + elseif nargin == 4 + GT.trials = trials; + GT.channel = channel; + GT.seconds = seconds; + GT.nfft = nfft; + else +% error('invalid number of arguments'); + end + end + + function extract(GT) + + numFeatures = length(GT.nfft); + numTrials = length(GT.trials); + instances = zeros(numTrials, numFeatures); + labels = zeros(numTrials,1); +% PWT.instances = zeros(numTrials, numFeatures); +% PWT.labels = zeros(numTrials,1); + tic; + for i=1:numTrials + numsamples = GT.trials{i}.samplingRate * GT.seconds; + if(numsamples == 0) + y = GT.trials{i}.signal(GT.channel,:); + else + y = GT.trials{i}.signal(GT.channel, 1:numsamples); + end +% N = (length(y)+1)/2; +% f = (PWT.trials{i}.samplingRate/2)/N*(0:N-1); +% indxs = find(f>1.2e3 & f<1.3e3); +% X = goertzel(x,indxs); + freq_indices = round(GT.nfft/GT.trials{i}.samplingRate*length(y)) + 1; +% ff = [0:1/512:1/2]*250; +% freq_indices = round(ff/PWT.trials{i}.samplingRate*length(y))+1 + dft_data = goertzel(y,freq_indices);%goertzel(y,freq_indices); general_shortened + instances(i,:) = abs(dft_data) ./ length(y); + labels(i,1) = floor(GT.trials{i}.label); + end + GT.avgTime = toc/numTrials; + GT.instanceSet = eegtoolkit.util.InstanceSet(instances, labels); + GT.pff = GT.nfft; + end + + function configInfo = getConfigInfo(GT) + configInfo = sprintf('Goertzel\tchannel:%d\tseconds:%d\tfreq range:%.3f to %.3f',GT.channel,GT.seconds,GT.nfft(1),GT.nfft(end)); + end + + function time = getTime(GT) + time = GT.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/graph.dot b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.dot new file mode 100644 index 0000000..6759e88 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Goertzel -> Goertzel; + + Goertzel [URL="Goertzel.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/graph.html b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.html new file mode 100644 index 0000000..d9b8e05 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@Goertzel + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@Goertzel >
+

Dependency Graph for +eegtoolkit/+featextraction/@Goertzel

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@Goertzel + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/graph.map b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.map new file mode 100644 index 0000000..c134b8a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/graph.png b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.png new file mode 100644 index 0000000..481b76b Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@Goertzel/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@Goertzel/index.html b/doc/+eegtoolkit/+featextraction/@Goertzel/index.html new file mode 100644 index 0000000..44af831 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@Goertzel/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@Goertzel + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@Goertzel >
+ +

Index for +eegtoolkit/+featextraction/@Goertzel

+ +

Matlab files in this directory:

+ +
 Goertzel
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.html b/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.html new file mode 100644 index 0000000..658af42 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.html @@ -0,0 +1,77 @@ + + + + Description of L1MCCA + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @L1MCCA > L1MCCA.m
+ + + +

L1MCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

L1MCCA.m

+

SOURCE CODE ^

+
0001 classdef L1MCCA < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase
+0002     %
+0003     % works only on our datasets, for other datasets needs modifications
+0004     %
+0005     properties (Access = public)
+0006         channel;
+0007         avgTime;
+0008         stimulus_freqs;
+0009         FreqSamp;
+0010         NumHarm;
+0011     end
+0012     methods (Access = public)
+0013         function L1MCCA = L1MCCA()
+0014         end
+0015         
+0016         function extract(L1MCCA)
+0017             L1MCCA.instanceSet = eegtoolkit.util.L1MCCAInstanceSet(L1MCCA.trials);
+0018         end
+0019         
+0020         function configInfo = getConfigInfo(L1MCCA)
+0021             configInfo = sprintf('L1MCCA');
+0022         end
+0023         function time = getTime(L1MCCA)
+0024             time = 0;
+0025         end
+0026     end
+0027 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.m b/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.m new file mode 100644 index 0000000..ed3a795 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/L1MCCA.m @@ -0,0 +1,27 @@ +classdef L1MCCA < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase + % + % works only on our datasets, for other datasets needs modifications + % + properties (Access = public) + channel; + avgTime; + stimulus_freqs; + FreqSamp; + NumHarm; + end + methods (Access = public) + function L1MCCA = L1MCCA() + end + + function extract(L1MCCA) + L1MCCA.instanceSet = eegtoolkit.util.L1MCCAInstanceSet(L1MCCA.trials); + end + + function configInfo = getConfigInfo(L1MCCA) + configInfo = sprintf('L1MCCA'); + end + function time = getTime(L1MCCA) + time = 0; + end + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.dot b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.dot new file mode 100644 index 0000000..5dff22f --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + L1MCCA -> L1MCCA; + + L1MCCA [URL="L1MCCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.html b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.html new file mode 100644 index 0000000..e98399a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@L1MCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@L1MCCA >
+

Dependency Graph for +eegtoolkit/+featextraction/@L1MCCA

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@L1MCCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.map b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.map new file mode 100644 index 0000000..55100c7 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.png b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.png new file mode 100644 index 0000000..99fba29 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@L1MCCA/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@L1MCCA/index.html b/doc/+eegtoolkit/+featextraction/@L1MCCA/index.html new file mode 100644 index 0000000..5812eb8 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@L1MCCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@L1MCCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@L1MCCA >
+ +

Index for +eegtoolkit/+featextraction/@L1MCCA

+ +

Matlab files in this directory:

+ +
 L1MCCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.html b/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.html new file mode 100644 index 0000000..045785d --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.html @@ -0,0 +1,114 @@ + + + + Description of MLR_Transf + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @MLR_Transf > MLR_Transf.m
+ + + +

MLR_Transf +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

MLR_Transf.m

+

SOURCE CODE ^

+
0001 classdef MLR_Transf < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase
+0002     %Computes the psd using the welch method
+0003     %Usage:
+0004     %   session = eegtoolkit.util.Session();
+0005     %   session.loadSubject(1);
+0006     %   pwt = ssveptolkit.transform.PWelchTransformer(session.trials);
+0007     %Specify the channel to be used (default = 126)
+0008     %   pwt.channel = 150;
+0009     %Specify the number of seconds to be used (default = 0, use all signal)
+0010     %   pwt.seconds = 3;
+0011     %Specify the nfft parameter (default = 512, computes 257 features)
+0012     %   pwt.nfft = 512;
+0013     %Transform the signal
+0014     %   pwt.transform();
+0015     properties (Access = public)
+0016         channel;
+0017         avgTime;
+0018     end
+0019     methods (Access = public)
+0020         function PWT = MLR_Transf(chns)
+0021             if nargin == 1
+0022                 PWT.trials = {};
+0023                 PWT.channel = [1:length(chns)];
+0024             else
+0025                 error('invalid number of arguments');
+0026             end
+0027         end
+0028         
+0029         function extract(PWT)
+0030             
+0031             numTrials = length(PWT.trials);
+0032             [m n]=size(PWT.trials{1}.signal(PWT.channel,:));
+0033             data = zeros(m,n,numTrials);
+0034             labels = zeros(numTrials,1);
+0035             
+0036             for i = 1 : numTrials   %
+0037                 for j=1:m
+0038                     data(j,:,i) = PWT.trials{i}.signal(j,:);%data(j,:,i)./norm(data(j,:,i));
+0039                     data(j,:,i) = (data(j,:,i) - mean(data(j,:,i)))./std(data(j,:,i));
+0040 %                     data(j,:,i) = data(j,:,i)./norm(data(j,:,i));
+0041                 end%
+0042                 labels(i) = floor(PWT.trials{i}.label);
+0043             end
+0044             %data= reshape(data,m*n,size(data,3));
+0045             for i=1:numTrials
+0046                 newData(i,:) = [data(1,:,i) data(2,:,i)];
+0047             end
+0048             %             MeanTrainData=mean(data,2);
+0049             %             data=data-repmat(MeanTrainData,1,numTrials);
+0050             data = newData;
+0051             PWT.instanceSet = eegtoolkit.util.InstanceSet(data, labels);
+0052         end
+0053         
+0054         function configInfo = getConfigInfo(PWT)
+0055             configInfo = sprintf('MLR_Transf_rawdata');
+0056         end
+0057         
+0058         function time = getTime(PWT)
+0059             time = PWT.avgTime;
+0060         end
+0061     end
+0062     
+0063 end
+0064
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.m b/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.m new file mode 100644 index 0000000..4c1c6e5 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/MLR_Transf.m @@ -0,0 +1,64 @@ +classdef MLR_Transf < eegtoolkit.featextraction.PSDExtractionBase%FeatureExtractionBase + %Computes the psd using the welch method + %Usage: + % session = eegtoolkit.util.Session(); + % session.loadSubject(1); + % pwt = ssveptolkit.transform.PWelchTransformer(session.trials); + %Specify the channel to be used (default = 126) + % pwt.channel = 150; + %Specify the number of seconds to be used (default = 0, use all signal) + % pwt.seconds = 3; + %Specify the nfft parameter (default = 512, computes 257 features) + % pwt.nfft = 512; + %Transform the signal + % pwt.transform(); + properties (Access = public) + channel; + avgTime; + end + methods (Access = public) + function PWT = MLR_Transf(chns) + if nargin == 1 + PWT.trials = {}; + PWT.channel = [1:length(chns)]; + else + error('invalid number of arguments'); + end + end + + function extract(PWT) + + numTrials = length(PWT.trials); + [m n]=size(PWT.trials{1}.signal(PWT.channel,:)); + data = zeros(m,n,numTrials); + labels = zeros(numTrials,1); + + for i = 1 : numTrials % + for j=1:m + data(j,:,i) = PWT.trials{i}.signal(j,:);%data(j,:,i)./norm(data(j,:,i)); + data(j,:,i) = (data(j,:,i) - mean(data(j,:,i)))./std(data(j,:,i)); +% data(j,:,i) = data(j,:,i)./norm(data(j,:,i)); + end% + labels(i) = floor(PWT.trials{i}.label); + end + %data= reshape(data,m*n,size(data,3)); + for i=1:numTrials + newData(i,:) = [data(1,:,i) data(2,:,i)]; + end + % MeanTrainData=mean(data,2); + % data=data-repmat(MeanTrainData,1,numTrials); + data = newData; + PWT.instanceSet = eegtoolkit.util.InstanceSet(data, labels); + end + + function configInfo = getConfigInfo(PWT) + configInfo = sprintf('MLR_Transf_rawdata'); + end + + function time = getTime(PWT) + time = PWT.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.dot b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.dot new file mode 100644 index 0000000..3031a6a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + MLR_Transf -> MLR_Transf; + + MLR_Transf [URL="MLR_Transf.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.html b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.html new file mode 100644 index 0000000..e6a0e5e --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@MLR_Transf + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@MLR_Transf >
+

Dependency Graph for +eegtoolkit/+featextraction/@MLR_Transf

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@MLR_Transf + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.map b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.map new file mode 100644 index 0000000..e86c677 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.png b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.png new file mode 100644 index 0000000..1598e22 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@MLR_Transf/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@MLR_Transf/index.html b/doc/+eegtoolkit/+featextraction/@MLR_Transf/index.html new file mode 100644 index 0000000..5160b57 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@MLR_Transf/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@MLR_Transf + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@MLR_Transf >
+ +

Index for +eegtoolkit/+featextraction/@MLR_Transf

+ +

Matlab files in this directory:

+ +
 MLR_Transf
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.html b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.html new file mode 100644 index 0000000..431deaa --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.html @@ -0,0 +1,55 @@ + + + + Description of PSDExtractionBase + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @PSDExtractionBase > PSDExtractionBase.m
+ + + +

PSDExtractionBase +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + + +

DOWNLOAD ^

+

PSDExtractionBase.m

+

SOURCE CODE ^

+
0001 classdef (Abstract) PSDExtractionBase < eegtoolkit.featextraction.FeatureExtractionBase
+0002     %Base class for a feature transformer based on power spectral density
+0003     %estimates
+0004     properties (Access = public)
+0005         pff; % The frequencies of the spectrum
+0006     end
+0007 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.m b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.m new file mode 100644 index 0000000..d2a71a7 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/PSDExtractionBase.m @@ -0,0 +1,7 @@ +classdef (Abstract) PSDExtractionBase < eegtoolkit.featextraction.FeatureExtractionBase + %Base class for a feature transformer based on power spectral density + %estimates + properties (Access = public) + pff; % The frequencies of the spectrum + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.dot b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.dot new file mode 100644 index 0000000..246d58e --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PSDExtractionBase -> PSDExtractionBase; + + PSDExtractionBase [URL="PSDExtractionBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.html b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.html new file mode 100644 index 0000000..75ab7a3 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@PSDExtractionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PSDExtractionBase >
+

Dependency Graph for +eegtoolkit/+featextraction/@PSDExtractionBase

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@PSDExtractionBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.map b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.map new file mode 100644 index 0000000..5c6e47e --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.png b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.png new file mode 100644 index 0000000..674167e Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/index.html b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/index.html new file mode 100644 index 0000000..1a77a17 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PSDExtractionBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@PSDExtractionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PSDExtractionBase >
+ +

Index for +eegtoolkit/+featextraction/@PSDExtractionBase

+ +

Matlab files in this directory:

+ +
 PSDExtractionBase
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.html b/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.html new file mode 100644 index 0000000..fe70e42 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.html @@ -0,0 +1,167 @@ + + + + Description of PWelch + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @PWelch > PWelch.m
+ + + +

PWelch +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

PWelch.m

+

SOURCE CODE ^

+
0001 classdef PWelch < eegtoolkit.featextraction.PSDExtractionBase
+0002 %Computes the psd using the welch method
+0003 %Usage:
+0004 %   session = eegtoolkit.util.Session();
+0005 %   session.loadSubject(1);
+0006 %   pwt = ssveptolkit.transform.PWelchTransformer(session.trials);
+0007 %Specify the channel to be used (default = 126)
+0008 %   pwt.channel = 150;
+0009 %Specify the number of seconds to be used (default = 0, use all signal)
+0010 %   pwt.seconds = 3;
+0011 %Specify the nfft parameter (default = 512, computes 257 features)
+0012 %   pwt.nfft = 512;
+0013 %Transform the signal
+0014 %   pwt.transform();
+0015     properties (Access = public)
+0016         channel;
+0017         seconds;
+0018         nfft;
+0019         avgTime;
+0020     end
+0021     
+0022     methods (Access = public)
+0023         function PW = PWelch(trials, seconds, channel, nfft)
+0024 %             if ~iscell(trials)
+0025 %                 error('trials must be cell array of Trial object');
+0026 %             end
+0027             if nargin == 0
+0028                 PW.trials = {};
+0029                 PW.seconds = 0;
+0030                 PW.channel = 1;
+0031                 PW.nfft = 512;
+0032             elseif nargin == 1
+0033                 PW.trials = trials;
+0034                 PW.seconds = 0;
+0035                 PW.channel = 1;
+0036                 PW.nfft = 512;
+0037             elseif nargin == 2
+0038                 PW.trials = trials;
+0039                 PW.channel = 1;
+0040                 PW.seconds = seconds;
+0041                 PW.nfft = 512;
+0042             elseif nargin == 3
+0043                 PW.trials = trials;
+0044                 PW.channel = channel;
+0045                 PW.seconds = seconds;
+0046                 PW.nfft = 512;
+0047             elseif nargin == 4
+0048                 PW.trials = trials;
+0049                 PW.channel = channel;
+0050                 PW.seconds = seconds;
+0051                 PW.nfft = nfft;
+0052             else
+0053 %                 error('invalid number of arguments');
+0054             end
+0055         end
+0056         
+0057         function extract(PW)
+0058             if length(PW.nfft)==1
+0059                 numFeatures = PW.nfft/2+1;
+0060             else
+0061                 numFeatures = length(PW.nfft);
+0062             end
+0063             numTrials = length(PW.trials);
+0064             instances = zeros(numTrials, numFeatures);
+0065             labels = zeros(numTrials,1);
+0066 %             PWT.instances = zeros(numTrials, numFeatures);
+0067 %             PWT.labels = zeros(numTrials,1);
+0068             tic;
+0069             for i=1:numTrials
+0070                 if length(PW.seconds) == 1
+0071                     numsamples = PW.trials{i}.samplingRate * PW.seconds;
+0072                     if(numsamples == 0)
+0073                         y = PW.trials{i}.signal(PW.channel,:);
+0074                     else
+0075                         y = PW.trials{i}.signal(PW.channel, 1:numsamples);
+0076                     end
+0077                 elseif length(PW.seconds) == 2
+0078                     sampleA = PW.trials{i}.samplingRate*PW.seconds(1) +1;
+0079                     sampleB = PW.trials{i}.samplingRate*PW.seconds(2);
+0080                     y = PW.trials{i}.signal(PW.channel, sampleA:sampleB);
+0081                 else 
+0082                     error('invalid seconds parameter');
+0083                 end
+0084                 if isa(PW.filter,'dfilt.df2sos') || isa(PW.filter,'dfilt.df2')
+0085                     y = filter(PW.filter,y);
+0086                 elseif isa(PW.filter,'dfilt.dffir')
+0087                     y = filtfilt(PW.filter.Numerator,1,y);
+0088                 end
+0089                 if length(PW.nfft>1)
+0090                     [pxx, pff]=pwelch(y,[],[],PW.nfft,PW.trials{i}.samplingRate);
+0091                 else
+0092                     [pxx, pff]=pwelch(y,[],[],PW.nfft,PW.trials{i}.samplingRate,'onesided');
+0093                 end
+0094                 instances(i,:) = pxx;
+0095                 labels(i,1) = floor(PW.trials{i}.label);
+0096             end
+0097             total = toc;
+0098             PW.avgTime = total/numTrials;
+0099             PW.instanceSet = eegtoolkit.util.InstanceSet(instances, labels);
+0100             PW.pff = pff;
+0101         end
+0102         
+0103         function configInfo = getConfigInfo(PW)
+0104             if length(PW.nfft)>1
+0105                 configInfo = sprintf('PWelch\tchannel:%d\tseconds:%d\t freq range:%.3f to %.3f',PW.channel,PW.seconds,PW.nfft(1),PW.nfft(end));
+0106             else
+0107                 configInfo = sprintf('PWelch\tchannel:%d\tseconds:%d\tnfft:%d',PW.channel,PW.seconds,PW.nfft);
+0108             end
+0109         end
+0110         
+0111         function time = getTime(PW)
+0112             time = PW.avgTime;
+0113         end
+0114     end
+0115    
+0116 end
+0117
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.m b/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.m new file mode 100644 index 0000000..0dc4a92 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/PWelch.m @@ -0,0 +1,117 @@ +classdef PWelch < eegtoolkit.featextraction.PSDExtractionBase +%Computes the psd using the welch method +%Usage: +% session = eegtoolkit.util.Session(); +% session.loadSubject(1); +% pwt = ssveptolkit.transform.PWelchTransformer(session.trials); +%Specify the channel to be used (default = 126) +% pwt.channel = 150; +%Specify the number of seconds to be used (default = 0, use all signal) +% pwt.seconds = 3; +%Specify the nfft parameter (default = 512, computes 257 features) +% pwt.nfft = 512; +%Transform the signal +% pwt.transform(); + properties (Access = public) + channel; + seconds; + nfft; + avgTime; + end + + methods (Access = public) + function PW = PWelch(trials, seconds, channel, nfft) +% if ~iscell(trials) +% error('trials must be cell array of Trial object'); +% end + if nargin == 0 + PW.trials = {}; + PW.seconds = 0; + PW.channel = 1; + PW.nfft = 512; + elseif nargin == 1 + PW.trials = trials; + PW.seconds = 0; + PW.channel = 1; + PW.nfft = 512; + elseif nargin == 2 + PW.trials = trials; + PW.channel = 1; + PW.seconds = seconds; + PW.nfft = 512; + elseif nargin == 3 + PW.trials = trials; + PW.channel = channel; + PW.seconds = seconds; + PW.nfft = 512; + elseif nargin == 4 + PW.trials = trials; + PW.channel = channel; + PW.seconds = seconds; + PW.nfft = nfft; + else +% error('invalid number of arguments'); + end + end + + function extract(PW) + if length(PW.nfft)==1 + numFeatures = PW.nfft/2+1; + else + numFeatures = length(PW.nfft); + end + numTrials = length(PW.trials); + instances = zeros(numTrials, numFeatures); + labels = zeros(numTrials,1); +% PWT.instances = zeros(numTrials, numFeatures); +% PWT.labels = zeros(numTrials,1); + tic; + for i=1:numTrials + if length(PW.seconds) == 1 + numsamples = PW.trials{i}.samplingRate * PW.seconds; + if(numsamples == 0) + y = PW.trials{i}.signal(PW.channel,:); + else + y = PW.trials{i}.signal(PW.channel, 1:numsamples); + end + elseif length(PW.seconds) == 2 + sampleA = PW.trials{i}.samplingRate*PW.seconds(1) +1; + sampleB = PW.trials{i}.samplingRate*PW.seconds(2); + y = PW.trials{i}.signal(PW.channel, sampleA:sampleB); + else + error('invalid seconds parameter'); + end + if isa(PW.filter,'dfilt.df2sos') || isa(PW.filter,'dfilt.df2') + y = filter(PW.filter,y); + elseif isa(PW.filter,'dfilt.dffir') + y = filtfilt(PW.filter.Numerator,1,y); + end + if length(PW.nfft>1) + [pxx, pff]=pwelch(y,[],[],PW.nfft,PW.trials{i}.samplingRate); + else + [pxx, pff]=pwelch(y,[],[],PW.nfft,PW.trials{i}.samplingRate,'onesided'); + end + instances(i,:) = pxx; + labels(i,1) = floor(PW.trials{i}.label); + end + total = toc; + PW.avgTime = total/numTrials; + PW.instanceSet = eegtoolkit.util.InstanceSet(instances, labels); + PW.pff = pff; + end + + function configInfo = getConfigInfo(PW) + if length(PW.nfft)>1 + configInfo = sprintf('PWelch\tchannel:%d\tseconds:%d\t freq range:%.3f to %.3f',PW.channel,PW.seconds,PW.nfft(1),PW.nfft(end)); + else + configInfo = sprintf('PWelch\tchannel:%d\tseconds:%d\tnfft:%d',PW.channel,PW.seconds,PW.nfft); + end + end + + function time = getTime(PW) + time = PW.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/graph.dot b/doc/+eegtoolkit/+featextraction/@PWelch/graph.dot new file mode 100644 index 0000000..806a74c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PWelch -> PWelch; + + PWelch [URL="PWelch.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/graph.html b/doc/+eegtoolkit/+featextraction/@PWelch/graph.html new file mode 100644 index 0000000..8903edf --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@PWelch + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PWelch >
+

Dependency Graph for +eegtoolkit/+featextraction/@PWelch

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@PWelch + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/graph.map b/doc/+eegtoolkit/+featextraction/@PWelch/graph.map new file mode 100644 index 0000000..de91879 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/graph.png b/doc/+eegtoolkit/+featextraction/@PWelch/graph.png new file mode 100644 index 0000000..b2fb958 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@PWelch/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@PWelch/index.html b/doc/+eegtoolkit/+featextraction/@PWelch/index.html new file mode 100644 index 0000000..a97ad01 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelch/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@PWelch + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PWelch >
+ +

Index for +eegtoolkit/+featextraction/@PWelch

+ +

Matlab files in this directory:

+ +
 PWelch
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.html b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.html new file mode 100644 index 0000000..d243b4c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.html @@ -0,0 +1,183 @@ + + + + Description of PWelchExperimental + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @PWelchExperimental > PWelchExperimental.m
+ + + +

PWelchExperimental +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

PWelchExperimental.m

+

SOURCE CODE ^

+
0001 classdef PWelchExperimental < eegtoolkit.featextraction.FeatureExtractionBase
+0002 %Computes the psd using the welch method
+0003 %Usage:
+0004 %   session = eegtoolkit.util.Session();
+0005 %   session.loadSubject(1);
+0006 %   pwt = ssveptolkit.transform.PWelchTransformer(session.trials);
+0007 %Specify the channel to be used (default = 126)
+0008 %   pwt.channel = 150;
+0009 %Specify the number of seconds to be used (default = 0, use all signal)
+0010 %   pwt.seconds = 3;
+0011 %Specify the nfft parameter (default = 512, computes 257 features)
+0012 %   pwt.nfft = 512;
+0013 %Transform the signal
+0014 %   pwt.transform();
+0015     properties (Access = public)
+0016         channel;
+0017         seconds;
+0018         nfft;
+0019         pff;
+0020         win_len;
+0021         over_len;
+0022         avgTime;
+0023     end
+0024     
+0025     methods (Access = public)
+0026         function PWT = PWelchExperimental(trials, seconds, channel, nfft,win_len,over_len)
+0027 %             if ~iscell(trials)
+0028 %                 error('trials must be cell array of Trial object');
+0029 %             end
+0030             if nargin == 0
+0031                 PWT.trials = {};
+0032                 PWT.seconds = 0;
+0033                 PWT.channel = 1;
+0034                 PWT.nfft = 512;
+0035                 PWT.win_len=[];
+0036                 PWT.over_len=[];
+0037             elseif nargin == 1
+0038                 PWT.trials = trials;
+0039                 PWT.seconds = 0;
+0040                 PWT.channel = 1;
+0041                 PWT.nfft = 512;
+0042                 PWT.win_len=[];
+0043                 PWT.over_len=[];
+0044             elseif nargin == 2
+0045                 PWT.trials = trials;
+0046                 PWT.channel = 1;
+0047                 PWT.seconds = seconds;
+0048                 PWT.nfft = 512;
+0049                 PWT.win_len=[];
+0050                 PWT.over_len=[];
+0051             elseif nargin == 3
+0052                 PWT.trials = trials;
+0053                 PWT.channel = channel;
+0054                 PWT.seconds = seconds;
+0055                 PWT.nfft = 512;
+0056                 PWT.win_len=[];
+0057                 PWT.over_len=[];
+0058             elseif nargin == 4
+0059                 PWT.trials = trials;
+0060                 PWT.channel = channel;
+0061                 PWT.seconds = seconds;
+0062                 PWT.nfft = nfft;
+0063                 PWT.win_len=[];
+0064                 PWT.over_len=[];
+0065             elseif nargin == 5
+0066                 PWT.trials = trials;
+0067                 PWT.channel = channel;
+0068                 PWT.seconds = seconds;
+0069                 PWT.nfft = nfft;
+0070                 PWT.win_len=win_len;
+0071                 PWT.over_len=[];
+0072             elseif nargin == 6
+0073                 PWT.trials = trials;
+0074                 PWT.channel = channel;
+0075                 PWT.seconds = seconds;
+0076                 PWT.nfft = nfft;
+0077                 PWT.win_len=win_len;
+0078                 PWT.over_len=over_len;
+0079             else
+0080 %                 error('invalid number of arguments');
+0081             end
+0082         end
+0083         
+0084         function extract(PWT)
+0085             if length(PWT.nfft)==1
+0086                 numFeatures = PWT.nfft/2+1;
+0087             else
+0088                 numFeatures = length(PWT.nfft);
+0089             end
+0090             numTrials = length(PWT.trials);
+0091             instances = zeros(numTrials, numFeatures);
+0092             labels = zeros(numTrials,1);
+0093 %             PWT.instances = zeros(numTrials, numFeatures);
+0094 %             PWT.labels = zeros(numTrials,1);
+0095             tic;
+0096             for i=1:numTrials
+0097                 numsamples = PWT.trials{i}.samplingRate * PWT.seconds;
+0098                 if(numsamples == 0)
+0099                     y = PWT.trials{i}.signal(PWT.channel,:);
+0100                 else
+0101                     y = PWT.trials{i}.signal(PWT.channel, 1:numsamples);
+0102                 end
+0103 %                 if length(PWT.nfft>1)
+0104 %                     [pxx, pff]=pwelch(y,[],[],PWT.nfft,PWT.trials{i}.samplingRate);
+0105 %                 else
+0106                     [pxx, pff]=pwelch(y,PWT.win_len,round(PWT.over_len*PWT.win_len),PWT.nfft,PWT.trials{i}.samplingRate,'onesided');
+0107 %                 end
+0108                 %xv = [1 -2 1 zeros(1,length(pxx)-3)];
+0109 %                 xv = [1/5 1/5 1/5 1/5 1/5 zeros(1,length(pxx)-5)];
+0110 %                 A = gallery('circul',xv);
+0111                 instances(i,:) = pxx;
+0112                 labels(i,1) = floor(PWT.trials{i}.label);
+0113             end
+0114             PWT.avgTime = toc/numTrials;
+0115             PWT.instanceSet = eegtoolkit.util.InstanceSet(instances, labels);
+0116             PWT.pff = pff;
+0117         end
+0118         
+0119         function configInfo = getConfigInfo(PWT)
+0120             if length(PWT.nfft)>1
+0121                 configInfo = sprintf('PWelchExperimental\tchannel:%d\tseconds:%d\t freq range:%.3f to %.3f',PWT.channel,PWT.seconds,PWT.nfft(1),PWT.nfft(end));
+0122             else
+0123                 configInfo = sprintf('PWelchExperimental\tchannel:%d\tseconds:%d\tnfft:%d',PWT.channel,PWT.seconds,PWT.nfft);
+0124             end
+0125         end
+0126         
+0127         function time = getTime(PWT)
+0128             time = PWT.avgTime;
+0129         end
+0130     end
+0131    
+0132 end
+0133
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.m b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.m new file mode 100644 index 0000000..d01cb0e --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/PWelchExperimental.m @@ -0,0 +1,133 @@ +classdef PWelchExperimental < eegtoolkit.featextraction.FeatureExtractionBase +%Computes the psd using the welch method +%Usage: +% session = eegtoolkit.util.Session(); +% session.loadSubject(1); +% pwt = ssveptolkit.transform.PWelchTransformer(session.trials); +%Specify the channel to be used (default = 126) +% pwt.channel = 150; +%Specify the number of seconds to be used (default = 0, use all signal) +% pwt.seconds = 3; +%Specify the nfft parameter (default = 512, computes 257 features) +% pwt.nfft = 512; +%Transform the signal +% pwt.transform(); + properties (Access = public) + channel; + seconds; + nfft; + pff; + win_len; + over_len; + avgTime; + end + + methods (Access = public) + function PWT = PWelchExperimental(trials, seconds, channel, nfft,win_len,over_len) +% if ~iscell(trials) +% error('trials must be cell array of Trial object'); +% end + if nargin == 0 + PWT.trials = {}; + PWT.seconds = 0; + PWT.channel = 1; + PWT.nfft = 512; + PWT.win_len=[]; + PWT.over_len=[]; + elseif nargin == 1 + PWT.trials = trials; + PWT.seconds = 0; + PWT.channel = 1; + PWT.nfft = 512; + PWT.win_len=[]; + PWT.over_len=[]; + elseif nargin == 2 + PWT.trials = trials; + PWT.channel = 1; + PWT.seconds = seconds; + PWT.nfft = 512; + PWT.win_len=[]; + PWT.over_len=[]; + elseif nargin == 3 + PWT.trials = trials; + PWT.channel = channel; + PWT.seconds = seconds; + PWT.nfft = 512; + PWT.win_len=[]; + PWT.over_len=[]; + elseif nargin == 4 + PWT.trials = trials; + PWT.channel = channel; + PWT.seconds = seconds; + PWT.nfft = nfft; + PWT.win_len=[]; + PWT.over_len=[]; + elseif nargin == 5 + PWT.trials = trials; + PWT.channel = channel; + PWT.seconds = seconds; + PWT.nfft = nfft; + PWT.win_len=win_len; + PWT.over_len=[]; + elseif nargin == 6 + PWT.trials = trials; + PWT.channel = channel; + PWT.seconds = seconds; + PWT.nfft = nfft; + PWT.win_len=win_len; + PWT.over_len=over_len; + else +% error('invalid number of arguments'); + end + end + + function extract(PWT) + if length(PWT.nfft)==1 + numFeatures = PWT.nfft/2+1; + else + numFeatures = length(PWT.nfft); + end + numTrials = length(PWT.trials); + instances = zeros(numTrials, numFeatures); + labels = zeros(numTrials,1); +% PWT.instances = zeros(numTrials, numFeatures); +% PWT.labels = zeros(numTrials,1); + tic; + for i=1:numTrials + numsamples = PWT.trials{i}.samplingRate * PWT.seconds; + if(numsamples == 0) + y = PWT.trials{i}.signal(PWT.channel,:); + else + y = PWT.trials{i}.signal(PWT.channel, 1:numsamples); + end +% if length(PWT.nfft>1) +% [pxx, pff]=pwelch(y,[],[],PWT.nfft,PWT.trials{i}.samplingRate); +% else + [pxx, pff]=pwelch(y,PWT.win_len,round(PWT.over_len*PWT.win_len),PWT.nfft,PWT.trials{i}.samplingRate,'onesided'); +% end + %xv = [1 -2 1 zeros(1,length(pxx)-3)]; +% xv = [1/5 1/5 1/5 1/5 1/5 zeros(1,length(pxx)-5)]; +% A = gallery('circul',xv); + instances(i,:) = pxx; + labels(i,1) = floor(PWT.trials{i}.label); + end + PWT.avgTime = toc/numTrials; + PWT.instanceSet = eegtoolkit.util.InstanceSet(instances, labels); + PWT.pff = pff; + end + + function configInfo = getConfigInfo(PWT) + if length(PWT.nfft)>1 + configInfo = sprintf('PWelchExperimental\tchannel:%d\tseconds:%d\t freq range:%.3f to %.3f',PWT.channel,PWT.seconds,PWT.nfft(1),PWT.nfft(end)); + else + configInfo = sprintf('PWelchExperimental\tchannel:%d\tseconds:%d\tnfft:%d',PWT.channel,PWT.seconds,PWT.nfft); + end + end + + function time = getTime(PWT) + time = PWT.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.dot b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.dot new file mode 100644 index 0000000..335d08e --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PWelchExperimental -> PWelchExperimental; + + PWelchExperimental [URL="PWelchExperimental.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.html b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.html new file mode 100644 index 0000000..4a34537 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@PWelchExperimental + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PWelchExperimental >
+

Dependency Graph for +eegtoolkit/+featextraction/@PWelchExperimental

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@PWelchExperimental + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.map b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.map new file mode 100644 index 0000000..16c5e9c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.png b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.png new file mode 100644 index 0000000..b1f7ae5 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@PWelchExperimental/index.html b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/index.html new file mode 100644 index 0000000..7365ef0 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PWelchExperimental/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@PWelchExperimental + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PWelchExperimental >
+ +

Index for +eegtoolkit/+featextraction/@PWelchExperimental

+ +

Matlab files in this directory:

+ +
 PWelchExperimental
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.html b/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.html new file mode 100644 index 0000000..67c2444 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.html @@ -0,0 +1,147 @@ + + + + Description of PYAR + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @PYAR > PYAR.m
+ + + +

PYAR +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

PYAR.m

+

SOURCE CODE ^

+
0001 classdef PYAR < eegtoolkit.featextraction.FeatureExtractionBase
+0002     
+0003     properties (Access = public)
+0004         channel;
+0005         seconds;
+0006         order;
+0007         nfft;
+0008         avgTime;
+0009     end
+0010     
+0011     methods (Access = public)
+0012         function mAR = PYAR(trials, seconds, channel,m_ord, nfft)
+0013             if nargin == 0
+0014                 mAR.seconds = 0;
+0015                 mAR.channel = 1;
+0016                 mAR.order = 20;
+0017                 mAR.nfft = 512;
+0018             elseif nargin == 1
+0019                 mAR.trials = trials;
+0020                 mAR.seconds = 0;
+0021                 mAR.channel = 1;
+0022                 mAR.order = 20;
+0023                 mAR.nfft = 512;
+0024             elseif nargin == 2
+0025                 mAR.trials = trials;
+0026                 mAR.channel = 1;
+0027                 mAR.seconds = seconds;
+0028                 mAR.order = 20;
+0029                 mAR.nfft = 512;
+0030             elseif nargin == 3
+0031                 mAR.trials = trials;
+0032                 mAR.channel = channel;
+0033                 mAR.seconds = seconds;
+0034                 mAR.order=20;
+0035                 mAR.nfft = 512;
+0036             elseif nargin == 4
+0037                 mAR.trials = trials;
+0038                 mAR.channel = channel;
+0039                 mAR.seconds = seconds;
+0040                 mAR.order = m_ord;
+0041                 mAR.nfft = 512;
+0042             elseif nargin == 5
+0043                 mAR.trials = trials;
+0044                 mAR.channel = channel;
+0045                 mAR.seconds = seconds;
+0046                 mAR.order = m_ord;
+0047                 mAR.nfft = nfft;
+0048             else
+0049                 error('invalid number of arguments');
+0050             end
+0051         end
+0052         
+0053         function extract(mAR)
+0054             NUM_FEATURES = mAR.nfft/2+1;
+0055             numTrials = length(mAR.trials);
+0056             instances = zeros(numTrials, NUM_FEATURES);
+0057             labels = zeros(numTrials,1);
+0058             tic
+0059             for i=1:numTrials
+0060                 if length(mAR.seconds) ==1
+0061                 numsamples = mAR.trials{i}.samplingRate * mAR.seconds;
+0062                 if(numsamples == 0)
+0063                     y = mAR.trials{i}.signal(mAR.channel,:);
+0064                 else
+0065                     y = mAR.trials{i}.signal(mAR.channel, 1:numsamples);
+0066                 end
+0067                 elseif length(mAR.seconds) ==2
+0068                     sampleA = mAR.trials{i}.samplingRate*mAR.seconds(1) + 1;
+0069                     sampleB = mAR.trials{i}.samplingRate*mAR.seconds(2);
+0070                 else
+0071                     error('invalid seconds parameter');
+0072                 end
+0073                 if isa(mAR.filter,'dfilt.df2sos') || isa(mAR.filter,'dfilt.df2')
+0074                     y = filter(mAR.filter,y);
+0075                 elseif isa(mAR.filter,'dfilt.dffir')
+0076                     y = filtfilt(mAR.filter.Numerator,1,y);
+0077                 end
+0078                 [pyy pff] = pyulear(y,mAR.order,mAR.nfft,mAR.trials{i}.samplingRate);
+0079                 instances(i,:) = pyy;
+0080                 labels(i,1) = floor(mAR.trials{i}.label);
+0081             end
+0082             mAR.avgTime = toc/numTrials;
+0083             mAR.instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0084         end
+0085         
+0086         function configInfo = getConfigInfo(mAR)
+0087             configInfo = sprintf('PYAR\tchannel:%d\tseconds:%d\tnfft:%d\torder:%d',mAR.channel,mAR.seconds,mAR.nfft,mAR.order);
+0088         end
+0089         
+0090                         
+0091         function time = getTime(mAR)
+0092             time = mAR.avgTime;
+0093         end
+0094     end
+0095    
+0096 end
+0097
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.m b/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.m new file mode 100644 index 0000000..9148f94 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/PYAR.m @@ -0,0 +1,97 @@ +classdef PYAR < eegtoolkit.featextraction.FeatureExtractionBase + + properties (Access = public) + channel; + seconds; + order; + nfft; + avgTime; + end + + methods (Access = public) + function mAR = PYAR(trials, seconds, channel,m_ord, nfft) + if nargin == 0 + mAR.seconds = 0; + mAR.channel = 1; + mAR.order = 20; + mAR.nfft = 512; + elseif nargin == 1 + mAR.trials = trials; + mAR.seconds = 0; + mAR.channel = 1; + mAR.order = 20; + mAR.nfft = 512; + elseif nargin == 2 + mAR.trials = trials; + mAR.channel = 1; + mAR.seconds = seconds; + mAR.order = 20; + mAR.nfft = 512; + elseif nargin == 3 + mAR.trials = trials; + mAR.channel = channel; + mAR.seconds = seconds; + mAR.order=20; + mAR.nfft = 512; + elseif nargin == 4 + mAR.trials = trials; + mAR.channel = channel; + mAR.seconds = seconds; + mAR.order = m_ord; + mAR.nfft = 512; + elseif nargin == 5 + mAR.trials = trials; + mAR.channel = channel; + mAR.seconds = seconds; + mAR.order = m_ord; + mAR.nfft = nfft; + else + error('invalid number of arguments'); + end + end + + function extract(mAR) + NUM_FEATURES = mAR.nfft/2+1; + numTrials = length(mAR.trials); + instances = zeros(numTrials, NUM_FEATURES); + labels = zeros(numTrials,1); + tic + for i=1:numTrials + if length(mAR.seconds) ==1 + numsamples = mAR.trials{i}.samplingRate * mAR.seconds; + if(numsamples == 0) + y = mAR.trials{i}.signal(mAR.channel,:); + else + y = mAR.trials{i}.signal(mAR.channel, 1:numsamples); + end + elseif length(mAR.seconds) ==2 + sampleA = mAR.trials{i}.samplingRate*mAR.seconds(1) + 1; + sampleB = mAR.trials{i}.samplingRate*mAR.seconds(2); + else + error('invalid seconds parameter'); + end + if isa(mAR.filter,'dfilt.df2sos') || isa(mAR.filter,'dfilt.df2') + y = filter(mAR.filter,y); + elseif isa(mAR.filter,'dfilt.dffir') + y = filtfilt(mAR.filter.Numerator,1,y); + end + [pyy pff] = pyulear(y,mAR.order,mAR.nfft,mAR.trials{i}.samplingRate); + instances(i,:) = pyy; + labels(i,1) = floor(mAR.trials{i}.label); + end + mAR.avgTime = toc/numTrials; + mAR.instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + + function configInfo = getConfigInfo(mAR) + configInfo = sprintf('PYAR\tchannel:%d\tseconds:%d\tnfft:%d\torder:%d',mAR.channel,mAR.seconds,mAR.nfft,mAR.order); + end + + + function time = getTime(mAR) + time = mAR.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/graph.dot b/doc/+eegtoolkit/+featextraction/@PYAR/graph.dot new file mode 100644 index 0000000..ce88b22 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PYAR -> PYAR; + + PYAR [URL="PYAR.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/graph.html b/doc/+eegtoolkit/+featextraction/@PYAR/graph.html new file mode 100644 index 0000000..677f3e1 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@PYAR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PYAR >
+

Dependency Graph for +eegtoolkit/+featextraction/@PYAR

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@PYAR + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/graph.map b/doc/+eegtoolkit/+featextraction/@PYAR/graph.map new file mode 100644 index 0000000..9efd3ae --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/graph.png b/doc/+eegtoolkit/+featextraction/@PYAR/graph.png new file mode 100644 index 0000000..51303b4 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@PYAR/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@PYAR/index.html b/doc/+eegtoolkit/+featextraction/@PYAR/index.html new file mode 100644 index 0000000..7e25ef9 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@PYAR/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@PYAR + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@PYAR >
+ +

Index for +eegtoolkit/+featextraction/@PYAR

+ +

Matlab files in this directory:

+ +
 PYAR
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.html b/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.html new file mode 100644 index 0000000..1765d5c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.html @@ -0,0 +1,77 @@ + + + + Description of RawSignal + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @RawSignal > RawSignal.m
+ + + +

RawSignal +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

RawSignal.m

+

SOURCE CODE ^

+
0001 classdef RawSignal < eegtoolkit.featextraction.FeatureExtractionBase
+0002     %RAWSIGNAL Summary of this class goes here
+0003     %   Detailed explanation goes here
+0004     
+0005     properties (Access = public)
+0006     end
+0007     
+0008     methods (Access = public)
+0009         function RS = RawSignal()
+0010 %             RS.instanceSet = eegtoolkit.util.RawSignalSet(RS.trials);
+0011         end
+0012         
+0013         function RS = extract(RS)
+0014             RS.instanceSet = eegtoolkit.util.RawSignalSet(RS.trials);
+0015         end
+0016         
+0017         function configInfo = getConfigInfo(RS)
+0018             configInfo = '\n';
+0019         end
+0020         
+0021         function time = getTime(RS)
+0022             time = 0;
+0023         end
+0024     end
+0025     
+0026 end
+0027
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.m b/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.m new file mode 100644 index 0000000..c08003a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/RawSignal.m @@ -0,0 +1,27 @@ +classdef RawSignal < eegtoolkit.featextraction.FeatureExtractionBase + %RAWSIGNAL Summary of this class goes here + % Detailed explanation goes here + + properties (Access = public) + end + + methods (Access = public) + function RS = RawSignal() +% RS.instanceSet = eegtoolkit.util.RawSignalSet(RS.trials); + end + + function RS = extract(RS) + RS.instanceSet = eegtoolkit.util.RawSignalSet(RS.trials); + end + + function configInfo = getConfigInfo(RS) + configInfo = '\n'; + end + + function time = getTime(RS) + time = 0; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/graph.dot b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.dot new file mode 100644 index 0000000..effc195 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + RawSignal -> RawSignal; + + RawSignal [URL="RawSignal.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/graph.html b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.html new file mode 100644 index 0000000..09ca980 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@RawSignal + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@RawSignal >
+

Dependency Graph for +eegtoolkit/+featextraction/@RawSignal

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@RawSignal + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/graph.map b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.map new file mode 100644 index 0000000..9455564 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/graph.png b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.png new file mode 100644 index 0000000..a5f6bcd Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@RawSignal/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@RawSignal/index.html b/doc/+eegtoolkit/+featextraction/@RawSignal/index.html new file mode 100644 index 0000000..e60243a --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@RawSignal/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@RawSignal + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@RawSignal >
+ +

Index for +eegtoolkit/+featextraction/@RawSignal

+ +

Matlab files in this directory:

+ +
 RawSignal
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@STFT/STFT.html b/doc/+eegtoolkit/+featextraction/@STFT/STFT.html new file mode 100644 index 0000000..6e7d4b3 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/STFT.html @@ -0,0 +1,151 @@ + + + + Description of STFT + + + + + + + + + +
Home > +eegtoolkit > +featextraction > @STFT > STFT.m
+ + + +

STFT +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

STFT.m

+

SOURCE CODE ^

+
0001 classdef STFT < eegtoolkit.featextraction.FeatureExtractionBase
+0002     
+0003     properties (Access = public)
+0004         channel;
+0005         seconds;
+0006         Frange;
+0007         avgTime;
+0008     end
+0009     
+0010     methods (Access = public)   
+0011         function mSTFT = STFT(trials, seconds, channel,rangeFreq)
+0012             if nargin == 0
+0013                 mSTFT.seconds = 0;
+0014                 mSTFT.channel = 1;
+0015                 mSTFT.Frange(1) = 0;
+0016 %                 mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate;
+0017             elseif nargin == 1
+0018                 mSTFT.trials = trials;
+0019                 mSTFT.seconds = 0;
+0020                 mSTFT.channel = 1;
+0021                 mSTFT.Frange(1) = 0;
+0022                 mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate;
+0023             elseif nargin == 2
+0024                 mSTFT.trials = trials;
+0025                 mSTFT.channel = 1;
+0026                 mSTFT.seconds = seconds;
+0027                 mSTFT.Frange(1) = 0;
+0028                 mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate;
+0029             elseif nargin == 3
+0030                 mSTFT.trials = trials;
+0031                 mSTFT.channel = channel;
+0032                 mSTFT.seconds = seconds;
+0033                 mSTFT.Frange(1) = 0;
+0034                 mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate;
+0035             elseif nargin==4
+0036                 
+0037                 mSTFT.trials = trials;
+0038                 
+0039                 if prod(size(rangeFreq)) ~=2
+0040                     error('vector for frequency range must has two elements')
+0041                 end
+0042                 if rangeFreq(1)>=rangeFreq(2)
+0043                     error('first element must be smaller.');
+0044                 end
+0045                 if (rangeFreq(1)<0 || rangeFreq(2)>mSTFT.trials{1}.samplingRate)
+0046                     error('invalid values for frequency range');
+0047                 end
+0048                 
+0049                 mSTFT.channel = channel;
+0050                 mSTFT.seconds = seconds;
+0051                 mSTFT.Frange(1) = rangeFreq(1);
+0052                 mSTFT.Frange(2) = rangeFreq(2);
+0053             else
+0054                 error('invalid number of arguments');
+0055             end
+0056         end
+0057         
+0058         function extract(mSTFT)
+0059             mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate;
+0060             numsamples = mSTFT.trials{1}.samplingRate * mSTFT.seconds;
+0061             if (numsamples == 0)                    
+0062                 numsamples = size(mSTFT.trials{1}.signal(mSTFT.channel,:),2);                             
+0063             end
+0064             tic
+0065             numTrials = length(mSTFT.trials);
+0066             y = mSTFT.trials{1}.signal(mSTFT.channel, 1:numsamples);
+0067             [S,F,T,P]=spectrogram(y,[],[],[mSTFT.Frange(1):0.5:mSTFT.Frange(2)],mSTFT.trials{1}.samplingRate);
+0068             instances = zeros(numTrials, length(P(:)));
+0069             labels = zeros(numTrials,1);
+0070             for i=1:numTrials
+0071                 numsamples = mSTFT.trials{i}.samplingRate * mSTFT.seconds;
+0072                 if(numsamples == 0)
+0073                     y = mSTFT.trials{i}.signal(mSTFT.channel,:);
+0074                 else
+0075                     y = mSTFT.trials{i}.signal(mSTFT.channel, 1:numsamples);
+0076                 end                
+0077                 
+0078                 [S,F,T,P]=spectrogram(y,[],[],[mSTFT.Frange(1):0.5:mSTFT.Frange(2)],mSTFT.trials{i}.samplingRate);
+0079                 instances(i,:) = P(:);
+0080                 labels(i,1) = floor(mSTFT.trials{i}.label);
+0081             end
+0082             mSTFT.avgTime = toc/numTrials;
+0083             mSTFT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels);
+0084         end
+0085         
+0086         function configInfo = getConfigInfo(mSTFT)
+0087             if length(mSTFT.Frange) == 2
+0088                 configInfo = sprintf('STFT\tchannel:%d\tseconds:%d\tfrange1:%d\tfrange2:%d',mSTFT.channel,mSTFT.seconds,mSTFT.Frange(1),mSTFT.Frange(2));
+0089             else
+0090                 configInfo = sprintf('STFT\tchannel:%d\tseconds:%d\tfrange1:%d\tfrange2:unset',mSTFT.channel,mSTFT.seconds,mSTFT.Frange(1));
+0091             end
+0092         end
+0093         
+0094                         
+0095         function time = getTime(mSTFT)
+0096             time = mSTFT.avgTime;
+0097         end
+0098     end
+0099    
+0100 end
+0101
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@STFT/STFT.m b/doc/+eegtoolkit/+featextraction/@STFT/STFT.m new file mode 100644 index 0000000..e7bde00 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/STFT.m @@ -0,0 +1,101 @@ +classdef STFT < eegtoolkit.featextraction.FeatureExtractionBase + + properties (Access = public) + channel; + seconds; + Frange; + avgTime; + end + + methods (Access = public) + function mSTFT = STFT(trials, seconds, channel,rangeFreq) + if nargin == 0 + mSTFT.seconds = 0; + mSTFT.channel = 1; + mSTFT.Frange(1) = 0; +% mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate; + elseif nargin == 1 + mSTFT.trials = trials; + mSTFT.seconds = 0; + mSTFT.channel = 1; + mSTFT.Frange(1) = 0; + mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate; + elseif nargin == 2 + mSTFT.trials = trials; + mSTFT.channel = 1; + mSTFT.seconds = seconds; + mSTFT.Frange(1) = 0; + mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate; + elseif nargin == 3 + mSTFT.trials = trials; + mSTFT.channel = channel; + mSTFT.seconds = seconds; + mSTFT.Frange(1) = 0; + mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate; + elseif nargin==4 + + mSTFT.trials = trials; + + if prod(size(rangeFreq)) ~=2 + error('vector for frequency range must has two elements') + end + if rangeFreq(1)>=rangeFreq(2) + error('first element must be smaller.'); + end + if (rangeFreq(1)<0 || rangeFreq(2)>mSTFT.trials{1}.samplingRate) + error('invalid values for frequency range'); + end + + mSTFT.channel = channel; + mSTFT.seconds = seconds; + mSTFT.Frange(1) = rangeFreq(1); + mSTFT.Frange(2) = rangeFreq(2); + else + error('invalid number of arguments'); + end + end + + function extract(mSTFT) + mSTFT.Frange(2) = mSTFT.trials{1}.samplingRate; + numsamples = mSTFT.trials{1}.samplingRate * mSTFT.seconds; + if (numsamples == 0) + numsamples = size(mSTFT.trials{1}.signal(mSTFT.channel,:),2); + end + tic + numTrials = length(mSTFT.trials); + y = mSTFT.trials{1}.signal(mSTFT.channel, 1:numsamples); + [S,F,T,P]=spectrogram(y,[],[],[mSTFT.Frange(1):0.5:mSTFT.Frange(2)],mSTFT.trials{1}.samplingRate); + instances = zeros(numTrials, length(P(:))); + labels = zeros(numTrials,1); + for i=1:numTrials + numsamples = mSTFT.trials{i}.samplingRate * mSTFT.seconds; + if(numsamples == 0) + y = mSTFT.trials{i}.signal(mSTFT.channel,:); + else + y = mSTFT.trials{i}.signal(mSTFT.channel, 1:numsamples); + end + + [S,F,T,P]=spectrogram(y,[],[],[mSTFT.Frange(1):0.5:mSTFT.Frange(2)],mSTFT.trials{i}.samplingRate); + instances(i,:) = P(:); + labels(i,1) = floor(mSTFT.trials{i}.label); + end + mSTFT.avgTime = toc/numTrials; + mSTFT.instanceSet = eegtoolkit.util.InstanceSet(instances,labels); + end + + function configInfo = getConfigInfo(mSTFT) + if length(mSTFT.Frange) == 2 + configInfo = sprintf('STFT\tchannel:%d\tseconds:%d\tfrange1:%d\tfrange2:%d',mSTFT.channel,mSTFT.seconds,mSTFT.Frange(1),mSTFT.Frange(2)); + else + configInfo = sprintf('STFT\tchannel:%d\tseconds:%d\tfrange1:%d\tfrange2:unset',mSTFT.channel,mSTFT.seconds,mSTFT.Frange(1)); + end + end + + + function time = getTime(mSTFT) + time = mSTFT.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+featextraction/@STFT/graph.dot b/doc/+eegtoolkit/+featextraction/@STFT/graph.dot new file mode 100644 index 0000000..b300e03 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + STFT -> STFT; + + STFT [URL="STFT.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@STFT/graph.html b/doc/+eegtoolkit/+featextraction/@STFT/graph.html new file mode 100644 index 0000000..cf0f187 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featextraction/@STFT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@STFT >
+

Dependency Graph for +eegtoolkit/+featextraction/@STFT

+ +
+Dependency Graph for +eegtoolkit/+featextraction/@STFT + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featextraction/@STFT/graph.map b/doc/+eegtoolkit/+featextraction/@STFT/graph.map new file mode 100644 index 0000000..1a17266 --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featextraction/@STFT/graph.png b/doc/+eegtoolkit/+featextraction/@STFT/graph.png new file mode 100644 index 0000000..1ed6633 Binary files /dev/null and b/doc/+eegtoolkit/+featextraction/@STFT/graph.png differ diff --git a/doc/+eegtoolkit/+featextraction/@STFT/index.html b/doc/+eegtoolkit/+featextraction/@STFT/index.html new file mode 100644 index 0000000..b072c0c --- /dev/null +++ b/doc/+eegtoolkit/+featextraction/@STFT/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featextraction/@STFT + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featextraction/@STFT >
+ +

Index for +eegtoolkit/+featextraction/@STFT

+ +

Matlab files in this directory:

+ +
 STFT
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FEAST/FEAST.html b/doc/+eegtoolkit/+featselection/@FEAST/FEAST.html new file mode 100644 index 0000000..76c9fdb --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/FEAST.html @@ -0,0 +1,126 @@ + + + + Description of FEAST + + + + + + + + + +
Home > +eegtoolkit > +featselection > @FEAST > FEAST.m
+ + + +

FEAST +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FEAST.m

+

SOURCE CODE ^

+
0001 classdef FEAST < eegtoolkit.featselection.FeatureSelectionBase
+0002     properties (Constant)
+0003         ALGORITHM_MIM = 'mim';
+0004         ALGORITHM_MRMR = 'mrmr';
+0005         ALGORITHM_CMIM = 'cmim';
+0006         ALGORITHM_JMI = 'jmi';
+0007         ALGORITHM_DISR = 'disr';
+0008         ALGORITHM_CIFE = 'cife';
+0009         ALGORITHM_ICAP = 'icap';
+0010         ALGORITHM_CONDRED = 'condred';
+0011         ALGORITHM_CMI = 'cmi';
+0012         ALGORITHM_RELIEF = 'relief';
+0013         ALGORITHM_MIFS = 'mifs' %beta parameter required
+0014         ALGORITHM_BETAGAMMA = 'betagamma'; %beta and gamma parameters required
+0015         ALGORITHM_FCBF = 'fcbf'; %threshold parameter required
+0016     end
+0017     properties (Access = public)
+0018         algorithm;
+0019         numToSelect;
+0020         parameter1;
+0021         parameter2;
+0022         avgTime;
+0023     end
+0024     
+0025     methods
+0026         function FF = FEAST(instanceSet,algorithm, numtoSelect, param1, param2)
+0027             if nargin == 0
+0028                 FF.algorithm = 'icap';
+0029                 FF.numToSelect = 85;
+0030             end
+0031             if nargin > 1
+0032                 FF.originalInstanceSet = instanceSet;
+0033                 FF.algorithm = algorithm;
+0034             end
+0035             if nargin > 2
+0036                 FF.numToSelect = numtoSelect;
+0037             end
+0038             if nargin > 3
+0039                 FF.parameter1 = param1;
+0040             end
+0041             if nargin > 4
+0042                 FF.parameter2 = param2;
+0043             end
+0044         end
+0045         
+0046         function FF = compute(FF)
+0047             tic
+0048             if (strcmp(FF.algorithm,FF.ALGORITHM_MIFS) == 1) || (strcmp(FF.algorithm, FF.ALGORITHM_FCBF) == 1)
+0049                 indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels, FF.parameter1);
+0050             elseif strcmp(FF.algorithm, FF.ALGORITHM_BETAGAMMA) == 1
+0051                 indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels, FF.parameter1, FF.parameter2);
+0052             else
+0053                 indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels);
+0054             end
+0055             dataset = FF.originalInstanceSet.getInstances;
+0056             [inst, ~] = size(dataset);
+0057             FF.avgTime = toc/inst;
+0058             FF.filteredInstanceSet = eegtoolkit.util.InstanceSet([dataset(:,indices) FF.originalInstanceSet.getLabels]);
+0059         end
+0060         
+0061         function configInfo = getConfigInfo(FF)
+0062             if (strcmp(FF.algorithm,FF.ALGORITHM_MIFS) == 1) || (strcmp(FF.algorithm, FF.ALGORITHM_FCBF) == 1)
+0063                 configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d\tparam1:%d',FF.algorithm, FF.numToSelect, FF.parameter1);
+0064             elseif strcmp(FF.algorithm, FF.ALGORITHM_BETAGAMMA) == 1
+0065                 configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d\tparam1:%d\tparam2:%d',FF.algorithm, FF.numToSelect, FF.parameter1, FF.parameter2);
+0066             else
+0067                 configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d',FF.algorithm, FF.numToSelect);
+0068             end
+0069         end
+0070         
+0071         function time = getTime(FF)
+0072             time = FF.avgTime;
+0073         end
+0074     end
+0075     
+0076 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FEAST/FEAST.m b/doc/+eegtoolkit/+featselection/@FEAST/FEAST.m new file mode 100644 index 0000000..bdfeb64 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/FEAST.m @@ -0,0 +1,76 @@ +classdef FEAST < eegtoolkit.featselection.FeatureSelectionBase + properties (Constant) + ALGORITHM_MIM = 'mim'; + ALGORITHM_MRMR = 'mrmr'; + ALGORITHM_CMIM = 'cmim'; + ALGORITHM_JMI = 'jmi'; + ALGORITHM_DISR = 'disr'; + ALGORITHM_CIFE = 'cife'; + ALGORITHM_ICAP = 'icap'; + ALGORITHM_CONDRED = 'condred'; + ALGORITHM_CMI = 'cmi'; + ALGORITHM_RELIEF = 'relief'; + ALGORITHM_MIFS = 'mifs' %beta parameter required + ALGORITHM_BETAGAMMA = 'betagamma'; %beta and gamma parameters required + ALGORITHM_FCBF = 'fcbf'; %threshold parameter required + end + properties (Access = public) + algorithm; + numToSelect; + parameter1; + parameter2; + avgTime; + end + + methods + function FF = FEAST(instanceSet,algorithm, numtoSelect, param1, param2) + if nargin == 0 + FF.algorithm = 'icap'; + FF.numToSelect = 85; + end + if nargin > 1 + FF.originalInstanceSet = instanceSet; + FF.algorithm = algorithm; + end + if nargin > 2 + FF.numToSelect = numtoSelect; + end + if nargin > 3 + FF.parameter1 = param1; + end + if nargin > 4 + FF.parameter2 = param2; + end + end + + function FF = compute(FF) + tic + if (strcmp(FF.algorithm,FF.ALGORITHM_MIFS) == 1) || (strcmp(FF.algorithm, FF.ALGORITHM_FCBF) == 1) + indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels, FF.parameter1); + elseif strcmp(FF.algorithm, FF.ALGORITHM_BETAGAMMA) == 1 + indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels, FF.parameter1, FF.parameter2); + else + indices = feast(FF.algorithm, FF.numToSelect, FF.originalInstanceSet.getInstances, FF.originalInstanceSet.getLabels); + end + dataset = FF.originalInstanceSet.getInstances; + [inst, ~] = size(dataset); + FF.avgTime = toc/inst; + FF.filteredInstanceSet = eegtoolkit.util.InstanceSet([dataset(:,indices) FF.originalInstanceSet.getLabels]); + end + + function configInfo = getConfigInfo(FF) + if (strcmp(FF.algorithm,FF.ALGORITHM_MIFS) == 1) || (strcmp(FF.algorithm, FF.ALGORITHM_FCBF) == 1) + configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d\tparam1:%d',FF.algorithm, FF.numToSelect, FF.parameter1); + elseif strcmp(FF.algorithm, FF.ALGORITHM_BETAGAMMA) == 1 + configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d\tparam1:%d\tparam2:%d',FF.algorithm, FF.numToSelect, FF.parameter1, FF.parameter2); + else + configInfo = sprintf('FEAST\talgorithm:%s\tnumtoselect:%d',FF.algorithm, FF.numToSelect); + end + end + + function time = getTime(FF) + time = FF.avgTime; + end + end + +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FEAST/graph.dot b/doc/+eegtoolkit/+featselection/@FEAST/graph.dot new file mode 100644 index 0000000..a790ffe --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FEAST -> FEAST; + + FEAST [URL="FEAST.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FEAST/graph.html b/doc/+eegtoolkit/+featselection/@FEAST/graph.html new file mode 100644 index 0000000..a9ba5bc --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featselection/@FEAST + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@FEAST >
+

Dependency Graph for +eegtoolkit/+featselection/@FEAST

+ +
+Dependency Graph for +eegtoolkit/+featselection/@FEAST + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FEAST/graph.map b/doc/+eegtoolkit/+featselection/@FEAST/graph.map new file mode 100644 index 0000000..9bbd9b1 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featselection/@FEAST/graph.png b/doc/+eegtoolkit/+featselection/@FEAST/graph.png new file mode 100644 index 0000000..01bc3c6 Binary files /dev/null and b/doc/+eegtoolkit/+featselection/@FEAST/graph.png differ diff --git a/doc/+eegtoolkit/+featselection/@FEAST/index.html b/doc/+eegtoolkit/+featselection/@FEAST/index.html new file mode 100644 index 0000000..0e7398b --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FEAST/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featselection/@FEAST + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@FEAST >
+ +

Index for +eegtoolkit/+featselection/@FEAST

+ +

Matlab files in this directory:

+ +
 FEAST
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.html b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.html new file mode 100644 index 0000000..f149335 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.html @@ -0,0 +1,93 @@ + + + + Description of FeatureSelectionBase + + + + + + + + + +
Home > +eegtoolkit > +featselection > @FeatureSelectionBase > FeatureSelectionBase.m
+ + + +

FeatureSelectionBase +

+ +

PURPOSE ^

+
Abstract class for feature selection. Implement the functions for any
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Abstract class for feature selection. Implement the functions for any
+ feature selection method (e.g. PCA, SVD, FEAST, etc.)
+ 
+ Properties:
+ originalInstanceSet: Input - the original instanceSet with the features
+ filteredInstanceSet: Output - the filtered instanceSet
+ 
+ Functions:
+Implement this function to process the originalInstanceSet trials and 
+return the filteredInstanceSet
+   obj.compute();
+Info & run time so that the experiments are easily documented. configInfo
+is a string with the configuration information and time is of type double.
+   configInfo = obj.getConfigInfo();
+   time = obj.getTime();
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + + +

DOWNLOAD ^

+

FeatureSelectionBase.m

+

SOURCE CODE ^

+
0001 % Abstract class for feature selection. Implement the functions for any
+0002 % feature selection method (e.g. PCA, SVD, FEAST, etc.)
+0003 %
+0004 % Properties:
+0005 % originalInstanceSet: Input - the original instanceSet with the features
+0006 % filteredInstanceSet: Output - the filtered instanceSet
+0007 %
+0008 % Functions:
+0009 %Implement this function to process the originalInstanceSet trials and
+0010 %return the filteredInstanceSet
+0011 %   obj.compute();
+0012 %Info & run time so that the experiments are easily documented. configInfo
+0013 %is a string with the configuration information and time is of type double.
+0014 %   configInfo = obj.getConfigInfo();
+0015 %   time = obj.getTime();
+0016 
+0017 classdef (Abstract) FeatureSelectionBase < handle
+0018     
+0019     properties
+0020         originalInstanceSet; % Input: The original dataset
+0021         filteredInstanceSet; % Output: The filtered dataset
+0022     end
+0023     
+0024     methods (Abstract = true)
+0025         obj = compute(obj);
+0026         configInfo = getConfigInfo(obj);
+0027         time = getTime(obj);
+0028     end
+0029     
+0030 end
+0031
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m new file mode 100644 index 0000000..7101cc1 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/FeatureSelectionBase.m @@ -0,0 +1,31 @@ +% Abstract class for feature selection. Implement the functions for any +% feature selection method (e.g. PCA, SVD, FEAST, etc.) +% +% Properties: +% originalInstanceSet: Input - the original instanceSet with the features +% filteredInstanceSet: Output - the filtered instanceSet +% +% Functions: +%Implement this function to process the originalInstanceSet trials and +%return the filteredInstanceSet +% obj.compute(); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + +classdef (Abstract) FeatureSelectionBase < handle + + properties + originalInstanceSet; % Input: The original dataset + filteredInstanceSet; % Output: The filtered dataset + end + + methods (Abstract = true) + obj = compute(obj); + configInfo = getConfigInfo(obj); + time = getTime(obj); + end + +end + diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.dot b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.dot new file mode 100644 index 0000000..9de1c9a --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FeatureSelectionBase -> FeatureSelectionBase; + + FeatureSelectionBase [URL="FeatureSelectionBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.html b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.html new file mode 100644 index 0000000..51a2d2f --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featselection/@FeatureSelectionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@FeatureSelectionBase >
+

Dependency Graph for +eegtoolkit/+featselection/@FeatureSelectionBase

+ +
+Dependency Graph for +eegtoolkit/+featselection/@FeatureSelectionBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.map b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.map new file mode 100644 index 0000000..fa3a33d --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.png b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.png new file mode 100644 index 0000000..5b6f809 Binary files /dev/null and b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/graph.png differ diff --git a/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/index.html b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/index.html new file mode 100644 index 0000000..ce52341 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@FeatureSelectionBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featselection/@FeatureSelectionBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@FeatureSelectionBase >
+ +

Index for +eegtoolkit/+featselection/@FeatureSelectionBase

+ +

Matlab files in this directory:

+ +
 FeatureSelectionBaseAbstract class for feature selection. Implement the functions for any
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@PCA/PCA.html b/doc/+eegtoolkit/+featselection/@PCA/PCA.html new file mode 100644 index 0000000..935a7c4 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/PCA.html @@ -0,0 +1,82 @@ + + + + Description of PCA + + + + + + + + + +
Home > +eegtoolkit > +featselection > @PCA > PCA.m
+ + + +

PCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

PCA.m

+

SOURCE CODE ^

+
0001 classdef PCA < eegtoolkit.featselection.FeatureSelectionBase
+0002     properties (Access = public)
+0003         componentNum;
+0004         avgTime;
+0005     end
+0006     methods
+0007         function PCA = PCA(instanceSet,componentNum)
+0008             if nargin == 0
+0009                 PCA.componentNum = 50;
+0010             else
+0011                 PCA.componentNum = componentNum;
+0012                 PCA.originalInstanceSet = instanceSet;
+0013             end
+0014         end
+0015         
+0016         function PCA = compute(PCA)
+0017             ins = PCA.originalInstanceSet.getInstances;
+0018             [numInst,~] = size(ins);
+0019             tic
+0020             [~,score,~,~,~] = pca(ins,'NumComponents',PCA.componentNum);
+0021             PCA.avgTime = toc/numInst;
+0022             PCA.filteredInstanceSet = eegtoolkit.util.InstanceSet(score,PCA.originalInstanceSet.getLabels);
+0023         end
+0024         function configInfo = getConfigInfo(PCA)
+0025             configInfo = sprintf('PCA\tcomponents:%d', PCA.componentNum);
+0026         end
+0027         
+0028         function time = getTime(PCA)
+0029             time = PCA.avgTime;
+0030         end
+0031     end
+0032 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@PCA/PCA.m b/doc/+eegtoolkit/+featselection/@PCA/PCA.m new file mode 100644 index 0000000..d0f8d4f --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/PCA.m @@ -0,0 +1,32 @@ +classdef PCA < eegtoolkit.featselection.FeatureSelectionBase + properties (Access = public) + componentNum; + avgTime; + end + methods + function PCA = PCA(instanceSet,componentNum) + if nargin == 0 + PCA.componentNum = 50; + else + PCA.componentNum = componentNum; + PCA.originalInstanceSet = instanceSet; + end + end + + function PCA = compute(PCA) + ins = PCA.originalInstanceSet.getInstances; + [numInst,~] = size(ins); + tic + [~,score,~,~,~] = pca(ins,'NumComponents',PCA.componentNum); + PCA.avgTime = toc/numInst; + PCA.filteredInstanceSet = eegtoolkit.util.InstanceSet(score,PCA.originalInstanceSet.getLabels); + end + function configInfo = getConfigInfo(PCA) + configInfo = sprintf('PCA\tcomponents:%d', PCA.componentNum); + end + + function time = getTime(PCA) + time = PCA.avgTime; + end + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@PCA/graph.dot b/doc/+eegtoolkit/+featselection/@PCA/graph.dot new file mode 100644 index 0000000..476a8be --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PCA -> PCA; + + PCA [URL="PCA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@PCA/graph.html b/doc/+eegtoolkit/+featselection/@PCA/graph.html new file mode 100644 index 0000000..4bfeb29 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featselection/@PCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@PCA >
+

Dependency Graph for +eegtoolkit/+featselection/@PCA

+ +
+Dependency Graph for +eegtoolkit/+featselection/@PCA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@PCA/graph.map b/doc/+eegtoolkit/+featselection/@PCA/graph.map new file mode 100644 index 0000000..c747cc7 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featselection/@PCA/graph.png b/doc/+eegtoolkit/+featselection/@PCA/graph.png new file mode 100644 index 0000000..9cdb495 Binary files /dev/null and b/doc/+eegtoolkit/+featselection/@PCA/graph.png differ diff --git a/doc/+eegtoolkit/+featselection/@PCA/index.html b/doc/+eegtoolkit/+featselection/@PCA/index.html new file mode 100644 index 0000000..3d2e250 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@PCA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featselection/@PCA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@PCA >
+ +

Index for +eegtoolkit/+featselection/@PCA

+ +

Matlab files in this directory:

+ +
 PCA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@SVD/SVD.html b/doc/+eegtoolkit/+featselection/@SVD/SVD.html new file mode 100644 index 0000000..01f8d50 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/SVD.html @@ -0,0 +1,82 @@ + + + + Description of SVD + + + + + + + + + +
Home > +eegtoolkit > +featselection > @SVD > SVD.m
+ + + +

SVD +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

SVD.m

+

SOURCE CODE ^

+
0001 classdef SVD < eegtoolkit.featselection.FeatureSelectionBase;
+0002     properties (Access = public)
+0003         modes;
+0004         avgTime;
+0005     end
+0006     methods
+0007         function SVD = SVD(instanceSet,modes)
+0008             if nargin == 0
+0009                 SVD.modes = 80;
+0010             else
+0011                 SVD.modes = modes;
+0012                 SVD.originalInstanceSet = instanceSet;
+0013             end
+0014         end
+0015         
+0016         function SVD = compute(SVD)
+0017             tic
+0018             [U, S, V] = svd(SVD.originalInstanceSet.getInstances);
+0019             data_svd = U*S(:,1:SVD.modes)*V(1:SVD.modes,1:SVD.modes)';
+0020             [numInst, ~] = size(data_svd);
+0021             SVD.avgTime = toc/numInst;
+0022             SVD.filteredInstanceSet = eegtoolkit.util.InstanceSet(data_svd, SVD.originalInstanceSet.getLabels);
+0023         end
+0024         function configInfo = getConfigInfo(SVD)
+0025             configInfo = sprintf('SVD\tmodes:%d', SVD.modes);
+0026         end
+0027         
+0028         function time = getTime(SVD)
+0029             time = SVD.avgTime;
+0030         end
+0031     end
+0032 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@SVD/SVD.m b/doc/+eegtoolkit/+featselection/@SVD/SVD.m new file mode 100644 index 0000000..e84a121 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/SVD.m @@ -0,0 +1,32 @@ +classdef SVD < eegtoolkit.featselection.FeatureSelectionBase; + properties (Access = public) + modes; + avgTime; + end + methods + function SVD = SVD(instanceSet,modes) + if nargin == 0 + SVD.modes = 80; + else + SVD.modes = modes; + SVD.originalInstanceSet = instanceSet; + end + end + + function SVD = compute(SVD) + tic + [U, S, V] = svd(SVD.originalInstanceSet.getInstances); + data_svd = U*S(:,1:SVD.modes)*V(1:SVD.modes,1:SVD.modes)'; + [numInst, ~] = size(data_svd); + SVD.avgTime = toc/numInst; + SVD.filteredInstanceSet = eegtoolkit.util.InstanceSet(data_svd, SVD.originalInstanceSet.getLabels); + end + function configInfo = getConfigInfo(SVD) + configInfo = sprintf('SVD\tmodes:%d', SVD.modes); + end + + function time = getTime(SVD) + time = SVD.avgTime; + end + end +end \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@SVD/graph.dot b/doc/+eegtoolkit/+featselection/@SVD/graph.dot new file mode 100644 index 0000000..4c18e29 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + SVD -> SVD; + + SVD [URL="SVD.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@SVD/graph.html b/doc/+eegtoolkit/+featselection/@SVD/graph.html new file mode 100644 index 0000000..a664cb6 --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+featselection/@SVD + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@SVD >
+

Dependency Graph for +eegtoolkit/+featselection/@SVD

+ +
+Dependency Graph for +eegtoolkit/+featselection/@SVD + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+featselection/@SVD/graph.map b/doc/+eegtoolkit/+featselection/@SVD/graph.map new file mode 100644 index 0000000..d61dd1c --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+featselection/@SVD/graph.png b/doc/+eegtoolkit/+featselection/@SVD/graph.png new file mode 100644 index 0000000..6946a19 Binary files /dev/null and b/doc/+eegtoolkit/+featselection/@SVD/graph.png differ diff --git a/doc/+eegtoolkit/+featselection/@SVD/index.html b/doc/+eegtoolkit/+featselection/@SVD/index.html new file mode 100644 index 0000000..9fa740d --- /dev/null +++ b/doc/+eegtoolkit/+featselection/@SVD/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+featselection/@SVD + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+featselection/@SVD >
+ +

Index for +eegtoolkit/+featselection/@SVD

+ +

Matlab files in this directory:

+ +
 SVD
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.html b/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.html new file mode 100644 index 0000000..c2b9df7 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.html @@ -0,0 +1,152 @@ + + + + Description of Amuse + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @Amuse > Amuse.m
+ + + +

Amuse +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Amuse.m

+

SOURCE CODE ^

+
0001 classdef Amuse < eegtoolkit.preprocessing.PreprocessingBase
+0002     
+0003     properties
+0004         first;
+0005         last;
+0006         avgTime;
+0007     end
+0008     
+0009     methods
+0010         function AM = Amuse()
+0011             AM.first = 2;
+0012             AM.last = 256;
+0013         end
+0014         
+0015         function out = process(AM,in )
+0016             out = {};
+0017             total = 0;
+0018             for i=1:length(in)
+0019                 %                 i
+0020                 %                 in{i}.signal(end,:) = [];
+0021                 tic
+0022                 signal = in{i}.signal;
+0023                 %                 signal(end,:) = [];
+0024                 [W,~,yest] = AM.amuse(signal);
+0025                 signal = pinv(W(AM.first:AM.last,:))*yest(AM.first:AM.last,: );
+0026                 total = total + toc;
+0027                 in{i}.signal = signal;
+0028                 %                 out{i} = eegtoolkit.util.Trial(signal,in{i}.label,in{i}.samplingRate,in{i}.subjectid);
+0029             end
+0030             out = in;
+0031             %             total = toc;
+0032             AM.avgTime = total/length(in);
+0033         end
+0034         
+0035         function configInfo = getConfigInfo(AM)
+0036             configInfo = sprintf('Amuse:\t%d-%d',AM.first,AM.last);
+0037         end
+0038         
+0039         function time = getTime(AM)
+0040             time = AM.avgTime;
+0041         end
+0042     end
+0043     
+0044     methods (Access = private)
+0045         function [W,D1,y] = amuse(AM,X)
+0046             % BSS using eigenvalue value decomposition
+0047             % Program written by A. Cichocki and R. Szupiluk
+0048             %
+0049             % X [m x N] matrix of observed (measured) signals,
+0050             % W separating matrix,
+0051             % y estimated separated sources
+0052             % p time delay used in computation of covariance matrices
+0053             % optimal time-delay default p= 1
+0054             %
+0055             % First stage: Standard prewhitening
+0056             
+0057             [m,N]=size(X);
+0058             if nargin==2,
+0059                 n=m; %
+0060             end;
+0061             
+0062             Rxx=(X*X')/N;
+0063             
+0064             [Ux,Dx,Vx]=svd(Rxx);
+0065             Dx=diag(Dx);
+0066             % n=xxx;
+0067             if n<m, % under assumption of additive white noise and
+0068                 %when the number of sources are known or can a priori estimated
+0069                 Dx=Dx-real((mean(Dx(n+1:m))));
+0070                 Q= diag(real(sqrt(1./Dx(1:n))))*Ux(:,1:n)';
+0071                 %
+0072             else    % under assumption of no additive noise and when the
+0073                 % number of sources is unknown
+0074                 n=max(find(Dx>1e-199)); %Detection the number of sources
+0075                 Q= diag(real(sqrt(1./Dx(1:n))))*Ux(:,1:n)';
+0076             end;
+0077 
+0078             %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+0079             % Second stage: Fast separation using sorting EVD
+0080             % notation the same as used in the Chapter 4
+0081             Xb=Q*X;
+0082             p=1;
+0083             % paramter p can take here value different than 1
+0084             % for example -1 or 2.
+0085             N=max(size(Xb));
+0086             Xb=Xb-kron(mean(Xb')',ones(1,N));
+0087             
+0088             Rxbxbp=(Xb(:,1:N-1)*Xb(:,2:N)')/(N-1);
+0089             Rxbxbp= Rxbxbp+Rxbxbp';
+0090             [Vxb Dxb]=eig(Rxbxbp);
+0091             [D1 perm]=sort(diag(Dxb));
+0092             D1=flipud(D1);
+0093             Vxb=Vxb(:,flipud(perm));
+0094             W = Vxb'*Q;
+0095             y = Vxb' * Xb;%change Xb instead of x1
+0096         end
+0097     end
+0098     
+0099     
+0100     
+0101 end
+0102
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.m b/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.m new file mode 100644 index 0000000..06e5302 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/Amuse.m @@ -0,0 +1,102 @@ +classdef Amuse < eegtoolkit.preprocessing.PreprocessingBase + + properties + first; + last; + avgTime; + end + + methods + function AM = Amuse() + AM.first = 2; + AM.last = 256; + end + + function out = process(AM,in ) + out = {}; + total = 0; + for i=1:length(in) + % i + % in{i}.signal(end,:) = []; + tic + signal = in{i}.signal; + % signal(end,:) = []; + [W,~,yest] = AM.amuse(signal); + signal = pinv(W(AM.first:AM.last,:))*yest(AM.first:AM.last,: ); + total = total + toc; + in{i}.signal = signal; + % out{i} = eegtoolkit.util.Trial(signal,in{i}.label,in{i}.samplingRate,in{i}.subjectid); + end + out = in; + % total = toc; + AM.avgTime = total/length(in); + end + + function configInfo = getConfigInfo(AM) + configInfo = sprintf('Amuse:\t%d-%d',AM.first,AM.last); + end + + function time = getTime(AM) + time = AM.avgTime; + end + end + + methods (Access = private) + function [W,D1,y] = amuse(AM,X) + % BSS using eigenvalue value decomposition + % Program written by A. Cichocki and R. Szupiluk + % + % X [m x N] matrix of observed (measured) signals, + % W separating matrix, + % y estimated separated sources + % p time delay used in computation of covariance matrices + % optimal time-delay default p= 1 + % + % First stage: Standard prewhitening + + [m,N]=size(X); + if nargin==2, + n=m; % + end; + + Rxx=(X*X')/N; + + [Ux,Dx,Vx]=svd(Rxx); + Dx=diag(Dx); + % n=xxx; + if n1e-199)); %Detection the number of sources + Q= diag(real(sqrt(1./Dx(1:n))))*Ux(:,1:n)'; + end; + + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + % Second stage: Fast separation using sorting EVD + % notation the same as used in the Chapter 4 + Xb=Q*X; + p=1; + % paramter p can take here value different than 1 + % for example -1 or 2. + N=max(size(Xb)); + Xb=Xb-kron(mean(Xb')',ones(1,N)); + + Rxbxbp=(Xb(:,1:N-1)*Xb(:,2:N)')/(N-1); + Rxbxbp= Rxbxbp+Rxbxbp'; + [Vxb Dxb]=eig(Rxbxbp); + [D1 perm]=sort(diag(Dxb)); + D1=flipud(D1); + Vxb=Vxb(:,flipud(perm)); + W = Vxb'*Q; + y = Vxb' * Xb;%change Xb instead of x1 + end + end + + + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/graph.dot b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.dot new file mode 100644 index 0000000..8736430 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Amuse -> Amuse; + + Amuse [URL="Amuse.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/graph.html b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.html new file mode 100644 index 0000000..a293083 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@Amuse + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Amuse >
+

Dependency Graph for +eegtoolkit/+preprocessing/@Amuse

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@Amuse + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/graph.map b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.map new file mode 100644 index 0000000..92cf9a4 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/graph.png b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.png new file mode 100644 index 0000000..c72cc09 Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@Amuse/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@Amuse/index.html b/doc/+eegtoolkit/+preprocessing/@Amuse/index.html new file mode 100644 index 0000000..0525777 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Amuse/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@Amuse + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Amuse >
+ +

Index for +eegtoolkit/+preprocessing/@Amuse

+ +

Matlab files in this directory:

+ +
 Amuse
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.html b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.html new file mode 100644 index 0000000..9c51504 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.html @@ -0,0 +1,100 @@ + + + + Description of DigitalFilter + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @DigitalFilter > DigitalFilter.m
+ + + +

DigitalFilter +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

DigitalFilter.m

+

SOURCE CODE ^

+
0001 classdef DigitalFilter < eegtoolkit.preprocessing.PreprocessingBase
+0002     properties
+0003         filt;
+0004         info;
+0005         avgTime;
+0006     end
+0007     
+0008     methods
+0009         function DF = DigitalFilter(filt)
+0010             if(nargin > 0)
+0011                 DF.filt = filt;
+0012             end
+0013         end
+0014         
+0015         function out = process(DF,in )
+0016             tic;
+0017             for i=1:length(in)
+0018 %                 i
+0019                 signal = in{i}.signal;
+0020                 [numChannels, ~] = size(signal);
+0021                 for j=1:numChannels
+0022                     if isa(DF.filt,'dfilt.df2sos') || isa(DF.filt,'dfilt.df2')
+0023 %                         signal(j,:) = filter(DF.filt,signal(j,:));
+0024                         signal(j,:) = filtfilt(DF.filt.sosMatrix,DF.filt.ScaleValues,signal(j,:));
+0025                     elseif isa(DF.filt,'dfilt.dffir')
+0026                         signal(j,:) = filtfilt(DF.filt.Numerator,1,signal(j,:));
+0027                     end
+0028                 end
+0029                   in{i}.signal = signal;
+0030             end
+0031             out = in;
+0032             total = toc;
+0033             DF.avgTime = total/length(in);
+0034         end
+0035         
+0036         function configInfo = getConfigInfo(DF)
+0037             if isempty(DF.info)
+0038                 configInfo = 'DigitalFilter';
+0039             else
+0040                 configInfo = strcat('DigitalFilter:\t',info);
+0041             end
+0042         end
+0043         
+0044         function time = getTime(DF)
+0045             time = DF.avgTime;
+0046         end
+0047     end
+0048     
+0049 end
+0050
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.m b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.m new file mode 100644 index 0000000..e3390be --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/DigitalFilter.m @@ -0,0 +1,50 @@ +classdef DigitalFilter < eegtoolkit.preprocessing.PreprocessingBase + properties + filt; + info; + avgTime; + end + + methods + function DF = DigitalFilter(filt) + if(nargin > 0) + DF.filt = filt; + end + end + + function out = process(DF,in ) + tic; + for i=1:length(in) +% i + signal = in{i}.signal; + [numChannels, ~] = size(signal); + for j=1:numChannels + if isa(DF.filt,'dfilt.df2sos') || isa(DF.filt,'dfilt.df2') +% signal(j,:) = filter(DF.filt,signal(j,:)); + signal(j,:) = filtfilt(DF.filt.sosMatrix,DF.filt.ScaleValues,signal(j,:)); + elseif isa(DF.filt,'dfilt.dffir') + signal(j,:) = filtfilt(DF.filt.Numerator,1,signal(j,:)); + end + end + in{i}.signal = signal; + end + out = in; + total = toc; + DF.avgTime = total/length(in); + end + + function configInfo = getConfigInfo(DF) + if isempty(DF.info) + configInfo = 'DigitalFilter'; + else + configInfo = strcat('DigitalFilter:\t',info); + end + end + + function time = getTime(DF) + time = DF.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.dot b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.dot new file mode 100644 index 0000000..ef63f77 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + DigitalFilter -> DigitalFilter; + + DigitalFilter [URL="DigitalFilter.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.html b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.html new file mode 100644 index 0000000..05c59fa --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@DigitalFilter + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@DigitalFilter >
+

Dependency Graph for +eegtoolkit/+preprocessing/@DigitalFilter

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@DigitalFilter + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.map b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.map new file mode 100644 index 0000000..7c4f4d2 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.png b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.png new file mode 100644 index 0000000..e292126 Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@DigitalFilter/index.html b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/index.html new file mode 100644 index 0000000..f6b68ae --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@DigitalFilter/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@DigitalFilter + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@DigitalFilter >
+ +

Index for +eegtoolkit/+preprocessing/@DigitalFilter

+ +

Matlab files in this directory:

+ +
 DigitalFilter
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.html b/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.html new file mode 100644 index 0000000..5df07ea --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.html @@ -0,0 +1,97 @@ + + + + Description of FastICA + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @FastICA > FastICA.m
+ + + +

FastICA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FastICA.m

+

SOURCE CODE ^

+
0001 classdef FastICA < eegtoolkit.preprocessing.PreprocessingBase
+0002     
+0003     properties
+0004         first;
+0005         last;
+0006         avgTime;
+0007     end
+0008     
+0009     methods
+0010         function ICA = FastICA()
+0011             ICA.first = 2;
+0012             ICA.last = 256;
+0013         end
+0014         
+0015         function out = process(ICA,in )
+0016             out = {};
+0017             total = 0;
+0018             for i=1:length(in)
+0019                 i
+0020 %                 in{i}.signal(end,:) = [];
+0021                 tic
+0022                 signal = in{i}.signal;
+0023 %                 signal(end,:) = [];
+0024 %                 [W,~,yest] = amuse(signal);
+0025 %                 signal = pinv(W(ICA.first:ICA.last,:))*yest(ICA.first:ICA.last,: );
+0026                 [icasig, A, W] = fastica (signal);
+0027                 signal = A(:,ICA.first:end)*icasig(ICA.first:end,:);
+0028                 total = total + toc;
+0029 %                 in{i}.signal = signal;
+0030                 out{i} = eegtoolkit.util.Trial(signal,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid,in{i}.type);
+0031             end
+0032 %             out = in;
+0033 %             total = toc;
+0034             ICA.avgTime = total/length(in);
+0035         end
+0036         
+0037         function configInfo = getConfigInfo(ICA)
+0038             configInfo = sprintf('FastICA:\t%d-%d',ICA.first,ICA.last);
+0039         end
+0040         
+0041         function time = getTime(ICA)
+0042             time = ICA.avgTime;
+0043         end
+0044     end
+0045     
+0046 end
+0047
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.m b/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.m new file mode 100644 index 0000000..dbc3ac3 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/FastICA.m @@ -0,0 +1,47 @@ +classdef FastICA < eegtoolkit.preprocessing.PreprocessingBase + + properties + first; + last; + avgTime; + end + + methods + function ICA = FastICA() + ICA.first = 2; + ICA.last = 256; + end + + function out = process(ICA,in ) + out = {}; + total = 0; + for i=1:length(in) + i +% in{i}.signal(end,:) = []; + tic + signal = in{i}.signal; +% signal(end,:) = []; +% [W,~,yest] = amuse(signal); +% signal = pinv(W(ICA.first:ICA.last,:))*yest(ICA.first:ICA.last,: ); + [icasig, A, W] = fastica (signal); + signal = A(:,ICA.first:end)*icasig(ICA.first:end,:); + total = total + toc; +% in{i}.signal = signal; + out{i} = eegtoolkit.util.Trial(signal,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid,in{i}.type); + end +% out = in; +% total = toc; + ICA.avgTime = total/length(in); + end + + function configInfo = getConfigInfo(ICA) + configInfo = sprintf('FastICA:\t%d-%d',ICA.first,ICA.last); + end + + function time = getTime(ICA) + time = ICA.avgTime; + end + end + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/graph.dot b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.dot new file mode 100644 index 0000000..22490a9 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FastICA -> FastICA; + + FastICA [URL="FastICA.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/graph.html b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.html new file mode 100644 index 0000000..a34a2c0 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@FastICA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@FastICA >
+

Dependency Graph for +eegtoolkit/+preprocessing/@FastICA

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@FastICA + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/graph.map b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.map new file mode 100644 index 0000000..ae66e9d --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/graph.png b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.png new file mode 100644 index 0000000..eae8def Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@FastICA/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@FastICA/index.html b/doc/+eegtoolkit/+preprocessing/@FastICA/index.html new file mode 100644 index 0000000..b7f5905 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@FastICA/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@FastICA + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@FastICA >
+ +

Index for +eegtoolkit/+preprocessing/@FastICA

+ +

Matlab files in this directory:

+ +
 FastICA
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.html b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.html new file mode 100644 index 0000000..fee69e9 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.html @@ -0,0 +1,95 @@ + + + + Description of PreprocessingBase + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @PreprocessingBase > PreprocessingBase.m
+ + + +

PreprocessingBase +

+ +

PURPOSE ^

+
Abstract class for preprocessing. Implement the functions for any
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Abstract class for preprocessing. Implement the functions for any
+ preprocessing step (e.g. filtering, artifact removal, sub-sampling,
+ rereferencing, etc.
+ 
+ Properties:
+ originalTrials: cell array with the trials to be processed
+ processedTrials: the processed trials to be returned
+ 
+ Functions:
+Implement this function to process the in trials and return the processed
+trials (out)
+   out = obj.process(in);
+Info & run time so that the experiments are easily documented. configInfo
+is a string with the configuration information and time is of type double.
+   configInfo = obj.getConfigInfo();
+   time = obj.getTime();
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
  • PreprocessingBase Abstract class for preprocessing. Implement the functions for any
+This function is called by: +
    +
  • PreprocessingBase Abstract class for preprocessing. Implement the functions for any
+ + + +

DOWNLOAD ^

+

PreprocessingBase.m

+

SOURCE CODE ^

+
0001 % Abstract class for preprocessing. Implement the functions for any
+0002 % preprocessing step (e.g. filtering, artifact removal, sub-sampling,
+0003 % rereferencing, etc.
+0004 %
+0005 % Properties:
+0006 % originalTrials: cell array with the trials to be processed
+0007 % processedTrials: the processed trials to be returned
+0008 %
+0009 % Functions:
+0010 %Implement this function to process the in trials and return the processed
+0011 %trials (out)
+0012 %   out = obj.process(in);
+0013 %Info & run time so that the experiments are easily documented. configInfo
+0014 %is a string with the configuration information and time is of type double.
+0015 %   configInfo = obj.getConfigInfo();
+0016 %   time = obj.getTime();
+0017 
+0018 classdef PreprocessingBase < handle
+0019     
+0020     properties
+0021         originalTrials;
+0022         processedTrials;
+0023     end
+0024     
+0025     methods (Abstract = true)
+0026         out = process(obj,in);
+0027         configInfo = getConfigInfo(obj);
+0028         time = getTime(obj);
+0029     end
+0030     
+0031 end
+0032
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m new file mode 100644 index 0000000..9abae63 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/PreprocessingBase.m @@ -0,0 +1,32 @@ +% Abstract class for preprocessing. Implement the functions for any +% preprocessing step (e.g. filtering, artifact removal, sub-sampling, +% rereferencing, etc. +% +% Properties: +% originalTrials: cell array with the trials to be processed +% processedTrials: the processed trials to be returned +% +% Functions: +%Implement this function to process the in trials and return the processed +%trials (out) +% out = obj.process(in); +%Info & run time so that the experiments are easily documented. configInfo +%is a string with the configuration information and time is of type double. +% configInfo = obj.getConfigInfo(); +% time = obj.getTime(); + +classdef PreprocessingBase < handle + + properties + originalTrials; + processedTrials; + end + + methods (Abstract = true) + out = process(obj,in); + configInfo = getConfigInfo(obj); + time = getTime(obj); + end + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.dot b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.dot new file mode 100644 index 0000000..c7affe5 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + PreprocessingBase -> PreprocessingBase; + + PreprocessingBase [URL="PreprocessingBase.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.html b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.html new file mode 100644 index 0000000..96a284d --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@PreprocessingBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@PreprocessingBase >
+

Dependency Graph for +eegtoolkit/+preprocessing/@PreprocessingBase

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@PreprocessingBase + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.map b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.map new file mode 100644 index 0000000..9d7c117 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.png b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.png new file mode 100644 index 0000000..170392e Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/index.html b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/index.html new file mode 100644 index 0000000..b099f28 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@PreprocessingBase/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@PreprocessingBase + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@PreprocessingBase >
+ +

Index for +eegtoolkit/+preprocessing/@PreprocessingBase

+ +

Matlab files in this directory:

+ +
 PreprocessingBaseAbstract class for preprocessing. Implement the functions for any
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.html b/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.html new file mode 100644 index 0000000..aa30f89 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.html @@ -0,0 +1,95 @@ + + + + Description of Rereferencing + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @Rereferencing > Rereferencing.m
+ + + +

Rereferencing +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Rereferencing.m

+

SOURCE CODE ^

+
0001 classdef Rereferencing < eegtoolkit.preprocessing.PreprocessingBase
+0002     
+0003     properties
+0004         %meanSignal=1: Subtract the mean from the signal
+0005         %meanSignal=2: Average rereferencing
+0006         meanSignal;
+0007         avgTime;
+0008     end
+0009     
+0010     methods
+0011         function RR = Rereferencing()
+0012             RR.meanSignal = 1;
+0013         end
+0014         
+0015         function out = process(RR,in)
+0016             out = {};
+0017             tic;
+0018             for i=1:length(in)
+0019                 if RR.meanSignal == 1
+0020                     [numChannels,~] = size(in{i}.signal);
+0021                     for j=1:numChannels
+0022                         in{i}.signal(j,:) = in{i}.signal(j,:) - mean(in{i}.signal(j,:));
+0023                     end
+0024                 elseif RR.meanSignal == 2
+0025                     meanChann = mean(in{i}.signal);
+0026                       in{i}.signal = in{i}.signal-repmat(meanChann,257,1);
+0027                 end
+0028                 out = in;
+0029             end
+0030             RR.avgTime = toc/length(in);
+0031         end
+0032         
+0033         function configInfo = getConfigInfo(RR)
+0034             configInfo = sprintf('Rereferencing:\tmeanSignal:%d',RR.meanSignal);
+0035         end
+0036         
+0037                         
+0038         function time = getTime(RR)
+0039             time = RR.avgTime;
+0040         end
+0041         
+0042     end
+0043     
+0044 end
+0045
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.m b/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.m new file mode 100644 index 0000000..06c48e7 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/Rereferencing.m @@ -0,0 +1,45 @@ +classdef Rereferencing < eegtoolkit.preprocessing.PreprocessingBase + + properties + %meanSignal=1: Subtract the mean from the signal + %meanSignal=2: Average rereferencing + meanSignal; + avgTime; + end + + methods + function RR = Rereferencing() + RR.meanSignal = 1; + end + + function out = process(RR,in) + out = {}; + tic; + for i=1:length(in) + if RR.meanSignal == 1 + [numChannels,~] = size(in{i}.signal); + for j=1:numChannels + in{i}.signal(j,:) = in{i}.signal(j,:) - mean(in{i}.signal(j,:)); + end + elseif RR.meanSignal == 2 + meanChann = mean(in{i}.signal); + in{i}.signal = in{i}.signal-repmat(meanChann,257,1); + end + out = in; + end + RR.avgTime = toc/length(in); + end + + function configInfo = getConfigInfo(RR) + configInfo = sprintf('Rereferencing:\tmeanSignal:%d',RR.meanSignal); + end + + + function time = getTime(RR) + time = RR.avgTime; + end + + end + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.dot b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.dot new file mode 100644 index 0000000..03cfa28 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Rereferencing -> Rereferencing; + + Rereferencing [URL="Rereferencing.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.html b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.html new file mode 100644 index 0000000..4f5d655 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@Rereferencing + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Rereferencing >
+

Dependency Graph for +eegtoolkit/+preprocessing/@Rereferencing

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@Rereferencing + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.map b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.map new file mode 100644 index 0000000..9e51d40 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.png b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.png new file mode 100644 index 0000000..6c4894f Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@Rereferencing/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@Rereferencing/index.html b/doc/+eegtoolkit/+preprocessing/@Rereferencing/index.html new file mode 100644 index 0000000..f5b3157 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Rereferencing/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@Rereferencing + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Rereferencing >
+ +

Index for +eegtoolkit/+preprocessing/@Rereferencing

+ +

Matlab files in this directory:

+ +
 Rereferencing
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.html b/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.html new file mode 100644 index 0000000..cbe204b --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.html @@ -0,0 +1,143 @@ + + + + Description of SampleSelection + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @SampleSelection > SampleSelection.m
+ + + +

SampleSelection +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

SampleSelection.m

+

SOURCE CODE ^

+
0001 classdef SampleSelection < eegtoolkit.preprocessing.PreprocessingBase
+0002     properties
+0003         channels;
+0004         sampleRange;
+0005         samplingRate;
+0006     end
+0007     
+0008     methods
+0009         function CS = SampleSelection(channels,sampleRange)
+0010             if(nargin == 0)
+0011                 CS.channels = 126;
+0012                 CS.sampleRange = [1,1250];
+0013             end
+0014             if(nargin > 0)
+0015                 CS.channels = channels;
+0016             end
+0017             if nargin > 1
+0018                 CS.sampleRange = sampleRange;
+0019             end
+0020         end
+0021         
+0022         function out = process(CS,in)
+0023             out = {};
+0024             CS.samplingRate = in{1}.samplingRate;
+0025             for i=1:length(in)
+0026                 if(length(CS.channels) > 0)
+0027                     if(length(CS.sampleRange) > 2)
+0028                         signal = in{i}.signal(CS.channels,CS.sampleRange);
+0029                         out{i} = eegtoolkit.util.Trial(signal ...
+0030                             ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid);
+0031                     elseif(length(CS.sampleRange) > 0)
+0032                         %channels AND sampleRange
+0033                         signal = in{i}.signal(CS.channels,CS.sampleRange(1):CS.sampleRange(2));
+0034                         out{i} = eegtoolkit.util.Trial(signal ...
+0035                             ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid);
+0036                     else
+0037                         %ONLY channels
+0038                         signal = in{i}.signal(CS.channels,:);
+0039                         out{i} = eegtoolkit.util.Trial(signal ...
+0040                             ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid);
+0041                     end
+0042                 else
+0043                     if(length(CS.sampleRange) > 2)
+0044                         signal = in{i}.signal(:,CS.sampleRange);
+0045                         out{i} = eegtoolkit.util.Trial(signal ...
+0046                             ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid);
+0047                     elseif(length(CS.sampleRange) > 0)
+0048                         %ONLY sampleRange
+0049                         signal = in{i}.signal(:,CS.sampleRange(1):CS.sampleRange(2));
+0050                         out{i} = eegtoolkit.util.Trial(signal ...
+0051                             ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid);
+0052                     else
+0053                         %NOTHING (?)
+0054                         disp('Warning: No parameter specified for SampleSelection, using all channels and samples');
+0055                     end
+0056                 end
+0057             end
+0058         end
+0059         
+0060         function configInfo = getConfigInfo(CS)
+0061             if(length(CS.channels) > 0)
+0062                 if(length(CS.sampleRange) > 0)
+0063                     configInfo = 'SampleSelection\tChannels:';
+0064                     for i=1:length(CS.channels)
+0065                         configInfo = strcat(configInfo,sprintf('%d+',CS.channels(i)));
+0066                     end
+0067                     configInfo = strcat(configInfo,sprintf('\tsampleRange:%d-%d',CS.sampleRange(1),CS.sampleRange(2)));
+0068                 else
+0069                     configInfo = 'SampleSelection\tChannels:';
+0070                     for i=1:length(CS.channels)
+0071                         configInfo = strcat(configInfo,sprintf('%d+',CS.channels(i)));
+0072                     end
+0073                 end
+0074             else
+0075                 if(length(CS.sampleRange) > 0)
+0076                     configInfo = sprintf('SampleSelection\tSampleRange:%d-%d',CS.sampleRange(1),CS.sampleRange(2));
+0077                     %ONLY sampleRange
+0078                 else
+0079                     %NOTHING (?)
+0080                     configInfo = sprintf('SampleSelection\tNothing specified');
+0081                 end
+0082             end
+0083         end
+0084         
+0085         
+0086         function time = getTime(CS)
+0087             time = 0;
+0088         end
+0089         
+0090     end
+0091     
+0092 end
+0093
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.m b/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.m new file mode 100644 index 0000000..fad7d87 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/SampleSelection.m @@ -0,0 +1,93 @@ +classdef SampleSelection < eegtoolkit.preprocessing.PreprocessingBase + properties + channels; + sampleRange; + samplingRate; + end + + methods + function CS = SampleSelection(channels,sampleRange) + if(nargin == 0) + CS.channels = 126; + CS.sampleRange = [1,1250]; + end + if(nargin > 0) + CS.channels = channels; + end + if nargin > 1 + CS.sampleRange = sampleRange; + end + end + + function out = process(CS,in) + out = {}; + CS.samplingRate = in{1}.samplingRate; + for i=1:length(in) + if(length(CS.channels) > 0) + if(length(CS.sampleRange) > 2) + signal = in{i}.signal(CS.channels,CS.sampleRange); + out{i} = eegtoolkit.util.Trial(signal ... + ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid); + elseif(length(CS.sampleRange) > 0) + %channels AND sampleRange + signal = in{i}.signal(CS.channels,CS.sampleRange(1):CS.sampleRange(2)); + out{i} = eegtoolkit.util.Trial(signal ... + ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid); + else + %ONLY channels + signal = in{i}.signal(CS.channels,:); + out{i} = eegtoolkit.util.Trial(signal ... + ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid); + end + else + if(length(CS.sampleRange) > 2) + signal = in{i}.signal(:,CS.sampleRange); + out{i} = eegtoolkit.util.Trial(signal ... + ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid); + elseif(length(CS.sampleRange) > 0) + %ONLY sampleRange + signal = in{i}.signal(:,CS.sampleRange(1):CS.sampleRange(2)); + out{i} = eegtoolkit.util.Trial(signal ... + ,in{i}.label,in{i}.samplingRate,in{i}.subjectid,in{i}.sessionid); + else + %NOTHING (?) + disp('Warning: No parameter specified for SampleSelection, using all channels and samples'); + end + end + end + end + + function configInfo = getConfigInfo(CS) + if(length(CS.channels) > 0) + if(length(CS.sampleRange) > 0) + configInfo = 'SampleSelection\tChannels:'; + for i=1:length(CS.channels) + configInfo = strcat(configInfo,sprintf('%d+',CS.channels(i))); + end + configInfo = strcat(configInfo,sprintf('\tsampleRange:%d-%d',CS.sampleRange(1),CS.sampleRange(2))); + else + configInfo = 'SampleSelection\tChannels:'; + for i=1:length(CS.channels) + configInfo = strcat(configInfo,sprintf('%d+',CS.channels(i))); + end + end + else + if(length(CS.sampleRange) > 0) + configInfo = sprintf('SampleSelection\tSampleRange:%d-%d',CS.sampleRange(1),CS.sampleRange(2)); + %ONLY sampleRange + else + %NOTHING (?) + configInfo = sprintf('SampleSelection\tNothing specified'); + end + end + end + + + function time = getTime(CS) + time = 0; + end + + end + +end + diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.dot b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.dot new file mode 100644 index 0000000..f1cd68a --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + SampleSelection -> SampleSelection; + + SampleSelection [URL="SampleSelection.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.html b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.html new file mode 100644 index 0000000..1e2df1a --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@SampleSelection + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@SampleSelection >
+

Dependency Graph for +eegtoolkit/+preprocessing/@SampleSelection

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@SampleSelection + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.map b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.map new file mode 100644 index 0000000..03d491b --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.png b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.png new file mode 100644 index 0000000..11ac01f Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@SampleSelection/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@SampleSelection/index.html b/doc/+eegtoolkit/+preprocessing/@SampleSelection/index.html new file mode 100644 index 0000000..4b6ebc0 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@SampleSelection/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@SampleSelection + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@SampleSelection >
+ +

Index for +eegtoolkit/+preprocessing/@SampleSelection

+ +

Matlab files in this directory:

+ +
 SampleSelection
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.html b/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.html new file mode 100644 index 0000000..8a6667b --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.html @@ -0,0 +1,114 @@ + + + + Description of Windsorize + + + + + + + + + +
Home > +eegtoolkit > +preprocessing > @Windsorize > Windsorize.m
+ + + +

Windsorize +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Windsorize.m

+

SOURCE CODE ^

+
0001 classdef Windsorize < eegtoolkit.preprocessing.PreprocessingBase
+0002     properties
+0003         limit_l;
+0004         limit_h;
+0005         subjectids;
+0006     end
+0007     
+0008     methods
+0009         function obj = Windsorize(low,high)
+0010             if nargin == 0
+0011                 obj.limit_l = 0.05;
+0012                 obj.limit_h = 0.95;
+0013             elseif nargin == 2
+0014                 obj.limit_l = low;
+0015                 obj.limit_h = high;
+0016             else
+0017                 error('2 inputs are required for windsorize, the low and high limits');
+0018             end
+0019         end
+0020         
+0021         function trials = process(obj,trials)
+0022             subs = unique(obj.subjectids);
+0023             nchannels = size(trials{1}.signal,1);
+0024             trial_length = size(trials{1}.signal,2);
+0025             for i=1:numel(subs)
+0026                 ids = find(obj.subjectids == subs(i));
+0027                 ntrials = numel(ids);
+0028                 % Concatenate signal
+0029                 signal = [];
+0030                 for j=1:numel(ids)
+0031                     signal = [signal trials{ids(j)}.signal];
+0032                 end
+0033                 %windsorize
+0034                 sorted_sig = sort(signal,2);
+0035                 upbound = sorted_sig(:,round(obj.limit_h*size(signal,2)));
+0036                 uprep = sorted_sig(:,round(obj.limit_h*size(signal,2))-1);
+0037                 lowbound = sorted_sig(:,round(obj.limit_l*size(signal,2)));
+0038                 lowrep = sorted_sig(:,round(obj.limit_l*size(signal,2))+1);
+0039                 for ch=1:nchannels
+0040                     signal(ch,signal(ch,:)>upbound(ch)) = uprep(ch);
+0041                     signal(ch,signal(ch,:)<lowbound(ch)) = lowrep(ch);
+0042                 end
+0043                 temp = mat2cell(signal,nchannels,trial_length*ones(ntrials,1));
+0044                 for j=1:numel(ids)
+0045                     trials{ids(j)}.signal = temp{j};
+0046                 end
+0047             end
+0048             
+0049         end
+0050         
+0051         
+0052         function configInfo = getConfigInfo(CS)
+0053             configInfo = sprintf('Windsorizing\tLow limit: %f, High limit: %f',CS.limit_l,CS.limit_l);
+0054         end
+0055         
+0056         
+0057         function time = getTime(CS)
+0058             time = 0;
+0059         end
+0060         
+0061     end
+0062     
+0063 end
+0064
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.m b/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.m new file mode 100644 index 0000000..6aafe6d --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Windsorize/Windsorize.m @@ -0,0 +1,64 @@ +classdef Windsorize < eegtoolkit.preprocessing.PreprocessingBase + properties + limit_l; + limit_h; + subjectids; + end + + methods + function obj = Windsorize(low,high) + if nargin == 0 + obj.limit_l = 0.05; + obj.limit_h = 0.95; + elseif nargin == 2 + obj.limit_l = low; + obj.limit_h = high; + else + error('2 inputs are required for windsorize, the low and high limits'); + end + end + + function trials = process(obj,trials) + subs = unique(obj.subjectids); + nchannels = size(trials{1}.signal,1); + trial_length = size(trials{1}.signal,2); + for i=1:numel(subs) + ids = find(obj.subjectids == subs(i)); + ntrials = numel(ids); + % Concatenate signal + signal = []; + for j=1:numel(ids) + signal = [signal trials{ids(j)}.signal]; + end + %windsorize + sorted_sig = sort(signal,2); + upbound = sorted_sig(:,round(obj.limit_h*size(signal,2))); + uprep = sorted_sig(:,round(obj.limit_h*size(signal,2))-1); + lowbound = sorted_sig(:,round(obj.limit_l*size(signal,2))); + lowrep = sorted_sig(:,round(obj.limit_l*size(signal,2))+1); + for ch=1:nchannels + signal(ch,signal(ch,:)>upbound(ch)) = uprep(ch); + signal(ch,signal(ch,:) Windsorize; + + Windsorize [URL="Windsorize.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.html b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.html new file mode 100644 index 0000000..87af35a --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+preprocessing/@Windsorize + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Windsorize >
+

Dependency Graph for +eegtoolkit/+preprocessing/@Windsorize

+ +
+Dependency Graph for +eegtoolkit/+preprocessing/@Windsorize + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.map b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.map new file mode 100644 index 0000000..c1acd95 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.png b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.png new file mode 100644 index 0000000..6dac85e Binary files /dev/null and b/doc/+eegtoolkit/+preprocessing/@Windsorize/graph.png differ diff --git a/doc/+eegtoolkit/+preprocessing/@Windsorize/index.html b/doc/+eegtoolkit/+preprocessing/@Windsorize/index.html new file mode 100644 index 0000000..d0a6469 --- /dev/null +++ b/doc/+eegtoolkit/+preprocessing/@Windsorize/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+preprocessing/@Windsorize + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+preprocessing/@Windsorize >
+ +

Index for +eegtoolkit/+preprocessing/@Windsorize

+ +

Matlab files in this directory:

+ +
 Windsorize
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.html b/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.html new file mode 100644 index 0000000..062ee71 --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.html @@ -0,0 +1,83 @@ + + + + Description of FusionInstanceSet + + + + + + + + + +
Home > +eegtoolkit > +util > @FusionInstanceSet > FusionInstanceSet.m
+ + + +

FusionInstanceSet +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

FusionInstanceSet.m

+

SOURCE CODE ^

+
0001 classdef FusionInstanceSet < eegtoolkit.util.InstanceSet
+0002     properties
+0003         numFusion;
+0004         instanceSets;
+0005     end
+0006     
+0007     methods 
+0008         function FIS = FusionInstanceSet(baseInstanceSet)
+0009             FIS = FIS@eegtoolkit.util.InstanceSet(baseInstanceSet.getDataset);
+0010             FIS.numFusion = 0;
+0011             FIS.instanceSets = {};
+0012         end
+0013         
+0014         function FIS = addInstanceSet(FIS, instanceSet)
+0015             FIS.numFusion = FIS.numFusion + 1;
+0016             FIS.instanceSets{FIS.numFusion} = instanceSet;
+0017         end
+0018         
+0019         function FIS = removeInstancesWithIndices(FIS, indices)
+0020             for i=1:length(FIS.instanceSets)
+0021                 FIS.instanceSets{i} = FIS.instanceSets{i}.removeInstancesWithIndices(indices);
+0022             end
+0023         end
+0024         
+0025         function instances = getInstancesWithIndices(FIS, indices)
+0026             instances = zeros(length(indices),FIS.getNumFeatures,FIS.numFusion);
+0027             for i=1:length(FIS.instanceSets)
+0028                 instances(:,:,i) = FIS.instanceSets{i}.getInstancesWithIndices(indices);
+0029             end
+0030         end
+0031     end
+0032     
+0033 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.m b/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.m new file mode 100644 index 0000000..f6cc0e0 --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/FusionInstanceSet.m @@ -0,0 +1,33 @@ +classdef FusionInstanceSet < eegtoolkit.util.InstanceSet + properties + numFusion; + instanceSets; + end + + methods + function FIS = FusionInstanceSet(baseInstanceSet) + FIS = FIS@eegtoolkit.util.InstanceSet(baseInstanceSet.getDataset); + FIS.numFusion = 0; + FIS.instanceSets = {}; + end + + function FIS = addInstanceSet(FIS, instanceSet) + FIS.numFusion = FIS.numFusion + 1; + FIS.instanceSets{FIS.numFusion} = instanceSet; + end + + function FIS = removeInstancesWithIndices(FIS, indices) + for i=1:length(FIS.instanceSets) + FIS.instanceSets{i} = FIS.instanceSets{i}.removeInstancesWithIndices(indices); + end + end + + function instances = getInstancesWithIndices(FIS, indices) + instances = zeros(length(indices),FIS.getNumFeatures,FIS.numFusion); + for i=1:length(FIS.instanceSets) + instances(:,:,i) = FIS.instanceSets{i}.getInstancesWithIndices(indices); + end + end + end + +end diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.dot b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.dot new file mode 100644 index 0000000..f8c92f9 --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + FusionInstanceSet -> FusionInstanceSet; + + FusionInstanceSet [URL="FusionInstanceSet.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.html b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.html new file mode 100644 index 0000000..4c673ed --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@FusionInstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@FusionInstanceSet >
+

Dependency Graph for +eegtoolkit/+util/@FusionInstanceSet

+ +
+Dependency Graph for +eegtoolkit/+util/@FusionInstanceSet + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.map b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.map new file mode 100644 index 0000000..35af42a --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.png b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.png new file mode 100644 index 0000000..d2373a8 Binary files /dev/null and b/doc/+eegtoolkit/+util/@FusionInstanceSet/graph.png differ diff --git a/doc/+eegtoolkit/+util/@FusionInstanceSet/index.html b/doc/+eegtoolkit/+util/@FusionInstanceSet/index.html new file mode 100644 index 0000000..c31bc7d --- /dev/null +++ b/doc/+eegtoolkit/+util/@FusionInstanceSet/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@FusionInstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@FusionInstanceSet >
+ +

Index for +eegtoolkit/+util/@FusionInstanceSet

+ +

Matlab files in this directory:

+ +
 FusionInstanceSet
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.html b/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.html new file mode 100644 index 0000000..87b3189 --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.html @@ -0,0 +1,327 @@ + + + + Description of InstanceSet + + + + + + + + + +
Home > +eegtoolkit > +util > @InstanceSet > InstanceSet.m
+ + + +

InstanceSet +

+ +

PURPOSE ^

+
A class for describing a set of instances and labels
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 A class for describing a set of instances and labels
+ 
+ Properties:
+ -instances : a m x n matrix where m = # instances and n =
+ # features
+ -labels: a m x 1 matrix containing the labels for each
+ instance
+ -K: a m x m matrix containing the kernel of the instances
+ required only for the Fast vesrion of LibSVM
+
+ Functions:
+Construct an instanceSet
+   IS = eegtoolkit.util.InstanceSet(instances, labels)
+Compute the kernel
+   K = IS.computeKernel(kernel, gamma, maxlag, scaleopt)
+ kernel can be one of 'linear' (default),'rbf','chi','xcorr','spearman',
+ 'correlation','cosine','euclidean','seuclidean','mahalanobis'
+Get the training kernel with indexes in the trainidx vector
+   Ktrain = IS.getTrainKernel(trainidx)
+Get the test kernel with test indexes testidx and train indexes trainidx
+   Ktest = IS.getTestKernel(trainidx, testidx)
+Get instances of specific indices in vector idx
+   instance = IS.getInstancesWithIndices(idx)
+Get the instances of a specific label
+   instances = IS.getInstancesForLabel(label)
+Get the indices corresponding to a specific label
+   indices = IS.getInstanceIndicesForLabel(label)
+Get the instances including the labels as the last row
+   dataset = getDataset(IS)
+Get the instances with specific indices. The last column of the matrix 
+will contain the label.
+   dataset = IS.getDatasetWithIndices(idx)
+Remove instances with specific indices. A new InstanceSet object is 
+returned by this function without the specified instances
+   IS = IS.removeInstancesWithIndices(idx)
+ Write the dataset to a csv file
+   IS.writeCSV(csvname)
+Write the dataset to a weka-readable file (arff). The whole dataset is
+written if the indices are not given (function called with 1 argument)
+   IS.writeArff(fname, indices)
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
  • InstanceSet A class for describing a set of instances and labels
+This function is called by: +
    +
  • InstanceSet A class for describing a set of instances and labels
+ + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

InstanceSet.m

+

SOURCE CODE ^

+
0001 % A class for describing a set of instances and labels
+0002 %
+0003 % Properties:
+0004 % -instances : a m x n matrix where m = # instances and n =
+0005 % # features
+0006 % -labels: a m x 1 matrix containing the labels for each
+0007 % instance
+0008 % -K: a m x m matrix containing the kernel of the instances
+0009 % required only for the Fast vesrion of LibSVM
+0010 %
+0011 % Functions:
+0012 %Construct an instanceSet
+0013 %   IS = eegtoolkit.util.InstanceSet(instances, labels)
+0014 %Compute the kernel
+0015 %   K = IS.computeKernel(kernel, gamma, maxlag, scaleopt)
+0016 % kernel can be one of 'linear' (default),'rbf','chi','xcorr','spearman',
+0017 % 'correlation','cosine','euclidean','seuclidean','mahalanobis'
+0018 %Get the training kernel with indexes in the trainidx vector
+0019 %   Ktrain = IS.getTrainKernel(trainidx)
+0020 %Get the test kernel with test indexes testidx and train indexes trainidx
+0021 %   Ktest = IS.getTestKernel(trainidx, testidx)
+0022 %Get instances of specific indices in vector idx
+0023 %   instance = IS.getInstancesWithIndices(idx)
+0024 %Get the instances of a specific label
+0025 %   instances = IS.getInstancesForLabel(label)
+0026 %Get the indices corresponding to a specific label
+0027 %   indices = IS.getInstanceIndicesForLabel(label)
+0028 %Get the instances including the labels as the last row
+0029 %   dataset = getDataset(IS)
+0030 %Get the instances with specific indices. The last column of the matrix
+0031 %will contain the label.
+0032 %   dataset = IS.getDatasetWithIndices(idx)
+0033 %Remove instances with specific indices. A new InstanceSet object is
+0034 %returned by this function without the specified instances
+0035 %   IS = IS.removeInstancesWithIndices(idx)
+0036 % Write the dataset to a csv file
+0037 %   IS.writeCSV(csvname)
+0038 %Write the dataset to a weka-readable file (arff). The whole dataset is
+0039 %written if the indices are not given (function called with 1 argument)
+0040 %   IS.writeArff(fname, indices)
+0041 
+0042 classdef InstanceSet
+0043     properties (Access = public)
+0044         instances; % the instances
+0045         labels; % the labels
+0046         K; % the kernel of the instances
+0047     end
+0048     
+0049     methods
+0050         function IS = InstanceSet(instances, labels)
+0051             % obj = InstanceSet(instances, labels)
+0052             
+0053             if nargin == 1
+0054                 [~, cols] = size(instances);
+0055                 IS.instances = instances(:,1:cols-1);
+0056                 IS.labels = instances(:,cols);
+0057             elseif nargin==2
+0058                 IS.instances = instances;
+0059                 IS.labels = floor(labels);
+0060             end
+0061             %             for i=1:size(IS.instances,1)
+0062             %                 IS.instances(i,:) = IS.instances(i,:)./norm(IS.instances(i,:));
+0063             %             end
+0064         end
+0065         
+0066         function instances = getInstances(IS)
+0067             % get the instances
+0068             instances = IS.instances;
+0069         end
+0070         
+0071         function K = computeKernel(IS,kernel, gamma, maxlag, scaleopt)
+0072             switch kernel
+0073                 case 'linear'
+0074                     K = IS.instances*IS.instances';
+0075                 case 'rbf'
+0076                     dist = pdist2(IS.instances,IS.instances).^2;
+0077                     %                     N = size(IS.instances,1);
+0078                     %                     dist = repmat(sum(IS.instances.^2, 2)', [N 1])' + ...
+0079                     %                         repmat(sum(IS.instances.^2,2)', [N 1]) - ...
+0080                     %                         2.*IS.instances*IS.instances';
+0081                     K = exp(-gamma.*dist);
+0082                 case 'chi'
+0083                     m = size(IS.instances,1);
+0084                     n = size(IS.instances,1);
+0085                     mOnes = ones(1,m); D = zeros(m,n);
+0086                     for i=1:n
+0087                         yi = IS.instances(i,:);  yiRep = yi( mOnes, : );
+0088                         s = yiRep + IS.instances;    d = yiRep - IS.instances;
+0089                         D(:,i) = sum( d.^2 ./ (s+eps), 2 );
+0090                     end
+0091                     D = D/2;
+0092                     K = exp(-gamma.*D);
+0093                     %                     error('chi kernel not implemented yet');
+0094                 case 'xcorr'
+0095                     K = zeros(size(IS.instances,1));
+0096                     if size(IS.instances,2) < 500 % if memory allows it go for the vectorized version
+0097                         a = xcorr(IS.instances',maxlag,scaleopt);
+0098                         c = reshape(a, 2*maxlag+1, size(IS.instances,1), size(IS.instances,1));
+0099                         if size(c,1) == 1 % no max is required
+0100                             K = squeeze(c);
+0101                         else
+0102                             K = squeeze(max(c));
+0103                         end
+0104                     else
+0105                         for i=1:size(IS.instances,1)
+0106                             for j=i:size(IS.instances,1)
+0107                                 K(i,j)=max(xcorr(IS.instances(i,:),IS.instances(j,:),maxlag,scaleopt));
+0108                                 K(j,i)=K(i,j);
+0109                             end
+0110                         end
+0111                     end
+0112                 case {'spearman','correlation','cosine'}
+0113                     dist = pdist2(IS.instances,IS.instances,kernel);
+0114                     K = 1-dist;
+0115                 case {'euclidean','seuclidean','mahalanobis'}
+0116                     dist = pdist2(IS.instances,IS.instances,kernel).^2;
+0117                     K = exp(-gamma.*dist);
+0118                 otherwise % if not one of the above, it can either be any value of distance in pdist2 or a function handle
+0119                     dist = pdist2(IS.instances,IS.instances,kernel);
+0120                     K = exp(-gamma.*dist);
+0121             end
+0122         end
+0123         
+0124         function Ktrain = getTrainKernel(IS, trainidx)
+0125             Ktrain = IS.K(trainidx,trainidx);
+0126         end
+0127         
+0128         function Ktest = getTestKernel(IS, trainidx, testidx)
+0129             Ktest = IS.K(testidx,trainidx);
+0130         end
+0131         
+0132         function instance = getInstancesWithIndices(IS, idx)
+0133             % get instances of specific indices
+0134             instance = IS.instances(idx,:);
+0135         end
+0136         function labels = getLabels(IS)
+0137             % get the labels
+0138             labels = IS.labels;
+0139         end
+0140         
+0141         function numLabels = getNumLabels(IS)
+0142             % get the number of labels
+0143             numLabels = length(unique(IS.getLabels()));
+0144         end
+0145         
+0146         function numInstances = getNumInstances(IS)
+0147             % get the number of instances
+0148             [numInstances,~] = size(IS.instances);
+0149         end
+0150         
+0151         function numFeatures = getNumFeatures(IS)
+0152             % get the number of features
+0153             [~, numFeatures] = size(IS.instances);
+0154         end
+0155         
+0156         
+0157         function instances = getInstancesForLabel(IS, label)
+0158             % get the instances of a specific label
+0159             indices = IS.getInstanceIndicesForLabel(label);
+0160             instances = IS.getInstances();
+0161             instances = instances(indices,:);
+0162         end
+0163         
+0164         function indices = getInstanceIndicesForLabel(IS,label)
+0165             % get the indices corresponding to a specific label
+0166             [indices, ~] = find(IS.getDataset()==label);
+0167         end
+0168         
+0169         function dataset = getDataset(IS)
+0170             % same with getInstances but includes the labels as the last
+0171             % row
+0172             dataset = horzcat(IS.instances,IS.labels);
+0173         end
+0174         
+0175         function dataset = getDatasetWithIndices(IS,idx)
+0176             % get the instances with specific indices. The last column of
+0177             % the matrix will contain the label.
+0178             instance = IS.instances(idx,:);
+0179             label = IS.labels(idx,:);
+0180             dataset = horzcat(instance,label);
+0181         end
+0182         function IS = removeInstancesWithIndices(IS, idx)
+0183             % remove instances with specific indices. A new InstanceSet
+0184             % object is returned by this functioned without the specified
+0185             % instances
+0186             IS.instances(idx,:) = [];
+0187             IS.labels(idx,:) = [];
+0188         end
+0189         function writeCSV(IS, csvname)
+0190             % write the dataset to a csv file
+0191             % Example:
+0192             %   obj.writeCSV('data.csv');
+0193             csvwrite(csvname, IS.getDataset());
+0194         end
+0195         function writeArff(IS, fname, indices)
+0196             % write the dataset to a weka-readable file (arff)
+0197             % Caution: filename without extension
+0198             % Example:
+0199             %   obj.writeArff('data')
+0200             if nargin==3
+0201                 data1 = IS.getDatasetWithIndices(indices);
+0202                 is1 = eegtoolkit.util.InstanceSet(data1);
+0203                 data2 = IS.getDatasetWithIndices(~indices);
+0204                 is2 = eegtoolkit.util.InstanceSet(data2);
+0205                 is1.writeArff(sprintf('test%s', fname));
+0206                 is2.writeArff(sprintf('train%s',fname));
+0207                 return;
+0208             else
+0209                 data = IS.getDataset();
+0210             end
+0211             %             data = horzcat(IS.instances,floor(IS.labels));
+0212             sss=size(data,2)-1;
+0213             filename1=strcat(fname,'.arff');
+0214             out1 = fopen (filename1, 'w+');
+0215             aa1=strcat('@relation',{' '},fname,'-weka.filters.unsupervised.attribute.NumericToNominal-Rlast');
+0216             fprintf (out1, '%s\n', char(aa1));
+0217             for jj=1:sss
+0218                 fprintf (out1, '@attribute %s numeric\n',num2str(jj));
+0219             end
+0220             n_classes=max(unique(data(:,end)));
+0221             txt1=strcat('@attribute',{' '},num2str(sss+1),{' {'});
+0222             
+0223             for ii=1:n_classes
+0224                 txt1=strcat(txt1,num2str(ii),{','});
+0225             end
+0226             txt1=strcat(txt1,{'}'});
+0227             
+0228             fprintf (out1, '%s\n\n',char(txt1));
+0229             fprintf (out1,'@data\n');
+0230             
+0231             fclose(out1);
+0232             
+0233             dlmwrite (filename1, data, '-append' );
+0234         end
+0235     end
+0236     
+0237 end
+0238
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.m b/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.m new file mode 100644 index 0000000..fbe2fc4 --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/InstanceSet.m @@ -0,0 +1,238 @@ +% A class for describing a set of instances and labels +% +% Properties: +% -instances : a m x n matrix where m = # instances and n = +% # features +% -labels: a m x 1 matrix containing the labels for each +% instance +% -K: a m x m matrix containing the kernel of the instances +% required only for the Fast vesrion of LibSVM +% +% Functions: +%Construct an instanceSet +% IS = eegtoolkit.util.InstanceSet(instances, labels) +%Compute the kernel +% K = IS.computeKernel(kernel, gamma, maxlag, scaleopt) +% kernel can be one of 'linear' (default),'rbf','chi','xcorr','spearman', +% 'correlation','cosine','euclidean','seuclidean','mahalanobis' +%Get the training kernel with indexes in the trainidx vector +% Ktrain = IS.getTrainKernel(trainidx) +%Get the test kernel with test indexes testidx and train indexes trainidx +% Ktest = IS.getTestKernel(trainidx, testidx) +%Get instances of specific indices in vector idx +% instance = IS.getInstancesWithIndices(idx) +%Get the instances of a specific label +% instances = IS.getInstancesForLabel(label) +%Get the indices corresponding to a specific label +% indices = IS.getInstanceIndicesForLabel(label) +%Get the instances including the labels as the last row +% dataset = getDataset(IS) +%Get the instances with specific indices. The last column of the matrix +%will contain the label. +% dataset = IS.getDatasetWithIndices(idx) +%Remove instances with specific indices. A new InstanceSet object is +%returned by this function without the specified instances +% IS = IS.removeInstancesWithIndices(idx) +% Write the dataset to a csv file +% IS.writeCSV(csvname) +%Write the dataset to a weka-readable file (arff). The whole dataset is +%written if the indices are not given (function called with 1 argument) +% IS.writeArff(fname, indices) + +classdef InstanceSet + properties (Access = public) + instances; % the instances + labels; % the labels + K; % the kernel of the instances + end + + methods + function IS = InstanceSet(instances, labels) + % obj = InstanceSet(instances, labels) + + if nargin == 1 + [~, cols] = size(instances); + IS.instances = instances(:,1:cols-1); + IS.labels = instances(:,cols); + elseif nargin==2 + IS.instances = instances; + IS.labels = floor(labels); + end + % for i=1:size(IS.instances,1) + % IS.instances(i,:) = IS.instances(i,:)./norm(IS.instances(i,:)); + % end + end + + function instances = getInstances(IS) + % get the instances + instances = IS.instances; + end + + function K = computeKernel(IS,kernel, gamma, maxlag, scaleopt) + switch kernel + case 'linear' + K = IS.instances*IS.instances'; + case 'rbf' + dist = pdist2(IS.instances,IS.instances).^2; + % N = size(IS.instances,1); + % dist = repmat(sum(IS.instances.^2, 2)', [N 1])' + ... + % repmat(sum(IS.instances.^2,2)', [N 1]) - ... + % 2.*IS.instances*IS.instances'; + K = exp(-gamma.*dist); + case 'chi' + m = size(IS.instances,1); + n = size(IS.instances,1); + mOnes = ones(1,m); D = zeros(m,n); + for i=1:n + yi = IS.instances(i,:); yiRep = yi( mOnes, : ); + s = yiRep + IS.instances; d = yiRep - IS.instances; + D(:,i) = sum( d.^2 ./ (s+eps), 2 ); + end + D = D/2; + K = exp(-gamma.*D); + % error('chi kernel not implemented yet'); + case 'xcorr' + K = zeros(size(IS.instances,1)); + if size(IS.instances,2) < 500 % if memory allows it go for the vectorized version + a = xcorr(IS.instances',maxlag,scaleopt); + c = reshape(a, 2*maxlag+1, size(IS.instances,1), size(IS.instances,1)); + if size(c,1) == 1 % no max is required + K = squeeze(c); + else + K = squeeze(max(c)); + end + else + for i=1:size(IS.instances,1) + for j=i:size(IS.instances,1) + K(i,j)=max(xcorr(IS.instances(i,:),IS.instances(j,:),maxlag,scaleopt)); + K(j,i)=K(i,j); + end + end + end + case {'spearman','correlation','cosine'} + dist = pdist2(IS.instances,IS.instances,kernel); + K = 1-dist; + case {'euclidean','seuclidean','mahalanobis'} + dist = pdist2(IS.instances,IS.instances,kernel).^2; + K = exp(-gamma.*dist); + otherwise % if not one of the above, it can either be any value of distance in pdist2 or a function handle + dist = pdist2(IS.instances,IS.instances,kernel); + K = exp(-gamma.*dist); + end + end + + function Ktrain = getTrainKernel(IS, trainidx) + Ktrain = IS.K(trainidx,trainidx); + end + + function Ktest = getTestKernel(IS, trainidx, testidx) + Ktest = IS.K(testidx,trainidx); + end + + function instance = getInstancesWithIndices(IS, idx) + % get instances of specific indices + instance = IS.instances(idx,:); + end + function labels = getLabels(IS) + % get the labels + labels = IS.labels; + end + + function numLabels = getNumLabels(IS) + % get the number of labels + numLabels = length(unique(IS.getLabels())); + end + + function numInstances = getNumInstances(IS) + % get the number of instances + [numInstances,~] = size(IS.instances); + end + + function numFeatures = getNumFeatures(IS) + % get the number of features + [~, numFeatures] = size(IS.instances); + end + + + function instances = getInstancesForLabel(IS, label) + % get the instances of a specific label + indices = IS.getInstanceIndicesForLabel(label); + instances = IS.getInstances(); + instances = instances(indices,:); + end + + function indices = getInstanceIndicesForLabel(IS,label) + % get the indices corresponding to a specific label + [indices, ~] = find(IS.getDataset()==label); + end + + function dataset = getDataset(IS) + % same with getInstances but includes the labels as the last + % row + dataset = horzcat(IS.instances,IS.labels); + end + + function dataset = getDatasetWithIndices(IS,idx) + % get the instances with specific indices. The last column of + % the matrix will contain the label. + instance = IS.instances(idx,:); + label = IS.labels(idx,:); + dataset = horzcat(instance,label); + end + function IS = removeInstancesWithIndices(IS, idx) + % remove instances with specific indices. A new InstanceSet + % object is returned by this functioned without the specified + % instances + IS.instances(idx,:) = []; + IS.labels(idx,:) = []; + end + function writeCSV(IS, csvname) + % write the dataset to a csv file + % Example: + % obj.writeCSV('data.csv'); + csvwrite(csvname, IS.getDataset()); + end + function writeArff(IS, fname, indices) + % write the dataset to a weka-readable file (arff) + % Caution: filename without extension + % Example: + % obj.writeArff('data') + if nargin==3 + data1 = IS.getDatasetWithIndices(indices); + is1 = eegtoolkit.util.InstanceSet(data1); + data2 = IS.getDatasetWithIndices(~indices); + is2 = eegtoolkit.util.InstanceSet(data2); + is1.writeArff(sprintf('test%s', fname)); + is2.writeArff(sprintf('train%s',fname)); + return; + else + data = IS.getDataset(); + end + % data = horzcat(IS.instances,floor(IS.labels)); + sss=size(data,2)-1; + filename1=strcat(fname,'.arff'); + out1 = fopen (filename1, 'w+'); + aa1=strcat('@relation',{' '},fname,'-weka.filters.unsupervised.attribute.NumericToNominal-Rlast'); + fprintf (out1, '%s\n', char(aa1)); + for jj=1:sss + fprintf (out1, '@attribute %s numeric\n',num2str(jj)); + end + n_classes=max(unique(data(:,end))); + txt1=strcat('@attribute',{' '},num2str(sss+1),{' {'}); + + for ii=1:n_classes + txt1=strcat(txt1,num2str(ii),{','}); + end + txt1=strcat(txt1,{'}'}); + + fprintf (out1, '%s\n\n',char(txt1)); + fprintf (out1,'@data\n'); + + fclose(out1); + + dlmwrite (filename1, data, '-append' ); + end + end + +end + diff --git a/doc/+eegtoolkit/+util/@InstanceSet/graph.dot b/doc/+eegtoolkit/+util/@InstanceSet/graph.dot new file mode 100644 index 0000000..4199c12 --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + InstanceSet -> InstanceSet; + + InstanceSet [URL="InstanceSet.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@InstanceSet/graph.html b/doc/+eegtoolkit/+util/@InstanceSet/graph.html new file mode 100644 index 0000000..8886ce7 --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@InstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@InstanceSet >
+

Dependency Graph for +eegtoolkit/+util/@InstanceSet

+ +
+Dependency Graph for +eegtoolkit/+util/@InstanceSet + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@InstanceSet/graph.map b/doc/+eegtoolkit/+util/@InstanceSet/graph.map new file mode 100644 index 0000000..9544beb --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@InstanceSet/graph.png b/doc/+eegtoolkit/+util/@InstanceSet/graph.png new file mode 100644 index 0000000..d6e3895 Binary files /dev/null and b/doc/+eegtoolkit/+util/@InstanceSet/graph.png differ diff --git a/doc/+eegtoolkit/+util/@InstanceSet/index.html b/doc/+eegtoolkit/+util/@InstanceSet/index.html new file mode 100644 index 0000000..44ae4e8 --- /dev/null +++ b/doc/+eegtoolkit/+util/@InstanceSet/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@InstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@InstanceSet >
+ +

Index for +eegtoolkit/+util/@InstanceSet

+ +

Matlab files in this directory:

+ +
 InstanceSetA class for describing a set of instances and labels
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.html b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.html new file mode 100644 index 0000000..aa29b95 --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.html @@ -0,0 +1,125 @@ + + + + Description of L1MCCAInstanceSet + + + + + + + + + +
Home > +eegtoolkit > +util > @L1MCCAInstanceSet > L1MCCAInstanceSet.m
+ + + +

L1MCCAInstanceSet +

+ +

PURPOSE ^

+
RESULTSET class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 RESULTSET class
+ Stores the results of an experiment
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

L1MCCAInstanceSet.m

+

SOURCE CODE ^

+
0001 % RESULTSET class
+0002 % Stores the results of an experiment
+0003 classdef L1MCCAInstanceSet < eegtoolkit.util.InstanceSet
+0004     
+0005     properties
+0006         matrix4D;
+0007         labelss;
+0008     end
+0009     
+0010     methods
+0011         function L1 = L1MCCAInstanceSet(trials)
+0012             %Constructor method
+0013             %Input:
+0014             %(InstanceSet object): the original instanceSet
+0015             %Labels: a vector containing the output labels of the
+0016             %experiment
+0017             %Proababilities: a vector containing the probabilities of each
+0018             %label
+0019             %Ranking (optional): a matrix containing a score for each label
+0020             L1 = L1@eegtoolkit.util.InstanceSet(zeros(1,1000),ones(1,1000));
+0021             if(nargin>0)
+0022                 numTrials = length(trials);
+0023                 lbls = zeros(numTrials,1);
+0024                 for i=1:numTrials
+0025                     lbls(i) = trials{i}.label;
+0026                 end
+0027 
+0028                 L1.labelss = lbls;
+0029                 [numChannels, numSamples] = size(trials{1}.signal);
+0030                 
+0031                 L1.matrix4D = zeros(numChannels,numSamples,numTrials,1);
+0032                 
+0033                 for i=1:numTrials
+0034                     L1.matrix4D(:,:,i) = trials{i}.signal;
+0035                 end
+0036             end
+0037 
+0038         end
+0039         
+0040         function newL1 = removeInstancesWithIndices(L1,indices)
+0041             newL1 = eegtoolkit.util.L1MCCAInstanceSet;
+0042             newL1.labelss = L1.labelss;
+0043             newL1.labelss(indices) = [];
+0044             newL1.matrix4D = L1.matrix4D;
+0045             newL1.matrix4D(:,:,indices) = [];
+0046         end
+0047         
+0048         function instances = getInstancesWithIndices(L1,indices)
+0049             instances = L1.matrix4D(:,:,indices);
+0050         end
+0051         
+0052         function dataset = getDatasetWithIndices(L1,indices)
+0053             instances = zeros(length(indices),1000);
+0054             labels = L1.labelss(indices);
+0055             dataset = horzcat(instances,labels);
+0056         end
+0057         
+0058         function numInstances = getNumInstances(L1)
+0059             [~,~,numInstances] = size(L1.matrix4D);
+0060         end
+0061         
+0062         function dataset = getDataset(L1)
+0063             instances = zeros(L1.getNumInstances,1000);
+0064             labels = L1.labelss;
+0065             dataset = horzcat(instances,labels);
+0066         end
+0067             
+0068         function numLabels = getNumLabels(L1)
+0069             numLabels = length(unique(L1.labelss));
+0070         end
+0071     end
+0072     
+0073 end
+0074
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.m b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.m new file mode 100644 index 0000000..bda3877 --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/L1MCCAInstanceSet.m @@ -0,0 +1,74 @@ +% RESULTSET class +% Stores the results of an experiment +classdef L1MCCAInstanceSet < eegtoolkit.util.InstanceSet + + properties + matrix4D; + labelss; + end + + methods + function L1 = L1MCCAInstanceSet(trials) + %Constructor method + %Input: + %(InstanceSet object): the original instanceSet + %Labels: a vector containing the output labels of the + %experiment + %Proababilities: a vector containing the probabilities of each + %label + %Ranking (optional): a matrix containing a score for each label + L1 = L1@eegtoolkit.util.InstanceSet(zeros(1,1000),ones(1,1000)); + if(nargin>0) + numTrials = length(trials); + lbls = zeros(numTrials,1); + for i=1:numTrials + lbls(i) = trials{i}.label; + end + + L1.labelss = lbls; + [numChannels, numSamples] = size(trials{1}.signal); + + L1.matrix4D = zeros(numChannels,numSamples,numTrials,1); + + for i=1:numTrials + L1.matrix4D(:,:,i) = trials{i}.signal; + end + end + + end + + function newL1 = removeInstancesWithIndices(L1,indices) + newL1 = eegtoolkit.util.L1MCCAInstanceSet; + newL1.labelss = L1.labelss; + newL1.labelss(indices) = []; + newL1.matrix4D = L1.matrix4D; + newL1.matrix4D(:,:,indices) = []; + end + + function instances = getInstancesWithIndices(L1,indices) + instances = L1.matrix4D(:,:,indices); + end + + function dataset = getDatasetWithIndices(L1,indices) + instances = zeros(length(indices),1000); + labels = L1.labelss(indices); + dataset = horzcat(instances,labels); + end + + function numInstances = getNumInstances(L1) + [~,~,numInstances] = size(L1.matrix4D); + end + + function dataset = getDataset(L1) + instances = zeros(L1.getNumInstances,1000); + labels = L1.labelss; + dataset = horzcat(instances,labels); + end + + function numLabels = getNumLabels(L1) + numLabels = length(unique(L1.labelss)); + end + end + +end + diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.dot b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.dot new file mode 100644 index 0000000..0498a3e --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + L1MCCAInstanceSet -> L1MCCAInstanceSet; + + L1MCCAInstanceSet [URL="L1MCCAInstanceSet.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.html b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.html new file mode 100644 index 0000000..d7e0f7e --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@L1MCCAInstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@L1MCCAInstanceSet >
+

Dependency Graph for +eegtoolkit/+util/@L1MCCAInstanceSet

+ +
+Dependency Graph for +eegtoolkit/+util/@L1MCCAInstanceSet + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.map b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.map new file mode 100644 index 0000000..69774f9 --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.png b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.png new file mode 100644 index 0000000..84c4f28 Binary files /dev/null and b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/graph.png differ diff --git a/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/index.html b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/index.html new file mode 100644 index 0000000..a38792d --- /dev/null +++ b/doc/+eegtoolkit/+util/@L1MCCAInstanceSet/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@L1MCCAInstanceSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@L1MCCAInstanceSet >
+ +

Index for +eegtoolkit/+util/@L1MCCAInstanceSet

+ +

Matlab files in this directory:

+ +
 L1MCCAInstanceSetRESULTSET class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.html b/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.html new file mode 100644 index 0000000..ab5ce4a --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.html @@ -0,0 +1,310 @@ + + + + Description of LSLWrapper + + + + + + + + + +
Home > +eegtoolkit > +util > @LSLWrapper > LSLWrapper.m
+ + + +

LSLWrapper +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

LSLWrapper.m

+

SOURCE CODE ^

+
0001 classdef LSLWrapper < handle
+0002     %LSLWRAPPER Summary of this class goes here
+0003     %   Detailed explanation goes here
+0004     
+0005     properties
+0006         lib;
+0007         datastreaminfo;
+0008         datainlet;
+0009         dataoutlet;
+0010         eventstreaminfo;
+0011         eventinlet;
+0012         eventoutlet;
+0013         preprocessing;
+0014         featextraction;
+0015         results;
+0016         trials;
+0017         classification; %pre-trained object required
+0018     end
+0019     
+0020     properties (Access = private)
+0021         streamsOK;
+0022         samplingRate;
+0023     end
+0024     
+0025     methods
+0026         function LSL = LSLWrapper()
+0027             LSL.lib = lsl_loadlib;
+0028             LSL.streamsOK = 0;
+0029         end
+0030         
+0031         function LSL = resolveStreams(LSL,datastream,maxbuffer,eventstream)
+0032             LSL.datastreaminfo = lsl_resolve_byprop(LSL.lib, 'name', datastream);
+0033             LSL.eventstreaminfo = lsl_resolve_byprop(LSL.lib, 'name', eventstream);
+0034             %get samplingRate from stream info
+0035             %samplingRate = ?
+0036             if(length(LSL.datastreaminfo) > 0)
+0037                 LSL.datainlet = lsl_inlet(LSL.datastreaminfo{1},maxbuffer);
+0038                 LSL.datainlet.pull_chunk;
+0039             else
+0040                 error('Cannot resolve data stream');
+0041             end
+0042             if(length(LSL.eventstreaminfo) > 0)
+0043                 LSL.eventinlet = lsl_inlet(LSL.eventstreaminfo{1},1);
+0044             else
+0045                 error('Cannot resolve event stream');
+0046             end
+0047             eventoutletInfo = lsl_streaminfo(LSL.lib,'CommandStream','Markers',1,0,'cf_int32','myuniquesourceid23442');
+0048             LSL.eventoutlet = lsl_outlet(eventoutletInfo);
+0049             LSL.samplingRate = LSL.datastreaminfo{1}.nominal_srate;
+0050             LSL.streamsOK = 1;
+0051         end
+0052         function LSL = runExperiment(LSL)
+0053             if(LSL.streamsOK ~=1)
+0054                 error('error: Did you call \"resolveStreams\"?');
+0055             end
+0056             strings = {'abstract','concept','objectives','structure','consortium'};
+0057             labels = {4,2,3,5,1,2,5,4,2,3,1,5,4,3,2,4,1,2,5,3,4,1,3,1,3};
+0058             [12 6.66 7.5 8.57 10];
+0059             8.57,6.66,7.5,10,12
+0060             %structure,concept,objectives,consortiu,abstract
+0061             LSL.trials = {};
+0062             [y,Fs] = audioread('beep-07.wav');
+0063             tts('get ready');
+0064             pause(10);
+0065             for i=1:length(labels)
+0066                 tts(strings{labels{i}});
+0067                 pause(1);
+0068                 sound(y,Fs);
+0069                 pause(5);
+0070                 
+0071                 chunk = LSL.datainlet.pull_chunk;
+0072                 trial = eegtoolkit.util.Trial(chunk,0,LSL.samplingRate,0,0);
+0073                 LSL.trials{length(LSL.trials)+1} = trial;
+0074                 tts('ok');
+0075                 pause(4);
+0076             end
+0077         end
+0078         %EBNeuro_BePLusLTM_192.168.171.81
+0079         function LSL = visualizeDataStream(LSL,windowlength,datastreamname,channel)
+0080             %             import java.util.Qu
+0081             LSL.datastreaminfo = lsl_resolve_byprop(LSL.lib, 'name', datastreamname);
+0082             LSL.datainlet = lsl_inlet(LSL.datastreaminfo{1},windowlength/LSL.datastreaminfo{1}.nominal_srate);
+0083             %             LSL.eventstreaminfo = lsl_resolve_byprop(LSL.lib,'name',eventstreamname);
+0084             
+0085             %             buffer = eegtoolkit.util.CQueue(windowlength);
+0086             % %             buffer.capacity = windowlength;
+0087             buffer = zeros(1,windowlength);
+0088             timestampBuffer = zeros(1,windowlength);
+0089             eventBuffer = zeros(1,windowlength);
+0090             indices = 1:windowlength;
+0091             t = 0 ;
+0092             x = 0 ;
+0093             startSpot = 0;
+0094             %             interv = windowlength; % considering 1000 samples
+0095             step = 0.1 ; % lowering step has a number of cycles and then acquire more data
+0096             k =1;
+0097             firstTimestamp = [];
+0098             while ( 1 )
+0099                 %                 sample = LSL.datainlet.pull_sample;
+0100                 [samples,timestamps] = LSL.datainlet.pull_chunk;
+0101                 if isempty(firstTimestamp)
+0102                     firstTimestamp = timestamps;
+0103                 end
+0104                 [~,numPulled] = size(samples);
+0105                 if(numPulled==0)
+0106                     continue;
+0107                 end
+0108                 %                 buffer.push(sample(1));
+0109                 %                 buffermat = cell2mat(buffer.content);
+0110                 buffer = circshift(buffer,[1,-numPulled]);
+0111                 timestampBuffer = circshift(timestampBuffer,[1,-numPulled]);
+0112                 buffer(windowlength-numPulled+1:end) = samples(channel,:);
+0113                 timestampBuffer(windowlength-numPulled+1:end) = timestamps-firstTimestamp;
+0114                 %                 buffer(windowlength) = sample(1);
+0115                 minBuff = min(buffer(buffer~=0));
+0116                 maxBuff = max(buffer(buffer~=0));
+0117                 plot(timestampBuffer,buffer);
+0118                 axis([ timestampBuffer(1), timestampBuffer(end)+1, minBuff , maxBuff+1 ]);
+0119                 xlabel('Seconds');
+0120                 %                 axis([ timestampBuffer(1), timestampBuffer(end), minBuff , maxBuff ]);
+0121                 grid
+0122                 
+0123                 t = t + step;
+0124                 drawnow;
+0125                 k = k+1;
+0126                 %                 indices = indices + 1;
+0127                 %                 pause(0.01)
+0128             end
+0129         end
+0130         
+0131         function streams = findStreams(LSL,timeout)
+0132             streams = {};
+0133             if(nargin>1)
+0134                 allInfo = lsl_resolve_all(LSL.lib,timeout);
+0135             else
+0136                 allInfo = lsl_resolve_all(LSL.lib);
+0137             end
+0138             for i=1:length(allInfo)
+0139                 streams{i} = allInfo{i}.name;
+0140             end
+0141         end
+0142         function LSL = runSSVEP(LSL,eventStopCode)
+0143             if (LSL.streamsOK ~=1)
+0144                 error('error: Did you call \"resolveStreams\" ?');
+0145             end
+0146             while 1
+0147                 sample = LSL.eventinlet.pull_sample;
+0148                 disp(['sample = ', num2str(sample)]);
+0149                 if(sample==eventStopCode)
+0150                     %                     disp('Collecting signal...');
+0151                     pause(5);
+0152                     %                     disp('Processing...');
+0153                     chunk = LSL.datainlet.pull_chunk;
+0154                     trial = {eegtoolkit.util.Trial(chunk,0,LSL.samplingRate,0,0)};
+0155                     for i=1:length(LSL.preprocessing)
+0156                         trial = LSL.preprocessing{i}.process(trial);
+0157                     end
+0158                     LSL.featextraction.trials = trial;
+0159                     LSL.featextraction.extract;
+0160                     [output, prob, rank] = LSL.classification.classifyInstance(LSL.featextraction.getInstances);
+0161                     result = 0;
+0162                     %                     plot(chunk')
+0163                     rank
+0164                     LSL.results = [LSL.results,output];
+0165                     disp(['classif output = ', num2str(output)]);
+0166                     %                     LSL.eventoutlet.push_sample(output);
+0167                     LSL.eventoutlet.push_sample(output-1);
+0168                     %                     disp(['prob = ', num2str(prob)]);
+0169                 end
+0170             end
+0171         end
+0172         
+0173     end
+0174     
+0175     methods(Access = private)
+0176         function wav = tts(txt,voice,pace,fs)
+0177             %TTS text to speech.
+0178             %   TTS (TXT) synthesizes speech from string TXT, and speaks it. The audio
+0179             %   format is mono, 16 bit, 16k Hz by default.
+0180             %
+0181             %   WAV = TTS(TXT) does not vocalize but output to the variable WAV.
+0182             %
+0183             %   TTS(TXT,VOICE) uses the specific voice. Use TTS('','List') to see a
+0184             %   list of availble voices. Default is the first voice.
+0185             %
+0186             %   TTS(...,PACE) set the pace of speech to PACE. PACE ranges from
+0187             %   -10 (slowest) to 10 (fastest). Default 0.
+0188             %
+0189             %   TTS(...,FS) set the sampling rate of the speech to FS kHz. FS must be
+0190             %   one of the following: 8000, 11025, 12000, 16000, 22050, 24000, 32000,
+0191             %       44100, 48000. Default 16.
+0192             %
+0193             %   This function requires the Microsoft Win32 Speech API (SAPI).
+0194             %
+0195             %   Examples:
+0196             %       % Speak the text;
+0197             %       tts('I can speak.');
+0198             %       % List availble voices;
+0199             %       tts('I can speak.','List');
+0200             %       % Do not speak out, store the speech in a variable;
+0201             %       w = tts('I can speak.',[],-4,44100);
+0202             %       wavplay(w,44100);
+0203             %
+0204             %   See also WAVREAD, WAVWRITE, WAVPLAY.
+0205             
+0206             % Written by Siyi Deng; 12-21-2007;
+0207             
+0208             if ~ispc, error('Microsoft Win32 SAPI is required.'); end
+0209             if ~ischar(txt), error('First input must be string.'); end
+0210             
+0211             SV = actxserver('SAPI.SpVoice');
+0212             TK = invoke(SV,'GetVoices');
+0213             
+0214             if nargin > 1
+0215                 % Select voice;
+0216                 for k = 0:TK.Count-1
+0217                     if strcmpi(voice,TK.Item(k).GetDescription)
+0218                         SV.Voice = TK.Item(k);
+0219                         break;
+0220                     elseif strcmpi(voice,'list')
+0221                         disp(TK.Item(k).GetDescription);
+0222                     end
+0223                 end
+0224                 % Set pace;
+0225                 if nargin > 2
+0226                     if isempty(pace), pace = 0; end
+0227                     if abs(pace) > 10, pace = sign(pace)*10; end
+0228                     SV.Rate = pace;
+0229                 end
+0230             end
+0231             
+0232             if nargin < 4 || ~ismember(fs,[8000,11025,12000,16000,22050,24000,32000,...
+0233                     44100,48000]), fs = 16000; end
+0234             
+0235             if nargout > 0
+0236                 % Output variable;
+0237                 MS = actxserver('SAPI.SpMemoryStream');
+0238                 MS.Format.Type = sprintf('SAFT%dkHz16BitMono',fix(fs/1000));
+0239                 SV.AudioOutputStream = MS;
+0240             end
+0241             
+0242             invoke(SV,'Speak',txt);
+0243             
+0244             if nargout > 0
+0245                 % Convert uint8 to double precision;
+0246                 wav = reshape(double(invoke(MS,'GetData')),2,[])';
+0247                 wav = (wav(:,2)*256+wav(:,1))/32768;
+0248                 wav(wav >= 1) = wav(wav >= 1)-2;
+0249                 delete(MS);
+0250                 clear MS;
+0251             end
+0252             
+0253             delete(SV);
+0254             clear SV TK;
+0255             pause(0.2);
+0256             
+0257         end % TTS;
+0258     end
+0259 end
+0260
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.m b/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.m new file mode 100644 index 0000000..92166c1 --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/LSLWrapper.m @@ -0,0 +1,260 @@ +classdef LSLWrapper < handle + %LSLWRAPPER Summary of this class goes here + % Detailed explanation goes here + + properties + lib; + datastreaminfo; + datainlet; + dataoutlet; + eventstreaminfo; + eventinlet; + eventoutlet; + preprocessing; + featextraction; + results; + trials; + classification; %pre-trained object required + end + + properties (Access = private) + streamsOK; + samplingRate; + end + + methods + function LSL = LSLWrapper() + LSL.lib = lsl_loadlib; + LSL.streamsOK = 0; + end + + function LSL = resolveStreams(LSL,datastream,maxbuffer,eventstream) + LSL.datastreaminfo = lsl_resolve_byprop(LSL.lib, 'name', datastream); + LSL.eventstreaminfo = lsl_resolve_byprop(LSL.lib, 'name', eventstream); + %get samplingRate from stream info + %samplingRate = ? + if(length(LSL.datastreaminfo) > 0) + LSL.datainlet = lsl_inlet(LSL.datastreaminfo{1},maxbuffer); + LSL.datainlet.pull_chunk; + else + error('Cannot resolve data stream'); + end + if(length(LSL.eventstreaminfo) > 0) + LSL.eventinlet = lsl_inlet(LSL.eventstreaminfo{1},1); + else + error('Cannot resolve event stream'); + end + eventoutletInfo = lsl_streaminfo(LSL.lib,'CommandStream','Markers',1,0,'cf_int32','myuniquesourceid23442'); + LSL.eventoutlet = lsl_outlet(eventoutletInfo); + LSL.samplingRate = LSL.datastreaminfo{1}.nominal_srate; + LSL.streamsOK = 1; + end + function LSL = runExperiment(LSL) + if(LSL.streamsOK ~=1) + error('error: Did you call \"resolveStreams\"?'); + end + strings = {'abstract','concept','objectives','structure','consortium'}; + labels = {4,2,3,5,1,2,5,4,2,3,1,5,4,3,2,4,1,2,5,3,4,1,3,1,3}; + [12 6.66 7.5 8.57 10]; + 8.57,6.66,7.5,10,12 + %structure,concept,objectives,consortiu,abstract + LSL.trials = {}; + [y,Fs] = audioread('beep-07.wav'); + tts('get ready'); + pause(10); + for i=1:length(labels) + tts(strings{labels{i}}); + pause(1); + sound(y,Fs); + pause(5); + + chunk = LSL.datainlet.pull_chunk; + trial = eegtoolkit.util.Trial(chunk,0,LSL.samplingRate,0,0); + LSL.trials{length(LSL.trials)+1} = trial; + tts('ok'); + pause(4); + end + end + %EBNeuro_BePLusLTM_192.168.171.81 + function LSL = visualizeDataStream(LSL,windowlength,datastreamname,channel) + % import java.util.Qu + LSL.datastreaminfo = lsl_resolve_byprop(LSL.lib, 'name', datastreamname); + LSL.datainlet = lsl_inlet(LSL.datastreaminfo{1},windowlength/LSL.datastreaminfo{1}.nominal_srate); + % LSL.eventstreaminfo = lsl_resolve_byprop(LSL.lib,'name',eventstreamname); + + % buffer = eegtoolkit.util.CQueue(windowlength); + % % buffer.capacity = windowlength; + buffer = zeros(1,windowlength); + timestampBuffer = zeros(1,windowlength); + eventBuffer = zeros(1,windowlength); + indices = 1:windowlength; + t = 0 ; + x = 0 ; + startSpot = 0; + % interv = windowlength; % considering 1000 samples + step = 0.1 ; % lowering step has a number of cycles and then acquire more data + k =1; + firstTimestamp = []; + while ( 1 ) + % sample = LSL.datainlet.pull_sample; + [samples,timestamps] = LSL.datainlet.pull_chunk; + if isempty(firstTimestamp) + firstTimestamp = timestamps; + end + [~,numPulled] = size(samples); + if(numPulled==0) + continue; + end + % buffer.push(sample(1)); + % buffermat = cell2mat(buffer.content); + buffer = circshift(buffer,[1,-numPulled]); + timestampBuffer = circshift(timestampBuffer,[1,-numPulled]); + buffer(windowlength-numPulled+1:end) = samples(channel,:); + timestampBuffer(windowlength-numPulled+1:end) = timestamps-firstTimestamp; + % buffer(windowlength) = sample(1); + minBuff = min(buffer(buffer~=0)); + maxBuff = max(buffer(buffer~=0)); + plot(timestampBuffer,buffer); + axis([ timestampBuffer(1), timestampBuffer(end)+1, minBuff , maxBuff+1 ]); + xlabel('Seconds'); + % axis([ timestampBuffer(1), timestampBuffer(end), minBuff , maxBuff ]); + grid + + t = t + step; + drawnow; + k = k+1; + % indices = indices + 1; + % pause(0.01) + end + end + + function streams = findStreams(LSL,timeout) + streams = {}; + if(nargin>1) + allInfo = lsl_resolve_all(LSL.lib,timeout); + else + allInfo = lsl_resolve_all(LSL.lib); + end + for i=1:length(allInfo) + streams{i} = allInfo{i}.name; + end + end + function LSL = runSSVEP(LSL,eventStopCode) + if (LSL.streamsOK ~=1) + error('error: Did you call \"resolveStreams\" ?'); + end + while 1 + sample = LSL.eventinlet.pull_sample; + disp(['sample = ', num2str(sample)]); + if(sample==eventStopCode) + % disp('Collecting signal...'); + pause(5); + % disp('Processing...'); + chunk = LSL.datainlet.pull_chunk; + trial = {eegtoolkit.util.Trial(chunk,0,LSL.samplingRate,0,0)}; + for i=1:length(LSL.preprocessing) + trial = LSL.preprocessing{i}.process(trial); + end + LSL.featextraction.trials = trial; + LSL.featextraction.extract; + [output, prob, rank] = LSL.classification.classifyInstance(LSL.featextraction.getInstances); + result = 0; + % plot(chunk') + rank + LSL.results = [LSL.results,output]; + disp(['classif output = ', num2str(output)]); + % LSL.eventoutlet.push_sample(output); + LSL.eventoutlet.push_sample(output-1); + % disp(['prob = ', num2str(prob)]); + end + end + end + + end + + methods(Access = private) + function wav = tts(txt,voice,pace,fs) + %TTS text to speech. + % TTS (TXT) synthesizes speech from string TXT, and speaks it. The audio + % format is mono, 16 bit, 16k Hz by default. + % + % WAV = TTS(TXT) does not vocalize but output to the variable WAV. + % + % TTS(TXT,VOICE) uses the specific voice. Use TTS('','List') to see a + % list of availble voices. Default is the first voice. + % + % TTS(...,PACE) set the pace of speech to PACE. PACE ranges from + % -10 (slowest) to 10 (fastest). Default 0. + % + % TTS(...,FS) set the sampling rate of the speech to FS kHz. FS must be + % one of the following: 8000, 11025, 12000, 16000, 22050, 24000, 32000, + % 44100, 48000. Default 16. + % + % This function requires the Microsoft Win32 Speech API (SAPI). + % + % Examples: + % % Speak the text; + % tts('I can speak.'); + % % List availble voices; + % tts('I can speak.','List'); + % % Do not speak out, store the speech in a variable; + % w = tts('I can speak.',[],-4,44100); + % wavplay(w,44100); + % + % See also WAVREAD, WAVWRITE, WAVPLAY. + + % Written by Siyi Deng; 12-21-2007; + + if ~ispc, error('Microsoft Win32 SAPI is required.'); end + if ~ischar(txt), error('First input must be string.'); end + + SV = actxserver('SAPI.SpVoice'); + TK = invoke(SV,'GetVoices'); + + if nargin > 1 + % Select voice; + for k = 0:TK.Count-1 + if strcmpi(voice,TK.Item(k).GetDescription) + SV.Voice = TK.Item(k); + break; + elseif strcmpi(voice,'list') + disp(TK.Item(k).GetDescription); + end + end + % Set pace; + if nargin > 2 + if isempty(pace), pace = 0; end + if abs(pace) > 10, pace = sign(pace)*10; end + SV.Rate = pace; + end + end + + if nargin < 4 || ~ismember(fs,[8000,11025,12000,16000,22050,24000,32000,... + 44100,48000]), fs = 16000; end + + if nargout > 0 + % Output variable; + MS = actxserver('SAPI.SpMemoryStream'); + MS.Format.Type = sprintf('SAFT%dkHz16BitMono',fix(fs/1000)); + SV.AudioOutputStream = MS; + end + + invoke(SV,'Speak',txt); + + if nargout > 0 + % Convert uint8 to double precision; + wav = reshape(double(invoke(MS,'GetData')),2,[])'; + wav = (wav(:,2)*256+wav(:,1))/32768; + wav(wav >= 1) = wav(wav >= 1)-2; + delete(MS); + clear MS; + end + + delete(SV); + clear SV TK; + pause(0.2); + + end % TTS; + end +end + diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/graph.dot b/doc/+eegtoolkit/+util/@LSLWrapper/graph.dot new file mode 100644 index 0000000..8119234 --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + LSLWrapper -> LSLWrapper; + + LSLWrapper [URL="LSLWrapper.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/graph.html b/doc/+eegtoolkit/+util/@LSLWrapper/graph.html new file mode 100644 index 0000000..ff0d441 --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@LSLWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@LSLWrapper >
+

Dependency Graph for +eegtoolkit/+util/@LSLWrapper

+ +
+Dependency Graph for +eegtoolkit/+util/@LSLWrapper + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/graph.map b/doc/+eegtoolkit/+util/@LSLWrapper/graph.map new file mode 100644 index 0000000..b230ed0 --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/graph.png b/doc/+eegtoolkit/+util/@LSLWrapper/graph.png new file mode 100644 index 0000000..fcee22c Binary files /dev/null and b/doc/+eegtoolkit/+util/@LSLWrapper/graph.png differ diff --git a/doc/+eegtoolkit/+util/@LSLWrapper/index.html b/doc/+eegtoolkit/+util/@LSLWrapper/index.html new file mode 100644 index 0000000..cc2ab26 --- /dev/null +++ b/doc/+eegtoolkit/+util/@LSLWrapper/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@LSLWrapper + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@LSLWrapper >
+ +

Index for +eegtoolkit/+util/@LSLWrapper

+ +

Matlab files in this directory:

+ +
 LSLWrapper
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.html b/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.html new file mode 100644 index 0000000..327a2f7 --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.html @@ -0,0 +1,112 @@ + + + + Description of RawSignalSet + + + + + + + + + +
Home > +eegtoolkit > +util > @RawSignalSet > RawSignalSet.m
+ + + +

RawSignalSet +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

RawSignalSet.m

+

SOURCE CODE ^

+
0001 classdef RawSignalSet < eegtoolkit.util.InstanceSet
+0002     %RAWSIGNALSET Summary of this class goes here
+0003     %   Detailed explanation goes here
+0004     
+0005     properties
+0006         %numTrials X numChannels X numSamples
+0007         signalMatrix;
+0008     end
+0009     
+0010     methods
+0011         function RSS = RawSignalSet(trials)
+0012             %             RSS = RSS@eegtoolkit.util.InstanceSet(zeros(1,1000),ones(1,1000));
+0013             if(nargin~=1)
+0014                 error('trials parameter not set');
+0015             end
+0016             %             if(nargin>0)
+0017             numTrials = length(trials);
+0018             labels = zeros(numTrials,1);
+0019             for i=1:numTrials
+0020                 labels(i) = trials{i}.label;
+0021             end
+0022             [numChannels, numSamples] = size(trials{i}.signal);
+0023             sMatrix = zeros(numTrials,numChannels,numSamples);
+0024             for i=1:numTrials
+0025                 sMatrix(i,:,:) = trials{i}.signal;
+0026             end
+0027             RSS = RSS@eegtoolkit.util.InstanceSet(squeeze(sMatrix(:,1,:)),labels);
+0028             RSS.signalMatrix = sMatrix;
+0029             %             end
+0030         end
+0031         
+0032         function sMatrix = get(indices)
+0033             sMatrix = squeeze(RSS.signalMatrix(indices,:,:));
+0034         end
+0035         
+0036         function sMatrix = getInstancesWithIndices(RSS,indices)
+0037             sMatrix = RSS.signalMatrix(indices,:,:);
+0038         end
+0039         
+0040         function instanceStruct = removeInstancesWithIndices(RSS,indices)
+0041 %             newRSS = eegtoolkit.util.RawSignalSet;
+0042 %             newRSS.labels = RSS.labels;
+0043 %             newRSS.labels(indices) = [];
+0044 %             newRSS.signalMatrix = RSS.signalMatrix;
+0045 %             newRSS.signalMatrix(indices,:,:) = [];
+0046             sMatrix = RSS.signalMatrix;
+0047             sMatrix(indices,:,:) = [];
+0048             
+0049             labels = RSS.labels;
+0050             labels(indices) = [];
+0051             instanceStruct = struct('sMatrix',sMatrix, 'labels', labels);
+0052         end
+0053         
+0054         function numInstances = getNumInstances(RSS)
+0055             [numInstances,~,~] = size(RSS.signalMatrix);
+0056         end
+0057             
+0058     end
+0059     
+0060     
+0061 end
+0062
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.m b/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.m new file mode 100644 index 0000000..4f963a7 --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/RawSignalSet.m @@ -0,0 +1,62 @@ +classdef RawSignalSet < eegtoolkit.util.InstanceSet + %RAWSIGNALSET Summary of this class goes here + % Detailed explanation goes here + + properties + %numTrials X numChannels X numSamples + signalMatrix; + end + + methods + function RSS = RawSignalSet(trials) + % RSS = RSS@eegtoolkit.util.InstanceSet(zeros(1,1000),ones(1,1000)); + if(nargin~=1) + error('trials parameter not set'); + end + % if(nargin>0) + numTrials = length(trials); + labels = zeros(numTrials,1); + for i=1:numTrials + labels(i) = trials{i}.label; + end + [numChannels, numSamples] = size(trials{i}.signal); + sMatrix = zeros(numTrials,numChannels,numSamples); + for i=1:numTrials + sMatrix(i,:,:) = trials{i}.signal; + end + RSS = RSS@eegtoolkit.util.InstanceSet(squeeze(sMatrix(:,1,:)),labels); + RSS.signalMatrix = sMatrix; + % end + end + + function sMatrix = get(indices) + sMatrix = squeeze(RSS.signalMatrix(indices,:,:)); + end + + function sMatrix = getInstancesWithIndices(RSS,indices) + sMatrix = RSS.signalMatrix(indices,:,:); + end + + function instanceStruct = removeInstancesWithIndices(RSS,indices) +% newRSS = eegtoolkit.util.RawSignalSet; +% newRSS.labels = RSS.labels; +% newRSS.labels(indices) = []; +% newRSS.signalMatrix = RSS.signalMatrix; +% newRSS.signalMatrix(indices,:,:) = []; + sMatrix = RSS.signalMatrix; + sMatrix(indices,:,:) = []; + + labels = RSS.labels; + labels(indices) = []; + instanceStruct = struct('sMatrix',sMatrix, 'labels', labels); + end + + function numInstances = getNumInstances(RSS) + [numInstances,~,~] = size(RSS.signalMatrix); + end + + end + + +end + diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/graph.dot b/doc/+eegtoolkit/+util/@RawSignalSet/graph.dot new file mode 100644 index 0000000..c3e43b9 --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + RawSignalSet -> RawSignalSet; + + RawSignalSet [URL="RawSignalSet.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/graph.html b/doc/+eegtoolkit/+util/@RawSignalSet/graph.html new file mode 100644 index 0000000..653ae7a --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@RawSignalSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@RawSignalSet >
+

Dependency Graph for +eegtoolkit/+util/@RawSignalSet

+ +
+Dependency Graph for +eegtoolkit/+util/@RawSignalSet + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/graph.map b/doc/+eegtoolkit/+util/@RawSignalSet/graph.map new file mode 100644 index 0000000..880bbfc --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/graph.png b/doc/+eegtoolkit/+util/@RawSignalSet/graph.png new file mode 100644 index 0000000..8587a1a Binary files /dev/null and b/doc/+eegtoolkit/+util/@RawSignalSet/graph.png differ diff --git a/doc/+eegtoolkit/+util/@RawSignalSet/index.html b/doc/+eegtoolkit/+util/@RawSignalSet/index.html new file mode 100644 index 0000000..de2b1bd --- /dev/null +++ b/doc/+eegtoolkit/+util/@RawSignalSet/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@RawSignalSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@RawSignalSet >
+ +

Index for +eegtoolkit/+util/@RawSignalSet

+ +

Matlab files in this directory:

+ +
 RawSignalSet
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@ResultSet/ResultSet.html b/doc/+eegtoolkit/+util/@ResultSet/ResultSet.html new file mode 100644 index 0000000..e347983 --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/ResultSet.html @@ -0,0 +1,111 @@ + + + + Description of ResultSet + + + + + + + + + +
Home > +eegtoolkit > +util > @ResultSet > ResultSet.m
+ + + +

ResultSet +

+ +

PURPOSE ^

+
RESULTSET class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 RESULTSET class
+ Stores the results of an experiment
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

ResultSet.m

+

SOURCE CODE ^

+
0001 % RESULTSET class
+0002 % Stores the results of an experiment
+0003 classdef ResultSet < eegtoolkit.util.InstanceSet
+0004     
+0005     properties
+0006         outputLabels; % The output labels
+0007         outputProbabilities; % Probabilities
+0008         outputRanking; % Confidence scores
+0009         confusionMatrix; % The Confusion Matrix
+0010     end
+0011     
+0012     methods
+0013         function RS = ResultSet(instanceSet, labels, probabilities, ranking)
+0014             %Constructor method
+0015             %Input:
+0016             %(InstanceSet object): the original instanceSet
+0017             %Labels: a vector containing the output labels of the
+0018             %experiment
+0019             %Proababilities: a vector containing the probabilities of each
+0020             %label
+0021             %Ranking (optional): a matrix containing a score for each label
+0022             
+0023             RS = RS@eegtoolkit.util.InstanceSet(instanceSet);
+0024             RS.outputLabels = labels;
+0025 
+0026             %compute the confusion matrix
+0027             labels = unique(RS.getLabels);
+0028             numLabels = length(labels);
+0029             RS.confusionMatrix = zeros(numLabels);
+0030             trueLabels = RS.getLabels;
+0031             numInstances = RS.getNumInstances;
+0032             for k=1:numInstances
+0033                 idx1 = find(labels==RS.outputLabels(k,1));
+0034                 idx2 = find(labels==trueLabels(k,1));
+0035                 RS.confusionMatrix(idx1,idx2) = RS.confusionMatrix(idx1,idx2)+ 1;
+0036             end
+0037             RS.confusionMatrix = RS.confusionMatrix';
+0038             %if classifier supports ranking/probabilities
+0039             if nargin > 2
+0040                 RS.outputProbabilities = probabilities;
+0041                 RS.outputRanking = ranking;
+0042             end
+0043         end
+0044         
+0045         function RSSubset = subset(RS,indices)
+0046             sOutputLabels = RS.outputLabels(indices);
+0047             sOutputProbabilities = RS.outputProbabilities(indices);
+0048             sInstanceSet = RS.getDatasetWithIndices(indices);
+0049             if isempty(RS.outputProbabilities)
+0050                 RSSubset = eegtoolkit.util.ResultSet(sInstanceSet,sOutputLabels,sOutputProbabilities);
+0051             else
+0052                 sOutputRanking = RS.outputRanking(indices);
+0053                 RSSubset = eegtoolkit.util.ResultSet(sInstanceSet,sOutputLabels,sOutputProbabilities,sOutputRanking);
+0054             end
+0055         end
+0056             
+0057     end
+0058     
+0059 end
+0060
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@ResultSet/ResultSet.m b/doc/+eegtoolkit/+util/@ResultSet/ResultSet.m new file mode 100644 index 0000000..01513b4 --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/ResultSet.m @@ -0,0 +1,60 @@ +% RESULTSET class +% Stores the results of an experiment +classdef ResultSet < eegtoolkit.util.InstanceSet + + properties + outputLabels; % The output labels + outputProbabilities; % Probabilities + outputRanking; % Confidence scores + confusionMatrix; % The Confusion Matrix + end + + methods + function RS = ResultSet(instanceSet, labels, probabilities, ranking) + %Constructor method + %Input: + %(InstanceSet object): the original instanceSet + %Labels: a vector containing the output labels of the + %experiment + %Proababilities: a vector containing the probabilities of each + %label + %Ranking (optional): a matrix containing a score for each label + + RS = RS@eegtoolkit.util.InstanceSet(instanceSet); + RS.outputLabels = labels; + + %compute the confusion matrix + labels = unique(RS.getLabels); + numLabels = length(labels); + RS.confusionMatrix = zeros(numLabels); + trueLabels = RS.getLabels; + numInstances = RS.getNumInstances; + for k=1:numInstances + idx1 = find(labels==RS.outputLabels(k,1)); + idx2 = find(labels==trueLabels(k,1)); + RS.confusionMatrix(idx1,idx2) = RS.confusionMatrix(idx1,idx2)+ 1; + end + RS.confusionMatrix = RS.confusionMatrix'; + %if classifier supports ranking/probabilities + if nargin > 2 + RS.outputProbabilities = probabilities; + RS.outputRanking = ranking; + end + end + + function RSSubset = subset(RS,indices) + sOutputLabels = RS.outputLabels(indices); + sOutputProbabilities = RS.outputProbabilities(indices); + sInstanceSet = RS.getDatasetWithIndices(indices); + if isempty(RS.outputProbabilities) + RSSubset = eegtoolkit.util.ResultSet(sInstanceSet,sOutputLabels,sOutputProbabilities); + else + sOutputRanking = RS.outputRanking(indices); + RSSubset = eegtoolkit.util.ResultSet(sInstanceSet,sOutputLabels,sOutputProbabilities,sOutputRanking); + end + end + + end + +end + diff --git a/doc/+eegtoolkit/+util/@ResultSet/graph.dot b/doc/+eegtoolkit/+util/@ResultSet/graph.dot new file mode 100644 index 0000000..08f05cc --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + ResultSet -> ResultSet; + + ResultSet [URL="ResultSet.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@ResultSet/graph.html b/doc/+eegtoolkit/+util/@ResultSet/graph.html new file mode 100644 index 0000000..a650c57 --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@ResultSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@ResultSet >
+

Dependency Graph for +eegtoolkit/+util/@ResultSet

+ +
+Dependency Graph for +eegtoolkit/+util/@ResultSet + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@ResultSet/graph.map b/doc/+eegtoolkit/+util/@ResultSet/graph.map new file mode 100644 index 0000000..8ee72a6 --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@ResultSet/graph.png b/doc/+eegtoolkit/+util/@ResultSet/graph.png new file mode 100644 index 0000000..0a4e763 Binary files /dev/null and b/doc/+eegtoolkit/+util/@ResultSet/graph.png differ diff --git a/doc/+eegtoolkit/+util/@ResultSet/index.html b/doc/+eegtoolkit/+util/@ResultSet/index.html new file mode 100644 index 0000000..3d019eb --- /dev/null +++ b/doc/+eegtoolkit/+util/@ResultSet/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@ResultSet + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@ResultSet >
+ +

Index for +eegtoolkit/+util/@ResultSet

+ +

Matlab files in this directory:

+ +
 ResultSetRESULTSET class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Session/Session.html b/doc/+eegtoolkit/+util/@Session/Session.html new file mode 100644 index 0000000..9649681 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/Session.html @@ -0,0 +1,589 @@ + + + + Description of Session + + + + + + + + + +
Home > +eegtoolkit > +util > @Session > Session.m
+ + + +

Session +

+ +

PURPOSE ^

+
SESSION class
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 SESSION class
+ Session I/O, splitting sessions into trials and applying filters
+
+ Properties:
+ trials: A cell array with the Trials of the loaded sessions.
+ filt: Filter to be applied when data is loaded
+ sessions: Cell array with the filenames of the dataset
+ subjectids: Vector with the subject ids corresponding to the loaded trials
+ sessionids: Vector with the session ids corresponding to the loaded trials
+
+ Functions:
+init a session
+   session = eegtoolkit.util.Session();
+init a session with a filter (created with 'filterbuilder')
+   session = eegtoolkit.util.Session(filt);
+load trials for a subject
+   session.loadSubject(subjectid);
+load a specific session
+   session.loadSubjectSession(subjectid,sessionid);
+load everything
+   session.loadAll();
+clear loaded data
+   session.clearData;
+apply a filter that was created with 'filterbuilder'
+   session.applyFilter(filt);
+
+
+DATASETS
+1. SSVEP Dataset I (SINGLE)
+2. SSVEP Dataset II (MULTI)
+3. SSVEP Dataset III (EPOC-MULTI)
+4. SSVEP Dataset SCCN
+5. ERRP Dataset
+6. MI Dataset
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: + +This function is called by: + + + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Session.m

+

SOURCE CODE ^

+
0001 % SESSION class
+0002 % Session I/O, splitting sessions into trials and applying filters
+0003 %
+0004 % Properties:
+0005 % trials: A cell array with the Trials of the loaded sessions.
+0006 % filt: Filter to be applied when data is loaded
+0007 % sessions: Cell array with the filenames of the dataset
+0008 % subjectids: Vector with the subject ids corresponding to the loaded trials
+0009 % sessionids: Vector with the session ids corresponding to the loaded trials
+0010 %
+0011 % Functions:
+0012 %init a session
+0013 %   session = eegtoolkit.util.Session();
+0014 %init a session with a filter (created with 'filterbuilder')
+0015 %   session = eegtoolkit.util.Session(filt);
+0016 %load trials for a subject
+0017 %   session.loadSubject(subjectid);
+0018 %load a specific session
+0019 %   session.loadSubjectSession(subjectid,sessionid);
+0020 %load everything
+0021 %   session.loadAll();
+0022 %clear loaded data
+0023 %   session.clearData;
+0024 %apply a filter that was created with 'filterbuilder'
+0025 %   session.applyFilter(filt);
+0026 %
+0027 %
+0028 %DATASETS
+0029 %1. SSVEP Dataset I (SINGLE)
+0030 %2. SSVEP Dataset II (MULTI)
+0031 %3. SSVEP Dataset III (EPOC-MULTI)
+0032 %4. SSVEP Dataset SCCN
+0033 %5. ERRP Dataset
+0034 %6. MI Dataset
+0035 
+0036 classdef Session < handle
+0037     
+0038     properties (Constant)
+0039         THRESHOLD_SPLIT_MILLIS = 2000; %Threshold for splitting the trials based on DIN data
+0040     end
+0041     properties (Access = public)
+0042         trials = {}; % Trials of the loaded sessions.
+0043         filt; % Filter to be applied when data is loaded
+0044         sessions; % Filenames of the dataset
+0045         subjectids; % The subject ids corresponding to the loaded trials
+0046         sessionids;
+0047     end
+0048     
+0049     
+0050     methods (Access = public)
+0051         function S = Session()
+0052             %S = eegtoolkit.util.Session();
+0053             %Constructs a session object
+0054             %
+0055             %S = eegtoolkit.util.Session(filt);
+0056             %Constructs a session object. A filter will applied to all
+0057             %loaded trials
+0058             %Dataset I
+0059             S.sessions{1,1,1} = 'S001a';
+0060             S.sessions{1,1,2} = 'S001b';
+0061             S.sessions{1,1,3} = 'S001c';
+0062             S.sessions{1,2,1} = 'S002a';
+0063             S.sessions{1,2,2} = 'S002b';
+0064             S.sessions{1,2,3} = 'S002c';
+0065             S.sessions{1,2,4} = 'S002d';
+0066             S.sessions{1,2,5} = 'S002e';
+0067             S.sessions{1,3,1} = 'S003a';
+0068             S.sessions{1,3,2} = 'S003b';
+0069             S.sessions{1,3,3} = 'S003c';
+0070             S.sessions{1,4,1} = 'S004a';
+0071             S.sessions{1,4,2} = 'S004b';
+0072             S.sessions{1,4,3} = 'S004c';
+0073             S.sessions{1,4,4} = 'S004d';
+0074             S.sessions{1,5,1} = 'S005a';
+0075             S.sessions{1,5,2} = 'S005b';
+0076             S.sessions{1,5,3} = 'S005c';
+0077             S.sessions{1,5,4} = 'S005d';
+0078             S.sessions{1,5,5} = 'S005e';
+0079             S.sessions{1,6,1} = 'S006a';
+0080             S.sessions{1,6,2} = 'S006b';
+0081             S.sessions{1,6,3} = 'S006c';
+0082             S.sessions{1,6,4} = 'S006d';
+0083             S.sessions{1,6,5} = 'S006e';
+0084             S.sessions{1,7,1} = 'S007a';
+0085             S.sessions{1,7,2} = 'S007b';
+0086             S.sessions{1,7,3} = 'S007c';
+0087             S.sessions{1,7,4} = 'S007d';
+0088             S.sessions{1,7,5} = 'S007e';
+0089             S.sessions{1,8,1} = 'S008a';
+0090             S.sessions{1,8,2} = 'S008b';
+0091             S.sessions{1,8,3} = 'S008c';
+0092             S.sessions{1,9,1} = 'S009a';
+0093             S.sessions{1,9,2} = 'S009b';
+0094             S.sessions{1,9,3} = 'S009c';
+0095             S.sessions{1,9,4} = 'S009d';
+0096             S.sessions{1,9,5} = 'S009e';
+0097             S.sessions{1,10,1} = 'S010a';
+0098             S.sessions{1,10,2} = 'S010b';
+0099             S.sessions{1,10,3} = 'S010c';
+0100             S.sessions{1,10,4} = 'S010d';
+0101             S.sessions{1,10,5} = 'S010e';
+0102             S.sessions{1,11,1} = 'S013a';
+0103             S.sessions{1,11,2} = 'S013b';
+0104             S.sessions{1,11,3} = 'S013c';
+0105             S.sessions{1,11,4} = 'S013d';
+0106             S.sessions{1,11,5} = 'S013e';
+0107             
+0108             %Dataset II
+0109             S.sessions{2,1,1} = 'T001a';
+0110             S.sessions{2,1,2} = 'T001b';
+0111             S.sessions{2,1,3} = 'T001c';
+0112             S.sessions{2,1,4} = 'T001d';
+0113             S.sessions{2,1,5} = 'T001e';
+0114             S.sessions{2,2,1} = 'T002a';
+0115             S.sessions{2,2,2} = 'T002b';
+0116             S.sessions{2,2,3} = 'T002c';
+0117             S.sessions{2,2,4} = 'T002d';
+0118             S.sessions{2,2,5} = 'T002e';
+0119             S.sessions{2,3,1} = 'T003a';
+0120             S.sessions{2,3,2} = 'T003b';
+0121             S.sessions{2,3,3} = 'T003c';
+0122             S.sessions{2,3,4} = 'T003d';
+0123             S.sessions{2,3,5} = 'T003e';
+0124             S.sessions{2,4,1} = 'T004a';
+0125             S.sessions{2,4,2} = 'T004b';
+0126             S.sessions{2,4,3} = 'T004c';
+0127             S.sessions{2,4,4} = 'T004d';
+0128             S.sessions{2,4,5} = 'T004e';
+0129             S.sessions{2,5,1} = 'T005a';
+0130             S.sessions{2,5,2} = 'T005b';
+0131             S.sessions{2,5,3} = 'T005c';
+0132             S.sessions{2,5,4} = 'T005d';
+0133             S.sessions{2,5,5} = 'T005e';
+0134             S.sessions{2,6,1} = 'T006a';
+0135             S.sessions{2,6,2} = 'T006b';
+0136             S.sessions{2,6,3} = 'T006c';
+0137             S.sessions{2,6,4} = 'T006d';
+0138             S.sessions{2,6,5} = 'T006e';
+0139             S.sessions{2,7,1} = 'T007a';
+0140             S.sessions{2,7,2} = 'T007b';
+0141             S.sessions{2,7,3} = 'T007c';
+0142             S.sessions{2,7,4} = 'T007d';
+0143             S.sessions{2,7,5} = 'T007e';
+0144             S.sessions{2,8,1} = 'T008a';
+0145             S.sessions{2,8,2} = 'T008b';
+0146             S.sessions{2,8,3} = 'T008c';
+0147             S.sessions{2,8,4} = 'T008d';
+0148             S.sessions{2,8,5} = 'T008e';
+0149             S.sessions{2,9,1} = 'T009a';
+0150             S.sessions{2,9,2} = 'T009b';
+0151             S.sessions{2,9,3} = 'T009c';
+0152             S.sessions{2,9,4} = 'T009d';
+0153             S.sessions{2,9,5} = 'T009e';
+0154             S.sessions{2,10,1} = 'T010a';
+0155             S.sessions{2,10,2} = 'T010b';
+0156             S.sessions{2,10,3} = 'T010c';
+0157             S.sessions{2,10,4} = 'T010d';
+0158             S.sessions{2,10,5} = 'T010e';
+0159             S.sessions{2,11,1} = 'T013a';
+0160             S.sessions{2,11,2} = 'T013b';
+0161             S.sessions{2,11,3} = 'T013c';
+0162             S.sessions{2,11,4} = 'T013d';
+0163             S.sessions{2,11,5} = 'T013e';
+0164             
+0165             %Dataset III (Epoc)
+0166             S.sessions{3,1,1} = 'U001a';
+0167             S.sessions{3,1,2} = 'U001b';
+0168             S.sessions{3,1,3} = 'U001c';
+0169             S.sessions{3,1,4} = 'U001d';
+0170             S.sessions{3,1,5} = 'U001e';
+0171             S.sessions{3,2,1} = 'U002a';
+0172             S.sessions{3,2,2} = 'U002b';
+0173             S.sessions{3,2,3} = 'U002c';
+0174             S.sessions{3,2,4} = 'U002d';
+0175             S.sessions{3,2,5} = 'U002e';
+0176             S.sessions{3,3,1} = 'U003a';
+0177             S.sessions{3,3,2} = 'U003b';
+0178             S.sessions{3,3,3} = 'U003c';
+0179             S.sessions{3,3,4} = 'U003d';
+0180             S.sessions{3,3,5} = 'U003e';
+0181             S.sessions{3,4,1} = 'U004a';
+0182             S.sessions{3,4,2} = 'U004b';
+0183             S.sessions{3,4,3} = 'U004c';
+0184             S.sessions{3,4,4} = 'U004d';
+0185             S.sessions{3,4,5} = 'U004e';
+0186             S.sessions{3,5,1} = 'U005a';
+0187             S.sessions{3,5,2} = 'U005b';
+0188             S.sessions{3,5,3} = 'U005c';
+0189             S.sessions{3,5,4} = 'U005d';
+0190             S.sessions{3,5,5} = 'U005e';
+0191             S.sessions{3,6,1} = 'U006a';
+0192             S.sessions{3,6,2} = 'U006b';
+0193             S.sessions{3,6,3} = 'U006c';
+0194             S.sessions{3,6,4} = 'U006d';
+0195             S.sessions{3,6,5} = 'U006e';
+0196             S.sessions{3,7,1} = 'U007a';
+0197             S.sessions{3,7,2} = 'U007b';
+0198             S.sessions{3,7,3} = 'U007c';
+0199             S.sessions{3,7,4} = 'U007d';
+0200             S.sessions{3,7,5} = 'U007e';
+0201             S.sessions{3,8,1} = 'U008a';
+0202             S.sessions{3,8,2} = 'U008b';
+0203             S.sessions{3,8,3} = 'U008c';
+0204             S.sessions{3,8,4} = 'U008d';
+0205             S.sessions{3,8,5} = 'U008e';
+0206             S.sessions{3,9,1} = 'U009a';
+0207             S.sessions{3,9,2} = 'U009b';
+0208             S.sessions{3,9,3} = 'U009c';
+0209             S.sessions{3,9,4} = 'U009d';
+0210             S.sessions{3,9,5} = 'U009e';
+0211             S.sessions{3,10,1} = 'U010a';
+0212             S.sessions{3,10,2} = 'U010b';
+0213             S.sessions{3,10,3} = 'U010c';
+0214             S.sessions{3,10,4} = 'U010d';
+0215             S.sessions{3,10,5} = 'U010e';
+0216             S.sessions{3,11,1} = 'U011a';
+0217             S.sessions{3,11,2} = 'U011b';
+0218             S.sessions{3,11,3} = 'U011c';
+0219             S.sessions{3,11,4} = 'U011d';
+0220             S.sessions{3,11,5} = 'U011e';
+0221             
+0222             %SCCN dataset
+0223             S.sessions{4,1,1} = 's1';
+0224             S.sessions{4,2,1} = 's2';
+0225             S.sessions{4,3,1} = 's3';
+0226             S.sessions{4,4,1} = 's4';
+0227             S.sessions{4,5,1} = 's5';
+0228             S.sessions{4,6,1} = 's6';
+0229             S.sessions{4,7,1} = 's7';
+0230             S.sessions{4,8,1} = 's8';
+0231             S.sessions{4,9,1} = 's9';
+0232             S.sessions{4,10,1} = 's10';
+0233             
+0234             %ERRP dataset
+0235             S.sessions{5,1,1} = 'EEG_s1.mat';
+0236             S.sessions{5,2,1} = 'EEG_s2.mat';
+0237             S.sessions{5,3,1} = 'EEG_s3.mat';
+0238             S.sessions{5,4,1} = 'EEG_s4.mat';
+0239             S.sessions{5,5,1} = 'EEG_s5.mat';
+0240             S.sessions{5,6,1} = 'EEG_s6.mat';
+0241             S.sessions{5,7,1} = 'EEG_s7.mat';
+0242             S.sessions{5,8,1} = 'EEG_s8.mat';
+0243             
+0244             S.sessions{6,1,1} = 'dataset_BCIcomp1.mat';
+0245             
+0246             S.sessions{7,1,1} = 'B01T.mat';
+0247             S.sessions{7,1,2} = 'B01T.mat';
+0248             S.sessions{7,2,1} = 'B02T.mat';
+0249             S.sessions{7,2,2} = 'B02T.mat';
+0250             S.sessions{7,3,1} = 'B03T.mat';
+0251             S.sessions{7,3,2} = 'B03T.mat';
+0252             S.sessions{7,4,1} = 'B04T.mat';
+0253             S.sessions{7,4,2} = 'B04T.mat';
+0254             S.sessions{7,5,1} = 'B05T.mat';
+0255             S.sessions{7,5,2} = 'B05T.mat';
+0256             S.sessions{7,6,1} = 'B06T.mat';
+0257             S.sessions{7,6,2} = 'B06T.mat';
+0258             S.sessions{7,7,1} = 'B07T.mat';
+0259             S.sessions{7,7,2} = 'B07T.mat';
+0260             S.sessions{7,8,1} = 'B08T.mat';
+0261             S.sessions{7,8,2} = 'B08T.mat';
+0262             S.sessions{7,9,1} = 'B09T.mat';
+0263             S.sessions{7,9,2} = 'B09T.mat';
+0264             
+0265             %MI dataset
+0266             %             S.sessions{6,1,1} = ;
+0267             
+0268             
+0269             S.subjectids = [];
+0270             S.sessionids = [];
+0271         end
+0272         function S = loadAll(S,experiment)
+0273             %loads everything
+0274             [~,l,~] = size(S.sessions);
+0275             h = waitbar(0,'Loading...');
+0276             for i=1:l
+0277                 waitbar(i/l,h,'Loading...');
+0278                 S.loadSubject(experiment,i);
+0279             end
+0280             close(h);
+0281         end
+0282         
+0283         function S = loadSubject(S,experiment,subject)
+0284             %loads all trials for a specific subject
+0285             %
+0286             %Example:
+0287             %   session.loadSubject(1);
+0288             %loads all the trials of the 1st subject
+0289             [~,~, y] = size(S.sessions);
+0290             for i=1:y
+0291                 if ~isempty(S.sessions{experiment,subject,i})
+0292                     S.loadSubjectSession(experiment,subject,i);
+0293                 end
+0294             end
+0295         end
+0296         function S = loadSubjectSession(S,experiment,subject,session)
+0297             %loads all trials for a specific session
+0298             %
+0299             %Example:
+0300             %   session.loadSubjectSession(1,2);
+0301             %loads the 2nd session of the 1st subject
+0302             %
+0303             switch(experiment)
+0304                 case 1
+0305                     %Load Dataset I (SINGLE)
+0306                     load(S.sessions{experiment,subject,session});
+0307                     signal = eval('eeg');
+0308                     numTrials = length(S.trials) + 1;
+0309                     curTrials = S.split(signal,DIN_1,subject,session);
+0310                     for i=1:length(curTrials)
+0311                         S.trials{numTrials} = curTrials{i};
+0312                         numTrials = numTrials + 1;
+0313                     end
+0314                 case 2
+0315                     %Load Dataset II (MULTI)
+0316                     load(S.sessions{experiment,subject,session});
+0317                     signal = eval('eeg');
+0318                     numTrials = length(S.trials) + 1;
+0319                     curTrials = S.split(signal,DIN_1,subject,session,labels);
+0320                     for i=1:length(curTrials)
+0321                         S.trials{numTrials} = curTrials{i};
+0322                         numTrials = numTrials + 1;
+0323                     end
+0324                 case 3
+0325                     %Dataset III (EPOC-MULTI)
+0326                     SAMPLING_RATE = 128;
+0327                     load(strcat(S.sessions{experiment,subject,session},'i'));
+0328                     events = eval('events');
+0329                     marks = events(events(:,2)==32779,3);
+0330                     stops = events(events(:,2)==32780,3);
+0331                     numTrials = length(S.trials) + 1;
+0332                     labels = {4,2,3,5,1,2,5,4,2,3,1,5};
+0333                     for i=1:length(marks)
+0334                         signal = eeg(:,marks(i):stops(i) -1);
+0335                         label = labels{i};
+0336                         S.trials{numTrials} = eegtoolkit.util.Trial(signal,label,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.SSVEP);
+0337                         numTrials = numTrials + 1;
+0338                         S.subjectids = [S.subjectids subject];
+0339                         S.sessionids = [S.sessionids session];
+0340                     end
+0341                     %load part 2
+0342                     load(strcat(S.sessions{experiment,subject,session},'ii'));
+0343                     events = eval('events');
+0344                     marks = events(events(:,2)==32779,3);
+0345                     stops = events(events(:,2)==32780,3);
+0346                     numTrials = length(S.trials) + 1;
+0347                     labels = {4,3,2,4,1,2,5,3,4,1,3,1,3};
+0348                     for i=1:length(marks)
+0349                         signal = eeg(:,marks(i):stops(i) -1);
+0350                         label = labels{i};
+0351                         S.trials{numTrials} = eegtoolkit.util.Trial(signal,label,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.SSVEP);
+0352                         numTrials = numTrials + 1;
+0353                         S.subjectids = [S.subjectids subject];
+0354                         S.sessionids = [S.sessionids session];
+0355                     end
+0356                 case 4
+0357                     %SCCN Dataset
+0358                     SAMPLING_RATE = 256;
+0359                     load(S.sessions{experiment,subject,session});
+0360                     [x,y,z,zz] = size(eeg);
+0361                     numTrials = length(S.trials) + 1;
+0362                     for i=1:x
+0363                         for j=1:zz
+0364                             S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(eeg(i,:,:,j)),i,SAMPLING_RATE,subject,j);
+0365                             numTrials = numTrials+1;
+0366                             S.subjectids = [S.subjectids subject];
+0367                             S.sessionids = [S.sessionids j];
+0368                         end
+0369                     end
+0370                 case 5
+0371                     %ERRP Dataset
+0372                     SAMPLING_RATE = 256;
+0373                     %range of trial in milliseconds based on the stimulus
+0374                     %event
+0375                     range = [200,800];
+0376                     xstart = round(range(1)*SAMPLING_RATE/1000)-1500;
+0377                     xend = round(range(2)*SAMPLING_RATE/1000);
+0378                     load(S.sessions{experiment,subject,session});
+0379                     events = {'correct_movement', 'error_movement'};
+0380                     numTrials = length(S.trials) + 1;
+0381                     for ev=1:length(events)
+0382                         idxev = find(strcmp(EEG.events.name, events{ev}));
+0383                         epochs.(events{ev}) = zeros(length(xstart:xend), size(EEG.signal,2), length(idxev));
+0384                         for i=1:length(idxev)
+0385                             epochs.(events{ev})(:,:,i) = EEG.signal(EEG.events.position(idxev(i))+xstart:EEG.events.position(idxev(i))+xend,:);
+0386                         end
+0387                         GrandAverages.(events{ev}) = mean(epochs.(events{ev}),3);
+0388                     end
+0389                     [~,~,numCorrect] = size(epochs.correct_movement);
+0390                     [~,~,numError] = size(epochs.error_movement);
+0391                     for i=1:numCorrect
+0392                         S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(epochs.correct_movement(:,:,i))',1,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.ERRP);
+0393                         numTrials = numTrials + 1;
+0394                         S.subjectids = [S.subjectids subject];
+0395                         S.sessionids = [S.sessionids session];
+0396                         
+0397                     end
+0398                     for i=1:numError
+0399                         S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(epochs.error_movement(:,:,i))',2,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.ERRP);
+0400                         numTrials = numTrials + 1;
+0401                         S.subjectids = [S.subjectids subject];
+0402                         S.sessionids = [S.sessionids session];
+0403                     end
+0404                 case 6
+0405                     load(S.sessions{experiment,subject,session});
+0406                     [~,~,n] = size(x_train);
+0407                     numTrials = length(S.trials) + 1;
+0408                     for i=1:n
+0409                         signal = squeeze(x_train(:,:,i));
+0410                         label = y_train(i);
+0411                         S.trials{numTrials} = eegtoolkit.util.Trial(signal',label,128,1,1,eegtoolkit.util.Trial.MI);
+0412                         S.subjectids = [S.subjectids subject];
+0413                         S.sessionids = [S.sessionids session];
+0414                         numTrials = numTrials + 1;
+0415                     end
+0416                 case 7
+0417                     load(S.sessions{experiment,subject,session});
+0418                     [trialsegm,labels] = segmentGratzB(data{session},0.5,2.5,250);
+0419                     [n,~,~] = size(trialsegm);
+0420                     numTrials = length(S.trials) + 1;
+0421                     for i=1:n
+0422                         signal = squeeze(trialsegm(i,:,:));
+0423                         label = labels(i);
+0424                         S.trials{numTrials} = eegtoolkit.util.Trial(signal',label,250,subject,session,eegtoolkit.util.Trial.MI);
+0425                         S.subjectids = [S.subjectids subject];
+0426                         S.sessionids = [S.sessionids session];
+0427                         numTrials = numTrials + 1;
+0428                     end
+0429                 otherwise
+0430                     error('invalid experiment id');
+0431             end
+0432         end
+0433         
+0434         function S = clearData(S)
+0435             %clears loaded data
+0436             S.trials = {};
+0437             S.subjectids = [];
+0438             S.sessionids = [];
+0439         end
+0440     end
+0441     
+0442     methods (Access = private)
+0443         function trials = split(S, signal, dins, subjectid, session,labels)
+0444             SAMPLING_RATE = 250;
+0445             timestamps = cell2mat(dins(2,:));
+0446             samples = cell2mat(dins(4,:));
+0447             [a numDins ]= size(dins);
+0448             sampleA= samples(1);
+0449             timeA = timestamps(1);
+0450             previous = timestamps(1);
+0451             ranges = [];
+0452             freqs = [];
+0453             times = [];
+0454             sum = 0;
+0455             count = 0;
+0456             i=2;
+0457             for i=2:numDins
+0458                 current = timestamps(i);
+0459                 if(current - previous) > S.THRESHOLD_SPLIT_MILLIS;
+0460                     sampleB = samples(i-1);
+0461                     timeB = timestamps(i-1);
+0462                     freqs = [freqs; (sum/count)];
+0463                     % don't ask why
+0464                     if(sampleB - sampleA>382)
+0465                         ranges = [ranges ; [sampleA (sampleA+1249)]];
+0466                         times = [times; [timeA timeB]];
+0467                     end
+0468                     sampleA = samples(i);
+0469                     timeA = timestamps(i);
+0470                     sum = 0;
+0471                     count = 0;
+0472                 else
+0473                     sum = sum + (current-previous);
+0474                     count = count +1;
+0475                 end
+0476                 previous = timestamps(i);
+0477             end
+0478             %             if(isempty(labels))
+0479             sampleB = samples(i-1);
+0480             timeB = timestamps(i-1);
+0481             freqs = [freqs; (sum/count)];
+0482             ranges = [ranges; [sampleA sampleA+1249]];
+0483             times = [times; [timeA timeB]];
+0484             freqs = freqs*2;
+0485             freqs = 1000./freqs;
+0486             %             end
+0487             [numSplits a] = size(ranges);
+0488             trials = {};
+0489             i = 1;
+0490             for i=1:numSplits
+0491                 if(nargin>5)
+0492                     trials{i} = eegtoolkit.util.Trial(signal(:, ranges(i,1):ranges(i,2)), labels{i},SAMPLING_RATE, subjectid,session,eegtoolkit.util.Trial.SSVEP);
+0493                     S.subjectids = [S.subjectids subjectid];
+0494                     S.sessionids = [S.sessionids session];
+0495                 else
+0496                     trials{i} = eegtoolkit.util.Trial(signal(:,ranges(i,1):ranges(i,2)), freqs(i), SAMPLING_RATE, subjectid,session,eegtoolkit.util.Trial.SSVEP);
+0497                     S.subjectids = [S.subjectids subjectid];
+0498                     S.sessionids = [S.sessionids session];
+0499                 end
+0500             end
+0501         end
+0502         
+0503         
+0504     end
+0505 end
+0506
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Session/Session.m b/doc/+eegtoolkit/+util/@Session/Session.m new file mode 100644 index 0000000..eb89757 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/Session.m @@ -0,0 +1,506 @@ +% SESSION class +% Session I/O, splitting sessions into trials and applying filters +% +% Properties: +% trials: A cell array with the Trials of the loaded sessions. +% filt: Filter to be applied when data is loaded +% sessions: Cell array with the filenames of the dataset +% subjectids: Vector with the subject ids corresponding to the loaded trials +% sessionids: Vector with the session ids corresponding to the loaded trials +% +% Functions: +%init a session +% session = eegtoolkit.util.Session(); +%init a session with a filter (created with 'filterbuilder') +% session = eegtoolkit.util.Session(filt); +%load trials for a subject +% session.loadSubject(subjectid); +%load a specific session +% session.loadSubjectSession(subjectid,sessionid); +%load everything +% session.loadAll(); +%clear loaded data +% session.clearData; +%apply a filter that was created with 'filterbuilder' +% session.applyFilter(filt); +% +% +%DATASETS +%1. SSVEP Dataset I (SINGLE) +%2. SSVEP Dataset II (MULTI) +%3. SSVEP Dataset III (EPOC-MULTI) +%4. SSVEP Dataset SCCN +%5. ERRP Dataset +%6. MI Dataset + +classdef Session < handle + + properties (Constant) + THRESHOLD_SPLIT_MILLIS = 2000; %Threshold for splitting the trials based on DIN data + end + properties (Access = public) + trials = {}; % Trials of the loaded sessions. + filt; % Filter to be applied when data is loaded + sessions; % Filenames of the dataset + subjectids; % The subject ids corresponding to the loaded trials + sessionids; + end + + + methods (Access = public) + function S = Session() + %S = eegtoolkit.util.Session(); + %Constructs a session object + % + %S = eegtoolkit.util.Session(filt); + %Constructs a session object. A filter will applied to all + %loaded trials + %Dataset I + S.sessions{1,1,1} = 'S001a'; + S.sessions{1,1,2} = 'S001b'; + S.sessions{1,1,3} = 'S001c'; + S.sessions{1,2,1} = 'S002a'; + S.sessions{1,2,2} = 'S002b'; + S.sessions{1,2,3} = 'S002c'; + S.sessions{1,2,4} = 'S002d'; + S.sessions{1,2,5} = 'S002e'; + S.sessions{1,3,1} = 'S003a'; + S.sessions{1,3,2} = 'S003b'; + S.sessions{1,3,3} = 'S003c'; + S.sessions{1,4,1} = 'S004a'; + S.sessions{1,4,2} = 'S004b'; + S.sessions{1,4,3} = 'S004c'; + S.sessions{1,4,4} = 'S004d'; + S.sessions{1,5,1} = 'S005a'; + S.sessions{1,5,2} = 'S005b'; + S.sessions{1,5,3} = 'S005c'; + S.sessions{1,5,4} = 'S005d'; + S.sessions{1,5,5} = 'S005e'; + S.sessions{1,6,1} = 'S006a'; + S.sessions{1,6,2} = 'S006b'; + S.sessions{1,6,3} = 'S006c'; + S.sessions{1,6,4} = 'S006d'; + S.sessions{1,6,5} = 'S006e'; + S.sessions{1,7,1} = 'S007a'; + S.sessions{1,7,2} = 'S007b'; + S.sessions{1,7,3} = 'S007c'; + S.sessions{1,7,4} = 'S007d'; + S.sessions{1,7,5} = 'S007e'; + S.sessions{1,8,1} = 'S008a'; + S.sessions{1,8,2} = 'S008b'; + S.sessions{1,8,3} = 'S008c'; + S.sessions{1,9,1} = 'S009a'; + S.sessions{1,9,2} = 'S009b'; + S.sessions{1,9,3} = 'S009c'; + S.sessions{1,9,4} = 'S009d'; + S.sessions{1,9,5} = 'S009e'; + S.sessions{1,10,1} = 'S010a'; + S.sessions{1,10,2} = 'S010b'; + S.sessions{1,10,3} = 'S010c'; + S.sessions{1,10,4} = 'S010d'; + S.sessions{1,10,5} = 'S010e'; + S.sessions{1,11,1} = 'S013a'; + S.sessions{1,11,2} = 'S013b'; + S.sessions{1,11,3} = 'S013c'; + S.sessions{1,11,4} = 'S013d'; + S.sessions{1,11,5} = 'S013e'; + + %Dataset II + S.sessions{2,1,1} = 'T001a'; + S.sessions{2,1,2} = 'T001b'; + S.sessions{2,1,3} = 'T001c'; + S.sessions{2,1,4} = 'T001d'; + S.sessions{2,1,5} = 'T001e'; + S.sessions{2,2,1} = 'T002a'; + S.sessions{2,2,2} = 'T002b'; + S.sessions{2,2,3} = 'T002c'; + S.sessions{2,2,4} = 'T002d'; + S.sessions{2,2,5} = 'T002e'; + S.sessions{2,3,1} = 'T003a'; + S.sessions{2,3,2} = 'T003b'; + S.sessions{2,3,3} = 'T003c'; + S.sessions{2,3,4} = 'T003d'; + S.sessions{2,3,5} = 'T003e'; + S.sessions{2,4,1} = 'T004a'; + S.sessions{2,4,2} = 'T004b'; + S.sessions{2,4,3} = 'T004c'; + S.sessions{2,4,4} = 'T004d'; + S.sessions{2,4,5} = 'T004e'; + S.sessions{2,5,1} = 'T005a'; + S.sessions{2,5,2} = 'T005b'; + S.sessions{2,5,3} = 'T005c'; + S.sessions{2,5,4} = 'T005d'; + S.sessions{2,5,5} = 'T005e'; + S.sessions{2,6,1} = 'T006a'; + S.sessions{2,6,2} = 'T006b'; + S.sessions{2,6,3} = 'T006c'; + S.sessions{2,6,4} = 'T006d'; + S.sessions{2,6,5} = 'T006e'; + S.sessions{2,7,1} = 'T007a'; + S.sessions{2,7,2} = 'T007b'; + S.sessions{2,7,3} = 'T007c'; + S.sessions{2,7,4} = 'T007d'; + S.sessions{2,7,5} = 'T007e'; + S.sessions{2,8,1} = 'T008a'; + S.sessions{2,8,2} = 'T008b'; + S.sessions{2,8,3} = 'T008c'; + S.sessions{2,8,4} = 'T008d'; + S.sessions{2,8,5} = 'T008e'; + S.sessions{2,9,1} = 'T009a'; + S.sessions{2,9,2} = 'T009b'; + S.sessions{2,9,3} = 'T009c'; + S.sessions{2,9,4} = 'T009d'; + S.sessions{2,9,5} = 'T009e'; + S.sessions{2,10,1} = 'T010a'; + S.sessions{2,10,2} = 'T010b'; + S.sessions{2,10,3} = 'T010c'; + S.sessions{2,10,4} = 'T010d'; + S.sessions{2,10,5} = 'T010e'; + S.sessions{2,11,1} = 'T013a'; + S.sessions{2,11,2} = 'T013b'; + S.sessions{2,11,3} = 'T013c'; + S.sessions{2,11,4} = 'T013d'; + S.sessions{2,11,5} = 'T013e'; + + %Dataset III (Epoc) + S.sessions{3,1,1} = 'U001a'; + S.sessions{3,1,2} = 'U001b'; + S.sessions{3,1,3} = 'U001c'; + S.sessions{3,1,4} = 'U001d'; + S.sessions{3,1,5} = 'U001e'; + S.sessions{3,2,1} = 'U002a'; + S.sessions{3,2,2} = 'U002b'; + S.sessions{3,2,3} = 'U002c'; + S.sessions{3,2,4} = 'U002d'; + S.sessions{3,2,5} = 'U002e'; + S.sessions{3,3,1} = 'U003a'; + S.sessions{3,3,2} = 'U003b'; + S.sessions{3,3,3} = 'U003c'; + S.sessions{3,3,4} = 'U003d'; + S.sessions{3,3,5} = 'U003e'; + S.sessions{3,4,1} = 'U004a'; + S.sessions{3,4,2} = 'U004b'; + S.sessions{3,4,3} = 'U004c'; + S.sessions{3,4,4} = 'U004d'; + S.sessions{3,4,5} = 'U004e'; + S.sessions{3,5,1} = 'U005a'; + S.sessions{3,5,2} = 'U005b'; + S.sessions{3,5,3} = 'U005c'; + S.sessions{3,5,4} = 'U005d'; + S.sessions{3,5,5} = 'U005e'; + S.sessions{3,6,1} = 'U006a'; + S.sessions{3,6,2} = 'U006b'; + S.sessions{3,6,3} = 'U006c'; + S.sessions{3,6,4} = 'U006d'; + S.sessions{3,6,5} = 'U006e'; + S.sessions{3,7,1} = 'U007a'; + S.sessions{3,7,2} = 'U007b'; + S.sessions{3,7,3} = 'U007c'; + S.sessions{3,7,4} = 'U007d'; + S.sessions{3,7,5} = 'U007e'; + S.sessions{3,8,1} = 'U008a'; + S.sessions{3,8,2} = 'U008b'; + S.sessions{3,8,3} = 'U008c'; + S.sessions{3,8,4} = 'U008d'; + S.sessions{3,8,5} = 'U008e'; + S.sessions{3,9,1} = 'U009a'; + S.sessions{3,9,2} = 'U009b'; + S.sessions{3,9,3} = 'U009c'; + S.sessions{3,9,4} = 'U009d'; + S.sessions{3,9,5} = 'U009e'; + S.sessions{3,10,1} = 'U010a'; + S.sessions{3,10,2} = 'U010b'; + S.sessions{3,10,3} = 'U010c'; + S.sessions{3,10,4} = 'U010d'; + S.sessions{3,10,5} = 'U010e'; + S.sessions{3,11,1} = 'U011a'; + S.sessions{3,11,2} = 'U011b'; + S.sessions{3,11,3} = 'U011c'; + S.sessions{3,11,4} = 'U011d'; + S.sessions{3,11,5} = 'U011e'; + + %SCCN dataset + S.sessions{4,1,1} = 's1'; + S.sessions{4,2,1} = 's2'; + S.sessions{4,3,1} = 's3'; + S.sessions{4,4,1} = 's4'; + S.sessions{4,5,1} = 's5'; + S.sessions{4,6,1} = 's6'; + S.sessions{4,7,1} = 's7'; + S.sessions{4,8,1} = 's8'; + S.sessions{4,9,1} = 's9'; + S.sessions{4,10,1} = 's10'; + + %ERRP dataset + S.sessions{5,1,1} = 'EEG_s1.mat'; + S.sessions{5,2,1} = 'EEG_s2.mat'; + S.sessions{5,3,1} = 'EEG_s3.mat'; + S.sessions{5,4,1} = 'EEG_s4.mat'; + S.sessions{5,5,1} = 'EEG_s5.mat'; + S.sessions{5,6,1} = 'EEG_s6.mat'; + S.sessions{5,7,1} = 'EEG_s7.mat'; + S.sessions{5,8,1} = 'EEG_s8.mat'; + + S.sessions{6,1,1} = 'dataset_BCIcomp1.mat'; + + S.sessions{7,1,1} = 'B01T.mat'; + S.sessions{7,1,2} = 'B01T.mat'; + S.sessions{7,2,1} = 'B02T.mat'; + S.sessions{7,2,2} = 'B02T.mat'; + S.sessions{7,3,1} = 'B03T.mat'; + S.sessions{7,3,2} = 'B03T.mat'; + S.sessions{7,4,1} = 'B04T.mat'; + S.sessions{7,4,2} = 'B04T.mat'; + S.sessions{7,5,1} = 'B05T.mat'; + S.sessions{7,5,2} = 'B05T.mat'; + S.sessions{7,6,1} = 'B06T.mat'; + S.sessions{7,6,2} = 'B06T.mat'; + S.sessions{7,7,1} = 'B07T.mat'; + S.sessions{7,7,2} = 'B07T.mat'; + S.sessions{7,8,1} = 'B08T.mat'; + S.sessions{7,8,2} = 'B08T.mat'; + S.sessions{7,9,1} = 'B09T.mat'; + S.sessions{7,9,2} = 'B09T.mat'; + + %MI dataset + % S.sessions{6,1,1} = ; + + + S.subjectids = []; + S.sessionids = []; + end + function S = loadAll(S,experiment) + %loads everything + [~,l,~] = size(S.sessions); + h = waitbar(0,'Loading...'); + for i=1:l + waitbar(i/l,h,'Loading...'); + S.loadSubject(experiment,i); + end + close(h); + end + + function S = loadSubject(S,experiment,subject) + %loads all trials for a specific subject + % + %Example: + % session.loadSubject(1); + %loads all the trials of the 1st subject + [~,~, y] = size(S.sessions); + for i=1:y + if ~isempty(S.sessions{experiment,subject,i}) + S.loadSubjectSession(experiment,subject,i); + end + end + end + function S = loadSubjectSession(S,experiment,subject,session) + %loads all trials for a specific session + % + %Example: + % session.loadSubjectSession(1,2); + %loads the 2nd session of the 1st subject + % + switch(experiment) + case 1 + %Load Dataset I (SINGLE) + load(S.sessions{experiment,subject,session}); + signal = eval('eeg'); + numTrials = length(S.trials) + 1; + curTrials = S.split(signal,DIN_1,subject,session); + for i=1:length(curTrials) + S.trials{numTrials} = curTrials{i}; + numTrials = numTrials + 1; + end + case 2 + %Load Dataset II (MULTI) + load(S.sessions{experiment,subject,session}); + signal = eval('eeg'); + numTrials = length(S.trials) + 1; + curTrials = S.split(signal,DIN_1,subject,session,labels); + for i=1:length(curTrials) + S.trials{numTrials} = curTrials{i}; + numTrials = numTrials + 1; + end + case 3 + %Dataset III (EPOC-MULTI) + SAMPLING_RATE = 128; + load(strcat(S.sessions{experiment,subject,session},'i')); + events = eval('events'); + marks = events(events(:,2)==32779,3); + stops = events(events(:,2)==32780,3); + numTrials = length(S.trials) + 1; + labels = {4,2,3,5,1,2,5,4,2,3,1,5}; + for i=1:length(marks) + signal = eeg(:,marks(i):stops(i) -1); + label = labels{i}; + S.trials{numTrials} = eegtoolkit.util.Trial(signal,label,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.SSVEP); + numTrials = numTrials + 1; + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + end + %load part 2 + load(strcat(S.sessions{experiment,subject,session},'ii')); + events = eval('events'); + marks = events(events(:,2)==32779,3); + stops = events(events(:,2)==32780,3); + numTrials = length(S.trials) + 1; + labels = {4,3,2,4,1,2,5,3,4,1,3,1,3}; + for i=1:length(marks) + signal = eeg(:,marks(i):stops(i) -1); + label = labels{i}; + S.trials{numTrials} = eegtoolkit.util.Trial(signal,label,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.SSVEP); + numTrials = numTrials + 1; + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + end + case 4 + %SCCN Dataset + SAMPLING_RATE = 256; + load(S.sessions{experiment,subject,session}); + [x,y,z,zz] = size(eeg); + numTrials = length(S.trials) + 1; + for i=1:x + for j=1:zz + S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(eeg(i,:,:,j)),i,SAMPLING_RATE,subject,j); + numTrials = numTrials+1; + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids j]; + end + end + case 5 + %ERRP Dataset + SAMPLING_RATE = 256; + %range of trial in milliseconds based on the stimulus + %event + range = [200,800]; + xstart = round(range(1)*SAMPLING_RATE/1000)-1500; + xend = round(range(2)*SAMPLING_RATE/1000); + load(S.sessions{experiment,subject,session}); + events = {'correct_movement', 'error_movement'}; + numTrials = length(S.trials) + 1; + for ev=1:length(events) + idxev = find(strcmp(EEG.events.name, events{ev})); + epochs.(events{ev}) = zeros(length(xstart:xend), size(EEG.signal,2), length(idxev)); + for i=1:length(idxev) + epochs.(events{ev})(:,:,i) = EEG.signal(EEG.events.position(idxev(i))+xstart:EEG.events.position(idxev(i))+xend,:); + end + GrandAverages.(events{ev}) = mean(epochs.(events{ev}),3); + end + [~,~,numCorrect] = size(epochs.correct_movement); + [~,~,numError] = size(epochs.error_movement); + for i=1:numCorrect + S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(epochs.correct_movement(:,:,i))',1,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.ERRP); + numTrials = numTrials + 1; + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + + end + for i=1:numError + S.trials{numTrials} = eegtoolkit.util.Trial(squeeze(epochs.error_movement(:,:,i))',2,SAMPLING_RATE,subject,session,eegtoolkit.util.Trial.ERRP); + numTrials = numTrials + 1; + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + end + case 6 + load(S.sessions{experiment,subject,session}); + [~,~,n] = size(x_train); + numTrials = length(S.trials) + 1; + for i=1:n + signal = squeeze(x_train(:,:,i)); + label = y_train(i); + S.trials{numTrials} = eegtoolkit.util.Trial(signal',label,128,1,1,eegtoolkit.util.Trial.MI); + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + numTrials = numTrials + 1; + end + case 7 + load(S.sessions{experiment,subject,session}); + [trialsegm,labels] = segmentGratzB(data{session},0.5,2.5,250); + [n,~,~] = size(trialsegm); + numTrials = length(S.trials) + 1; + for i=1:n + signal = squeeze(trialsegm(i,:,:)); + label = labels(i); + S.trials{numTrials} = eegtoolkit.util.Trial(signal',label,250,subject,session,eegtoolkit.util.Trial.MI); + S.subjectids = [S.subjectids subject]; + S.sessionids = [S.sessionids session]; + numTrials = numTrials + 1; + end + otherwise + error('invalid experiment id'); + end + end + + function S = clearData(S) + %clears loaded data + S.trials = {}; + S.subjectids = []; + S.sessionids = []; + end + end + + methods (Access = private) + function trials = split(S, signal, dins, subjectid, session,labels) + SAMPLING_RATE = 250; + timestamps = cell2mat(dins(2,:)); + samples = cell2mat(dins(4,:)); + [a numDins ]= size(dins); + sampleA= samples(1); + timeA = timestamps(1); + previous = timestamps(1); + ranges = []; + freqs = []; + times = []; + sum = 0; + count = 0; + i=2; + for i=2:numDins + current = timestamps(i); + if(current - previous) > S.THRESHOLD_SPLIT_MILLIS; + sampleB = samples(i-1); + timeB = timestamps(i-1); + freqs = [freqs; (sum/count)]; + % don't ask why + if(sampleB - sampleA>382) + ranges = [ranges ; [sampleA (sampleA+1249)]]; + times = [times; [timeA timeB]]; + end + sampleA = samples(i); + timeA = timestamps(i); + sum = 0; + count = 0; + else + sum = sum + (current-previous); + count = count +1; + end + previous = timestamps(i); + end + % if(isempty(labels)) + sampleB = samples(i-1); + timeB = timestamps(i-1); + freqs = [freqs; (sum/count)]; + ranges = [ranges; [sampleA sampleA+1249]]; + times = [times; [timeA timeB]]; + freqs = freqs*2; + freqs = 1000./freqs; + % end + [numSplits a] = size(ranges); + trials = {}; + i = 1; + for i=1:numSplits + if(nargin>5) + trials{i} = eegtoolkit.util.Trial(signal(:, ranges(i,1):ranges(i,2)), labels{i},SAMPLING_RATE, subjectid,session,eegtoolkit.util.Trial.SSVEP); + S.subjectids = [S.subjectids subjectid]; + S.sessionids = [S.sessionids session]; + else + trials{i} = eegtoolkit.util.Trial(signal(:,ranges(i,1):ranges(i,2)), freqs(i), SAMPLING_RATE, subjectid,session,eegtoolkit.util.Trial.SSVEP); + S.subjectids = [S.subjectids subjectid]; + S.sessionids = [S.sessionids session]; + end + end + end + + + end +end + diff --git a/doc/+eegtoolkit/+util/@Session/graph.dot b/doc/+eegtoolkit/+util/@Session/graph.dot new file mode 100644 index 0000000..3d285ba --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Session -> Session; + + Session [URL="Session.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Session/graph.html b/doc/+eegtoolkit/+util/@Session/graph.html new file mode 100644 index 0000000..8dec51e --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@Session + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@Session >
+

Dependency Graph for +eegtoolkit/+util/@Session

+ +
+Dependency Graph for +eegtoolkit/+util/@Session + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Session/graph.map b/doc/+eegtoolkit/+util/@Session/graph.map new file mode 100644 index 0000000..921f312 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@Session/graph.png b/doc/+eegtoolkit/+util/@Session/graph.png new file mode 100644 index 0000000..487d6f6 Binary files /dev/null and b/doc/+eegtoolkit/+util/@Session/graph.png differ diff --git a/doc/+eegtoolkit/+util/@Session/index.html b/doc/+eegtoolkit/+util/@Session/index.html new file mode 100644 index 0000000..91d17af --- /dev/null +++ b/doc/+eegtoolkit/+util/@Session/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@Session + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@Session >
+ +

Index for +eegtoolkit/+util/@Session

+ +

Matlab files in this directory:

+ +
 SessionSESSION class
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Trial/Trial.html b/doc/+eegtoolkit/+util/@Trial/Trial.html new file mode 100644 index 0000000..e9b86a0 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/Trial.html @@ -0,0 +1,115 @@ + + + + Description of Trial + + + + + + + + + +
Home > +eegtoolkit > +util > @Trial > Trial.m
+ + + +

Trial +

+ +

PURPOSE ^

+
A class that defines a Trial
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 A class that defines a Trial
+ 
+ Properties:
+ signal: the signal of the trial, matrix m x n, where m is the channels
+ and n the samples
+ label: a label for the trial (typically assigned with the frequency that is calculated using DIN data)
+ duration: the duration of the trial in seconds
+ samplingRate: the samling rate used to capture the signal
+ subjectid: the subject from whom the trial was recorded
+ sessionid: the session id
+ type: the type of the trial. Supported types of trials:
+ SSVEP = 1;
+ ERRP = 2;
+ MI = 3;
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
  • Trial A class that defines a Trial
+This function is called by: +
    +
  • Trial A class that defines a Trial
+ + +

SUBFUNCTIONS ^

+ +

DOWNLOAD ^

+

Trial.m

+

SOURCE CODE ^

+
0001 % A class that defines a Trial
+0002 %
+0003 % Properties:
+0004 % signal: the signal of the trial, matrix m x n, where m is the channels
+0005 % and n the samples
+0006 % label: a label for the trial (typically assigned with the frequency that is calculated using DIN data)
+0007 % duration: the duration of the trial in seconds
+0008 % samplingRate: the samling rate used to capture the signal
+0009 % subjectid: the subject from whom the trial was recorded
+0010 % sessionid: the session id
+0011 % type: the type of the trial. Supported types of trials:
+0012 % SSVEP = 1;
+0013 % ERRP = 2;
+0014 % MI = 3;
+0015 
+0016 classdef Trial < handle
+0017     
+0018     
+0019     properties (Constant)
+0020         %Type of trial
+0021         SSVEP = 1;
+0022         ERRP = 2;
+0023         MI = 3;
+0024     end
+0025     
+0026     properties (Access = public)
+0027         signal; % the signal of the trial
+0028         label; % a label for the trial (typically assigned with the frequency that is calculated using DIN data)
+0029         duration; % the duration of the trial in seconds
+0030         samplingRate; % the samling rate used to capture the signal
+0031         subjectid; %the subject from
+0032         sessionid; %the session id
+0033         type;
+0034     end
+0035     
+0036     methods (Access = public)
+0037         function T = Trial(signal, label, samplingRate, subjectID, sessionID,type)
+0038             T.signal = signal;
+0039             T.label = label;
+0040             T.samplingRate = samplingRate;
+0041             T.duration = length(signal)/samplingRate;
+0042             T.subjectid = subjectID;
+0043             T.sessionid = sessionID;
+0044             if nargin>5
+0045                 T.type = type;
+0046             end
+0047         end
+0048         
+0049     end
+0050     
+0051 end
+0052
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Trial/Trial.m b/doc/+eegtoolkit/+util/@Trial/Trial.m new file mode 100644 index 0000000..f3a4b06 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/Trial.m @@ -0,0 +1,52 @@ +% A class that defines a Trial +% +% Properties: +% signal: the signal of the trial, matrix m x n, where m is the channels +% and n the samples +% label: a label for the trial (typically assigned with the frequency that is calculated using DIN data) +% duration: the duration of the trial in seconds +% samplingRate: the samling rate used to capture the signal +% subjectid: the subject from whom the trial was recorded +% sessionid: the session id +% type: the type of the trial. Supported types of trials: +% SSVEP = 1; +% ERRP = 2; +% MI = 3; + +classdef Trial < handle + + + properties (Constant) + %Type of trial + SSVEP = 1; + ERRP = 2; + MI = 3; + end + + properties (Access = public) + signal; % the signal of the trial + label; % a label for the trial (typically assigned with the frequency that is calculated using DIN data) + duration; % the duration of the trial in seconds + samplingRate; % the samling rate used to capture the signal + subjectid; %the subject from + sessionid; %the session id + type; + end + + methods (Access = public) + function T = Trial(signal, label, samplingRate, subjectID, sessionID,type) + T.signal = signal; + T.label = label; + T.samplingRate = samplingRate; + T.duration = length(signal)/samplingRate; + T.subjectid = subjectID; + T.sessionid = sessionID; + if nargin>5 + T.type = type; + end + end + + end + +end + diff --git a/doc/+eegtoolkit/+util/@Trial/graph.dot b/doc/+eegtoolkit/+util/@Trial/graph.dot new file mode 100644 index 0000000..f5d038e --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/graph.dot @@ -0,0 +1,6 @@ +/* Created by mdot for Matlab */ +digraph m2html { + Trial -> Trial; + + Trial [URL="Trial.html"]; +} \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Trial/graph.html b/doc/+eegtoolkit/+util/@Trial/graph.html new file mode 100644 index 0000000..2dba938 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/graph.html @@ -0,0 +1,28 @@ + + + + Dependency Graph for +eegtoolkit/+util/@Trial + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@Trial >
+

Dependency Graph for +eegtoolkit/+util/@Trial

+ +
+Dependency Graph for +eegtoolkit/+util/@Trial + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/+eegtoolkit/+util/@Trial/graph.map b/doc/+eegtoolkit/+util/@Trial/graph.map new file mode 100644 index 0000000..ec38555 --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/graph.map @@ -0,0 +1 @@ + diff --git a/doc/+eegtoolkit/+util/@Trial/graph.png b/doc/+eegtoolkit/+util/@Trial/graph.png new file mode 100644 index 0000000..7e10bd4 Binary files /dev/null and b/doc/+eegtoolkit/+util/@Trial/graph.png differ diff --git a/doc/+eegtoolkit/+util/@Trial/index.html b/doc/+eegtoolkit/+util/@Trial/index.html new file mode 100644 index 0000000..61fb45f --- /dev/null +++ b/doc/+eegtoolkit/+util/@Trial/index.html @@ -0,0 +1,32 @@ + + + + Index for Directory +eegtoolkit/+util/@Trial + + + + + + + + + + +
< Master indexIndex for +eegtoolkit/+util/@Trial >
+ +

Index for +eegtoolkit/+util/@Trial

+ +

Matlab files in this directory:

+ +
 TrialA class that defines a Trial
+ + + +

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/alpha.png b/doc/alpha.png new file mode 100644 index 0000000..c73de7b Binary files /dev/null and b/doc/alpha.png differ diff --git a/doc/c++.png b/doc/c++.png new file mode 100644 index 0000000..24f56e6 Binary files /dev/null and b/doc/c++.png differ diff --git a/doc/c.png b/doc/c.png new file mode 100644 index 0000000..c39fbf0 Binary files /dev/null and b/doc/c.png differ diff --git a/doc/demoicon.gif b/doc/demoicon.gif new file mode 100644 index 0000000..c89e7ac Binary files /dev/null and b/doc/demoicon.gif differ diff --git a/doc/down.png b/doc/down.png new file mode 100644 index 0000000..d41104a Binary files /dev/null and b/doc/down.png differ diff --git a/doc/doxysearch.php b/doc/doxysearch.php new file mode 100644 index 0000000..36112a4 --- /dev/null +++ b/doc/doxysearch.php @@ -0,0 +1,329 @@ +$word, + "match"=>$w, + "index"=>$statIdx, + "full"=>strlen($w)==strlen($word), + "docs"=>array() + ); + } + $w = readString($file); + } + $totalFreq=0; + for ($count=$start;$count$idx,"freq"=>$freq,"rank"=>0.0); + $totalFreq+=$freq; + if ($statInfo["full"]) $totalfreq+=$freq; + } + // read name an url info for the doc + for ($i=0;$i<$numDocs;$i++) + { + fseek($file,$docInfo[$i]["idx"]); + $docInfo[$i]["name"]=readString($file); + $docInfo[$i]["url"]=readString($file); + } + $statInfo["docs"]=$docInfo; + } + for ($count=$start;$count$key, + "name"=>$di["name"], + "rank"=>$rank + ); + } + $docs[$key]["words"][] = array( + "word"=>$wordInfo["word"], + "match"=>$wordInfo["match"], + "freq"=>$di["freq"] + ); + } + } + return $docs; +} + +function normalize_ranking(&$docs) +{ + $maxRank = 0.0000001; + // compute maximal rank + foreach ($docs as $doc) + { + if ($doc["rank"]>$maxRank) + { + $maxRank=$doc["rank"]; + } + } + reset($docs); + // normalize rankings + while (list ($key, $val) = each ($docs)) + { + $docs[$key]["rank"]*=100/$maxRank; + } +} + +function filter_results($docs,&$requiredWords,&$forbiddenWords) +{ + $filteredDocs=array(); + while (list ($key, $val) = each ($docs)) + { + $words = &$docs[$key]["words"]; + $copy=1; // copy entry by default + if (sizeof($requiredWords)>0) + { + foreach ($requiredWords as $reqWord) + { + $found=0; + foreach ($words as $wordInfo) + { + $found = $wordInfo["word"]==$reqWord; + if ($found) break; + } + if (!$found) + { + $copy=0; // document contains none of the required words + break; + } + } + } + if (sizeof($forbiddenWords)>0) + { + foreach ($words as $wordInfo) + { + if (in_array($wordInfo["word"],$forbiddenWords)) + { + $copy=0; // document contains a forbidden word + break; + } + } + } + if ($copy) $filteredDocs[$key]=$docs[$key]; + } + return $filteredDocs; +} + +function compare_rank($a,$b) +{ + return ($a["rank"]>$b["rank"]) ? -1 : 1; +} + +function sort_results($docs,&$sorted) +{ + $sorted = $docs; + usort($sorted,"compare_rank"); + return $sorted; +} + +function report_results(&$docs) +{ + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + $numDocs = sizeof($docs); + if ($numDocs==0) + { + echo " \n"; + echo " \n"; + echo " \n"; + } + else + { + echo " \n"; + echo " \n"; + echo " \n"; + $num=1; + foreach ($docs as $doc) + { + echo " \n"; + echo " "; + echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + $num++; + } + } + echo "

Search Results

".matches_text(0)."
".matches_text($numDocs); + echo "\n"; + echo "
$num.".$doc["name"]."
Matches: "; + foreach ($doc["words"] as $wordInfo) + { + $word = $wordInfo["word"]; + $matchRight = substr($wordInfo["match"],strlen($word)); + echo "$word$matchRight(".$wordInfo["freq"].") "; + } + echo "
\n"; +} + +function matches_text($num) +{ + if ($num==0) + { + return 'Sorry, no documents matching your query.'; + } + else if ($num==1) + { + return 'Found 1 document matching your query.'; + } + else // $num>1 + { + return 'Found '.$num.' documents matching your query. Showing best matches first.'; + } +} + +function main($idxfile) +{ + if(strcmp('4.1.0', phpversion()) > 0) + { + die("Error: PHP version 4.1.0 or above required!"); + } + if (!($file=fopen($idxfile,"rb"))) + { + die("Error: Search index file could NOT be opened!"); + } + if (readHeader($file)!="DOXS") + { + die("Error: Header of index file is invalid!"); + } + $query=""; + if (array_key_exists("query", $_GET)) + { + $query=$_GET["query"]; + } + $results = array(); + $requiredWords = array(); + $forbiddenWords = array(); + $foundWords = array(); + $word=strtolower(strtok($query," ")); + while ($word) // for each word in the search query + { + if (($word{0}=='+')) { $word=substr($word,1); $requiredWords[]=$word; } + if (($word{0}=='-')) { $word=substr($word,1); $forbiddenWords[]=$word; } + if (!in_array($word,$foundWords)) + { + $foundWords[]=$word; + search($file,$word,$results); + } + $word=strtolower(strtok(" ")); + } + $docs = array(); + combine_results($results,$docs); + // filter out documents with forbidden word or that do not contain + // required words + $filteredDocs = filter_results($docs,$requiredWords,$forbiddenWords); + // normalize rankings so they are in the range [0-100] + normalize_ranking($filteredDocs); + // sort the results based on rank + $sorted = array(); + sort_results($filteredDocs,$sorted); + // report results to the user + report_results($sorted); + fclose($file); +} + +?> diff --git a/doc/exampleCSP.html b/doc/exampleCSP.html new file mode 100644 index 0000000..3cb4202 --- /dev/null +++ b/doc/exampleCSP.html @@ -0,0 +1,87 @@ + + + + Description of exampleCSP + + + + + + + + + +
Home > . > exampleCSP.m
+ + + +

exampleCSP +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleCSP.m

+

SOURCE CODE ^

+
0001 sess = eegtoolkit.util.Session;
+0002 sess.loadAll(6);
+0003 %
+0004 
+0005 % load('testingMotorVag1');
+0006 % % load
+0007 % sess = eegtoolkit.util.Session;
+0008 % % sess.loadMOTOR(labels,trials);
+0009 % sess.loadVag(trials,labels);
+0010 
+0011 ss = eegtoolkit.preprocessing.SampleSelection;
+0012 ss.channels = [1,3];
+0013 ss.sampleRange = [384,896];
+0014 
+0015 [z,p,k]=butter(3,[8,16]/64);
+0016 [s,g]=zp2sos(z,p,k);
+0017 Hd = dfilt.df2sos(s,g);
+0018 df = eegtoolkit.preprocessing.DigitalFilter; %
+0019 df.filt = Hd;
+0020 
+0021 refer = eegtoolkit.preprocessing.Rereferencing;
+0022 refer.meanSignal = 1;
+0023 
+0024 extr = eegtoolkit.featextraction.RawSignal;
+0025 
+0026 classif = eegtoolkit.classification.CSPWrapper;
+0027 classif.baseClassifier = eegtoolkit.classification.LIBSVM;
+0028 
+0029 experiment = eegtoolkit.experiment.Experimenter;
+0030 experiment.session = sess;
+0031 experiment.preprocessing = {ss,refer,df};
+0032 experiment.featextraction = extr;
+0033 experiment.classification = classif;
+0034 experiment.evalMethod = experiment.EVAL_METHOD_LOOCV;
+0035 % experiment.run();
+0036 % experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV;
+0037 experiment.run(3);
+0038 accuracy = experiment.results{1}.getAccuracy();
+0039
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleCSP.m b/doc/exampleCSP.m new file mode 100644 index 0000000..4c466b6 --- /dev/null +++ b/doc/exampleCSP.m @@ -0,0 +1,39 @@ +sess = eegtoolkit.util.Session; +sess.loadAll(6); +% + +% load('testingMotorVag1'); +% % load +% sess = eegtoolkit.util.Session; +% % sess.loadMOTOR(labels,trials); +% sess.loadVag(trials,labels); + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.channels = [1,3]; +ss.sampleRange = [384,896]; + +[z,p,k]=butter(3,[8,16]/64); +[s,g]=zp2sos(z,p,k); +Hd = dfilt.df2sos(s,g); +df = eegtoolkit.preprocessing.DigitalFilter; % +df.filt = Hd; + +refer = eegtoolkit.preprocessing.Rereferencing; +refer.meanSignal = 1; + +extr = eegtoolkit.featextraction.RawSignal; + +classif = eegtoolkit.classification.CSPWrapper; +classif.baseClassifier = eegtoolkit.classification.LIBSVM; + +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {ss,refer,df}; +experiment.featextraction = extr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOOCV; +% experiment.run(); +% experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV; +experiment.run(3); +accuracy = experiment.results{1}.getAccuracy(); + diff --git a/doc/exampleCombiCCA.html b/doc/exampleCombiCCA.html new file mode 100644 index 0000000..95ad859 --- /dev/null +++ b/doc/exampleCombiCCA.html @@ -0,0 +1,93 @@ + + + + Description of exampleCombiCCA + + + + + + + + + +
Home > . > exampleCombiCCA.m
+ + + +

exampleCombiCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleCombiCCA.m

+

SOURCE CODE ^

+
0001 m_secs = 0.5:0.5:4;
+0002 for ii=1:8
+0003     for jj = 1:8
+0004         sess = eegtoolkit.util.Session;
+0005         % sess.loadAll(4);
+0006         % sess.loadAll(4);
+0007         sess.loadSubject(4,ii);
+0008         
+0009         ss = eegtoolkit.preprocessing.SampleSelection;
+0010         ss.channels = 1:8;
+0011         % ss.sampleRange = [75,1024+74];
+0012         ss.sampleRange = [75,74+256*m_secs(jj)];
+0013         % ss.sampleRange = [1,1140];
+0014         % 75:1024+74
+0015         [z,p,k]=butter(3,[6,80]/128);
+0016         [s,g]=zp2sos(z,p,k);
+0017         Hd = dfilt.df2sos(s,g);
+0018         df = eegtoolkit.preprocessing.DigitalFilter; %
+0019         df.filt = Hd;
+0020         
+0021         refer = eegtoolkit.preprocessing.Rereferencing;
+0022         refer.meanSignal = 1;
+0023         
+0024         extr = eegtoolkit.featextraction.RawSignal;
+0025         sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75];
+0026         classif = eegtoolkit.classification.CombiCCA(sti_f,4,256*m_secs(jj),256);
+0027         classif.baseClassifier = eegtoolkit.classification.MaxChooser;
+0028         
+0029         experiment = eegtoolkit.experiment.Experimenter;
+0030         experiment.session = sess;
+0031         experiment.preprocessing = {ss,refer,df};
+0032         experiment.featextraction = extr;
+0033         experiment.classification = classif;
+0034         % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV;
+0035         % experiment.run();
+0036         experiment.evalMethod = experiment.EVAL_METHOD_LOBO;
+0037         experiment.run();
+0038         for i=1:length(experiment.results)
+0039             accuracy(i) = experiment.results{i}.getAccuracy();
+0040         end
+0041         acc2(ii,jj) = mean(accuracy);
+0042         
+0043         % accuracy = experiment.results{1}.getAccuracy();
+0044     end
+0045 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleCombiCCA.m b/doc/exampleCombiCCA.m new file mode 100644 index 0000000..f54f361 --- /dev/null +++ b/doc/exampleCombiCCA.m @@ -0,0 +1,45 @@ +m_secs = 0.5:0.5:4; +for ii=1:8 + for jj = 1:8 + sess = eegtoolkit.util.Session; + % sess.loadAll(4); + % sess.loadAll(4); + sess.loadSubject(4,ii); + + ss = eegtoolkit.preprocessing.SampleSelection; + ss.channels = 1:8; + % ss.sampleRange = [75,1024+74]; + ss.sampleRange = [75,74+256*m_secs(jj)]; + % ss.sampleRange = [1,1140]; + % 75:1024+74 + [z,p,k]=butter(3,[6,80]/128); + [s,g]=zp2sos(z,p,k); + Hd = dfilt.df2sos(s,g); + df = eegtoolkit.preprocessing.DigitalFilter; % + df.filt = Hd; + + refer = eegtoolkit.preprocessing.Rereferencing; + refer.meanSignal = 1; + + extr = eegtoolkit.featextraction.RawSignal; + sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75]; + classif = eegtoolkit.classification.CombiCCA(sti_f,4,256*m_secs(jj),256); + classif.baseClassifier = eegtoolkit.classification.MaxChooser; + + experiment = eegtoolkit.experiment.Experimenter; + experiment.session = sess; + experiment.preprocessing = {ss,refer,df}; + experiment.featextraction = extr; + experiment.classification = classif; + % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV; + % experiment.run(); + experiment.evalMethod = experiment.EVAL_METHOD_LOBO; + experiment.run(); + for i=1:length(experiment.results) + accuracy(i) = experiment.results{i}.getAccuracy(); + end + acc2(ii,jj) = mean(accuracy); + + % accuracy = experiment.results{1}.getAccuracy(); + end +end diff --git a/doc/exampleDefault.html b/doc/exampleDefault.html new file mode 100644 index 0000000..e9ffd3e --- /dev/null +++ b/doc/exampleDefault.html @@ -0,0 +1,97 @@ + + + + Description of exampleDefault + + + + + + + + + +
Home > . > exampleDefault.m
+ + + +

exampleDefault +

+ +

PURPOSE ^

+
Load the data. Call this once outside of the script so you dont have to
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(1); %Loads dataset I
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleDefault.m

+

SOURCE CODE ^

+
0001 % Load the data. Call this once outside of the script so you dont have to
+0002 % load the data again and again. Make sure the dataset is included in your
+0003 % Matlab path
+0004 % sess = eegtoolkit.util.Session;
+0005 % sess.loadAll(1); %Loads dataset I
+0006 
+0007 %Load a filter from the samples
+0008 load filters/filt_IIRElliptic.mat;
+0009 
+0010 %Extract features with the pwelch method
+0011 extr = eegtoolkit.featextraction.PWelch;
+0012 
+0013 refer = eegtoolkit.preprocessing.Rereferencing;
+0014 %Subtract the mean from the signal
+0015 refer.meanSignal = 1;
+0016 
+0017 ss = eegtoolkit.preprocessing.SampleSelection;
+0018 ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial
+0019 ss.channels = 126; % Specify the channel(s) to be used
+0020 
+0021 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0022 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0023 
+0024 %Configure the classifier
+0025 classif = eegtoolkit.classification.LIBSVMFast;
+0026 
+0027 %Set the Experimenter wrapper class
+0028 experiment = eegtoolkit.experiment.Experimenter;
+0029 experiment.session = sess;
+0030 % Add the preprocessing steps (order is taken into account)
+0031 experiment.preprocessing = {ss,refer,df};
+0032 experiment.featextraction = extr;
+0033 experiment.classification = classif;
+0034 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0035 experiment.run();
+0036 for i=1:length(experiment.results)
+0037     accuracies(i) = experiment.results{i}.getAccuracy();
+0038 end
+0039 
+0040 accuracies'
+0041 %mean accuracy for all subjects
+0042 fprintf('mean acc = %f\n', mean(accuracies));
+0043 %get the configuration used (for reporting)
+0044 experiment.getExperimentInfo
+0045 experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleDefault.m b/doc/exampleDefault.m new file mode 100644 index 0000000..82ea4d4 --- /dev/null +++ b/doc/exampleDefault.m @@ -0,0 +1,45 @@ +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(1); %Loads dataset I + +%Load a filter from the samples +load filters/filt_IIRElliptic.mat; + +%Extract features with the pwelch method +extr = eegtoolkit.featextraction.PWelch; + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial +ss.channels = 126; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + +%Configure the classifier +classif = eegtoolkit.classification.LIBSVMFast; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {ss,refer,df}; +experiment.featextraction = extr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +experiment.getExperimentInfo +experiment.getTime diff --git a/doc/exampleEPOCCCASVM.html b/doc/exampleEPOCCCASVM.html new file mode 100644 index 0000000..bd01d3e --- /dev/null +++ b/doc/exampleEPOCCCASVM.html @@ -0,0 +1,105 @@ + + + + Description of exampleEPOCCCASVM + + + + + + + + + +
Home > . > exampleEPOCCCASVM.m
+ + + +

exampleEPOCCCASVM +

+ +

PURPOSE ^

+
Load the data. Call this once outside of the script so you dont have to
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(3); %its best to do this once, outside the script (too much
+ time)
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleEPOCCCASVM.m

+

SOURCE CODE ^

+
0001 % Load the data. Call this once outside of the script so you dont have to
+0002 % load the data again and again. Make sure the dataset is included in your
+0003 % Matlab path
+0004 % sess = eegtoolkit.util.Session;
+0005 % sess.loadAll(3); %its best to do this once, outside the script (too much
+0006 % time)
+0007 
+0008 %Load a filter from the samples
+0009 load filters/epocfilter;
+0010 % 7 = O1
+0011 % 8 = O2
+0012 
+0013 % Stimulus frequencies for generating the CCA reference signals
+0014 sti_f = [12,10,8.57,7.5,6.66];
+0015 
+0016 % CCA feat extraction method
+0017 extr = eegtoolkit.featextraction.CCA(sti_f,1:4,128,4);
+0018 extr.allFeatures = 1;
+0019 
+0020 refer = eegtoolkit.preprocessing.Rereferencing;
+0021 %Subtract the mean from the signal
+0022 refer.meanSignal = 1;
+0023 
+0024 ss = eegtoolkit.preprocessing.SampleSelection;
+0025 ss.sampleRange = [64,640]; % Specify the sample range to be used for each Trial
+0026 ss.channels = 6:9; % Specify the channel(s) to be used
+0027 
+0028 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0029 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0030 
+0031 %Configure the classifier
+0032 classif = eegtoolkit.classification.LIBSVM;
+0033 
+0034 %Set the Experimenter wrapper class
+0035 experiment = eegtoolkit.experiment.Experimenter;
+0036 experiment.session = sess;
+0037 % Add the preprocessing steps (order is taken into account)
+0038 experiment.preprocessing = {ss,df};
+0039 experiment.featextraction = extr;
+0040 experiment.classification = classif;
+0041 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0042 experiment.run();
+0043 for i=1:length(experiment.results)
+0044     accuracies(i) = experiment.results{i}.getAccuracy();
+0045 end
+0046 
+0047 accuracies'
+0048 %mean accuracy for all subjects
+0049 fprintf('mean acc = %f\n', mean(accuracies));
+0050 %get the configuration used (for reporting)
+0051 % experiment.getExperimentInfo
+0052 % experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleEPOCCCASVM.m b/doc/exampleEPOCCCASVM.m new file mode 100644 index 0000000..cc2e828 --- /dev/null +++ b/doc/exampleEPOCCCASVM.m @@ -0,0 +1,52 @@ +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(3); %its best to do this once, outside the script (too much +% time) + +%Load a filter from the samples +load filters/epocfilter; +% 7 = O1 +% 8 = O2 + +% Stimulus frequencies for generating the CCA reference signals +sti_f = [12,10,8.57,7.5,6.66]; + +% CCA feat extraction method +extr = eegtoolkit.featextraction.CCA(sti_f,1:4,128,4); +extr.allFeatures = 1; + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [64,640]; % Specify the sample range to be used for each Trial +ss.channels = 6:9; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + +%Configure the classifier +classif = eegtoolkit.classification.LIBSVM; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {ss,df}; +experiment.featextraction = extr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +% experiment.getExperimentInfo +% experiment.getTime \ No newline at end of file diff --git a/doc/exampleERRP.html b/doc/exampleERRP.html new file mode 100644 index 0000000..c9e3148 --- /dev/null +++ b/doc/exampleERRP.html @@ -0,0 +1,91 @@ + + + + Description of exampleERRP + + + + + + + + + +
Home > . > exampleERRP.m
+ + + +

exampleERRP +

+ +

PURPOSE ^

+
d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleERRP.m

+

SOURCE CODE ^

+
0001 % d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+0002 
+0003 sess = eegtoolkit.util.Session;
+0004 sess.loadSubject(5,6);
+0005 
+0006 [z,p,k]=butter(3,[6,40]/128);
+0007 [s,g]=zp2sos(z,p,k);
+0008 Hd = dfilt.df2sos(s,g);
+0009 df = eegtoolkit.preprocessing.DigitalFilter; %
+0010 df.filt = Hd;
+0011 
+0012 ss = eegtoolkit.preprocessing.SampleSelection;
+0013 ss.channels = [4,9,14];
+0014 ss.sampleRange = 1500:1:1655;
+0015 
+0016 extr = {};
+0017 for i=1:3
+0018     extr{i} = eegtoolkit.featextraction.ERRPFeatures;
+0019     extr{i}.channel = 1;
+0020 end
+0021 
+0022 aggr = eegtoolkit.aggregation.ChannelConcat;
+0023 
+0024 classif = eegtoolkit.classification.LIBSVM;
+0025 
+0026 %Setup experiment
+0027 experiment = eegtoolkit.experiment.Experimenter;
+0028 experiment.session = sess;
+0029 experiment.preprocessing = {df,ss};
+0030 experiment.featextraction = extr;
+0031 experiment.aggregator = aggr;
+0032 experiment.classification = classif;
+0033 experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV;
+0034 
+0035 experiment.run(10);
+0036 
+0037 accuracies = [];
+0038 for i=1:length(experiment.results)
+0039     accuracies(i) = experiment.results{i}.getAccuracy();
+0040 end
+0041 
+0042 accuracies'
+0043 fprintf('mean acc = %.2f\n',mean(accuracies));
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleERRP.m b/doc/exampleERRP.m new file mode 100644 index 0000000..2723761 --- /dev/null +++ b/doc/exampleERRP.m @@ -0,0 +1,43 @@ +% d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter'); + +sess = eegtoolkit.util.Session; +sess.loadSubject(5,6); + +[z,p,k]=butter(3,[6,40]/128); +[s,g]=zp2sos(z,p,k); +Hd = dfilt.df2sos(s,g); +df = eegtoolkit.preprocessing.DigitalFilter; % +df.filt = Hd; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.channels = [4,9,14]; +ss.sampleRange = 1500:1:1655; + +extr = {}; +for i=1:3 + extr{i} = eegtoolkit.featextraction.ERRPFeatures; + extr{i}.channel = 1; +end + +aggr = eegtoolkit.aggregation.ChannelConcat; + +classif = eegtoolkit.classification.LIBSVM; + +%Setup experiment +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {df,ss}; +experiment.featextraction = extr; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV; + +experiment.run(10); + +accuracies = []; +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +fprintf('mean acc = %.2f\n',mean(accuracies)); \ No newline at end of file diff --git a/doc/exampleERRPSSVEPDemo.html b/doc/exampleERRPSSVEPDemo.html new file mode 100644 index 0000000..d629350 --- /dev/null +++ b/doc/exampleERRPSSVEPDemo.html @@ -0,0 +1,94 @@ + + + + Description of exampleERRPSSVEPDemo + + + + + + + + + +
Home > . > exampleERRPSSVEPDemo.m
+ + + +

exampleERRPSSVEPDemo +

+ +

PURPOSE ^

+
d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleERRPSSVEPDemo.m

+

SOURCE CODE ^

+
0001 % d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
+0002 
+0003 sess = eegtoolkit.util.Session;
+0004 sess.loadSubjectSession(8,5,2);
+0005 
+0006 [z,p,k]=butter(3,[1,10]/64);
+0007 [s,g]=zp2sos(z,p,k);
+0008 Hd = dfilt.df2sos(s,g);
+0009 df = eegtoolkit.preprocessing.DigitalFilter; %
+0010 df.filt = Hd;
+0011 
+0012 ss = eegtoolkit.preprocessing.SampleSelection;
+0013 ss.channels = [1:14];
+0014 ss.sampleRange = [1:6:200];
+0015 
+0016 extr = {};
+0017 for i=1:3
+0018     extr{i} = eegtoolkit.featextraction.PWelch;
+0019     extr{i}.channel = 1;
+0020 end
+0021 
+0022 aggr = eegtoolkit.aggregation.ChannelConcat;
+0023 
+0024 classif = eegtoolkit.classification.LIBSVM;
+0025 classif.kernel = classif.KERNEL_RBF;
+0026 classif.gamma = 1/9;
+0027 classif.cost = 1;
+0028 
+0029 %Setup experiment
+0030 experiment = eegtoolkit.experiment.Experimenter;
+0031 experiment.session = sess;
+0032 experiment.preprocessing = {df,ss};
+0033 experiment.featextraction = extr;
+0034 experiment.aggregator = aggr;
+0035 experiment.classification = classif;
+0036 experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV;
+0037 
+0038 experiment.run(10);
+0039 
+0040 accuracies = [];
+0041 for i=1:length(experiment.results)
+0042     accuracies(i) = experiment.results{i}.getAccuracy();
+0043 end
+0044 
+0045 accuracies'
+0046 fprintf('mean acc = %.2f\n',mean(accuracies));
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleERRPSSVEPDemo.m b/doc/exampleERRPSSVEPDemo.m new file mode 100644 index 0000000..4bd172f --- /dev/null +++ b/doc/exampleERRPSSVEPDemo.m @@ -0,0 +1,46 @@ +% d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter'); + +sess = eegtoolkit.util.Session; +sess.loadSubjectSession(8,5,2); + +[z,p,k]=butter(3,[1,10]/64); +[s,g]=zp2sos(z,p,k); +Hd = dfilt.df2sos(s,g); +df = eegtoolkit.preprocessing.DigitalFilter; % +df.filt = Hd; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.channels = [1:14]; +ss.sampleRange = [1:6:200]; + +extr = {}; +for i=1:3 + extr{i} = eegtoolkit.featextraction.PWelch; + extr{i}.channel = 1; +end + +aggr = eegtoolkit.aggregation.ChannelConcat; + +classif = eegtoolkit.classification.LIBSVM; +classif.kernel = classif.KERNEL_RBF; +classif.gamma = 1/9; +classif.cost = 1; + +%Setup experiment +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {df,ss}; +experiment.featextraction = extr; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV; + +experiment.run(10); + +accuracies = []; +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +fprintf('mean acc = %.2f\n',mean(accuracies)); \ No newline at end of file diff --git a/doc/exampleEarlyFusion.html b/doc/exampleEarlyFusion.html new file mode 100644 index 0000000..5e0bcb4 --- /dev/null +++ b/doc/exampleEarlyFusion.html @@ -0,0 +1,123 @@ + + + + Description of exampleEarlyFusion + + + + + + + + + +
Home > . > exampleEarlyFusion.m
+ + + +

exampleEarlyFusion +

+ +

PURPOSE ^

+
Leave one subject out testing
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Leave one subject out testing
+ load filtMAMEM; % load a filter
+ sess = eegtoolkit.util.Session(Hhp);
+ sess.loadAll(1); %its best to do this once, outside the script (too much
+ time)
+ transf = eegtoolkit.transformer.PWelchTransformer();
+ Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(1); %Loads dataset I
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleEarlyFusion.m

+

SOURCE CODE ^

+
0001 % Leave one subject out testing
+0002 % load filtMAMEM; % load a filter
+0003 % sess = eegtoolkit.util.Session(Hhp);
+0004 % sess.loadAll(1); %its best to do this once, outside the script (too much
+0005 % time)
+0006 % transf = eegtoolkit.transformer.PWelchTransformer();
+0007 % Load the data. Call this once outside of the script so you dont have to
+0008 % load the data again and again. Make sure the dataset is included in your
+0009 % Matlab path
+0010 % sess = eegtoolkit.util.Session;
+0011 % sess.loadAll(1); %Loads dataset I
+0012 
+0013 %Load a filter from the samples
+0014 load filters/filt_IIRElliptic;
+0015 
+0016 
+0017 
+0018 refer = eegtoolkit.preprocessing.Rereferencing;
+0019 %Subtract the mean from the signal
+0020 refer.meanSignal = 1;
+0021 
+0022 ss = eegtoolkit.preprocessing.SampleSelection;
+0023 ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial
+0024 ss.channels = [138,139,150]; % Specify the channel(s) to be used
+0025 
+0026 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0027 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0028 
+0029 
+0030 %Extract features with the pwelch method
+0031 extr1 = eegtoolkit.featextraction.PWelch;
+0032 extr1.channel = 1; %will use channel 138
+0033 
+0034 extr2 = eegtoolkit.featextraction.PWelch;
+0035 extr2.channel = 2; %will use channel 139
+0036 
+0037 extr3 = eegtoolkit.featextraction.PWelch;
+0038 extr3.channel = 3; %will use channel 150
+0039 
+0040 extr = {extr1,extr2,extr3};
+0041 % Average all three channels so as to get a new feature vector
+0042 aggr = eegtoolkit.aggregation.ChannelAveraging;
+0043 %Configure the classifier
+0044 classif = eegtoolkit.classification.LIBSVM;
+0045 
+0046 %Set the Experimenter wrapper class
+0047 experiment = eegtoolkit.experiment.Experimenter;
+0048 experiment.session = sess;
+0049 % Add the preprocessing steps (order is taken into account)
+0050 experiment.preprocessing = {ss,refer,df};
+0051 experiment.featextraction = {extr1,extr2,extr3};
+0052 experiment.aggregator = aggr;
+0053 experiment.classification = classif;
+0054 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0055 experiment.run();
+0056 for i=1:length(experiment.results)
+0057     accuracies(i) = experiment.results{i}.getAccuracy();
+0058 end
+0059 
+0060 accuracies'
+0061 %mean accuracy for all subjects
+0062 fprintf('mean acc = %f\n', mean(accuracies));
+0063 %get the configuration used (for reporting)
+0064 experiment.getExperimentInfo
+0065 experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleEarlyFusion.m b/doc/exampleEarlyFusion.m new file mode 100644 index 0000000..e3e79b4 --- /dev/null +++ b/doc/exampleEarlyFusion.m @@ -0,0 +1,65 @@ +% Leave one subject out testing +% load filtMAMEM; % load a filter +% sess = eegtoolkit.util.Session(Hhp); +% sess.loadAll(1); %its best to do this once, outside the script (too much +% time) +% transf = eegtoolkit.transformer.PWelchTransformer(); +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(1); %Loads dataset I + +%Load a filter from the samples +load filters/filt_IIRElliptic; + + + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial +ss.channels = [138,139,150]; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + + +%Extract features with the pwelch method +extr1 = eegtoolkit.featextraction.PWelch; +extr1.channel = 1; %will use channel 138 + +extr2 = eegtoolkit.featextraction.PWelch; +extr2.channel = 2; %will use channel 139 + +extr3 = eegtoolkit.featextraction.PWelch; +extr3.channel = 3; %will use channel 150 + +extr = {extr1,extr2,extr3}; +% Average all three channels so as to get a new feature vector +aggr = eegtoolkit.aggregation.ChannelAveraging; +%Configure the classifier +classif = eegtoolkit.classification.LIBSVM; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {ss,refer,df}; +experiment.featextraction = {extr1,extr2,extr3}; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +experiment.getExperimentInfo +experiment.getTime \ No newline at end of file diff --git a/doc/exampleEpoc.html b/doc/exampleEpoc.html new file mode 100644 index 0000000..2b52e20 --- /dev/null +++ b/doc/exampleEpoc.html @@ -0,0 +1,106 @@ + + + + Description of exampleEpoc + + + + + + + + + +
Home > . > exampleEpoc.m
+ + + +

exampleEpoc +

+ +

PURPOSE ^

+
Load the data. Call this once outside of the script so you dont have to
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(3); %its best to do this once, outside the script (too much
+ time)
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleEpoc.m

+

SOURCE CODE ^

+
0001 % Load the data. Call this once outside of the script so you dont have to
+0002 % load the data again and again. Make sure the dataset is included in your
+0003 % Matlab path
+0004 % sess = eegtoolkit.util.Session;
+0005 % sess.loadAll(3); %its best to do this once, outside the script (too much
+0006 % time)
+0007 
+0008 %Load a filter from the samples
+0009 load filters/epocfilter;
+0010 % 7 = O1
+0011 % 8 = O2
+0012 
+0013 % Stimulus frequencies. The order corresponds to the label id (12Hz=1,
+0014 % 10Hz=2, 8.57Hz=3, 7.5Hz=4, 6.66Hz=5)
+0015 % If the order is wrong, then the "Max" classifier will not work properly
+0016 sti_f = [12,10,8.57,7.5,6.66];
+0017 
+0018 % CCA feat extraction method
+0019 extr = eegtoolkit.featextraction.CCA(sti_f,1:4,128,4);
+0020 
+0021 refer = eegtoolkit.preprocessing.Rereferencing;
+0022 %Subtract the mean from the signal
+0023 refer.meanSignal = 1;
+0024 
+0025 ss = eegtoolkit.preprocessing.SampleSelection;
+0026 ss.sampleRange = [64,640]; % Specify the sample range to be used for each Trial
+0027 ss.channels = 6:9; % Specify the channel(s) to be used
+0028 
+0029 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0030 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0031 
+0032 %Configure the classifier
+0033 classif = eegtoolkit.classification.MaxChooser;
+0034 
+0035 %Set the Experimenter wrapper class
+0036 experiment = eegtoolkit.experiment.Experimenter;
+0037 experiment.session = sess;
+0038 % Add the preprocessing steps (order is taken into account)
+0039 experiment.preprocessing = {ss,df};
+0040 experiment.featextraction = extr;
+0041 experiment.classification = classif;
+0042 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0043 experiment.run();
+0044 for i=1:length(experiment.results)
+0045     accuracies(i) = experiment.results{i}.getAccuracy();
+0046 end
+0047 
+0048 accuracies'
+0049 %mean accuracy for all subjects
+0050 fprintf('mean acc = %f\n', mean(accuracies));
+0051 %get the configuration used (for reporting)
+0052 % experiment.getExperimentInfo
+0053 % experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleEpoc.m b/doc/exampleEpoc.m new file mode 100644 index 0000000..dc55bb7 --- /dev/null +++ b/doc/exampleEpoc.m @@ -0,0 +1,53 @@ +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(3); %its best to do this once, outside the script (too much +% time) + +%Load a filter from the samples +load filters/epocfilter; +% 7 = O1 +% 8 = O2 + +% Stimulus frequencies. The order corresponds to the label id (12Hz=1, +% 10Hz=2, 8.57Hz=3, 7.5Hz=4, 6.66Hz=5) +% If the order is wrong, then the "Max" classifier will not work properly +sti_f = [12,10,8.57,7.5,6.66]; + +% CCA feat extraction method +extr = eegtoolkit.featextraction.CCA(sti_f,1:4,128,4); + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [64,640]; % Specify the sample range to be used for each Trial +ss.channels = 6:9; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + +%Configure the classifier +classif = eegtoolkit.classification.MaxChooser; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {ss,df}; +experiment.featextraction = extr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +% experiment.getExperimentInfo +% experiment.getTime \ No newline at end of file diff --git a/doc/exampleITCCA.html b/doc/exampleITCCA.html new file mode 100644 index 0000000..f2cd1fd --- /dev/null +++ b/doc/exampleITCCA.html @@ -0,0 +1,90 @@ + + + + Description of exampleITCCA + + + + + + + + + +
Home > . > exampleITCCA.m
+ + + +

exampleITCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleITCCA.m

+

SOURCE CODE ^

+
0001 m_secs = 0.5:0.5:4;
+0002 for ii=1:8
+0003     for jj = 1:8
+0004         sess = eegtoolkit.util.Session;
+0005         % sess.loadAll(4);
+0006         % sess.loadAll(4);
+0007         sess.loadSubject(4,ii);
+0008         ss = eegtoolkit.preprocessing.SampleSelection;
+0009         ss.channels = 1:8;
+0010         ss.sampleRange = [75,74+256*m_secs(jj)];
+0011         % ss.sampleRange = [1,1140];
+0012         % 75:1024+74
+0013         h = fdesign.bandpass('N,F3dB1,F3dB2',10,6,80,256);
+0014         d1 = design(h,'butter');
+0015         df = eegtoolkit.preprocessing.DigitalFilter; %
+0016         df.filt = d1;
+0017         
+0018         refer = eegtoolkit.preprocessing.Rereferencing;
+0019         refer.meanSignal = 1;
+0020         
+0021         extr = eegtoolkit.featextraction.RawSignal;
+0022         
+0023         classif = eegtoolkit.classification.ITCCA;
+0024         classif.baseClassifier = eegtoolkit.classification.MaxChooser;
+0025         
+0026         experiment = eegtoolkit.experiment.Experimenter;
+0027         experiment.session = sess;
+0028         experiment.preprocessing = {ss,refer,df};
+0029         experiment.featextraction = extr;
+0030         experiment.classification = classif;
+0031         % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV;
+0032         % experiment.run();
+0033         experiment.evalMethod = experiment.EVAL_METHOD_LOBO;
+0034         experiment.run();
+0035         for i=1:length(experiment.results)
+0036             accuracy(i) = experiment.results{i}.getAccuracy();
+0037         end
+0038         acc2(ii,jj) = mean(accuracy);
+0039         % accuracy = experiment.results{1}.getAccuracy();
+0040         
+0041     end
+0042 end
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleITCCA.m b/doc/exampleITCCA.m new file mode 100644 index 0000000..c20387a --- /dev/null +++ b/doc/exampleITCCA.m @@ -0,0 +1,42 @@ +m_secs = 0.5:0.5:4; +for ii=1:8 + for jj = 1:8 + sess = eegtoolkit.util.Session; + % sess.loadAll(4); + % sess.loadAll(4); + sess.loadSubject(4,ii); + ss = eegtoolkit.preprocessing.SampleSelection; + ss.channels = 1:8; + ss.sampleRange = [75,74+256*m_secs(jj)]; + % ss.sampleRange = [1,1140]; + % 75:1024+74 + h = fdesign.bandpass('N,F3dB1,F3dB2',10,6,80,256); + d1 = design(h,'butter'); + df = eegtoolkit.preprocessing.DigitalFilter; % + df.filt = d1; + + refer = eegtoolkit.preprocessing.Rereferencing; + refer.meanSignal = 1; + + extr = eegtoolkit.featextraction.RawSignal; + + classif = eegtoolkit.classification.ITCCA; + classif.baseClassifier = eegtoolkit.classification.MaxChooser; + + experiment = eegtoolkit.experiment.Experimenter; + experiment.session = sess; + experiment.preprocessing = {ss,refer,df}; + experiment.featextraction = extr; + experiment.classification = classif; + % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV; + % experiment.run(); + experiment.evalMethod = experiment.EVAL_METHOD_LOBO; + experiment.run(); + for i=1:length(experiment.results) + accuracy(i) = experiment.results{i}.getAccuracy(); + end + acc2(ii,jj) = mean(accuracy); + % accuracy = experiment.results{1}.getAccuracy(); + + end +end \ No newline at end of file diff --git a/doc/exampleL1MCCA.html b/doc/exampleL1MCCA.html new file mode 100644 index 0000000..ba0115b --- /dev/null +++ b/doc/exampleL1MCCA.html @@ -0,0 +1,89 @@ + + + + Description of exampleL1MCCA + + + + + + + + + +
Home > . > exampleL1MCCA.m
+ + + +

exampleL1MCCA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleL1MCCA.m

+

SOURCE CODE ^

+
0001 
+0002 sess = eegtoolkit.util.Session;
+0003 sess.loadSubject(4,1);
+0004 % load filters/epocfilter;
+0005 
+0006 sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75];%Reference signals -
+0007 extr = eegtoolkit.featextraction.L1MCCA;
+0008 
+0009 refer = eegtoolkit.preprocessing.Rereferencing;
+0010 refer.meanSignal = 1;
+0011 
+0012 [z,p,k]=butter(3,[6,80]/128);
+0013 % [z,p,k]=butter(3,[5,48]/125);
+0014 [s,g]=zp2sos(z,p,k);
+0015 Hd = dfilt.df2sos(s,g);
+0016 
+0017 m_secs = 5;
+0018 ss = eegtoolkit.preprocessing.SampleSelection;
+0019 ss.sampleRange = [1,1114]; % Specify the sample range to be used for each Trial
+0020 ss.channels = [1:8];%Specify the channel(s) to be used
+0021 %
+0022 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0023 df.filt = Hd; % Hbp is a filter built with "filterbuilder" matlab function
+0024 
+0025 lcca = eegtoolkit.classification.L1MCCA(256,1114/256,4,sti_f);
+0026 
+0027 experiment = eegtoolkit.experiment.Experimenter;
+0028 experiment.session = sess;
+0029 experiment.preprocessing = {ss,refer,df};% Order of preprocessing steps matters.
+0030 experiment.featextraction = extr;
+0031 experiment.classification = lcca;
+0032 experiment.evalMethod = experiment.EVAL_METHOD_LOBO; % specify that you want a "leave one subject out" (default is LOOCV)
+0033 %run the experiment
+0034 experiment.run();
+0035 accuracies = [];
+0036 for i=1:length(experiment.results)
+0037     accuracies(i) = experiment.results{i}.getAccuracy();    
+0038 end
+0039 accuracies'
+0040 %mean accuracy for all subjects
+0041 fprintf('mean acc = %.2f\n', mean(accuracies));
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleL1MCCA.m b/doc/exampleL1MCCA.m new file mode 100644 index 0000000..ed3ead9 --- /dev/null +++ b/doc/exampleL1MCCA.m @@ -0,0 +1,41 @@ + +sess = eegtoolkit.util.Session; +sess.loadSubject(4,1); +% load filters/epocfilter; + +sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75];%Reference signals - +extr = eegtoolkit.featextraction.L1MCCA; + +refer = eegtoolkit.preprocessing.Rereferencing; +refer.meanSignal = 1; + +[z,p,k]=butter(3,[6,80]/128); +% [z,p,k]=butter(3,[5,48]/125); +[s,g]=zp2sos(z,p,k); +Hd = dfilt.df2sos(s,g); + +m_secs = 5; +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [1,1114]; % Specify the sample range to be used for each Trial +ss.channels = [1:8];%Specify the channel(s) to be used +% +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hd; % Hbp is a filter built with "filterbuilder" matlab function + +lcca = eegtoolkit.classification.L1MCCA(256,1114/256,4,sti_f); + +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {ss,refer,df};% Order of preprocessing steps matters. +experiment.featextraction = extr; +experiment.classification = lcca; +experiment.evalMethod = experiment.EVAL_METHOD_LOBO; % specify that you want a "leave one subject out" (default is LOOCV) +%run the experiment +experiment.run(); +accuracies = []; +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %.2f\n', mean(accuracies)); \ No newline at end of file diff --git a/doc/exampleLSL.html b/doc/exampleLSL.html new file mode 100644 index 0000000..df7ea66 --- /dev/null +++ b/doc/exampleLSL.html @@ -0,0 +1,109 @@ + + + + Description of exampleLSL + + + + + + + + + +
Home > . > exampleLSL.m
+ + + +

exampleLSL +

+ +

PURPOSE ^

+
Add dependencies to the Matlab path, LibLSL is required for this example
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
Add dependencies to the Matlab path, LibLSL is required for this example
+to work
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleLSL.m

+

SOURCE CODE ^

+
0001 %Add dependencies to the Matlab path, LibLSL is required for this example
+0002 %to work
+0003 addpath liblsl-Matlab\;
+0004 addpath liblsl-Matlab\bin\;
+0005 addpath liblsl-Matlab\mex\;
+0006 %Initialize LSL Wrapper class
+0007 lsl = eegtoolkit.util.LSLWrapper;
+0008 %Declare the name of the stream that will contain the EEG data
+0009 datastream = 'EMOTIVStream';
+0010 %Declare the name of the stream through which the events will be
+0011 %communicated
+0012 eventstream = 'MyEventStream';
+0013 %Size of signal that will be used for the recognition task
+0014 bufferSize = 5; %in seconds
+0015 %The event code that will trigger the recognition task
+0016 eventCode = 100;
+0017  
+0018  
+0019 % RECOGNITION ALGORITHM CONFIGURATION
+0020  
+0021 %Indicate the number of stimuli (5) and their frequencies
+0022 stimulus_frequencies = [12 10 8.57 7.5 6.66];
+0023  
+0024 %Filtering the eeg data
+0025 % df = eegtoolkit.preprocessing.DigitalFilter;
+0026 % %This filter was created via the 'filterbuilder' method of Matlab
+0027 % df.filt = Hbp;
+0028  
+0029 %Indicate which channels of the data (different electrodes) will be used
+0030 ss = eegtoolkit.preprocessing.SampleSelection;
+0031 %We will use all EPOC channels for this example
+0032 channels = 1:1:14;
+0033 ss.channels = channels;
+0034 ss.sampleRange = [1,128];
+0035  
+0036 %Sampling rate for the EPOC headset is 128Hz
+0037 samplingRate = 128;
+0038  
+0039 %Another required parameter for the CCA algorithm
+0040 numberOfHarmonics = 4;
+0041 %Initialize the Canonical Correlation Analysis class for the stimuli
+0042 %recognition
+0043 cca = eegtoolkit.featextraction.CCA(stimulus_frequencies,channels,samplingRate,numberOfHarmonics);
+0044  
+0045 %Simple classifier that uses the max value of the features to assign the
+0046 %label
+0047 maxC = eegtoolkit.classification.MaxChooser;
+0048  
+0049 %Assign the algorithm configuration to the LSL Wrapper class
+0050 lsl.preprocessing = {ss};
+0051 lsl.featextraction = cca;
+0052 lsl.classification = maxC;
+0053  
+0054 %Find the streams in the network
+0055 lsl.resolveStreams(datastream,bufferSize,eventstream);
+0056 %Pause for 5 seconds to allow the stream to gather some data
+0057 pause(bufferSize); 
+0058 %Run the recognition task. The task runs indefinetely until is specifically
+0059 %interrupted
+0060 lsl.runSSVEP(eventCode);
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleLSL.m b/doc/exampleLSL.m new file mode 100644 index 0000000..51b2e2a --- /dev/null +++ b/doc/exampleLSL.m @@ -0,0 +1,60 @@ +%Add dependencies to the Matlab path, LibLSL is required for this example +%to work +addpath liblsl-Matlab\; +addpath liblsl-Matlab\bin\; +addpath liblsl-Matlab\mex\; +%Initialize LSL Wrapper class +lsl = eegtoolkit.util.LSLWrapper; +%Declare the name of the stream that will contain the EEG data +datastream = 'EMOTIVStream'; +%Declare the name of the stream through which the events will be +%communicated +eventstream = 'MyEventStream'; +%Size of signal that will be used for the recognition task +bufferSize = 5; %in seconds +%The event code that will trigger the recognition task +eventCode = 100; + + +% RECOGNITION ALGORITHM CONFIGURATION + +%Indicate the number of stimuli (5) and their frequencies +stimulus_frequencies = [12 10 8.57 7.5 6.66]; + +%Filtering the eeg data +% df = eegtoolkit.preprocessing.DigitalFilter; +% %This filter was created via the 'filterbuilder' method of Matlab +% df.filt = Hbp; + +%Indicate which channels of the data (different electrodes) will be used +ss = eegtoolkit.preprocessing.SampleSelection; +%We will use all EPOC channels for this example +channels = 1:1:14; +ss.channels = channels; +ss.sampleRange = [1,128]; + +%Sampling rate for the EPOC headset is 128Hz +samplingRate = 128; + +%Another required parameter for the CCA algorithm +numberOfHarmonics = 4; +%Initialize the Canonical Correlation Analysis class for the stimuli +%recognition +cca = eegtoolkit.featextraction.CCA(stimulus_frequencies,channels,samplingRate,numberOfHarmonics); + +%Simple classifier that uses the max value of the features to assign the +%label +maxC = eegtoolkit.classification.MaxChooser; + +%Assign the algorithm configuration to the LSL Wrapper class +lsl.preprocessing = {ss}; +lsl.featextraction = cca; +lsl.classification = maxC; + +%Find the streams in the network +lsl.resolveStreams(datastream,bufferSize,eventstream); +%Pause for 5 seconds to allow the stream to gather some data +pause(bufferSize); +%Run the recognition task. The task runs indefinetely until is specifically +%interrupted +lsl.runSSVEP(eventCode); diff --git a/doc/exampleLateFusion.html b/doc/exampleLateFusion.html new file mode 100644 index 0000000..043b18a --- /dev/null +++ b/doc/exampleLateFusion.html @@ -0,0 +1,126 @@ + + + + Description of exampleLateFusion + + + + + + + + + +
Home > . > exampleLateFusion.m
+ + + +

exampleLateFusion +

+ +

PURPOSE ^

+
Leave one subject out testing
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Leave one subject out testing
+ load filtMAMEM; % load a filter
+ sess = eegtoolkit.util.Session(Hhp);
+ sess.loadAll(1); %its best to do this once, outside the script (too much
+ time)
+ transf = eegtoolkit.transformer.PWelchTransformer();
+ Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(1); %Loads dataset I
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleLateFusion.m

+

SOURCE CODE ^

+
0001 % Leave one subject out testing
+0002 % load filtMAMEM; % load a filter
+0003 % sess = eegtoolkit.util.Session(Hhp);
+0004 % sess.loadAll(1); %its best to do this once, outside the script (too much
+0005 % time)
+0006 % transf = eegtoolkit.transformer.PWelchTransformer();
+0007 % Load the data. Call this once outside of the script so you dont have to
+0008 % load the data again and again. Make sure the dataset is included in your
+0009 % Matlab path
+0010 % sess = eegtoolkit.util.Session;
+0011 % sess.loadAll(1); %Loads dataset I
+0012 
+0013 %Load a filter from the samples
+0014 load filters/filt_IIRElliptic;
+0015 
+0016 
+0017 
+0018 refer = eegtoolkit.preprocessing.Rereferencing;
+0019 %Subtract the mean from the signal
+0020 refer.meanSignal = 1;
+0021 
+0022 ss = eegtoolkit.preprocessing.SampleSelection;
+0023 ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial
+0024 ss.channels = [138,139,150]; % Specify the channel(s) to be used
+0025 
+0026 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0027 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0028 
+0029 
+0030 %Extract features with the pwelch method
+0031 extr1 = eegtoolkit.featextraction.PWelch;
+0032 extr1.channel = 1; % will use channel 138
+0033 
+0034 extr2 = eegtoolkit.featextraction.PWelch;
+0035 extr2.channel = 2; % will use channel 139
+0036 
+0037 extr3 = eegtoolkit.featextraction.PWelch;
+0038 extr3.channel = 3; % will use channel 150
+0039 
+0040 extr = {extr1,extr2,extr3};
+0041 % Generate a special feature vector to be used with fusion classifier
+0042 aggr = eegtoolkit.aggregation.LateFusion;
+0043 %Configure the classifier
+0044 % Generate 3 instances of the "baseClassifier" and output the label by
+0045 % majority vote
+0046 classif = eegtoolkit.classification.FusionClassifierWrapper;
+0047 classif.baseClassifier = eegtoolkit.classification.LIBSVM;
+0048 
+0049 %Set the Experimenter wrapper class
+0050 experiment = eegtoolkit.experiment.Experimenter;
+0051 experiment.session = sess;
+0052 % Add the preprocessing steps (order is taken into account)
+0053 experiment.preprocessing = {ss,refer,df};
+0054 experiment.featextraction = {extr1,extr2,extr3};
+0055 experiment.aggregator = aggr;
+0056 experiment.classification = classif;
+0057 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0058 experiment.run();
+0059 for i=1:length(experiment.results)
+0060     accuracies(i) = experiment.results{i}.getAccuracy();
+0061 end
+0062 
+0063 accuracies'
+0064 %mean accuracy for all subjects
+0065 fprintf('mean acc = %f\n', mean(accuracies));
+0066 %get the configuration used (for reporting)
+0067 experiment.getExperimentInfo
+0068 experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleLateFusion.m b/doc/exampleLateFusion.m new file mode 100644 index 0000000..259bf3e --- /dev/null +++ b/doc/exampleLateFusion.m @@ -0,0 +1,68 @@ +% Leave one subject out testing +% load filtMAMEM; % load a filter +% sess = eegtoolkit.util.Session(Hhp); +% sess.loadAll(1); %its best to do this once, outside the script (too much +% time) +% transf = eegtoolkit.transformer.PWelchTransformer(); +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(1); %Loads dataset I + +%Load a filter from the samples +load filters/filt_IIRElliptic; + + + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial +ss.channels = [138,139,150]; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + + +%Extract features with the pwelch method +extr1 = eegtoolkit.featextraction.PWelch; +extr1.channel = 1; % will use channel 138 + +extr2 = eegtoolkit.featextraction.PWelch; +extr2.channel = 2; % will use channel 139 + +extr3 = eegtoolkit.featextraction.PWelch; +extr3.channel = 3; % will use channel 150 + +extr = {extr1,extr2,extr3}; +% Generate a special feature vector to be used with fusion classifier +aggr = eegtoolkit.aggregation.LateFusion; +%Configure the classifier +% Generate 3 instances of the "baseClassifier" and output the label by +% majority vote +classif = eegtoolkit.classification.FusionClassifierWrapper; +classif.baseClassifier = eegtoolkit.classification.LIBSVM; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {ss,refer,df}; +experiment.featextraction = {extr1,extr2,extr3}; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +experiment.getExperimentInfo +experiment.getTime \ No newline at end of file diff --git a/doc/exampleMotorPWelch.html b/doc/exampleMotorPWelch.html new file mode 100644 index 0000000..00086cc --- /dev/null +++ b/doc/exampleMotorPWelch.html @@ -0,0 +1,83 @@ + + + + Description of exampleMotorPWelch + + + + + + + + + +
Home > . > exampleMotorPWelch.m
+ + + +

exampleMotorPWelch +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleMotorPWelch.m

+

SOURCE CODE ^

+
0001 sess = eegtoolkit.util.Session;
+0002 sess.loadAll(6);
+0003 %
+0004 
+0005 % load('testingMotorVag1');
+0006 % % load
+0007 % sess = eegtoolkit.util.Session;
+0008 % % sess.loadMOTOR(labels,trials);
+0009 % sess.loadVag(trials,labels);
+0010 
+0011 ss = eegtoolkit.preprocessing.SampleSelection;
+0012 ss.channels = [1,3];
+0013 ss.sampleRange = [384,896];
+0014 
+0015 extr1  = eegtoolkit.featextraction.PWelch;
+0016 extr1.channel = 1;
+0017 
+0018 extr2 = eegtoolkit.featextraction.PWelch;
+0019 extr2.channel = 2;
+0020 
+0021 aggr = eegtoolkit.aggregation.ChannelConcat;
+0022 
+0023 classif = eegtoolkit.classification.MLR;
+0024 experiment = eegtoolkit.experiment.Experimenter;
+0025 experiment.session = sess;
+0026 experiment.preprocessing = {ss};
+0027 experiment.featextraction = {extr1, extr2};
+0028 experiment.aggregator = aggr;
+0029 experiment.classification = classif;
+0030 experiment.evalMethod = experiment.EVAL_METHOD_LOOCV;
+0031 % experiment.run();
+0032 % experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV;
+0033 experiment.run();
+0034 accuracy = experiment.results{1}.getAccuracy();
+0035
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleMotorPWelch.m b/doc/exampleMotorPWelch.m new file mode 100644 index 0000000..76f83cc --- /dev/null +++ b/doc/exampleMotorPWelch.m @@ -0,0 +1,35 @@ +sess = eegtoolkit.util.Session; +sess.loadAll(6); +% + +% load('testingMotorVag1'); +% % load +% sess = eegtoolkit.util.Session; +% % sess.loadMOTOR(labels,trials); +% sess.loadVag(trials,labels); + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.channels = [1,3]; +ss.sampleRange = [384,896]; + +extr1 = eegtoolkit.featextraction.PWelch; +extr1.channel = 1; + +extr2 = eegtoolkit.featextraction.PWelch; +extr2.channel = 2; + +aggr = eegtoolkit.aggregation.ChannelConcat; + +classif = eegtoolkit.classification.MLR; +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {ss}; +experiment.featextraction = {extr1, extr2}; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOOCV; +% experiment.run(); +% experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV; +experiment.run(); +accuracy = experiment.results{1}.getAccuracy(); + diff --git a/doc/exampleOptimal.html b/doc/exampleOptimal.html new file mode 100644 index 0000000..b895dfb --- /dev/null +++ b/doc/exampleOptimal.html @@ -0,0 +1,107 @@ + + + + Description of exampleOptimal + + + + + + + + + +
Home > . > exampleOptimal.m
+ + + +

exampleOptimal +

+ +

PURPOSE ^

+
Load the data. Call this once outside of the script so you dont have to
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
 Load the data. Call this once outside of the script so you dont have to
+ load the data again and again. Make sure the dataset is included in your
+ Matlab path
+ sess = eegtoolkit.util.Session;
+ sess.loadAll(1); %Loads dataset I
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleOptimal.m

+

SOURCE CODE ^

+
0001 % Load the data. Call this once outside of the script so you dont have to
+0002 % load the data again and again. Make sure the dataset is included in your
+0003 % Matlab path
+0004 % sess = eegtoolkit.util.Session;
+0005 % sess.loadAll(1); %Loads dataset I
+0006 
+0007 %Load a filter from the samples
+0008 load filters/filt_IIRElliptic;
+0009 
+0010 extr = eegtoolkit.featextraction.PWelchExperimental;
+0011 extr.nfft = 512;
+0012 extr.over_len = 0.75;
+0013 extr.win_len = 350;
+0014 
+0015 amu = eegtoolkit.preprocessing.Amuse;
+0016 amu.first = 15;
+0017 amu.last = 252;
+0018 
+0019 refer = eegtoolkit.preprocessing.Rereferencing;
+0020 %Subtract the mean from the signal
+0021 refer.meanSignal = 1;
+0022 
+0023 ss = eegtoolkit.preprocessing.SampleSelection;
+0024 ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial
+0025 ss.channels = 138; % Specify the channel(s) to be used
+0026 
+0027 df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0028 df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function
+0029 
+0030 svd = eegtoolkit.featselection.SVD;
+0031 svd.modes = 90;
+0032 
+0033 %Configure the classifier
+0034 classif = eegtoolkit.classification.LIBSVMFast;
+0035 
+0036 %Set the Experimenter wrapper class
+0037 experiment = eegtoolkit.experiment.Experimenter;
+0038 experiment.session = sess;
+0039 % Add the preprocessing steps (order is taken into account)
+0040 experiment.preprocessing = {amu,ss,refer,df};
+0041 experiment.featselection = svd;
+0042 experiment.featextraction = extr;
+0043 experiment.classification = classif;
+0044 experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV)
+0045 experiment.run();
+0046 for i=1:length(experiment.results)
+0047     accuracies(i) = experiment.results{i}.getAccuracy();
+0048 end
+0049 
+0050 accuracies'
+0051 %mean accuracy for all subjects
+0052 fprintf('mean acc = %f\n', mean(accuracies));
+0053 %get the configuration used (for reporting)
+0054 experiment.getExperimentInfo
+0055 experiment.getTime
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleOptimal.m b/doc/exampleOptimal.m new file mode 100644 index 0000000..36573f7 --- /dev/null +++ b/doc/exampleOptimal.m @@ -0,0 +1,55 @@ +% Load the data. Call this once outside of the script so you dont have to +% load the data again and again. Make sure the dataset is included in your +% Matlab path +% sess = eegtoolkit.util.Session; +% sess.loadAll(1); %Loads dataset I + +%Load a filter from the samples +load filters/filt_IIRElliptic; + +extr = eegtoolkit.featextraction.PWelchExperimental; +extr.nfft = 512; +extr.over_len = 0.75; +extr.win_len = 350; + +amu = eegtoolkit.preprocessing.Amuse; +amu.first = 15; +amu.last = 252; + +refer = eegtoolkit.preprocessing.Rereferencing; +%Subtract the mean from the signal +refer.meanSignal = 1; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.sampleRange = [1,1250]; % Specify the sample range to be used for each Trial +ss.channels = 138; % Specify the channel(s) to be used + +df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data +df.filt = Hbp; % Hbp is a filter built with "filterbuilder" matlab function + +svd = eegtoolkit.featselection.SVD; +svd.modes = 90; + +%Configure the classifier +classif = eegtoolkit.classification.LIBSVMFast; + +%Set the Experimenter wrapper class +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +% Add the preprocessing steps (order is taken into account) +experiment.preprocessing = {amu,ss,refer,df}; +experiment.featselection = svd; +experiment.featextraction = extr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_LOSO; % specify that you want a "leave one subject out" (default is LOOCV) +experiment.run(); +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +%mean accuracy for all subjects +fprintf('mean acc = %f\n', mean(accuracies)); +%get the configuration used (for reporting) +experiment.getExperimentInfo +experiment.getTime diff --git a/doc/exampleSMFA.html b/doc/exampleSMFA.html new file mode 100644 index 0000000..860897a --- /dev/null +++ b/doc/exampleSMFA.html @@ -0,0 +1,163 @@ + + + + Description of exampleSMFA + + + + + + + + + +
Home > . > exampleSMFA.m
+ + + +

exampleSMFA +

+ +

PURPOSE ^

+
+ +

SYNOPSIS ^

+
This is a script file.
+ +

DESCRIPTION ^

+
+ + +

CROSS-REFERENCE INFORMATION ^

+This function calls: +
    +
+This function is called by: +
    +
+ + + +

DOWNLOAD ^

+

exampleSMFA.m

+

SOURCE CODE ^

+
0001 clear
+0002 
+0003 % fileID = fopen('SMFA_Results.txt','a');
+0004 for subn=1:10
+0005     
+0006     %Dataset 4
+0007     sess = eegtoolkit.util.Session;
+0008     % sess.loadAll(4);
+0009     sess.loadSubject(4,subn);
+0010     
+0011     % %Dataset 2
+0012     % sess = ssveptoolkit.util.Session;
+0013     % sess.loadAll(2);
+0014     
+0015     load filters/filt_IIRElliptic;
+0016     
+0017     %Dataset 4
+0018     % sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75];
+0019     % extr = ssveptoolkit.featextraction.CCA(sti_f,[1:8],256,4);
+0020     
+0021     extr = eegtoolkit.featextraction.MLR_Transf(1:8);
+0022     %         sti_f = [9.25, 9.75, 10.25, 10.75, 11.25, 11.75, 12.25, 12.75, 13.25, 13.75, 14.25, 14.75];
+0023     %         extr = ssveptoolkit.featextraction.CCA(sti_f,1:8,256,4);
+0024     
+0025     %%Dataset 2
+0026     % sti_f = [12 10 8.57 7.50 6.66];
+0027     % sti_f = [6.66 7.5 8.57 10 12];
+0028     % extr = ssveptoolkit.featextraction.CCA(sti_f,[1:2],250,4);
+0029     
+0030     % extr = ssveptoolkit.featextraction.OMP(sti_f,[1:2],250,4,16,0);
+0031     %sti_f: reference signals
+0032     %[1:2]: input=2 channels. Depends on what you set on "ss.channels" e.g. if
+0033     %you select 10 channels you need to set "[1:10]"
+0034     %250: sampling rate (Dataset 1&2=250)
+0035     %4: number of harmonics of the reference signals
+0036     
+0037     % %Dataset 2
+0038     % amu = ssveptoolkit.preprocessing.Amuse;
+0039     % amu.first = 15;
+0040     % amu.last = 252;
+0041     
+0042     refer = eegtoolkit.preprocessing.Rereferencing;
+0043     %Subtract the mean from the signal
+0044     refer.meanSignal = 1;
+0045     
+0046     %Dataset 4
+0047     % m_secs = 2;
+0048     
+0049     % %Dataset 2
+0050     % m_secs = 5;
+0051     
+0052     ss = eegtoolkit.preprocessing.SampleSelection;
+0053     
+0054     %Dataset 4
+0055     onset=39;
+0056     %delay of the visual system
+0057     visual_delay = 35;
+0058     ss.sampleRange = [onset+visual_delay+1,onset+visual_delay+1*256];
+0059     ss.channels = 1:8;
+0060     % ss.channels = 7;
+0061     
+0062     % %Dataset 2
+0063     % ss.sampleRange = [1,250*m_secs]; % Specify the sample range to be used for each Trial
+0064     % % ss.channels = [116,126,137,138,139,147,150];%[126,138]%Specify the channel(s) to be used
+0065     % ss.channels = [126,138];
+0066     
+0067     %Dataset 4
+0068     df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data
+0069     [z,p,k]=butter(3,[6,80]/128);
+0070     [s,g]=zp2sos(z,p,k);
+0071     Hd = dfilt.df2sos(s,g);
+0072     df.filt = Hd;
+0073     
+0074     Res = zeros(length(1:4:10),length(1:4:100));
+0075     
+0076     % Set parameter grid to search
+0077     %         for qq=1:10
+0078     %             for ww=1:25
+0079     
+0080     %Number of subclasses per class
+0081     NumS = 2*ones(1,12);
+0082     
+0083     S = 0.4;
+0084     %                 kInt = qq;
+0085     %                 kPen = 4*(ww-1)+1;
+0086     kInt = 3;
+0087     kPen = 50;
+0088     classif = eegtoolkit.classification.SMFA(0,NumS,S,kInt,kPen);
+0089     
+0090     experiment = eegtoolkit.experiment.Experimenter;
+0091     experiment.session = sess;
+0092     
+0093     %Dataset 4
+0094     experiment.preprocessing = {ss,refer,df};
+0095     
+0096     % %Dataset 2
+0097     % experiment.preprocessing = {amu,ss,refer,df};% Order of preprocessing steps matters.
+0098     
+0099     experiment.featextraction = extr;
+0100     experiment.classification = classif;
+0101     experiment.evalMethod = experiment.EVAL_METHOD_LOBO; % specify that you want a "leave one subject out" (default is LOOCV)
+0102     % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV;
+0103     
+0104     %run the experiment
+0105     experiment.run();
+0106     accuracies = [];
+0107     for i=1:length(experiment.results)
+0108         accuracies(i) = experiment.results{i}.getAccuracy();
+0109     end
+0110     % accuracies'
+0111     % mean accuracy for all subjects
+0112 %     fprintf('mean acc = %.2f\n', mean(accuracies));
+0113     subaccuracies(subn) = mean(accuracies);
+0114 end
+0115 fprintf('mean acc for all subjects %.2f\n',mean(subaccuracies));
+
Generated on Fri 25-Nov-2016 17:12:22 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/exampleSMFA.m b/doc/exampleSMFA.m new file mode 100644 index 0000000..15a580d --- /dev/null +++ b/doc/exampleSMFA.m @@ -0,0 +1,115 @@ +clear + +% fileID = fopen('SMFA_Results.txt','a'); +for subn=1:10 + + %Dataset 4 + sess = eegtoolkit.util.Session; + % sess.loadAll(4); + sess.loadSubject(4,subn); + + % %Dataset 2 + % sess = ssveptoolkit.util.Session; + % sess.loadAll(2); + + load filters/filt_IIRElliptic; + + %Dataset 4 + % sti_f = [9.25, 11.25, 13.25, 9.75, 11.75, 13.75, 10.25, 12.25, 14.25, 10.75, 12.75, 14.75]; + % extr = ssveptoolkit.featextraction.CCA(sti_f,[1:8],256,4); + + extr = eegtoolkit.featextraction.MLR_Transf(1:8); + % sti_f = [9.25, 9.75, 10.25, 10.75, 11.25, 11.75, 12.25, 12.75, 13.25, 13.75, 14.25, 14.75]; + % extr = ssveptoolkit.featextraction.CCA(sti_f,1:8,256,4); + + %%Dataset 2 + % sti_f = [12 10 8.57 7.50 6.66]; + % sti_f = [6.66 7.5 8.57 10 12]; + % extr = ssveptoolkit.featextraction.CCA(sti_f,[1:2],250,4); + + % extr = ssveptoolkit.featextraction.OMP(sti_f,[1:2],250,4,16,0); + %sti_f: reference signals + %[1:2]: input=2 channels. Depends on what you set on "ss.channels" e.g. if + %you select 10 channels you need to set "[1:10]" + %250: sampling rate (Dataset 1&2=250) + %4: number of harmonics of the reference signals + + % %Dataset 2 + % amu = ssveptoolkit.preprocessing.Amuse; + % amu.first = 15; + % amu.last = 252; + + refer = eegtoolkit.preprocessing.Rereferencing; + %Subtract the mean from the signal + refer.meanSignal = 1; + + %Dataset 4 + % m_secs = 2; + + % %Dataset 2 + % m_secs = 5; + + ss = eegtoolkit.preprocessing.SampleSelection; + + %Dataset 4 + onset=39; + %delay of the visual system + visual_delay = 35; + ss.sampleRange = [onset+visual_delay+1,onset+visual_delay+1*256]; + ss.channels = 1:8; + % ss.channels = 7; + + % %Dataset 2 + % ss.sampleRange = [1,250*m_secs]; % Specify the sample range to be used for each Trial + % % ss.channels = [116,126,137,138,139,147,150];%[126,138]%Specify the channel(s) to be used + % ss.channels = [126,138]; + + %Dataset 4 + df = eegtoolkit.preprocessing.DigitalFilter; % Apply a filter to the raw data + [z,p,k]=butter(3,[6,80]/128); + [s,g]=zp2sos(z,p,k); + Hd = dfilt.df2sos(s,g); + df.filt = Hd; + + Res = zeros(length(1:4:10),length(1:4:100)); + + % Set parameter grid to search + % for qq=1:10 + % for ww=1:25 + + %Number of subclasses per class + NumS = 2*ones(1,12); + + S = 0.4; + % kInt = qq; + % kPen = 4*(ww-1)+1; + kInt = 3; + kPen = 50; + classif = eegtoolkit.classification.SMFA(0,NumS,S,kInt,kPen); + + experiment = eegtoolkit.experiment.Experimenter; + experiment.session = sess; + + %Dataset 4 + experiment.preprocessing = {ss,refer,df}; + + % %Dataset 2 + % experiment.preprocessing = {amu,ss,refer,df};% Order of preprocessing steps matters. + + experiment.featextraction = extr; + experiment.classification = classif; + experiment.evalMethod = experiment.EVAL_METHOD_LOBO; % specify that you want a "leave one subject out" (default is LOOCV) + % experiment.evalMethod = experiment.EVAL_METHOD_LOOCV; + + %run the experiment + experiment.run(); + accuracies = []; + for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); + end + % accuracies' + % mean accuracy for all subjects +% fprintf('mean acc = %.2f\n', mean(accuracies)); + subaccuracies(subn) = mean(accuracies); +end +fprintf('mean acc for all subjects %.2f\n',mean(subaccuracies)); \ No newline at end of file diff --git a/doc/fortran.png b/doc/fortran.png new file mode 100644 index 0000000..350c572 Binary files /dev/null and b/doc/fortran.png differ diff --git a/doc/graph.dot b/doc/graph.dot new file mode 100644 index 0000000..d92e500 --- /dev/null +++ b/doc/graph.dot @@ -0,0 +1,19 @@ +/* Created by mdot for Matlab */ +digraph m2html { + + exampleCSP [URL="exampleCSP.html"]; + exampleCombiCCA [URL="exampleCombiCCA.html"]; + exampleDefault [URL="exampleDefault.html"]; + exampleEPOCCCASVM [URL="exampleEPOCCCASVM.html"]; + exampleERRP [URL="exampleERRP.html"]; + exampleERRPSSVEPDemo [URL="exampleERRPSSVEPDemo.html"]; + exampleEarlyFusion [URL="exampleEarlyFusion.html"]; + exampleEpoc [URL="exampleEpoc.html"]; + exampleITCCA [URL="exampleITCCA.html"]; + exampleL1MCCA [URL="exampleL1MCCA.html"]; + exampleLSL [URL="exampleLSL.html"]; + exampleLateFusion [URL="exampleLateFusion.html"]; + exampleMotorPWelch [URL="exampleMotorPWelch.html"]; + exampleOptimal [URL="exampleOptimal.html"]; + exampleSMFA [URL="exampleSMFA.html"]; +} \ No newline at end of file diff --git a/doc/graph.html b/doc/graph.html new file mode 100644 index 0000000..c7461e9 --- /dev/null +++ b/doc/graph.html @@ -0,0 +1,42 @@ + + + + Dependency Graph for . + + + + + + + + + + +
< Master indexIndex for . >
+

Dependency Graph for .

+ +
+Dependency Graph for . + + + + + + + + + + + + + + + + + +
+ +
Generated on Fri 25-Nov-2016 17:12:21 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/graph.map b/doc/graph.map new file mode 100644 index 0000000..4d340f9 --- /dev/null +++ b/doc/graph.map @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/doc/graph.png b/doc/graph.png new file mode 100644 index 0000000..4aebd66 Binary files /dev/null and b/doc/graph.png differ diff --git a/doc/hp.png b/doc/hp.png new file mode 100644 index 0000000..d09f988 Binary files /dev/null and b/doc/hp.png differ diff --git a/doc/index.html b/doc/index.html new file mode 100644 index 0000000..6a2bf0a --- /dev/null +++ b/doc/index.html @@ -0,0 +1,34 @@ + + + + Index for Directory . + + + + + + + + + + +
< Master indexIndex for . >
+ +

Index for .

+ +

Matlab files in this directory:

+ +
 exampleCSP
 exampleCombiCCA
 exampleDefaultLoad the data. Call this once outside of the script so you dont have to
 exampleEPOCCCASVMLoad the data. Call this once outside of the script so you dont have to
 exampleERRPd2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
 exampleERRPSSVEPDemod2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter');
 exampleEarlyFusionLeave one subject out testing
 exampleEpocLoad the data. Call this once outside of the script so you dont have to
 exampleITCCA
 exampleL1MCCA
 exampleLSLAdd dependencies to the Matlab path, LibLSL is required for this example
 exampleLateFusionLeave one subject out testing
 exampleMotorPWelch
 exampleOptimalLoad the data. Call this once outside of the script so you dont have to
 exampleSMFA
+ + +

Subsequent directories:

+
    +
  • +eegtoolkit
  • .git
  • doc
  • filters
+

Dependency Graph

+ +
Generated on Fri 25-Nov-2016 17:12:20 by m2html © 2005
+ + \ No newline at end of file diff --git a/doc/left.png b/doc/left.png new file mode 100644 index 0000000..404df04 Binary files /dev/null and b/doc/left.png differ diff --git a/doc/linux.png b/doc/linux.png new file mode 100644 index 0000000..42c0c32 Binary files /dev/null and b/doc/linux.png differ diff --git a/doc/m2html.css b/doc/m2html.css new file mode 100644 index 0000000..030a84b --- /dev/null +++ b/doc/m2html.css @@ -0,0 +1,90 @@ +body { + background: white; + color: black; + font-family: arial,sans-serif; + margin: 0; + padding: 1ex; +} + +div.fragment { + width: 98%; + border: 1px solid #CCCCCC; + background-color: #f5f5f5; + padding-left: 4px; + margin: 4px; +} + +div.box { + width: 98%; + background-color: #f5f5f5; + border: 1px solid #CCCCCC; + color: black; + padding: 4px; +} + +.comment { + color: #228B22; +} +.string { + color: #B20000; +} +.keyword { + color: #0000FF; +} + +.keywordtype { color: #604020; } +.keywordflow { color: #e08000; } +.preprocessor { color: #806020; } +.stringliteral { color: #002080; } +.charliteral { color: #008080; } + +a { + text-decoration: none; +} + +a:hover { + background-color: #006699; + color:#FFFFFF; +} + +a.code { + font-weight: normal; + color: #A020F0; +} + +a.code:hover { + background-color: #FF0000; + color: #FFFFFF; +} + +h1 { + background: transparent; + color: #006699; + font-size: x-large; + text-align: center; +} + +h2 { + background: transparent; + color: #006699; + font-size: large; +} + +address { + font-size:small; +} + +form.search { + margin-bottom: 0px; + margin-top: 0px; +} +input.search { + font-size: 75%; + color: #000080; + font-weight: normal; + background-color: #eeeeff; +} + +li { + padding-left:5px; +} \ No newline at end of file diff --git a/doc/matlabicon.gif b/doc/matlabicon.gif new file mode 100644 index 0000000..7c2b5e6 Binary files /dev/null and b/doc/matlabicon.gif differ diff --git a/doc/mex.png b/doc/mex.png new file mode 100644 index 0000000..396f1bc Binary files /dev/null and b/doc/mex.png differ diff --git a/doc/pcode.png b/doc/pcode.png new file mode 100644 index 0000000..6801bd9 Binary files /dev/null and b/doc/pcode.png differ diff --git a/doc/right.png b/doc/right.png new file mode 100644 index 0000000..067c5ba Binary files /dev/null and b/doc/right.png differ diff --git a/doc/sgi.png b/doc/sgi.png new file mode 100644 index 0000000..20052bc Binary files /dev/null and b/doc/sgi.png differ diff --git a/doc/simulinkicon.gif b/doc/simulinkicon.gif new file mode 100644 index 0000000..1386ddd Binary files /dev/null and b/doc/simulinkicon.gif differ diff --git a/doc/solaris.png b/doc/solaris.png new file mode 100644 index 0000000..e31e8a2 Binary files /dev/null and b/doc/solaris.png differ diff --git a/doc/up.png b/doc/up.png new file mode 100644 index 0000000..b348b9a Binary files /dev/null and b/doc/up.png differ diff --git a/doc/windows.png b/doc/windows.png new file mode 100644 index 0000000..6cec95b Binary files /dev/null and b/doc/windows.png differ diff --git a/exampleERRPSSVEPDemo.m b/exampleERRPSSVEPDemo.m new file mode 100644 index 0000000..4bd172f --- /dev/null +++ b/exampleERRPSSVEPDemo.m @@ -0,0 +1,46 @@ +% d2 = designfilt('bandpassiir', 'SampleRate', 256, 'FilterOrder', 8 ,'HalfPowerFrequency1', 1, 'HalfPowerFrequency2', 10,'DesignMethod', 'butter'); + +sess = eegtoolkit.util.Session; +sess.loadSubjectSession(8,5,2); + +[z,p,k]=butter(3,[1,10]/64); +[s,g]=zp2sos(z,p,k); +Hd = dfilt.df2sos(s,g); +df = eegtoolkit.preprocessing.DigitalFilter; % +df.filt = Hd; + +ss = eegtoolkit.preprocessing.SampleSelection; +ss.channels = [1:14]; +ss.sampleRange = [1:6:200]; + +extr = {}; +for i=1:3 + extr{i} = eegtoolkit.featextraction.PWelch; + extr{i}.channel = 1; +end + +aggr = eegtoolkit.aggregation.ChannelConcat; + +classif = eegtoolkit.classification.LIBSVM; +classif.kernel = classif.KERNEL_RBF; +classif.gamma = 1/9; +classif.cost = 1; + +%Setup experiment +experiment = eegtoolkit.experiment.Experimenter; +experiment.session = sess; +experiment.preprocessing = {df,ss}; +experiment.featextraction = extr; +experiment.aggregator = aggr; +experiment.classification = classif; +experiment.evalMethod = experiment.EVAL_METHOD_XFOLD_CV; + +experiment.run(10); + +accuracies = []; +for i=1:length(experiment.results) + accuracies(i) = experiment.results{i}.getAccuracy(); +end + +accuracies' +fprintf('mean acc = %.2f\n',mean(accuracies)); \ No newline at end of file