Giter Site home page Giter Site logo

Comments (12)

aloctavodia avatar aloctavodia commented on August 22, 2024

Hi @nguyenhoaiThanhbk2811

  • You assign prior distributions to parameters, not problems. Thus when you say "My problem has a prior value that is uniform distribution [0,1]", you should identify which parameter in your model has such a prior.

  • You say the likelihood is a normal distribution, that's fine. But you also say is a normal with mean 1.35 and standard deviation 0.05. If that's true then you don't need to perform any inference. Because you already know the values of all the parameters in your model.

Thus to solve your problem you must first identify the unknown parameters in your model and then assign priors to those unknown parameters. For example you may have a normal likelihood with know mean, let say 0 and unknown standard deviation. In that case your PyMC3 model will be something like this:

with pm.Model() as model:
    std = pm.HalfNormal('std', 25)
    y = pm.Normal('y', 0, std, observed=your_data)

or maybe you have something like this

with pm.Model() as model:
    mean = pm.Normal('mean', 1.35, 0.05)
    std = pm.Uniform('std', 0, 1)
    y = pm.Normal('y', mean, std, observed=your_data)

from bap.

nguyenhoaiThanhbk2811 avatar nguyenhoaiThanhbk2811 commented on August 22, 2024

Thanks you. you replied your message.
My problem means:
I has a coefficient C1 with [0,1] uniform distribution (P (C1): priors ) and the likelihood of observations P(d/C1) with mean 1.3 and standard deviation 0.5.
My aim is how to find the posterior distribution, P(C1/d) via Bayesian inference with MCMC by pymc3.
Could you give me the tutorial is same as this problem.
Thanks you very much

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024

If you say your data is distributed as Normal with unknown mean and unknown standard deviation, then you put priors over the mean and standard deviation and after that you can perform Bayesian inference. As a result you will get the posterior distribution of the mean and standard deviation.

If instead you say your data is distributed as a normal with a mean 1.35 and standard deviation 0.05, then you already have the answer to your problem. The mean is 1.35 and the standard deviation is 0.05 (without any uncertainty).

A few questions:

Are you saying that the mean is 1.35 and the standard deviation 0.05, because you compute that directly from the data?

How is C1 related to your data?

Could you try to write your model down?

from bap.

nguyenhoaiThanhbk2811 avatar nguyenhoaiThanhbk2811 commented on August 22, 2024

Hi you,
Now, I say detail my problem, I hope that you could help me.
my problem: I have a velocity of an airplane. I don't know exactly the velocity of the airplane. So I want to experiment to have the value of this velocity. I assume that I have a range value of the velocity is [0,1] m/s. Getting 200 random values in the range of the velocity I have corresponding to the 200 values of drag force. I saw the values of drag force which is normal distribution with mean = 1.35 and standard deviation 0.05.
I want to apply the Bayesian inference to find the posterior distribution p(velocity/drag).
maybe my thoughts about the distribution of drag force (likelihood function p(drag/velocity)) is wrong.
Do you know how to apply the Bayesian inference to find the posterior distribution p(velocity/drag).
thanks you.

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024

Hi,

The speed of an object is related to the drag force by a deterministic physical model, something like

Fd = S * k

where:
Fd = drag force
S = speed of the object
k = some constant that should be tabulated somewhere.

Thus, if you know the speed you can directly compute the drag force (or vice versa). And if you have 200 samples of the speed you can directly compute 200 samples of the drag force.

I am not sure from your description what is the observed quantity (the speed or the drag force) but given that you can compute one from the other this should not be a problem, so let assume you have samples of the drag force and you know the value of k from some table, one possible model is to find the mean and standard deviation of the drag force under a Gaussian model, then you will have something like

with pm.Model() as model_0:
    mean_fd = pm.HalfNormal('mean_fd', 25)  # I am assuming the Fd is always positive, the value "25" is just arbitrary.
    sd_fd = pm.HalfNormal('sd_fd', 25)  #  The value "25" is just arbitrary.

    obs_fd = pm.Normal('obs_fd', mu=mean_fd, sigma=sd_fd, observed=data)
    trace = pm.sample()

You can also have a model that put a prior over the mean of the speed and transform the speed into drag force.

with pm.Model() as model_1:
    S = pm.HalfNorma('S', 0, 1)  # I am using a HalfNormal prior instead of the uniform prior you suggested, this generally works better, unless you really know speed over 1 are impossible.
    sd = pm.HalfNormal('sd', 25)  # just some default prior, you should check if this makes sense. 

    Fd = S * k

    obs_fd = pm.Normal('obs_fd', mu=Fd, sigma=sd_fd, observed=data)
    trace = pm.sample()

I hope this helps.

from bap.

nguyenhoaiThanhbk2811 avatar nguyenhoaiThanhbk2811 commented on August 22, 2024

http://www.fz-juelich.de/SharedDocs/Downloads/CONFERENCES/IRW12/EN/MondayAfternoon_08.pdf?__blob=publicationFile

this is the link of paper which I am referring. At the page 7 It is same as the step which I have used Stochastic collocation method based on gPC to find the histogram of the drag force (in this page is power). Similar with the paper, If I can find the "uncertainties affecting the signals" how to apply Bayesian to that?. in my problem is " velocity and drag force" and paper's is "h,tc,Lc with power".

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024

The model in you link is more or less the same as model_1 in my previous comment. In the link F is a function of h,tc,Lc, in model_1, Fd is a function of S and k. In the link the unknown standard deviation is σ, in model_1 sd_fd. In your link the observations are labelled as d and sd_fd in model_1.

from bap.

nguyenhoaiThanhbk2811 avatar nguyenhoaiThanhbk2811 commented on August 22, 2024

Dear you,
If I find the function between input and out. how to consider the posterior distribution.
I have a input Uniform distribution (0.9,1.1). the relative between input and output is a linear regression.

"
import pymc3 as pm
import numpy as np
import scipy.stats as stats
from sklearn.preprocessing import StandardScaler
import matplotlib.pyplot as plt

np.random.seed(123)

observed_values = np.array([0.0204232,0.0205054,0.0204971,0.0204463,0.0206686,0.0206678,0.0206883,0.0204627,0.020426,0.0206532,0.0206322,0.020677,0.0204431,0.0205319,0.0204508,0.0204115,0.020721,0.0206988,0.0206179,0.0206418])

basic_model = pm.Model()

with pm.Model () as model:
ce1 = pm.Uniform ('ce1',lower = 0.9, upper =1.1) # prior distribution

# expected value of outcome

linear regression

# likelihood  of observation
y = pm.Normal ('y',mu=mu,sd=ce1,observed=observed_values)

map_estimate = pm.find_MAP(model = basic_model)

print (map_estimate)
"

how to find the posterior distribution of input.

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024
with pm.Model() as model:
    ce1 = pm.Uniform ('ce1',lower = 0.9, upper =1.1)  # prior
    a = pm.Normal('a', 0, 100)  # prior
    b = pm.Normal('b', 0, 100)  # prior
    mu = a + b * x_obs_values   # linear model
    y = pm.Normal ('y', mu=mu, sd=ce1,observed=y_obs_values)
    trace = pm.sample()

Please do not use pm.find_MAP() is not generally a good idea.

The trace object will contain samples from the posterior distribution.

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024

Hi, @nguyenhoaiThanhbk2811 I am closing this. Feel free to reopen if you think this issue has not been solved.

from bap.

nguyenhoaiThanhbk2811 avatar nguyenhoaiThanhbk2811 commented on August 22, 2024

Hi You,
Now If I estimated the surrogate model between input and output.
y = 2.6642 + 2.3829x^4 - 9.8086x^3+15.111x^2-10.334x
how to find the posterior distribution of x.?
with pior distribution of X is normal distribution (mu=1, sd=0.05).

from bap.

aloctavodia avatar aloctavodia commented on August 22, 2024

Please explain your problem in detail, what is your data and what do you want to know, how do you get your priors? also how this question is related with the previous ones, is this still the same problem? Are you reading the book? To which model in the book do you think your problem is closer to?

from bap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.