Skip to content

Instantly share code, notes, and snippets.

@TobCap
Last active December 9, 2017 11:02
Show Gist options
  • Select an option

  • Save TobCap/a0fcd28c07976f528379ce5df35bbb35 to your computer and use it in GitHub Desktop.

Select an option

Save TobCap/a0fcd28c07976f528379ce5df35bbb35 to your computer and use it in GitHub Desktop.
MulLayer <- function(){
x_ <- NA
y_ <- NA
forward <- function(x, y){
x_ <<- x
y_ <<- y
x * y
}
backward <- function(dout){
dx <- dout * y
dy <- dout * x
list(dx = dx, dy = dy)
}
list(forward = forward, backward = backward, x = function() x_, y = function() y_)
}
m <- MulLayer()
print(m$x())
## [1] NA
m$forward(100, 2)
print(m$x())
## [1] 100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment