Skip to content

Instantly share code, notes, and snippets.

View huynhnguyen's full-sized avatar
🎯
Focusing

Nguyen Huynh huynhnguyen

🎯
Focusing
View GitHub Profile
@huynhnguyen
huynhnguyen / privacy_recommendation.py
Last active November 13, 2019 11:02
privacy preserving recommendation system by injecting noise
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
#annoying babel error
npm install -D babel-loader @babel/core @babel/preset-env webpack
element.append(`<button type="button"
onclick='$("div.input").toggle(1000)'
class="btn btn-primary active">toggle code</button>`)
@huynhnguyen
huynhnguyen / ldd
Last active June 9, 2017 12:07
open journal (2/6/2017)
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]))
@huynhnguyen
huynhnguyen / tank_mh.py
Last active June 1, 2017 05:57
open journal (3/15/2017): tank estimation problem with Edward
'''
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
@huynhnguyen
huynhnguyen / orthogonal_initialize_demo_code.py
Created May 24, 2017 13:01
open journal (24/5/217): orthogonal initializer for lstm with tensorflow 1.10.
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
@huynhnguyen
huynhnguyen / BayesianSearchOptimization.py
Last active September 8, 2016 07:55
Implementation for bayesian optimization with PoI acquisition function for finding the minimum point of the function
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
%% 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
@huynhnguyen
huynhnguyen / index.html
Created June 30, 2016 08:31 — forked from bellbind/index.html
[browser] drawing Japan map (with canvas)
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<script src="script.js"></script>
</head>
<body><body>
</html>