minigrad

package module
v0.0.0-...-acb35ab Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 4 Imported by: 0

README

minigrad

A neural network library in golang on an autograd engine. Faster and easy to use like PyTorch. ( This is Andrej Karpathy's Micrograd implementation in Go)

Usage

package main

import (
  mg "github.com/0verread/minigrad"
)

func main() {
  a := mg.NewValue(-4.0, nil, "")
  b := mg.NewValue(2.0, nil, "")
  c := a.Add(b)
  d := a.Mul(b).Add(b.Pow(3))
  c = c.Add(c.Add(mg.NewValue(1.0, nil, "")))
  c = c.Add(mg.NewValue(1.0, nil, "").Add(c))
  d = d.Add(d.Mul(2.0).Add(b.Add(a).Relu()))

  d.Backward()

}

Contribution

Feel free to raise a issue or PR to make enhancements or report a bug. I would love to see more test cases.

License

minigrad is under MIT.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Layer

type Layer struct {
	// contains filtered or unexported fields
}

func NewLayer

func NewLayer(nin, nout int, nonlin bool) *Layer

func (*Layer) Call

func (l *Layer) Call(x []*Value) []*Value

func (*Layer) Parameters

func (l *Layer) Parameters() []*Value

func (*Layer) String

func (l *Layer) String() string

type MLP

type MLP struct {
	// contains filtered or unexported fields
}

MLP struct

func NewMLP

func NewMLP(nin int, nouts []int) *MLP

func (*MLP) Call

func (m *MLP) Call(x []*Value) []*Value

func (*MLP) Parameters

func (m *MLP) Parameters() []*Value

func (*MLP) String

func (m *MLP) String() string

type Neuron

type Neuron struct {
	// contains filtered or unexported fields
}

func NewNeuron

func NewNeuron(nin int, nonlin bool) *Neuron

func (*Neuron) Call

func (n *Neuron) Call(x []*Value) *Value

func (*Neuron) Parameters

func (n *Neuron) Parameters() []*Value

func (*Neuron) String

func (n *Neuron) String() string

type Value

type Value struct {
	// contains filtered or unexported fields
}

func Add

func Add(other interface{}, v *Value) *Value

func Div

func Div(other interface{}, v *Value) *Value

func Mul

func Mul(other interface{}, v *Value) *Value

func NewValue

func NewValue(data float64, children []*Value, op string) *Value

func Sub

func Sub(other interface{}, v *Value) *Value

func (*Value) Add

func (v *Value) Add(other interface{}) *Value

func (*Value) Backward

func (v *Value) Backward()

func (*Value) Div

func (v *Value) Div(other interface{}) *Value

func (*Value) Mul

func (v *Value) Mul(other interface{}) *Value

func (*Value) Neg

func (v *Value) Neg() *Value

func (*Value) Pow

func (v *Value) Pow(other float64) *Value

func (*Value) Relu

func (v *Value) Relu() *Value

func (*Value) String

func (v *Value) String() string

func (*Value) Sub

func (v *Value) Sub(other interface{}) *Value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL