Skip to content

Instantly share code, notes, and snippets.

View leifvan's full-sized avatar

Leif Van Holland leifvan

View GitHub Profile
@leifvan
leifvan / python_format_cheat_sheet.md
Last active October 18, 2018 08:15
Overview of the str.format() mini-language, taken from https://docs.python.org/3/library/string.html#formatspec.

Python Format Cheat Sheet

format_spec     ::=  [[fill]align][sign][#][0][width][grouping_option][.precision][type]
fill            ::=  <any character>
align           ::=  "<" | ">" | "=" | "^"
sign            ::=  "+" | "-" | " "
width           ::=  digit+
grouping_option ::=  "_" | ","
precision       ::=  digit+
type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
@leifvan
leifvan / elmo-pooling-issue.ipynb
Created September 28, 2019 12:18
ELMo pooling issue
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@leifvan
leifvan / matern_for_int_and_categorical.py
Last active November 24, 2022 05:14
A wrapper for the `sklearn.gaussian_process.kernels.Matern` kernel that implements the kernel-level transformation of parameters as described by Garrido-Merchán and Hernández-Lobato in "Dealing with Categorical and Integer-valued Variables in Bayesian Optimization with Gaussian Processes"
import numpy as np
from sklearn.gaussian_process.kernels import Matern
from collections import defaultdict
class WrappedMatern(Matern):
def __init__(self, param_types, length_scale=1.0, length_scale_bounds=(1e-5, 1e5), nu=1.5):
self.param_types = param_types
super(WrappedMatern, self).__init__(length_scale, length_scale_bounds, nu)
def _transform(self, X):