Approximate Solution Methods/Memory-Based and Kernel Methods

Lesson 3.122,668 words

Memory-Based and Kernel Methods

Least-squares TD spent more compute to extract more from each example; this lesson drops the parametric form entirely. Memory-based methods store training examples untouched and answer a query locally at retrieval time — nearest neighbor, weighted average, locally weighted regression — so accuracy grows with the data and effort concentrates where the agent actually goes.

╌╌╌╌

This builds on least-squares TD and memory-based methods, which stayed parametric — LSTD kept the linear form and merely solved for its fixed point directly. This lesson drops the parametric commitment altogether: store the examples themselves, and let the approximation take whatever shape the data implies.

Memory-based function approximation

Everything so far — linear or nonlinear, iterative or batch — has been parametric. A parametric method commits to a functional form governed by a fixed-size parameter vector ; each update adjusts to reduce error, and afterward the training example can be discarded. When a query state needs a value, the function is evaluated at that state using the latest parameters. The whole of the data's influence has been squeezed into .

Memory-based methods work differently, and the difference is fundamental. They save training examples in memory as they arrive — or at least a subset — without updating any parameters at all. When a value estimate is needed for a query state, a set of examples is retrieved from memory and combined on the spot to produce the estimate. Because the work of processing examples is postponed until a query arrives, this is called lazy learning.1

Parametric versus memory-based approximation. The parametric method (top) folds each example into a fixed weight vector and discards it, evaluating at query time; the memory-based method (bottom) stores examples untouched and retrieves nearby ones only when a query state arrives.

Memory-based methods are the prime example of nonparametric approximation. The approximating function is not limited to a pre-specified class — linear functions, polynomials, a fixed set of basis functions — but is determined jointly by the stored examples and the rule for combining them. There is no fixed cap on expressiveness: as more examples accumulate, a nonparametric method can produce an ever more accurate approximation to any target function.

Local learning: nearest neighbor and weighted average

The memory-based methods most useful here are local-learning methods, which approximate the value function only in the neighborhood of the current query state. They retrieve the examples judged most relevant to the query, where relevance usually falls off with distance: the closer a stored example's state is to the query state, the more it counts. Once the query has been answered, the local approximation is discarded.

The simplest is the nearest neighbor method: find the stored example whose state is closest to the query state , and return that example's value. If the query is and is the example in memory whose state is closest to , then is returned as the approximate value of . A refinement is the weighted average: retrieve a set of nearest examples and return a weighted average of their target values, the weights decreasing with distance from the query. More elaborate still is locally weighted regression, which fits a surface to the values of a set of nearby states using a parametric fit that minimizes a distance-weighted error, then evaluates that surface at the query state — and, being memory-based, throws the fitted surface away afterward.1

Three local memory-based rules answering a query at (blue). Nearest neighbor copies the value of the single closest stored state; weighted average blends a set of neighbors with distance-decaying weights; locally weighted regression fits a small surface to the neighbors and evaluates it at .

A weighted-average example. Suppose the query state has three stored neighbors with target values at distances . A common weighting is the Gaussian with bandwidth , giving weights , , and . The weighted average is

The nearest neighbor alone would return ; the weighted average pulls the estimate toward by including the two farther examples at diminishing weight. Shrinking the bandwidth toward zero recovers pure nearest neighbor (only the closest example retains weight); growing it toward infinity recovers the unweighted mean of all three, . The bandwidth is the single parameter that trades locality against smoothing.

Bandwidth controls the weighted average. Small (left) concentrates all weight on the nearest example and approaches nearest neighbor; large (right) spreads weight evenly and approaches the unweighted mean. The worked example () sits between, returning 7.84 for neighbors valued 10, 6, 2.

Being nonparametric, local methods carry advantages that suit reinforcement learning particularly well. They are not confined to a pre-chosen functional form, so accuracy improves as data accumulates. Because trajectory sampling concentrates experience on the states actually visited, local methods can focus their approximation exactly there — there may be no need to approximate the value of the vast regions of state space the policy never reaches. And a single new example has an immediate, local effect on estimates in its neighborhood, whereas a parametric method must incrementally adjust a global approximation into agreement.

Avoiding a global approximation is also a way to blunt the curse of dimensionality. A tabular method storing a global approximation over a -dimensional space needs memory exponential in . A memory-based method needs memory proportional to per example, so storing examples is linear in and linear in — nothing is exponential.1 The catch is speed. The critical question is whether a memory-based method can answer queries fast enough to be useful, and how retrieval slows as memory grows: finding nearest neighbors in a large database can be too slow to be practical. Special data structures such as -d trees, which recursively split the space into regions arranged as a binary tree, can quickly rule out large regions during a neighbor search and make retrieval feasible where a naive scan would not be.

Kernel-based function approximation

