def _decide_default( self, peaks: Peaks, corpus: Corpus, transform_handler: TransformHandler, **kwargs) -> Optional[Tuple[CorpusEvent, AbstractTransform]]: if peaks.is_empty(): return None max_peak_value: float = np.max(peaks.scores) if max_peak_value < self.threshold: return None else: return super()._decide_default(peaks, corpus, transform_handler)
def _decide_default( self, peaks: Peaks, corpus: Corpus, transform_handler: TransformHandler, **kwargs) -> Optional[Tuple[CorpusEvent, AbstractTransform]]: if peaks.is_empty(): return None score_cumsum: np.ndarray = np.cumsum(peaks.scores) max_value: float = score_cumsum[ -1] - 1e-5 # slight offset to avoid an extremely rare case of a fp error output_target_score: float = float(np.random.random(1) * max_value) peak_idx: int = np.argwhere(score_cumsum > output_target_score)[0] transform_hash: int = int(peaks.transform_ids[peak_idx]) return corpus.event_around( peaks.times[peak_idx]), transform_handler.get_transform( transform_hash)
def _scale_peaks(self, peaks: Peaks, scheduler_time: float, corpus: Corpus, **kwargs): if peaks.is_empty(): return peaks corresponding_events: List[CorpusEvent] = corpus.events_around( peaks.times) corresponding_transforms: List[AbstractTransform] = [ self._transform_handler.get_transform(t) for t in np.unique(peaks.transform_ids) ] for scale_action in self.scale_actions.values(): if scale_action.is_enabled_and_eligible(): peaks = scale_action.scale(peaks, scheduler_time, corresponding_events, corresponding_transforms, corpus, **kwargs) return peaks
def _decide_default( self, peaks: Peaks, corpus: Corpus, transform_handler: TransformHandler, **kwargs) -> Optional[Tuple[CorpusEvent, AbstractTransform]]: self.logger.debug("[decide] _decide_default called.") if peaks.is_empty(): return None max_peak_value: float = np.max(peaks.scores) self.logger.debug( f"[decide_default] Max peak value is {max_peak_value}.") max_peaks_idx: List[int] = np.argwhere( np.abs(peaks.scores - max_peak_value) < 0.001) peak_idx: int = random.choice(max_peaks_idx) transform_hash: int = int(peaks.transform_ids[peak_idx]) return corpus.event_around( peaks.times[peak_idx]), transform_handler.get_transform( transform_hash)