Project Description
A library that provides fast, accurate and automatic differentiation (computes derivative / gradient) of mathematical functions.

Getting AutoDiff
You can download the library either from this site's download section, or you can use NuGet to install the package in your solution.

News
DateContent
31/10/11 Version 0.5 has been released. Added user-defined n-ary functions, new power term, support for parameterized functions and a division operator, NuGet contracts problem has been resolved
08/08/11 Version 0.4 08/08/2011 has been released. Includes a bug fix that might cause AutoDiff give the wrong answer in an extreme case See WorkItem 1164
10/06/11 Version 0.4 has been released. Includes custom unary and binary functions. See documentation
24/04/11 We're on NuGet
17/04/11 We have a benchmark. Here is the link: 0.3 benchmark
09/04/11 We have an article on CodeProject


Overview
This library allows developers to define functions from basic primitives and evaluate/differentiate them analytically. The library allows calculating a function's value and gradient at a specified point. This library is very useful for prototyping and developing applications that use numeric optimization. Instead of manually developing a formula for the gradient, the library does the differentiation for you.

Documentation
In the Documentation tab right now we have some basic tutorials, and some others are under construction. In addition, the binary distribution contains XML comments for all public methods and a help file you can view with your favorite help viewer. And finally, the source control contains some code examples in addition to the library's code.

Motivation
There are many open and commercial .NET libraries that have numeric optimization as one of their features (for example, Microsoft Solver Foundation, AlgLib, Microsoft Research SHO Extreme Optimization, CenterSpace NMath) . Most of them require the user to be able to evaluate the function and the function's gradient. This library tries to save the work in manually developing the function's gradient and coding it.
Once the developer defines his/her function, the AutoDiff library can automatically evaluate and differentiate this function at any point. This allows easy development and prototyping of applications based on numeric optimization.

Features
  • Fast! See 0.3 benchmark.
  • Composition of functions using arithmetic operators, Exp, Log, Power and user-defined unary and binary functions.
  • Function gradient evaluation at specified points
  • Function value evaluation at specified points
  • Uses Code Contracts for specifying valid parameters and return values
  • Computes gradients using Reverse-Mode AD algorithm in linear time!
    • Yes, it's faster than numeric approximation for multivariate functions
    • You get both high accuracy and speed!


Code example
using AutoDiff;

class Program
{
    public static void Main(string[] args)
    {
            // define variables
            var x = new Variable();
            var y = new Variable();
            var z = new Variable();

            // define our function
            var func = (x + y) * TermBuilder.Exp(z + x * y);

            // prepare arrays needed for evaluation/differentiation
            Variable[] vars = { x, y, z };
            double[] values = {1, 2, -3 };

            // evaluate func at (1, 2, -3)
            double value = func.Evaluate(vars, values);

            // calculate the gradient at (1, 2, -3)
            double[] gradient = func.Differentiate(vars, values);

            // print results
            Console.WriteLine("The value at (1, 2, -3) is " + value);
            Console.WriteLine("The gradient at (1, 2, -3) is ({0}, {1}, {2})", gradient[0], gradient[1], gradient[2]);
    }
}

Last edited Nov 5, 2011 at 1:04 PM by alexshtf, version 37