Skip to content
This repository was archived by the owner on May 8, 2025. It is now read-only.

mxberner/Autodiff-Ocaml

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

189 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Final Project for Functional Programming in Software Engineering (601.629) FA24

Project Requirements

The project implements an Automatic Differentiation library in OCaml.

Automatic differentiation is an algorithm used to evaluate partial derivatives of functions. Automatic differentiation is more efficient than symbolic differentiation, and more accurate than numeric differentiation. Our library can be used to define functions using our Variable and Tensor modules. One can then find gradients and various partial derivatives of these functions. Examples are listed below. We also use the Bigarray library to build our tensors, so that needs to be installed.

Building and Running Examples

Clone the repository and build the project.

git clone https://github.com/mxberner/Autodiff-Ocaml
cd Autodiff-Ocaml
dune build

Next there are a bunch of examples that make it easy to see the library work in practice.

dune exec <example_name>

Examples

  • basic - Runs some basic operations using tensor module.
  • simple - Run autodifferentiation on a simple function.
  • nn - Train a single layer neural network on some random data.
  • visualize - Visualizes the dynamically built computation graph.
  • printed - Demonstrates the underlying Hashtable.

Under the hood

When building a function representation, the function is split into primitives defined by Variable module. This results in a directed acyclic graph (DAG) where each node contains an id, the actual Tensor.t value and its calculated gradient based on function primitive type. Additionally there is an operation tag that specifies if the graph entry is a function of two variables, or one variable. This is mostly useful for demo purposes and looking into the computational graph. This graph is implicitly formed through the use of a hashtable of type v in the Variable module. Both the Tensor and Variable modules have accompanying tests. The oplot and graph libraries that we downloaded weren't ultimately of use, so they just remain with their demos.

Features

  • First order derivative
  • Vectorization
  • N-th order derivative
  • Example
    • Basic
    • Simple Neural Network
    • Visualizing autodiff computation graph
    • Demonstration of Hashtable

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages