TheoreticalEcology / s-jSDM

Scalable joint species distribution modeling
https://theoreticalecology.github.io/s-jSDM/
GNU General Public License v3.0
64 stars 14 forks source link

ValueError: Expected value argument #136

Open Sarahbouclette opened 3 months ago

Sarahbouclette commented 3 months ago

Hello, I tried my best to understand and find a solution but I'm stuck. My problem is that i want to use a poisson distribution on eDNA data. So, each species for each sample is described as its number of reads/Total number of reads of the sample. When i try to run my model:

sjSDM(Y=Occ, env=linear(data=Env, formula=~ Run), spatial=linear(data=SC,formula=~0+Longitude:Latitude),sampling = 5L, se=TRUE, family=poisson('log'), learning_rate = 0.0001) I have this warning: "Error in py_call_impl(callable, call_args$unnamed, call_args$named) : ValueError: Expected value argument (Tensor of shape (3, 16)) to be within the support (IntegerGreaterThan(lower_bound=0)) of the distribution Poisson(rate: torch.Size([3, 3, 16])), but found invalid values: tensor([[0.0000, 0.8209, 0.0000, 0.0000, 0.0000, 0.0448, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0448, 0.0000, 0.0896, 0.0000, 0.0000], [0.0131, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.9869, 0.0000, 0.0000], [0.2174, 0.1739, 0.0000, 0.0870, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, 0.5217, 0.0000, 0.0000, 0.0000, 0.0000]])"

I saw that someone already has this issue and you recommended to change the learning rate and to scale the data. I tried both and it's still not working. Do you have an idea of what can I possibly change?

Thank you

MaximilianPi commented 3 months ago

Hi @Sarahbouclette,

Could you also share a histogram of your response? It may also be difficult for the optimizer if your response is strongly overdispersed. In this case, you may want to switch to a negative binomial distribution.

Sarahbouclette commented 3 months ago

Yes, here is to examples of response histograms. But I have the same error message with Nbinom.

hist carassius hist cyprinus carpio
MaximilianPi commented 3 months ago

Hi @Sarahbouclette,

Sorry, it is hard to say if it is because of the data or because of convergence problems in the model. If this is ok for you, could you please send me your code+data (via email) so I can take a look myself?