R/forward_pass.R

Defines functions forward_pass

Documented in forward_pass

#' @title Forward pass a set of inputs throughout the network
#' @description This function does a forward propagation.
#' @param inputs A matrix of size (N, 1), where N is the size
#' of the layer that is going to receive such inputs. (matrix)
#' @param network A network object generated by create_network (list)
#' @author Eduardo Kapp
forward_pass <- function(inputs, network) {

  layer_sequence <- seq_len(network$n_layers)

  for (layer in layer_sequence) {
    # Compute layer outputs
    raw_layer_output <- compute_layer(
      inputs,
      network$layers[[layer]]
    )
    layer_output <- network$layers[[layer]]$activation(raw_layer_output)

    # the new inputs will be the last layer outputs
    inputs <- layer_output
  }
  return(layer_output)
}
eduardokapp/r_neural_network documentation built on Dec. 20, 2021, 3:21 a.m.