11.2 A simple neural network
Source: Ideas from Computational Physics (Landau, Páez, Bordeianu), §11.2–11.2.2. Rewritten in original wording — no textbook
NeuralNet.pydump. Continues 11.1b. Next: 11.2b.
One AI neuron
Inputs arrive with weights; the body forms an affine map , then an activation decides the outgoing signal. Soft activations (logistic, tanh, ReLU) train more easily than hard thresholds. Pick /, the logistic sigmoid, and the 2–2–1 nesting among lookalikes.
Weights and biases are the learnable parameters. Example: , , , , ⇒ . With the output is . Logistic sigmoid ∈ ; tanh ∈ ; ReLU passes positives and zeros negatives. Our shallow demos use the logistic sigmoid.
Shallow network (2–2–1)
Two inputs, two hidden nodes, one output (“shallow” — more than one hidden layer would be deep). The output neuron’s inputs are the hidden activations (not the raw ’s) — as in the formulas you picked.
Hand check: if every neuron uses the same weights and bias , with , , then and .
Coding sketch (structure only)
# neuron_forward_sketch.py — original structure
import math
def sigmoid(z):
return 1.0 / (1.0 + math.exp(-z))
def neuron(xs, ws, b=0.0, f=sigmoid):
return f(sum(w * x for w, x in zip(ws, xs)) + b)
# network: h1 = neuron([x1,x2], [w1,w2], b1); ...; y = neuron([h1,h2], [w5,w6], b3)
Libraries (NumPy / PyTorch) vectorize the same math; labs stay pure Python so every float is inspectable.
Takeaway
- Node = affine map + activation.
- Stack nodes into layers; forward pass is nested activations.
- Soft activations train more easily than hard thresholds.
- Even a tiny net has many weights — training comes next.
Simple NN
1 / 4With w₁=-1, w₂=1, b=0, x=(12,8) and f=identity, y is…
Pick an answer to see if you are right.
Next: 11.2b Simple NN labs.