https://github.com/aadityaza/cpp-micrograd
C++ implementaiton of micrograd
https://github.com/aadityaza/cpp-micrograd
Last synced: 3 months ago
JSON representation
C++ implementaiton of micrograd
- Host: GitHub
- URL: https://github.com/aadityaza/cpp-micrograd
- Owner: Aadityaza
- Created: 2024-03-17T16:45:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-01T13:36:07.000Z (over 1 year ago)
- Last Synced: 2025-02-28T16:13:18.257Z (8 months ago)
- Language: C++
- Size: 61.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Micro Grad
This is a C++ implementation of a simple automatic differentiation library inspired by Andrej Karpathy's micrograd project. The library provides a `Value` class that allows for automatic differentiation of scalar functions, making it easier to compute gradients for optimization tasks in machine learning and other domains.
## Features
- Automatic computation of gradients for scalar functions
- Support for basic arithmetic operations (`+`, `-`, `*`, `^`)
- Topological sorting of the computational graph for efficient backward propagation
- Overloaded `<<` operator for printing `Value` objects## Usage
To use the library, you need to include the necessary header files and create instances of the `Value` class. Here's a simple example:
```cpp
#include
#include "micrograd.h"int main() {
Value a = Value(4);
Value b = Value(2);
Value c = a * b; // c = 8c.backward();
std::cout << "Gradient of a: " << a.getGrad() << std::endl; // Output: 2
std::cout << "Gradient of b: " << b.getGrad() << std::endl; // Output: 4return 0;
}