Example #1
0
def power_chisq_bins(htilde, num_bins, psd, low_frequency_cutoff=None,
                     high_frequency_cutoff=None):
    """Returns bins of equal power for use with the chisq functions

    Parameters
    ----------

    htilde: FrequencySeries
        A frequency series containing the template waveform
    num_bins: int
        The number of chisq bins to calculate.
    psd: FrequencySeries
        A frequency series containing the psd. Its length must be commensurate
        with the template waveform.
    low_frequency_cutoff: {None, float}, optional
        The low frequency cutoff to apply
    high_frequency_cutoff: {None, float}, optional
        The high frequency cutoff to apply

    Returns
    -------

    bins: List of ints
        A list of the edges of the chisq bins is returned.
    """
    sigma_vec = sigmasq_series(htilde, psd, low_frequency_cutoff,
                               high_frequency_cutoff).numpy()
    kmin, kmax = get_cutoff_indices(low_frequency_cutoff,
                                    high_frequency_cutoff,
                                    htilde.delta_f,
                                    (len(htilde)-1)*2)
    return power_chisq_bins_from_sigmasq_series(sigma_vec, num_bins, kmin, kmax)
Example #2
0
def power_chisq_bins(htilde,
                     num_bins,
                     psd,
                     low_frequency_cutoff=None,
                     high_frequency_cutoff=None):
    """Returns bins of equal power for use with the chisq functions

    Parameters
    ----------

    htilde: FrequencySeries
        A frequency series containing the template waveform
    num_bins: int
        The number of chisq bins to calculate.
    psd: FrequencySeries
        A frequency series containing the psd. Its length must be commensurate
        with the template waveform.
    low_frequency_cutoff: {None, float}, optional
        The low frequency cutoff to apply
    high_frequency_cutoff: {None, float}, optional
        The high frequency cutoff to apply

    Returns
    -------

    bins: List of ints
        A list of the edges of the chisq bins is returned.
    """
    sigma_vec = sigmasq_series(htilde, psd, low_frequency_cutoff,
                               high_frequency_cutoff).numpy()
    kmin, kmax = get_cutoff_indices(low_frequency_cutoff,
                                    high_frequency_cutoff, htilde.delta_f,
                                    (len(htilde) - 1) * 2)
    return power_chisq_bins_from_sigmasq_series(sigma_vec, num_bins, kmin,
                                                kmax)
Example #3
0
 def __init__(self, variable_args, waveform_generator=None, data=None,
              f_lower=None, psds=None, f_upper=None, norm=None,
              **kwargs):
     if waveform_generator is None:
         raise ValueError("waveform_generator must be provided")
     if data is None:
         raise ValueError("data must be provided")
     if f_lower is None:
         raise ValueError("f_lower must be provided")
     # set up the boiler-plate attributes; note: we'll compute the
     # log evidence later
     super(GaussianLikelihood, self).__init__(
         variable_args,
         waveform_generator=waveform_generator, data=data,
         **kwargs)
     # check that the data and waveform generator have the same detectors
     if sorted(waveform_generator.detectors.keys()) != \
             sorted(self._data.keys()):
         raise ValueError("waveform generator's detectors (%s) " %(
             ','.join(sorted(waveform_generator.detector_names))) +
             "does not match data (%s)" %(
             ','.join(sorted(self._data.keys()))))
     # check that the data and waveform generator have the same epoch
     if any(waveform_generator.epoch != d.epoch
            for d in self._data.values()):
         raise ValueError("waveform generator does not have the same epoch "
             "as all of the data sets.")
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = data.values()[0]
     N = len(d)
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
         (N-1)*2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4*d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = Array(numpy.sqrt(norm)*numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {det: Array(numpy.sqrt(norm/psds[det]))
                         for det in data}
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
     # compute the log likelihood function of the noise and save it
     self.set_lognl(-0.5*sum([
         d[kmin:kmax].inner(d[kmin:kmax]).real
         for d in self._data.values()]))
     # set default call function to logplor
     self.set_callfunc('logplr')
Example #4
0
 def __init__(self, variable_args, waveform_generator=None, data=None,
              f_lower=None, psds=None, f_upper=None, norm=None,
              **kwargs):
     if waveform_generator is None:
         raise ValueError("waveform_generator must be provided")
     if data is None:
         raise ValueError("data must be provided")
     if f_lower is None:
         raise ValueError("f_lower must be provided")
     # set up the boiler-plate attributes; note: we'll compute the
     # log evidence later
     super(GaussianLikelihood, self).__init__(
         variable_args,
         waveform_generator=waveform_generator, data=data,
         **kwargs)
     # check that the data and waveform generator have the same detectors
     if sorted(waveform_generator.detectors.keys()) != \
             sorted(self._data.keys()):
         raise ValueError("waveform generator's detectors (%s) " %(
             ','.join(sorted(waveform_generator.detector_names))) +
             "does not match data (%s)" %(
             ','.join(sorted(self._data.keys()))))
     # check that the data and waveform generator have the same epoch
     if any(waveform_generator.epoch != d.epoch
            for d in self._data.values()):
         raise ValueError("waveform generator does not have the same epoch "
             "as all of the data sets.")
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = data.values()[0]
     N = len(d)
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
         (N-1)*2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4*d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = Array(numpy.sqrt(norm)*numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {det: Array(numpy.sqrt(norm/psds[det]))
                         for det in data}
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
     # compute the log likelihood function of the noise and save it
     self.set_lognl(-0.5*sum([
         d[kmin:kmax].inner(d[kmin:kmax]).real
         for d in self._data.values()]))
     # set default call function to logplor
     self.set_callfunc('logplr')
Example #5
0
 def __init__(self,
              variable_params,
              data,
              waveform_generator,
              f_lower,
              psds=None,
              f_upper=None,
              norm=None,
              **kwargs):
     # set up the boiler-plate attributes; note: we'll compute the
     # log evidence later
     super(GaussianNoise, self).__init__(variable_params, data,
                                         waveform_generator, **kwargs)
     # check that the data and waveform generator have the same detectors
     if (sorted(waveform_generator.detectors.keys()) != sorted(
             self._data.keys())):
         raise ValueError(
             "waveform generator's detectors ({0}) does not "
             "match data ({1})".format(
                 ','.join(sorted(waveform_generator.detector_names)),
                 ','.join(sorted(self._data.keys()))))
     # check that the data and waveform generator have the same epoch
     if any(waveform_generator.epoch != d.epoch
            for d in self._data.values()):
         raise ValueError("waveform generator does not have the same epoch "
                          "as all of the data sets.")
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = data.values()[0]
     N = len(d)
     # figure out the kmin, kmax to use
     self._f_lower = f_lower
     kmin, kmax = pyfilter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
                                              (N - 1) * 2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4 * d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         self._psds = None
         w = Array(numpy.sqrt(norm) * numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # store a copy of the psds
         self._psds = {ifo: d.copy() for (ifo, d) in psds.items()}
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {
             det: Array(numpy.sqrt(norm / psds[det]))
             for det in data
         }
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
Example #6
0
 def __init__(self, waveform_generator, data, f_lower, psds=None,
         f_upper=None, norm=None, prior=None):
     self._waveform_generator = waveform_generator
     self._data = data
     # check that the data and waveform generator have the same detectors
     if sorted(waveform_generator.detectors.keys()) != \
             sorted(self._data.keys()):
         raise ValueError("waveform generator's detectors (%s) " %(
             ','.join(sorted(waveform_generator.detector_names))) +
             "does not match data (%s)" %(
             ','.join(sorted(self._data.keys()))))
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     N = dlens[0]
     # we'll use the first data set for setting values
     d = data.values()[0]
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
         (N-1)*2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4*d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = norm*Array(numpy.ones(N))
         # FIXME: use the following when we've switched to 2.7
         #self._weight = {det: w for det in data} 
         self._weight = dict([(det, w) for det in data])
     else:
         # temporarily suppress numpy divide by 0 warning
         numpy.seterr(divide='ignore')
         # FIXME: use the following when we've switched to 2.7
         #self._weight = {det: norm/psds[det] for det in data}
         self._weight = dict([(det, norm/psds[det]) for det in data])
         numpy.seterr(divide='warn')
     # compute <d, d>
     # FIXME: use the following when we've switched to 2.7
     #self._dd = {det:
     #    d[kmin:kmax].inner(d[kmin:kmax]*self._weight[det][kmin:kmax]).real/2.
      #   for det,d in self._data.items()}
     self._dd = dict([(det,
         d[kmin:kmax].inner(d[kmin:kmax]*self._weight[det][kmin:kmax]).real/2.)
         for det,d in self._data.items()])
     # store prior
     if prior is None:
         self._prior = _noprior 
     else:
         # check that the variable args of the prior evaluator is the same
         # as the waveform generator
         if prior.variable_args != self._waveform_generator.variable_args:
             raise ValueError("variable args of prior and waveform "
                 "generator do not match")
         self._prior = prior
 def __init__(self,
              variable_params,
              data,
              low_frequency_cutoff,
              psds=None,
              high_frequency_cutoff=None,
              norm=None,
              static_params=None,
              **kwargs):
     # set up the boiler-plate attributes
     super(GaussianNoise, self).__init__(variable_params,
                                         data,
                                         static_params=static_params,
                                         **kwargs)
     # create the waveform generator
     self._waveform_generator = create_waveform_generator(
         self.variable_params,
         self.data,
         recalibration=self.recalibration,
         gates=self.gates,
         **self.static_params)
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in self.data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = list(self.data.values())[0]
     N = len(d)
     # Set low frequency cutoff
     self._f_lower = low_frequency_cutoff
     self._f_upper = high_frequency_cutoff
     kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower, self._f_upper,
                                              d.delta_f, (N - 1) * 2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4 * d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         self._psds = None
         w = Array(numpy.sqrt(norm) * numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # store a copy of the psds
         self._psds = {ifo: d.copy() for (ifo, d) in psds.items()}
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {
             det: Array(numpy.sqrt(norm / psds[det]))
             for det in data
         }
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
Example #8
0
 def __init__(self,
              waveform_generator,
              data,
              f_lower,
              psds=None,
              f_upper=None,
              norm=None,
              prior=None,
              sampling_parameters=None,
              replace_parameters=None,
              sampling_transforms=None,
              return_meta=True):
     # set up the boiler-plate attributes; note: we'll compute the
     # log evidence later
     super(GaussianLikelihood,
           self).__init__(waveform_generator,
                          data,
                          prior=prior,
                          sampling_parameters=sampling_parameters,
                          replace_parameters=replace_parameters,
                          sampling_transforms=sampling_transforms,
                          return_meta=return_meta)
     # we'll use the first data set for setting values
     d = data.values()[0]
     N = len(d)
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
                                            (N - 1) * 2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4 * d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = Array(numpy.sqrt(norm) * numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {
             det: Array(numpy.sqrt(norm / psds[det]))
             for det in data
         }
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
     # compute the log likelihood function of the noise and save it
     self.set_lognl(-0.5 * sum([
         d[kmin:kmax].inner(d[kmin:kmax]).real for d in self._data.values()
     ]))
     # set default call function to logplor
     self.set_callfunc('logplr')
Example #9
0
 def __init__(self, variable_params, data, low_frequency_cutoff, psds=None,
              high_frequency_cutoff=None, norm=None, static_params=None,
              **kwargs):
     # set up the boiler-plate attributes
     super(GaussianNoise, self).__init__(variable_params, data,
                                         static_params=static_params,
                                         **kwargs)
     # create the waveform generator
     self._waveform_generator = create_waveform_generator(
         self.variable_params, self.data, recalibration=self.recalibration,
         gates=self.gates, **self.static_params)
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in self.data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = list(self.data.values())[0]
     N = len(d)
     # Set low frequency cutoff
     self._f_lower = low_frequency_cutoff
     self._f_upper = high_frequency_cutoff
     kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower, self._f_upper,
                                              d.delta_f, (N-1)*2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4*d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         self._psds = None
         w = Array(numpy.sqrt(norm)*numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # store a copy of the psds
         self._psds = {ifo: d.copy() for (ifo, d) in psds.items()}
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {det: Array(numpy.sqrt(norm/psds[det]))
                         for det in data}
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
Example #10
0
 def __init__(self, waveform_generator, data, f_lower, psds=None,
              f_upper=None, norm=None, prior=None,
              sampling_parameters=None, replace_parameters=None,
              sampling_transforms=None, return_meta=True):
     # set up the boiler-plate attributes; note: we'll compute the
     # log evidence later
     super(GaussianLikelihood, self).__init__(waveform_generator, data,
         prior=prior, sampling_parameters=sampling_parameters,
         replace_parameters=replace_parameters,
         sampling_transforms=sampling_transforms, return_meta=return_meta)
     # we'll use the first data set for setting values
     d = data.values()[0]
     N = len(d)
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
         (N-1)*2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4*d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = Array(numpy.sqrt(norm)*numpy.ones(N))
         self._weight = {det: w for det in data} 
     else:
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {det: Array(numpy.sqrt(norm/psds[det]))
                         for det in data}
         numpy.seterr(**numpysettings)
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
     # compute the log likelihood function of the noise and save it
     self.set_lognl(-0.5*sum([
         d[kmin:kmax].inner(d[kmin:kmax]).real
         for d in self._data.values()]))
     # set default call function to logplor
     self.set_callfunc('logplr')
Example #11
0
    def __init__(self, variable_params, data, low_frequency_cutoff, psds=None,
                 high_frequency_cutoff=None, normalize=False,
                 static_params=None, **kwargs):
        # set up the boiler-plate attributes
        super(BaseGaussianNoise, self).__init__(variable_params, data,
                                                static_params=static_params,
                                                **kwargs)
        # check if low frequency cutoff has been provided for every IFO with
        # data
        for ifo in self.data.keys():
            if low_frequency_cutoff[ifo] is None:
                raise ValueError(
                    "A low-frequency-cutoff must be provided for every "
                    "detector for which data has been provided. If "
                    "loading the model settings from "
                    "a config file, please provide "
                    "`{DETECTOR}:low-frequency-cutoff` options for "
                    "every detector in the `[model]` section, where "
                    "`{DETECTOR} is the name of the detector,"
                    "or provide a single low-frequency-cutoff option"
                    "which will be used for all detectors")

        # check that the data sets all have the same delta fs and delta ts
        dts = numpy.array([d.delta_t for d in self.data.values()])
        dfs = numpy.array([d.delta_f for d in self.data.values()])
        if not all(dts == dts[0]):
            raise ValueError("all data must have the same sample rate")
        if not all(dfs == dfs[0]):
            raise ValueError("all data must have the same segment length")
        # store the number of samples in the time domain
        self._N = int(1./(dts[0]*dfs[0]))
        # Set low frequency cutoff
        self.low_frequency_cutoff = self._f_lower = low_frequency_cutoff
        # set upper frequency cutoff
        self._f_upper = None
        self.high_frequency_cutoff = high_frequency_cutoff
        # Set the cutoff indices
        self._kmin = {}
        self._kmax = {}

        for (det, d) in self._data.items():
            kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower[det],
                                                     self._f_upper[det],
                                                     d.delta_f, self._N)
            self._kmin[det] = kmin
            self._kmax[det] = kmax
        # store the psd segments
        self._psd_segments = {}
        if psds is not None:
            self.set_psd_segments(psds)
        # store the psds and calculate the inner product weight
        self._psds = {}
        self._weight = {}
        self._lognorm = {}
        self._det_lognls = {}
        self._whitened_data = {}
        # set the normalization state
        self._normalize = False
        self.normalize = normalize
        # store the psds and whiten the data
        self.psds = psds
Example #12
0
    def __init__(self,
                 variable_params,
                 data,
                 low_frequency_cutoff,
                 psds=None,
                 high_frequency_cutoff=None,
                 normalize=False,
                 static_params=None,
                 ignore_failed_waveforms=False,
                 no_save_data=False,
                 **kwargs):
        # set up the boiler-plate attributes
        super(BaseGaussianNoise, self).__init__(variable_params,
                                                data,
                                                static_params=static_params,
                                                no_save_data=no_save_data,
                                                **kwargs)
        self.ignore_failed_waveforms = ignore_failed_waveforms
        self.no_save_data = no_save_data
        # check if low frequency cutoff has been provided for every IFO with
        # data
        for ifo in self.data:
            if low_frequency_cutoff[ifo] is None:
                raise ValueError(
                    "A low-frequency-cutoff must be provided for every "
                    "detector for which data has been provided. If "
                    "loading the model settings from "
                    "a config file, please provide "
                    "`{DETECTOR}:low-frequency-cutoff` options for "
                    "every detector in the `[model]` section, where "
                    "`{DETECTOR} is the name of the detector,"
                    "or provide a single low-frequency-cutoff option"
                    "which will be used for all detectors")

        # check that the data sets all have the same delta fs and delta ts
        dts = numpy.array([d.delta_t for d in self.data.values()])
        dfs = numpy.array([d.delta_f for d in self.data.values()])
        if all(dts == dts[0]) and all(dfs == dfs[0]):
            self.all_ifodata_same_rate_length = True
        else:
            self.all_ifodata_same_rate_length = False
            logging.info("You are using different data segment lengths or "
                         "sampling rates for different IFOs")

        # store the number of samples in the time domain
        self._N = {}
        for (det, d) in self._data.items():
            self._N[det] = int(1. / (d.delta_f * d.delta_t))

        # set lower/upper frequency cutoff
        if high_frequency_cutoff is None:
            high_frequency_cutoff = {ifo: None for ifo in self.data}
        self._f_upper = high_frequency_cutoff
        self._f_lower = low_frequency_cutoff

        # Set the cutoff indices
        self._kmin = {}
        self._kmax = {}

        for (det, d) in self._data.items():
            kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower[det],
                                                     self._f_upper[det],
                                                     d.delta_f, self._N[det])
            self._kmin[det] = kmin
            self._kmax[det] = kmax

        # store the psd segments
        self._psd_segments = {}
        if psds is not None:
            self.set_psd_segments(psds)

        # store the psds and calculate the inner product weight
        self._psds = {}
        self._invpsds = {}
        self._weight = {}
        self._lognorm = {}
        self._det_lognls = {}
        self._whitened_data = {}

        # set the normalization state
        self._normalize = False
        self.normalize = normalize
        # store the psds and whiten the data
        self.psds = psds

        # attribute for storing the current waveforms
        self._current_wfs = None
Example #13
0
 def __init__(self,
              waveform_generator,
              data,
              f_lower,
              psds=None,
              f_upper=None,
              norm=None,
              prior=None):
     self._waveform_generator = waveform_generator
     self._data = data
     # check that the data and waveform generator have the same detectors
     if sorted(waveform_generator.detectors.keys()) != \
             sorted(self._data.keys()):
         raise ValueError(
             "waveform generator's detectors (%s) " %
             (','.join(sorted(waveform_generator.detector_names))) +
             "does not match data (%s)" %
             (','.join(sorted(self._data.keys()))))
     # check that the data and waveform generator have the same epoch
     if any(waveform_generator.epoch != d.epoch
            for d in self._data.values()):
         raise ValueError(
             "waveform generator does not have the same epoch as all "
             "of the data sets.")
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     N = dlens[0]
     # we'll use the first data set for setting values
     d = data.values()[0]
     # figure out the kmin, kmax to use
     kmin, kmax = filter.get_cutoff_indices(f_lower, f_upper, d.delta_f,
                                            (N - 1) * 2)
     self._kmin = kmin
     self._kmax = kmax
     if norm is None:
         norm = 4 * d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         w = Array(numpy.sqrt(norm) * numpy.ones(N))
         # FIXME: use the following when we've switched to 2.7
         #self._weight = {det: w for det in data}
         self._weight = dict([(det, w) for det in data])
     else:
         # temporarily suppress numpy divide by 0 warning
         numpy.seterr(divide='ignore')
         # FIXME: use the following when we've switched to 2.7
         #self._weight = {det: Array(numpy.sqrt(norm/psds[det])) for det in data}
         self._weight = dict([(det, Array(numpy.sqrt(norm / psds[det])))
                              for det in data])
         numpy.seterr(divide='warn')
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
     # compute <d, d>
     # FIXME: use the following when we've switched to 2.7
     #self._dd = {det:
     #    d[kmin:kmax].inner(d[kmin:kmax]).real/2.
     #   for det,d in self._data.items()}
     self._dd = dict([(det, d[kmin:kmax].inner(d[kmin:kmax]).real / 2.)
                      for det, d in self._data.items()])
     # store prior
     if prior is None:
         self._prior = _noprior
     else:
         # check that the variable args of the prior evaluator is the same
         # as the waveform generator
         if prior.variable_args != self._waveform_generator.variable_args:
             raise ValueError("variable args of prior and waveform "
                              "generator do not match")
         self._prior = prior
Example #14
0
 def __init__(self,
              variable_params,
              data,
              low_frequency_cutoff,
              psds=None,
              high_frequency_cutoff=None,
              norm=None,
              static_params=None,
              **kwargs):
     # set up the boiler-plate attributes
     super(GaussianNoise, self).__init__(variable_params,
                                         data,
                                         static_params=static_params,
                                         **kwargs)
     # check if low frequency cutoff has been provided for every IFO.
     if set(low_frequency_cutoff.keys()) != set(self.data.keys()):
         raise KeyError("IFOs for which data has been provided should "
                        "match IFOs for which low-frequency-cutoff has "
                        "been provided for likelihood inner product "
                        "calculation. If loading the model settings from "
                        "a config file, please provide an "
                        "`IFO-low-frequency-cutoff` input for each "
                        "detector in the `[model]` section, where IFO is "
                        "the name of the detector.")
     # create the waveform generator
     self._waveform_generator = create_waveform_generator(
         self.variable_params,
         self.data,
         recalibration=self.recalibration,
         gates=self.gates,
         **self.static_params)
     # check that the data sets all have the same lengths
     dlens = numpy.array([len(d) for d in self.data.values()])
     if not all(dlens == dlens[0]):
         raise ValueError("all data must be of the same length")
     # we'll use the first data set for setting values
     d = list(self.data.values())[0]
     N = len(d)
     # Set low frequency cutoff
     self._f_lower = low_frequency_cutoff
     self._f_upper = {}
     if high_frequency_cutoff is not None and bool(high_frequency_cutoff):
         for det in self._data:
             if det in high_frequency_cutoff:
                 self._f_upper[det] = high_frequency_cutoff[det]
             else:
                 self._f_upper[det] = None
     else:
         for det in self._data.keys():
             self._f_upper[det] = None
     if norm is None:
         norm = 4 * d.delta_f
     # we'll store the weight to apply to the inner product
     if psds is None:
         self._psds = None
         w = Array(numpy.sqrt(norm) * numpy.ones(N))
         self._weight = {det: w for det in data}
     else:
         # store a copy of the psds
         self._psds = {ifo: d.copy() for (ifo, d) in psds.items()}
         # temporarily suppress numpy divide by 0 warning
         numpysettings = numpy.seterr(divide='ignore')
         self._weight = {
             det: Array(numpy.sqrt(norm / psds[det]))
             for det in data
         }
         numpy.seterr(**numpysettings)
     self._kmin = {}
     self._kmax = {}
     for det in self._data:
         # whiten the data
         kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower[det],
                                                  self._f_upper[det],
                                                  d.delta_f, (N - 1) * 2)
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]
         self._kmin[det] = kmin
         self._kmax[det] = kmax
Example #15
0
 def __init__(self,
              variable_params,
              data,
              low_frequency_cutoff,
              psds=None,
              high_frequency_cutoff=None,
              static_params=None,
              **kwargs):
     # set up the boiler-plate attributes
     super(GaussianNoise, self).__init__(variable_params,
                                         data,
                                         static_params=static_params,
                                         **kwargs)
     # check if low frequency cutoff has been provided for every IFO.
     if set(low_frequency_cutoff.keys()) != set(self.data.keys()):
         raise KeyError("IFOs for which data has been provided should "
                        "match IFOs for which low-frequency-cutoff has "
                        "been provided for likelihood inner product "
                        "calculation. If loading the model settings from "
                        "a config file, please provide an "
                        "`IFO-low-frequency-cutoff` input for each "
                        "detector in the `[model]` section, where IFO is "
                        "the name of the detector.")
     # create the waveform generator
     # the waveform generator will get the variable_params + the output
     # of the waveform transforms, so we'll add them to the list of
     # parameters
     if self.waveform_transforms is not None:
         wfoutputs = set.union(
             *[t.outputs for t in self.waveform_transforms])
     else:
         wfoutputs = set()
     params = list(self.variable_params) + list(wfoutputs)
     self._waveform_generator = create_waveform_generator(
         params,
         self.data,
         recalibration=self.recalibration,
         gates=self.gates,
         **self.static_params)
     # check that the data sets all have the same delta fs and delta ts
     dts = numpy.array([d.delta_t for d in self.data.values()])
     dfs = numpy.array([d.delta_f for d in self.data.values()])
     if not all(dts == dts[0]):
         raise ValueError("all data must have the same sample rate")
     if not all(dfs == dfs[0]):
         raise ValueError("all data must have the same segment length")
     # store the number of samples in the time domain
     self._N = int(1. / (dts[0] * dfs[0]))
     # Set low frequency cutoff
     self._f_lower = None
     self.low_frequency_cutoff = low_frequency_cutoff
     # set upper frequency cutoff
     self._f_upper = None
     self.high_frequency_cutoff = high_frequency_cutoff
     # Set the cutoff indices
     self._kmin = {}
     self._kmax = {}
     for (det, d) in self._data.items():
         kmin, kmax = pyfilter.get_cutoff_indices(self._f_lower[det],
                                                  self._f_upper[det],
                                                  d.delta_f, self._N)
         self._kmin[det] = kmin
         self._kmax[det] = kmax
     # store the psds and calculate the inner product weight
     self._psds = {}
     self._weight = {}
     self._lognorm = {}
     self._det_lognls = {}
     self.psds = psds
     # whiten the data
     for det in self._data:
         self._data[det][kmin:kmax] *= self._weight[det][kmin:kmax]