havakv / pycox

Survival analysis with PyTorch
BSD 2-Clause "Simplified" License
780 stars 180 forks source link

Continuous-Time Models Loss Calculation #145

Open up-tree opened 1 year ago

up-tree commented 1 year ago

Hi, Havard.

I'm using the CoxPH Model in my project, and trying to apply the corresponding Continuous-Time Loss function, CoxPHLoss, to calculate the loss. However, it got some errors. The output of my net (log_h) was (270, 10), the durations and events were both (270,). When the loss function called, the log_h would be changed into (2700,), and error occurred as follow:

RuntimeError: The size of tensor a (2700) must match the size of tensor b (270) at non-singleton dimension 0

Do you have any suggestions to help me fix this problem? Looking forward to your reply. Thanks for your time and your help.

havakv commented 1 year ago

Hi, if you can write up a full example (including data) that reproduce this error, maybe I can help you. This isn't really too much to go on