Skip to content
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

Observation-wise logloss / crossentropy #55

Open
jemus42 opened this issue Oct 22, 2024 · 0 comments
Open

Observation-wise logloss / crossentropy #55

jemus42 opened this issue Oct 22, 2024 · 0 comments

Comments

@jemus42
Copy link
Member

jemus42 commented Oct 22, 2024

In the context of #39, I would have use for the instance-wise logloss as e.g. available in Metrics::ll.

I cloned the repo to see if I can prepare this myself, but then I got sidetracked thinking about logloss as it is implemented right now, which from what I gather works for both binary and multiclass tasks. In the instance-wise case however it would need to be split into basically blogloss and mlogloss, akin to bbrier and mbrier, no?

So I'm not sure how to go about all that.

I would assume we'd have something along these lines if I understand correctly, yes?

blogloss_obs = function(truth, prob, positive, eps = 1e-15, ...) {
  assert_binary(truth, prob = prob, positive = positive)
  assert_number(eps, lower = 0, upper = 1)
  
  ii = match(as.character(truth), colnames(prob))
  p = prob[cbind(seq_len(nrow(prob)), ii)]
  p = pmax(eps, pmin(1 - eps, p))
  truth = as.integer(truth == positive)
  -(truth * log(p) + (1 - truth) * log(1 - p))
}
mlogloss_obs = function(truth, prob, eps = 1e-15, ...) {
  assert_classif(truth, prob = prob)
  assert_number(eps, lower = 0, upper = 1)

  ii = match(as.character(truth), colnames(prob))
  p = prob[cbind(seq_len(nrow(prob)), ii)]
  p = pmax(eps, pmin(1 - eps, p))
  log(p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant