How to use the celerite.modeling.Model function in celerite

To help you get started, we’ve selected a few celerite 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 dfm / celerite / celerite / modeling.py View on Github external
i = self.get_parameter_names(include_frozen=True).index(name)
        v = self.get_parameter_vector(include_frozen=True)
        v[i] = value
        self.set_parameter_vector(v, include_frozen=True)

    def log_prior(self):
        """Compute the log prior probability of the current parameters"""
        for p, b in zip(self.parameter_vector, self.parameter_bounds):
            if b[0] is not None and p < b[0]:
                return -np.inf
            if b[1] is not None and p > b[1]:
                return -np.inf
        return 0.0


class ModelSet(Model):
    """
    An abstract wrapper for combining named :class:`Model` objects

    The parameter names of a composite model are prepended by the submodel
    name. For example:

    .. code-block:: python

        model = ModelSet([
            ("model1", Model(par1=1.0, par2=2.0)),
            ("model2", Model(par3=3.0, par4=4.0)),
        ])
        print(model.get_parameter_names())

    will print
github dfm / celerite / papers / paper1 / figures / transit_model.py View on Github external
f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) * (1.0 + f) / (2.0 + f),
            np.exp(-self.log_timescale),
        )

    def get_complex_coefficients(self):
        f = np.exp(self.log_factor)
        return (
            np.exp(self.log_amp) / (2.0 + f),
            0.0,
            np.exp(-self.log_timescale),
            2*np.pi*np.exp(-self.log_period),
        )

class TransitModel(modeling.Model):
    parameter_names = ("mean_flux", "log_period", "log_ror", "log_duration",
                       "t0", "impact", "q1", "q2")

    def __init__(self, texp, *args, **kwargs):
        self.texp = texp
        super(TransitModel, self).__init__(*args, **kwargs)

    def get_value(self, t):
        system = transit.SimpleSystem(
            period=np.exp(self.log_period),
            ror=np.exp(self.log_ror),
            duration=np.exp(self.log_duration),
            t0=self.t0,
            impact=self.impact,
            q1=self.q1,
            q2=self.q2
github dfm / celerite / papers / paper1 / figures / simulated / wrong-qpo.py View on Github external
import emcee
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import minimize
from scipy.linalg import cho_factor, cho_solve

import celerite
from celerite import terms
from celerite.modeling import Model

from celerite import plot_setup

plot_setup.setup(auto=True)

class TrueModel(Model):
    parameter_names = ("log_amp", "log_ell", "log_period")

    def get_K(self, x):
        tau = x[:, None] - x[None, :]
        return (
            np.exp(self.log_amp - 0.5 * tau**2 * np.exp(-2.0*self.log_ell)) *
            np.cos(2*np.pi*tau*np.exp(-self.log_period))
        )

    def __call__(self, params, x, y, yerr):
        self.set_parameter_vector(params)
        lp = self.log_prior()
        if not np.isfinite(lp):
            return -np.inf

        K = self.get_K(x)
github dfm / celerite / celerite / terms.py View on Github external
import autograd.numpy as np
    from autograd import jacobian, elementwise_grad
    HAS_AUTOGRAD = True

from itertools import chain, product

from .modeling import Model, ModelSet
from .solver import get_kernel_value, get_psd_value, check_coefficients

__all__ = [
    "Term", "TermProduct", "TermSum",
    "JitterTerm", "RealTerm", "ComplexTerm", "SHOTerm", "Matern32Term",
]


class Term(Model):
    """
    The abstract base "term" that is the superclass of all other terms

    Subclasses should overload the :func:`terms.Term.get_real_coefficients`
    and :func:`terms.Term.get_complex_coefficients` methods.

    """

    _has_jitter = False
    _has_coeffs = True

    @property
    def terms(self):
        """A list of all the terms included in a sum of terms"""
        return [self]
github dfm / celerite / celerite / modeling.py View on Github external
return self._apply_to_parameter("get_parameter", name)

    def set_parameter(self, name, value):
        self.dirty = True
        return self._apply_to_parameter("set_parameter", name, value)

    def log_prior(self):
        lp = 0.0
        for model in self.models.values():
            lp += model.log_prior()
            if not np.isfinite(lp):
                return -np.inf
        return lp


class ConstantModel(Model):
    """
    A simple concrete model with a single parameter ``value``

    Args:
        value (float): The value of the model.

    """

    parameter_names = ("value", )

    def get_value(self, x):
        return self.value + np.zeros_like(x)

    def compute_gradient(self, x):
        return np.array([np.ones_like(x)])