I have a question about Pymc3 fit the equation:
S = A* f**(-a)+C
and I have known : log10(A) obeys Uniform(-10,10)
log10(c) obeys Uniform (-20,10)
a abeys Uniform (1,4)
And likelihood just a normal distribution,
How can I use Pymc3 determine the A ,a ,C (and I have the data about S, and f , like S=[1,2,3…], f=[1,2,3…])
Thanks!
I’m assuming by “obey” you’re stating prior distributions on a
, A
, and C
. The code below should work:
import pymc3 as pm
with pm.Model() as model:
a = pm.Uniform("a", lower=1, upper=4)
log_A = pm.Uniform("log_A", lower=-10, 10)
log_C = pm.Uniform("log_C", lower=-20, 10)
A = pm.Deterministic("A", pm.math.exp(log_A))
C = pm.Deterministic("C", pm.math.exp(log_C))
mean_S = pm.Deterministic("mean_S", A*(f**(-a)) + C)
# Either fix the standard deviation of noise or put a prior on it, perhaps with pm.Exponential
sigma = 2.0
likelihood = pm.Normal("likelihood", mu=mean_S, sigma=sigma, observed=S)
# Sample the posterior
trace = pm.sample()
Hi @StarryNight, I am maybe wrong, but it looks like from the notation that you are fitting a power spectrum/periodogram (S) as a function of frequency (f), with a power law model. If the power spectrum has come from the application of a Discrete Fourier Transform, then the likelihood is not a Normal. It should be chi-squared.
If I am wrong, then feel free to ignore me
Happy to provide further information if I am right though. You can send me a direct message.
2 Likes
Oh Yeah! It is power spactrum that Iam doing! emmm , Would you like to share your suggestions further?
Best is your code, use pymc3(hahaha)
Becouse the data(list(S) is very small, I have to take logarithm, but I have no idea how to use pymc3 to fit well