-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.R
executable file
·93 lines (85 loc) · 2.89 KB
/
doc.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
library(rJava)
#setwd("C:\\Users\\Konstantin\\Desktop\\Uni\\6Semester\\BachelorArbeit\\code")
runDoc <- function(data, alpha=0.2, beta=0.8, w=0.05){
data <- apply(data, 2, function(x) {
if (suppressWarnings(is.na(as.numeric(x[[1]])))){
return(as.numeric(factor(x)))
}
return(as.numeric(x))
})
initDoc()
clusterApplier <- .jnew("ClusterApplier")
arrayDouble <- .jcall(clusterApplier, "[[D", "matrix_from_array",as.vector(as.matrix(data)),ncol(data),evalArray=F)
result <- .jcall(clusterApplier, "[Lde/lmu/ifi/dbs/elki/data/Cluster;", "doc",.jarray(as.matrix(data), dispatch = TRUE),alpha,beta,w,evalArray = F)
result
}
getProtoDoc <- function(cluster){
if (length(cluster)==0){
return()
}
clusterApplier <- .jnew("ClusterApplier")
protos <- .jcall(clusterApplier, "[S", "getPrototypeTypes",cluster, simplify = TRUE)
}
getIdsDoc <- function(cluster){
if (length(cluster)==0){
return()
}
clusterApplier <- .jnew("ClusterApplier")
#ids <- .jcall(clusterApplier, "[[D", "getIds",cluster, simplify = TRUE)
ids <- .jcall(clusterApplier, "[D", "getIdsOneDim",cluster, simplify = TRUE)
#if (class(ids)[[1]]!='list'){
# ids <- split(ids, rep(1:nrow(ids), each = ncol(ids)))
#}
.jcheck()
listIds <- lapply(ids,function(x){max(x-min(unlist(ids[ids!=0]))+1,0)})
result <- list()
counter <- 1
temp <- numeric()
for (elem in unlist(listIds)){
if (elem == 0){
result[[counter]] <- temp
counter <- counter + 1
temp <- numeric()
} else {
temp <- c(temp,elem)
}
}
result[[counter]] <- temp
result
}
getDimsDoc <- function(cluster){
if (length(cluster)==0){
return()
}
clusterApplier <- .jnew("ClusterApplier")
dims <- .jcall(clusterApplier, "[[D", "getDims",cluster, simplify = T)
.jcheck()
dims
}
getAvgsDoc <- function(cluster){
if (length(cluster)==0){
return()
}
clusterApplier <- .jnew("ClusterApplier")
avgs <- .jcall(clusterApplier, "[[D", "getAverages",cluster, simplify = T)
.jcheck()
avgs
}
initDoc <- function(){
.jinit(".")
.jaddClassPath("dependencies/elki-clustering-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-api-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-data-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-dbids-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-dbids-int-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-distance-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-math-0.7.5.jar")
.jaddClassPath("dependencies/elki-core-util-0.7.5.jar")
.jaddClassPath("dependencies/elki-database-0.7.5.jar")
.jaddClassPath("dependencies/elki-input-0.7.5.jar")
.jaddClassPath("dependencies/elki-logging-0.7.5.jar")
.jaddClassPath("dependencies/fastutil-8.2.2.jar")
.jaddClassPath("dependencies/jafama-2.3.1.jar")
.jaddClassPath("dependencies/Clust.jar")
}