Skip to content

Instantly share code, notes, and snippets.

View Bollegala's full-sized avatar

Danushka Bollegala Bollegala

View GitHub Profile
@Bollegala
Bollegala / Einsum-Examples.ipynb
Created November 16, 2023 12:49
Einsum Examples
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Bollegala
Bollegala / conflict.py
Created June 16, 2023 09:05
check whether demo/main-conf poster sessions have author conflicts
# Check whether for each demo paper, the authors of that paper has a poster to be presented in the same session
import collections
import pandas as pd
import numpy as np
def main():
posters_df = pd.read_csv('posters.csv')
demos_df = pd.read_csv('demos.csv')
posters_selected = posters_df[["Session", "Author"]]
@Bollegala
Bollegala / import-acl.scpt
Created October 26, 2019 23:07
If you use BibDesk as your bibliography manager and you copy BibTex from acl anthology, then this script hook will (a) determine the PDF file from the bibtex entry and (b) download the PDF and link it to the bibdesk entry. You need to save this apple script and associate to "Import Publication" script hook in BibDesk. All credit goes to Christia…
property theURLPrefixes : {"https://www.aclweb.org/anthology/"}
property thePDFExtension : ".pdf"
on hasAnyPrefix(theString, thePrefixes)
repeat with thePrefix in thePrefixes
if theString starts with thePrefix then return true
end repeat
return false
end hasAnyPrefix
@Bollegala
Bollegala / binofit.py
Created February 17, 2017 23:33
Binomial Exact Test with Clopper-Pearson Confidence Intervals
from statsmodels.stats.proportion import proportion_confint as binofit
# download statmodels from: http://statsmodels.sourceforge.net/
import sys
acc = float(sys.argv[1])
# 0.01 confidence intervals
easy_interval = binofit(acc * 400, 400, 0.01)
print "0.01 interval = ", easy_interval
strict_interval = binofit(acc * 400, 400, 0.001)
@Bollegala
Bollegala / fisher-corr.py
Created February 17, 2017 23:29
Fisher confidence intervals for Spearman correlation
import math
import sys
r = float(sys.argv[1])
num = int(sys.argv[2])
stderr = 1.0 / math.sqrt(num - 3)
delta = 1.96 * stderr
lower = math.tanh(math.atanh(r) - delta)
upper = math.tanh(math.atanh(r) + delta)
print "lower %.6f upper %.6f" % (lower, upper)
@Bollegala
Bollegala / convolution.py
Last active February 17, 2017 23:29
Demonstrates vector convolution
"""
This code shows how to perform convolution between two vectors.
Danushka Bollegala.
14-04-2016
"""
import numpy
@Bollegala
Bollegala / mds.py
Last active October 2, 2022 16:32
This code shows how to perform multi-dimensional scaling (MDS). We will consider three data points (0,1), (0,0), and (1,0) in 2d space, and compute their pairwise Euclidean distance. We then compute the MDS projection, and again plot the projected points in the 2d space. Although the absolute positions of the projected points are different from …
import numpy
import matplotlib.pyplot as plt
import sys
def bval(D, r, s):
n = D.shape[0]
total_r = numpy.sum(D[:,s] ** 2)
total_s = numpy.sum(D[r,:] ** 2)
total = numpy.sum(D ** 2)
"""
This script demonstrates the optimization for a oblong quadratic function
using stochastic gradient descent (SGD), SGD with classical momentum (CM),
and SGD with Nestrov's accelerated gradient (NAG).
You will require matplotlib and numpy to run this example.
Danushka Bollegala.
20th June 2015.
"""
@Bollegala
Bollegala / ADAMvsAdaGrad.py
Created March 10, 2015 18:33
ADAM vs AdaGrad
"""
This program compares ADAM vs AdaGrad. You can modify the function f and its gradient grad_f
in the code, run the two algorithms and compare their convergence. For the simple function
f(x1, x2) = (x1 - 2) ** 2 + (x1 + 3) ** 2, (alpha = 0.1 and tolerence 1e-3)
AdaGrad converged at 2023 iterations, whereas ADAM required only 83!
"""
import numpy
@Bollegala
Bollegala / Theano-memo.py
Last active August 29, 2015 14:13
A brief memo of useful functions in theano
from theano import Tensor as T
# If you want to multiply two matrices (matrix product) in theano do the following
T.dot(X,Y)
# This will multiply matrix X (n,m) into the matrix Y(m,k) and produce a matrix (n,k)
# You can use this to compute inner-product between two row vectors as well
T.dot(w,x)
# will give the inner-product wx\T where w(n,) and x(n,)