Skip to content

Instantly share code, notes, and snippets.

View ferrine's full-sized avatar

Maxim Kochurov ferrine

View GitHub Profile
@ferrine
ferrine / convolution_matrix.py
Last active October 4, 2018 19:49
Convert 2d convolution kernel into linear operator over vectorized image
import numpy as np
import itertools
def Amat(kernel, size):
assert kernel.shape[0] == kernel.shape[1]
ksize = kernel.shape[0]
assert ksize % 2
osize = (size + 1 - ksize)
A = np.zeros((osize ** 2, size ** 2))
pos = lambda _1, _2, s: _1 * s + _2
@ferrine
ferrine / model_check_test_point.ipynb
Last active November 3, 2018 10:37
Horseshoe prior fail
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ferrine
ferrine / svdn.py
Last active September 16, 2019 12:11
multidimensional svd pytorch
import itertools
import torch
def svd(x):
# https://discuss.pytorch.org/t/multidimensional-svd/4366/2
batches = x.shape[:-2]
if batches:
n, m = x.shape[-2:]
k = min(n, m)
@ferrine
ferrine / fft.ipynb
Created November 28, 2018 13:16
FFT study
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ferrine
ferrine / benchmarks-0.4.1.ipynb
Created January 27, 2019 20:46
geoopt-stiefel-benchmark
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ferrine
ferrine / nested_map.py
Created April 2, 2019 09:04
solution to catalyst fp16 forward
import torch
def map_nested(fn, structure, cond=lambda obj: isinstance(obj, torch.Tensor)):
r"""
Applies fn to an object in a possibly nested data structure and returns same
structure with every element changed if condition satisfied.
"""
def inner_map(obj):
if cond(obj):
return fn(obj)
@ferrine
ferrine / network_builder.py
Last active September 28, 2024 18:48
Pytorch models from yaml files
import torch.nn
import collections
class Builder(object):
def __init__(self, *namespaces):
self._namespace = collections.ChainMap(*namespaces)
def __call__(self, name, *args, **kwargs):
try:
return self._namespace[name](*args, **kwargs)
@ferrine
ferrine / tensorboard_observer.py
Created April 11, 2019 11:46
Tensorboard sacred observer
import sacred.observers
import tensorboardX
import os
class TensorboardObserver(sacred.observers.FileStorageObserver, tensorboardX.SummaryWriter):
VERSION = "TensorboardObserver-0.0.1"
def __init__(self, basedir, resource_dir=None, source_dir=None,
template=None, priority=sacred.observers.file_storage.DEFAULT_FILE_STORAGE_PRIORITY,
@ferrine
ferrine / playground.ipynb
Last active May 5, 2019 23:18
pymc4 playground
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.