How to use the stingray.modeling.PSDLogLikelihood function in stingray

To help you get started, we’ve selected a few stingray examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StingraySoftware / dave / src / main / python / utils / dave_engine.py View on Github external
as_priors = ModelHelper.get_astropy_priors(priors)
                if len(as_priors.keys()) > 0:
                    # If there are priors then is a Bayesian Parameters Estimation
                    max_post=True
                    fitmethod="BFGS"

                else:
                    as_priors=None
                    logging.warn("fit_power_density_spectrum: can't create priors from dave_priors.")

            if as_priors:
                # Creates a Posterior object with the priors
                lpost = PSDPosterior(pds.freq, pds.power, fit_model, priors=as_priors, m=pds.m)
            else:
                # Creates the Maximum Likelihood object for fitting
                lpost = PSDLogLikelihood(pds.freq, pds.power, fit_model, m=pds.m)

            # Creates the PSD Parameters Estimation object and runs the fitting
            parest = PSDParEst(pds, fitmethod=fitmethod, max_post=max_post)
            res = parest.fit(lpost, starting_pars, neg=True)

            sample = None
            if as_priors and sampling_params is not None:
                # If is a Bayesian Par. Est. and has sampling parameters
                # then sample the posterior distribution defined in `lpost` using MCMC
                sample = parest.sample(lpost, res.p_opt, cov=res.cov,
                                         nwalkers=sampling_params["nwalkers"],
                                         niter=sampling_params["niter"],
                                         burnin=sampling_params["burnin"],
                                         threads=sampling_params["threads"],
                                         print_results=False, plot=False)
github StingraySoftware / dave / src / main / python / utils / model_helper.py View on Github external
def fit_data_with_lorentz_and_const(x_values, y_values):
    amplitude=5.
    x_0=1
    fwhm=0.5
    const=5.
    g_init = Lorentz1D(amplitude, x_0, fwhm)
    g_init += Const1D(const)
    lpost = PSDLogLikelihood(x_values, y_values, g_init)
    parest = ParameterEstimation()
    res = parest.fit(lpost, [amplitude, x_0, fwhm, const], neg=True)
    opt_amplitude = res.p_opt[0]
    opt_x_0 = res.p_opt[1]
    opt_fwhm = res.p_opt[2]
    opt_const = res.p_opt[3]
    return opt_amplitude, opt_x_0, opt_fwhm, opt_const
github StingraySoftware / dave / src / main / python / utils / model_helper.py View on Github external
def fit_data_with_gaussian(x_values, y_values, amplitude=1., mean=0, stddev=1.):
    g_init = Gaussian1D(amplitude, mean, stddev)
    lpost = PSDLogLikelihood(x_values, y_values, g_init)
    parest = ParameterEstimation()
    res = parest.fit(lpost, [amplitude, mean, stddev], neg=True)
    opt_amplitude = res.p_opt[0]
    opt_mean = res.p_opt[1]
    opt_stddev = res.p_opt[2]
    return opt_amplitude, opt_mean, opt_stddev