Skip to content

Instantly share code, notes, and snippets.

@kstoneriv3
kstoneriv3 / brownian_bridge_construction.py
Created February 1, 2024 14:37
Visualization of Brownian bridge construction of a Brownian motion
"""Visualization of Brownian bridge construction of a Brownian motion."""
import numpy as np
from matplotlib import pyplot as plt
T = 1
TAB10_CMAP = plt.get_cmap("tab10")
DEFAULT_COLOR = TAB10_CMAP(0)
@kstoneriv3
kstoneriv3 / benchmark_batched_botorch.py
Created April 9, 2023 22:20
Benchmark script of batched sampling with botorch
from concurrent.futures import ProcessPoolExecutor, wait
import fire
from matplotlib import pyplot as plt
import numpy as np
import optuna
import os
import time
import torch
N_WORKERS = 10
@kstoneriv3
kstoneriv3 / halton.py
Last active January 25, 2022 15:01
`run_all.sh` runs the benchmark of `QMCSamplers` by kurobako. The performance of `QMCSampler` differs significantly when called from kurobako CUI vs when called using python script.
from kurobako import solver
from kurobako.solver.optuna import OptunaSolverFactory
import optuna
from optuna.samplers import QMCSampler
def create_study(seed):
sampler = QMCSampler(seed=seed, scramble=True, qmc_type="halton", warn_independent_sampling=False)
return optuna.create_study(sampler=sampler)
@kstoneriv3
kstoneriv3 / denoising.py
Last active April 17, 2021 14:09
(Incomplete) Reproduction of image denoising using kernel PCA in "Learning to Find Pre-Images"
import numpy
import scipy.ndimage
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import decomposition
digits = datasets.load_digits()
images = digits.images
images = map(lambda x: scipy.ndimage.zoom(x, 2, order=1), images)
@kstoneriv3
kstoneriv3 / RGS.py
Created March 9, 2021 08:13
A possibly incorrect implementation of RGS algorithm discussed in Owen, A. B. (1994). Controlling correlations in Latin hypercube samples. Journal of the American Statistical Association, 89(428), 1517-1522.
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
# centered case
def LHS(n, d):
samples = np.tile(np.arange(n, dtype=np.float64), (d, 1)).reshape(d, n)
@kstoneriv3
kstoneriv3 / RGS.py
Last active March 9, 2021 08:42
A possibly incorrect implementation of RGS algorithm discussed in Owen, A. B. (1994). Controlling correlations in Latin hypercube samples. Journal of the American Statistical Association, 89(428), 1517-1522.
#!/usr/bin/env python
# coding: utf-8
import numpy as np
import matplotlib.pyplot as plt
# centered case
def LHS(n, d):
samples = np.tile(np.arange(n, dtype=np.float64), (d, 1)).reshape(d, n)
@kstoneriv3
kstoneriv3 / hpi_evaluatior_comparison_lightgbm.py
Last active September 21, 2020 18:52
benchmark code for `MutualInformationImportanceEvaluator`
import lightgbm as lgb
import numpy as np
import pandas as pd
import sklearn.datasets
from sklearn.datasets import fetch_openml
import sklearn.metrics
from sklearn.model_selection import train_test_split
import optuna