Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

34 Commits

Repository files navigation

Kanerva Coding

Kanerva coding is a coarse coding method that distributes prototypes across the state space, and uses them to produce binary feature vectors for for points in a continuous space. This implementation is a variant that uses the L∞ distance metric, and activates the k-nearest prototypes to the input.

Dependencies

  • numpy
  • matplotlib (to run the example)

Usage

importnumpyasnpfromkanervacodingimportkanervacoder# dimensions, value limits of each dimension, prototypes, and number of active features (k)dims=4lims= [(3.0, 7.5), (-4.4, 4.2), (9.6, 12.7), (0.0, 1.0)]
ptypes=1024n_active=32# create kanervacoderK=kanervacoder(dims, ptypes, n_active, lims)
# init weights and step sizew=np.zeros(K.n_ptypes)
alpha=0.1/n_active# training iteration with value 5.5 at location (3.3, -2.1, 11.1, 0.7)phi=K[3.3, -2.1, 11.1, 0.7]
w[phi] =alpha* (5.5-w[phi].sum())
# get approximated value at (3.3, -2.1, 11.1, 0.7)print(w[phi].sum())

Examples


Kanerva coder with 512 prototypes and 2.5% sparsity approximating f(x, y) = sin(x) + cos(y) + N(0, 0.1)

About

Binary feature representations with Kanerva coding

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages