Пример #1
0
from __future__ import division, print_function

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):
Пример #2
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import numpy as np
import matplotlib.pyplot as plt

from timer import benchmark

from celerite import GP, terms
from celerite import plot_setup
plot_setup.setup()

# Set up the dimensions of the problem
N = 2**np.arange(6, 20)
times = np.empty((len(N), 3))
times[:] = np.nan

# Simulate a "dataset"
np.random.seed(42)
t = np.sort(np.random.rand(np.max(N)))
yerr = np.random.uniform(0.1, 0.2, len(t))
y = np.sin(t)

# Set up the GP model
kernel = terms.RealTerm(1.0, 0.1) + terms.ComplexTerm(0.1, 2.0, 1.6)
gp = GP(kernel)

for i, n in enumerate(N):
    times[i, 0] = benchmark("gp.compute(t[:{0}], yerr[:{0}])".format(n),
Пример #3
0
import matplotlib.pyplot as plt
from scipy.optimize import minimize
from scipy.ndimage.filters import gaussian_filter

import emcee3
from emcee3 import autocorr

from astropy.stats import LombScargle

import celerite
from celerite import modeling

from astero_term import AsteroTerm
from celerite.plot_setup import setup, get_figsize, COLORS

setup(auto=True)

def format_filename(name):
    base = "astero-{0}-".format(kicid)
    return base + name + ".pdf"

# Factor to convert between day^-1 and uHz
uHz_conv = 1e-6 * 24 * 60 * 60

# Download the data for a giant star from MAST
kicid = 11615890
client = kplr.API()
star = client.star(kicid)

x = []
y = []
Пример #4
0
Файл: error.py Проект: dfm/GenRP
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import h5py
import numpy as np

import celerite
from celerite import terms, plot_setup

np.random.seed(42)
plot_setup.setup(auto=True)

K = 10
J = np.arange(2, 64, 8)
N = 2**np.arange(6, 16)

alpha_error = np.empty((K, len(J), len(N)))
logdet_error = np.empty((K, len(J), len(N)))
logdet_error[:, :, :] = np.nan

for k in range(K):
    t = np.sort(np.random.uniform(0, N.max() * 0.8, N.max()))
    yerr = np.random.uniform(1.0, 1.5, len(t))

    for ix, j in enumerate(J):
        kernel = terms.RealTerm(np.random.uniform(-1, 1),
                                np.random.uniform(-5, -1))
        kernel += terms.RealTerm(np.random.uniform(-1, 1),
                                 np.random.uniform(-5, -1))
Пример #5
0
Файл: plot.py Проект: dfm/GenRP
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import os
import argparse
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

from celerite.plot_setup import setup, get_figsize, COLOR_CYCLE
setup(auto=True)

parser = argparse.ArgumentParser()
parser.add_argument("platform")
parser.add_argument("--suffix", default=None)
parser.add_argument("--directory",
                    default=os.path.dirname(os.path.abspath(__file__)))
args = parser.parse_args()

# Compile into a matrix
suffix = ""
if args.suffix is not None:
    suffix = "_" + args.suffix

fn = "benchmark_{0}{1}.csv".format(args.platform, suffix)
fn = os.path.join(args.directory, fn)
data = pd.read_csv(fn, comment="#")
data_matrix = np.empty((data.xi.max() + 1, data.yi.max() + 1))
data_matrix[:] = np.nan
Пример #6
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import division, print_function

import numpy as np
from itertools import product

import matplotlib
import matplotlib.pyplot as plt

from celerite.plot_setup import setup, get_figsize

setup()

J = 2
width = 2 * J + 1 + 4 * J + 1 + 2 * J
height = 1 + 4 * J

block = np.zeros((height, width), dtype=int)

# y_n
block[0, 2 * J] = 1  # diag
block[0, :2 * J:2] = 2  # a/2
block[0, 1:2 * J:2] = 3  # b/2
block[0, 2 * J + 1:4 * J + 1:2] = 4  # phi
block[0, 2 * J + 2:4 * J + 1:2] = 5  # psi

# g_{n,j}
for j in range(J):
    block[1 + 2 * j, 2 * j] = 4  # phi