Parameters¶
There are four options for parameters in chromatic_fitting: Fixed, WavelikeFixed, Fitted, and WavelikeFitted. Fixed is one fixed value for all wavelengths, WavelikeFixed are fixed values that are different between wavelengths. Fitted determines a prior distribution (e.g. Uniform, Normal, TruncatedNormal) that we will use to fit one value for the parameter across all wavelengths. Similarly, WavelikeFitted is a prior distribution that we will use to fit for a different value for every wavelength.
from chromatic_fitting import *
from pymc3 import Uniform, Normal
import pymc3 as pm
from pymc3 import sample_prior_predictive
Running chromatic_fitting v0.0.2! This program is running on: Python v3.9.12 (main, Jun 1 2022, 06:34:44) [Clang 12.0.0 ] numpy v1.22.1 chromatic v0.3.14 pymc3 v3.11.5 pymc3_ext v0.1.1 exoplanet v0.5.2
Fixed¶
A fixed value for all wavelengths.
a = Fixed(3.0)
print(a)
<🧮 Fixed | 3.0 🧮>
When we call the .get_prior() function a Fixed parameter will just return its value:
a.get_prior()
3.0
WavelikeFixed¶
A fixed value for each wavelength:
b = WavelikeFixed([1.0, 2.2, 3.6, 7.7])
print(b)
<🧮 WavelikeFixed | one value for each wavelength (4 elements)🧮>
For the WavelikeFixed parameter we need to provide the wavelength index we want to the .get_prior() function
b.get_prior(i=2)
3.6
Fitted¶
The Fitted parameter is for fitting a prior distribution (self.distribution) with the given inputs (self.inputs) to give us one value for all wavelengths. We can use any distribution we like instead of Normal here, we just need to give it the correct inputs:
c = Fitted(Normal, mu=1.0, sigma=0.1, name="c")
print(c)
<🧮 Fitted Normal(mu=1.0, sigma=0.1, name='c') 🧮>
Let's check we set up the distribution and inputs correctly:
c.distribution, c.inputs
(pymc3.distributions.continuous.Normal, {'mu': 1.0, 'sigma': 0.1, 'name': 'c'})
For the Fitted parameters we need to call the .get_prior() function for the first time inside of a PyMC3 model:
with pm.Model() as mod:
print(c.get_prior())
c ~ Normal
c.get_prior()
Now let's check the model (and see if our parameter has been set up in it!):
mod
A final check we can do to understand this parameter is to sample from the prior we've given the model:
with mod:
# take 5000 samples from the prior distributions:
sample = sample_prior_predictive(5000)
And if everything has worked then this should look like a Gaussian centred at 1 with ~sigma of 0.1!
plt.hist(sample['c'], bins=20);
WavelikeFitted¶
The WavelikeFitted parameter is fitting the prior distribution (self.distribution) with the given inputs (self.inputs) for each wavelength independantly.
d = WavelikeFitted(Uniform, lower=1.0, upper=5.0, name="d")
print(d)
<🧮 WavelikeFitted Uniform(lower=1.0, upper=5.0, name='d') for each wavelength 🧮>
Let's check our distribution and input values:
d.distribution, d.inputs
(pymc3.distributions.continuous.Uniform,
{'lower': 1.0, 'upper': 5.0, 'name': 'd'})
For WavelikeFitted, similarly to Fitted parameters, we also need to call the .get_prior() function for the first time inside a PyMC3 model, however, we need to tell the function which wavelength we want to fit:
with pm.Model() as m:
print(d.get_prior(i=2))
print(d.get_prior(i=4))
d_w2 ~ Uniform d_w4 ~ Uniform
d.get_prior(i=2)
Now if we look at the model we should see the parameters d_w2 and d_w4 because we've specified i=2 and i=4:
m
with m:
sample = sample_prior_predictive(1000)
plt.hist(sample['d_w4']);
Looks pretty uniform between 1-5!