Please see the AMA code release at the BurgeLab GitHub repository for our most update-to-date code:


Accuracy Maximization Analysis (AMA) - Matlab and C code implementation

Relevant publications: Please cite the following papers if the code on this page

                                    or in the GitHub repository contributes to your research

               • Burge J, Jaini P (2017). Accuracy Maximization Analysis for sensory-perceptual tasks: Computational

                  improvements, filter robustness, and coding advantages for scaled additive noise.  PLoS Computational

                  Biology, 13(2): e1005281. doi:10.1371/journal.pcbi.1005281 [ pdf ]

               • Jaini P, Burge J (2017). Linking normative models of natural tasks with descriptive models of neural

                  response.  bioarXiv, doi:https://doi.org/10.1101/158741 [ pdf ]

               • Burge J, Geisler WS (2015). Optimal speed estimation in natural image movies predicts human

                  performance. Nature Communications, 6: 7900, 1-11 doi:10.1038/ncomms8900 [ pdf ]

               • Burge J, Geisler WS (2011). Optimal defocus estimation in individual natural images. Proceedings of

                  the National Academy of Sciences, 108 (40): 16849-16854 [ pdf ]

               • Geisler WS, Najemnik J, Ing AD (2009). Optimal stimulus encoders for natural tasks. Journal of

                   Vision, 9(13):17, 1-16 [ pdf | correction ]

Download: AMAengine.zip ( more info: AMAengine_ReadMe.rtf )

Description: Computes the posterior probability of a category given the filter response(s) to the stimulus

Setup:          (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                    

                               ...OR, if it errors out, type: >> mex -compatibleArrayDims AMAengine.cpp

                    (4) At the command prompt type: >> help AMAengine

                    (5) At the command prompt type: >> AMAengineTest;

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

        Troubleshooting (Matlab R2011a, R2011b, R2012a and Xcode 4.2, Xcode 4.3)

        Any combination of these versions of Mathworks & Apple software may prevent Matlab from finding the C++ header files

        To fix the issue, go to http://www.mathworks.com/support/solutions/en/data/1-FR6LXJ/ and follow the instructions


>> [w] = fmincon(@(w) objFunc(w,s,ctgInd),w0,[],[],[],[],[],[],@(w) wConEq(w));


function E = objFunc(w,s,ctgInd)

% function E = objFunc(w,s,ctgInd)


% objective function for AMA


% w:      filters. vector magnitude of each  filter  must equal 1    [numDimensions x numFilters]

% s:      stimuli. vector magnitude of each stimulus must equal 1    [numStims x numDimensions]

% ctgInd: category indices of each stimulus (must be integer valued) [numStims x 1]

% %%%%%%

% E:      objective to minimize

if min(ctgInd) == 0, error(['objFunc: WARNING! min(ctgInd) must be equal 1']); end; % error check


r      =  stim2resp(w,s,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


function [c,ceq] = wConEq(w)

c = [];

ceq = sum(w.^2)-1;                       % filter vector magnitude must equal 1


function [r] = stim2resp(w,s,rMax)

r = rMax.*(s*w);                         % mean filter response      [numStims x 1]

%%%   SIGMA   FUNCTION  %%%

function [sigma] = resp2sigma(r,fano,varBase)

sigma = sqrt( fano.*abs(r) + varBase );  % stddev of filter response [numStims x 1]

(1) Select stimulus: s(k,l)

(2) Response Distribution of that Stimulus:               N(r(k,l),sigma(k,l))

(3) Response Distributions of All Stims in Same Ctg:  N(r(k,j),sigma(k,j))

(4) Response Distributions of All Stims in All Ctgs: N(r(i,j),sigma(i,j))

(5) Likelihood of Mean Response r(k,l) from s(k,l)

(6) Likelihood of Mean Response r(k,l) from s(k,j) and s(i,j)

(7) Posterior Probability of Correct Category given s(k,l)

(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