I want to predict count data using a simple fully connected network. I could in principle frame it as a classification problem where each class corresponds to the event count, but I would like to do it properly using a Poisson loss function. Two quick questions:
I can’t seem to find the implementation of this loss function, am I missing anything?
I also cannot seem to find any examples of using pytorch to predict count data, any pointers?
Super simple question: since lambda > 0 [because of the log(lambda_hat)] how could I go about defining the loss function to guarantee proper lambdas? In principle implementing it with pytorch functions is straightforward:
def poissonLoss(predicted, observed):
"""Custom loss function for Poisson model."""
loss=torch.mean(predicted-observed*torch.log(predicted))
return loss
But I obviously need to force the output to be strictly positive otherwise I’ll get -inf and nans. What sort of correction for the last layer could I use? Like ReLU with a floor>0 of sorts?