Skip to content

Instantly share code, notes, and snippets.

View anirudhjayaraman's full-sized avatar
🏠
Working from home

Anirudh Jayaraman anirudhjayaraman

🏠
Working from home
View GitHub Profile
@anirudhjayaraman
anirudhjayaraman / graphUndirected.ipynb
Created July 28, 2016 07:58
Python Implementation of Undirected Graphs (Adjacency List and Adjacency Matrix)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anirudhjayaraman
anirudhjayaraman / DSelect.py
Created July 22, 2016 12:34
Deterministic Selection (Median of Medians) Algorithm
def merge_tuple(a,b):
""" Function to merge two arrays of tuples """
c = []
while len(a) != 0 and len(b) != 0:
if a[0][0] < b[0][0]:
c.append(a[0])
a.remove(a[0])
else:
c.append(b[0])
b.remove(b[0])
@anirudhjayaraman
anirudhjayaraman / linear_regression.ipynb
Created July 19, 2016 16:14
Linear Regression in scikit learn
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anirudhjayaraman
anirudhjayaraman / knn.ipynb
Created July 18, 2016 11:38
KNN algorithm implemented with scikit learn
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anirudhjayaraman
anirudhjayaraman / RSelect.py
Created July 18, 2016 03:37
Randomized Selection Algorithm
from random import randrange
def partition(x, pivot_index = 0):
i = 0
if pivot_index !=0: x[0],x[pivot_index] = x[pivot_index],x[0]
for j in range(len(x)-1):
if x[j+1] < x[0]:
x[j+1],x[i+1] = x[i+1],x[j+1]
i += 1
x[0],x[i] = x[i],x[0]
@anirudhjayaraman
anirudhjayaraman / countComparisons.py
Created July 13, 2016 17:55
Computing Work Done (Total Comparisons) by Quick Sort
#!/usr/bin/env
# Case I
# First element of the unsorted array is chosen as pivot element for sorting using Quick Sort
def countComparisonsWithFirst(x):
""" Counts number of comparisons while using Quick Sort with first element of unsorted array as pivot """
global count_pivot_first
if len(x) == 1 or len(x) == 0:
@anirudhjayaraman
anirudhjayaraman / QuickSort_List.txt
Created July 12, 2016 23:11
Integer list to sort using Quick Sort (Exercise)
2148
9058
7742
3153
6324
609
7628
5469
7017
504
@anirudhjayaraman
anirudhjayaraman / quicksort.py
Last active February 3, 2021 20:01
Python code for the Quick Sort Algorithm
def quicksort(x):
if len(x) == 1 or len(x) == 0:
return x
else:
pivot = x[0]
i = 0
for j in range(len(x)-1):
if x[j+1] < pivot:
x[j+1],x[i+1] = x[i+1], x[j+1]
i += 1
@anirudhjayaraman
anirudhjayaraman / FrankelWei_2010_2016.r
Created May 15, 2016 20:26
Frankel Wei Regression for 2010-2016
## if fxregime is absent from installed packages, download it and load it
if(!require('fxregime')){
install.packages("fxregime")
}
## load package
library("fxregime")
# load the necessary data related to exchange rates - 'FXRatesCHF'
# this dataset treats CHF as unit currency
# install / load Quandl
@anirudhjayaraman
anirudhjayaraman / FrankelWei_2005_2010.r
Last active May 15, 2016 20:12
Auto-detecting Structural Breaks in China’s FX Regime
## if fxregime or strucchange package is absent from installed packages, download it and load it
if(!require('fxregime')){
install.packages("fxregime")
}
if(!require('strucchange')){
install.packages("strucchange")
}
## load packages
library("fxregime")