Streaming Entropy of Softmax Distribution (Single-Pass, Numerically Stable)

Given a stream of logits x_1..x_n, let p_i = exp(x_i) / sum_j exp(x_j). Compute the Shannon entropy H = -sum_i p_i * ln(p_i) (natural log) of the softmax distribution.

Requirements:

  1. Online / strea...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: