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.linalg import circulant | |
def solve_circulant(A,b): | |
return np.fft.ifft(np.fft.fft(b)/np.fft.fft(A[:,0])) | |
n = 10000 | |
a = np.random.randn(1,n) | |
A = circulant(a) | |
b = np.random.rand(n) |
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
\documentclass{article} | |
\usepackage{algorithm} | |
\usepackage{minted} | |
\begin{document} | |
\begin{algorithm} | |
\vspace{0.2em} | |
\begin{minted}[xleftmargin=1em, numbersep=6pt, linenos, breaklines]{python} | |
def fib(n): | |
"""This function calculates the n-th Fibonacci number.""" |
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 argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('arg1') | |
parser.add_argument('--arg2', default=0.1, type=float) | |
args = parser.parse_args() | |
print(args.arg1) | |
print(args.arg2) |
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
def check_triangle_inequality(D): | |
""" Returns true iff the matrix D fulfills | |
the triangle inequaltiy. | |
""" | |
n = len(D) | |
valid = True | |
for i in range(n): | |
for j in range(i, n): | |
for k in range(n): | |
if k == j or k == i: |
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 | |
import matplotlib | |
# ugly hack to embed fonts | |
matplotlib.rc("pdf", fonttype=42) | |
edgecolor = "black" | |
bar_scale = 0.8 |
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 pickle | |
r = [1, 2, 3] | |
pickle.dump(r, open('r.file', mode='wb')) | |
r = pickle.load(open('r.file', mode='rb')) |
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 | |
import torch.optim as optim | |
import matplotlib.pyplot as plt | |
# 2d Rosenbrock function | |
def f(x): | |
return (1 - x[0])**2 + 100 * (x[1] - x[0]**2)**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
class GMM(torch.nn.Module): | |
def __init__(self, n, d=2, k=2): | |
super(GMM, self).__init__() | |
self.d = d | |
self.k = k | |
self.n = n | |
self.covs = torch.eye(self.d).view(-1, self.d, self.d).repeat(self.k,1,1) | |
self.mus = torch.zeros(n, k) | |
self.member = torch.zeros(n, k) |