Homework - 0: - MD Aamir Sohail - EE16BTECH11021 - AI5001: Introduction To Modern AI CODE: Q.5 ( - Greedy Method)
Homework - 0: - MD Aamir Sohail - EE16BTECH11021 - AI5001: Introduction To Modern AI CODE: Q.5 ( - Greedy Method)
Homework - 0: - MD Aamir Sohail - EE16BTECH11021 - AI5001: Introduction To Modern AI CODE: Q.5 ( - Greedy Method)
• MD AAMIR SOHAIL
• EE16BTECH11021
• AI5001: Introduction to Modern AI
1
59
60 # Updating count o f t h e s e l e c t e d a c t i o n
61 N t [ index ] [ task ] = N t [ index ] [ task ] + 1
62 # Updating Action−v a l u e e s t i m a t e o f t h e s e l e c t e d a c t i o n
63 Q[ i n d e x ] [ t a s k ] = Q[ i n d e x ] [ t a s k ] + ( reward − Q[ i n d e x ] [ t a s k ] ) / N t [ i n d e x ] [ t a s k ]
64
65 # a v e r a g e o v e r 2000 t a s k s
66 avg R = np . mean (R)
67 e p s i l o n a v g . append ( avg R ) # S t e p s no . o f e l e m e n t s
68
69 p r i n t ( ’ Done e p s i l o n ’ )
70 plt . plot ( epsilon avg )
71
72 p l t . r c ( ’ t e x t ’ , u s e t e x=True )
73
74 p l t . x l a b e l ( ’ Steps ’ )
75 p l t . y l a b e l ( ’ Average Reward ’ )
76 p l t . l e g e n d ( [ r ” $ \ e p s i l o n=$ ”+s t r ( e p s i l o n [ 0 ] ) , r ” $ \ e p s i l o n=$ ”+s t r ( e p s i l o n [ 1 ] ) , r ” $ \ e p s i l o n=$ ”+s t r
( e p s i l o n [ 2 ] ) ] , l o c= ’ l o w e r r i g h t ’ , prop={ ’ s i z e ’ : 1 6 } )
77 p l t . t i t l e ( r ” $ \ e p s i l o n $ −g r e e d y a l g o r i t h m : 10−armed b a n d i t t e s t b e d ( Average o v e r 2000 t a s k s ) ”
)
78 p l t . show ( )
2
Figure 2: Average Reward vs Steps ( = 3000)
OBSERVATIONS:
• -Greedy approach eventually performs better than Greedy approach.
• For the first ∼ 100 steps, Greedy method improved faster but stuck with a sub-optimal action.
• = 0.01-Greedy approach improves slowly but after some experience performs better than = 0.10-
Greedy approach (see Figure 2)
3
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner