{"id":28174393,"url":"https://github.com/2bad/micrograd","last_synced_at":"2025-10-29T19:42:01.573Z","repository":{"id":277383043,"uuid":"926428373","full_name":"2BAD/micrograd","owner":"2BAD","description":"A TypeScript implementation of an autograd engine for educational purposes.","archived":false,"fork":false,"pushed_at":"2025-05-12T07:36:16.000Z","size":416,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T08:53:47.071Z","etag":null,"topics":["autodiff","autograd","autograd-engine","micrograd","micrograd-in-ts"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2BAD.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-03T08:34:42.000Z","updated_at":"2025-05-12T07:35:10.000Z","dependencies_parsed_at":"2025-03-24T07:30:59.845Z","dependency_job_id":"a6da4df9-e4f9-48bd-a217-ad8eedbd8311","html_url":"https://github.com/2BAD/micrograd","commit_stats":null,"previous_names":["2bad/micrograd"],"tags_count":1,"template":false,"template_full_name":"2BAD/ts-lib-starter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAD%2Fmicrograd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAD%2Fmicrograd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAD%2Fmicrograd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2BAD%2Fmicrograd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2BAD","download_url":"https://codeload.github.com/2BAD/micrograd/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254430308,"owners_count":22069909,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autodiff","autograd","autograd-engine","micrograd","micrograd-in-ts"],"created_at":"2025-05-15T22:16:07.911Z","updated_at":"2025-10-29T19:41:56.541Z","avatar_url":"https://github.com/2BAD.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MicroGrad\n\n[![NPM version](https://img.shields.io/npm/v/@2bad/micrograd)](https://www.npmjs.com/package/@2bad/micrograd)\n[![License](https://img.shields.io/npm/l/@2bad/micrograd)](https://opensource.org/license/MIT)\n[![GitHub Build Status](https://img.shields.io/github/actions/workflow/status/2BAD/micrograd/build.yml)](https://github.com/2BAD/micrograd/actions/workflows/build.yml)\n[![Code coverage](https://img.shields.io/codecov/c/github/2BAD/micrograd)](https://codecov.io/gh/2BAD/micrograd)\n[![Written in TypeScript](https://img.shields.io/github/languages/top/2BAD/micrograd)](https://www.typescriptlang.org/)\n\nA TypeScript implementation of an autograd engine for educational purposes.\n\n## Overview\n\nMicroGrad implements backpropagation (reverse-mode autodiff) over a dynamically built Directed Acyclic Graph (DAG). This project demonstrates how to implement automatic differentiation principles in TypeScript.\n\n## Key Components\n\n- **Value Class**: Core autodiff functionality with gradient computation\n- **Neural Network Primitives**: Simple Neuron, Layer, and MLP implementations\n- **Graph Visualization**: Tools to visualize computation graphs\n\n## Key improvements over the Python version\n\n- **API Design**: Both instance and static methods for operations compared to instance-only methods\n- **Higher Order Gradients**: Support for computing higher-order derivatives\n- **Extended Math**: Additional operations including log, exp, tanh, and sigmoid\n- **Gradient Tools**: Methods for gradient health checks and gradient clipping\n- **Performance**: Iterative stack-based topological sort for better efficiency\n\n## Usage Example\n\n```typescript\nimport { Value } from '@2bad/micrograd';\n  // Create computation graph\n  const a = new Value(-4.0, 'a')\n  const b = new Value(2.0, 'b')\n  let c = Value.add(a, b, 'c') // a + b\n  let d = Value.add(Value.mul(a, b), Value.pow(b, 3), 'd') // a * b + b**3\n\n  // c += c + 1\n  c = Value.add(c, Value.add(c, new Value(1.0)))\n\n  // c += 1 + c + (-a)\n  c = Value.add(c, Value.add(Value.add(new Value(1.0), c), Value.negate(a)))\n\n  // d += d * 2 + (b + a).relu()\n  const bPlusA = Value.add(b, a)\n  d = Value.add(d, Value.add(Value.mul(d, 2), Value.relu(bPlusA)))\n\n  // d += 3 * d + (b - a).relu()\n  const bMinusA = Value.sub(b, a)\n  d = Value.add(d, Value.add(Value.mul(3, d), Value.relu(bMinusA)))\n\n  // e = c - d\n  const e = Value.sub(c, d, 'e')\n\n  // f = e**2\n  const f = Value.pow(e, 2, 'f')\n\n  // g = f / 2.0\n  let g = Value.div(f, 2.0, 'g')\n\n  // g += 10.0 / f\n  g = Value.add(g, Value.div(10.0, f))\n\n  // Forward pass\n  console.log(g.data); // Value of the computation\n\n  // Backward pass (compute gradients)\n  g.backward();\n\n  // Access gradients\n  console.log(a.grad); // dg/da\n  console.log(b.grad); // dg/db\n```\n\n## Building and Testing\n\n```bash\n# Install dependencies\nnpm install\n\n# Build the project\nnpm run build\n\n# Run tests\nnpm test\n```\n\n## Acknowledgements\n\nThis project is inspired by [micrograd](https://github.com/karpathy/micrograd) by Andrej Karpathy. The TypeScript implementation extends the core concepts with additional features and type safety.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bad%2Fmicrograd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2bad%2Fmicrograd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2bad%2Fmicrograd/lists"}