Skip to content

Instantly share code, notes, and snippets.

View bistaumanga's full-sized avatar

bistaumanga bistaumanga

View GitHub Profile
@bistaumanga
bistaumanga / DTW_python.py
Created July 17, 2013 19:33
Dynamic Time warping implemented in python
'''Implementation and Demostration of Dynamic Time Warping
Requires : python 2.7.x, Numpy 1.7.1, Matplotlib, 1.2.1'''
from math import *
import numpy as np
import sys
def DTW(A, B, window = sys.maxint, d = lambda x,y: abs(x-y)):
# create the cost matrix
A, B = np.array(A), np.array(B)
@bistaumanga
bistaumanga / gmm.py
Last active January 2, 2023 04:09
Gaussian Mixture Model using Expectation Maximization algorithm in python
# -*- coding: utf-8 -*-
"""
Created on Sat May 3 10:21:21 2014
@author: umb
"""
import numpy as np
class GMM:
@bistaumanga
bistaumanga / hist.py
Created August 22, 2013 16:32
Histogram Equalization in python
import numpy as np
def imhist(im):
# calculates normalized histogram of an image
m, n = im.shape
h = [0.0] * 256
for i in range(m):
for j in range(n):
h[im[i, j]]+=1
return np.array(h)/(m*n)
@bistaumanga
bistaumanga / media_outlets_bias_mbfc_oct2020.csv
Last active November 8, 2022 23:43
Media outlets bias and factuality from MBFC (oct 2020)
title country mbfc_page bias_raw Factual Ideology url
Alliance for Justice (AFJ) USA left left8 High L https://www.afj.org/
Act.TV USA left left4 MostlyFactual L http://act.tv
ACHNews USA left left8 MostlyFactual L https://achnews.org/
AlterNet USA left left2 Mixed L https://www.alternet.org/
Al DIA USA left left4 Mixed L https://aldianews.com
Aftonbladet Sweden left left9 Mixed L https://www.aftonbladet.se
Alt News India left left10 High L https://www.altnews.in
Amandla South Africa left left7 High L http://aidc.org.za/amandla-media/
ANX Media (American News X) USA left left3 Mixed L http://anx.media/
@bistaumanga
bistaumanga / myFFT.py
Last active October 19, 2022 14:59
Fast Fourier Transform Library in Python
#################################################################################
#
# This is FFT library implemented in python.
# The Algorithm used is FFT, decimation in time, radix -2 algorithm
# can compute FFT of 1-d and 2-d lists, 1-d for 1-d signals , and 2-d for images
#
# by : Umanga Bista @ bistaumanga@gmail.com
#
#################################################################################
@bistaumanga
bistaumanga / BinaryHeap.scala
Last active May 20, 2022 04:20
Binary Heap implementation in Scala. It can be used for priority queue. In addition to standard Priority Queue available in Java or Scala, this supports delete and update on K-V pair(Priority is defined by Value) with addition pointer/map stored to the keys.
package util
import scala.collection.mutable.HashMap
import scala.collection.mutable.ArrayBuffer
/*
* Single Array Based Binary Min Heap
*/
class BinaryHeap[T]{
@bistaumanga
bistaumanga / pca.py
Last active May 14, 2021 08:32
Principal component analysis in python.
import numpy as np
import pylab as plt
'''
Performs the Principal Coponent analysis of the Matrix X
Matrix must be n * m dimensions
where n is # features
m is # examples
'''
def PCA(X, varRetained = 0.95, show = False):
@bistaumanga
bistaumanga / phase_vocoder.py
Created August 19, 2013 13:12
Phase vocoder algorithm for time scaling and pitch scaling of audio signals
import numpy as np
from scipy.io import wavfile
from numpy.fft import fft, ifft, fftshift
def hamming(M):
n = np.arange(M)
return 0.54 - 0.46 * np.cos( 2 * np.pi * n / (M - 1))
def hann(M):
n = np.arange(M)
@bistaumanga
bistaumanga / kMeans.py
Last active December 7, 2020 10:16
KMeans Clustering Implemented in python with numpy
'''Implementation and of K Means Clustering
Requires : python 2.7.x, Numpy 1.7.1+'''
import numpy as np
def kMeans(X, K, maxIters = 10, plot_progress = None):
centroids = X[np.random.choice(np.arange(len(X)), K), :]
for i in range(maxIters):
# Cluster Assignment step
C = np.array([np.argmin([np.dot(x_i-y_k, x_i-y_k) for y_k in centroids]) for x_i in X])
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.