Last active
December 9, 2017 11:02
-
-
Save TobCap/a0fcd28c07976f528379ce5df35bbb35 to your computer and use it in GitHub Desktop.
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
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