本文整理汇总了Python中location.Location.getGrids方法的典型用法代码示例。如果您正苦于以下问题:Python Location.getGrids方法的具体用法?Python Location.getGrids怎么用?Python Location.getGrids使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类location.Location
的用法示例。
在下文中一共展示了Location.getGrids方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getGrids [as 别名]
def __init__(self,N_mazeSize, x,y, ith, SURFdict):
#self.placeCells = np.zeros((1+4*N_mazeSize))
loc=Location()
loc.setXY(x,y)
#placeId = loc.placeId
#self.placeCells[placeId] = 1
self.grids = loc.getGrids().copy()
self.hd = np.array([0,0,0,0])
self.hd[ith]=1
self.rgb=np.array([0,0,0]) #assume a red poster in the east and a green poster in the north
if ith==0: #NB these differ from head direction cells, as HD odometry can go wrong!
self.rgb[0]=1
if ith==1:
self.rgb[1]=1
if SURFdict is not None:
#HOOK ALAN - include SURF features in the senses of the dictionary
#Problem with merging here is you can only have one image per direction?
self.surfs=findSurfs(x,y,ith,SURFdict)
else:
self.surfs=np.array([])
#print("Surf feature for %d,%d,%d:\n%s" % (x,y,ith,self.surfs))
#x,y relate to surf features in SURFdict
self.whiskers=np.array([0,0,0]) #to be filled in outside
示例2: updateGrids
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getGrids [as 别名]
def updateGrids(self, ca1grids, ca1hd, b_odom, N_mazeSize, dictGrids):
loc=Location()
loc.setGrids(ca1grids, dictGrids)
(x_hat_prev, y_hat_prev) = loc.getXY()
## Hard coded again here North negative.....
dxys = [[1,0],[0,1],[-1,0],[0,-1]] #by hd cell
ihd = argmax(ca1hd)
odom_dir = dxys[ihd]
odom = [0,0]
if b_odom:
odom=odom_dir
x_hat_now = x_hat_prev + odom[0]
y_hat_now = y_hat_prev + odom[1]
##SMART UPDATE -- if odom took us outside the maze, then ignore it
#pdb.set_trace()
##if this takes me to somewhere not having a '3'(=N_mazeSize) in the coordinate, then the move was illegal?
if sum( (x_hat_now==N_mazeSize) + (y_hat_now==N_mazeSize))==0:
print "OFFMAZE FIX: OLD:" ,x_hat_now, y_hat_now
x_hat_now = x_hat_prev
y_hat_now = y_hat_prev
print "NEW:",x_hat_now, y_hat_now
x_hat_now = crop(x_hat_now, 0, 2*N_mazeSize)
y_hat_now = crop(y_hat_now, 0, 2*N_mazeSize) #restrict to locations in the maze
loc=Location()
loc.setXY(x_hat_now, y_hat_now)
#self.placeCells=zeros(ca1placeCells.shape)
#self.placeCells[loc.placeId] = 1
self.grids = loc.getGrids().copy()
示例3: makeNoisyCopy
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getGrids [as 别名]
def makeNoisyCopy(self, b_GPSNoise=True): #makes and returns a noisy copy
ec = ECState(self)
p_flip = 0.2
p_flip_odom = 0.2 #testing, make the grids,hds very unreliable (TODO iterative training??)
if b_GPSNoise:
if random.random()<p_flip_odom: #simulate grid errors- fmove to a random place (as when lost)
#N_places = 13 # Luke arguments sent in at top!
i = random.randrange(0,self.N_places) # Luke converted to self
loc = Location()
loc.setPlaceId(i)
ec.grids = loc.getGrids().copy()
if random.random()<p_flip_odom: #simulate HD errors
i = random.randrange(0,4)
ec.hd[:] = 0
ec.hd[i] = 1
##if random.random()< 0.05: ####simulate lost/reset events WRITEUP: EM like estimation of own error rate needed here (cf. Mitch's chanel equalisation decision feedback/decision directed)
## ec.placeCells = 0.0 * ec.placeCells
## ec.hd = 0.0 * ec.hd ##no this isnt what we want to do -- we dont want to leatn flatness as an OUTPUT!
if random.random()<p_flip: #flip whiskers
ec.whiskers[0] = 1-ec.whiskers[0]
if random.random()<p_flip: #flip whiskers
ec.whiskers[0] = 1-ec.whiskers[0]
if random.random()<p_flip: #flip whiskers
ec.whiskers[1] = 1-ec.whiskers[1]
if random.random()<p_flip: #flip whiskers
ec.whiskers[2] = 1-ec.whiskers[2]
if random.random()<p_flip: #flip lightAhead
ec.lightAhead = 1-ec.lightAhead
if random.random()<p_flip: #flip colors
ec.rgb[0] = 1-ec.rgb[0]
if random.random()<p_flip: #flip colors
ec.rgb[1] = 1-ec.rgb[1]
for featureInd, feature in enumerate(ec.surfs): #ALAN implemented flipping
if random.random()<p_flip:
ec.surfs[featureInd] = 1-feature
return ec
示例4: __init__
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getGrids [as 别名]
def __init__(self, p_odom, p_senses, dghelper=None, n_places=13):
i=0
n_grids=6
n_hd=4
# AGAIN n_places
# Luke removed! n_places=13
#pdb.set_trace()
p_grids = p_odom[i:i+n_grids]; i+=n_grids
p_hd = p_odom[i:i+n_hd]; i+=n_hd
p_places = p_odom[i:i+n_places]; i+=n_places
i=0
n_whiskers=3
n_rgb=3
n_lightAhead=1
n_whiskerCombis=3
p_whiskers = p_senses[i:i+n_whiskers]; i+=n_whiskers
p_rgb = p_senses[i:i+n_rgb]; i+=n_rgb
p_lightAhead = p_senses[i:i+n_lightAhead]; i+=n_lightAhead
p_whiskerCombis = p_senses[i:i+n_whiskerCombis]; i+=n_whiskerCombis
#HOOK: put your decoding of output (whatever representation that is...., here)
#decode remaining sensors which are the features previously encoded
if dghelper is not None:
#Get the number of surf features
n_surfFeatures = dghelper.numOfSurfFeatures
#Get the number of encoded features
n_encoded = dghelper.numOfEncodedFeatures
#print("Num of surf features: %d\nNum of encodedFeatures: %d\nNum of all feautres: %d" % (n_surfFeatures, n_encoded, (n_surfFeatures+n_encoded)))
p_surfFeatures = p_senses[i:i+n_surfFeatures]; i+=n_surfFeatures
p_encoded = p_senses[i:i+n_encoded]; i+=n_encoded
#We now have two sources of surf, one from the probabilities that came from EC into CA3, and one from the DG encoded going into CA3
#Dumb decode the former:
surfFromEC = (p_surfFeatures>0.5)
#Very smart decode... use the weights learnt to decode back to EC space
surfFromDG = dghelper.decode(p_encoded)
#Experiment with using both see what advantage DG gives over EC
self.surfs = surfFromDG
#print("Total length of senses:%d, used:%d" % (len(p_senses), i))
#smart decoding, use smart feature collapse, then create ECd pops here too
self.places = smartCollapse(p_places)
self.hd = smartCollapse(p_hd)
#print("p_whiskerCombis: %s" % p_whiskerCombis)
self.whiskerCombis = smartCollapse(p_whiskerCombis)
loc=Location()
loc.setPlaceId(argmax(self.places))
self.grids=loc.getGrids()
#dumb decodes
self.lightAhead = (p_lightAhead>0.5)
self.rgb = (p_rgb>0.5)
#print("whisker combis: %s" % self.whiskerCombis)
#whiskers
if self.whiskerCombis[0]:
self.whiskers=np.array([1,1,1]) #all
elif self.whiskerCombis[1]:
#print(self.places)
#print("no whiskers touching")
self.whiskers=np.array([0,0,0]) #none
elif self.whiskerCombis[2]:
#print("left right whiskers touching")
self.whiskers=np.array([1,0,1]) #L+R
示例5: makeMaze
# 需要导入模块: from location import Location [as 别名]
# 或者: from location.Location import getGrids [as 别名]
def makeMaze(b_useNewDG=False, prefixFolder = None):
# Set up maze data loader
maze_data=maze_from_data(prefixFolder)
# Load data from folder
maze_data.index_image_files()
# Display maze - TESTING
#maze_data.display_maps_images()
#maze_data.maze_interactive()
# maze_data.maze_walk()
# Run SURF features....
surfDict=None
surfDict = makeSURFRepresentation(prefixFolder,False)
print('SURF Completed')
## Store all sensory inputs in here, head direction, image surfs, whiskers
dictSenses=dict()
dictAvailableActions=dict()
dictNext=dict()
# Calculate NMax as grid cell encoding...
# Setup as a 2xn grid, therfore need to encode for complete grid sapce, ie if x=4,y=5 grid x*y=20
# Max size of peak2peak of x and y, log2 and maximum size.....
Nmax=int(np.ceil(np.log2(np.amax([maze_data.place_cell_id[1].ptp(),maze_data.place_cell_id[2].ptp()]))))
# Setup location class with nMax
loc=Location(Nmax)
# Step for each move around Maze
maze_step_size=1
# Calc step depending on direction...... PROBELMS HERE WITH LUKE AND CF MAZES!!!!
# Luke x = East is Positive, y = North = positive
# 'N' x=0, y=+ /'E' x=+, y=0 / 'S' x=0, y=- / 'W' x=-, y=0
# step_index=np.array([[0,maze_step_size],[maze_step_size,0],[0,-maze_step_size],[-maze_step_size,0]])
# print 'WARNING RUNNING IN Luke MODE..... North positive!'
# CF x = East is Positive y = South = Positive
# 'N' x=0, y=- / 'E' x=-, y=0 / 'S' x=0, y=+ / 'W' x=+, y=0
print 'WARNING RUNNING IN CHARLES FOX MODE..... North negative!'
step_index=np.array([[0,-maze_step_size],[maze_step_size,0],[0,maze_step_size],[-maze_step_size,0]])
# Loop through all locations.... N,E,S,W
for current_id in range(0,maze_data.place_cell_id[0,:].size):
# maze_data.find_next_set_images(0,26,1)
current_x=maze_data.place_cell_id[1,current_id]
current_y=maze_data.place_cell_id[2,current_id]
print('Place cell ID:',str(current_id),' x:',str(current_x),' y:',str(current_y))
## Fn find_next_set_images
## returns: (images_to_combine,image_found,heading,direction_vector,picture_name,available_direction_vector)
## available_direction_vector = [forwards, backwards, left, right]
# Get only those headings available....
included_headings=np.where(maze_data.locations_unique[(current_x,current_y)]['Image_count']>0)
for current_direction in included_headings[0]: # N=0,E=1,S=2,W=3
#direction = directionDict[current_direction]
# SURF HAS A DIFFERENT BLOODY DICTIONARY Key!!!!
#current_surf_location=((current_x,current_y),direction)
current_location=(current_x,current_y,current_direction)
_,image_found,_,_,_,available_direction_vector=maze_data.find_next_set_images(current_x,current_y,current_direction)
if image_found:
# Sense dictionary
dictSenses[current_location]=Senses()
dictSenses[current_location].hd[current_direction]=1 # REVERSE and REMOVE BACKWARDS
dictSenses[current_location].whiskers=np.square(available_direction_vector[[2,0,3]]-1) # LEFT / FORWARDS / RIGHT
dictSenses[current_location].rgb=np.array([0,0,0]) # Not set at the moment
try:
dictSenses[current_location].surfs=findSurfs(current_x,current_y,current_direction,surfDict)
except:
pass
##dictSenses[current_location].grids=1#SORT GRIDS
loc.setXY(current_x,current_y)
dictSenses[current_location].grids = loc.getGrids().copy()
# Which ways can you go....
# Take from available action vector [FWD=1, REVERSE(UTURN)=4, LEFT=2, RIGHT=3]
#TODO: MAY need to spin this round - Charles fox different systems
dictAvailableActions[current_location] = np.concatenate(([0],np.array([1,4,2,3])[np.where(available_direction_vector>0)]))#[STAY,FWD,LEFT,RIGHT]
# What is available next
#WTF!!!! dictNext[current_location] = [(x,y,direction), (x+step_xs[direction],y+step_ys[direction],direction), (x,y,direction_l), (x,y,direction_r)]
# Stay in the same place!!!!
# = 0
#dictNext[current_location] = [current_location]
next_locations=(current_x,current_y,current_direction)
# Calc step depending on direction...... x, y
current_stepping=step_index[current_direction]
# Forward
if 1 in dictAvailableActions[current_location]:
#dictNext[current_location].append([(current_x+current_stepping[0],current_y+current_stepping[1]),current_direction])
next_locations=next_locations+(current_x+current_stepping[0],current_y+current_stepping[1],current_direction)
# Left
if 2 in dictAvailableActions[current_location]:
new_heading,_=maze_data.phase_wrap_heading(current_direction-1)
#dictNext[current_location].append([(current_x,current_y),directionDict[new_heading]])
#.........这里部分代码省略.........