-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlgorithmAnalysisFunctions.R
68 lines (56 loc) · 2.34 KB
/
AlgorithmAnalysisFunctions.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#Usefule functions for analysing the performance of an algorithm
#Detection rate for a single outlier (detected (1) or not(0))
trueoutdet <- function(outs,trueout){
if (is.na(match(trueout,outs)) == T){
return(0)
}
else {
return(1)
}
}
outs1 <- eucdistoutlierdet(Ybookingsa)
trueoutdet(outs1,501)
#Function for detection rate as % of number of outliers
multidetrate <- function(outs, trueouts){
((length(trueouts) - sum(is.na(match(trueouts,outs))))/length(trueouts))
}
##############################################################################################################################################################################################
##############################################################################################################################################################################################
#define function which returns FP rate based on list of outliers
fpratedists <- function(outs,trueout){
if ((length(which(outs==trueout))) == 0){
return(length(outs))
}
else {
return(length(outs)-1)
}
}
outs1 <- eucdistoutlierdetthresh(dists1,t1)
fpratedists(outs1,501)
#calculate rate of false positives of euclidean distance algorithm
fprate <- function(data,trueout){
outs <- eucdistoutlierdet(data)
if (is.na(match(trueout,outs)) == T){
return(length(outs))
}
else {
return(length(outs)-1)
}
}
fprate(Ybookings,501)
#Consider the effect of multiple outliers
#Function for FP rate as % of number of total observations
multifprate <- function(outs, trueouts, n){
return(sum(is.na(match(trueouts,outs)))/n) ##returns number of outlier which are not genuine
}
##############################################################################################################################################################################################
##############################################################################################################################################################################################
#create a function which times how long it takes to run a function
timerfunc <- function(func){
start.time <- Sys.time()
func
end.time <- Sys.time()
time.taken <- end.time - start.time
return(time.taken)
}
timerfunc(eucdistsums(Ybookings)) #50.36682 secs