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 )

  1. Geisler WS, Najemnik J, Ing AD (2009). Optimal stimulus encoders for natural tasks. Journal of Vision, 9(13):17, 1-16 [ pdf | correction ]

  1. 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

                                    or in the GitHub repository 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


        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

%%% OBJECTIVE FUNCTION %%%

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

% COMPUTER OBJECTIVE

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

  1. (1) Download and unzip AMAengine.zip

  2. (2) Put all five unzipped files in the current folder and/or in a folder on the Matlab path

  3. (3) At the command prompt type: >> mex AMAengine.cpp

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

  5. (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(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]

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

  1. Talks

  1. Research

  1. Teaching

  1. Music

  1. Patents

 HomeHome.htmlResearch.htmlshapeimage_4_link_0
  1. People

  1. Code

  1. Projects

  1. Demos

  1. Press

  1. Contact

  1. CV

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

                                http://github.com/burgelab/AMA

  1. 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 ]

  1. 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 ]

  1. 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 ]