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
#Another simple test | |
x.1<-rnorm(50, 10, 3) | |
y.1<-rnorm(50, 10, 3) | |
x.2<-rnorm(50, 20, 3) | |
y.2<-rnorm(50, 10, 3) | |
x.3<-rnorm(50, 13, 3) | |
y.3<-rnorm(50, 20, 3) | |
test.data<-data.frame(group=rep(1:3, each=50), x=c(x.1, x.2, x.3), y=c(y.1, y.2, y.3)) |
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
#Testing on the iris data set | |
iris.dist<-dist(iris[,1:4]) | |
bhc<-buster(iris.dist, n=250, k=3, size=0.66, method='ward', pct.exc=0.1) | |
plot(bhc) | |
#We see the unstable observations in pink. | |
cluster<-bhc$obs.eval$cluster[order(bhc$obs.eval$obs.ind)] | |
plot(iris[,1:4], col=6-cluster, pch = rep(15:17, each=50)) |
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
#Maximize a mixture of multivariate normal distributions | |
library(mvtnorm) | |
mnMix<-function(args){ | |
mean.vec.d1<-rep(0.3,5) | |
std.vec.d1<-diag(rep(1,5)) | |
mean.vec.d2<-rep(1,5) | |
std.vec.d2<-diag(rep(1.5,5)) | |
mean.vec.d3<-c(1, 5, 2, 1, 0) | |
std.vec.d3<-diag(rep(0.5, 5)) | |
if (args[1]<0){ |
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
# *-------------------------------------------------------------------- | |
# | FUNCTION: visGAPath | |
# | Function for visualising the path of a genetic algorithmn using | |
# | principal components analysis | |
# *-------------------------------------------------------------------- | |
# | Version |Date |Programmer |Details of Change | |
# | 01 |18/04/2012|Simon Raper |first version. | |
# *-------------------------------------------------------------------- | |
# | INPUTS: func The function to be optimised | |
# | npar The number of parameters to optimise over |
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
library(reshape2) | |
#Bagging hierarchical clustering | |
bagHClust<-function(data, n, k, size, outlier.th) { | |
clus.bs<-NULL | |
for (i in 1:n) { |
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
clusComp<-function(cl1, cl2, num.clus){ | |
#Set up object for recording clusters | |
clus.change<-NULL | |
ct1<-cutree(cl1, k=num.clus) | |
add.1<-data.frame(size=rep(1, length(ct1)), ind=names(ct1), cluster=paste0(1, ".", ct1)) | |
ct2<-cutree(cl2, k=num.clus) | |
add.2<-data.frame(size=rep(2, length(ct2)), ind=names(ct2), cluster=paste0(2, ".", ct2)) |
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
#Check the relationship between correlation and mutual information for binary vars | |
store<-NULL | |
for (i in 1:1000){ | |
prob.1<-runif(1) | |
prob.2<-runif(1) | |
x<-rbinom(10000, 1, prob.1) | |
y<-rbinom(10000, 1, prob.2) | |
c<-cor(x,y) | |
m<-mi.empirical(table(x,y)) | |
store<-rbind(store, data.frame(c=c, m=m)) |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Tangle: a JavaScript library for reactive documents</title> | |
<link rel="stylesheet" href="http://worrydream.com/Tangle/TangleKit/TangleKit.css" type="text/css"> | |
<script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/mootools.js"></script> | |
<script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/sprintf.js"></script> | |
<script type="text/javascript" src="http://worrydream.com/Tangle/TangleKit/BVTouchable.js"></script> |
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
#Run hclust | |
hc <- hclust(dist(USArrests[1:40,]), "ave") | |
#Function for extracting nodes and links | |
extractGraph<-function(hc){ | |
n<-length(hc$order) | |
m<-hc$merge | |
links<-data.frame(source=as.numeric(), target=as.numeric(), value=as.numeric()) |
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
#Sequence for adding new data | |
s<-seq(20,50, by=5) | |
#Set up object for recording clusters | |
clus.change<-NULL | |
#Cycle through the clustering solutions | |
for (i in s){ | |
hc <- hclust(dist(USArrests[1:i,]), "ave") |