Hi guys. I am fairly new to Stan, so this might be a really elementary question. Is it possible to write a custom density function that contains discontinuities and use it to model a likelihood? I have searched the forum and did not find any relevant questions.

For my problem I have checked to ensure my custom likelihood is grammatically correct in the sense that it can correctly calculate the density values of given data points when using fix parameters. Now I am trying to see if I assign some parameters to be unknown and feed my density the simulated data, it can give me back the correct values of the parameters. However, when I try to run RStan it gives me the error of

```
Chain 1: Rejecting initial value:
Chain 1: Gradient evaluated at the initial value is not finite.
Chain 1: Stan can't start sampling from this initial value.
```

I know this is probably due to the reason that my density contains discontinuities, so do I have to write my own analytical gradient function? I can paste my code if necessary. Thank you in advance for your help!