Take the 2-minute tour ×
Computational Science Stack Exchange is a question and answer site for scientists using computers to solve scientific problems. It's 100% free, no registration required.

Are there any open-source auto-differentiation libraries for MATLAB? I am aware of commerical packages such as http://tomopt.com/tomlab/products/mad/ and plenty of C++ libraries, but I can't find much more MATLAB other than http://www.mathworks.com/matlabcentral/fileexchange/15235-automatic-differentiation-for-matlab which isn't a major package.

Added

As a bare minimum of functionality, I need to be able it to handle vectors as variables. In that MathWorks package I reference, for example, here is a test case:

val = [1 2 3]; %Some value
x = myAD(val); %Creates a vector with that value.

x .* [4 5 6]; %This should give the derivatives [4; 5; 6]
x_inner = sum(x.* x);% To get the inner product.  The derivative here is [2 4 6] here
%Ideally, the above would simply be x_inner = x * x'
share|improve this question
1  
When I last used AdMat some years ago it was quite capable, but it doesn't satisfy your requirement of being open source. –  Brian Borchers Jul 20 at 3:52

4 Answers 4

up vote 3 down vote accepted

The SINTEF Matlab Reservoir Simulation Toolbox includes a GPL-licensed AD library. The usage is mostly geared towards numerical applications in subsurface flow, but the library itself is usable for more general purposes.

Here is a basic runthrough of your example as you would run it from the base directory of MRST:

startup;
% Load ad based module
mrstModule add ad-fi


val = [1; 2; 3];
x = initVariablesADI(val);
y = x.*[4; 5; 6];
disp 'Jacobian:'
full(y.jac{1})

z = sum(x.*x);
disp 'Jacobian:'
full(z.jac{1})
Jacobian:

% MRST AD also supports multiple vector valued functions
a = ones(5, 1);
b = ones(5, 1);
[a, b] = initVariablesADI(a, b);
c = a.*b + 2.*b;
full(c.jac{1})
full(c.jac{2})

There exists a work-in-progress user guide at the website, where chapter 7 has some usage of the AD library. This library is primarily geared towards problems that require all Jacobian values and is vectorized using forward mode only. It does include some nice things though, like 2d table interpolation and so on. It has been used for moderate size non-linear problems (order of 500,000 unknowns).

The non-linear solvers and components are heavily focused on reservoir applications at the moment. This part of the library is presently being rewritten and may in the future have some use outside of this specific domain. However, if you just want the AD part, the ADI class and the initVariablesADI function should be sufficient.

Disclaimer: I am one of the developers attached to this research group.

share|improve this answer
    
Thanks, sounds great. I will take a look. Are there features for sparsity patterns, etc.? –  jlperla Jul 21 at 17:45
    
Presently all Jacobians are stored as cell arrays of sparse matrices (for groupings of variables). We did investigate having subclasses/treatment for some specific sparsity patterns, but as our linear systems are mostly from unstructured grids the overhead was too large to gain any benefit. –  moyner Jul 21 at 17:48
    
Thanks. This seems like a good library. It doesn't appear to have support for matrix-vector multiplications, which would be nice based on my current structure, but I may be able to do it with loops. –  jlperla Jul 22 at 22:38

This article in SIAM Review describes how to implement operator-overloading automatic differentiation in MATLAB, and gives a good introduction to the technology.

share|improve this answer
    
Thank you, let me take a look. For completeness, it looks like the files are located in: academics.davidson.edu/math/neidinger/IntroAD&OOP.zip –  jlperla Jul 19 at 23:45
    
This is a great explanation of AD and matlab, but doesn't support vector based variables as far as I can tell. I would have a (runtime determined) vector of variables, so individually defining each wouldn't work. See my adjusted test case in the description. –  jlperla Jul 20 at 0:15

If you are really interested in open source and like to promote/support it, then you should probably take a look at the open source matlab clone octave. There is an extension to it, called ad that supports automatic forward differentiation. Unfortunately, it seems to be unmaintained currently.

share|improve this answer

The wikipedia page for automatic differentiation has links to many software packages or libraries, including several for MATLAB. http://en.wikipedia.org/wiki/Automatic_differentiation#Software

share|improve this answer
    
Thanks. Yeah, I have looked at them and it is pretty out of date. most seem to be proprietary or just something someone threw together for an older version of matlab without core functionality. I was hoping there was a major implementation, but I am starting to doubt it exists. –  jlperla Jul 21 at 14:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.