The local methods above all assign a weight to each stored example based on the distance between and the query . The function that assigns those weights is a kernel function, or simply a kernel. In the weighted-average and locally-weighted-regression methods a kernel turns a distance into a weight. More generally the weight need not depend on distance at all: a kernel assigns as the weight given to data about when answering a query about . Read this way, measures the strength of generalization from to — how relevant knowledge about one state is to another.2

Kernel regression is the memory-based method that computes a kernel-weighted average of the targets of all examples in memory, and assigns the result to the query. If is the set of stored examples and is the target stored for state , kernel regression approximates the value function as

The weighted-average method of the previous section is the special case in which is nonzero only when and are close, so the sum need not run over all of .

Kernel regression at query . Each stored state contributes its target weighted by the kernel , which falls off with distance; the estimate is the kernel-weighted average, and the bell curve traces how the RBF kernel weights range over states.

RBF kernels and the kernel trick

A common choice is the Gaussian radial basis function (RBF) kernel. In the RBF features of the previous lesson, the RBFs were parametric: a fixed set of bumps with pre-placed centers, whose weights were learned by gradient descent. Kernel regression with an RBF kernel differs on both counts. It is memory-based — the RBFs are centered on the states of the stored examples, not on a fixed grid — and it is nonparametric — there are no weights to learn, the response to a query coming directly from the kernel-weighted sum above.2

The deeper point is that any linear parametric method can be recast as a kernel method. Take states represented by feature vectors , exactly the linear setup of the previous lesson. That method can be recast as kernel regression with the kernel

the inner product of the two states' feature vectors. Kernel regression with this kernel produces the same approximation the linear parametric method would, trained on the same data. The implication runs the other way too: instead of constructing features and taking inner products, one can specify a kernel directly, never mentioning feature vectors at all. This is the kernel trick. For many feature sets, has a compact closed form that can be evaluated without ever computing in the high-dimensional feature space — effectively working in an expansive (even infinite-dimensional) feature space while touching only the stored examples. When the feature space is large, kernel regression can be far cheaper than the equivalent linear parametric method.2

The kernel trick. A linear method maps each state to a high-dimensional feature vector and takes an inner product; the kernel computes that same quantity directly from and , skipping the feature space entirely.

Not every kernel arises as an inner product of features, but any kernel that can be written this way inherits the parametric method's approximation while potentially costing far less. The kernel trick underlies a great deal of machine learning — support vector machines and Gaussian processes most prominently — and it has been shown to benefit reinforcement learning as well.

Interest and emphasis

One more assumption ran through the previous lesson: all states encountered are treated as equally important. Every algorithm updated states in proportion to the on-policy distribution , and function-approximation resources — always limited — were spread evenly across them. Often that is wrong. In a discounted episodic problem we may care far more about valuing early states accurately than late ones whose rewards, heavily discounted, barely affect the start state's value. In an action-value setting we may care little about the precise value of poor actions far below the greedy one. If the limited approximation resources could be aimed at the states that matter, performance would improve.3

The reason all states were weighted equally is that doing so, according to the on-policy distribution, is where the stronger convergence results for semi-gradient methods hold. Interest and emphasis generalize that distribution rather than discard it. Introduce a non-negative scalar random variable , the interest, measuring how much we care about accurately valuing the state (or state–action pair) at time : zero if we do not care at all, larger where we care more, set in any causal way — it may depend on anything up to time . The weighting in the objective is then redefined as the distribution of states encountered while following the target policy, weighted by interest. Second, introduce another non-negative scalar, the emphasis, which multiplies the learning update and so emphasizes or de-emphasizes the learning done at time . The general -step update becomes

with the emphasis determined recursively from the interest by

taking for all . Emphasis is not just the interest at : it accumulates a discounted echo of the interest at states that bootstrap through. A state whose interest is zero can still receive nonzero emphasis if an interesting state's estimate depends, through bootstrapping, on it.3

A four-state Markov reward process. Interest is 1 only at the leftmost state () and 0 elsewhere; each transition earns reward +1 to a terminal state (gray). True values decrease left to right; the parameterization ties the first two states to one weight and the last two to another.

How emphasis sharpens estimates

The four-state process above shows the effect. Episodes start at the left and step right, reward each step, so the true values are . The parameterization has only two weights: the first two states share , the last two share . No setting of can be right everywhere, so the method must choose which states to fit. Suppose interest is at the leftmost state alone and at the other three.3

Without interest and emphasis, gradient Monte Carlo converges to splits the difference between the true and of the first two states, giving the state we actually care about a value rather than its correct . The methods with interest and emphasis instead learn exactly, valuing the interesting first state correctly, and never update at all because emphasis is zero at every state but the leftmost. The two-step semi-gradient TD case is sharper still: without emphasis it again reaches ; with emphasis it converges to , exactly correct at both the first state and the third state — because the first state bootstraps from the third, emphasis flows back to it, and both get valued correctly even though the interest at the third state was zero.

