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
import numpy as np | |
from matplotlib import pylab as plt | |
#from mpltools import style # uncomment for prettier plots | |
#style.use(['ggplot']) | |
# generate all bernoulli rewards ahead of time | |
def generate_bernoulli_bandit_data(num_samples,K): | |
CTRs_that_generated_data = np.tile(np.random.rand(K),(num_samples,1)) | |
true_rewards = np.random.rand(num_samples,K) < CTRs_that_generated_data | |
return true_rewards,CTRs_that_generated_data |
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
import numpy as np | |
from sklearn.feature_extraction import image | |
from sklearn.cluster import MiniBatchKMeans | |
from sklearn import cross_validation, svm, datasets | |
from sklearn.datasets import fetch_olivetti_faces, fetch_mldata | |
from matplotlib import pylab as pl | |
def HIK_kernel(X,Y): | |
return np.array([[np.sum(np.minimum(x,y)) for y in Y] for x in X]) | |
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
from scipy.stats import rv_continuous | |
from scipy.special import gammaln, gammaincinv, gammainc | |
from numpy import log,exp | |
class igamma_gen(rv_continuous): | |
def _pdf(self, x, a, b): | |
return exp(self._logpdf(x,a,b)) | |
def _logpdf(self, x, a, b): | |
return a*log(b) - gammaln(a) -(a+1)*log(x) - b/x | |
def _cdf(self, x, a, b): |
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
import numpy as np | |
import matplotlib.pyplot | |
mu, sigma = 3., 1. # mean and standard deviation | |
s = np.random.lognormal(mu, sigma, 10000) | |
log_s = np.log(s) | |
subplot(211) | |
count,bins,_ = hist(s, 100, normed=True, align='mid') | |
x = np.linspace(min(bins), max(bins), 10000) | |
pdf = (np.exp(-(np.log(x) - mu)**2 / (2 * sigma**2)) / (x * sigma * np.sqrt(2 * np.pi))) |
NewerOlder