niura: Automatic differentiation library that's actually easy to use

36 points whyvitamins

The niura crate provides automatic differentiation for arbitrarily complex scalar valued functions composed of algebraic and (most) elementary functions.

The niura crate mimics the pytorch autograd api, and was designed to be very simple to use. No need to define a graph object or mess with complex types, just define your variables using the var type, perform operations, call the .backward() function, and access the resulting gradient using .grad().

For example, to calculate the gradient of

f(a,b) = a / tan(a * b) at (2, 3)

the following code is required:

let a = var::float(2.0);
let b = var::float(3.0);

let c = &a / &tan(&(&a * &b));

c.backward();
println!("{}, {}", a.grad(), b.grad());

At the moment only scalar valued functions are supported, however, I'm working on supporting vector valued functions at the moment.

If you like niura, please give it a star at https://github.com/taminki/niura, it'll look good on my university application 🤗.

As I'm very much a rust beginner, any suggestions and remarks with regards to the codebase and general project structure and practices are very welcome.

You may notice that some mathematical terminology is slightly misused. This is because the api was designed to eventually work with vector valued functions, and the current system is more of a intermediary stage. However, if you think that automatic differentiation of scalar valued functions would be useful to someone, please let me know and I'll leave support for both scalar and vector valued functions.