This file contains 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
print('install splotlight if needed') | |
#!pip install git+https://github.com/maciejkula/spotlight.git@master#egg=spotlight | |
# # movielense data | |
# - Download the 100k version from https://grouplens.org/datasets/movielens/ | |
# - extract to folder './ml-100k/' | |
import numpy as np | |
from spotlight.interactions import Interactions |
This file contains 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
#annoying babel error | |
npm install -D babel-loader @babel/core @babel/preset-env webpack |
This file contains 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
element.append(`<button type="button" | |
onclick='$("div.input").toggle(1000)' | |
class="btn btn-primary active">toggle code</button>`) |
This file contains 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
p = np.random.randint(0,10,[n_topics, n_words])*1.0 | |
sum_over_topic = np.sum(p, axis=1) | |
dists = np.divide(p.T,sum_over_topic).T | |
n_topics = 3 | |
n_words = 10 | |
docs_topic = [0, 1, 2, 2, 1, 2, 0, 1, 2] | |
docs = [] | |
for d_topic in docs_topic: | |
_pvals = dists[d_topic] | |
# print(np.sum(_pvals[:,-1])) |
This file contains 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
''' | |
This is the edward implementation of German tank problem | |
link: https://en.wikipedia.org/wiki/German_tank_problem | |
''' | |
from __future__ import absolute_import | |
from __future__ import division | |
from __future__ import print_function | |
import edward as ed | |
import numpy as np |
This file contains 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 orthogonal_initializer(scale=1.0, seed=None, dtype=tf.float32): | |
def _initializer(shape, dtype=dtype, partition_info=None): | |
flat = (shape[0], np.prod(shape[1:])) | |
a = np.random.normal(0.0, 1.0, flat) | |
u, _, v = np.linalg.svd(a, full_matrices=False) | |
q = (u if u.shape == flat else v).reshape(shape) | |
return tf.constant(scale * q[:shape[0], :shape[1]], dtype=dtype) | |
return _initializer |
This file contains 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 import minimum,maximum | |
from scipy.optimize import minimize | |
import time | |
from sklearn.gaussian_process import GaussianProcess | |
from scipy.stats import norm,entropy | |
Bounds = [[-16,16]] | |
#target function | |
def f(x): | |
y = x**2*np.sin(x) | |
return y |
This file contains 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
%% Baseball Batting Average Shrinkage Estimates | |
% Reproduce example from | |
% "Data Analysis Using Stein's Estimator and its Generalizations" | |
% Bradley Efron; Carl Morris JASA Vol. 70, No. 350. (Jun., 1975), pp. | |
% 311-319. | |
%% Data | |
% 1970 batting averages for 18 major league players. | |
% first column = batting average for first 45 at bats | |
% 2nd column = batting everage for remainder of season |
This file contains 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<script src="script.js"></script> | |
</head> | |
<body><body> | |
</html> |