Skip to content

Instantly share code, notes, and snippets.

View jmbr's full-sized avatar

Juan M. Bello-Rivas jmbr

View GitHub Profile
@jmbr
jmbr / holder.stl
Created August 23, 2021 05:51
Holder for needle-tip plastic bottles
//$fn = 90;
diameter = 30.5;
spacing = 2;
width = 4 * spacing + 3 * diameter;
depth = 2 * spacing + diameter;
height = 20 + spacing;
difference() {
scale([0.94, 0.85, 1])
@jmbr
jmbr / double_well.py
Created May 20, 2021 21:39
Sample from a simple mixture of Gaussians
import numpy as np
from scipy.stats import rv_continuous
import matplotlib.pyplot as plt
class double_well_gen(rv_continuous):
def _pdf(self, x, mu, sigma):
sigma2 = sigma**2
return ((np.exp(-(x - mu)**2 / (2.0 * sigma2))
+ np.exp(-(x + mu)**2 / (2.0 * sigma2)))
@jmbr
jmbr / switch-to-python-buffer.el
Created April 9, 2021 18:33
Quickly switch to (or start) a Python interpreter buffer in Emacs.
(defun switch-to-python-buffer ()
"Switch to Python shell buffer quickly."
(interactive)
(let ((python-buffer (get-buffer "*Python*")))
(if python-buffer
(switch-to-buffer python-buffer)
(run-python))))
(global-set-key (kbd "C-c z") 'switch-to-python-buffer)
(global-set-key (kbd "C-c C-z") 'switch-to-python-buffer)
@jmbr
jmbr / gaussian_process_regressor_gradient.py
Last active October 18, 2021 21:49
Gradient of a Gaussian process regressor from scikit-learn
import numpy as np
from sklearn.gaussian_process import GaussianProcessRegressor
def gradient(gpr: GaussianProcessRegressor, Xstar: np.ndarray) -> np.ndarray:
"""Evaluate the gradient of a Gaussian process at a given point."""
X = gpr.X_train_
m, n = Xstar.shape[0], X.shape[0]
assert Xstar.shape[1] == X.shape[1]
Xstar_minus_X = Xstar[:, np.newaxis, :] - X[np.newaxis, :, :]
@jmbr
jmbr / pca_experiment.py
Last active April 9, 2021 15:54
The distances between points in a linear Euclidean manifold are the same before and after dimensionality reduction with principal component analysis.
import numpy as np
from sklearn.decomposition import PCA
from scipy.spatial.distance import pdist
def get_points_from_square(num_points: int, ambient_dim: int) -> np.ndarray:
"""Get points from a grid of a linear manifold (a square in this case) endowed with the Euclidean metric.
"""
aux = np.linspace(-1, 1, int(np.sqrt(num_points)))
@jmbr
jmbr / hoop.scad
Created March 23, 2021 17:03
Quarter of hoop for kitty
/*[ Radius of big circle ]*/
r0 = 150;
/*[ Radius of tube ]*/
r1 = 8; // r0/10.0;
/*[ Tolerance ]*/
rtol = 0.2;
module joint(r) {
@jmbr
jmbr / diffusion_maps.py
Last active April 13, 2021 04:07
Fast and simple computation of diffusion maps
from typing import Tuple
import numpy as np
import scipy.spatial
DEFAULT_NUM_EIGENPAIRS: int = 10 + 1
def diffusion_maps(points: np.ndarray, epsilon2: float,
@jmbr
jmbr / compute_distance_matrix.py
Created February 1, 2021 19:50
Compute RMS distances between frames in an mdtraj Trajectory object
import numpy as np
import mdtraj as md
import tqdm
def compute_distance_matrix(trajectory: md.Trajectory) -> np.ndarray:
"""Compute distance matrix.
"""
topology = trajectory.topology
@jmbr
jmbr / fig-example.gp
Created September 19, 2020 23:23
Gnuplot figure rendered in LaTeX with proper fonts and sizes
reset
load '~/gnuplot-colorbrewer/qualitative/Set2.plt' # Optional
set terminal push
set terminal epslatex size 3.22in, 2.255in
set output "fig-example.tex"
unset key
set border 3
@jmbr
jmbr / .stumpwmrc.lisp
Last active August 8, 2020 06:15
My StumpWM configuration file
;;; StumpWM initialization file.
(ql:quickload "swank")
(in-package :stumpwm)
(setf *window-border-style* :none
*resize-hides-windows* nil)
;;; Redirect output to ~/.stumpwm.d/stumpwm.log