Structure and Segmentation

audio_samples.segment holds path enhancement, time-lag filtering, temporally constrained clustering and subsegmentation.

Structure analysis over feature matrices: path enhancement, temporally constrained clustering, subsegmentation.

class audio_samples.segment.TimelagFiltered

Bases: object

The filter that [timelag_filter] returns.

audio_samples.segment.agglomerative(data, k, *, clusterer=None, axis=-1)

Segment boundaries from Ward clustering in which only neighbouring segments merge.

Parameters:
  • data (array_like) – Features with time along axis.

  • k (int) – Number of segments.

  • clusterer (Optional[object]) – Any object with fit and labels_, in place of the built-in clustering.

  • axis (int) – The time axis. Default -1.

Returns:

The first frame of each segment.

Return type:

numpy.ndarray[int64]

audio_samples.segment.diagonal_filter(window, n, *, slope=1.0, angle=None, zero_mean=False)

A normalised smoothing kernel along a line through the origin.

Parameters:
  • window (str | tuple | array_like) – The window along the line.

  • n (int) – Its length, before rotation.

  • slope (float) – The line’s slope; 1 is the main diagonal. Default 1.

  • angle (Optional[float]) – The line’s angle in radians, in place of slope.

  • zero_mean (bool) – Subtract the mean. Default false.

Returns:

The kernel.

Return type:

numpy.ndarray[float64]

audio_samples.segment.path_enhance(R, n, *, window='hann', max_ratio=2.0, min_ratio=None, n_filters=7, zero_mean=False, clip=True, **kwargs)

The largest response of a recurrence matrix to diagonal kernels of several slopes.

Parameters:
  • R (array_like) – (..., n, n) or lag matrix.

  • n (int) – Length of each kernel, before rotation.

  • window (str | tuple | array_like) – The window along each diagonal. Default "hann".

  • max_ratio (float) – Largest slope. Default 2.

  • min_ratio (Optional[float]) – Smallest slope. Default 1 / max_ratio.

  • n_filters (int) – Number of slopes. Default 7.

  • zero_mean (bool) – Subtract each kernel’s mean. Default false.

  • clip (bool) – Set negative results to zero. Default true.

  • **kwargs – mode ("reflect", "constant", "nearest", "mirror", "wrap"), cval and origin.

Returns:

The shape of R, of its precision.

Return type:

numpy.ndarray

audio_samples.segment.subsegment(data, frames, *, n_segments=4, axis=-1)

Subdivides each interval of a segmentation with agglomerative().

Parameters:
  • data (array_like) – Features with time along axis.

  • frames (array_like[int]) – Segment boundaries; the ends are added.

  • n_segments (int) – The most subsegments per interval. Default 4.

  • axis (int) – The time axis. Default -1.

Returns:

The first frame of each subsegment.

Return type:

numpy.ndarray[int64]

audio_samples.segment.timelag_filter(function, pad=True, index=0)

Wraps a filter so that it runs on a recurrence matrix in lag coordinates.

Parameters:
  • function (Callable) – The filter. It receives the time-lag matrix at position index.

  • pad (bool) – Pad the lag matrix to twice the length. Default true.

  • index (int) – Position of the matrix in the call’s arguments. Default 0.

Returns:

Takes the same arguments as function and returns a recurrence matrix.

Return type:

Callable