Concept 01: Linear Layers (Weights, Biases & Dot Products)
Every neural network—from a simple robot sensor filter to a 100-billion-parameter language model—is constructed from basic mathematical units called Linear Layers (also called Dense or Fully-Connected layers).
Open the interactive demo below to adjust the weights and bias of a 2-input neuron and watch how it creates a linear decision boundary across sensor data.
The Everyday Robot Problem
Suppose you want to predict your robot’s Battery Voltage during an intense match based on two live sensor readings:
x₁: Total motor current draw (Amps).x₂: Battery temperature (°C).
How do we combine these two numbers into an accurate voltage prediction?
1. What Are Weights and Biases?
A linear neuron performs a weighted sum plus an offset:
predicted_voltage = (w₁ · current) + (w₂ · temperature) + bias
- Weights (
w₁,w₂): Measure the influence (or sensitivity) of each input.- Higher current causes a voltage drop:
w₁ = -0.018 V/Amp. - Higher heat increases internal resistance:
w₂ = -0.025 V/°C.
- Higher current causes a voltage drop:
- Bias (
b): The baseline intercept when all inputs are zero.- When current is
0 Ampsand temp is0 °C, a fully-charged battery sits at rest:b = 12.60 V.
- When current is
2. Solving It in Code (Java & WPILib)
First-Principles Java: Linear Layer Forward Pass
public class LinearNeuron {
public static void main(String[] args) {
// Inputs: [Current = 120.0 Amps, Temperature = 35.0 °C]
double[] inputs = {120.0, 35.0};
// Learned Weights and Baseline Bias
double[] weights = {-0.018, -0.025};
double bias = 12.60;
// Linear Output: y = dot_product(w, x) + b
double predictedVoltage = bias;
for (int i = 0; i < weights.length; i++) {
predictedVoltage += weights[i] * inputs[i];
}
System.out.printf("Predicted Battery Voltage: %.2f Volts%n", predictedVoltage);
}
}
3. Math! Translation Sidebar
Here is how linear layers are written in machine learning literature:
y = W · x + b
For a single neuron i receiving M inputs:
yᵢ = ∑ (wᵢⱼ · xⱼ) + bᵢ
How to Read This Out Loud:
W(“capital W”): The Weight Matrix, where each row represents the weights for one neuron.x(“vector x”): The Input Vector containing the incoming features.b(“vector b”): The Bias Vector that shifts the output up or down.·or@: Vector dot product / matrix multiplication.
4. Geometric Meaning: Separation Planes
In 2D space, the equation w₁ · x₁ + w₂ · x₂ + b = 0 defines a straight line.
- Everything on one side of the line produces a positive output (
y > 0→ Safe Battery). - Everything on the other side produces a negative output (
y < 0→ Brownout Warning!).
The weights determine the tilt (angle) of the separation line, while the bias slides the line left or right across the field.