@@ -380,7 +380,7 @@ def compare_annotations(ref_sample, test_sample, window_width, signal=None):
380
380
return comparitor
381
381
382
382
383
- def benchmark_mitdb (detector , verbose = False ):
383
+ def benchmark_mitdb (detector , verbose = False , print_results = False ):
384
384
"""
385
385
Benchmark a qrs detector against mitdb's records.
386
386
@@ -390,11 +390,15 @@ def benchmark_mitdb(detector, verbose=False):
390
390
The detector function.
391
391
verbose : bool, optional
392
392
The verbose option of the detector function.
393
+ print_results : bool, optional
394
+ Whether to print the overall performance, and the results for
395
+ each record.
393
396
394
397
Returns
395
398
-------
396
- comparitors : list
397
- List of Comparitor objects run on the records.
399
+ comparitors : dictionary
400
+ Dictionary of Comparitor objects run on the records, keyed on
401
+ the record names.
398
402
specificity : float
399
403
Aggregate specificity.
400
404
positive_predictivity : float
@@ -434,8 +438,18 @@ def benchmark_mitdb(detector, verbose=False):
434
438
false_positive_rate = np .mean (
435
439
[c .false_positive_rate for c in comparitors ])
436
440
441
+ comparitors = dict (zip (record_list , comparitors ))
442
+
437
443
print ('Benchmark complete' )
438
444
445
+ if print_results :
446
+ print ('\n Overall MITDB Performance - Specificity: %.4f, Positive Predictivity: %.4f, False Positive Rate: %.4f\n '
447
+ % (specificity , positive_predictivity , false_positive_rate ))
448
+ for record_name in record_list :
449
+ print ('Record %s:' % record_name )
450
+ comparitors [record_name ].print_summary ()
451
+ print ('\n \n ' )
452
+
439
453
return comparitors , specificity , positive_predictivity , false_positive_rate
440
454
441
455
@@ -451,5 +465,6 @@ def benchmark_mitdb_record(rec, detector, verbose):
451
465
comparitor = compare_annotations (ref_sample = ann_ref .sample [1 :],
452
466
test_sample = qrs_inds ,
453
467
window_width = int (0.1 * fields ['fs' ]))
454
- print ('Finished record %s' % rec )
468
+ if verbose :
469
+ print ('Finished record %s' % rec )
455
470
return comparitor
0 commit comments