Split an agent's eval score across its parts

Agent buildHard40 min

Your task

Your agent has several parts you can switch on or off, such as a planner, a memory and a few tools. You ran the eval once for every combination of parts and recorded each run's score. Now you want to credit the full agent's score to its parts fairly, so each part gets its average gain over every order in which the parts could be switched on.

Write part_credit(scores) that returns each part's credit.

Input and output:

  • scores: the eval score for every combination of m parts, for m from 1 to 12, so the list holds 2 to the power m whole numbers from 0 to 10,000. scores[mask] is the score with exactly the parts whose bits are set in mask switched on: part i is the bit 1 << i.
  • Return a list of m floats, part 0 first. The tests accept any value within 0.000001 of the exact one.

Rules:

  • Picture switching the parts on one at a time, in some order, starting with none on. A part's gain in that order is the score just after it is switched on minus the score just before.
  • A part's credit is its gain averaged over all the orders of the m parts, each order counted once.

Examples

part_credit(scores: list[int]) -> list[float]
Example 1
Inputpart_credit([40, 70])
Output[30]
Example 2
Inputpart_credit([40, 55, 60, 90])
Output[22.5, 27.5]
Example 3
Inputpart_credit([20, 20, 20, 80])
Output[30, 30]