Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ratinabox/contribs/SuccessorFeatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class SuccessorFeatures(ValueNeuron):
"""
Contributer: Tom George tomgeorge1@btinternet.com

The SuccessorFeatures class defines neuron(s) which learns the "successor features" of a set of features {\phi_i(x)}, using TD learning. This is a special case of the ValueNeuron class where the reward function is the features (thus the value function being learned are the successor features). Successor features are approximated, {\hat{\psi}_i}, as a non-linearly activated (default relu) linear sum of a set of "basis features", {f_i(x)}.
The SuccessorFeatures class defines neuron(s) which learns the "successor features" of a set of features {\\phi_i(x)}, using TD learning. This is a special case of the ValueNeuron class where the reward function is the features (thus the value function being learned are the successor features). Successor features are approximated, {\\hat{\\psi}_i}, as a non-linearly activated (default relu) linear sum of a set of "basis features", {f_i(x)}.

Note the basis features are not the same as the input features, they are a set of basis functions (e.g. place cells, grid cells, boundary vector cells etc...) which are used to represent the successor features of the input features. This TeX equation summarises the idea:

$$\hat{\psi_i}(t) = \sigma^{\textrm{non-lin}}\bigg(\sum_j w_{ij} f_j(t)\bigg) \approx \psi_i^{\pi}(t) = \mathbb{E} \bigg[ \int_{t}^{\infty} e^{-\frac{t^{\prime}-t}{\tau}} \phi_i(t^{\prime}) dt^{\prime}\bigg] $$
$$\\hat{\\psi_i}(t) = \\sigma^{\\textrm{non-lin}}\\bigg(\\sum_j w_{ij} f_j(t)\\bigg) \\approx \\psi_i^{\\pi}(t) = \\mathbb{E} \\bigg[ \\int_{t}^{\\infty} e^{-\\frac{t^{\\prime}-t}{\\tau}} \\phi_i(t^{\\prime}) dt^{\\prime}\\bigg] $$

Basis features can be any list of RatInABox Neurons class here (a set of PlaceCells, BoundaryVectorCells, GridCells etc...or more complex things). Specify basis features with the params["input_layers"] kwarg. It linearly sums these inputs to calculate the firing rate (this summation is all handled by the FeedForwardLayer class). Since successor features are a subset of value functions (where the reward is the feature activity), this class is a subclass of WalueNeuron. The only fundamental difference is it also insists you pass features, on each update_weights() call passes the activity of the feaures to super().update() as reward signals. Weights are trained using TD learning, self.update_weights() should be called at each update step. Remember 'eta' and 'tau_e' as kwargs of the ValueNeuron which you may like to play around with. For more infor see ratinabox/example_scripts/successor_features/ or the parent class ValueNeuron for details of the learning rule.

Expand Down
8 changes: 4 additions & 4 deletions ratinabox/contribs/ValueNeuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class ValueNeuron(FeedForwardLayer):

The ValueNeuron class defines neuron(s) which learns the "value" of a policy using TD learning. For n > 1 the reward function is assumed to be multidimensional and n value functions (one neuron for each reward function) will be learned under the current policy.

The true value function, V, is approximated, \hat{V}, as a non-linearly activated (default relu) linear sum of input features (i.e. one layer neural network, in later classes we may generalise this):
The true value function, V, is approximated, \\hat{V}, as a non-linearly activated (default relu) linear sum of input features (i.e. one layer neural network, in later classes we may generalise this):

V_i(x) = \int_{t}^{\infty}e^{-\frac{t^{\prime}-t}{\tau}}R_i(x(t^{\prime}))) dt^{\prime} | x(t) = x \\
\hat{V}_i(x) \approx \sigma_{nonlinearity} ( \w_{ij} \cdot \phi_j(x) )
V_i(x) = \\int_{t}^{\\infty}e^{-\\frac{t^{\\prime}-t}{\\tau}}R_i(x(t^{\\prime}))) dt^{\\prime} | x(t) = x \\
\\hat{V}_i(x) \\approx \\sigma_{nonlinearity} ( \\w_{ij} \\cdot \\phi_j(x) )

For this we calculate the (temporally continuous) temporal difference error and apply it to the weights:

td_error(t) = R(t) + dV(t)/dt - V(t)
d w_i = \eta td_error(t) \z_i(t) \psi_prime(t)
d w_i = \\eta td_error(t) \\z_i(t) \\psi_prime(t)

where z is the eligibility trace of the i^th feature (psi_prime accounts for the non-linearrity in the learning rule and is caluclated by the parent class.

Expand Down
Loading