Code
Code
Accuracy Maximization Analysis (AMA) - Matlab and C code implementation
Description: Computes the posterior probability of a category given the filter response(s) to the stimulus
Download: AMAengine.zip ( more info: AMAengine_ReadMe.rtf )
•Geisler WS, Najemnik J, Ing AD (2009). Optimal stimulus encoders for natural tasks. Journal of Vision, 9(13):17, 1-16 [ pdf | correction ]
•Burge J, Geisler WS (2011). Optimal defocus estimation in individual natural images. Proceedings of the National Academy of Sciences, 108 (40): 16849-16854 [ pdf ]
Relevant publications: Please cite the following papers if the code on this page contributes to your research
Logic:
(4) Response Distributions of All Stims in All Ctgs: N(r(i,j),sigma(i,j))
(7) Posterior Probability of Correct Category given s(k,l)
(3) Response Distributions of All Stims in Same Ctg: N(r(k,j),sigma(k,j))
(6) Likelihood of Mean Response r(k,l) from s(k,j) and s(i,j)
(5) Likelihood of Mean Response r(k,l) from s(k,l)
(2) Response Distribution of that Stimulus: N(r(k,l),sigma(k,l))
(1) Select stimulus: s(k,l)
Use: AMA requires computing the posterior probability of each stimulus category given the filter responses
for every stimulus in the training set
To use AMA, a minimization routine and an objective function must be chosen
Note that the minimization routine and objective function are not fundamental to the AMA procedure
To get you started, an example minimization routine and an example objective function are provided
However, other minimization routines and/or objective functions may better suit your needs
The example below uses Matlab’s fmincon.m to find AMA filters that minimize the average relative
entropy of the posterior probability distributions over the categories, across all stimuli in the training set
%%% OBJECTIVE FUNCTION %%%
function E = objFunc(w,s,ctgInd)
% function E = objFunc(s,w,ctgInd)
%
% objective function for AMA
%
% s: stimuli. vector magnitude of each stimulus must equal 1 [numStims x numDimensions]
% w: filters. vector magnitude of each filter must equal 1 [numDimensions x numFilters]
% ctgInd: category membership of each stimulus [numDimensions x 1]
% %%%%%%
% E: objective to minimize
r = stim2resp(s,w,5.7); % mean response from filter weights and stimuli
sigma = resp2sigma(r,1.36,0.23); % sigma from mean response
pp = AMAengine(r,sigma,ctgInd); % posterior probability of correct category
E = -sum((1/size(s,1)).*log2(pp)); % average relative entropy in bits
(1) Download and unzip AMAengine.zip
(2) Put all five unzipped files in the current folder and/or in a folder on the Matlab path
(3) At the command prompt type: >> mex AMAengine.cpp
(4) At the command prompt type: >> help AMAengine
(5) At the command prompt type: >> AMAengineTest;
%%% MINIMIZATION ROUTINE %%%
>> [w] = fmincon(@(w) objFunc(w,s,ctgInd),w0,[],[],[],[],[],[],@(w) wConEq(w));
%%% CONSTRAINT FUNCTION %%%
function [c,ceq] = wConEq(w)
c = [];
ceq = sum(w.^2)-1; % filter vector magnitude must equal 1
%%% RESPONSE FUNCTION %%%
function [r] = stim2resp(s,w,rMax)
r = rMax.*(s*w);
%%% SIGMA FUNCTION %%%
function [sigma] = resp2sigma(r,fano,varBase)
sigma = sqrt( fano.*abs(r) + varBase );
Setup:
(8) Repeat for all other stimuli in the training set
All code is published under the GNU General Public License: this software is free; you can
redistribute it and/or modify it under the terms of the GNU General Public License (GPLv3)
Please report bugs to jburge@mail.cps.utexas.edu with subject jburge.cps.utexas.edu/Code
• Talks
• Research
• Teaching
• CV
• Music
• Patents

• People
• Code
• Projects
• Demos
• Press