Exemplo n.º 1
0
 def get_tiles(self, state):
     """Transform a state composed of a group of continous features to tiles"""
     #print(state)
     tiledState = tiles.tiles(self.numtilings, self.memct,
                              state[0])  #Comment [0]
     tiledState.extend(
         tiles.tiles(self.numtilingsFriend, self.memctFriend,
                     state[1]))  #Comment Here
     #Converting to tuple makes the tile coding hashable
     return tuple(tiledState)
def stripetiles(numtilings, memctable, floats, widths=None, ints=[]):
    "returns tiles in the shape of stripes (scaled by widths), a set for each dimension in floats"
    floats = scalefloats(floats, widths)
    # should another int be added here for each dimension if there is more than one?
    return reduce(
        operator.add,
        [tiles.tiles(numtilings, memctable, [f], ints) for f in floats])
Exemplo n.º 3
0
    def quantize(self, features):
        """Quantize the features, returns a list containing the value of the tiles for each variable
          The return is a array of arrays, each array consists in the value of a tile for all variables"""

        resultList = []

        #Computes the value of tiles for each feature
        #for feature in features:
        #    resultList.extend(tiles.tiles(self.t,self.col,[feature]))
        resultList.extend(tiles.tiles(self.t, self.col, features))

        return resultList
Exemplo n.º 4
0
 def getTileState(self):
     coords = (self.divisions/(self.xGoal-self.xMin)*self.x, self.divisions/(2*self.xDotMax)*self.xdot)
     return np.array(tiles.tiles(self.numtilings,self.ctable,coords))
def fancytiles(numtilings, floats, tileshape="square", tilesize="uniform", \
               tilewidths=None, memctable=2048, ints=[]):
    """Does appropriate manipulations to get special shaped or sized tiles.
       Tileshapes are 'square' - square or rectangular tiles (the default),
                      'stripe' - stripes for each dimension, and
                      'diagonal' - diagonal stripes for each pair of dimensions
                      'backdiagonal' diagonal stripes the other way
                      'alldiagonal' - diagonal stripes for all dimensions at once
                      'allbackdiagonal' - diagonal stripes the other way for all dimensions at once
                      'diamond' - diagonal stripes and back diagonal stripes are applied
       Tilesizes are 'uniform' - all tiles are the same size (the default),
                     'log' - tile sizes vary logarithmically from small to large, and
                     'exp' - tile sizes vary exponentially from large to small
       Scaling is handled first if tilewidths is set - there should be a width for every
       element of the float vector. If you don't wish to apply scaling to the floats,
       tilewidths may be set to None, or to a vector of 1's the same length as floats.
       memctable, numtilings and ints are the same as for the regular tiles routine.
       Note that you may get back more tiles than numtilings - for stripes or diagonal stripes
       you may get a larger number of tiles back.
    """
    if tilewidths != None:  # apply scaling, if desired
        floats = scalefloats(floats, tilewidths)
    if tilesize == "log":  # logarithmic sized tiles
        floats = logfloats(floats)
    elif tilesize == "exp":  # exponential sized tiles
        floats = expfloats(floats)

    if tileshape == "stripe":  # stripes - do one set for each variable in floats
        return reduce(
            operator.add,
            [tiles.tiles(numtilings, memctable, [f], ints) for f in floats])
    elif tileshape == "diagonal":  # diagonal stripes for every pair of dimensions
        flist = floats[:]
        tlist = []
        while len(flist) > 1:
            current = flist[0]
            for next in flist[1:]:
                tlist.extend(
                    tiles.tiles(numtilings, memctable,
                                diagonalstripe([current, next]), ints))
            flist = flist[1:]
        return tlist
    elif tileshape == "backdiagonal":  # diagonal stripes for every pair of dimensions
        flist = floats[:]
        tlist = []
        while len(flist) > 1:
            current = flist[0]
            for next in flist[1:]:
                tlist.extend(
                    tiles.tiles(numtilings, memctable,
                                backdiagonalstripe([current, next]), ints))
            flist = flist[1:]
        return tlist
    elif tileshape == "alldiagonal":  # diagonal stripe through all dimensions at once - no different than diag?
        return tiles.tiles(numtilings, memctable, diagonalfloats(floats), ints)
    elif tileshape == "allbackdiagonal":  # diagonal stripe through all dimensions at once
        return tiles.tiles(numtilings, memctable, backdiagonalfloats(floats),
                           ints)
    elif tileshape == "diamond":  # diamond shaped tiles
        floats1 = diagonalfloats(floats)
        floats2 = backdiagonalfloats(floats)
        return tiles.tiles(numtilings, memctable, floats1 + floats2, ints)
    else:  # square/rectangular - do the regular tiles
        return tiles.tiles(numtilings, memctable, floats, ints)
def diamondtiles(numtilings, memctable, floats, widths=None, ints=[]):
    "returns tiles in the shape of diamonds"
    floats = scalefloats(floats, widths)
    floats1 = diagonalfloats(floats)
    floats2 = backdiagonalfloats(floats)
    return tiles.tiles(numtilings, memctable, floats1 + floats2, ints)
def exptiles(numtilings, memctable, floats, ints=[]):
    "returns tiles which vary in size exponentially from large to small"
    floats = expfloats(floats)
    return tiles.tiles(numtilings, memctable, floats, ints)
def logtiles(numtilings, memctable, floats, ints=[]):
    "returns tiles which vary in size logarithmically from small to large"
    floats = logfloats(floats)
    return tiles.tiles(numtilings, memctable, floats, ints)
def scaletiles(numtilings, memctable, floats, widths=None, ints=[]):
    "returns tiles scaled by widths"
    floats = scalefloats(floats, widths)
    return tiles.tiles(numtilings, memctable, floats, ints)