def represent (self, input): nlist = [] i = 0 for scalingi in self.scaling: nlist .append(input[i] * scalingi) i += 1 if self.hashingset == None: return tiles.tiles(self.numoutputs, self.memorysize, nlist) else: return tiles.tiles(self.numoutputs, self.memorysize, nlist, self.hashingset)
def represent(self, input): nlist = [] i = 0 for scalingi in self.scaling: nlist.append(input[i] * scalingi) i += 1 if self.hashingset == None: return tiles.tiles(self.numoutputs, self.memorysize, nlist) else: return tiles.tiles(self.numoutputs, self.memorysize, nlist, self.hashingset)
def q(S_tiles, A, weights): val = 0 for index in S_tiles: val += weights[A][index] return val count = 1 avg_ep_length = 0 converging = True while converging: pos1, vel1 = np.random.uniform(low=-0.6, high=-0.4), 0 # position, velocity S1 = tiles.tiles(num_tilings, memsize, (pos1 / tile_width, vel1 / tile_width)) A1 = policy(S1, theta, epsilon) _, pos2, vel2 = bound(pos1, vel1 + .001 * (A1 - 1) - .0025 * np.cos(3 * pos1)) S2 = tiles.tiles(num_tilings, memsize, (pos2 / tile_width, vel2 / tile_width)) A2 = policy(S2, theta, epsilon) theta[A1][S1] += alpha * (-1 + gamma * q(S2, A2, theta) - q(S1, A1, theta)) ep_length = 0 game_in_progress = True while game_in_progress: pos1, vel1 = pos2, vel2
def calcTiledata(self, numtilings, memct, floats, ints=[]): global ctss, ctssc, cts, ctsc, ctu, ctuc if memct == ctss: memctc = ctssc elif memct == ctu: memctc = ctuc elif memct == cts: memctc = ctsc else: memctc = memct samet = [] sametd = [] sametbd = [] sametdm = [] sametl = [] samete = [] samets = [] t = tiles.tiles(numtilings, memct, floats, ints) tsx = fancytiles.stripetiles(numtilings, memct, [floats[0]], None, ints) tsy = fancytiles.stripetiles(numtilings, memct, [floats[1]], None, ints) td = fancytiles.diagonaltiles(numtilings, memct, floats, None, ints) tbd = fancytiles.backdiagonaltiles(numtilings, memct, floats, None, ints) tdm = fancytiles.diamondtiles(numtilings, memct, floats, None, ints) tl = fancytiles.logtiles(numtilings, memct, floats, ints) te = fancytiles.exptiles(numtilings, memct, floats, ints) ct = ctiles.tiles(numtilings, memctc, floats, ints) ctsx = fancytilesc.stripetiles(numtilings, memctc, [floats[0]], None, ints) ctsy = fancytilesc.stripetiles(numtilings, memctc, [floats[1]], None, ints) ctd = fancytilesc.diagonaltiles(numtilings, memctc, floats, None, ints) ctbd = fancytilesc.backdiagonaltiles(numtilings, memctc, floats, None, ints) ctdm = fancytilesc.diamondtiles(numtilings, memctc, floats, None, ints) ctl = fancytilesc.logtiles(numtilings, memctc, floats, ints) cte = fancytilesc.exptiles(numtilings, memctc, floats, ints) csame = [] psame = [] total = int((self.end - self.start) * self.intervals) for i in range(total): for j in range(total): x = float(i) / self.intervals + self.start y = float(j) / self.intervals + self.start newfloats = [x, y] tnew = tiles.tiles(numtilings, memct, newfloats, ints) ctnew = ctiles.tiles(numtilings, memctc, newfloats, ints) if tnew == t and ctnew == ct: samet.append(newfloats) elif tnew == t: psame.append(newfloats) # print "regular tiles same in python but not c", x, y, t, tnew, ct, ctnew elif ctnew == ct: csame.append(newfloats) # print "regular tiles same in c but not python", x, y, t, tnew, ct, ctnew if fancytiles.stripetiles(numtilings, memct, [x], None, ints) == tsx or \ fancytiles.stripetiles(numtilings, memct, [y], None, ints) == tsy: samets.append(newfloats) tdnew = fancytiles.diagonaltiles(numtilings, memct, newfloats, None, ints) ctdnew = fancytilesc.diagonaltiles(numtilings, memctc, newfloats, None, ints) if tdnew == td and ctdnew == ctd: sametd.append(newfloats) elif tdnew == td: psame.append(newfloats) # print "diagonal tiles same in python but not c", x, y, td, tdnew, ctd, ctdnew elif ctdnew == ctd: csame.append(newfloats) # print "diagonal tiles same in c but not python", x, y, td, tdnew, ctd, ctdnew tbdnew = fancytiles.backdiagonaltiles(numtilings, memct, newfloats, None, ints) ctbdnew = fancytilesc.backdiagonaltiles( numtilings, memctc, newfloats, None, ints) if tbdnew == tbd and ctbdnew == ctbd: sametbd.append(newfloats) elif tbdnew == tbd: psame.append(newfloats) print(("back diagonal tiles same in python but not c", x, y, tbd, tbdnew, ctbd, ctbdnew)) elif ctbdnew == ctbd: csame.append(newfloats) print(("back diagonal tiles same in c but not python", x, y, tbd, tbdnew, ctbd, ctbdnew)) tdmnew = fancytiles.diamondtiles(numtilings, memct, newfloats, None, ints) ctdmnew = fancytilesc.diamondtiles(numtilings, memctc, newfloats, None, ints) if tdmnew == tdm and ctdmnew == ctdm: sametdm.append(newfloats) elif tdmnew == tdm: psame.append(newfloats) # print "diamond tiles same in python but not c", x, y, tdm, tdmnew, ctdm, ctdmnew elif ctdmnew == ctdm: csame.append(newfloats) # print "diamond tiles same in c but not python", x, y, tdm, tdmnew, ctdm, ctdmnew tlnew = fancytiles.logtiles(numtilings, memct, newfloats, ints) ctlnew = fancytilesc.logtiles(numtilings, memctc, newfloats, ints) if tlnew == tl and ctlnew == ctl: sametl.append(newfloats) elif tlnew == tl: psame.append(newfloats) # print "log tiles same in python but not c", x, y, tl, tlnew, ctl, ctlnew elif ctlnew == ctl: csame.append(newfloats) # print "log tiles same in c but not python", x, y, tl, tlnew, ctl, ctlnew tenew = fancytiles.exptiles(numtilings, memct, newfloats, ints) ctenew = fancytilesc.exptiles(numtilings, memctc, newfloats, ints) if tenew == te and ctenew == cte: samete.append(newfloats) elif tenew == te: psame.append(newfloats) # print "exp tiles same in python but not c", x, y, te, tenew, cte, ctenew elif ctenew == cte: csame.append(newfloats) # print "exp tiles same in c but not python", x, y, te, tenew, cte, ctenew data = [ samet, samets, sametd, sametbd, sametdm, sametl, samete, psame, csame ] return data
def calcTiledata(self, numtilings, memct, floats, ints=[]): global ctss, ctssc, cts, ctsc, ctu, ctuc if memct == ctss: memctc = ctssc elif memct == ctu: memctc = ctuc elif memct == cts: memctc = ctsc else: memctc = memct samet = [] sametd = [] sametbd = [] sametdm = [] sametl = [] samete = [] samets = [] t = tiles.tiles(numtilings, memct, floats, ints) tsx = fancytiles.stripetiles(numtilings, memct, [floats[0]], None, ints) tsy = fancytiles.stripetiles(numtilings, memct, [floats[1]], None, ints) td = fancytiles.diagonaltiles(numtilings, memct, floats, None, ints) tbd = fancytiles.backdiagonaltiles(numtilings, memct, floats, None, ints) tdm = fancytiles.diamondtiles(numtilings, memct, floats, None, ints) tl = fancytiles.logtiles(numtilings, memct, floats, ints) te = fancytiles.exptiles(numtilings, memct, floats, ints) ct = ctiles.tiles(numtilings, memctc, floats, ints) ctsx = fancytilesc.stripetiles(numtilings, memctc, [floats[0]], None, ints) ctsy = fancytilesc.stripetiles(numtilings, memctc, [floats[1]], None, ints) ctd = fancytilesc.diagonaltiles(numtilings, memctc, floats, None, ints) ctbd = fancytilesc.backdiagonaltiles(numtilings, memctc, floats, None, ints) ctdm = fancytilesc.diamondtiles(numtilings, memctc, floats, None, ints) ctl = fancytilesc.logtiles(numtilings, memctc, floats, ints) cte = fancytilesc.exptiles(numtilings, memctc, floats, ints) csame = [] psame = [] total = int((self.end - self.start) * self.intervals) for i in xrange(total): for j in xrange(total): x = float(i)/self.intervals + self.start y = float(j)/self.intervals + self.start newfloats = [x, y] tnew = tiles.tiles(numtilings, memct, newfloats, ints) ctnew = ctiles.tiles(numtilings, memctc, newfloats, ints) if tnew == t and ctnew == ct: samet.append(newfloats) elif tnew == t: psame.append(newfloats) #print "regular tiles same in python but not c", x, y, t, tnew, ct, ctnew elif ctnew == ct: csame.append(newfloats) #print "regular tiles same in c but not python", x, y, t, tnew, ct, ctnew if fancytiles.stripetiles(numtilings, memct, [x], None, ints) == tsx or \ fancytiles.stripetiles(numtilings, memct, [y], None, ints) == tsy: samets.append(newfloats) tdnew = fancytiles.diagonaltiles(numtilings, memct, newfloats, None, ints) ctdnew = fancytilesc.diagonaltiles(numtilings, memctc, newfloats, None, ints) if tdnew == td and ctdnew == ctd: sametd.append(newfloats) elif tdnew == td: psame.append(newfloats) #print "diagonal tiles same in python but not c", x, y, td, tdnew, ctd, ctdnew elif ctdnew == ctd: csame.append(newfloats) #print "diagonal tiles same in c but not python", x, y, td, tdnew, ctd, ctdnew tbdnew = fancytiles.backdiagonaltiles(numtilings, memct, newfloats, None, ints) ctbdnew = fancytilesc.backdiagonaltiles(numtilings, memctc, newfloats, None, ints) if tbdnew == tbd and ctbdnew == ctbd: sametbd.append(newfloats) elif tbdnew == tbd: psame.append(newfloats) print "back diagonal tiles same in python but not c", x, y, tbd, tbdnew, ctbd, ctbdnew elif ctbdnew == ctbd: csame.append(newfloats) print "back diagonal tiles same in c but not python", x, y, tbd, tbdnew, ctbd, ctbdnew tdmnew = fancytiles.diamondtiles(numtilings, memct, newfloats, None, ints) ctdmnew = fancytilesc.diamondtiles(numtilings, memctc, newfloats, None, ints) if tdmnew == tdm and ctdmnew == ctdm: sametdm.append(newfloats) elif tdmnew == tdm: psame.append(newfloats) #print "diamond tiles same in python but not c", x, y, tdm, tdmnew, ctdm, ctdmnew elif ctdmnew == ctdm: csame.append(newfloats) #print "diamond tiles same in c but not python", x, y, tdm, tdmnew, ctdm, ctdmnew tlnew = fancytiles.logtiles(numtilings, memct, newfloats, ints) ctlnew = fancytilesc.logtiles(numtilings, memctc, newfloats, ints) if tlnew == tl and ctlnew == ctl: sametl.append(newfloats) elif tlnew == tl: psame.append(newfloats) #print "log tiles same in python but not c", x, y, tl, tlnew, ctl, ctlnew elif ctlnew == ctl: csame.append(newfloats) #print "log tiles same in c but not python", x, y, tl, tlnew, ctl, ctlnew tenew = fancytiles.exptiles(numtilings, memct, newfloats, ints) ctenew = fancytilesc.exptiles(numtilings, memctc, newfloats, ints) if tenew == te and ctenew == cte: samete.append(newfloats) elif tenew == te: psame.append(newfloats) #print "exp tiles same in python but not c", x, y, te, tenew, cte, ctenew elif ctenew == cte: csame.append(newfloats) #print "exp tiles same in c but not python", x, y, te, tenew, cte, ctenew data = [samet, samets, sametd, sametbd, sametdm, sametl, samete, psame, csame] return data