Skip to content

Latest commit

 

History

History
55 lines (48 loc) · 1.3 KB

README.md

File metadata and controls

55 lines (48 loc) · 1.3 KB

scalgrad

A minimal C++ autograd engine implementation for scalars. Inspired by micrograd. Also implemented small neural network on top of the engine.

Example

Here is the example of engine usage:

#include "engine.hpp"

using scal = typename red_engine::scalar<double>;
int main() {
  auto a = scal::create(2.0);
  auto b = scal::create(3.0);
  auto c = scal::create(4.0);
  auto d = c - b;
  auto r = red_engine::exponentiate((a + b) * c + d);
  r->backprop();
  r->draw_dot("dump.dot");

Example of the neural network usage:

#include "engine.hpp"
#include "nn.hpp"

using scal = typename red_engine::scalar<double>;
int main() {
  std::vector<scal::pointer> x{scal::create(1.0), scal::create(-2.0)};

  auto n = nn::MLP<double>{2, {2, 1}};
  auto tmp = n(x);
  auto r = std::get<1>(tmp);
  r->backprop();
  r->draw_dot("dump.dot");
}

The graph of the neural network example is here. You can also try to run the example yourself.

How to build

git clone git@github.com:ajlekcahdp4/scalgrad.git
cd scalargrad
cmake -S . -B build -DNOGTEST=False
make -C build -j8 install

How to run (after build)

# to run unit tests:
cd build
ctest

# to run the example
cd example
bin/example