Skip to content

Instantly share code, notes, and snippets.

View maedoc's full-sized avatar

marmaduke woodman maedoc

  • now
  • here
View GitHub Profile
@maedoc
maedoc / np_tf_bench.py
Created November 26, 2020 09:49
Benchmarking NumPy and TensorFlow2 on simple network model
import time
import tqdm
import numpy as np
import tensorflow as tf
import numba as nb
#tf.config.experimental.set_visible_devices([], 'GPU')
tf.zeros((1,), tf.float32)
@maedoc
maedoc / specfit.py
Created August 25, 2020 20:24
Spectral fitting TVB with autograd
import sys
import time
from autograd import numpy as np, grad
from autograd.misc.optimizers import adam, rmsprop, sgd
from scipy.optimize import minimize
import pylab as pl
# simplification of the generic 2d oscillator
def dfun(state, w, theta):
@maedoc
maedoc / vdpo-autograd.py
Created March 11, 2020 08:11
Simple autograd odeint model
import time
from autograd import numpy as np, grad
from autograd.scipy.integrate import odeint
from autograd.builtins import tuple
from autograd.scipy.stats import norm
from autograd.misc.optimizers import adam
def vdpo(y, t0, a, k, tau=3.0):
x, y = np.reshape(y, (2, -1))
@maedoc
maedoc / jr95.py
Created January 15, 2020 12:47
Reproduce results of Jansen, Rit 1995 paper with TVB
import numpy as np
import tvb.simulator.lab as tvb
from tvb.basic.neotraits.api import Final, List
# setup model based on paper's parameters
model_pars = dict(
A=3.25,
B=22.0,
v0=6.0,
a=0.1, # TVB uses ms, not s
@maedoc
maedoc / sdde.py
Last active August 4, 2020 07:28
SDDE estimation with Stan
import pystan
try:
model # avoid recompiling during IPython/notebook session
except:
model = pystan.StanModel('sdde.stan')
data = dict(
nt=500,
d=50,
@maedoc
maedoc / simplevi.py
Last active October 20, 2021 06:33
Simple example of variational inference with autograd
from autograd import grad, numpy as np
from autograd.scipy.stats import norm
from autograd.misc.optimizers import adam
def simple_vi(n=2000):
x = np.random.normal(loc=+1.5, scale=+0.3, size=10)
log_p = lambda z: np.mean(norm.logpdf(x[:, None], z[0], np.exp(z[1])), axis=0)
log_q = lambda z, l: norm.logpdf(z, l[:, None], 0.3)
samp_q = lambda l: np.random.normal(l[:, None], 0.3, (2, n))
# https://arxiv.org/pdf/1401.0118.pdf, eq 3
@maedoc
maedoc / trace_tvb.py
Created November 19, 2019 06:58
Trace a TVB simulation to produce pretty call graph
from pycallgraph import PyCallGraph
from pycallgraph.output import GraphvizOutput
from pycallgraph import GlobbingFilter
from pycallgraph import Config
from tvb.simulator.models.wong_wang import ReducedWongWang
from tvb.simulator.lab import *
import numpy
@maedoc
maedoc / anon-manifold.md
Last active November 12, 2019 20:13
anon estimates manifolds
> be me
> dukenukem.jpg
> tired of playing ITCrowd.exe
> drool while looking at HMC.jpeg

> install numpyro
> assume homogeneous coupling
@maedoc
maedoc / ssh_magic.py
Created October 22, 2019 20:36
SSH cell magic for IPython/Jupyter
import IPython.core.magic, subprocess
@IPython.core.magic.register_cell_magic
def ssh(line, cell):
proc = subprocess.Popen(['ssh'] + line.split(),
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
out, _ = proc.communicate(cell.encode('ascii'))
print(out.decode('ascii'))
@maedoc
maedoc / lsmod.out
Last active September 27, 2019 13:13
R510 info on OpenSuse
Module Size Used by
fuse 114688 3
tcp_diag 16384 0
inet_diag 20480 1 tcp_diag
veth 16384 0
nfsv3 49152 0
nfs_acl 16384 1 nfsv3
nf_conntrack_netlink 49152 0
xfrm_user 40960 1
xfrm_algo 16384 1 xfrm_user