Skip to content

Instantly share code, notes, and snippets.

@talesa
talesa / plot_uncertainties.py
Last active May 22, 2018 17:04
Plot with vertical uncertainties using Seaborn
import seaborn as sns
import pandas as pd
data = pd.DataFrame(columns=["tolerance", "baseline", "run_no", "value"])
for baseline_true, table in zip([True, False], [baseline, no_baseline]):
for tol, row in zip(x, table):
for run_no, val in zip(range(len(row)), row):
data.loc[len(data)] = [tol, baseline_true, run_no, val]
@talesa
talesa / dynamic_plotting.py
Created May 8, 2018 12:55 — forked from greydanus/dynamic_plotting.py
Dynamic plotting for matplotlib
"Dynamic plotting in matplotlib. Copy and paste into a Jupyter notebook."
# written October 2016 by Sam Greydanus
%matplotlib notebook
import matplotlib.pyplot as plt
import numpy as np
import time
def plt_dynamic(x, y, ax, colors=['b']):
for color in colors:
ax.plot(x, y, color)

SSH agent forwarding and screen

When connecting to a remote server via SSH it is often convenient to use SSH agent forwarding so that you don't need a separate keypair on that server for connecting to further servers.

This is enabled by adding the

ForwardAgent yes

option to any of your Host entries in ~/.ssh/config (or alternatively with the -A option). Don't set this option in a wildcard Host * section since any user on the remote server that can bypass file permissions can now als use keys loaded in your SSH agent. So only use this with hosts you trust.

@talesa
talesa / sacred_issue.md
Last active January 11, 2019 14:48
sacred issue

I am far from certain about the cause of the issue.

The symptoms are as follows (I haven't gathered extensive evidence yet, because I'm just setting up and testing sacred for the first time):

  • the start of the experiment is always logged
  • sometimes some heartbeats are sent at the beginning (because the stdout capture and metrics are showing up)
  • then they stop (stdout capture and metrics are not updated, and the experiment has 'Probably dead' status in sacredboard)
  • sometimes they show up again for a while (tens of minutes later, much more than what I would expect to see as reasonable delay)
  • and then they usually disappear again
  • when the experiment completes the appropriate event is sent to the database (and experiment is marked as completed in sacredboard), but the script freezes after the final message INFO - experiment_name - Completed after 0:14:29 and takes ages to finish (same as #273)
  • if I let the frozen script finish the output capture and metrics are collected
@talesa
talesa / gmm.py
Last active January 4, 2019 14:46
GMM model sampling and log_pdf in PyTorch
import torch
import torch.distributions as dist
# Generates a sample from the generative model
def gmm_generate_data(K, N, batch_size=10,
upsilon=torch.Tensor([2.]).to('cpu'),
mu_0=torch.Tensor([0., 0.]).to('cuda'),
sigma2_0=torch.Tensor([2., 2.]).to('cuda')):
# Sample parameters to distribution over mixture components
@talesa
talesa / online_mean_variance.py
Created January 14, 2019 14:54
online mean & variance estimators
class OnlineStats:
# https://www.johndcook.com/blog/standard_deviation/
# Knuth TAOCP vol 2, 3rd edition, page 232
def __init__(self):
self.n = 0
def push(self, x):
self.n += 1
@talesa
talesa / author_list_to_pairs.py
Last active April 4, 2019 22:21
Code for Ewa Siwicka 04/04/2019
filename = 'Network-publishing-database2_short2.csv'
import csv
import itertools
import numpy as np
with open(filename, newline='') as csvfile:
rows = csv.reader(csvfile)
rows = [[i for i in row if i!=''] for row in rows]
@talesa
talesa / run_experiments.py
Created April 9, 2019 23:12
runs experiments when the previous one is finished
import multiprocessing
import subprocess
import os
def init(queue):
global gpuid
gpuid = queue.get()
gpus_list = list(range(8))
num_gpus = len(gpus_list)
t = (1, 2, [30, 40])
t[2] += [50, 60]
print(t)
# Options:
# a) t becomes (1, 2, [30, 40, 50, 60]).
# b) TypeError is raised with the message 'tuple' object does not support item assignment.
# c) Neither.
# d) Both a and b.
class OrthogonalLinear(nn.Module):
""" Implements a non-square linear with orthogonal colums """
def __init__(self, input_size, output_size, lr_factor=0.1):
super(OrthogonalLinear, self).__init__()
self.input_size = input_size
self.output_size = output_size
self.max_size = max(self.input_size, self.output_size)
self.log_orthogonal_kernel = nn.Parameter(torch.Tensor(self.max_size, self.max_size))
self.log_orthogonal_kernel.register_hook(lambda: print("This should not be executed"))