how to access abstract class in matlab

12 views (last 30 days)
Hi,
how can i access this abstract class i had lote of try to access this abstract class directly and indirectly .when i try this indirectly make object it give error of <Error displaying value > and when i access direclt it give error in calling obj@featureGenerationUnit
thanks already
classdef asymmetryFeatures < featureGenerationUnit
properties
psd;
de;
EEG;
INFO;
end
methods
% Constructor calls super
function obj = asymmetryFeatures(EEG, INFO)
obj@featureGenerationUnit(EEG, INFO);
obj.addDE();
end
%%Takes in a 2D matrix of channels versus raw EEG and computes
%%the psd over given frequency bands in the INFO datafile
function [psdPerBand] = getPSD(obj, data)
%get data dimensions
[nChannels, N] = size(data);
%psd = zeros(nChannels,size(obj.INFO.bands.names,2));
%compute raw power sprectral density (psd)
xdft = fft(data, N, 2);
xdft = xdft(:,1:N/2+1);
psd = (1/(obj.INFO.fs*N)) * abs(xdft).^2;
%take away mirrored data
psd(:,2:end-1) = 2*psd(:,2:end-1);
%Get indexes for frequency band cutoffs
INFO.bands.i = obj.INFO.bands.freq.*(size(psd,2)-1)/(obj.INFO.fs/2);
nBands = size(obj.INFO.bands.freq,1);
psdPerBand = zeros(nChannels,nBands);
for band = 1:nBands
%Get indexes of interest
name = char(obj.INFO.bands.names(band));
i1 = obj.INFO.bands.freq(band,1);
i2 = obj.INFO.bands.freq(band,2);
%number of points used in calculation
point_num = abs(i2 - i1);
%compute mid freq for each band (plotting)
INFO.bands.med(band) = i1 + (i2-i1)/2;
%index PSD matrix for given band
band_data = psd(:,i1:i2);
%Calculate average power over band for each channel
psdPerBand(:,band) = sum(band_data,2)./point_num;
end
end
function addPSD(obj)
obj.psd = zeros(obj.EEG.nbchan,obj.INFO.bands.n,obj.INFO.epochs);
for epoch = 1:obj.INFO.epochs
obj.psd(:,:,epoch) = obj.getPSD(obj.EEG.data(:,:,epoch));
end
end
function addDE(obj)
if(size(obj.psd)>0)
obj.de = log(obj.psd);
else
obj.addPSD()
obj.de = log(obj.psd);
end
end
function [features, names] = doOnPairsByBands(obj, data, operation, pairs, operationName)
% if string pairs, map to numbers
if(iscell(pairs))
pairs = arrayfun(@(x) obj.INFO.channelMap(x{1}),[pairs(:,1),pairs(:,2)]);
end
nPairs = size(pairs,1);
[~, nBands] = size(data);
nFeatures = nPairs*nBands;
features = zeros(nFeatures,1);
names = cell(nFeatures,1);
count = 0;
for i=1:nPairs
%disp(assymPairs{i,1})
for band = 1:nBands
count = count + 1;
left = pairs(i,1);
right = pairs(i,2);
features(count,:) = operation(data(left,band), data(right,band));
mapChan = @(x) obj.INFO.reverseMap(x);
bandMap = @(x) obj.INFO.bands.names{x};
names{count} = strcat(mapChan(left),'-',mapChan(right),'-',bandMap(band),'-',operationName);
end
end
end
function [features, sampleNames] = forAllEpochs(obj,func,data,operation,pairs,operationName)
%get size
epochs = obj.INFO.epochs;
[sampleFeature,sampleNames] = func(data(:,:,1), operation,pairs,operationName);
features = zeros([epochs size(sampleFeature)]);
for epoch = 1:epochs
[features(epoch,:),~] = func(data(:,:,epoch), operation,pairs,operationName);
end
end
function processPairs(obj,data, operation, pairs, operationName)
[features,names] = obj.forAllEpochs(@obj.doOnPairsByBands,data,operation,pairs,operationName);
obj.addFeaturesAndNames(features,names);
end
function addPSDfeatures(obj)
if(size(obj.psd) == 0)
obj.addPSD();
end
[nChannels,nBands, epochs] = size(obj.psd);
names = (strcat(...
(arrayfun(@(x) obj.INFO.reverseMap(x),repmat([1:nChannels],1,nBands),'UniformOutput',false)),'-',...
arrayfun(@(x) obj.INFO.bands.names{x},reshape(repmat([1:nBands],1,nChannels),1,[]),'UniformOutput',false)...
,'-psd'))';
dims = size(obj.psd);
features = reshape(permute(obj.psd,[3,2,1]),dims(3),dims(1)*dims(2));
obj.addFeaturesAndNames(features,names);
end
function addDEfeatures(obj)
if(size(obj.de) == 0)
obj.addDE();
end
[nChannels,nBands, epochs] = size(obj.de);
names = (strcat(...
(arrayfun(@(x) obj.INFO.reverseMap(x),repmat([1:nChannels],1,nBands),'UniformOutput',false)),'-',...
arrayfun(@(x) obj.INFO.bands.names{x},reshape(repmat([1:nBands],1,nChannels),1,[]),'UniformOutput',false)...
,'-de'))';
dims = size(obj.de);
features = reshape(permute(obj.de,[3,1,2]),dims(3),dims(1)*dims(2));
obj.addFeaturesAndNames(features,names);
end
function addDASMfeatures(obj)
obj.processPairs(obj.de, @gsubtract, obj.INFO.pairs.lateral, 'sub');
end
function addDCAUfeatures(obj)
obj.processPairs(obj.de, @gsubtract, obj.INFO.pairs.caudal, 'sub');
end
function addRASMfeatures(obj)
obj.processPairs(obj.de, @gdivide, obj.INFO.pairs.lateral, 'div');
end
function addALLfeatures(obj)
N = size(obj.de,1);
count = 0;
pairs = zeros(N*(N-1)/2,2);
for i = 1:N
for j = i+1:N
count = count + 1;
pairs(count,:) = [i, j];
end
end
obj.processPairs(obj.de, @gsubtract, pairs, 'sub');
end
function [features,names] = getClassic(obj)
obj.addPSDfeatures();
obj.addDEfeatures();
obj.addDASMfeatures();
obj.addDCAUfeatures();
obj.addRASMfeatures();
features = obj.features;
names = obj.names;
end
function[features,names] = getAll(obj)
obj.addDEfeatures();
obj.addALLfeatures();
features = obj.features;
names = obj.names;
end
function[features,names] = getDE(obj)
obj.addDEfeatures();
features = obj.features;
names = obj.names;
end
function addFeaturesAndNames(obj, newFeatures, newNames)
if(size(obj.features,1) > 0)
obj.features = horzcat(obj.features, newFeatures);
else
obj.features = newFeatures;
end
if(size(obj.names,1) > 0)
obj.names = cat(1, obj.names, newNames);
else
obj.names = newNames;
end
end
function [features] = getFeatures(obj)
features = obj.features;
end
end
end
.
% inherets from handle to work with reference
classdef (Abstract) featureGenerationUnit < handle
properties
EEG;
features;
names;
INFO;
status;
end
methods
function obj = featureGenerationUnit(EEG, INFO)
obj.EEG = EEG;
obj.INFO = INFO;
end
function loadData(EEG)
obj.EEG = EGG;
end
function loadInfo(INFO)
obj.INFO = INFO;
end
end
methods(Abstract)
getFeatures(obj)
end
end
  3 Comments
Muhammad Khalid
Muhammad Khalid on 12 Aug 2019
I could not find this type of question
Guillaume
Guillaume on 14 Aug 2019
@Muhammad, use comments to add additional information. Do not use Answer this question for that. Your question now has 4 answers, included one accepted, so nobody is going to bother looking at it, thinking: "well it already has 4 answers, one has been accepted, there's probably nothing more to say".
So, please delete your answers and post them as comment to your question (or the answer you've accepted), as I've done here.

Sign in to comment.

Accepted Answer

per isakson
per isakson on 12 Aug 2019
Edited: per isakson on 12 Aug 2019
I'm not sure, I exactly understand what you mean. However, I try
"how can I access this abstract class" You cannot "access" an abstract class "directly".
>> fGU = featureGenerationUnit(EEG,INFO)
Abstract classes cannot be instantiated. Class 'featureGenerationUnit' defines
abstract methods and/or properties.
"indirectly" you can "access" it by creating an instance of its subclass, asymmetryFeatures.
There are several mistakes in your code, e.g. defining EEG and INFO in the subclass.
If you want further help you need to supply values of EEG and INFO.
/R2018b

More Answers (3)

Muhammad Khalid
Muhammad Khalid on 13 Aug 2019
thanks @per isakson
last info is the info data and Table 11 is EEG
  1 Comment
per isakson
per isakson on 13 Aug 2019
Edited: per isakson on 14 Aug 2019
The method, addPSD, indicates that EEG is a struct with two fields, nbchan and data. Table11.txt contains one column of numbers.
function addPSD(obj)
obj.psd = zeros(obj.EEG.nbchan,obj.INFO.bands.n,obj.INFO.epochs);
for epoch = 1:obj.INFO.epochs
obj.psd(:,:,epoch) = obj.getPSD(obj.EEG.data(:,:,epoch));
end
end
How shall the column of numbers be assigned to EEG.data?

Sign in to comment.


Muhammad Khalid
Muhammad Khalid on 14 Aug 2019
Edited: per isakson on 14 Aug 2019
classdef mRMR < featureExtractionUnit
methods
% Constructor calls super
function obj = mRMR(INFO, features, names, labels)
obj@featureExtractionUnit(INFO);
obj.features = features;
obj.names = names;
obj.labels = labels;
end
function load(obj,features, labels)
obj.features = features;
obj.labels = labels;
end
function normalize(obj)
temp = bsxfun(@minus,obj.features,mean(obj.features));
obj.features = bsxfun(@rdivide,temp,std(obj.features));
end
function changeResolution(obj, resolution)
obj.features = round(obj.features.*resolution);
end
function select(obj, nFeatures)
obj.selected_i = feast('mrmr',nFeatures,obj.features, obj.labels);
obj.selected_features = obj.features(:,obj.selected_i);
obj.selected_names = obj.names(obj.selected_i);
end
function [selected_features,selected_names] = extract(obj,resolution,nFeatures)
obj.normalize();
obj.changeResolution(resolution);
obj.select(nFeatures);
selected_features = obj.selected_features;
selected_names = obj.selected_names;
end
end
end
.
function [ resTable, features_i ] = classifySVM( features, labels, numFeatures, res, resTable )
%% Cheat
%features(:,1) = labels;
%% Normalize Features
temp = bsxfun(@minus,features,mean(features));
features = bsxfun(@rdivide,temp,std(features));
%% Discretize
features_res = round(features.*res);
%% Select Featuresres
features_i = feast('mrmr',numFeatures,features_res, labels);
features = features(:,features_i);
%% Cross Val
SVMModel = fitcsvm(features, labels,'KernelFunction','linear','Standardize','on','CrossVal','on','KFold', 10);
%indGenError = kfoldLoss(SVMModelValence,'mode','individual')
avgGeneralizationError = kfoldLoss(SVMModel);
%CVSVMModelValence = crossval(SVMModelValence);
%[predicted_labels_train,scores] = predict(CVSVMModelValence, train_data);
%[predicted_labels,scores] = predict(SVMModelValence, test_data);
newRow = {numFeatures res avgGeneralizationError num2cell(features_i) SVMModel};
resTable = [resTable; cell2table(newRow, 'VariableNames',resTable.Properties.VariableNames)];
end

Muhammad Khalid
Muhammad Khalid on 14 Aug 2019
I use a code for preprocessing and feature Extraction and I have no code for support vector machine but i have other code which has feature is preprocessing , feature extraction and svm which is based on EEGLAB .Can I use this Code which is based on only for support vector machine without EEGLAB ?
  1 Comment
per isakson
per isakson on 14 Aug 2019
This is a new question. I has no answer. Post a new question and tag it "EEGLAB".

Sign in to comment.

Categories

Find more on EEG/MEG/ECoG in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!