#NEWLINE# def showLearning( self , representation ) : #NEWLINE# #INDENT# if ( self . valueFunction_fig is None ) : #NEWLINE# #INDENT# plt . figure ( 'Value Function' ) #NEWLINE# self . valueFunction_fig = plt . imshow ( self . map , cmap = 'ValueFunction' , interpolation = 'nearest' , vmin = self . MIN_RETURN , vmax = self . MAX_RETURN ) #NEWLINE# plt . xticks ( np . arange ( self . COLS ) , fontsize = 12 ) #NEWLINE# plt . yticks ( np . arange ( self . ROWS ) , fontsize = 12 ) #NEWLINE# X = ( np . arange ( self . ROWS ) - self . SHIFT ) #NEWLINE# Y = np . arange ( self . COLS ) #NEWLINE# ( X , Y ) = np . meshgrid ( X , Y ) #NEWLINE# DX = DY = np . ones ( X . shape ) #NEWLINE# C = np . zeros ( X . shape ) #NEWLINE# C [ ( 0 , 0 ) ] = 1 #NEWLINE# arrow_ratio = 0.4 #NEWLINE# Max_Ratio_ArrowHead_to_ArrowLength = 0.25 #NEWLINE# ARROW_WIDTH = ( ( 0.5 * Max_Ratio_ArrowHead_to_ArrowLength ) / 5.0 ) #NEWLINE# self . upArrows_fig = plt . quiver ( Y , X , DY , DX , C , units = 'y' , cmap = 'Actions' , scale_units = 'height' , scale = ( self . ROWS / arrow_ratio ) , width = ( ( - 1 ) * ARROW_WIDTH ) ) #NEWLINE# self . upArrows_fig . set_clim ( vmin = 0 , vmax = 1 ) #NEWLINE# X = ( np . arange ( self . ROWS ) + self . SHIFT ) #NEWLINE# Y = np . arange ( self . COLS ) #NEWLINE# ( X , Y ) = np . meshgrid ( X , Y ) #NEWLINE# self . downArrows_fig = plt . quiver ( Y , X , DY , DX , C , units = 'y' , cmap = 'Actions' , scale_units = 'height' , scale = ( self . ROWS / arrow_ratio ) , width = ( ( - 1 ) * ARROW_WIDTH ) ) #NEWLINE# self . downArrows_fig . set_clim ( vmin = 0 , vmax = 1 ) #NEWLINE# X = np . arange ( self . ROWS ) #NEWLINE# Y = ( np . arange ( self . COLS ) - self . SHIFT ) #NEWLINE# ( X , Y ) = np . meshgrid ( X , Y ) #NEWLINE# self . leftArrows_fig = plt . quiver ( Y , X , DY , DX , C , units = 'x' , cmap = 'Actions' , scale_units = 'width' , scale = ( self . COLS / arrow_ratio ) , width = ARROW_WIDTH ) #NEWLINE# self . leftArrows_fig . set_clim ( vmin = 0 , vmax = 1 ) #NEWLINE# X = np . arange ( self . ROWS ) #NEWLINE# Y = ( np . arange ( self . COLS ) + self . SHIFT ) #NEWLINE# ( X , Y ) = np . meshgrid ( X , Y ) #NEWLINE# self . rightArrows_fig = plt . quiver ( Y , X , DY , DX , C , units = 'x' , cmap = 'Actions' , scale_units = 'width' , scale = ( self . COLS / arrow_ratio ) , width = ARROW_WIDTH ) #NEWLINE# self . rightArrows_fig . set_clim ( vmin = 0 , vmax = 1 ) #NEWLINE# plt . show ( ) #NEWLINE# #UNINDENT# plt . figure ( 'Value Function' ) #NEWLINE# V = np . zeros ( ( self . ROWS , self . COLS ) ) #NEWLINE# Mask = np . ones ( ( self . COLS , self . ROWS , self . actions_num ) , dtype = 'bool' ) #NEWLINE# arrowSize = np . zeros ( ( self . COLS , self . ROWS , self . actions_num ) , dtype = 'float' ) #NEWLINE# arrowColors = np . zeros ( ( self . COLS , self . ROWS , self . actions_num ) , dtype = 'uint8' ) #NEWLINE# for r in xrange ( self . ROWS ) : #NEWLINE# #INDENT# for c in xrange ( self . COLS ) : #NEWLINE# #INDENT# if ( self . map [ ( r , c ) ] == self . BLOCKED ) : #NEWLINE# #INDENT# V [ ( r , c ) ] = 0 #NEWLINE# #UNINDENT# if ( self . map [ ( r , c ) ] == self . GOAL ) : #NEWLINE# #INDENT# V [ ( r , c ) ] = self . MAX_RETURN #NEWLINE# #UNINDENT# if ( self . map [ ( r , c ) ] == self . PIT ) : #NEWLINE# #INDENT# V [ ( r , c ) ] = self . MIN_RETURN #NEWLINE# #UNINDENT# if ( ( self . map [ ( r , c ) ] == self . EMPTY ) or ( self . map [ ( r , c ) ] == self . START ) ) : #NEWLINE# #INDENT# s = np . array ( [ r , c ] ) #NEWLINE# As = self . possibleActions ( s ) #NEWLINE# terminal = self . isTerminal ( s ) #NEWLINE# Qs = representation . Qs ( s , terminal ) #NEWLINE# bestA = representation . bestActions ( s , terminal , As ) #NEWLINE# V [ ( r , c ) ] = max ( Qs [ As ] ) #NEWLINE# Mask [ ( c , r , As ) ] = False #NEWLINE# arrowColors [ ( c , r , bestA ) ] = 1 #NEWLINE# for i in xrange ( len ( As ) ) : #NEWLINE# #INDENT# a = As [ i ] #NEWLINE# Q = Qs [ i ] #NEWLINE# value = linearMap ( Q , self . MIN_RETURN , self . MAX_RETURN , 0 , 1 ) #NEWLINE# arrowSize [ ( c , r , a ) ] = value #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# self . valueFunction_fig . set_data ( V ) #NEWLINE# DX = arrowSize [ : , : , 0 ] #NEWLINE# DY = np . zeros ( ( self . ROWS , self . COLS ) ) #NEWLINE# DX = np . ma . masked_array ( DX , mask = Mask [ : , : , 0 ] ) #NEWLINE# DY = np . ma . masked_array ( DY , mask = Mask [ : , : , 0 ] ) #NEWLINE# C = np . ma . masked_array ( arrowColors [ : , : , 0 ] , mask = Mask [ : , : , 0 ] ) #NEWLINE# self . upArrows_fig . set_UVC ( DY , DX , C ) #NEWLINE# DX = ( - arrowSize [ : , : , 1 ] ) #NEWLINE# DY = np . zeros ( ( self . ROWS , self . COLS ) ) #NEWLINE# DX = np . ma . masked_array ( DX , mask = Mask [ : , : , 1 ] ) #NEWLINE# DY = np . ma . masked_array ( DY , mask = Mask [ : , : , 1 ] ) #NEWLINE# C = np . ma . masked_array ( arrowColors [ : , : , 1 ] , mask = Mask [ : , : , 1 ] ) #NEWLINE# self . downArrows_fig . set_UVC ( DY , DX , C ) #NEWLINE# DX = np . zeros ( ( self . ROWS , self . COLS ) ) #NEWLINE# DY = ( - arrowSize [ : , : , 2 ] ) #NEWLINE# DX = np . ma . masked_array ( DX , mask = Mask [ : , : , 2 ] ) #NEWLINE# DY = np . ma . masked_array ( DY , mask = Mask [ : , : , 2 ] ) #NEWLINE# C = np . ma . masked_array ( arrowColors [ : , : , 2 ] , mask = Mask [ : , : , 2 ] ) #NEWLINE# self . leftArrows_fig . set_UVC ( DY , DX , C ) #NEWLINE# DX = np . zeros ( ( self . ROWS , self . COLS ) ) #NEWLINE# DY = arrowSize [ : , : , 3 ] #NEWLINE# DX = np . ma . masked_array ( DX , mask = Mask [ : , : , 3 ] ) #NEWLINE# DY = np . ma . masked_array ( DY , mask = Mask [ : , : , 3 ] ) #NEWLINE# C = np . ma . masked_array ( arrowColors [ : , : , 3 ] , mask = Mask [ : , : , 3 ] ) #NEWLINE# self . rightArrows_fig . set_UVC ( DY , DX , C ) #NEWLINE# plt . draw ( )