-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add (back) student t likelihood (#61); new example to demonstrate it
- Loading branch information
Showing
16 changed files
with
214 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
KIMA_DIR = ../.. | ||
include $(KIMA_DIR)/examples.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# File containing parameters for DNest4 | ||
# Put comments at the top, or at the end of the line. | ||
2 # Number of particles | ||
1000 # new level interval | ||
500 # save interval | ||
10 # threadSteps: number of steps each thread does independently before communication | ||
0 # maximum number of levels | ||
10 # Backtracking scale length (lambda) | ||
100 # Strength of effect to force histogram to equal push (beta) | ||
5000 # Maximum number of saves (0 = infinite) | ||
# (optional) samples file | ||
# (optional) sample_info file | ||
# (optional) levels file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
This example showcases the use of a Student t likelihood for more robustness | ||
regarding outlier RV measurements. The folder contains a simulated dataset with | ||
known outliers and a planetary signal. | ||
|
||
The `kima_setup.cpp` file sets the main options for the model, including | ||
|
||
```c++ | ||
const bool studentt = true; | ||
``` | ||
|
||
This introduces an additional parameter in the model, the degrees of freedom of | ||
the Student t likelihood (called `nu` in the code). | ||
|
||
The number of planets in the model is fixed to 1. This example uses default | ||
priors for all parameters. The default prior for `nu` is a log-uniform | ||
distribution between 2 and 1000. | ||
Note that the variance of the t-distribution is infinite for 1 < `nu` <= 2. | ||
Larger values for `nu` make the t-distribution approach a Gaussian distribution. | ||
|
||
To compile and run, type | ||
|
||
``` | ||
kima-run | ||
``` | ||
|
||
With the default options, this example should take about a minute to finish. | ||
|
||
It's interesting to set `studentt = false` in order to check the nasty effect of | ||
the outliers on the Gaussian distribution. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from scipy.stats import t as Tstudent, norm | ||
|
||
from pykima.keplerian import keplerian | ||
|
||
# reproducible | ||
np.random.seed(43) | ||
|
||
vsys = 11.1 # (m/s) | ||
P = 32.1 # (days) | ||
K = 4.6 # (m/s) | ||
ecc = 0.1 | ||
w = 0.3 | ||
|
||
|
||
def create_d1(): | ||
N = 68 | ||
# from 01/03/2010 to 24/01/2019, because why not | ||
t = np.sort(np.random.uniform(55256, 58507, N)) | ||
|
||
rv = np.full_like(t, vsys) | ||
|
||
Tp = t[0] + 10 | ||
planet = keplerian(t, P, K, ecc, w, Tp, 0.0) | ||
rv += planet | ||
|
||
srv = np.random.uniform(0.6, 0.9, t.size) | ||
jit = 0.3 | ||
|
||
err = norm(0, np.hypot(np.median(srv), jit)).rvs(t.size) | ||
# err = Tstudent(df=2.1, loc=0, scale=np.hypot(np.median(srv), jit)).rvs(t.size) | ||
rv += err | ||
|
||
# outliers!!! | ||
rv[10] += 16.1 | ||
rv[15] += 20 | ||
rv[56] -= 13 | ||
|
||
header = 'bjd\tvrad\tsvrad\n---\t----\t-----' | ||
np.savetxt('d1.txt', np.c_[t, rv, srv], | ||
header=header, comments='', fmt='%6.3f') | ||
|
||
return t, rv, srv, (P, K, ecc, w, Tp, vsys, jit) | ||
|
||
|
||
def plot_dataset(): | ||
t, rv, srv, pars = create_d1() | ||
|
||
tt = np.linspace(t[0], t[-1], 5000) | ||
pl = keplerian(tt, *pars[:6]) | ||
|
||
_, ax = plt.subplots(1, 1) | ||
ax.set(xlabel='Time [days]', ylabel='RV [m/s]') | ||
|
||
ax.errorbar(t, rv, srv, fmt='o') | ||
ax.plot(tt, pl, 'k', zorder=-1) | ||
|
||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include "kima.h" | ||
|
||
const bool obs_after_HARPS_fibers = false; | ||
const bool GP = false; | ||
const bool MA = false; | ||
const bool hyperpriors = false; | ||
const bool trend = false; | ||
const int degree = 0; | ||
const bool multi_instrument = false; | ||
const bool known_object = false; | ||
const bool studentt = true; // use a Student's t-distribution for the likelihood | ||
|
||
RVmodel::RVmodel():fix(true),npmax(1) | ||
{ | ||
// all default priors | ||
// the default prior for the degrees of freedom (nu) of the t-distribution: | ||
// nu_prior = make_prior<LogUniform>(2, 1000); | ||
} | ||
|
||
|
||
int main(int argc, char** argv) | ||
{ | ||
datafile = "d1.txt"; | ||
|
||
load(datafile, "ms", 2); | ||
|
||
Sampler<RVmodel> sampler = setup<RVmodel>(argc, argv); | ||
sampler.run(50); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.