Utils

Standard event metrics

wardmetrics.utils.print_standard_event_metrics(standard_event_results)[source]

Print standard precision and recall values

Examples

>>> print_standard_event_metrics(test_r)
Standard event results:
    precision:  0.8888888       Weighted by length:     0.9186991
    recall:     0.3333333       Weighted by length:     0.2230576
wardmetrics.utils.standard_event_metrics_to_list(standard_event_results)[source]

Converting standard event metric results to a list (position of each item is fixed)

Argument:
standard_event_results (dictionary): as provided by the 4th item in the results of eval_events function
Returns:Item order: 1. Precision, 2. Recall 3. Length weighted precision, 4. Length weighted recall
Return type:list
wardmetrics.utils.standard_event_metrics_to_string(standard_event_results, separator=', ', prefix='[', suffix=']')[source]

Converting standard event metric results to a string

Argument:
standard_event_results (dictionary): as provided by the 4th item in the results of eval_events function
Keyword Arguments:
 
  • separator (str) – characters between each item
  • prefix (str) – string that will be added before the line
  • suffix (str) – string that will be added to the end of the line
Returns:

Item order: 1. Precision, 2. Recall 3. Length weighted precision, 4. Length weighted recall

Return type:

str

Examples

>>> standard_event_metrics_to_string(test_r)
[0.88888, 0.33333, 0.918, 0.22305]
>>> standard_event_metrics_to_string(test_r, separator="        ", prefix="/", suffix="/")
/0.88888        0.33333 0.918   0.22305/
>>> standard_event_metrics_to_string(test_r, prefix="", suffix="\n")
0.88888, 0.33333, 0.918, 0.22305\n

Detailed event metrics

wardmetrics.utils.print_detailed_event_metrics(detailed_event_results)[source]

Print totals for each event category

Example

>>> print_detailed_event_metrics(test_r)
Detailed event results:
     Actual events:
         deletions:             1       12.50% of actual events
         merged:                3       37.50% of actual events
         fragmented:            1       12.50% of actual events
         frag. and merged:      1       12.50% of actual events
         correct:               2       25.00% of actual events
    Detected events:
         insertions:            1       11.11% of detected events
         merging:               1       11.11% of detected events
         fragmenting:           4       44.44% of detected events
         frag. and merging:     1       11.11% of detected events
         correct:               2       22.22% of detected events
wardmetrics.utils.detailed_event_metrics_to_list(detailed_event_results)[source]

Converting detailed event metric results to a list (position of each item is fixed)

Argument:
detailed_event_results (dictionary): as provided by the 3rd item in the results of eval_events function
Returns:Item order: 0. correct, 1. deletions 2. merged, 3. fragmented, 4. fragmented and merged, 5. fragmenting, 6. merging, 7. fragmenting and merging, 8. insertions, 9. total of actual events, 10. total of detected events
Return type:list
wardmetrics.utils.detailed_event_metrics_to_string(detailed_event_results, separator=', ', prefix='[', suffix=']')[source]

Converting detailed event metric results to a string

Argument:
detailed_event_results (dictionary): as provided by the 3rd item in the results of eval_events function
Keyword Arguments:
 
  • separator (str) – characters between each item
  • prefix (str) – string that will be added before the line
  • suffix (str) – string that will be added to the end of the line
Returns:

Item order: 0. correct, 1. deletions 2. merged, 3. fragmented, 4. fragmented and merged, 5. fragmenting, 6. merging, 7. fragmenting and merging, 8. insertions, 9. total of actual events, 10. total of detected events

Return type:

str

Examples

>>> detailed_event_metrics_to_string(test_r)
[2, 1, 3, 1, 1, 4, 1, 1, 1, 8, 9]
>>> detailed_event_metrics_to_string(test_r, separator=";", prefix="(", suffix=")\n")
(2;1;3;1;1;4;1;1;1;8;9)\n

Detailed segment-based results

wardmetrics.utils.print_detailed_segment_results(detailed_segment_results)[source]

Print segment length for each detailed segment category. Can be used with normed values as well.

Parameters:detailed_segment_results (dictionary) – as provided by the 3rd or 4th item in the results of eval_segments function

Example

>>> print_detailed_segment_results(test_r)
Detailed segment results (length or frame count):
    true positive segments:             40
    true negative segments:             91
    insertion segments:                 10
    deletion segments:                  10
    fragmenting segments:               7
    merge segments:                     15
    start overfill segments:            10
    end overfill segments:              28
    start underfill segments:           13
    end underfill segments:             15
wardmetrics.utils.detailed_segment_results_to_list(detailed_segment_results)[source]

Converting detailed segment results to a list (position of each item is fixed). Can be used with normed values as well.

