22 Aug 2016 - This is a post on my blog.
I recently released slots, a Python library that implements multi-armed bandit strategies. If that sounds like something that won't put you to sleep, then please pip install slots and read on.
| import gym | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| env = gym.make('CartPole-v0') | |
| env.render(close=True) | |
| #vector of means(mu) and standard dev(sigma) for each paramater | |
| mu=np.random.uniform(size=state.shape) | |
| sigma=np.random.uniform(low=0.001,size=state.shape) | |
| """Calculate the probability of generating a duplicate random number after | |
| generating "n" random numbers in the range "d". | |
| Usage: python birthday_probability.py n [d=365] | |
| Each value can either be an integer directly, or in the format "2**x", where | |
| x is the number of bits in the value. | |
| For example, to calculate the probability that two people will have the same | |
| birthday in a room with 23 people: |
| """Calculate the average number of moves in a snakes and ladders game. | |
| Because as a parent one gets roped into these board (boring?) games | |
| every so often, and I wanted to calculate the average duration of a | |
| snakes and ladders game. Turns out it's about 36 moves (though | |
| admittedly that's for a single-player game). :-) | |
| > python snakes_and_ladders.py | |
| Played 10000 rounds, averaged 36.0559 moves, max 324 moves, took 0.508s | |
| """ |
Find the Discord channel in which you would like to send commits and other updates
In the settings for that channel, find the Webhooks option and create a new webhook. Note: Do NOT give this URL out to the public. Anyone or service can post messages to this channel, without even needing to be in the server. Keep it safe!
| """Test how many threads we can run at once.""" | |
| import itertools | |
| import threading | |
| import time | |
| import sys | |
| import requests | |
| """Embed a YouTube video via its embed url into a notebook.""" | |
| from functools import partial | |
| from IPython.display import display, IFrame | |
| width, height = (560, 315, ) | |
| def _iframe_attrs(embed_url): | |
| """Get IFrame args.""" | |
| return ( |
| import numpy as np | |
| from numpy.random import uniform | |
| def update(S, k, v): | |
| "Update value position `k` in time O(log n)." | |
| d = S.shape[0] | |
| i = d//2 + k | |
| S[i] = v | |
| while i > 0: |
| Name | t | |
|---|---|---|
| Jovan | 0.143522377788 | |
| Wilford | 0.171813290491 | |
| Newton | 0.192343843426 | |
| Maurice | 0.193607112432 | |
| Emmanuel | 0.20571087052 | |
| Joseph | 0.210762071958 | |
| Milton | 0.21296788724 | |
| Ahmad | 0.214983745995 | |
| Julius | 0.218052193228 |
| #!/usr/bin/env xdg-open | |
| [Desktop Entry] | |
| Type=Application | |
| Name=Marp | |
| GenericName=Marp - Markdown Presentation Editor | |
| Icon=/home/lilian/.local/Marp/marp.png | |
| Exec=/home/lilian/.local/Marp/Marp %f | |
| Categories=Office | |
| Terminal=false |