Compute the optimal partitions given a distribution of set sizes. Args: sizes (numpy.array): The complete domain of set sizes in ascending order. counts (numpy.array): The frequencies of all set sizes in the same order as `sizes`. num_part (int):
(sizes, counts, num_part)
| 170 | |
| 171 | |
| 172 | def optimal_partitions(sizes, counts, num_part): |
| 173 | """Compute the optimal partitions given a distribution of set sizes. |
| 174 | |
| 175 | Args: |
| 176 | sizes (numpy.array): The complete domain of set sizes in ascending |
| 177 | order. |
| 178 | counts (numpy.array): The frequencies of all set sizes in the same |
| 179 | order as `sizes`. |
| 180 | num_part (int): The number of partitions to create. |
| 181 | |
| 182 | Returns: |
| 183 | list: A list of partitions in the form of `(lower, upper)` tuples, |
| 184 | where `lower` and `upper` are lower and upper bound (inclusive) |
| 185 | set sizes of each partition. |
| 186 | """ |
| 187 | if num_part < 2: |
| 188 | return [(sizes[0], sizes[-1])] |
| 189 | if num_part >= len(sizes): |
| 190 | partitions = [(x, x) for x in sizes] |
| 191 | return partitions |
| 192 | nfps = _compute_nfps_real(counts, sizes) |
| 193 | partitions, _, _ = _compute_best_partitions(num_part, sizes, nfps) |
| 194 | return partitions |
no test coverage detected