anirudhacharya commented on a change in pull request #12360: [MXNET-690] Add 
tests for initializers in R
URL: https://github.com/apache/incubator-mxnet/pull/12360#discussion_r213160623
 
 

 ##########
 File path: R-package/tests/testthat/test_initializer.R
 ##########
 @@ -0,0 +1,121 @@
+require(mxnet)
+
+context("initializer")
+
+testthat("mx.init.uniform", {
+  uniform_init = mx.init.uniform(scale = 1)
+  expect_equal(typeof(uniform_init), 'closure')
+
+  X_bias <- uniform_init('X_bias', c(1, 10000), ctx = mx.ctx.default())
+  expect_equal(X_bias, mx.nd.zeros(c(1, 10000)))
+
+  X_weight <- uniform_init('X_weight', c(5, 10, 10000), ctx = mx.ctx.default())
+  expect_equal(X_weight >= -1, mx.nd.ones(c(5, 10, 10000)))
+  expect_equal(X_weight <= 1, mx.nd.ones(c(5, 10, 10000)))
+  mean_weight <- mean(as.array(X_weight))
+  expect_equal(mean_weight, 0, tolerance=1e-2)
+})
+
+testthat("mx.init.normal", {
+  normal_init = mx.init.normal(sd = 0.1)
+  expect_equal(typeof(normal_init), 'closure')
+
+  X_bias <- normal_init('X_bias', c(1, 10000), ctx = mx.ctx.default())
+  expect_equal(X_bias, mx.nd.zeros(c(1, 10000)))
+  
+  X_weight <- normal_init('X_weight', c(5, 10, 10000), ctx = mx.ctx.default())
+  weight_mean <- mean(as.array(X_weight))
+  weight_sd <- sd(as.array(X_weight))
+  expect_equal(weight_mean, 0, tolerance=1e-2)
+  expect_equal(weight_sd, 0.1, tolerance=1e-2)
+})
+
+testthat("mx.init.Xavier", {
+  xavier_init <- mx.init.Xavier()
+  expect_equal(typeof(xavier_init), 'closure')
+
+  # default parameters
+  shape <- c(2, 3, 324, 324)
 
 Review comment:
   no particular reason, I just did not want to pick a number too low that the 
test becomes flaky or too high that the test takes very long to execute. It was 
quite random

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to