# Loss function for an unsupervised neural network

I am trying to use a neural network approach to fit a model based on two sets of data: the "before" set and the "after" set. The "after" set is the subset of "before" examples that have survived to a given point in time. The neural net tries to attribute survival probabilities y to entries x. This is an unsupervised task. For N observations in the "after" set, the loss function in this case is a log-likelihood based on the survival probabilities y of each datapoint x.

It writes:

loss = Sum[log[y],{x,{"after"}}]-N*Log[Sum[y,{x,"before"}]]


However, how can I define the loss function in that case, since it must collect all outputs from a given batch and combine them in non-additive way to be computed?