Skip to content

Instantly share code, notes, and snippets.

@suzusuzu
suzusuzu / nsw.jl
Created Dec 13, 2020
Navigable Small World(NSW)
View nsw.jl
using Random
using LinearAlgebra
using DataStructures
using Base
mutable struct Node
data
friend::Set{Node}
end
@suzusuzu
suzusuzu / non_null_filter.ts
Created Jul 9, 2020
non null filter implementation in typescript
View non_null_filter.ts
const arr = [...Array(100).keys()];
const arr1 = arr.map(x => x*x % 2 == 0 ? x*x : null).filter((x): x is number => x !== null);
// arr1: number[]
const arr2 = arr.flatMap(x => x*x % 2 == 0 ? [x*x] : [])
// arr2: number[]
@suzusuzu
suzusuzu / stateless2stateful.ipynb
Created Dec 12, 2019
stateless2stateful.ipynb
View stateless2stateful.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View df_imagenet.jl
using Cascadia
using Gumbo
using HTTP
using JSON
using DataFrames
using Dates
using Plots
# scraping
r = HTTP.request("GET", "https://paperswithcode.com/sota/image-classification-on-imagenet")
@suzusuzu
suzusuzu / knn_universal_divergence_estimator.py
Last active Nov 21, 2019
An Implementation of Divergence Estimation for Multidimensional Densities Via k-Nearest-Neighbor Distance(https://www.princeton.edu/~kulkarni/Papers/Journals/j068_2009_WangKulVer_TransIT.pdf)
View knn_universal_divergence_estimator.py
import numpy as np
import matplotlib.pyplot as plt
from sklearn.neighbors import NearestNeighbors
def kl_d_norm(mu1, sigma1, mu2, sigma2):
d = np.log(sigma2/sigma1)
d += (sigma1**2 + (mu1 - mu2)**2) / (2 * sigma2**2)
d -= 1/2
return d
@suzusuzu
suzusuzu / horseshoe_distribution.ipynb
Last active Nov 14, 2019
Horseshoe distribution sampling
View horseshoe_distribution.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@suzusuzu
suzusuzu / 3d_gaussian_mean_shift.py
Last active Nov 11, 2019
An implementation of Gaussian Mean Shift Procedure(3d)
View 3d_gaussian_mean_shift.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from mpl_toolkits.mplot3d import Axes3D
def kde(data, sigma):
def f(x):
l = x.shape[0]
res = np.zeros(l)
for i in range(l):
@suzusuzu
suzusuzu / gaussian_mean_shift.py
Last active Nov 11, 2019
An implementation of Gaussian Mean Shift Procedure
View gaussian_mean_shift.py
import numpy as np
import matplotlib.pyplot as plt
from scipy.stats import gaussian_kde
import matplotlib.animation as animation
def gaussian_kernel(x, sigma):
return 1 / (np.sqrt(2*np.pi)*sigma) * np.exp(-(x**2)/(2*(sigma**2)))
def x_update(x, xi, sigma):
return np.sum(gaussian_kernel(xi - x, sigma) * x) / np.sum(gaussian_kernel(xi - x, sigma))
View purecmaes.py
import numpy as np
def rosenbrock(x):
end = x.shape[0]
a = 100.0
b = 1.0
return np.sum(a * np.power((x[1:] - np.power(x[:end-1], 2)), 2) + np.power((x[:end-1] - b), 2))
def cmaes(dim, f):
# User defined parameters
@suzusuzu
suzusuzu / higher_order_svd.ipynb
Last active Nov 4, 2019
Higher Order SVD(HOSVD)
View higher_order_svd.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.