Skip to content

Instantly share code, notes, and snippets.

@jcboyd
jcboyd / svm-visualisation.py
Created April 29, 2024 04:12
SVM margin visualisation
import matplotlib.pyplot as plt
import numpy as np
from numpy.random import multivariate_normal
np.random.seed(100)
num_samples = 20
X = np.concatenate((
multivariate_normal(mean=np.array([2, 2]),
@jcboyd
jcboyd / coding_an_svm.ipynb
Created April 29, 2024 04:06
Coding an SVM
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcboyd
jcboyd / slic.py
Created March 27, 2024 11:59
The SLIC superpixel algorithm
import matplotlib.pyplot as plt
import numpy as np
from skimage import data
from skimage.measure import find_contours
from skimage.color import rgb2rgbcie
img = data.astronaut()
img_cie = rgb2rgbcie(img)
@jcboyd
jcboyd / harris_visualisation.py
Created February 13, 2024 06:46
Visualisation of Harris detector
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.patches import Circle, Rectangle, FancyArrowPatch
import matplotlib.lines as mlines
from scipy.ndimage import gaussian_filter
@jcboyd
jcboyd / subset_sum.py
Created February 10, 2024 06:23
Dynamic programming algorithm for subset sum
"""Two tricks enable an efficient solution:
2. We can solve the problem for the first i numbers in the list, for
i = 1, ..., N
1. The range of possible sums, R is bounded by an efficiently computable
min_sum and max_sum.
The lookup table is thus of dimension N x R. For each subset i = 1, ..., N,
we determine the range of values attainable with that subset, which are
simply all the targets of subset i - 1, plus nums[i] (included), and plus 0
(not included). Thus, we perform only R operation per N subsets.
"""
@jcboyd
jcboyd / eratosthenes.tex
Created January 30, 2024 08:22
Sieve of Eratosthenes with tikz
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\def\primes{2,3,5,7,11,13,17,19,23}
\def\revprimes{23,19,17,13,11,7,5,3,2}
\def\palette{{
"0.00 0.00 1.00",
@jcboyd
jcboyd / metropolis-hastings.ipynb
Created January 15, 2023 15:55
Metropolis-Hastings algorithm
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jcboyd
jcboyd / pca.ipynb
Created October 15, 2022 11:01
PCA residual plot
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from __future__ import print_function
from __future__ import division
import io
import random
import numpy as np
from PIL import Image
from skimage.transform import resize
import quantumrandom # https://qrng.anu.edu.au/