This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(fn table-insert [tab val] | |
(var t tab) | |
(table.insert t val) | |
t) | |
(fn table-remove [tab indx] | |
(var t tab) | |
(table.remove t indx) | |
t) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (zip lis1 lis2) | |
(if (and (not (equal? lis1 '())) (not (equal? lis2 '()))) | |
(cons (cons (car lis1) (car lis2)) (zip (cdr lis1) (cdr lis2))) | |
'())) | |
(define (take ls count) | |
(if (and (> count 0) (not (equal? ls '()))) | |
(cons (car ls) (take (cdr ls) (- count 1))) | |
'())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(flatten_ints). | |
-export([flatten/1, test/0]). | |
% I also wrote a scala one from the prolog 99 problems set - but this was a while back | |
% located here: https://github.com/Nixonite/scala-99/blob/master/p07.scala | |
% base cases here | |
flatten([]) -> []; | |
flatten([[]|T]) -> flatten(T); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy.io | |
import numpy as np | |
data = scipy.io.loadmat("subject.mat") | |
for i in data: | |
if '__' not in i and 'readme' not in i: | |
np.savetxt(("filesforyou/"+i+".csv"),data[i],delimiter=',') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def CH_index(X, labels, centroids): | |
#X being a pandas dataframe, so X = dataframe.values | |
#labels being the (KMeans(n_clusters=i).fit(X)).labels_ | |
#centroids being the KMeans centroid values of a fitted kmeans model | |
''' | |
https://github.com/scampion/scikit-learn/blob/master/scikits/learn/cluster/__init__.py | |
''' | |
mean = np.mean(X,axis=0) | |
B = np.sum([ np.sum(labels==i)*(c - mean)**2 for i,c in enumerate(centroids)]) | |
W = np.sum([ (x-centroids[labels[i]])**2 for i, x in enumerate(X)]) |