Skip to content

Instantly share code, notes, and snippets.

View agramfort's full-sized avatar

Alexandre Gramfort agramfort

View GitHub Profile
@agramfort
agramfort / nlms.py
Created July 14, 2024 08:58
NLMS: Normalized Least-mean-square
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import lfilter
# Step 1: Create a synthetic dataset
np.random.seed(42) # For reproducibility
N = 1000 # Number of samples
x = np.random.randn(N) # Input signal (random noise)
w_true = np.array([0.5, -0.3, 0.1]) # True filter coefficients
e_ = 0.01 * np.random.randn(N) # Noise
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@agramfort
agramfort / demo_dipole_fit_goodness_of_fit.ipynb
Last active June 12, 2022 09:53
Demo of dipole fit and GOF computation using MNE
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import vtk
import pyvista as pv
from vtk.util import numpy_support
# from vtk.numpy_interface import dataset_adapter as dsa
data = np.zeros((50, 50, 50))
data[20:30, 20:30, 20:30] = 1
data_vtk = numpy_support.numpy_to_vtk(
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 20 19:45:49 2020
@author: zhanglingxi
"""
import os
import os.path as op
@agramfort
agramfort / ipynb2sg.py
Created September 26, 2020 14:03
ipynb2sg.py
from pathlib import Path
from nbconvert import PythonExporter
import textwrap
exporter = PythonExporter()
notebook = Path('docs/tutorials/decomposition/ajive_tutorial.ipynb')
def nb2py(notebook):
@agramfort
agramfort / generalized_additive_models.ipynb
Last active July 23, 2020 21:36
generalized additive models with backfitting and splines
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
Benchmark of MultiTaskLasso
"""
import gc
from itertools import product
from time import time
import numpy as np
import pandas as pd
from sklearn.datasets import make_regression
$ pip list
Package Version Location
--------------------------------- --------------------- -------------------------------------------------------------------------
absl-py 0.7.1
alabaster 0.7.11
alembic 1.0.11
alphacsc 0.4.dev0 /Users/alex/work/src/alphacsc
alphawaves 0.1 /Users/alex/work/src/Alpha-Waves-Dataset
appdirs 1.4.3
appnope 0.1.0
import numpy as np
import pandas as pd
from sklearn.preprocessing import OrdinalEncoder
class CountOrdinalEncoder(OrdinalEncoder):
"""Encode categorical features as an integer array
usint count information.
"""
def __init__(self, categories='auto', dtype=np.float64):
self.categories = categories