Skip to content

Instantly share code, notes, and snippets.

@mbq
Last active January 26, 2018 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbq/8714800f81e67e43d863cc75fe3bf8f3 to your computer and use it in GitHub Desktop.
Save mbq/8714800f81e67e43d863cc75fe3bf8f3 to your computer and use it in GitHub Desktop.
library(ggplot2)
readRDS('ans-ps.RDS')->ss
do.call(rbind,lapply(
split(ss,paste(ss$met,ss$k)),
function(S){
median(S$time[S$p==1])->bl
S$speedup<-bl/S$time
S
})
)->ss
do.call(rbind,lapply(
split(ss,paste(ss$met,ss$p)),
function(S){
S$time<-median(S$time)
S$speedup<-median(S$speedup)
S[1,]
})
)->ss
ss$Method<-toupper(ss$met)
scaleplot<-ggplot(ss,aes(y=speedup,x=p))+geom_line()+
theme(legend.position="bottom")+
ylab("Speed-up")+
xlab("Number of threads")+
facet_wrap(~Method,scales="free")
ggsave("praznik-scale.pdf",scaleplot)
readRDS('ans-pf.RDS')->cc
cc$Package<-cc$pkg
compplot<-ggplot(cc,aes(x=factor(k),col=Package,y=time/1e6))+
geom_boxplot()+
facet_wrap(~toupper(met),scales='free')+ylab("Execution time [ms]")+xlab("Number of features to return (k)")+theme(legend.position="bottom")
ggsave("feast-praznik.pdf",compplot)
library(microbenchmark)
library(praznik) #CRAN/install_github("mbq/praznik")
library(feast) #install_github("mbq/feast_r")
data(MadelonD)
mets_p<-list(jmi=praznik::JMI,disr=praznik::DISR,jmim=praznik::JMIM,mim=praznik::MIM,njmim=praznik::NJMIM,cmim=praznik::CMIM,mrmr=praznik::MRMR)
mets_f<-list(jmi=feast::JMI,disr=feast::DISR,mim=feast::MIM,cmim=feast::CMIM,mrmr=feast::mRMR_D)
X<-MadelonD$X
Y<-MadelonD$Y
TIMES<-30
message("Praznik vs feast_r")
ans<-NULL
ks<-c(20,40)
#FEAST is single-threaded; make comparison fair
setOmpThreads(1)
for(k in ks){
for(e in names(mets_f)){ #mets_f \in mets_p
message(sprintf("Met %s, k=%d",e,k))
rbind(
ans,
data.frame(
met=e,
k=k,
p=1,
pkg="praznik",
time=microbenchmark(mets_p[[e]](X,Y,k),times=TIMES)$time
),
data.frame(
met=e,
k=k,
p=1,
pkg="feast",
time=microbenchmark(mets_f[[e]](X,Y,k),times=TIMES)$time
)
)->ans
}
}
saveRDS(ans,file="ans-pf.RDS")
message("Praznik scaling")
ans<-NULL
for(p in 1:parallel::detectCores()){
for(e in names(mets_p)){
setOmpThreads(p)
message(sprintf("Met %s, cores=%d",e,p))
rbind(
ans,
data.frame(
met=e,
k=20,
p=p,
pkg="praznik",
time=microbenchmark(mets_p[[e]](X,Y,20),times=TIMES)$time
)
)->ans
}
}
saveRDS(ans,file="ans-ps.RDS")
library(praznik)
data(MadelonD)
K<-list(
DISR=DISR,MIM=MIM,MRMR=MRMR,JMI=JMI,
JMIM=JMIM,NJMIM=NJMIM,CMIM=CMIM)
sapply(
#Pull 20 features using each praznik method
lapply(
K,
do.call,c(MadelonD,list(k=20))
),
#Relevant features have >>Rel<< in name
function(ans){
good<-grepl("Rel",names(ans$selection))
c(hits=sum(good),streak=rle(good)$len[1])
}
)
## DISR MIM MRMR JMI JMIM NJMIM CMIM
## hits 20 15 3 20 12 14 13
## streak 20 14 1 20 11 14 11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment