Skip to content

Instantly share code, notes, and snippets.

@WhatIThinkAbout
Last active February 17, 2021 10:55
Show Gist options
  • Select an option

  • Save WhatIThinkAbout/a209e66c14369995a3329dc48dd63670 to your computer and use it in GitHub Desktop.

Select an option

Save WhatIThinkAbout/a209e66c14369995a3329dc48dd63670 to your computer and use it in GitHub Desktop.
create and test a set of sockets over a single test run
class SocketTester():
""" create and test a set of sockets over a single test run """
def __init__(self, socket=PowerSocket, socket_order=socket_order, **kwargs ):
# create supplied socket type with a mean value defined by socket order
self.sockets = [socket((q*2)+2, **kwargs) for q in socket_order]
def charge_and_update(self,socket_index):
""" charge from the chosen socket and update its mean reward value """
reward = self.sockets[socket_index].charge()
self.sockets[socket_index].update(reward)
def select_socket( self, t ):
""" choose the socket with the current highest mean reward
or arbitrarily select a socket in the case of a tie """
socket_index = random_argmax([socket.sample() for socket in self.sockets])
return socket_index
def run( self, number_of_steps ):
""" perform a single run for the defined number of steps """
for t in range(number_of_steps):
# select a socket
socket_index = self.select_socket(t)
# charge from the chosen socket and update its mean reward value
self.charge_and_update(socket_index)
@WhatIThinkAbout
Copy link
Copy Markdown
Author

WhatIThinkAbout commented Feb 17, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment