You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/10/10 22:36:07 UTC
[GitHub] sandeep-krishnamurthy closed pull request #12776: R fix metric shape
sandeep-krishnamurthy closed pull request #12776: R fix metric shape
URL: https://github.com/apache/incubator-mxnet/pull/12776
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/R-package/R/metric.R b/R-package/R/metric.R
index b29d0ea487f..8715ccfb3a1 100644
--- a/R-package/R/metric.R
+++ b/R-package/R/metric.R
@@ -59,7 +59,8 @@ mx.metric.top_k_accuracy <- mx.metric.custom("top_k_accuracy", function(label, p
#'
#' @export
mx.metric.mse <- mx.metric.custom("mse", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0)
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1)
res <- mx.nd.mean(mx.nd.square(label-pred))
return(as.array(res))
})
@@ -68,7 +69,8 @@ mx.metric.mse <- mx.metric.custom("mse", function(label, pred) {
#'
#' @export
mx.metric.rmse <- mx.metric.custom("rmse", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0)
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1)
res <- mx.nd.sqrt(mx.nd.mean(mx.nd.square(label-pred)))
return(as.array(res))
})
@@ -77,7 +79,8 @@ mx.metric.rmse <- mx.metric.custom("rmse", function(label, pred) {
#'
#' @export
mx.metric.mae <- mx.metric.custom("mae", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0)
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1)
res <- mx.nd.mean(mx.nd.abs(label-pred))
return(as.array(res))
})
@@ -86,7 +89,8 @@ mx.metric.mae <- mx.metric.custom("mae", function(label, pred) {
#'
#' @export
mx.metric.rmsle <- mx.metric.custom("rmsle", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0)
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1)
res <- mx.nd.sqrt(mx.nd.mean(mx.nd.square(mx.nd.log1p(pred) - mx.nd.log1p(label))))
return(as.array(res))
})
@@ -95,13 +99,13 @@ mx.metric.rmsle <- mx.metric.custom("rmsle", function(label, pred) {
#'
#' @export
mx.metric.Perplexity <- mx.metric.custom("Perplexity", function(label, pred, mask_element = -1) {
-
+
label <- mx.nd.reshape(label, shape = -1)
pred_probs <- mx.nd.pick(data = pred, index = label, axis = 1)
-
+
mask <- label != mask_element
mask_length <- mx.nd.sum(mask)
-
+
NLL <- -mx.nd.sum(mx.nd.log(pred_probs) * mask) / mask_length
res <- mx.nd.exp(NLL)
return(as.array(res))
@@ -111,7 +115,8 @@ mx.metric.Perplexity <- mx.metric.custom("Perplexity", function(label, pred, mas
#'
#' @export
mx.metric.logloss <- mx.metric.custom("logloss", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0)
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1)
pred <- mx.nd.clip(pred, a_min = 1e-15, a_max = 1-1e-15)
res <- -mx.nd.mean(label * mx.nd.log(pred) + (1-label) * mx.nd.log(1-pred))
return(as.array(res))
@@ -121,7 +126,8 @@ mx.metric.logloss <- mx.metric.custom("logloss", function(label, pred) {
#'
#' @export
mx.metric.logistic_acc <- mx.metric.custom("accuracy", function(label, pred) {
- pred <- mx.nd.reshape(pred, shape = 0) > 0.5
+ label <- mx.nd.reshape(label, shape = -1)
+ pred <- mx.nd.reshape(pred, shape = -1) > 0.5
res <- mx.nd.mean(label == pred)
return(as.array(res))
})
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services