With versus without emphasis on the four-state process. Ordinary learning settles on (dashed), a compromise between true values 4 and 3; interest and emphasis pin (blue) — exact at the one state that matters — and, under two-step TD, pull the bootstrapped third state to its correct value too.

Emphasis, then, is the on-policy weighting made adjustable. The equal weighting assumed everywhere in the previous lesson is the special case for all , which reduces to the on-policy distribution and recovers the ordinary methods exactly. Setting some interests to zero concentrates the same limited approximation capacity on the states that matter, and the recursion ensures the states those states bootstrap from are learned along with them.

Gaussian processes and experience replay

The kernel and memory threads run well past Sutton and Barto. Treating the value function as a draw from a Gaussian process turns kernel regression into a Bayesian method that returns a full posterior — a value estimate and a calibrated uncertainty — at every query. Gaussian-process temporal-difference learning (Engel, Mannor, and Meir 2005, ICML, Reinforcement Learning with Gaussian Processes) builds exactly this, using the kernel to encode generalization between states and the posterior variance to drive exploration toward states the model is unsure about.4 The same GP-with-kernel machinery underlies PILCO (Deisenroth and Rasmussen 2011, ICML, PILCO: A Model-Based and Data-Efficient Approach to Policy Search), a model-based method that learns a GP dynamics model and remains one of the most sample-efficient continuous-control algorithms known — a direct descendant of the kernel view that any linear feature method is a kernel method.5

Memory-based, lazy learning is also the ancestor of experience replay (Lin 1992, Self-improving reactive agents), the technique of storing past transitions in a buffer and re-drawing them to train an off-policy learner. Deep Q-networks (Mnih et al. 2015, Nature) made replay standard practice — storing raw transitions and reusing them is the same keep the examples, process them at query time idea that defines memory-based approximation, moved from the value estimate to the training loop.6

Where this leaves us

Dropping the parametric commitment gives a different kind of flexibility. Memory-based methods store the examples and answer queries locally, so accuracy grows with the data and effort concentrates where trajectory sampling actually puts the agent. Kernel methods systematize the local weighting into a kernel and, through the kernel trick, work implicitly in vast feature spaces while touching only stored examples; every linear method is itself a kernel method. Interest and emphasis make the on-policy weighting itself a design choice, aiming scarce approximation capacity at the states that matter.

AxisOptionsTrade
Parametric vs. nonparametricfixed vs. stored examplescapacity fixed vs. grows with data
Global vs. localone everywhere vs. per-query fitgeneralizes broadly vs. focuses where visited
Feature vs. kernel vs. explicit features vs. implicit similarity

Across both halves of this pair, data efficiency can be traded for compute, as in LSTD, or for memory, as in kernel and memory-based methods; the right point on that curve depends on which resource is scarce. From here the subject leaves on-policy prediction for control at scale and the deadly triad, where combining approximation, bootstrapping, and off-policy training can make even these carefully weighted methods diverge.

Footnotes

  1. Sutton & Barto, §9.9 — Memory-based Function Approximation: parametric versus memory-based (lazy) learning; nonparametric methods; local-learning methods — nearest neighbor, weighted average, and locally weighted regression; the advantages for trajectory-sampled RL and against the curse of dimensionality (memory linear in and ); and the retrieval-speed concern with -d trees. 2 3
  2. Sutton & Barto, §9.10 — Kernel-based Function Approximation: the kernel function as strength of generalization; kernel regression (9.23); the RBF kernel as memory-based and nonparametric; the recasting of any linear parametric method as kernel regression with (9.24); and the kernel trick working in high-dimensional feature spaces at low cost. 2 3
  3. Sutton & Barto, §9.11 — Looking Deeper at On-policy Learning: Interest and Emphasis: the interest redefining in ; the emphasis scaling the update (9.25) with the recursion (9.26); and Example 9.4, the four-state Markov reward process where interest and emphasis recover the exact value of the leftmost state (and, under two-step TD, the bootstrapped third state). 2 3
  4. Engel, Mannor, and Meir (2005), Reinforcement Learning with Gaussian Processes, ICML: models the value function as a Gaussian process, using the kernel to encode state generalization and the posterior variance as a calibrated uncertainty for exploration — a Bayesian form of the kernel regression this lesson describes.
  5. Deisenroth and Rasmussen (2011), PILCO: A Model-Based and Data-Efficient Approach to Policy Search, ICML: learns a Gaussian-process model of the environment dynamics and optimizes a policy through it; among the most sample-efficient continuous-control methods, built on the same GP-with-kernel machinery.
  6. Lin (1992), Self-Improving Reactive Agents Based on Reinforcement Learning, Planning and Teaching, Machine Learning 8: introduces experience replay, storing past transitions and re-drawing them for training. Mnih et al. (2015), Human-level control through deep reinforcement learning, Nature 518: makes replay standard practice in deep Q-networks — a training-loop analogue of memory-based, lazy learning.

╌╌ END ╌╌