Skip to content

Instantly share code, notes, and snippets.

View mnarayan's full-sized avatar

mnarayan mnarayan

View GitHub Profile
@mnarayan
mnarayan / skggm_optimal_selection_example.py
Created October 8, 2017 17:43
Example of using scikit-optimize with skggm
import sys
import numpy as np
from skopt.space import Real, Categorical, Integer
from skopt import BayesSearchCV
from sklearn.grid_search import GridSearchCV
from sklearn.datasets import make_sparse_spd_matrix
from sklearn.model_selection import train_test_split
from sklearn.metrics import make_scorer
@mnarayan
mnarayan / Wavelets-TMS-fMRI-timeseries.md
Last active October 6, 2022 00:30
A brief note on using wavelet decompositions to study functional connectivity in block-TMS fMRI data.

Introduction

Here is an example of single-subject time-series during R pMFG stimulation.

Break down of global time-series by wavelet scales

Measuring total variance in the signal at each ROI could be very useful to do, particularly across scales 1 to 4.

@mnarayan
mnarayan / BetweenSubjectDifferentialLogLikelihood.md
Last active October 6, 2022 00:31
Log-likelihood Ratio between Pooled Covariance and Individual Covariance

Additional Algorithm for Two Sample Differences in Populations of Graphical Models

Consider two graphical models case

$$\mathbf{X}^{(1,i)} \sim \mathcal{N}(0,\boldsymbol\Sigma^{(1,i)})$$ $$\mathbf{X}^{(2,i)} \sim \mathcal{N}(0,\boldsymbol\Sigma^{(2,i)})$$

Idea:

  1. Create pooled sample covariance matrix given by $\frac{\widehat{\boldsymbol\Sigma^{1}} + \widehat{\boldsymbol\Sigma^{2}}}{2}$
  2. Obtain multiple estimates of $\Delta^{(1,i)}, i=1,\ldots, n_g$ and similarly for $g = 2$ using the sparse log-likelihood ratio
@mnarayan
mnarayan / README.md
Last active February 10, 2017 07:24
Modified example of \psMatrixPlot with pstricks-add

Here is an improvement over a nice answer from @herbert that took advantage of pstricks-add and xelatex.

The earlier answer however did not create a proper grid for every cell in the matrix.It only displayed the grid structure for values set to 1. This enables a more generic solution beyond [0,1] valued matrices.

What we would like to see however is something like this —

[![Alternative color scheme, highlights grid over all cells][2]][2]

Here is a code snippet to achieve this:

@mnarayan
mnarayan / sidenotes-demo.tex
Created February 8, 2017 20:17 — forked from dgleich/sidenotes-demo.tex
tufte sidenotes -- a tufte-latex ripoff
\documentclass{article}
\usepackage{booktabs}
\usepackage{geometry}
\usepackage{tabularx}
\geometry{lmargin=72pt,tmargin=72pt,textwidth=350pt,marginparwidth=144pt}
\usepackage{tufte-sidenotes}
\begin{document}
Here is demo of the \verb#tufte-sidenotes# style.
@mnarayan
mnarayan / backup_sherlock.md
Last active December 19, 2023 03:12
MATLAB on sherlock

How to backup data from sherlock to google drive

  1. Download and install rclone to your $HOME/bin directory. Setup up rclone to connect to your google drive. Suppose you call your remote google drive drive.

  2. Create a bash script called backup_gdrive.sh with the following information

#!/bin/sh

STUDY_DIR=STUDY
LOCAL_DIR=${SCRATCH}/${STUDY_DIR}
@mnarayan
mnarayan / gist:75cd4f9bda2301a843f3
Created January 12, 2016 03:25 — forked from fabianp/gist:3081831
Pool Adjacent Violators
import numpy as np
# Author : Alexandre Gramfort
# license : BSD
def pav(y):
"""
PAV uses the pair adjacent violators method to produce a monotonic
smoothing of y
@mnarayan
mnarayan / springer-free-maths-books.md
Created December 29, 2015 00:03 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links
@mnarayan
mnarayan / tex-to-pdf
Created December 20, 2015 18:04 — forked from AdrianoFerrari/tex-to-pdf
Node server to take Gingko Tex output into PDF
var TreeId = "your_tree_id_here";
var Filename = "output_filename";
var http =require('http');
var fs = require('fs');
var request = require('request');
var exec = require('child_process').exec;
var header = fs.readFileSync('parts/header.tex', 'utf8');
var footer = fs.readFileSync('parts/footer.tex', 'utf8');
var replacements = { '\\\\begin\\{center\\}\\\\rule\\{3in\\}\\{0\\.4pt\}\\\\end\\{center\\}': '\\hr', '\\\\section\{([^\}]*)\}\\\\label\{([^\}]*)\}\\n\\n([^\.]*[\\.\\\'\\\'\\?\\!]*)\\s': '\\finishchapter\n\\section{$1}\\label{$2}\n\\setupchapter\n\\newthought{$3} ' };
@mnarayan
mnarayan / CovariancesMeetComplexNetworks.md
Last active June 2, 2022 19:31
Why graph topological metrics applied to sample covariance graphs can blow up

Note: The betweenness centrality used here is based on the shortest path implementation in the Brain Connectivity Toolbox.

  1. Take a real known correlation matrix $\Sigma$
  2. Simulate multivariate data i.e. observations x regions matrix from normal distribution with known correlation matrix $\mathcal{N}(0,\Sigma)$
  3. For each random sample from step 2, compute betweenness-centrality for a series of thresholds on the correlation matrix. This constitutes one monte-carlo trial run in the first figure.
  4. One can vary the number of observations t from 100 to 500 and see the error bars on betweenness-centrality go down.

Take-ways: Network metric is unstable in two ways: A small change to the threshold leads to huge change in metric. As a result it is also highly unstable between monte-carlo trials as well. **Theory says that all shortest path based metrics are similarly unstable, with unpredictably large variance. Thus z-scores and t-tests don't even converge to any distribution let alone a normal one. There