# Poisson loss function

**URL:** <https://discuss.pytorch.org/t/poisson-loss-function/44301>\
**Category:** Uncategorized\
**Created:** [May 3, 2019, 5:45pm UTC](https://discuss.pytorch.org/t/poisson-loss-function/44301 "2019-05-03T17:45:50Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![chilango](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/c/e47c2d/32.png) [@chilango](https://discuss.pytorch.org/u/chilango)\
**Post date:** [May 10, 2019, 2:33pm UTC](https://discuss.pytorch.org/t/poisson-loss-function/44301/6 "2019-05-10T14:33:28Z")

</div>

I’ve implemented the following poisson loss function using the first suggested link:

```auto
def poissonLoss(xbeta, y):
    """Custom loss function for Poisson model."""
    loss=torch.mean(torch.exp(xbeta)-y*xbeta)
    return loss

```

Training:

```auto
optimizer=torch.optim.SGD(net.parameters())
lossFn=poissonLoss

output_ = net(input_)
loss = lossFn(output_, target_)
net.zero_grad()
loss.backward()
optimizer.step()

```

Since I’m using pytorch internals, is this the right way to train/backprop/optimize? Not sure about this because my model is not learning.

Thanks,

---

_[View the full topic](https://discuss.pytorch.org/t/poisson-loss-function/44301)._
