Last active
March 31, 2018 09:18
-
-
Save thinhdanggroup/fb8c30b474e129e0ca3c628c137afa3c to your computer and use it in GitHub Desktop.
mcut algorithms
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(ggplot2) | |
library(utiml) | |
# Use stdout as per normal... | |
print("Hello, world!") | |
mcut_thresholdk <- function (prediction, probability = FALSE) { | |
UseMethod("mcut_thresholdk") | |
} | |
mcut_thresholdk.default <- function (prediction, probability = FALSE) { | |
result <- apply(prediction, 1, function (row) { | |
print("line") | |
sorted.row <- sort(row, decreasing = TRUE) | |
print(sorted.row) | |
difs <- unlist(lapply(seq(length(row)-1), function (i) { | |
sorted.row[i] - sorted.row[i+1] | |
})) | |
print(difs) | |
t <- which.max(difs) | |
print(t) | |
mcut <- (sorted.row[t] + sorted.row[t+1]) / 2 | |
print(mcut) | |
row <- ifelse(row > mcut, 1, 0) | |
row | |
}) | |
multilabel_prediction(t(result), prediction, probability) | |
} | |
mcut_thresholdk.mlresult <- function (prediction, probability = FALSE) { | |
mcut_thresholdk.default(as.probability(prediction), probability) | |
} | |
prediction <- matrix(runif(16), ncol = 4) | |
prediction | |
mcut_thresholdk(prediction) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment