Skip to content

Instantly share code, notes, and snippets.

import shelve
def save_scope(session_id='default'):
filename = f'/tmp/{session_id}.out'
shelf = shelve.open(filename, 'n')
for name in dir():
try:
shelf[name] = globals()[name]
except Exception as e:
@lhk
lhk / environment.yml
Created September 19, 2019 09:30
conda eval_env yml
name: eval_env
channels:
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- asn1crypto=0.24.0=py36_0
- attrs=19.1.0=py36_1
- backcall=0.1.0=py36_0
- blas=1.0=mkl
- bleach=3.1.0=py36_0
-- a bit of subsampling, to make the size more manageable
-- I'm using the first N events, ordered by timestamp
-- this way, the learning traces should not be interrupted.
drop table if exists smaller;
create table smaller
as
select *
from log
order by timestamp
limit 20000000;
@lhk
lhk / mh.py
Created June 14, 2018 18:28
multi-dim metropolis hastings in python
# coding: utf-8
import numpy as np
from scipy.stats import multivariate_normal
def metropolis_hastings(f, num_samples, burn_in, result_queue=None):
# sample normal values as stepsize for the updates
# important: g is symmetric, so we don't have to use it in the calculation of alpha below
steps = np.random.normal(0, 1, (num_samples, 2))
@lhk
lhk / firebase_rest
Last active October 19, 2017 20:32
import json
import requests
data = {"song_id": "sjrt56usng",
"author_id": "spdfhu",
"song_name": "best song ever",
"artist_name": "onehitwonder",
"voters": {
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
@lhk
lhk / tf_numerical_diff.ipynb
Created June 9, 2017 16:39
Tensorflow, including numerical derivative into graph
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@lhk
lhk / seven.ipynb
Created November 22, 2016 12:08
numpy array features
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.