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))) |
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 | |
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
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 | |
class Data_generator(object): | |
def __init__(self,K,d,reward_type='binary'): | |
self.d = d # dimension of the feature vector | |
self.K = K # number of bandits | |
self.reward_type = reward_type |
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
''' | |
Based on: https://gist.github.com/bshillingford/6259986edca707ca58dd | |
Modified to work on Windows by: Sergey Feldman | |
Jan 17, 2016 | |
Requirements: pdflatex, bibtex | |
''' | |
import requests | |
import lxml.html as html |
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 scipy.spatial.distance import pdist, squareform | |
# function that converts categorical variable | |
# into a one-hot encoding | |
def one_hot_encoding(x): | |
n = len(x) | |
min_category = np.min(x) | |
max_category = np.max(x) | |
num_categories = max_category - min_category + 1 |
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 | |
def f_of_x(X,w): | |
n,d = X.shape | |
X_dot_w = np.dot(X,w) | |
y = np.zeros(n) | |
# the inner product goes through a sin | |
# or a cos, depending on simple condition | |
cos_flag = X[:,0] < 0.0 | |
sin_flag = ~cos_flag |
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 matplotlib.pyplot as plt | |
import numpy as np | |
import seaborn | |
from keras.layers import Input, Dense, merge, ELU, Dropout | |
from keras.models import Model | |
from keras.regularizers import l2 | |
from keras import backend as K | |
from keras.optimizers import rmsprop, adam |
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 | |
# the function | |
def f_of_x(X, w): | |
n,d = X.shape | |
X_dot_w = np.dot(X,w) | |
y = np.zeros(n) | |
# the inner product randomly goes through a sin | |
# or a cos | |
cos_flag = np.random.randn(n) < 0.0 |
OlderNewer