Skip to main content
`Ctrl`+`K`

# FitnessFunc

class astropy.stats.FitnessFunc(p0=0.05, gamma=None, ncp_prior=None)

  Bases: `object`

  Base class for bayesian blocks fitness functions.

  Derived classes should overload the following method:

  `fitness(self, **kwargs)`:

    Compute the fitness given a set of named arguments. Arguments accepted by fitness must be among `[T_k, N_k, a_k, b_k, c_k]` (See [1] for details on the meaning of these parameters).

  Additionally, other methods may be overloaded as well:

  `__init__(self, **kwargs)`:

    Initialize the fitness function with any parameters beyond the normal `p0` and `gamma`.

  `validate_input(self, t, x, sigma)`:

    Enable specific checks of the input data (`t`, `x`, `sigma`) to be performed prior to the fit.

  `compute_ncp_prior(self, N)`: If `ncp_prior` is not defined explicitly,

    this function is called in order to define it before fitting. This may be calculated from `gamma`, `p0`, or whatever method you choose.

  `p0_prior(self, N)`:

    Specify the form of the prior given the false-alarm probability `p0` (See [1] for details).

  For examples of implemented fitness functions, see `Events`, `RegularEvents`, and `PointMeasures`.

  References

  [1] (1,2)

  Scargle, J et al. (2013) https://ui.adsabs.harvard.edu/abs/2013ApJ…764..167S

  Methods Summary

  `compute_ncp_prior`(N) | If `ncp_prior` is not explicitly defined, compute it from `gamma` or `p0`.
  `fit`(t[, x, sigma]) | Fit the Bayesian Blocks model given the specified fitness function.
  `fitness`(**kwargs) |
  `p0_prior`(N) | Empirical prior, parametrized by the false alarm probability `p0`.
  `validate_input`(t[, x, sigma]) | Validate inputs to the model.

  Methods Documentation

  compute_ncp_prior(N)

    If `ncp_prior` is not explicitly defined, compute it from `gamma` or `p0`.

  fit(t, x=None, sigma=None)

    Fit the Bayesian Blocks model given the specified fitness function.

    Parameters:
      t numpy:array_like

        data times (one dimensional, length N)

      x numpy:array_like, optional

        data values

      sigma numpy:array_like or `python:float`, optional

        data errors

    Returns:
      edges `ndarray`

        array containing the (M+1) edges defining the M optimal bins

  fitness(**kwargs)
  p0_prior(N)

    Empirical prior, parametrized by the false alarm probability `p0`.

    See eq. 21 in Scargle (2013).

    Note that there was an error in this equation in the original Scargle paper (the “log” was missing). The following corrected form is taken from https://arxiv.org/abs/1304.2818

  validate_input(t, x=None, sigma=None)

    Validate inputs to the model.

    Parameters:
      t numpy:array_like

        times of observations

      x numpy:array_like, optional

        values observed at each time

      sigma `python:float` or numpy:array_like, optional

        errors in values x

    Returns:
      t, x, sigma numpy:array_like, `python:float`

        validated and perhaps modified versions of inputs