MicrogradEx.NN.Neuron (MicrogradEx v0.1.0)

Copy Markdown View Source

A scalar neuron: weighted sum, bias, and optional ReLU.

This mirrors micrograd.nn.Neuron. The Elixir struct stores immutable parameter values. Calling MicrogradEx.NN.apply_gradients/3 returns a new neuron with updated parameter values instead of mutating the existing neuron.

Summary

Functions

Runs a forward pass through the neuron.

Creates a neuron.

Returns this neuron's trainable parameters in weight-then-bias order.

Types

t()

@type t() :: %MicrogradEx.NN.Neuron{
  bias: MicrogradEx.Value.t(),
  nonlin: boolean(),
  weights: [MicrogradEx.Value.t()]
}

Functions

forward(neuron, inputs)

Runs a forward pass through the neuron.

Inputs may be plain numbers, Value structs, or a single scalar when the neuron has exactly one input. Numbers are promoted to differentiable leaves so input gradients can be inspected too.

new(input_count, opts \\ [])

Creates a neuron.

Options:

  • :nonlin - when true, apply ReLU after the affine transform.
  • :weights - exact initial weights, useful for tests and examples.
  • :bias - exact initial bias, defaults to 0.0.
  • :seed - {a, b, c} tuple for deterministic random weights.

parameters(neuron)

Returns this neuron's trainable parameters in weight-then-bias order.