Skip to content

Instantly share code, notes, and snippets.

@mnarayan
mnarayan / hoeffdingsD.m
Created November 21, 2018 01:58
Naive Function computing Hoeffding's D in MATLAB
function [ D ] = hoeffdingsD( x, y )
%Compute's Hoeffding's D measure of dependence between x and y
% inputs x and y are both N x 1 arrays
% output D is a scalar
% The formula for Hoeffding's D is taken from
% http://support.sas.com/documentation/cdl/en/procstat/63104/HTML/default/viewer.htm#procstat_corr_sect016.htm
% Below is demonstration code for several types of dependencies.
% Implementation by Jascha https://stackoverflow.com/a/9322657
%
% % this case should be 0 - there are no dependencies
@mnarayan
mnarayan / ds000031_model.json
Last active October 18, 2018 20:22 — forked from cmaumet/ds114_model.json
BIDS-models for ds000031
{
"name": "ds000031 example",
"description": "An example of connectivity analysis using ds000031",
"input":
{
"task": "rest"
},
"blocks": [
{
"level": "run",
@mnarayan
mnarayan / tutorial-combat.ipynb
Last active October 6, 2022 00:30
Explore Between Site "Batch" Effects in fMRI QC
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mnarayan
mnarayan / sample_canonical_correlation.m
Created October 19, 2017 02:52
How to compute canonical variates and canonical correlations across training and test splits
function [cca_rho cca_v cca_cv] = sample_canonical_correlation(X,Y,varargin)
% SAMPLE_CANONICAL_CORRELATION
%
% Usage: [rho] = sample_canonical_correlation(X,Y, R_X, R_Y)
%
% Inputs:
% - X is the test set data matrix of n_samples x p features
% - Y is the test set data matrix of n_samples x r features
% - options.W_X is the linear projection matrix for X
% - options.W_Y is a linear projection matrix for Y
@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}