Argument:
detailed_segment_results (dictionary): as provided by the 3rd or 4th item in the results of eval_segments function
Returns:Item order: 0. true posives, 1. true negatives, 2. insertions, 3. deletions, 4. fragmenting, 5. merged, 6. start overfill, 7. end overfill, 8. start underfill, 9. end underfill
Return type:list
wardmetrics.utils.detailed_segment_results_to_string(detailed_segment_results, separator=', ', prefix='[', suffix=']')[source]

Converting detailed segment results to a string. Can be used with normed values as well.

Argument:
detailed_segment_results (dictionary): as provided by the 3rd or 4th item in the results of eval_segments function
Keyword Arguments:
 
  • separator (str) – characters between each item
  • prefix (str) – string that will be added before the line
  • suffix (str) – string that will be added to the end of the line
Returns:

Item order: 0. true posives, 1. true negatives, 2. insertions, 3. deletions, 4. fragmenting, 5. merged, 6. start overfill, 7. end overfill, 8. start underfill, 9. end underfill

Return type:

str

Examples

>>> detailed_segment_results_to_string(test_r)
[2, 1, 3, 1, 1, 4, 1, 1, 1, 8]
>>> detailed_segment_results_to_string(test_r, separator=";", prefix="(", suffix=")\n")
(2;1;3;1;1;4;1;1;1;8)\n

2SET segment-based metrics

wardmetrics.utils.print_twoset_segment_metrics(twoset_metrics_results)[source]

Print 2SET metric results

Argument:
twoset_metrics_results (dictionary): as provided by the 1st item in the results of eval_events function

Example

>>> print_twoset_segment_metrics(test_r)
2SET metrics:
    true positive rate:         0.471
    deletion rate:              0.118
    fragmenting rate:           0.082
    start underfill rate:       0.153
    end underfill rate:         0.176
    1 - false positive rate:    0.591
    insertion rate:             0.065
    merge rate:                 0.097
    start overfill rate:        0.065
    end overfill rate:          0.182
wardmetrics.utils.twoset_segment_metrics_to_list(twoset_metrics_results)[source]

Converting detailed event metric results to a list (position of each item is fixed)

Argument:
twoset_metrics_results (dictionary): as provided by the 1st item in the results of eval_events function
Returns:Item order: 0. true positive rate, 1. deletion rate 2. fragmenting rate, 3. start underfill rate, 4. end underfill rate, 5. 1 - false positive rate, 6. insertion rate, 7. merge rate, 8. start overfill rate, 9. end overfill rate
Return type:list
wardmetrics.utils.twoset_segment_metrics_to_string(twoset_metrics_results, separator=', ', prefix='[', suffix=']')[source]

Converting detailed event metric results to a string

Argument:
twoset_metrics_results (dictionary): as provided by the 1st item in the results of eval_events function
Keyword Arguments:
 
  • separator (str) – characters between each item
  • prefix (str) – string that will be added before the line
  • suffix (str) – string that will be added to the end of the line
Returns:

Item order: 0. true positive rate, 1. deletion rate 2. fragmenting rate, 3. start underfill rate, 4. end underfill rate, 5. 1 - false positive rate, 6. insertion rate, 7. merge rate, 8. start overfill rate, 9. end overfill rate

Return type:

str

Examples

>>> twoset_segment_metrics_to_string(test_r)
[0.47058823529411764, 0.11764705882352941, 0.08235294117647059, 0.15294117647058825, 0.17647058823529413, 0.5909090909090909, 0.06493506493506493, 0.09740259740259741, 0.06493506493506493, 0.18181818181818182]
>>> twoset_segment_metrics_to_string(test_r, separator=";", prefix="(", suffix=")\n")
(0.47058823529411764;0.11764705882352941;0.08235294117647059;0.15294117647058825;0.17647058823529413;0.5909090909090909;0.06493506493506493;0.09740259740259741;0.06493506493506493;0.18181818181818182)\n

Convert frame-by-frame multiclass results to events

wardmetrics.utils.frame_results_to_events(frame_results, frame_times=None)[source]

Converting frame-by-frame results into a list of events for each label. If the classifier predicts the same label in a sequence it is considers as an event. (Filtering too short events, or merge close-by events is not included here.)

Parameters:
  • frame_results (list or numpy array) – list of frame class labels in an temporal order (sequential). It can contain numeric or string values e.g. [1, 1, 0, ...] or ['class_1', 'class_1', 'class_0', ...]
  • frame_times (list or numpy array) – list of timestamps (preferably as numeric values e.g. posix time) for each frame.
Returns:

list of events (tuple of start and end times/indexes) for each unique label found in the frame_results. Event start value is the first occurence of the label, event end is the time or index of the next frame after the event (also the start of the next event).

Return type:

dictionary