Skip to content

Instantly share code, notes, and snippets.

@TobCap
Last active December 9, 2017 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TobCap/a0fcd28c07976f528379ce5df35bbb35 to your computer and use it in GitHub Desktop.
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