Matlab functions for finding false acceptance rate????

조회 수: 11 (최근 30일)
saba
saba 2012년 4월 24일
편집: SGUNITN 2018년 2월 9일
i want to calculate the false acceptance rate for a image data base.....can u plz help me with functions or code that i can use for this purpose. i have divided my data into training and testing set now i will do the comparison comparing 1 to n values and check the FAR but i dont know how to implement it...plz help
  댓글 수: 1
Jan
Jan 2018년 2월 7일
편집: Jan 2018년 2월 7일
Concerning the Copyright note in Sandeep Gupta's answer: See the MATLAB Central Terms of Use:
4. MATLAB Answers
You agree that all Content that you contribute to the MATLAB Answers
portion of MATLAB Central will be licensed under the Creative Commons
Attribution Share Alike 3.0 license.
As far as I know this is no conflict with a copyright claim, as long as it is not accompanied by any stricter conditions as the "CC BY-SA 3.0" license.

댓글을 달려면 로그인하십시오.

답변 (1개)

SGUNITN
SGUNITN 2018년 2월 6일
편집: SGUNITN 2018년 2월 7일
Please acknowledge to "Machine-learning-using-PRTools" project while using this code and use the link (https://www.researchgate.net/project/Machine-learning-using-PRTools) in the footnote.
The database, label and source code can be downloaded at https://www.researchgate.net/project/Machine-learning-using-PRTools
To generate the input data
genMDS = gendatm; %160 x 20
csvwrite('gendatm3Feb18.csv', genMDS.data);
And create the labels 160x1 array with 16 class of size 20.
Create a file name main.m
This is the main file containing 2 functions.
--------------------------------------------------------------------------
clear;
clc;
%genMDS = gendatm; %160 x 20
%csvwrite('gendatm3Feb18.csv', genMDS.data);
% scatterd(genMDS); % defines the plotting domain of interest
data = csvread('gendatm3Feb18.csv');
labels = csvread('labels8x20.csv'); % Read a 1 D labels 8 x 20
prData = prdataset(data, labels);
prData = setprior(prData,0);
prData(isnan(prData)) = 0;
%//////////////////////////////////////////////////////////////////////
nClasses = 8;
nTrainingSamples = 5;
nSamplesPerClass = 20;
[train, test] = gendat(prData, nTrainingSamples/nSamplesPerClass); % Here assign observations for
training
w = qdc(train); % the class names (labels) of train are stored in w
trueTrainingLabels = getlabels(w); % this routine shows labels
%plotc(w, 'col');
%hold on;
%scatterd(a); % defines the plotting domain of interest
FR = test*w; % classify test set
arrFRLabels = FR*labeld; % get the labels of the test objects
%disp([+d arrFRLabels]); % show the posterior probabilities and labels
weighted_average_error = FR*testc;
%///////////////////////////////////////////////////////////////////
prCM = test*w*classc; % Confusion Matrix
csvwrite('cm.csv', prCM.data);
csvwrite('true_label.csv', prCM.nlab);
csvwrite('est_label.csv', arrFRLabels);
% Calculate FRR that is the number of false rejected for each class.
FRR = fxGetFRR(arrFRLabels, nClasses, nSamplesPerClass-nTrainingSamples);
xlswrite('result.xls', FRR, 'FRR');
%///////////////////////////////////////////////////////////////////
% Attack Scenario
FAR = cell(nClasses+3, 3);
FAR(1,:) = {'Class', 'TRR', 'FAR'};
attackLabels = zeros((nClasses-1)*nSamplesPerClass, 1);
for c = 1:nClasses
attackLabels(1:nTotalAttacks, 1) = c;
% Exclude data between startRow and endRow
startExRow = (c-1)*nSamplesPerClass;
endExRow = startExRow + nSamplesPerClass + 1;
A = data(1:startExRow,:);
B = data(endExRow:nClasses*nSamplesPerClass,:);
attackData = vertcat(A,B);
prAttack = prdataset(attackData, attackLabels);
prAttack = setprior(prAttack,0);
prAttack(isnan(prAttack)) = 0;
trueAttackLabels = getlabels(prAttack);
% FAR
FA = prAttack*w;
arrFALabels = FA*labeld;
% Calculate FAR that is the number of false acceptance for each class.
FARperClass = fxGetFAR(arrFALabels, nClasses, nSamplesPerClass, c);
FAR(c+1,:) = FARperClass;
end
FAR{nClasses+2,1} = 'SUM';
FAR{nClasses+3,1} = 'PERCENTAGE';
for col = 2:3
sum = 0;
for c = 2:nClasses+1
sum = sum + FAR{c,col};
end
FAR{nClasses+2,col} = sum;
FAR{nClasses+3, col} = FAR{nClasses+2,col}/(nClasses*(nClasses-1)*nSamplesPerClass);
end
xlswrite('result.xls', FAR, 'FAR');
--------------------------------------------------------------------------------------------------
Second file, create a file name fxGetFRR.m
function FRR = fxGetFRR(arrLabels, aClasses, aObservations)
% FAR - False Rejection Rate is number of false rejections per class
% for a legitimate user.
FRR = cell(aClasses+3, 3);
FRR(1,:) = {'Class', 'TAR', 'FRR'};
for c = 1:aClasses
trueAccepts = 0;
for o = 1:aObservations
nCount = aObservations * (c-1) + o;
%fprintf('%d,%d\n', c, aLabels(nCount))
if arrLabels(nCount) == c
trueAccepts = trueAccepts + 1;
end
end
FRR(c+1,:) = {c, trueAccepts, aObservations - trueAccepts};
end
FRR{aClasses+2,1} = 'SUM';
FRR{aClasses+3,1} = 'PERCENTAGE';
for col = 2:3
sum = 0;
for c = 2:aClasses+1
sum = sum + FRR{c,col};
end
FRR{aClasses+2,col} = sum;
FRR{aClasses+3, col} = FRR{aClasses+2,col}/(aClasses*aObservations);
end
--------------------------------------------------------------------------------------------------
Third file, create a file name fxGetFAR.m
function FAR = fxGetFAR(arrLabels, aClasses, aObservations, aC)
% FAR - False acceptance rate is number of false acceptance per class
% for imposters.
nTotalObservations = (aClasses-1)*aObservations;
falseAccepts = 0;
for o = 1:nTotalObservations
if arrLabels(o) == aC
falseAccepts = falseAccepts + 1;
end
end
FAR = {aC, nTotalObservations - falseAccepts, falseAccepts};
  댓글 수: 2
Jan
Jan 2018년 2월 7일
How is this code used? Neither the inputs files are provided, nor is it explained, what they should contain.
"sum" is used as name of a variable, which is an evergreen problem in the forum. The code can be simplified, e.g.:
falseAccepts = 0;
for o = 1:nTotalObservations
if arrLabels(o) == aC
falseAccepts = falseAccepts + 1;
end
end
can and should be replaced by:
falseAccept = sum(arrLabels(1:nTotalObservations) == aC);
Or
sum = 0;
for c = 2:nClasses+1
sum = sum + FAR{c,col};
end
by
S = sum([FAR{2:nClasses+1, col}]);
SGUNITN
SGUNITN 2018년 2월 9일
편집: SGUNITN 2018년 2월 9일
Please refer to the link https://www.researchgate.net/project/Machine-learning-using-PRTools
I have uploaded the source file along with labels file. DataSet can be generated dynamically.
genMDS = gendatm; %160 x 20
Most of the modern compilers optimize the instruction. for example, in case of C++ if you write the instruction
if (1) {
// DO NOTHING
}
g++ compiler will optimize the program by excluding the redundant code like above.
I guess Matlab compiler can also take care of below type of code.
sum = 0;
for c = 2:nClasses+1
sum = sum + FAR{c,col};
end
I deliberately not have optimized my code. However, your suggestions are appreciated.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by