Last active
July 20, 2020 13:54
-
-
Save WhatIThinkAbout/da6fd5361ab34e454a496d8beb07fbbe to your computer and use it in GitHub Desktop.
Socket tester class for Epsilon-Greedy algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class EpsilonGreedySocketTester( SocketTester ): | |
| def __init__(self, epsilon = 0. ): | |
| # create a standard socket tester | |
| super().__init__() | |
| # save the probability of selecting the non-greedy action | |
| self.epsilon = epsilon | |
| def select_socket( self, t ): | |
| """ Epsilon-Greedy Socket Selection""" | |
| # probability of selecting a random socket | |
| p = np.random.random() | |
| # if the probability is less than epsilon then a random socket is chosen from the complete set | |
| if p < self.epsilon: | |
| socket_index = np.random.choice(self.number_of_sockets) | |
| else: | |
| # choose the socket with the current highest mean reward or arbitrary select a socket in the case of a tie | |
| socket_index = random_argmax([socket.sample() for socket in self.sockets]) | |
| return socket_index |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment