This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
import pstats | |
import io | |
def profile(file_path=None, breakpoint_after_call=False): | |
"""decorator for runtime profiling of functions or class methods | |
prints the profiling statistics sorted by | |
cumulative time, | |
total time, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fswatch ~/repo/ -o | xargs -I {} rsync -avzhe ssh ~/repo/ server:/home/user/repo/ --delete --exclude "venv/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from scipy.stats import chi2_contingency | |
# example data taken from | |
# https://en.wikipedia.org/wiki/Chi-squared_test#Example_chi-squared_test_for_categorical_data | |
X = np.array([ | |
[90, 60, 104, 95], | |
[30, 50, 51, 20], | |
[30, 40, 45, 35], | |
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from torchvision.datasets import MNIST | |
import numpy as np | |
def data(train): | |
mnist = MNIST(root='.', download=True, train=train) | |
X = mnist.data.numpy().reshape(-1, 784) / 255 | |
y = mnist.targets.numpy() | |
return X, y | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.kernel_approximation import Nystroem | |
from sklearn.cluster import MiniBatchKMeans | |
# dot in the middle | |
X = np.random.randn(100, 2) | |
# circle around | |
Y = X / np.sqrt((X**2).mean(1, keepdims=True)) * 8 | |
Y = Y + np.random.randn(100, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy | |
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
import matplotlib.pyplot as plt | |
from torchvision.datasets import MNIST | |
from torch.utils.data import DataLoader | |
import torchvision.transforms as T | |
from einops import rearrange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import queue | |
from random import randint | |
from random import seed | |
from random import uniform | |
from typing import NamedTuple | |
class Item(NamedTuple): | |
id: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
from joblib import Parallel, delayed | |
def compose2(f, g): | |
return lambda x: g(f(x)) | |
def compose(*fs): | |
return functools.reduce(compose2, fs) | |
def pipe(x, *fs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch.nn as nn | |
class Residual(nn.Module): | |
def __init__(self, dim): | |
super().__init__() | |
self.layer = nn.Sequential( | |
nn.Conv2d(dim, dim, 7, 1, 3, groups=dim), | |
nn.BachNorm2d(dim), | |
nn.Conv2d(dim, dim*4, 1), | |
nn.ReLU(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ubuntu:20.04 | |
ARG DEBIAN_FRONTEND=noninteractive | |
RUN apt-get update; apt-get upgrade -y | |
RUN apt-get install -y emacs vim r-base r-base-dev libcurl4-openssl-dev | |
ARG DOWNLOAD_STATIC_LIBV8=1 | |
RUN R -e 'install.packages("rstan")' |
OlderNewer