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 | |
from sklearn.linear_model import Lasso, lars_path | |
np.random.seed(42) | |
def gen_data(n, m, k): | |
X = np.random.randn(n, m) | |
w = np.zeros((m, 1)) | |
i = np.arange(0, m) |
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 FuncDesigner as fd | |
from openopt import NLP | |
from sklearn.metrics.pairwise import rbf_kernel, polynomial_kernel | |
def theta(x): | |
return 0.5 * (fd.sign(x) + 1.) |
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
""" | |
Multinomial Logistic Regression (MLR) | |
===================================== | |
Multiclass-classification with the MLR classifier | |
Authors: Adrien Gaidon & Jakob Verbeek | |
""" |
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 scipy as sp | |
from scipy import optimize as opt | |
def nnlr(X, y, C): | |
""" | |
Non-negative Logistic Regression with L2 regularizer | |
""" | |
def lr_cost(X, y, theta, C): | |
m = len(y) | |
return (1./m) * (sp.dot(-y, sp.log(sigmoid(sp.dot(X, theta)))) \ |
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
#DOES NOT WORK: GIFTI READ/WRITE is broken | |
import nibabel as nb | |
import nibabel.gifti as gifti | |
# load combined file | |
# created with: mris_convert --combinesurfs lh.pial rh.pial ./pial.gii | |
surf = gifti.read('pial.gii') | |
#load orig affine transform | |
ao = nb.load('orig.nii').get_affine() |
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 online_mean_variance(iterable): | |
mN = 0 | |
mM = 0.0 | |
mS = 0.0 | |
for x in iterable: | |
mN += 1 | |
nextM = mM + (x - mM) / mN | |
mS += (x - mM) * (x - nextM) |
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 | |
def _compute_bins(x, n_bins=10): | |
""" Find optimal bins from a univariate distribution | |
Parameters | |
=========== | |
x: 1D array-like | |
Samples | |
n_bins: integer |
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
"""A helper node to concatenate images in nipype""" | |
import os | |
from nipype.interfaces.base import TraitedSpec, File, CommandLineInputSpec, CommandLine | |
from nipype.utils.misc import isdefined | |
class ConcatImgInputSpec(CommandLineInputSpec): | |
in_file1 = File(exists=True, argstr="-append %s", | |
position=1, mandatory=True) |