Skip to content

Instantly share code, notes, and snippets.

Avatar

Conor conormm

View GitHub Profile
View finetune_cnn_dogbreeds.py
import torch
import torch.nn as nn
import torch.nn.functional as F
import numpy as np
from torch.utils.data import Dataset, DataLoader, SubsetRandomSampler
from torchvision.datasets.folder import ImageFolder, default_loader
from torchvision.datasets.utils import check_integrity
from torchvision import transforms
from torchvision import models
import matplotlib.pyplot as plt
View concrete_dropout.py
# usr/bin/env python3
# author: Conor McDonald
# torch==0.4.1
# numpy==1.14.3
import torch
import torch.nn as nn
import torch.nn.functional as F
View thompsonsamper.py
class ThompsonSampler(BaseSampler):
def __init__(self, env):
super().__init__(env)
def choose_k(self):
# sample from posterior (this is the thompson sampling approach)
# this leads to more exploration because machines with > uncertainty can then be selected as the machine
self.theta = np.random.beta(self.a, self.b)
# select machine with highest posterior p of payout
View egreedy.py
class eGreedy(BaseSampler):
def __init__(self, env, n_learning, e):
super().__init__(env, n_learning, e)
def choose_k(self):
# e% of the time take a random draw from machines
# random k for n learning trials, then the machine with highest theta
self.k = np.random.choice(self.variants) if self.i < self.n_learning else np.argmax(self.theta)
View RandomSampler.py
class RandomSampler(BaseSampler):
def __init__(self, env):
super().__init__(env)
def choose_k(self):
self.k = np.random.choice(self.variants)
return self.k
View bandits_boilerplate.py
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
from scipy.stats import beta
sns.set_style("whitegrid")
class Environment:
def __init__(self, variants, payouts, n_trials, variance=False):
View gist:996d8899049d3c09c048c185b7e70e09
#%load_ext cythonmagic
#%cython
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set_style("whitegrid")
get_ipython().run_line_magic('matplotlib', 'inline')
View agent_environment.py
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
sns.set_style("whitegrid")
get_ipython().run_line_magic('matplotlib', 'inline')
from IPython.core.display import display, HTML
View bandits.py
# coding: utf-8
# In[150]:
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
View vvery_simple_linear_regression.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
You can’t perform that action at this time.