### define a dnn model, calculate the feed forward network
model = dNNmodel(units = c(8, 6, 1),
activation = c("elu", "sigmoid", "sigmoid"), input_shape = 3)
print(model)
x = matrix(runif(15), nrow = 5, ncol = 3)
cache = fwdNN(x, model)
# dy = dL/dp, where L is the cost function such as the
# log-likehood and p is the output layer parameter of the DNN
dy = as.matrix(runif(5, -0.1, 0.1), nrow = 5) # a dummy dy for bwdNN input
y = predict(model, x) + dy
# back propagation
dW = bwdNN(dy, cache, model)
dw = bwdCheck(x, y, model)
print(dW[[1]])
print(dw[[1]])
Run the code above in your browser using DataLab