31 from fpconst
import NegInf
34 NegInf = float(
"-inf")
39 from scipy
import interpolate
40 from scipy
import stats
46 from ligo.lw
import ligolw
47 from ligo.lw
import lsctables
48 from ligo.lw
import array
as ligolw_array
49 from ligo.lw
import param
as ligolw_param
50 from ligo.lw
import utils
as ligolw_utils
51 from ligo
import segments
52 from gstlal
import chirptime
53 from gstlal.stats
import horizonhistory
54 from gstlal.stats
import inspiral_extrinsics
55 from gstlal.stats
import inspiral_intrinsics
56 from gstlal.stats
import trigger_rate
59 from lalburst
import snglcoinc
67 from gstlal
import paths
as gstlal_config_paths
73 "DatalessLnSignalDensity",
74 "DatalessLnNoiseDensity",
75 "OnlineFrankensteinLnSignalDensity",
76 "OnlineFrankensteinLnNoiseDensity"
82 TYPICAL_HORIZON_DISTANCE = 150.
86 def idq_interp(idq_file):
89 for ifo
in (
"H1",
"L1",
"V1",
"K1"):
90 out[ifo] =
lambda x: numpy.zeros(len(x))
91 if idq_file
is not None:
93 from scipy.interpolate
import interp1d
94 f = h5py.File(idq_file,
"r")
97 t = [0.] + list(numpy.array(f[ifo][
"time"])) + [2000000000.]
98 d = [0.] + list(numpy.array(f[ ifo][
"data"])) + [0.]
99 out[ifo] = interp1d(t, d)
115 chi2_over_snr2_min = 1e-5
116 chi2_over_snr2_max = 1e20
119 snr_chi_binning = rate.NDBins((rate.ATanLogarithmicBins(2.6, 26., 300), rate.ATanLogarithmicBins(.001, 0.2, 280)))
121 def __init__(self, template_ids, instruments, delta_t, min_instruments = 2):
126 if template_ids
is not None and not template_ids:
127 raise ValueError(
"template_ids cannot be empty")
128 if min_instruments < 1:
129 raise ValueError(
"min_instruments=%d must be >= 1" % min_instruments)
130 if min_instruments > len(instruments):
131 raise ValueError(
"not enough instruments (%s) to satisfy min_instruments=%d" % (
", ".join(sorted(instruments)), min_instruments))
133 raise ValueError(
"delta_t=%g must be >= 0" % delta_t)
139 self.
template_ids = frozenset(template_ids)
if template_ids
is not None else template_ids
145 for instrument
in instruments:
148 def __iadd__(self, other):
149 if type(other) != type(self):
150 raise TypeError(other)
156 raise ValueError(
"incompatible template IDs")
158 raise ValueError(
"incompatible instrument sets")
160 raise ValueError(
"incompatible minimum number of instruments")
161 if self.
delta_t != other.delta_t:
162 raise ValueError(
"incompatible delta_t coincidence thresholds")
164 if self.
template_ids is None and other.template_ids
is not None:
167 for key, lnpdf
in self.densities.items():
168 lnpdf += other.densities[key]
172 except AttributeError:
176 def increment(self, event):
181 raise ValueError(
"event from wrong template")
203 self.
densities[
"%s_snr_chi" % event.ifo].count[event.snr, event.chisq / event.snr**2.] += 1.0
207 for key, lnpdf
in self.densities.items():
208 new.densities[key] = lnpdf.copy()
212 self.
interps = dict((key, lnpdf.mkinterp())
for key, lnpdf
in self.densities.items())
215 snr_kernel_width_at_8 = 8.,
216 chisq_kernel_width = 0.08,
218 for key, lnpdf
in self.densities.items():
223 numsamples = max(lnpdf.array.sum() / 10. + 1., 1e6)
224 snr_bins, chisq_bins = lnpdf.bins
225 snr_per_bin_at_8 = (snr_bins.upper() - snr_bins.lower())[snr_bins[8.]]
226 chisq_per_bin_at_0_02 = (chisq_bins.upper() - chisq_bins.lower())[chisq_bins[0.02]]
230 snr_kernel_bins = snr_kernel_width_at_8 / snr_per_bin_at_8 / numsamples**(1./6.)
231 chisq_kernel_bins = chisq_kernel_width / chisq_per_bin_at_0_02 / numsamples**(1./6.)
235 if snr_kernel_bins < 2.5:
236 snr_kernel_bins = 2.5
237 warnings.warn(
"Replacing snr kernel bins with 2.5")
238 if chisq_kernel_bins < 2.5:
239 chisq_kernel_bins = 2.5
240 warnings.warn(
"Replacing chisq kernel bins with 2.5")
243 rate.filter_array(lnpdf.array, rate.gaussian_window(snr_kernel_bins, chisq_kernel_bins, sigma = sigma))
248 lnpdf.array[:lnpdf.bins[0][self.
snr_min],:] = 0.
261 def to_xml(*args, **kwargs):
262 raise NotImplementedError(
"writing .finish()'ed LnLRDensity object to disk is forbidden")
264 def finish(*args, **kwargs):
265 raise NotImplementedError(
".finish()ing a .finish()ed LnLRDensity object is forbidden")
268 def to_xml(self, name):
269 xml = super(LnLRDensity, self).to_xml(name)
270 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"template_ids",
",".join(
"%d" % template_id
for template_id
in sorted(self.
template_ids))
if self.
template_ids is not None else None))
272 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"instruments", lsctables.instrumentsproperty.set(self.
instruments)))
273 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"min_instruments", self.
min_instruments))
274 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"delta_t", self.
delta_t))
275 for key, lnpdf
in self.densities.items():
279 xml.appendChild(lnpdf.to_xml(key))
283 def from_xml(cls, xml, name):
284 xml = cls.get_xml_root(xml, name)
285 template_ids = ligolw_param.get_pyvalue(xml,
u"template_ids")
293 if template_ids
is not None:
294 template_ids = frozenset(int(i)
for i
in template_ids.split(
","))
296 template_ids = template_ids,
297 instruments = lsctables.instrumentsproperty.get(ligolw_param.get_pyvalue(xml,
u"instruments")),
298 delta_t = ligolw_param.get_pyvalue(xml,
u"delta_t"),
299 min_instruments = ligolw_param.get_pyvalue(xml,
u"min_instruments")
316 def __init__(self, *args, **kwargs):
320 self.
idq_file = kwargs.pop(
"idq_file",
None)
321 super(LnSignalDensity, self).__init__(*args, **kwargs)
338 def set_horizon_factors(self, horizon_factors):
341 def __call__(self, segments, snrs, chi2s_over_snr2s, phase, dt, template_id):
348 assert all(segments.values()),
"encountered trigger with duration = 0"
349 horizons = dict((instrument, (self.
horizon_history[instrument].functional_integral(map(float, seg),
lambda d: d**3.) / float(abs(seg)))**(1./3.))
for instrument, seg
in segments.items())
370 horizon = sorted(horizons.values())[-self.
min_instruments] / TYPICAL_HORIZON_DISTANCE
382 lnP += math.log(self.InspiralExtrinsics.p_of_instruments_given_horizons(snrs.keys(), horizons))
389 lnP += math.log(self.InspiralExtrinsics.time_phase_snr(dt, phase, snrs, horizons))
395 lnP += self.population_model.lnP_template_signal(template_id, max(snrs.values()))
399 interp = self.
interps[
"snr_chi"]
402 for ifo, seg
in segments.items():
410 return lnP + sum(interp(snrs[instrument], chi2_over_snr2)
for instrument, chi2_over_snr2
in chi2s_over_snr2s.items())
412 def __iadd__(self, other):
413 super(LnSignalDensity, self).__iadd__(other)
416 raise ValueError(
"incompatible mass model file names")
419 if self.
dtdphi_file is not None and other.dtdphi_file
is not None and other.dtdphi_file != self.
dtdphi_file:
420 raise ValueError(
"incompatible dtdphi files")
421 if self.
dtdphi_file is None and other.dtdphi_file
is not None:
423 if self.
idq_file is not None and other.idq_file
is not None and other.idq_file != self.
idq_file:
424 raise ValueError(
"incompatible idq files")
425 if self.
idq_file is None and other.idq_file
is not None:
431 raise ValueError(
"incompatible horizon_factors")
437 def increment(self, *args, **kwargs):
438 raise NotImplementedError
441 new = super(LnSignalDensity, self).copy()
442 new.horizon_history = self.horizon_history.copy()
453 def local_mean_horizon_distance(self, gps, window = segments.segment(-32., +2.)):
462 vtdict = self.horizon_history.functional_integral_dict(window.shift(float(gps)),
lambda D: D**3.)
463 return dict((instrument, (vt / t)**(1./3.))
for instrument, vt
in vtdict.items())
465 def add_signal_model(self, prefactors_range = (0.001, 0.30), df = 100, inv_snr_pow = 4.):
468 inspiral_extrinsics.NumeratorSNRCHIPDF.add_signal_model(self.
densities[
"snr_chi"], 1e12, prefactors_range, df, inv_snr_pow = inv_snr_pow, snr_min = self.
snr_min)
473 Compute and return a prediction for the total number of
474 above-threshold signal candidates expected. The rate
475 parameter sets the nominal signal rate in units of Gpc^-3
481 seg = (self.horizon_history.minkey(), self.horizon_history.maxkey())
482 V_times_t = self.horizon_history.functional_integral(seg,
lambda horizons: sorted(horizons.values())[-self.
min_instruments]**3.)
484 V_times_t *= 1e-9 / (86400. * 365.25)
489 Generator that yields an endless sequence of randomly
490 generated parameter dictionaries drawn from the
491 distribution of parameters expected for the given
492 injection, which is an instance of a SimInspiral table row
493 object (see ligo.lw.lsctables.SimInspiral for more
494 information). Each value in the sequence is a tuple, the
495 first element of which is the random parameter dictionary
500 LnNoiseDensity.random_params()
502 The parameters do not necessarily represent valid
503 candidates, for example the number of detectors reporting a
504 trigger might be less than the .min_instruments parameter
505 configured for the ranking statistic. It is the job of the
506 calling code to check the parameters for validity before
507 using them to compute ranking statistic values. This is
508 done to allow the calling code to measure the frequency
509 with which the injection is expected to be undetectable.
510 Otherwise, the sequence is suitable for input to the
511 .ln_lr_samples() log likelihood ratio generator.
515 The second element in each tuple in the sequence is merely
516 a placeholder, not the natural logarithm of the PDF from
517 which the sample has been drawn, as in the case of
518 random_params(). Therefore, when used in combination with
519 .ln_lr_samples(), the two probability densities computed
520 and returned by that generator along with each log
521 likelihood ratio value will simply be the probability
522 densities of the signal and noise populations at that point
523 in parameter space. They cannot be used to form an
524 importance weighted sampler of the log likelihood ratios.
540 cosi = math.cos(sim.inclination)
541 gmst = lal.GreenwichMeanSiderealTime(sim.time_geocent)
545 params = {
u"H1":
"alpha4",
u"L1":
"alpha5",
u"V1":
"alpha6"}
547 fp, fc = lal.ComputeDetAMResponse(lalsimulation.DetectorPrefixToLALDetector(str(instrument)).response, sim.longitude, sim.latitude, sim.polarization, gmst)
548 snr_0[instrument] = getattr(sim, params[instrument])
if horizon_distance[instrument] != 0.
else 0.
549 phase_0[instrument] = math.atan2(fc * cosi, fp * (1. + cosi**2.)/2.) - 2*sim.coa_phase + numpy.pi/2.
550 phase_0[instrument] = phase_0[instrument] - math.floor((phase_0[instrument] + numpy.pi)/numpy.pi/2.)*numpy.pi*2
556 template_duration =
chirptime.imr_time(f_low, sim.mass1*lal.MSUN_SI, sim.mass2*lal.MSUN_SI, numpy.sqrt(numpy.dot(sim.spin1, sim.spin1)), numpy.sqrt(numpy.dot(sim.spin2, sim.spin2)))
565 def snr_phase_gen(snr0, phase):
574 snr0 = cmath.rect(snr0, phase)
575 randn = numpy.random.randn
577 yield cmath.polar(snr0 + complex(*randn(2)))
578 def chi2_over_snr2_gen(snr):
580 rates_lnx = numpy.log(self.
densities[
"snr_chi"].bins[1].centres())
584 assert not numpy.isnan(rates_cdf).any()
586 drcoss = self.
densities[
"snr_chi"].bins[1].upper() - self.
densities[
"snr_chi"].bins[1].lower()
587 rates_cdf =(numpy.exp(rates_cdf)[:-1]*drcoss[:-1]).cumsum()
588 assert not numpy.isnan(rates_cdf).any()
592 rates_cdf += numpy.linspace(0., 0.00001 * rates_cdf[-1], len(rates_cdf))
593 rates_cdf /= rates_cdf[-1]
596 assert rates_cdf[-1] == 1.0
597 assert not numpy.isnan(rates_cdf).any()
599 interp = interpolate.interp1d(rates_cdf, rates_lnx[:-1])
603 random_random = random.random
605 yield math_exp(interp(random_random()))
608 rvs = stats.norm(loc=time, scale = 0.002).rvs
613 snr_phase = dict((instrument, iter(snr_phase_gen(snr, phase_0[instrument])).__next__)
for instrument, snr
in snr_0.items())
615 gens_t = dict((instrument, iter(time_gen(sim.time_at_instrument(instrument, {instrument: 0.0}))).__next__)
for instrument
in self.
instruments)
626 "chi2s_over_snr2s": {},
628 "dt": dict((instrument, time())
for instrument, time
in gens_t.items()),
629 "template_id": template_id
if template_id
else random.choice(template_ids)
631 ref_end = kwargs[
"dt"][min(kwargs[
"dt"])]
632 for instrument, time
in list(kwargs[
"dt"].items()):
633 kwargs[
"segments"][instrument] = segments.segment(time - template_duration, time)
634 kwargs[
"snrs"][instrument], kwargs[
"phase"][instrument] = snr_phase[instrument]()
635 kwargs[
"chi2s_over_snr2s"][instrument] = chi2_over_snr2_gen(kwargs[
"snrs"][instrument]).__next__()
636 kwargs[
"dt"][instrument] = time - ref_end
639 def to_xml(self, name):
640 xml = super(LnSignalDensity, self).to_xml(name)
641 xml.appendChild(self.horizon_history.to_xml(
u"horizon_history"))
642 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"population_model_file", self.
population_model_file))
643 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"horizon_factors", json.dumps(self.
horizon_factors)
if self.
horizon_factors is not None else None))
644 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"dtdphi_file", self.
dtdphi_file))
645 xml.appendChild(ligolw_param.Param.from_pyvalue(
u"idq_file", self.
idq_file))
649 def from_xml(cls, xml, name):
650 xml = cls.get_xml_root(xml, name)
651 self = super(LnSignalDensity, cls).from_xml(xml, name)
652 self.
horizon_history = horizonhistory.HorizonHistories.from_xml(xml,
u"horizon_history")
654 self.
dtdphi_file = ligolw_param.get_pyvalue(xml,
u"dtdphi_file")
657 self.
idq_file = ligolw_param.get_pyvalue(xml,
u"idq_file")
658 except ValueError
as e:
659 print(
"idq file not found", e, file=sys.stderr)
661 self.
horizon_factors = ligolw_param.get_pyvalue(xml,
u"horizon_factors")
664 self.
horizon_factors = self.horizon_factors.replace(
"\\",
"").replace(
'\\"',
'"')
666 self.
horizon_factors = dict((int(k), v)
for k, v
in self.horizon_factors.items())
676 Stripped-down version of LnSignalDensity for use in estimating
677 ranking statistics when no data has been collected from an
678 instrument with which to define the ranking statistic.
680 Used, for example, to implement low-significance candidate culls,
683 Assumes all available instruments are on and have the same horizon
684 distance, and assess candidates based only on SNR and \chi^2
687 def __init__(self, *args, **kwargs):
688 super(DatalessLnSignalDensity, self).__init__(*args, **kwargs)
692 def __call__(self, segments, snrs, chi2s_over_snr2s, phase, dt, template_id):
699 horizons = dict.fromkeys(segments, TYPICAL_HORIZON_DISTANCE)
701 lnP += math.log(self.InspiralExtrinsics.p_of_instruments_given_horizons(snrs.keys(), horizons))
709 lnP += math.log(self.InspiralExtrinsics.time_phase_snr(dt, phase, snrs, horizons))
715 lnP += self.population_model.lnP_template_signal(template_id, max(snrs.values()))
719 interp = self.
interps[
"snr_chi"]
720 return lnP + sum(interp(snrs[instrument], chi2_over_snr2)
for instrument, chi2_over_snr2
in chi2s_over_snr2s.items())
722 def __iadd__(self, other):
723 raise NotImplementedError
725 def increment(self, *args, **kwargs):
726 raise NotImplementedError
729 raise NotImplementedError
731 def to_xml(self, name):
735 raise NotImplementedError
738 def from_xml(cls, xml, name):
742 raise NotImplementedError
747 Version of LnSignalDensity with horizon distance history spliced in
748 from another instance. Used to solve a chicken-or-egg problem and
749 assign ranking statistic values in an aonline anlysis. NOTE: the
750 horizon history is not copied from the donor, instances of this
751 class hold a reference to the donor's data, so as it is modified
752 those modifications are immediately reflected here.
754 For safety's sake, instances cannot be written to or read from
755 files, cannot be marginalized together with other instances, nor
756 accept updates from new data.
759 def splice(cls, src, Dh_donor):
760 self = cls(src.template_ids, src.instruments, src.delta_t, population_model_file = src.population_model_file, dtdphi_file = src.dtdphi_file, min_instruments = src.min_instruments, horizon_factors = src.horizon_factors)
761 for key, lnpdf
in src.densities.items():
768 def __iadd__(self, other):
769 raise NotImplementedError
771 def increment(self, *args, **kwargs):
772 raise NotImplementedError
775 raise NotImplementedError
777 def to_xml(self, name):
781 raise NotImplementedError
784 def from_xml(cls, xml, name):
788 raise NotImplementedError
801 def __init__(self, *args, **kwargs):
802 super(LnNoiseDensity, self).__init__(*args, **kwargs)
827 def segmentlists(self):
828 return self.triggerrates.segmentlistdict()
830 def __call__(self, segments, snrs, chi2s_over_snr2s, phase, dt, template_id):
841 triggers_per_second_per_template = {}
842 for instrument, seg
in segments.items():
845 assert all(triggers_per_second_per_template[instrument]
for instrument
in snrs),
"impossible candidate in %s at %s when rates were %s triggers/s/template" % (
", ".join(sorted(snrs)),
", ".join(
"%s s in %s" % (str(seg[1]), instrument)
for instrument, seg
in sorted(segments.items())), str(triggers_per_second_per_template))
856 lnP = math.log(sum(self.coinc_rates.strict_coinc_rates(**triggers_per_second_per_template).values()) * len(self.
template_ids))
859 lnP += self.coinc_rates.lnP_instruments(**triggers_per_second_per_template)[frozenset(snrs)]
867 return lnP + sum(interps[
"%s_snr_chi" % instrument](snrs[instrument], chi2_over_snr2)
for instrument, chi2_over_snr2
in chi2s_over_snr2s.items())
869 def __iadd__(self, other):
870 super(LnNoiseDensity, self).__iadd__(other)
875 new = super(LnNoiseDensity, self).copy()
876 new.triggerrates = self.triggerrates.copy()
889 super(LnNoiseDensity, self).mkinterps()
893 self.
interps = dict((key, (pdf + self.lnzerolagdensity.densities[key]).mkinterp())
for key, pdf
in self.densities.items())
895 def add_noise_model(self, number_of_events = 1):
906 lnpdf = list(self.densities.values())[0]
907 arr = numpy.zeros_like(lnpdf.array)
909 snrindices, rcossindices = lnpdf.bins[self.
snr_min:1e10, 1e-6:1e2]
910 snr, dsnr = lnpdf.bins[0].centres()[snrindices], lnpdf.bins[0].upper()[snrindices] - lnpdf.bins[0].lower()[snrindices]
911 rcoss, drcoss = lnpdf.bins[1].centres()[rcossindices], lnpdf.bins[1].upper()[rcossindices] - lnpdf.bins[1].lower()[rcossindices]
913 prcoss = numpy.ones(len(rcoss))
918 psnr = numpy.outer(psnr, numpy.ones(len(rcoss)))
919 vol = numpy.outer(dsnr, drcoss)
921 arr[snrindices, rcossindices] = psnr * vol
925 arr *= number_of_events / arr.sum()
927 for lnpdf
in self.densities.values():
935 Compute and return a prediction for the total number of
936 noise candidates expected for each instrument
944 return dict((instruments, count * len(self.
template_ids))
for instruments, count
in self.coinc_rates.marginalized_strict_coinc_counts(
945 self.triggerrates.segmentlistdict(),
946 **dict((instrument, rate / len(self.
template_ids))
for instrument, rate
in self.triggerrates.densities.items())
951 Generator that yields an endless sequence of randomly
952 generated candidate parameters. NOTE: the parameters will
953 be within the domain of the repsective binnings but are not
954 drawn from the PDF stored in those binnings --- this is not
955 an MCMC style sampler. Each value in the sequence is a
956 three-element tuple. The first two elements of each tuple
957 provide the *args and **kwargs values for calls to this PDF
958 or the numerator PDF or the ranking statistic object. The
959 final is the natural logarithm (up to an arbitrary
960 constant) of the PDF from which the parameters have been
961 drawn evaluated at the point described by the *args and
968 The sequence is suitable for input to the .ln_lr_samples()
969 log likelihood ratio generator.
974 t_and_rate_gen = iter(self.triggerrates.random_uniform()).__next__
975 t_offsets_gen = dict((instruments, self.coinc_rates.plausible_toas(instruments).__next__)
for instruments
in self.coinc_rates.all_instrument_combos)
976 random_randint = random.randint
977 random_sample = random.sample
978 random_uniform = random.uniform
979 segment = segments.segment
981 ln_1_2 = math.log(0.5)
985 return math.factorial(n) // math.factorial(k) // math.factorial(n - k)
987 t, rates, lnP_t = t_and_rate_gen()
989 instruments = tuple(instrument
for instrument, rate
in rates.items()
if rate > 0)
1008 lnP_instruments = -math.log((len(instruments) - self.
min_instruments + 1) * nCk(len(instruments), k))
1009 instruments = frozenset(random_sample(instruments, k))
1011 seq = sum((snrchi2gens[instrument]()
for instrument
in instruments), ())
1015 "segments": dict.fromkeys(self.
instruments, segment(t - 10.0, t)),
1016 "snrs": dict((instrument, value[0])
for instrument, value
in zip(instruments, seq[0::2])),
1017 "chi2s_over_snr2s": dict((instrument, value[1])
for instrument, value
in zip(instruments, seq[0::2])),
1018 "phase": dict((instrument, random_uniform(0., twopi))
for instrument
in instruments),
1023 "dt": t_offsets_gen[instruments](),
1028 "template_id": random.choice(template_ids)
1037 yield (), kwargs, sum(seq[1::2], lnP_t + lnP_instruments + lnP_template_id)
1039 def to_xml(self, name):
1040 xml = super(LnNoiseDensity, self).to_xml(name)
1041 xml.appendChild(self.triggerrates.to_xml(
u"triggerrates"))
1045 def from_xml(cls, xml, name):
1046 xml = cls.get_xml_root(xml, name)
1047 self = super(LnNoiseDensity, cls).from_xml(xml, name)
1048 self.
triggerrates = trigger_rate.triggerrates.from_xml(xml,
u"triggerrates")
1049 self.triggerrates.coalesce()
1055 Stripped-down version of LnNoiseDensity for use in estimating
1056 ranking statistics when no data has been collected from an
1057 instrument with which to define the ranking statistic.
1059 Used, for example, to implement low-significance candidate culls,
1062 Assumes all available instruments are on and have the same horizon
1063 distance, and assess candidates based only on SNR and \chi^2
1067 DEFAULT_FILENAME = os.path.join(gstlal_config_paths[
"pkgdatadir"],
"inspiral_datalesslndensity.xml.gz")
1069 @ligolw_array.use_in
1070 @ligolw_param.use_in
1074 def __init__(self, *args, **kwargs):
1075 super(DatalessLnNoiseDensity, self).__init__(*args, **kwargs)
1084 def __call__(self, segments, snrs, chi2s_over_snr2s, phase, dt, template_id):
1087 triggers_per_second_per_template = dict.fromkeys(segments, 1.)
1098 lnP = math.log(sum(self.coinc_rates.strict_coinc_rates(**triggers_per_second_per_template).values()) * len(self.
template_ids))
1101 lnP += self.coinc_rates.lnP_instruments(**triggers_per_second_per_template)[frozenset(snrs)]
1105 interp = self.
interps[
"snr_chi"]
1106 return lnP + sum(interp(snrs[instrument], chi2_over_snr2)
for instrument, chi2_over_snr2
in chi2s_over_snr2s.items())
1108 def random_params(self):
1110 raise NotImplementedError
1112 def __iadd__(self, other):
1113 raise NotImplementedError
1115 def increment(self, *args, **kwargs):
1116 raise NotImplementedError
1119 raise NotImplementedError
1121 def to_xml(self, name):
1125 raise NotImplementedError
1128 def from_xml(cls, xml, name):
1132 raise NotImplementedError
1137 Version of LnNoiseDensity with trigger rate data spliced in from
1138 another instance. Used to solve a chicken-or-egg problem and
1139 assign ranking statistic values in an aonline anlysis. NOTE: the
1140 trigger rate data is not copied from the donor, instances of this
1141 class hold a reference to the donor's data, so as it is modified
1142 those modifications are immediately reflected here.
1144 For safety's sake, instances cannot be written to or read from
1145 files, cannot be marginalized together with other instances, nor
1146 accept updates from new data.
1149 def splice(cls, src, rates_donor):
1150 self = cls(src.template_ids, src.instruments, src.delta_t, min_instruments = src.min_instruments)
1151 for key, lnpdf
in src.densities.items():
1158 def __iadd__(self, other):
1159 raise NotImplementedError
1161 def increment(self, *args, **kwargs):
1162 raise NotImplementedError
1165 raise NotImplementedError
1167 def to_xml(self, name):
1171 raise NotImplementedError
1174 def from_xml(cls, xml, name):
1178 raise NotImplementedError
def local_mean_horizon_distance
def candidate_count_model
def candidate_count_model