partitionCurvedSpace

maelzel.distribute.partitionCurvedSpace(x, numpart, curve, minval=1, maxdev=1, accuracy=1)[source]

Partition a number x into numpart partitions following a curve

Parameters:
  • x (float) – the number to partition

  • numpart (int) – number of partitions

  • curve (BpfInterface) – a bpf curve where y goes from 0 to some integer (this values is not important) It must grow monotonically from 0, meaning that for any x_n f(x_n) >= f(x_(n-1))

  • minval – min. value of a partition

  • maxdev – max. deviation

  • accuracy – a value between 0 and 1

Reeturns:

a list of partitions, None if not solution is possible

Note

curve must be a monotonically growing curve starting at 0. See the example using .integrated() to learn how to make a monotonically growing curve out of any distribution

NB: returns None if no solution is possible

Examples

Divide 23 into 6 partitions following an exponential curve

>>> import bpf4
>>> curve = bpf4.expon(0, 0, 1, 1, exp=3)
>>> partitionCurvedSpace(23, 6, curve)
[1, 1, 2, 4, 6, 9]

Partition a distance following, an arbitraty curve, where the y defines the relative duration of the partitions. In this case, the curve defined the derivative of our space.

>>> import bpf4
>>> curve = bpf4.linear(
...   0, 1,
...   0.5, 0,
...   1, 1)
>>> partitionCurvedSpace(21, 7, curve.integrated())
[5, 3, 2, 1, 2, 3, 5]