priors

The priors module contains the kde class, which is used to construct the prior for `asy_peakbag’ as well as providing the initial starting location .

class pbjam.priors.kde(starinst=None, prior_file=None)[source]

A class to produce prior for asy_peakbag and initial starting location.

This class will take a sample of previously fit stars and compute a multi-variate KDE which acts as a prior for asy_peakbag.

The class will also compute a posterior, using the computed KDE and the the input parameters, numax, dnu, Teff and Gbp-Grp as observational constraints. This posterior is then sampled to estimate the most likely initial starting location for asy_peakbag.

Examples

Use KDE from the star class instance (recommended)

>>> st = pbjam.star(ID='KIC4448777', pg=pg, numax=[220.0, 3.0],
                       dnu=[16.97, 0.01], teff=[4750, 100],
                       bp_rp = [1.34, 0.01])
>>> st.run_kde()

Using KDE on it’s own.

>>> K = pbjam.prior.kde()
>>> K(numax=[220.0, 3.0], dnu=[16.97, 0.01], teff=[4750, 100],
      bp_rp = [1.34, 0.01])
Parameters:
  • starinst (pbjam.star class instance, optional) – A star class instance to use for observational parameters. Default is None, which will then require observational parameters be provided at the class instance call.
  • prior_file (str, optional) – File path to the csv file containing the previous fit values to be used to compute the KDE. Default is to use pbjam/data/prior_data.csv
kde_predict(n)[source]

Predict the l=0 mode frequencies from the KDE samples.

Takes the samples drawn using the kde_sampler method and produces a distribution of where it thinks each radial mode should be.

Parameters:n (numpy_array) – The radial order
Returns:
  • freq_mean (ndarray) – A numpy array of length len(n) containing the mean frequency estimates.
  • freq_std (ndarray) – A numpy array of length len(n) containing the standard deviation of the frequency estimates.
kde_sampler(nwalkers=50)[source]

Samples the posterior distribution with the KDE prior

Draws samples from the posterior given by

$p( heta|D) propto p( heta) p(D| heta)$,

where $p( heta)$ is given by the KDE function of the prior data and $p(D| heta)$ is given by the observable constraints

Samples are drawn using the `emcee’ package.

Parameters:nwalkers (int) – Number of walkers to use to sample the posterior. This is passed to the `emcee’ package. Default is 50.
Returns:flatchain – Flattened chains from the emcee sampling.
Return type:ndarray
likelihood(p)[source]

Calculate likelihood for the initial guess fit

Calculates the likelihood of the observed properties given the proposed parameters p.

Parameters:p (ndarray) – Array of model parameters to evaluate the likelihood at.
Returns:lnlike – The log likelihood evaluated at p.
Return type:float
make_kde(bw_fac=1.0)[source]

Takes the prior data and constructs a KDE function

Computes the KDE based on the parameters of a previously fit sample of targets.

The KDE bandwidth is by default computed automatically using the cross-validated maximum liklihood method in the `statsmodels’ package.

Notes

If the bandwidth factor is != 1 the method for calculating the initial bandwidth is the ‘scott’ method. Otherwise it is the cross-validated maximum likelihood method, employed by the `statsmodels’ package. This is currently a limitation of imposed by the current version of `statsmodels’.

Parameters:bw_fac (float, optional) – Factor for expanding the bandwidth of the KDE. If float-like the scaling will be the same for all paramaters. If array-like it must be of the same length as the number of fit parameters. Each scaling will then be applied individually to each parameter.
prior(p)[source]

Calculates the log prior for the initial guess fit.

Evaluates the KDE for the parameters p. Additional hard/soft priors can be added here as needed to, e.g., apply boundaries to the fit.

Hard constraints should be applied at the top so function exits early, if necessary.

Parameters:p (ndarray) – Array of model parameters to evaluate the prior at.
Returns:lp – The log likelihood evaluated at p.
Return type:float
select_prior_data(numax=None, KDEsize=100)[source]

Selects useful prior data based on proximity to estimated numax.

Selects a subset of targets around input numax to use for computing the KDE. If the number of targets in the range considered for the prior is less than KDEsize, the range will be expanded until it ~KDEsize. This is to ensure that the KDE can be constructed. If the initial range includes more than KDEsize targets (e.g., in dense parts of the RGB) the selection of targets will be downsampled randomly. The range is expanded to a maximum of $20sigma$.

Notes

Does not ensure that the KDE is finite at the location of your target.

Parameters:
  • numax (list, optional) – The estimate of numax together with uncertainty in log space. Default is none, in which case no selection will be made - all data will be used (you probably don’t want to do this).
  • KDEsize (int, optional) – Number of targets to include in the KDE estimation. Default is 100.