{"_id":"@2bad/micrograd","name":"@2bad/micrograd","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@2bad/micrograd","version":"1.0.0","description":"[![NPM version](https://img.shields.io/npm/v/@2bad/micrograd)](https://www.npmjs.com/package/@2bad/micrograd) [![License](https://img.shields.io/npm/l/@2bad/micrograd)](https://opensource.org/license/MIT) [![GitHub Build Status](https://img.shields.io/git","keywords":["autodiff","autograd","automatic-differentiation","computational-graph","micrograd","neural-network"],"homepage":"https://github.com/2BAD/micrograd#readme","bugs":{"url":"https://github.com/2BAD/micrograd/issues"},"repository":{"type":"git","url":"git+https://github.com/2BAD/micrograd.git"},"license":"MIT","author":{"name":"2BAD","url":"https://github.com/2BAD"},"contributors":[{"name":"Jason Hyde","email":"github@2bad.me","url":"https://github.com/mrhyde"}],"type":"module","exports":"./build/index.js","types":"./build/index.d.ts","scripts":{"prebuild":"rimraf build","build":"run-p build:*","postbuild":"tsfix","build:swc":"swc ./source -d ./build --strip-leading-paths","build:types":"tsc --project tsconfig.build.json","check":"run-p check:*","check:eslint":"eslint . --report-unused-disable-directives --max-warnings 0","check:biome":"biome check ./source","fix":"run-s fix:code fix:format","fix:code":"run-s 'check:eslint -- --fix'","fix:format":"biome format --write ./source","prepublishOnly":"run-s build","preversion":"run-s check test build","test":"vitest run","test:integration":"vitest run integration --coverage","test:unit":"vitest run unit --coverage"},"devDependencies":{"@2bad/axiom":"1.0.0-beta.15","@2bad/tsconfig":"3.0.1","@2bad/tsfix":"1.1.1","@biomejs/biome":"1.9.4","@swc/cli":"0.7.3","@swc/core":"1.11.24","@types/node":"22.15.3","@vitest/coverage-v8":"3.1.2","mermaid":"11.6.0","npm-run-all2":"7.0.2","rimraf":"6.0.1","typescript":"5.8.3","vite-tsconfig-paths":"5.1.4","vitest":"3.1.2"},"packageManager":"npm@11.3.0","engines":{"node":">=20"},"volta":{"node":"22.15.0","npm":"11.3.0"},"_id":"@2bad/micrograd@1.0.0","gitHead":"c0ec5abb37f910378866641fa442c526598a462c","_nodeVersion":"22.15.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-TJZBhCDM4pJiyT79MWqyDlKlzN3wlD1ZidBGiuNN3IB56A7jdmSE03PyfYOeQAENqyxkE2LndLqR00+aWT4xHQ==","shasum":"63574c807e365245f00b3bbc4452f7505ca3bbdc","tarball":"https://registry.npmjs.org/@2bad/micrograd/-/micrograd-1.0.0.tgz","fileCount":11,"unpackedSize":25049,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@2bad%2fmicrograd@1.0.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCo9VQez1WTJztf99EhxXfAz/+57TLO2uLWKw4mFPTZ2gIgJPw497zmqGgk3HXXFoPELmDXIXnPaX5i+gezY6R0ANk="}]},"_npmUser":{"name":"mrhyde","email":"npm@2bad.me"},"directories":{},"maintainers":[{"name":"mrhyde","email":"npm@2bad.me"},{"name":"armordarks","email":"npm@lavrins.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/micrograd_1.0.0_1746160898715_0.32742525282749635"},"_hasShrinkwrap":false}},"time":{"created":"2025-05-02T04:41:38.646Z","1.0.0":"2025-05-02T04:41:38.914Z","modified":"2025-05-02T04:41:39.491Z"},"maintainers":[{"name":"mrhyde","email":"npm@2bad.me"},{"name":"armordarks","email":"npm@lavrins.com"}],"description":"[![NPM version](https://img.shields.io/npm/v/@2bad/micrograd)](https://www.npmjs.com/package/@2bad/micrograd) [![License](https://img.shields.io/npm/l/@2bad/micrograd)](https://opensource.org/license/MIT) [![GitHub Build Status](https://img.shields.io/git","homepage":"https://github.com/2BAD/micrograd#readme","keywords":["autodiff","autograd","automatic-differentiation","computational-graph","micrograd","neural-network"],"repository":{"type":"git","url":"git+https://github.com/2BAD/micrograd.git"},"contributors":[{"name":"Jason Hyde","email":"github@2bad.me","url":"https://github.com/mrhyde"}],"author":{"name":"2BAD","url":"https://github.com/2BAD"},"bugs":{"url":"https://github.com/2BAD/micrograd/issues"},"license":"MIT","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","readmeFilename":"README.md","_rev":"1-5c7314f6af9a6b9e545aac80264f7c0f"}