About this simulation

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 5 July 2026

This simulation trains a radial basis function (RBF) network to approximate a 1D target curve. Each basis unit is a Gaussian φⁱ(x) = exp(−|x−cⁱ|²/2σ²) centred at a point cⁱ found by running k-means clustering on the training inputs. Once the centres are fixed, the output weights w are solved directly with linear least squares (normal equations Aw = b, solved by Gaussian elimination with a small ridge term for stability), so the network output ŷ = Σ wⁱ·φⁱ(x) is a weighted sum of bumps. You can watch how the number of bases N and their width σ trade off between underfitting and overfitting noisy data.

🔬 What it shows

A scatter of training points from a chosen dataset (sine, noisy sine, step, or chirp), the individual weighted Gaussian bases (coloured bumps, each centred on a k-means centre), and the resulting fitted curve ŷ(x) that sums them together. Live stats report mean squared error (MSE), R², the number of centres, and the range of the fitted output weights.

🎮 How to use

Drag Basis functions N (2–30) to add or remove Gaussian units, and Width σ (0.02–0.5) to make each bump narrower or broader. Pick a dataset from the dropdown, toggle Show individual bases to see or hide the coloured component curves, then press Fit RBF to re-run k-means and least squares, or New data to regenerate the training points.

💡 Did you know?

RBF networks were one of the first practical universal function approximators in machine learning, popularised in the late 1980s. Because the hidden-layer centres are found unsupervised (via k-means) and only the output weights are fitted by (linear) least squares, training an RBF network is dramatically cheaper than backpropagating through a deep neural network of comparable capacity.

Frequently asked questions

What is a radial basis function network?

An RBF network is a two-layer model that approximates a function as a weighted sum of Gaussian "bump" functions. Each hidden unit computes φⁱ(x) = exp(−|x−cⁱ|²/2σ²), a value that peaks at 1 when x is at its centre cⁱ and decays smoothly to 0 further away. The network's output is a linear combination ŷ = Σ wⁱ·φⁱ(x) of these bumps, so it can represent smooth curves by overlapping many localised Gaussians.

How are the centres and weights actually computed?

The simulation picks centres in two stages, mirroring the classic RBF training recipe. First, k-means clustering runs on the training x-values for up to 50 iterations, assigning each point to its nearest centre and re-averaging until the centres settle — this fixes where each Gaussian sits. Second, with centres and width fixed, the output weights are found by solving the linear least-squares problem (ΦᵀΦ)w = Φᵀy via Gaussian elimination, where Φ is the matrix of basis-function activations. A tiny ridge term (1e-6) is added to the diagonal purely to keep the system numerically stable.

What do the N and σ sliders control?

N sets how many Gaussian basis functions (and therefore k-means centres) the network uses, from 2 up to 30. σ controls the width of every Gaussian bump: a small σ makes each basis function narrow and highly localised, letting the network fit sharp local detail but risking overfitting noisy data; a large σ makes bumps wide and overlapping, producing a smoother, more averaged fit that can underfit sharp features like the step function.

What do MSE and R² tell me about the fit?

Mean squared error (MSE) is the average of the squared differences between each training point's true y-value and the network's prediction — lower is a tighter fit. R² (coefficient of determination) compares that residual error to the variance of the data itself, so it reports what fraction of the target's variation the model explains: values near 1 mean the fitted curve tracks the data closely, while low or negative values mean the fit is a poor match, which typically happens when N is too small or σ is set too large or too small for the chosen dataset.

Why does k-means sometimes place centres unevenly?

K-means initialises centres by randomly sampling points from the training data, then iteratively reassigns each point to its nearest centre and moves each centre to the mean of its assigned points. Because the starting centres are random and the algorithm only guarantees convergence to a local optimum, centres can cluster more densely where training data is denser (for example near the fast oscillations of the chirp dataset) and more sparsely elsewhere — this is expected behaviour, not a bug, and is why pressing "New data" or refitting can shift the bump positions slightly each time.