PY-97

Split a Permutation without Losing Records

  • Medium
  • Dataset Splits
  • Python

Task

Write split_permutation(permutation, split_sizes). permutation is a one-dimensional integer NumPy array containing every position from 0 through n - 1 exactly once. It must contain at least three positions.

split_sizes is a dictionary with exactly these keys: train, validation, and test. Each value is a positive integer, and the three values must add to n. Use the fixed partition order train, then validation, then test. Take the first train positions from the supplied permutation, the next validation positions, and the remainder for test. Do not sort, reshuffle, or generate a new permutation.

Return a dictionary with exactly these keys:

splits, audit

splits is a new dictionary with the same three keys. Each value is an independent one-dimensional integer array. The arrays must retain the order of their contiguous slice from the supplied permutation.

audit must be a new dictionary with exactly these keys:

sizes, disjoint, covers_all, order_preserved

sizes maps each partition name to its actual number of positions. The three remaining values are booleans. They must report that no position occurs in more than one partition, all source positions occur once across the partitions, and concatenating the partitions in the fixed order reproduces the supplied permutation.

Example

The three arrays are [4, 0], [3], and [1, 2, 5]. Their values are not sorted; they are the exact contiguous pieces of the supplied position plan.

Your implementation

You may import NumPy as np. Do not print or ask for input.