Mercurial > hg > vamp-plugin-sdk
comparison src/vamp-hostsdk/PluginSummarisingAdapter.cpp @ 418:a13635e9c440
Tweak debug output
author | Chris Cannam |
---|---|
date | Tue, 01 Mar 2016 12:10:29 +0000 |
parents | 632d90c185ec |
children | 55de53d7c777 |
comparison
equal
deleted
inserted
replaced
385:632d90c185ec | 418:a13635e9c440 |
---|---|
39 #include <map> | 39 #include <map> |
40 #include <algorithm> | 40 #include <algorithm> |
41 #include <cmath> | 41 #include <cmath> |
42 #include <climits> | 42 #include <climits> |
43 | 43 |
44 using namespace std; | |
45 | |
44 //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER 1 | 46 //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER 1 |
45 //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT 1 | 47 //#define DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT 1 |
46 | 48 |
47 _VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.cpp) | 49 _VAMP_SDK_HOSTSPACE_BEGIN(PluginSummarisingAdapter.cpp) |
48 | 50 |
78 size_t m_stepSize; | 80 size_t m_stepSize; |
79 size_t m_blockSize; | 81 size_t m_blockSize; |
80 | 82 |
81 SegmentBoundaries m_boundaries; | 83 SegmentBoundaries m_boundaries; |
82 | 84 |
83 typedef std::vector<float> ValueList; | 85 typedef vector<float> ValueList; |
84 | 86 |
85 struct Result { // smaller than Feature | 87 struct Result { // smaller than Feature |
86 RealTime time; | 88 RealTime time; |
87 RealTime duration; | 89 RealTime duration; |
88 ValueList values; // bin number -> value | 90 ValueList values; // bin number -> value |
89 }; | 91 }; |
90 | 92 |
91 typedef std::vector<Result> ResultList; | 93 typedef vector<Result> ResultList; |
92 | 94 |
93 struct OutputAccumulator { | 95 struct OutputAccumulator { |
94 int bins; | 96 int bins; |
95 ResultList results; | 97 ResultList results; |
96 OutputAccumulator() : bins(0) { } | 98 OutputAccumulator() : bins(0) { } |
97 }; | 99 }; |
98 | 100 |
99 typedef std::map<int, OutputAccumulator> OutputAccumulatorMap; | 101 typedef map<int, OutputAccumulator> OutputAccumulatorMap; |
100 OutputAccumulatorMap m_accumulators; // output number -> accumulator | 102 OutputAccumulatorMap m_accumulators; // output number -> accumulator |
101 | 103 |
102 typedef std::map<RealTime, OutputAccumulator> SegmentAccumulatorMap; | 104 typedef map<RealTime, OutputAccumulator> SegmentAccumulatorMap; |
103 typedef std::map<int, SegmentAccumulatorMap> OutputSegmentAccumulatorMap; | 105 typedef map<int, SegmentAccumulatorMap> OutputSegmentAccumulatorMap; |
104 OutputSegmentAccumulatorMap m_segmentedAccumulators; // output -> segmented | 106 OutputSegmentAccumulatorMap m_segmentedAccumulators; // output -> segmented |
105 | 107 |
106 typedef std::map<int, RealTime> OutputTimestampMap; | 108 typedef map<int, RealTime> OutputTimestampMap; |
107 OutputTimestampMap m_prevTimestamps; // output number -> timestamp | 109 OutputTimestampMap m_prevTimestamps; // output number -> timestamp |
108 OutputTimestampMap m_prevDurations; // output number -> durations | 110 OutputTimestampMap m_prevDurations; // output number -> durations |
109 | 111 |
110 struct OutputBinSummary { | 112 struct OutputBinSummary { |
111 | 113 |
126 double mode_c; | 128 double mode_c; |
127 double mean_c; | 129 double mean_c; |
128 double variance_c; | 130 double variance_c; |
129 }; | 131 }; |
130 | 132 |
131 typedef std::map<int, OutputBinSummary> OutputSummary; | 133 typedef map<int, OutputBinSummary> OutputSummary; |
132 typedef std::map<RealTime, OutputSummary> SummarySegmentMap; | 134 typedef map<RealTime, OutputSummary> SummarySegmentMap; |
133 typedef std::map<int, SummarySegmentMap> OutputSummarySegmentMap; | 135 typedef map<int, SummarySegmentMap> OutputSummarySegmentMap; |
134 | 136 |
135 OutputSummarySegmentMap m_summaries; | 137 OutputSummarySegmentMap m_summaries; |
136 | 138 |
137 bool m_reduced; | 139 bool m_reduced; |
138 RealTime m_endTime; | 140 RealTime m_endTime; |
142 void accumulateFinalDurations(); | 144 void accumulateFinalDurations(); |
143 void findSegmentBounds(RealTime t, RealTime &start, RealTime &end); | 145 void findSegmentBounds(RealTime t, RealTime &start, RealTime &end); |
144 void segment(); | 146 void segment(); |
145 void reduce(); | 147 void reduce(); |
146 | 148 |
147 std::string getSummaryLabel(SummaryType type, AveragingMethod avg); | 149 string getSummaryLabel(SummaryType type, AveragingMethod avg); |
148 }; | 150 }; |
149 | 151 |
150 static RealTime INVALID_DURATION(INT_MIN, INT_MIN); | 152 static RealTime INVALID_DURATION(INT_MIN, INT_MIN); |
151 | 153 |
152 PluginSummarisingAdapter::PluginSummarisingAdapter(Plugin *plugin) : | 154 PluginSummarisingAdapter::PluginSummarisingAdapter(Plugin *plugin) : |
243 Plugin::FeatureSet | 245 Plugin::FeatureSet |
244 PluginSummarisingAdapter::Impl::process(const float *const *inputBuffers, | 246 PluginSummarisingAdapter::Impl::process(const float *const *inputBuffers, |
245 RealTime timestamp) | 247 RealTime timestamp) |
246 { | 248 { |
247 if (m_reduced) { | 249 if (m_reduced) { |
248 std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl; | 250 cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << endl; |
249 } | 251 } |
250 FeatureSet fs = m_plugin->process(inputBuffers, timestamp); | 252 FeatureSet fs = m_plugin->process(inputBuffers, timestamp); |
251 accumulate(fs, timestamp, false); | 253 accumulate(fs, timestamp, false); |
252 m_endTime = timestamp + | 254 m_endTime = timestamp + |
253 RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5)); | 255 RealTime::frame2RealTime(m_stepSize, int(m_inputSampleRate + 0.5)); |
256 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | |
257 cerr << "timestamp = " << timestamp << ", end time becomes " << m_endTime | |
258 << endl; | |
259 #endif | |
254 return fs; | 260 return fs; |
255 } | 261 } |
256 | 262 |
257 Plugin::FeatureSet | 263 Plugin::FeatureSet |
258 PluginSummarisingAdapter::Impl::getRemainingFeatures() | 264 PluginSummarisingAdapter::Impl::getRemainingFeatures() |
259 { | 265 { |
260 if (m_reduced) { | 266 if (m_reduced) { |
261 std::cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << std::endl; | 267 cerr << "WARNING: Cannot call PluginSummarisingAdapter::process() or getRemainingFeatures() after one of the getSummary methods" << endl; |
262 } | 268 } |
263 FeatureSet fs = m_plugin->getRemainingFeatures(); | 269 FeatureSet fs = m_plugin->getRemainingFeatures(); |
264 accumulate(fs, m_endTime, true); | 270 accumulate(fs, m_endTime, true); |
265 return fs; | 271 return fs; |
266 } | 272 } |
268 void | 274 void |
269 PluginSummarisingAdapter::Impl::setSummarySegmentBoundaries(const SegmentBoundaries &b) | 275 PluginSummarisingAdapter::Impl::setSummarySegmentBoundaries(const SegmentBoundaries &b) |
270 { | 276 { |
271 m_boundaries = b; | 277 m_boundaries = b; |
272 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 278 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
273 std::cerr << "PluginSummarisingAdapter::setSummarySegmentBoundaries: boundaries are:" << std::endl; | 279 cerr << "PluginSummarisingAdapter::setSummarySegmentBoundaries: boundaries are:" << endl; |
274 for (SegmentBoundaries::const_iterator i = m_boundaries.begin(); | 280 for (SegmentBoundaries::const_iterator i = m_boundaries.begin(); |
275 i != m_boundaries.end(); ++i) { | 281 i != m_boundaries.end(); ++i) { |
276 std::cerr << *i << " "; | 282 cerr << *i << " "; |
277 } | 283 } |
278 std::cerr << std::endl; | 284 cerr << endl; |
279 #endif | 285 #endif |
280 } | 286 } |
281 | 287 |
282 Plugin::FeatureList | 288 Plugin::FeatureList |
283 PluginSummarisingAdapter::Impl::getSummaryForOutput(int output, | 289 PluginSummarisingAdapter::Impl::getSummaryForOutput(int output, |
418 } | 424 } |
419 } | 425 } |
420 } | 426 } |
421 } | 427 } |
422 | 428 |
423 std::string | 429 string |
424 PluginSummarisingAdapter::Impl::getSummaryLabel(SummaryType type, | 430 PluginSummarisingAdapter::Impl::getSummaryLabel(SummaryType type, |
425 AveragingMethod avg) | 431 AveragingMethod avg) |
426 { | 432 { |
427 std::string label; | 433 string label; |
428 std::string avglabel; | 434 string avglabel; |
429 | 435 |
430 if (avg == SampleAverage) avglabel = ", sample average"; | 436 if (avg == SampleAverage) avglabel = ", sample average"; |
431 else avglabel = ", continuous-time average"; | 437 else avglabel = ", continuous-time average"; |
432 | 438 |
433 switch (type) { | 439 switch (type) { |
448 | 454 |
449 void | 455 void |
450 PluginSummarisingAdapter::Impl::accumulate(int output, | 456 PluginSummarisingAdapter::Impl::accumulate(int output, |
451 const Feature &f, | 457 const Feature &f, |
452 RealTime timestamp, | 458 RealTime timestamp, |
453 bool /* final */) | 459 bool |
460 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | |
461 final | |
462 #endif | |
463 ) | |
454 { | 464 { |
455 // What should happen if a feature's duration spans a segment | 465 // What should happen if a feature's duration spans a segment |
456 // boundary? I think we probably want to chop it, and pretend | 466 // boundary? I think we probably want to chop it, and pretend |
457 // that it appears in both. A very long feature (e.g. key, if the | 467 // that it appears in both. A very long feature (e.g. key, if the |
458 // whole audio is in a single key) might span many or all | 468 // whole audio is in a single key) might span many or all |
464 // to have per-segment accumulators (and the feature value goes | 474 // to have per-segment accumulators (and the feature value goes |
465 // into both -- with a separate phase to split the accumulator up | 475 // into both -- with a separate phase to split the accumulator up |
466 // into segments). | 476 // into segments). |
467 | 477 |
468 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 478 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
469 std::cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << ", final " << final << std::endl; | 479 cerr << "output " << output << ": timestamp " << timestamp << ", prev timestamp " << m_prevTimestamps[output] << ", final " << final << endl; |
470 #endif | 480 #endif |
471 | 481 |
472 // At each process step, accumulate() is called once for each | 482 // At each process step, accumulate() is called once for each |
473 // feature on each output within that process's returned feature | 483 // feature on each output within that process's returned feature |
474 // list, and with the timestamp passed in being that of the start | 484 // list, and with the timestamp passed in being that of the start |
505 // current timestamps. | 515 // current timestamps. |
506 | 516 |
507 if (m_prevDurations[output] != INVALID_DURATION) { | 517 if (m_prevDurations[output] != INVALID_DURATION) { |
508 prevDuration = m_prevDurations[output]; | 518 prevDuration = m_prevDurations[output]; |
509 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 519 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
510 std::cerr << "Previous duration from previous feature: " << prevDuration << std::endl; | 520 cerr << "Previous duration from previous feature: " << prevDuration << endl; |
511 #endif | 521 #endif |
512 } else { | 522 } else { |
513 prevDuration = timestamp - m_prevTimestamps[output]; | 523 prevDuration = timestamp - m_prevTimestamps[output]; |
514 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 524 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
515 std::cerr << "Previous duration from diff: " << timestamp << " - " | 525 cerr << "Previous duration from diff: " << timestamp << " - " |
516 << m_prevTimestamps[output] << std::endl; | 526 << m_prevTimestamps[output] << endl; |
517 #endif | 527 #endif |
518 } | 528 } |
519 | 529 |
520 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 530 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
521 std::cerr << "output " << output << ": "; | 531 cerr << "output " << output << ": "; |
522 std::cerr << "Pushing previous duration as " << prevDuration << std::endl; | 532 cerr << "Pushing previous duration as " << prevDuration << endl; |
523 #endif | 533 #endif |
524 | 534 |
525 m_accumulators[output].results | 535 m_accumulators[output].results |
526 [m_accumulators[output].results.size() - 1] | 536 [m_accumulators[output].results.size() - 1] |
527 .duration = prevDuration; | 537 .duration = prevDuration; |
534 | 544 |
535 if (f.hasDuration) { | 545 if (f.hasDuration) { |
536 RealTime et = timestamp; | 546 RealTime et = timestamp; |
537 et = et + f.duration; | 547 et = et + f.duration; |
538 if (et > m_endTime) m_endTime = et; | 548 if (et > m_endTime) m_endTime = et; |
549 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | |
550 cerr << "feature has duration, updating end time to " << m_endTime << endl; | |
551 #endif | |
539 } | 552 } |
540 | 553 |
541 Result result; | 554 Result result; |
542 result.time = timestamp; | 555 result.time = timestamp; |
543 result.duration = INVALID_DURATION; | 556 result.duration = INVALID_DURATION; |
564 int acount = m_accumulators[output].results.size(); | 577 int acount = m_accumulators[output].results.size(); |
565 | 578 |
566 if (acount == 0) continue; | 579 if (acount == 0) continue; |
567 | 580 |
568 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 581 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
569 std::cerr << "output " << output << ": "; | 582 cerr << "output " << output << ": "; |
570 #endif | 583 #endif |
571 | 584 |
572 if (m_prevDurations.find(output) != m_prevDurations.end() && | 585 if (m_prevDurations.find(output) != m_prevDurations.end() && |
573 m_prevDurations[output] != INVALID_DURATION) { | 586 m_prevDurations[output] != INVALID_DURATION) { |
574 | 587 |
575 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 588 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
576 std::cerr << "Pushing final duration from feature as " << m_prevDurations[output] << std::endl; | 589 cerr << "Pushing final duration from feature as " << m_prevDurations[output] << endl; |
577 #endif | 590 #endif |
578 | 591 |
579 m_accumulators[output].results[acount - 1].duration = | 592 m_accumulators[output].results[acount - 1].duration = |
580 m_prevDurations[output]; | 593 m_prevDurations[output]; |
581 | 594 |
582 } else { | 595 } else { |
583 | 596 |
584 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 597 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
585 std::cerr << "Pushing final duration from diff as " << m_endTime << " - " << m_prevTimestamps[output] << std::endl; | 598 cerr << "Pushing final duration from diff as " << m_endTime << " - " << m_prevTimestamps[output] << endl; |
586 #endif | 599 #endif |
587 | 600 |
588 m_accumulators[output].results[acount - 1].duration = | 601 m_accumulators[output].results[acount - 1].duration = |
589 m_endTime - m_prevTimestamps[output]; | 602 m_endTime - m_prevTimestamps[output]; |
590 } | 603 } |
591 | 604 |
592 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 605 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
593 std::cerr << "so duration for result no " << acount-1 << " is " | 606 cerr << "so duration for result no " << acount-1 << " is " |
594 << m_accumulators[output].results[acount-1].duration | 607 << m_accumulators[output].results[acount-1].duration |
595 << std::endl; | 608 << endl; |
596 #endif | 609 #endif |
597 } | 610 } |
598 } | 611 } |
599 | 612 |
600 void | 613 void |
601 PluginSummarisingAdapter::Impl::findSegmentBounds(RealTime t, | 614 PluginSummarisingAdapter::Impl::findSegmentBounds(RealTime t, |
602 RealTime &start, | 615 RealTime &start, |
603 RealTime &end) | 616 RealTime &end) |
604 { | 617 { |
605 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 618 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
606 std::cerr << "findSegmentBounds: t = " << t << std::endl; | 619 cerr << "findSegmentBounds: t = " << t << endl; |
607 #endif | 620 #endif |
608 | 621 |
609 SegmentBoundaries::const_iterator i = std::upper_bound | 622 SegmentBoundaries::const_iterator i = upper_bound |
610 (m_boundaries.begin(), m_boundaries.end(), t); | 623 (m_boundaries.begin(), m_boundaries.end(), t); |
611 | 624 |
612 start = RealTime::zeroTime; | 625 start = RealTime::zeroTime; |
613 end = m_endTime; | 626 end = m_endTime; |
614 | 627 |
619 if (i != m_boundaries.begin()) { | 632 if (i != m_boundaries.begin()) { |
620 start = *--i; | 633 start = *--i; |
621 } | 634 } |
622 | 635 |
623 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 636 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
624 std::cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << std::endl; | 637 cerr << "findSegmentBounds: " << t << " is in segment " << start << " -> " << end << endl; |
625 #endif | 638 #endif |
626 } | 639 } |
627 | 640 |
628 void | 641 void |
629 PluginSummarisingAdapter::Impl::segment() | 642 PluginSummarisingAdapter::Impl::segment() |
630 { | 643 { |
631 SegmentBoundaries::iterator boundaryitr = m_boundaries.begin(); | 644 SegmentBoundaries::iterator boundaryitr = m_boundaries.begin(); |
632 | 645 |
633 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 646 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
634 std::cerr << "segment: starting" << std::endl; | 647 cerr << "segment: starting" << endl; |
635 #endif | 648 #endif |
636 | 649 |
637 for (OutputAccumulatorMap::iterator i = m_accumulators.begin(); | 650 for (OutputAccumulatorMap::iterator i = m_accumulators.begin(); |
638 i != m_accumulators.end(); ++i) { | 651 i != m_accumulators.end(); ++i) { |
639 | 652 |
640 int output = i->first; | 653 int output = i->first; |
641 OutputAccumulator &source = i->second; | 654 OutputAccumulator &source = i->second; |
642 | 655 |
643 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 656 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
644 std::cerr << "segment: total results for output " << output << " = " | 657 cerr << "segment: total results for output " << output << " = " |
645 << source.results.size() << std::endl; | 658 << source.results.size() << endl; |
646 #endif | 659 #endif |
647 | 660 |
648 // This is basically nonsense if the results have no values | 661 // This is basically nonsense if the results have no values |
649 // (i.e. their times and counts are the only things of | 662 // (i.e. their times and counts are the only things of |
650 // interest)... but perhaps it's the user's problem if they | 663 // interest)... but perhaps it's the user's problem if they |
658 | 671 |
659 RealTime resultStart = source.results[n].time; | 672 RealTime resultStart = source.results[n].time; |
660 RealTime resultEnd = resultStart + source.results[n].duration; | 673 RealTime resultEnd = resultStart + source.results[n].duration; |
661 | 674 |
662 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 675 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
663 std::cerr << "output: " << output << ", result start = " << resultStart << ", end = " << resultEnd << std::endl; | 676 cerr << "output: " << output << ", result start = " << resultStart << ", end = " << resultEnd << endl; |
664 #endif | 677 #endif |
665 | 678 |
666 RealTime segmentStart = RealTime::zeroTime; | 679 RealTime segmentStart = RealTime::zeroTime; |
667 RealTime segmentEnd = resultEnd - RealTime(1, 0); | 680 RealTime segmentEnd = resultEnd - RealTime(1, 0); |
668 | 681 |
669 RealTime prevSegmentStart = segmentStart - RealTime(1, 0); | 682 RealTime prevSegmentStart = segmentStart - RealTime(1, 0); |
670 | 683 |
671 while (segmentEnd < resultEnd) { | 684 while (segmentEnd < resultEnd) { |
672 | 685 |
673 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 686 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
674 std::cerr << "segment end " << segmentEnd << " < result end " | 687 cerr << "segment end " << segmentEnd << " < result end " |
675 << resultEnd << " (with result start " << resultStart << ")" << std::endl; | 688 << resultEnd << " (with result start " << resultStart << ")" << endl; |
676 #endif | 689 #endif |
677 | 690 |
678 findSegmentBounds(resultStart, segmentStart, segmentEnd); | 691 findSegmentBounds(resultStart, segmentStart, segmentEnd); |
679 | 692 |
680 if (segmentStart == prevSegmentStart) { | 693 if (segmentStart == prevSegmentStart) { |
697 chunk.time = chunkStart; | 710 chunk.time = chunkStart; |
698 chunk.duration = chunkEnd - chunkStart; | 711 chunk.duration = chunkEnd - chunkStart; |
699 chunk.values = source.results[n].values; | 712 chunk.values = source.results[n].values; |
700 | 713 |
701 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT | 714 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER_SEGMENT |
702 std::cerr << "chunk for segment " << segmentStart << ": from " << chunk.time << ", duration " << chunk.duration << std::endl; | 715 cerr << "chunk for segment " << segmentStart << ": from " << chunk.time << ", duration " << chunk.duration << endl; |
703 #endif | 716 #endif |
704 | 717 |
705 m_segmentedAccumulators[output][segmentStart].results | 718 m_segmentedAccumulators[output][segmentStart].results |
706 .push_back(chunk); | 719 .push_back(chunk); |
707 | 720 |
750 OutputAccumulator &accumulator = j->second; | 763 OutputAccumulator &accumulator = j->second; |
751 | 764 |
752 int sz = accumulator.results.size(); | 765 int sz = accumulator.results.size(); |
753 | 766 |
754 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 767 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
755 std::cerr << "reduce: segment starting at " << segmentStart | 768 cerr << "reduce: segment starting at " << segmentStart |
756 << " on output " << output << " has " << sz << " result(s)" << std::endl; | 769 << " on output " << output << " has " << sz << " result(s)" << endl; |
757 #endif | 770 #endif |
758 | 771 |
759 double totalDuration = 0.0; | 772 double totalDuration = 0.0; |
760 //!!! is this right? | 773 //!!! is this right? |
761 if (sz > 0) { | 774 if (sz > 0) { |
762 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 775 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
763 std::cerr << "last time = " << accumulator.results[sz-1].time | 776 cerr << "last time = " << accumulator.results[sz-1].time |
764 << ", duration = " << accumulator.results[sz-1].duration | 777 << ", duration = " << accumulator.results[sz-1].duration |
765 << " (step = " << m_stepSize << ", block = " << m_blockSize << ")" | 778 << " (step = " << m_stepSize << ", block = " << m_blockSize << ")" |
766 << std::endl; | 779 << endl; |
767 #endif | 780 #endif |
768 totalDuration = toSec((accumulator.results[sz-1].time + | 781 totalDuration = toSec((accumulator.results[sz-1].time + |
769 accumulator.results[sz-1].duration) - | 782 accumulator.results[sz-1].duration) - |
770 segmentStart); | 783 segmentStart); |
771 } | 784 } |
772 | 785 |
773 for (int bin = 0; bin < accumulator.bins; ++bin) { | 786 for (int bin = 0; bin < accumulator.bins; ++bin) { |
774 | 787 |
775 // work on all values over time for a single bin | 788 // work on all values over time for a single bin |
776 | 789 |
790 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | |
791 cerr << "bin " << bin << ":" << endl; | |
792 #endif | |
793 | |
777 OutputBinSummary summary; | 794 OutputBinSummary summary; |
778 | 795 |
779 summary.count = sz; | 796 summary.count = sz; |
780 | 797 |
781 summary.minimum = 0.f; | 798 summary.minimum = 0.f; |
791 summary.mean_c = 0.f; | 808 summary.mean_c = 0.f; |
792 summary.variance_c = 0.f; | 809 summary.variance_c = 0.f; |
793 | 810 |
794 if (sz == 0) continue; | 811 if (sz == 0) continue; |
795 | 812 |
796 std::vector<ValueDurationFloatPair> valvec; | 813 vector<ValueDurationFloatPair> valvec; |
797 | 814 |
798 for (int k = 0; k < sz; ++k) { | 815 for (int k = 0; k < sz; ++k) { |
799 while (int(accumulator.results[k].values.size()) < | 816 while (int(accumulator.results[k].values.size()) < |
800 accumulator.bins) { | 817 accumulator.bins) { |
801 accumulator.results[k].values.push_back(0.f); | 818 accumulator.results[k].values.push_back(0.f); |
807 valvec.push_back(ValueDurationFloatPair | 824 valvec.push_back(ValueDurationFloatPair |
808 (value, | 825 (value, |
809 toSec(accumulator.results[k].duration))); | 826 toSec(accumulator.results[k].duration))); |
810 } | 827 } |
811 | 828 |
812 std::sort(valvec.begin(), valvec.end()); | 829 sort(valvec.begin(), valvec.end()); |
813 | 830 |
814 summary.minimum = valvec[0].value; | 831 summary.minimum = valvec[0].value; |
815 summary.maximum = valvec[sz-1].value; | 832 summary.maximum = valvec[sz-1].value; |
816 | 833 |
817 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 834 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
818 std::cerr << "total duration = " << totalDuration << std::endl; | 835 cerr << "total duration = " << totalDuration << endl; |
819 #endif | 836 #endif |
820 | 837 |
821 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 838 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
822 /* | 839 /* |
823 std::cerr << "value vector for medians:" << std::endl; | 840 cerr << "value vector for medians:" << endl; |
824 for (int k = 0; k < sz; ++k) { | 841 for (int k = 0; k < sz; ++k) { |
825 std::cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") "; | 842 cerr << "(" << valvec[k].value << "," << valvec[k].duration << ") "; |
826 } | 843 } |
827 std::cerr << std::endl; | 844 cerr << endl; |
828 */ | 845 */ |
829 #endif | 846 #endif |
830 | 847 |
831 if (sz % 2 == 1) { | 848 if (sz % 2 == 1) { |
832 summary.median = valvec[sz/2].value; | 849 summary.median = valvec[sz/2].value; |
844 break; | 861 break; |
845 } | 862 } |
846 } | 863 } |
847 | 864 |
848 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 865 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
849 std::cerr << "median_c = " << summary.median_c << std::endl; | 866 cerr << "median_c = " << summary.median_c << endl; |
850 std::cerr << "median = " << summary.median << std::endl; | 867 cerr << "median = " << summary.median << endl; |
851 #endif | 868 #endif |
852 | 869 |
853 std::map<float, int> distribution; | 870 map<float, int> distribution; |
854 | 871 |
855 for (int k = 0; k < sz; ++k) { | 872 for (int k = 0; k < sz; ++k) { |
856 summary.sum += accumulator.results[k].values[bin]; | 873 summary.sum += accumulator.results[k].values[bin]; |
857 distribution[accumulator.results[k].values[bin]] += 1; | 874 distribution[accumulator.results[k].values[bin]] += 1; |
858 } | 875 } |
859 | 876 |
860 int md = 0; | 877 int md = 0; |
861 | 878 |
862 for (std::map<float, int>::iterator di = distribution.begin(); | 879 for (map<float, int>::iterator di = distribution.begin(); |
863 di != distribution.end(); ++di) { | 880 di != distribution.end(); ++di) { |
864 if (di->second > md) { | 881 if (di->second > md) { |
865 md = di->second; | 882 md = di->second; |
866 summary.mode = di->first; | 883 summary.mode = di->first; |
867 } | 884 } |
868 } | 885 } |
869 | 886 |
870 distribution.clear(); | 887 distribution.clear(); |
871 | 888 |
872 std::map<float, double> distribution_c; | 889 map<float, double> distribution_c; |
873 | 890 |
874 for (int k = 0; k < sz; ++k) { | 891 for (int k = 0; k < sz; ++k) { |
875 distribution_c[accumulator.results[k].values[bin]] | 892 distribution_c[accumulator.results[k].values[bin]] |
876 += toSec(accumulator.results[k].duration); | 893 += toSec(accumulator.results[k].duration); |
877 } | 894 } |
878 | 895 |
879 double mrd = 0.0; | 896 double mrd = 0.0; |
880 | 897 |
881 for (std::map<float, double>::iterator di = distribution_c.begin(); | 898 for (map<float, double>::iterator di = distribution_c.begin(); |
882 di != distribution_c.end(); ++di) { | 899 di != distribution_c.end(); ++di) { |
883 if (di->second > mrd) { | 900 if (di->second > mrd) { |
884 mrd = di->second; | 901 mrd = di->second; |
885 summary.mode_c = di->first; | 902 summary.mode_c = di->first; |
886 } | 903 } |
897 * toSec(accumulator.results[k].duration); | 914 * toSec(accumulator.results[k].duration); |
898 sum_c += value; | 915 sum_c += value; |
899 } | 916 } |
900 | 917 |
901 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 918 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
902 std::cerr << "mean_c = " << sum_c << " / " << totalDuration << " = " | 919 cerr << "mean_c = " << sum_c << " / " << totalDuration << " = " |
903 << sum_c / totalDuration << " (sz = " << sz << ")" << std::endl; | 920 << sum_c / totalDuration << " (sz = " << sz << ")" << endl; |
904 #endif | 921 #endif |
905 | 922 |
906 summary.mean_c = sum_c / totalDuration; | 923 summary.mean_c = sum_c / totalDuration; |
907 | 924 |
908 for (int k = 0; k < sz; ++k) { | 925 for (int k = 0; k < sz; ++k) { |
918 } | 935 } |
919 | 936 |
920 double mean = summary.sum / summary.count; | 937 double mean = summary.sum / summary.count; |
921 | 938 |
922 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER | 939 #ifdef DEBUG_PLUGIN_SUMMARISING_ADAPTER |
923 std::cerr << "mean = " << summary.sum << " / " << summary.count << " = " | 940 cerr << "mean = " << summary.sum << " / " << summary.count << " = " |
924 << summary.sum / summary.count << std::endl; | 941 << summary.sum / summary.count << endl; |
925 #endif | 942 #endif |
926 | 943 |
927 for (int k = 0; k < sz; ++k) { | 944 for (int k = 0; k < sz; ++k) { |
928 float value = accumulator.results[k].values[bin]; | 945 float value = accumulator.results[k].values[bin]; |
929 summary.variance += (value - mean) * (value - mean); | 946 summary.variance += (value - mean) * (value - mean); |