MicroGPT.ts - a conversion of Karpathy's MicroGPT to Typescript
    Preparing search index...

    Class Value

    A scalar value that tracks its computation graph for automatic differentiation.

    Because TypeScript has no operator overloading, arithmetic is performed via methods: a.add(b), a.mul(b), a.pow(n), etc.

    Index

    Constructors

    Properties

    Methods

    Constructors

    • Parameters

      • data: number
      • children: Value[] = []
      • localGrads: number[] = []

      Returns Value

    Properties

    data: number

    Scalar value computed during the forward pass.

    grad: number

    Derivative of the loss with respect to this node, computed during backward.

    Methods

    • Backpropagate gradients through the computation graph rooted at this node. Sets this.grad = 1 and accumulates gradients on all ancestors.

      Returns void

    • Exponentiation: this ** exponent (exponent is a plain number).

      Parameters

      • exponent: number

      Returns Value