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:

  1. x₁: Total motor current draw (Amps).
  2. 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

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:


4. Geometric Meaning: Separation Planes

In 2D space, the equation w₁ · x₁ + w₂ · x₂ + b = 0 defines a straight line.

The weights determine the tilt (angle) of the separation line, while the bias slides the line left or right across the field.


← Module 2: Neural Layers
ML Axon Home
Concept 24: Activation Functions →