RLPark 1.0.0
Reinforcement Learning Framework in Java

UNH.java

Go to the documentation of this file.
00001 package rlpark.plugin.rltoys.algorithms.representations.tilescoding.hashing;
00002 
00003 import java.util.Random;
00004 
00005 
00006 /*
00007  External documentation and recommendations on the use of this code is
00008  available at http://webdocs.cs.ualberta.ca/~sutton/tiles2.html
00009 
00010  This is an implementation of grid-style tile codings, based originally on 
00011  the UNH CMAC code (see http://www.ece.unh.edu/robots/cmac.htm). 
00012  We assume that hashing collisions are to be ignored. There may be
00013  duplicates in the list of tiles, but this is unlikely if memory-size is
00014  large. 
00015  */
00016 public class UNH extends AbstractHashing {
00017   private static final long serialVersionUID = 6445159636778781514L;
00018   private static final int increment = 470;
00019   private final int[] rndseq;
00020 
00021   public UNH(Random random, int memorySize) {
00022     super(memorySize);
00023     rndseq = new int[16384];
00024     for (int k = 0; k < rndseq.length; k++) {
00025       rndseq[k] = 0;
00026       for (int i = 0; i < 4; ++i)
00027         rndseq[k] = rndseq[k] << 8 | random.nextInt() & 0xff;
00028     }
00029   }
00030 
00031   @Override
00032   protected int hash(int[] coordinates) {
00033     int index = 0;
00034     long sum = 0;
00035     for (int i = 0; i < coordinates.length; i++) {
00036       /* add random table offset for this dimension and wrap around */
00037       index = coordinates[i];
00038       index += increment * i;
00039       index %= rndseq.length;
00040       while (index < 0)
00041         index += rndseq.length;
00042       /* add selected random number to sum */
00043       sum += rndseq[index];
00044     }
00045     index = (int) (sum % memorySize);
00046     while (index < 0)
00047       index += memorySize;
00048     return index;
00049   }
00050 }
 All Classes Namespaces Files Functions Variables Enumerations
Zephyr
RLPark