Skip to content

Commit

Permalink
refs #92 doc updats
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyLim23 committed Aug 8, 2024
1 parent 4bc7145 commit 16a19e7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 5 deletions.
53 changes: 52 additions & 1 deletion docs/source/cf_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Bayes Theorm
------------

Bayesian inference is used to calculate the whole posterior probability distribution function (PDF).
The equation for the posterior probability can be written as
.. math::
:name: eq:post
P(\underline{\theta}| D, M) = P(D | \underline{\theta}, M)\frac{P(D | \underline{\theta}, M)}{P(D | M),
where :math:`\underline{\theta}` is a vector of model parameters, :math:`M` is the model and :math:`D` is the data.
:math:`P(\underline{\theta} | M)` is the prior distribution and represents current knowledge of the system.
:math:`P(D | M)` is the evidence and acts as a normalisation for the posterior.
The shape and spread of the PDF provides insight into the model and the parameter.
A narrow PDF suggests that the parameter is well defined or has little evidence of variation.
A broad PDF could mean that the model is insensitive to that specific parameter.
Expand Down Expand Up @@ -48,9 +57,51 @@ The key assumptions are:
Odds factor
-----------

One method for comparing models is known as the odds factor.
It assumes that you can calculate the probability of the data given the :math:`i^{\mathrm{th}` model (:math:`M_i`), by taking the ratio of two different models.
This section will use a derivation based on the work from `here <https://jakevdp.github.io/blog/2015/08/07/frequentism-and-bayesianism-5-model-selection/>`_.

For model selection we want the model posterior

.. math::
P(M | D) = P(D | M) \frac{P(M)}{P(D)},
where :math:`P(D | M)` is the probability of the data given the model, :math:`P(M)` is the probability of the model and :math:`P(D)` the probability of the data.
The probability of the data will be the same for all models, so by taking a ratio the term can be removed

.. math::
:name: eq:odds
O_{21} = \frac{P(M_2 | D)}{P(M_1 | D) = \frac{P(D | M_2)P(M_2)}{P(D | M_1)P(M_1)}
where :math:`0_{21}` is the odds factor for models two (:math:`M_2`) and one (:math:`M_1`).
Assuming that there is no prior knowledge then :math:`P(M_1) \approx P(M_2)`.
Then equation :numref:`eq:odds` can be simplified to

.. math::
O_{21} = \frac{P(D | M_2)}{P(D | M_1)},
which is known as the Bayes factor.
Alternatively, the Bayesian probability for the :math:`j^\mathrm{th}` model is

.. math::
P(M_j | D) = \frac{ P((D | M_j)}{ \sum_k P(D | M_k)}.
To evaluate the odds factor, the probability of the data given the model needs to be calculated.
This is written as

.. math::
:name: eq:P(D|M)
P(D | M) = \int_\omega d\undeline{\theta} \quad P(D| \underline{\theta}, M)P(\underline{\theta} | M)
where the integral over :math:`\omega` is over the available parameter space for :math:`\underline{\theta}`.





Check the label for :ref:`integration <eq:int>`

`odds factor <https://jakevdp.github.io/blog/2015/08/07/frequentism-and-bayesianism-5-model-selection/>`_


MCMC to eval integral
Expand Down
4 changes: 2 additions & 2 deletions docs/source/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ In the development of quickBayes the code became more modular and flexable.
This allows the code to be applied to any probelm that requires model selection.

To verify the results of quickBayes it was compared to the quasielasticbayes calculations.
For lorentzian fits it produced the close enough results.
However, for a stretched exponential it gave different results for the FWHM.
For lorentzian fits it produced close enough results.
However, for a stretched exponential it gave different results for the Full Width Half Max (FWHM).
The stretched exponential results for the FWHM are different to quasielasticbayes, as shown by the figure below.
However, the new results agree with the FWHM values for fitting a single Lorentzian ('QL').
The quickBayes method provides FWHM results that are comparable for all :math:`Q` values (green and black data), unlike the original code that has a divergence for low :math:`Q` value.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ Introduction
Statistics is dominated by a school of thought known as frequentist statistics.
To demonstrate the difference, let's consider a bag containing a mixture of red and yellow balls.
If a ball is chosen from the bag, such that only one person knows its colour.
Then a frequentist would say that the probability of that ball being red is either :math:`100%` or :math:`0%`, as it is definitely red or not.
Then a frequentist would say that the probability of that ball being red is either :math:`100\%` or :math:`0\%`, as it is definitely red or not.

A Bayesian approach relies more on probability and uncertainty.
In the above example of picking a ball, they would say that the probability of the ball being red is :math:`50%` as it is either red or yellow.
In the above example of picking a ball, they would say that the probability of the ball being red is :math:`50\%` as it is either red or yellow.
This initial probability is known as a prior and represents the known information at the beginning.
After revealing the colour of the ball it is placed back into the bag, it is shaken, and a new ball is picked.
After repeating this :math:`100` times a red ball was picked :math:`70` times.
Expand Down

0 comments on commit 16a19e7

Please sign in to comment.