Skip to content

Instantly share code, notes, and snippets.

View kwinkunks's full-sized avatar
🐍
Writing bugs

Matt Hall kwinkunks

🐍
Writing bugs
View GitHub Profile
@kwinkunks
kwinkunks / fornberg.py
Created December 13, 2023 11:55
Bengt Fornbeg weights for finite difference
import numpy as np
def weights(z, x, m=0):
"""
Fornberg finite difference weights.
F90: https://github.com/bjodah/finitediff/blob/master/src/finitediff_fort.f90
Made this for Advent of Code 2023, Day 9.
Arguments:
@kwinkunks
kwinkunks / Modulate_colourmap_with_opacity.ipynb
Last active October 26, 2023 09:12
Combining maps with matplotlib, by mapping one with a colourmap and the other with opacity.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Should_you_scale_the_target_in_regression_tasks.ipynb
Created July 31, 2023 13:29
When, if ever, should you scale the target in a regression task?
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / dtw.md
Created April 16, 2023 21:40
Dynmic time (or whatever!) warping libraries
@kwinkunks
kwinkunks / Unmapping.ipynb
Created March 20, 2023 06:50
Unmapping colours from pseudocolour images
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / docstrings_and_doctests.py
Last active March 8, 2023 15:52
*Docstrings* and *doctests* are nice ways to get started with the topics of documentation and testing. The idea is to write the string that shows up when you do `help(some_function)` and in particular to include examples of how to call your function. The beautiful thing is that we can check that those examples work as advertised, a very useful …
def has_illegal_chars(string: str, illegal: str = ',;"!+=') -> bool:
"""
Detect the presence of illegal characters in a string.
By default, illegal characters are: `,;"!+=`
Args:
string: A string of text of any length.
illegal: A sequence of characters that are not allowed.
Returns:
@kwinkunks
kwinkunks / Mis-steps_in_machine_learning.ipynb
Created January 19, 2023 09:20
A notebook showing a simple data science exploration, but with mis-steps for discussion and teaching purposes
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / Image_grid.py
Created October 16, 2022 13:01
Reshape a 4D array into a image grid
"""
Given a 4D array of shape (n, h, w, c) representing n images of shape (h, w, c),
make a single image consisting of a regular grid of smaller images.
License: MIT No attribution
"""
import numpy as np
def reshape(arr, rows, cols, pixels=False):
"""Reshapes a 4D array into a grid of images.
@kwinkunks
kwinkunks / Recover_data_with_known_colourmap.ipynb
Last active September 14, 2022 14:39
Demo of recovering data from an image with a known colourmap. Thank you to David Johnstone (Manchester) for the data example.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kwinkunks
kwinkunks / sdhe.py
Last active June 29, 2022 17:19
Confidence analysis of standard deviational ellipse and its extension into higher dimensional Euclidean space
# Properties of the scaled standard deviational hyperellipsoid.
#
# Author: Matt Hall, kwinkunks@gmail.com
# Copyright: 2022, Matt Hall
# Licence: Apache 2.0, https://www.apache.org/licenses/LICENSE-2.0
#
# These small functions implement n-dimensional lookup of the beta-distribution
# approximation to this problem. They answer the questions, "What proportion
# of a multivariate Gaussian distribution is contained by `r` standard
# deviations?" and "How many standard deviations contain a proportion `p` of