DeutschGitHub
prototypepackages/neuronal-network/src

Neuronal Network

@ralphschuler/neuronal-network

Executes numeric feed-forward inference and gradient-based learning with shape checks.

neural networkbackpropagationmatrix

01 · Problem

What is it for?

A graph of connections is not a trainable neural network unless forward evaluation and weight updates are defined.

02 · Mental model

How should you think about it?

Each layer computes activations from the previous layer; training changes parameters using a measured loss.

In this repository

Executes numeric feed-forward inference and gradient-based learning with shape checks. The educational sigmoid network uses squared-error gradients. It is not a tensor or GPU framework.

03 · Control flow

What happens in which order?

  1. Validate input and layer dimensions.
  2. Compute weighted sums plus biases.
  3. Apply an activation function.
  4. Measure loss against the target.
  5. Update weights using an explicit learning rule.

04 · Building blocks

The important contracts

Neuron / LayerRepresent numeric activations and weighted connections.
Network.activate / trainEvaluate feed-forward outputs and update parameters.
toObject()Serialize graph identifiers without cycles.

05 · Build it yourself

Implement a small core

Start with this small independent implementation, then use the steps below to make its contract explicit.

  1. Validate input and layer dimensions.
  2. Compute weighted sums plus biases.
  3. Apply an activation function.
  4. Measure loss against the target.
  5. Update weights using an explicit learning rule.
Concept sketch · may reference omitted helpers
type Layer = { weights: number[][]; biases: number[] };

function forward(input: number[], layers: Layer[]) {
  const activations = [input];
  for (const layer of layers) {
    const previous = activations.at(-1) as number[];
    const next = layer.weights.map((row, output) => {
      const sum = row.reduce((value, weight, i) => value + weight * previous[i], 0);
      return 1 / (1 + Math.exp(-(sum + layer.biases[output])));
    });
    activations.push(next);
  }
  return activations;
}

06 · Verify

What should you test?

  • Use fixed weights for a known forward result.
  • Verify one training step reduces a simple loss.
  • Reject bad shapes and serialize a connected graph safely.

Try it yourself

Turn the first verification claim into a failing test, implement the smallest fix, then add a boundary case.

Use fixed weights for a known forward result.

Compare your approach

Your check should fail when the stated invariant is deliberately broken, and pass again after the fix. Keep setup deterministic and assert an observable result.

07 · Limits

Trade-offs and failure modes

  • Generic T does not make numeric arithmetic type-safe.
  • Large models need specialized tensor tools.
  • An educational implementation needs deterministic initialization.
Important

The educational sigmoid network uses squared-error gradients. It is not a tensor or GPU framework.

08 · Keep exploring

Source code and related ideas

yarn tsx packages/neuronal-network/examples/basic.ts