# Automatic basis function construction

Automatic basis function construction (or basis discovery) is the method of looking for a set of task-independent basis functions that map the state space to a lower-dimensional embedding, while still representing the value function accurately. Automatic basis construction is independent of prior knowledge of the domain, which allows it to perform well where expert-constructed basis functions are difficult or impossible to create.

## Motivation

In reinforcement learning (RL), most real-world Markov Decision Process (MDP) problems have large or continuous state spaces, which typically require some sort of approximation to be represented efficiently.

Linear function approximators[1](LFAs) are widely adopted for their low theoretical complexity. Two subproblems needs to be solved for better approximation: weight optimization and basis construction. To solve the second problem, one way is to design special basis functions. Those basis functions work well in specific tasks but are significantly restricted to domains. Thus constructing basis construction functions automatically is preferred for broader applications.[citation needed]

## Problem definition

A Markov decision process with finite state space and fixed policy is defined with a 5-tuple ${\displaystyle {s,a,p,\gamma ,r}}$, which includes the finite state space ${\displaystyle S={1,2,\ldots ,s}}$, the finite action space ${\displaystyle A}$, the reward function ${\displaystyle r}$, discount factor ${\displaystyle \gamma \in [0,1)}$, and the transition model ${\displaystyle P}$.

Bellman equation is defined as:

${\displaystyle v=r+\gamma Pv.\,}$

When the number of elements in ${\displaystyle S}$ is small, ${\displaystyle v}$ is usually maintained as tabular form. While ${\displaystyle S}$ grows too large for this kind of representation. ${\displaystyle v}$ is commonly being approximated via a linear combination of basis function ${\displaystyle \Phi ={\phi _{1},\phi _{2},\ldots ,\phi _{n}}}$,[2] so that we have:

${\displaystyle v\approx {\hat {v}}=\sum _{i=1}^{n}\theta _{n}\phi _{n}}$

Here ${\displaystyle \Phi }$ is a ${\displaystyle |S|\times n}$ matrix in which every row contains a feature vector for corresponding row, ${\displaystyle \theta }$ is a weight vector with n parameters and usually ${\displaystyle n\ll |s|}$.

Basis construction looks for ways to automatically construct better basis function ${\displaystyle \Phi }$ which can represent the value function well. A good construction method should have the following characteristics:

• Small error bounds between the estimate and real value function
• Form orthogonal basis in the value function space
• Converge to stationary value function fast

## Popular methods

### Proto-value basis

In this approach, Mahadevan analyzes the connectivity graph between states to determine a set of basis functions.[3]

The normalized graph Laplacian is defined as:

${\displaystyle L=I-D^{-{\frac {1}{2}}}WD^{-{\frac {1}{2}}}}$

Here W is an adjacency matrix which represents the states of fixed policy MDP which forms an undirected graph (N,E). D is a diagonal matrix related to nodes' degrees.

In discrete state space, the adjacency matrix ${\displaystyle W}$ could be constructed by simply checking whether two states are connected, and D could be calculated by summing up every row of W. In continuous state space, we could take random walk Laplacian of W.

This spectral framework can be used for value function approximation(VFA). Given the fixed policy, the edge weights are determined by corresponding states' transition probability. To get smooth value approximation, diffusion wavelets are used.[3]

### Krylov basis

Krylov basis construction uses the actual transition matrix instead of random walk Laplacian. The assumption of this method is that transition model P and reward r are available.

The vectors in Neumann series are denoted as ${\displaystyle y_{i}=P^{i}r}$ for all ${\displaystyle i\in [0,infty)}$. It shows that Krylov space spanned by ${\displaystyle y_{0},y_{1},\ldots ,y_{m-1}}$ is enough to represent any value function,[4] and m is the degree of minimal polynomial of ${\displaystyle (I-\gamma P)}$.

Suppose the minimal polynomial is ${\displaystyle p(A)={\frac {1}{\alpha _{0}}}\sum _{i=0}^{m-1}\alpha _{i+1}A^{i}}$, and we have ${\displaystyle BA=I}$, the value function can be written as:

