You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ENH: Add Sequence and Boxes classes, to be returned by segment algorithms #51
After thinking about it more, I think we don't need classes to represent the two atomic units of segmentation algorithms, line segments and boxes. That's because the algorithm always produces either a sequence of line segments or a set of boxes (except for edge cases, e.g. a sequence with a single segment, or e.g., returning no segments because none were found with the specified parameters). Additionally, we almost never perform operations with a single line segment or box; instead we operate on the sequences themselves
So what would a Sequence class be like?
its data should be "backed" by scientific Python primitives: either two numpy arrays or a pandas DataFrame with two columns: start and stop, as well as a 'label' array / column
say it's three numpy arrays for now:
the start and stop array should have the same type, either float (seconds) or integer (sample number)
upon instantiation we should validate that
the length of start times equals the length of stop times
all values are non-negative
array values are strictly monotonically increasing
there's no overlap of segments
(possibly) nice to haves:
override array indexing so that it gives us a new Sequence instance
a notion of "units"
ability to represent a single sequence as both seconds and sample number -- this is sometimes useful for segmentation metrics; one could do this with a property, e.g. by supplying a sampling rate and having property = start_s return self.start_sample * self.samplerate
I don't have strong opinions yet about what a Boxes class would look like. It is perhaps more naturally represented by a pandas DataFrame since we are now for sure dealing with 5 arrays / columns (start, stop, low, high, label).
changed the title [-]ENH: Add `Sequence` and `BoxSet` classes, to be returned by `segment` algorithms[/-][+]ENH: Add `Sequence` and `Boxes` classes, to be returned by `segment` algorithms[/+]on Sep 20, 2023
we will want a LineSegment [and a Box] class for an ORM that builds a dataset of sequences, because there we will need to have a more OO-like representation of each individual segment as a row in a database table.
Thought about this more during development of #57 to fix #54
One thing I realized there: segmenting algorithms that threshold (eg RMS) and return pairs of onsets and offsets are a special case of segmenting in general.
It's better to think of all algorithms that segment into sequences as returning a single vector of non-negative, strictly increasing boundary times. Then we can think of the special case of algorithms that threshold to find start and stop times returns as returning two types of boundaries: the onset type and the offset type. But if we threw that boundary type away we'd still have a vector of non-negative strictly increasing event times, the same way other fields think about segmenting 1-D signals (e.g., MIR).
If instead you try to cram other segmenting algorithms into the onset/offset mold (e.g. one that applies a distance metric to a time series) you end up thinking you need to allow onsets and offsets to be either greater than or equal to the previous boundary--because some algorithms can return adjacent segments with no silent gap between them. You also end up writing really verbose functions where you try to take onset and offset times in separately and provide the ability to compute the IR metrics either separately or "combined". And by "you", I mean "me" 😭
This is relevant for this issue because it should inform how we implement the Sequence class. I now think we will definitely want it to be backed by a dataframe, so that we can add an additional column that denotes the boundary type. This will then allow us to compute IR metrics the standard way by default, but then compute them by boundary type when needed.
Activity
[-]ENH: Add `Sequence` and `BoxSet` classes, to be returned by `segment` algorithms[/-][+]ENH: Add `Sequence` and `Boxes` classes, to be returned by `segment` algorithms[/+]NickleDave commentedon Sep 20, 2023
Context from another issue:
#49 (comment)
NickleDave commentedon Sep 30, 2023
Thought about this more during development of #57 to fix #54
One thing I realized there: segmenting algorithms that threshold (eg RMS) and return pairs of onsets and offsets are a special case of segmenting in general.
It's better to think of all algorithms that segment into sequences as returning a single vector of non-negative, strictly increasing boundary times. Then we can think of the special case of algorithms that threshold to find start and stop times returns as returning two types of boundaries: the onset type and the offset type. But if we threw that boundary type away we'd still have a vector of non-negative strictly increasing event times, the same way other fields think about segmenting 1-D signals (e.g., MIR).
If instead you try to cram other segmenting algorithms into the onset/offset mold (e.g. one that applies a distance metric to a time series) you end up thinking you need to allow onsets and offsets to be either greater than or equal to the previous boundary--because some algorithms can return adjacent segments with no silent gap between them. You also end up writing really verbose functions where you try to take onset and offset times in separately and provide the ability to compute the IR metrics either separately or "combined". And by "you", I mean "me" 😭
This is relevant for this issue because it should inform how we implement the Sequence class. I now think we will definitely want it to be backed by a dataframe, so that we can add an additional column that denotes the boundary type. This will then allow us to compute IR metrics the standard way by default, but then compute them by boundary type when needed.
NickleDave commentedon Feb 12, 2024
Closing, superceded by #127