Skip to content
← All questions

What is the Matlab exercise about conditional entropy?

The exercise asks students to implement a Matlab function conditionalentropy(p) that computes the conditional entropy of X given Y from a 2D joint probability matrix p(x,y)p(x,y). It includes specific test cases to verify correctness, such as deterministic and uniform distributions.

Conditions

  • Input p is assumed to be a 2D joint probability array p(x,y)p(x,y).
  • Students may reuse existing entropy() and jointentropy() routines.

Reasoning, step by step

  1. Define the function conditionalentropy(p) taking a 2D matrix p.
  2. Compute the joint entropy H(X,Y)H(X,Y) and marginal entropy H(Y)H(Y) using existing routines, or calculate directly from p.
  3. Apply the chain rule H(X|Y) = H(X,Y)−H(Y)H(X,Y) - H(Y) to return the result.
  4. Validate the function against provided test cases: conditionalentropy([0.5,0;0,0.5]) should equal 0, and conditionalentropy([0.25,0.25;0.25,0.25]) should equal 1.

Example

The exercise slide states: 'Edit the Matlab function conditionalentropy(p) to return the conditional entropy for X given Y for the joint probability p.' with printed tests conditionalentropy([0.5,0;0,0.5])=0 and conditionalentropy([0.25,0.25;0.25,0.25])=1.

Common misconceptions

  • Assuming the input p is a marginal probability vector rather than a 2D joint probability matrix.
  • Forgetting that conditional entropy is not symmetric, as highlighted by the Guess Who! example comparing H(sex|earrings) and H(earrings|sex).

Watch the explanation

Connected concepts

Explore next

Related questions

Meet the concept

↗
Understand why

↗
Meet the concept

↗
Find a method

↗
Understand why

↗

Answers are generated from source material and independently checked. Consult the original video or creator if something is unclear.