Created
June 9, 2020 17:37
-
-
Save WhatIThinkAbout/1d7ddfefe560a5af3b31a700fa7f9558 to your computer and use it in GitHub Desktop.
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 UCBSocketTester( SocketTester ): | |
| def __init__(self, socket_order, confidence_level = 2.0 ): | |
| super().__init__(socket_order) # create a standard socket tester | |
| self.confidence_level = confidence_level # save the confidence_level | |
| def ucb(self, Q, t, n): | |
| if n == 0: return float('inf') | |
| return Q + self.confidence_level * (np.sqrt(np.log(t) / n)) | |
| def select_socket( self, t ): | |
| """ UCB Socket Selection""" | |
| # choose the socket with the current highest mean reward | |
| return random_argmax([self.ucb(socket.Q, t, socket.n) for socket in self.sockets]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment