Polynomial and Fourier Basis in RL
Cosine waves give linear TD methods a bounded orthogonal feature set, so coarse shape and fine detail learn without the blowups polynomials cause.
Why Does This Exist?
Continuous control breaks tables. A robot arm or a mountain car lives in an infinite state space, so you cannot store one value per state. Linear methods replace the table with : a weight vector times a feature vector built from the raw state . The features decide what shapes the approximator can draw.
The obvious features are polynomials: , , , , , and so on. They fail in practice for three concrete reasons. A TD error in one corner shifts weights that warp predictions everywhere, powers above 2 shoot toward huge magnitudes near the edges, and the features correlate with each other so gradient steps zigzag. Feature construction exists to pick something better, and this page covers the pair most often compared: the polynomial baseline and its replacement.
Konidaris, Osentoski, and Thomas (AAAI 2011) showed the Fourier cosine basis beats polynomials and radial basis functions on standard control benchmarks and matches far heavier learned bases. The idea is simple: normalize each state coordinate into , then use cosine harmonics with integer frequency vectors . Every feature stays inside , distinct frequencies are orthogonal, and high frequencies get smaller step sizes automatically.
The one idea you need first. A basis is just a fixed dictionary of shapes whose weighted sum approximates the value surface. Polynomials use powers, tile coding uses overlapping grids, and radial basis functions use bumps. The Fourier basis uses waves. If you know that means one weight per shape, you have enough to follow this page.
Think of It Like This
Shaping clay with mallets versus tuning with organ pipes
You must reproduce a bumpy landscape in clay. The polynomial toolkit is a set of mallets shaped like , , . Each strike bends the whole sheet at once, and the heavy mallet dents the middle whenever you tap the edge. Fixing one corner ruins the opposite corner.
The Fourier toolkit is a row of organ pipes. The first pipe hums the broad slope of the land, the next adds one gentle undulation, the next adds two. Each pipe sounds only its own note, none can blast the roof off, and you turn the high shimmering pipes down low so they add texture without screaming. You build the same landscape, but every control does one job and stays bounded.
Where it stops: pipes sound in time while basis features vary across state space, and real organs do not scale their stops by frequency norm. The bounded plus orthogonal part carries over; the acoustics do not.
How It Actually Works
An order basis in dimensions has features. For and that is 4 features; for and it is 16. Both bases below share that count. They differ in what each feature computes.
The polynomial baseline
Each feature multiplies powers of the state coordinates. With exponent vector whose entries run to :
For and the 9 features are , , , , , , , , . Nothing bounds them and nothing orthogonalizes them, so the Hessian of the projected error is ill conditioned and semi gradient TD chases its own tail near the borders.
The Fourier cosine basis
Normalize first: every coordinate is clipped and scaled into . Then each feature is one cosine of an integer frequency combination. With coefficient vector whose entries run to :
Three properties matter. Boundedness: every lies in , so no feature can explode. Orthogonality: distinct frequency vectors give zero inner product over , which keeps the gradient covariance well conditioned and lets coarse and fine structure learn without fighting. Frequency scaled steps: with base rate and norm , use when the norm is and otherwise. High frequency waves oscillate fast over short distances, so they earn smaller steps and the ringing the paper reports with uniform rates disappears.
Worked example
Take a 2D state at normalized coordinates , order , base rate . The 4 frequency vectors are , , , .
Bias term : dot product , feature , norm , step .
Vertical mode : dot product , feature , norm , step .
Horizontal mode : dot product , feature , norm , step .
Diagonal mode : dot product , feature , norm , step .
So with steps . The diagram draws exactly these four bars. Note the diagonal step is damped about 30 percent: the finest detail moves slowest, which is the point of the scaling rule.
Code
The snippet builds the same 4 features with the standard library only and prints the numbers from the worked example.
import math
def fourier_features(s: list[float], order: int = 1) -> list[float]: """Cosine features cos(pi * c^T s) for a 2D state in [0, 1]^2.""" freqs = [(0, 0), (0, 1), (1, 0), (1, 1)] out = [] for c1, c2 in freqs: out.append(math.cos(math.pi * (c1 * s[0] + c2 * s[1]))) return out
def scaled_alphas(base: float = 0.01) -> list[float]: freqs = [(0, 0), (0, 1), (1, 0), (1, 1)] out = [] for c1, c2 in freqs: norm = math.sqrt(c1 * c1 + c2 * c2) out.append(base if norm == 0 else base / norm) return out
s = [0.2, 0.8]print([round(v, 4) for v in fourier_features(s)]) # -> [1.0, -0.809, 0.809, -1.0]print([round(a, 4) for a in scaled_alphas()]) # -> [0.01, 0.01, 0.01, 0.0071]The first print matches the hand computation and the second matches the damped diagonal step .
Watch Out For
Feeding raw coordinates straight into the cosines
The symptom is a value surface that looks like static: neighboring states get wildly different predictions and nothing learns. The cause is almost always skipped normalization. Physical ranges like position in swing the argument through many stray cycles, so spatial neighbors land on unrelated phases.
Clip each coordinate to its known bounds and scale linearly into before encoding. Keep the bounds fixed for the whole run; refitting them mid training silently redefines every feature.
One step size for every frequency
The symptom is high frequency ripple: the broad shape looks right but fine waves jitter across updates and the error will not settle. A uniform pushes fast oscillating features as hard as the smooth bias term, which is exactly the ringing Konidaris and coauthors warn about.
Divide by the frequency norm, , keeping for the zero vector. If ripple persists, lower the base before adding more orders.
The Quick Version
- Polynomial features multiply state powers and suffer global interference, edge blowups, and correlated gradients.
- Fourier features take over states normalized into , giving bounded waves.
- Every Fourier feature stays in and distinct frequencies are orthogonal, so coarse and fine structure stop fighting.
- Step sizes scale as , which damps high frequencies and removes ringing.
- At with order 1 the features are and the diagonal step is .