Skip to content

model$entropy becomes NaN when rr contains zeros → predict(type="cloglog") returns NaN #28

@dleotjd520

Description

@dleotjd520

Hello!

After training a maxnet model, I get NA from:
predict(model, newdata, type = "cloglog")

There are no NAs in newdata.
Debugging shows model$entropy is NaN.

In maxnet() the entropy is computed as:

rr  <- predict.maxnet(model, data[p == 0, , drop = FALSE],  type = "exponent", clamp = FALSE)
raw <- rr / sum(rr)
model$entropy <- -sum(raw * log(raw))

When any entry of rr is exactly 0, raw contains zeros and raw * log(raw) evaluates to NaN.
This NaN then propagates and causes predict(..., "cloglog") to return NA.

Questions
(1) Is a model with model$entropy = NaN considered a failed/invalid fit?
(2) Would it be appropriate for maxnet() to compute entropy with a zero-safe convention (e.g., -sum(ifelse(raw > 0, raw * log(raw), 0)))?
(3) Alternatively, should zeros in rr be prevented at the source (e.g., filtering extreme features) or be explicitly excluded when computing entropy?
(4) Is there a recommended preprocessing or parameter setting to avoid rr = 0 ?

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions