Skip to content

Instantly share code, notes, and snippets.

@dtemkin
dtemkin / markovTransitions.py
Last active October 26, 2018 03:36
Markov Chain Transition Matrix Class
import numpy as np
class matrix(state_seq):
def __init__(self, state_sequence):
"""
state_sequence: array or list of integers representing state transitions
"""
self.state_seq = state_sequence
self.n = max(state_sequence) + 1
@dtemkin
dtemkin / damerauLevenshteinDistance.py
Created July 14, 2018 15:12
Function to assess distance between two strings, analogous to the Levenshtein distance but also allows for transposition operations
def damerau_levenshtein_distance(s1, s2):
"""
Like the Levenshtein Distance, this metric calculates the
distance between 2 strings as a the number of single-character
insertions, deletions, or substitutions that it takes to make
the strings equivalent. However, in this case, transpositions
are added into the list of available transformation operations.
Source(s):
@dtemkin
dtemkin / eclat.R
Created May 1, 2018 05:33
Returns all frequent itemsets at every level of the association tree
setClass("itemset", slots=c(id="character", support="numeric", tids="vector")
ECLAT <- function(filename, minsupport, nfeatures, out=NULL){
.input <- read.csv(file = datafile, header=FALSE, sep = " ")
.coninue <- TRUE
.tids <- function(data, ){
itemsets = c()
for (i in c(1:nfeatures)){
item.row.str = ""
item.row.vec = vector()
0,1
1,3
1,2
2,4
3,4
4,5
5,6
6,7
6,8
7,8
Harry
Dave
Sue
Chuck
Theo
Clay
Hugo
Dan
Kate
Kip
@dtemkin
dtemkin / levenshteinDistance.py
Last active July 14, 2018 15:10
Function to determine the Levenshtein Distance between two strings.
def levenshtein_distance(s1, s2):
"""
Calculates the distance between 2 strings as a the number of single-character
insertions, deletions, or substitutions that it takes to make
the two strings equivalent.
Source(s):
(1) Levenshtein, Vladimir I. (February 1966).
"Binary codes capable of correcting deletions, insertions, and reversals".
Soviet Physics Doklady. 10 (8): 707–710.
@dtemkin
dtemkin / storageContainer.java
Created October 23, 2017 22:57
Constructing storage containers in java
/**
Abstract storage containers.
**/
public class storageContainer<E>{
private E[] storageSpace;
public storageContainer(int size){
this.size = size
storageSpace = (E[]) new Object[size];
}
private void populateArray(int n){
@dtemkin
dtemkin / cikfinder.py
Created October 16, 2017 01:08
unofficial api for CIK lookup on EDGAR
class CIK(object):
def __init__(self, company, auto_select_result=0):
self.params = {"company": company}
self.url = "https://www.sec.gov/cgi-bin/cik_lookup"
def _user_select(self, companies):
print("Select item from results list using the integer located to the left of each row")
selected = None
info = []
for i in range(1, len(companies)):
import java.io.*;
import java.util.Scanner;
public class fileIO{
public static void writer(String target_dir; String file){
try
{
PrintWriter writer = new PrinterWriter(new FileOutputStream(target_dir + file));
}
catch(FileNotFoundException e){
public class capitalizeWord{
public static String main(String s){
String[] a = s.split(" ");
for(int i=0; i<a.length; i++){
a[i] = a[i].substring(0, 1).toUppercase() + a[i].substring(1);
}
String r = "";
for(int i=0; i<a.length; i++){
r += a[i] + " ";
}