-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Weibull loglikelihood issues #59
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,13 +166,13 @@ def loglik_discrete(y, u, a, b, epsilon=K.epsilon()): | |
hazard1 = K.pow((y + 1.0) / a, b) | ||
|
||
loglikelihoods = u * \ | ||
K.log(K.exp(hazard1 - hazard0) - (1.0 - epsilon)) - hazard1 | ||
K.log((1.0 + epsilon) - K.exp(hazard0 - hazard1)) - hazard0 | ||
return loglikelihoods | ||
|
||
|
||
def loglik_continuous(y, u, a, b, epsilon=K.epsilon()): | ||
ya = (y + epsilon) / a | ||
loglikelihoods = u * (K.log(b) + b * K.log(ya)) - K.pow(ya, b) | ||
loglikelihoods = u * (K.log(b) - K.log(a) + (b-1) * K.log(ya)) - K.pow(ya, b) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Considering the only terms that differ:
Where the latter can be written
With regards to the parameters, this is proportional to
Since The upsides are very marginal computational benefit. The downsides are that it can be confusing if one expects that I'm leaning towards that the upsides is not worth the downsides and would be open for a loss function that is equal, rather than proportional. I'm a bit worried about touching these equations too much, they are battle tested in numerous fights against NaN and have proven themselves very stable and performant. A form like
Seems like a pretty safe and cheap alternative however. What do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now when I come think of it once again, you're right! There is no need to add redundant constant term to the log-likelihood in continuous case. |
||
return loglikelihoods | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the discrete case it’s equivalent. It’s just a matter of where we put epsilon:
Which form is right is just a matter of style. My reasons is that I like to emphasis that for positive distributions discretized loglikelihood can always be written on the form
u*log[exp(Λ(y+1)-Λ(y))-1]-Λ(y+1)
, which is a form I chose because empirically it seemed most numerically stable/efficient and that automatic differentiation seemed to unfold it efficiently. I may be wrong about this however so please provide me with counterexamples if you have them.See proposition 2.26.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the only true difference was in case of
u=0
.