v9.1.1
Menu

Softmax Transition Probabilities

mediumPROVideo TexturesVideoCV: Image-Based Rendering

Convert frame similarities to transition probabilities using softmax.

For varied video texture playback, we use probabilistic transitions instead of always jumping to the best match. The transition probability from frame ii to frame jj is:

P(j∣i)=exp⁡(−Dij/σ)∑kexp⁡(−Dik/σ)P(j|i) = \frac{\exp(-D_{ij}/\sigma)}{\sum_k \exp(-D_{ik}/\sigma)}

where:

  • DijD_{ij} is the dissimilarity from ii to jj
  • σ\sigma is a temperature parameter
  • Lower dissimilarity = higher probability

This creates smooth random playback that prefers good transitions but allows variety.

Return the probabilities as a list in the same order as the input, with each probability rounded to 4 decimal places.

Example

Input
transition_probs([0, 10, 10], 10)
Output
[0.5761, 0.2119, 0.2119]
Reasoning
  • Inputs: similarities = [0, 10, 10] holds the dissimilarity DijD_{ij} from the current frame to each of 3 candidate frames (0 means a perfect match), and sigma = 10 is the temperature.
  • Scale and negate: each score becomes −Dij/σ-D_{ij}/\sigma, giving 0,−1,−10, -1, -1. The negative sign is what makes a small dissimilarity produce a large weight.
  • Weights: e0=1e^{0} = 1 and e−1≈0.3679e^{-1} \approx 0.3679 (twice), so the denominator is 1+2×0.3679≈1.73581 + 2 \times 0.3679 \approx 1.7358.
  • Normalise: P=1/1.7358≈0.5761P = 1 / 1.7358 \approx 0.5761 for the matching frame and 0.3679/1.7358≈0.21190.3679 / 1.7358 \approx 0.2119 for each of the other two, each rounded to 4 decimal places: [0.5761, 0.2119, 0.2119].
  • Notice: the two frames with equal dissimilarity get equal probability, and the rounded values add to 0.99990.9999, not exactly 1. A larger σ\sigma would shrink the gaps and push all three toward 1/31/3.

Constraints

  • similarities: list of similarity scores from current frame to all frames
  • sigma: temperature parameter (higher = more uniform)
  • Return probability distribution (sums to 1)

Learn this in

More from CV: Image-Based Rendering

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.