Skip to content

Commit e292b68

Browse files
authored
Merge pull request #344 from OpenKnowledgeMaps/fix-336-maprotation
Fix 336 maprotation
2 parents 0b63925 + 35990ab commit e292b68

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

server/preprocessing/other-scripts/cluster.R

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,13 @@ get_ndms <- function(distance_matrix, mindim=2, maxdim=2, maxit=500) {
9797
# nm.nmin = nmds.min(nm)
9898
if (nrow(distance_matrix) <= 2) {
9999
points <- tryCatch({
100-
ord <- metaMDS(distance_matrix, k = 2, parallel = 3)
100+
ord <- metaMDS(distance_matrix, k = 2, parallel = 3, trymax=30,
101+
engine="monoMDS", distance='cao',
102+
threshold = 0.19, nthreshold=10,
103+
model = "linear",
104+
pc = TRUE,
105+
autotransform = FALSE, center = TRUE,
106+
halfchange = TRUE)
101107
points <- ord$points
102108
}, error=function(err){
103109
points <- cbind(runif(nrow(distance_matrix), min=-1, max=0),
@@ -107,20 +113,18 @@ get_ndms <- function(distance_matrix, mindim=2, maxdim=2, maxit=500) {
107113
} else if (nrow(distance_matrix) == 1) {
108114
points <- cbind(0, 0)
109115
} else {
110-
ord <- metaMDS(distance_matrix, k = 2, parallel = 3)
116+
ord <- metaMDS(distance_matrix, k = 2, parallel = 3, trymax=30,
117+
engine="monoMDS", distance='cao',
118+
threshold = 0.19, nthreshold=10,
119+
model = "linear",
120+
pc = TRUE,
121+
autotransform = FALSE, center = TRUE,
122+
halfchange = TRUE)
111123
points <- ord$points
112124
vclog$info(paste("NMDS-Stress:", min(ord$stress), sep=" "))
113125
}
114126

115-
# vclog$info(paste("NMDS-R2:", min(nm$r2), sep=" "))
116127

117-
# NEEDS FIX
118-
# if(exists("DEBUG") && DEBUG == TRUE) {
119-
# # Plot results from multidimensional scaling, highlight clusters with symbols
120-
# pdf("mds.pdf")
121-
# plot(nm.nmin, pch=groups)
122-
# dev.off()
123-
# }
124128
layout <- list(X1 = points[,1], X2 = points[,2])
125129
return(layout)
126130
}

server/preprocessing/other-scripts/postprocess.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ create_output <- function(clusters, layout, metadata) {
1919

2020
output_json = toJSON(output)
2121

22+
if(exists("DEBUG") && DEBUG == TRUE) {
23+
library(ggplot2)
24+
# Plot results from multidimensional scaling, highlight clusters with symbols
25+
temp <- fromJSON(output_json)
26+
temp$x <- as.numeric(temp$x)
27+
temp$y <- as.numeric(temp$y)
28+
temp$title <- unlist(lapply(temp$title, substr, start=0, stop=15))
29+
g <- ggplot(temp, aes(x, y, label=title)) +
30+
geom_point(aes(colour=area_uri)) +
31+
geom_text(size=2)
32+
ggsave(file = "debug_nmds.svg", plot = g, width = 15, height = 15)
33+
}
34+
2235
# NEEDS FIX
2336
# if(exists("DEBUG") && DEBUG == TRUE) {
2437
# # Write output to file
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"document_types":["121"],
33
"from":"1665-01-01",
4-
"to":"2017-08-19",
5-
"sorting":"most-recent",
4+
"to":"2019-02-12",
5+
"sorting":"most-relevant",
66
"lang_id":"eng"
77
}

0 commit comments

Comments
 (0)