${\displaystyle v=Br={\frac {1}{\alpha _{0}}}\sum _{i=0}^{m-1}\alpha _{i+1}(I-\gamma P)^{i}r=\sum _{i=0}^{m-1}\alpha _{i+1}\beta _{i}y_{i}.}$[5]
Algorithm Augmented Krylov Method[5]
${\displaystyle z_{1},z_{2},\ldots ,z_{k}}$ are top real eigenvectors of P
${\displaystyle z_{k+1}:=r}$
for ${\displaystyle i:=1:(l+k)}$ do
if ${\displaystyle i>k+1}$ then
${\displaystyle z_{i}:=Pz_{i-1}}$;
end if
for ${\displaystyle j:=1:(i-1)}$ do
${\displaystyle z_{i}:=z_{i}-z_{j};}$
end for
if ${\displaystyle \parallel z_{i}\parallel \approx 0}$ then
break;
end if
end for
• k: number of eigenvectors in basis
• l: total number of vectors

### Bellman error basis

Bellman error(or BEBFs) is defined as: ${\displaystyle \varepsilon =r+\gamma P{\hat {v}}-{\hat {v}}=r+\gamma P\Phi \theta -\Phi \theta }$.

Loosely speaking, Bellman error points towards the optimal value function.[6] The sequence of BEBF form a basis space which is orthogonal to the real value function space; thus with sufficient number of BEBFs, any value function can be represented exactly.

Algorithm BEBF
stage stage i=1, ${\displaystyle \phi _{1}=r}$;
stage ${\displaystyle i\in [2,N]}$
compute the weight vector ${\displaystyle \theta _{i}}$ according to current basis function ${\displaystyle \Phi _{i}}$;
compute new bellman error by ${\displaystyle \varepsilon =r+\gamma P\Phi _{i}\theta _{i}-\Phi _{i}\theta _{i}}$;
add bellman error to form new basis function: ${\displaystyle \Phi _{i+1}=[\Phi _{i}:\varepsilon ]}$;
• N represents the number of iterations till convergence.
• ":" means juxtaposing matrices or vectors.

### Bellman average reward bases

Bellman Average Reward Bases(or BARBs)[7] is similar to Krylov Bases, but the reward function is being dilated by the average adjusted transition matrix ${\displaystyle P-P^{*}}$. Here ${\displaystyle P^{*}}$ can be calculated by many methods in.[8]

BARBs converges faster than BEBFs and Krylov when ${\displaystyle \gamma }$ is close to 1.

Algorithm BARBs
stage stage i=1, ${\displaystyle P^{*}r}$;
stage ${\displaystyle i\in [2,N]}$
compute the weight vector ${\displaystyle \theta _{i}}$ according to current basis function ${\displaystyle \Phi _{i}}$;
compute new basis: ${\displaystyle :\phi _{i+1}=r-P^{*}r+P\Phi _{i}\theta _{i}-\Phi _{i}\theta _{i}}$, and add it to form new bases matrix${\displaystyle \Phi _{i+1}=[\Phi _{i}:\phi _{i+1}]}$;
• N represents the number of iterations till convergence.
• ":" means juxtaposing matrices or vectors.

## Discussion and analysis

There are two principal types of basis construction methods.

The first type of methods are reward-sensitive, like Krylov and BEBFs, they dilate the reward function geometrically through transition matrix. However, when discount factor ${\displaystyle \gamma }$ approaches to 1, Krylov and BEBFs converge slowly. This is because the error Krylov based methods are restricted by Chebyshev polynomial bound.[5] To solve this problem, some methods, like BARBs are proposed. BARBs is an incremental variant of Drazin bases, and converges faster than Krylov and BEBFs when ${\displaystyle \gamma }$ becomes large.

Another one [clarification needed] is reward-insensitive proto value basis function derived from graph Lapalacian. This method uses graph information, but the construction of adjacency matrix makes this method hard to analyze.[5]