Skip to content

Instantly share code, notes, and snippets.

@mbillingr
mbillingr / mnescot.py
Created April 21, 2014 23:14
Use SCoT to estimate effective connectivity on MNE labels
"""
=============================================================
Compute PDC spectrum source space connectivity between labels
=============================================================
The connectivity is computed between 4 labels across the spectrum
between 5 and 40 Hz.
"""
# Authors: Alexandre Gramfort <gramfort@nmr.mgh.harvard.edu>
@mbillingr
mbillingr / sspline.py
Last active August 29, 2015 14:02
spherical spline interpolation
import numpy as np
from numpy.polynomial.legendre import legval
from numpy.linalg import solve
def calc_spline(cosang, stiffnes=4, num_lterms=50):
"""Calculate spherical spline between points on a sphere.
Parameters
@mbillingr
mbillingr / example_lda.py
Created August 14, 2014 18:47
Comparison of LDA transforms
import numpy as np
from sklearn.lda import LDA
from sklearn.datasets import make_blobs
from sklearn.utils import check_array
from sklearn.svm import LinearSVC
import matplotlib.pyplot as plt
def new_transform(lda, X):
X = check_array(X)
@mbillingr
mbillingr / fancy_correlation.py
Last active December 8, 2015 15:40
Fancy correlation plots with some sort of outlier detection.
# Released under The MIT License (MIT)
# http://opensource.org/licenses/MIT
# Copyright (c) 2015 Martin Billinger
import numpy as np
import scipy as sp
import matplotlib
from matplotlib.colors import LinearSegmentedColormap
@mbillingr
mbillingr / compare_icas.py
Created February 15, 2016 12:56
Compare ICA methods
import numpy as np
from sklearn.decomposition import FastICA, PCA
from sklearn.cluster import AffinityPropagation
import matplotlib.pyplot as plt
from scot.eegtopo.topoplot import Topoplot
from scot.external.infomax_ import infomax
from scot.csp import csp
@mbillingr
mbillingr / example_sinedtf.py
Last active April 4, 2016 15:36
Toy example that shows what happens to the DTF when a sinusoid is added to white noise signals
import numpy as np
import matplotlib.pyplot as plt
import seaborn
from scot.var import VAR
from scot.connectivity import connectivity
fs = 100
n = 10001
@mbillingr
mbillingr / pyrx.py
Last active April 23, 2023 05:58
Implementation of a minimal Forth interpreter/compiler on top of Python 3.5.
""" pyrx
Implementation of a minimal Forth interpreter/compiler on top of Python 3.6.
It is based on Rx [1] and should eventually support Retro [2].
Facts & Features:
- New words are compiled to Python bytecode (subroutine threading model).
- Dynamically typed: the only data type is the Python object.
- Literals are evaluated as Python expressions.
- The data stack is a global Python list.
@mbillingr
mbillingr / median_ci.py
Last active February 13, 2018 08:22
Confidence Interval of the Median
import numpy as np
import scipy.stats as sps
def median_ci(x, alpha=0.95, method='approximate'):
"""confidence interval of the median"""
n = len(x)
y = np.sort(x)
if method[0] == 'a':
@mbillingr
mbillingr / bfjitwin32.py
Last active June 11, 2019 15:23
Brainfuck JIT compiler written in Python
from ctypes import CFUNCTYPE, c_double, c_int32, c_voidp, c_char
import llvmlite.binding as llvm
from llvmlite import ir
# Looping does not yet work... looks like I'll need to grok the phi instruction....
@mbillingr
mbillingr / timestat.py
Created March 22, 2018 16:09
Module for conveniently comparing the performance of Python statements.
""" Python module for conveniently comparing the performance of
different Python statements.
Features:
- wraps `timeit`
- one function call to compare multiple statements
- textual and graphical representation of results
"""
import numpy as np