def covers(self, proposal, min_match): """ Return True if any template in the bank has match with proposal greater than min_match. """ # find templates in the bank "near" this tmplt prop_nhd = getattr(proposal, self.nhood_param) low, high = _find_neighborhood(self._nhoods, prop_nhd, self.nhood_size) tmpbank = self._templates[low:high] if not tmpbank: return False # sort the bank by its nearness to tmplt in mchirp # NB: This sort comes up as a dominating cost if you profile, # but it cuts the number of match evaluations by 80%, so turns out # to be worth it even for metric match, where matches are cheap. tmpbank.sort(key=lambda b: abs( getattr(b, self.nhood_param) - prop_nhd)) # set parameters of match calculation that are optimized for this block df_end, f_max = get_neighborhood_df_fmax(tmpbank + [proposal], self.flow) df_start = max(df_end, self.iterative_match_df_max) # find and test matches for tmplt in tmpbank: self._nmatch += 1 df = df_start match_last = 0 if self.coarse_match_df: # Perform a match at high df to see if point can be quickly # ruled out as already covering the proposal PSD = get_PSD(self.coarse_match_df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, self.coarse_match_df, PSD=PSD) if (1 - match) > 4.0*(1 - min_match): continue while df >= df_end: PSD = get_PSD(df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, df, PSD=PSD) # if the result is a really bad match, trust it isn't # misrepresenting a good match if (1 - match) > 4.0*(1 - min_match): break # calculation converged if match_last > 0 and abs(match_last - match) < 0.001: break # otherwise, refine calculation match_last = match df /= 2.0 if match > min_match: return True return False
def covers(self, proposal, min_match, nhood=None): """ Return (max_match, template) where max_match is either (i) the best found match if max_match < min_match or (ii) the match of the first template found with match >= min_match. template is the Template() object which yields max_match. """ max_match = 0 template = None # find templates in the bank "near" this tmplt prop_nhd = getattr(proposal, self.nhood_param) if not nhood: low, high = _find_neighborhood(self._nhoods, prop_nhd, self.nhood_size) tmpbank = self._templates[low:high] else: tmpbank = nhood if not tmpbank: return (max_match, template) # sort the bank by its nearness to tmplt in mchirp # NB: This sort comes up as a dominating cost if you profile, # but it cuts the number of match evaluations by 80%, so turns out # to be worth it even for metric match, where matches are cheap. tmpbank.sort(key=lambda b: abs( getattr(b, self.nhood_param) - prop_nhd)) # set parameters of match calculation that are optimized for this block df_end, f_max = get_neighborhood_df_fmax(tmpbank + [proposal], self.flow) if self.fhigh_max: f_max = min(f_max, self.fhigh_max) df_start = max(df_end, self.iterative_match_df_max) # find and test matches for tmplt in tmpbank: self._nmatch += 1 df = df_start match_last = 0 if self.coarse_match_df: # Perform a match at high df to see if point can be quickly # ruled out as already covering the proposal PSD = get_PSD(self.coarse_match_df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, self.coarse_match_df, PSD=PSD) if match == 0: err_msg = "Match is 0. This might indicate that you have " err_msg += "the df value too high. Please try setting the " err_msg += "coarse-value-df value lower." # FIXME: This could be dealt with dynamically?? raise ValueError(err_msg) if (1 - match) > 0.05 + (1 - min_match): continue while df >= df_end: PSD = get_PSD(df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, df, PSD=PSD) if match == 0: err_msg = "Match is 0. This might indicate that you have " err_msg += "the df value too high. Please try setting the " err_msg += "iterative-match-df-max value lower." # FIXME: This could be dealt with dynamically?? raise ValueError(err_msg) # if the result is a really bad match, trust it isn't # misrepresenting a good match if (1 - match) > 0.05 + (1 - min_match): break # calculation converged if match_last > 0 and abs(match_last - match) < 0.001: break # otherwise, refine calculation match_last = match df /= 2.0 if match > min_match: return (match, tmplt) # record match and template params for highest match if match > max_match: max_match = match template = tmplt return (max_match, template)
def covers(self, proposal, min_match, nhood=None): """ Return (max_match, template) where max_match is either (i) the best found match if max_match < min_match or (ii) the match of the first template found with match >= min_match. template is the Template() object which yields max_match. """ max_match = 0 template = None # find templates in the bank "near" this tmplt prop_nhd = getattr(proposal, self.nhood_param) if not nhood: low, high = _find_neighborhood(self._nhoods, prop_nhd, self.nhood_size) tmpbank = self._templates[low:high] else: tmpbank = nhood if not tmpbank: return (max_match, template) # sort the bank by its nearness to tmplt in mchirp # NB: This sort comes up as a dominating cost if you profile, # but it cuts the number of match evaluations by 80%, so turns out # to be worth it even for metric match, where matches are cheap. tmpbank.sort( key=lambda b: abs(getattr(b, self.nhood_param) - prop_nhd)) # set parameters of match calculation that are optimized for this block df_end, f_max = get_neighborhood_df_fmax(tmpbank + [proposal], self.flow) if self.fhigh_max: f_max = min(f_max, self.fhigh_max) df_start = max(df_end, self.iterative_match_df_max) # find and test matches for tmplt in tmpbank: self._nmatch += 1 df = df_start match_last = 0 if self.coarse_match_df: # Perform a match at high df to see if point can be quickly # ruled out as already covering the proposal PSD = get_PSD(self.coarse_match_df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, self.coarse_match_df, PSD=PSD) if match == 0: err_msg = "Match is 0. This might indicate that you have " err_msg += "the df value too high. Please try setting the " err_msg += "coarse-value-df value lower." # FIXME: This could be dealt with dynamically?? raise ValueError(err_msg) # record match and template params for highest match if match > max_match: max_match = match template = tmplt if (1 - match) > 0.05 + (1 - min_match): continue while df >= df_end: PSD = get_PSD(df, self.flow, f_max, self.noise_model) match = self.compute_match(tmplt, proposal, df, PSD=PSD) if match == 0: err_msg = "Match is 0. This might indicate that you have " err_msg += "the df value too high. Please try setting the " err_msg += "iterative-match-df-max value lower." # FIXME: This could be dealt with dynamically?? raise ValueError(err_msg) # record match and template params for highest match if match > max_match: max_match = match template = tmplt # if the result is a really bad match, trust it isn't # misrepresenting a good match if (1 - match) > 0.05 + (1 - min_match): break # calculation converged if match_last > 0 and abs(match_last - match) < 0.001: break # otherwise, refine calculation match_last = match df /= 2.0 if match > min_match: return (match, tmplt) return (max_match, template)