npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@2bad/micrograd

v1.0.0

Published

[![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

Readme

MicroGrad

NPM version License GitHub Build Status Code coverage Written in TypeScript

A TypeScript implementation of an autograd engine for educational purposes.

Overview

MicroGrad implements backpropagation (reverse-mode autodiff) over a dynamically built Directed Acyclic Graph (DAG). This project demonstrates how to implement automatic differentiation principles in TypeScript.

Key Components

  • Value Class: Core autodiff functionality with gradient computation
  • Neural Network Primitives: Simple Neuron, Layer, and MLP implementations
  • Graph Visualization: Tools to visualize computation graphs

Key improvements over the Python version

  • API Design: Both instance and static methods for operations compared to instance-only methods
  • Higher Order Gradients: Support for computing higher-order derivatives
  • Extended Math: Additional operations including log, exp, tanh, and sigmoid
  • Gradient Tools: Methods for gradient health checks and gradient clipping
  • Performance: Iterative stack-based topological sort for better efficiency

Usage Example

import { Value } from '@2bad/micrograd';
  // Create computation graph
  const a = new Value(-4.0, 'a')
  const b = new Value(2.0, 'b')
  let c = Value.add(a, b, 'c') // a + b
  let d = Value.add(Value.mul(a, b), Value.pow(b, 3), 'd') // a * b + b**3

  // c += c + 1
  c = Value.add(c, Value.add(c, new Value(1.0)))

  // c += 1 + c + (-a)
  c = Value.add(c, Value.add(Value.add(new Value(1.0), c), Value.negate(a)))

  // d += d * 2 + (b + a).relu()
  const bPlusA = Value.add(b, a)
  d = Value.add(d, Value.add(Value.mul(d, 2), Value.relu(bPlusA)))

  // d += 3 * d + (b - a).relu()
  const bMinusA = Value.sub(b, a)
  d = Value.add(d, Value.add(Value.mul(3, d), Value.relu(bMinusA)))

  // e = c - d
  const e = Value.sub(c, d, 'e')

  // f = e**2
  const f = Value.pow(e, 2, 'f')

  // g = f / 2.0
  let g = Value.div(f, 2.0, 'g')

  // g += 10.0 / f
  g = Value.add(g, Value.div(10.0, f))

  // Forward pass
  console.log(g.data); // Value of the computation

  // Backward pass (compute gradients)
  g.backward();

  // Access gradients
  console.log(a.grad); // dg/da
  console.log(b.grad); // dg/db

Building and Testing

# Install dependencies
npm install

# Build the project
npm run build

# Run tests
npm test

Acknowledgements

This project is inspired by micrograd by Andrej Karpathy. The TypeScript implementation extends the core concepts with additional features and type safety.