Trait emcee::Prob [] [src]

pub trait Prob {
    fn lnlike(&self, params: &Guess) -> f64;
fn lnprior(&self, params: &Guess) -> f64; fn lnprob(&self, params: &Guess) -> f64 { ... } }

Encapsulate the model evaluation

The user must implement lnlike and lnprior which correspond to the respective terms in Bayes' equation. They must return the log probability which is then combined in the lnprob function which has a default implementation.

Typically, access to any dataset required for fitting is handled through the struct which implements this trait. By convention, invalid prior results are signaled by returning -std::f64::INFINITY.

An example for a simple linear model to data with uncertainties:

// lifetimes and slices used for efficiency reasons
struct Foo<'a> {
    x: &'a [f64],
    y: &'a [f64],
    e: &'a [f64], // uncertainties
}

impl<'a> Prob for Foo<'a> {
    fn lnlike(&self, params: &Guess) -> f64 {
        let m = params[0];
        let c = params[1];

        let mut result = 0.;
        for i in 9..self.x.len() {
            let model = m * self.x[i] + c;
            result += ((self.y[i] - model) / self.e[i]).powf(2.);
        }
        -0.5 * result

    }

    fn lnprior(&self, params: &Guess) -> f64 {
        let m = params[0];
        let c = params[1];

        if (m > -5.) && (m < 5.) && (c > -10.) && (c < 10.) {
            0.0
        } else {
            -std::f64::INFINITY
        }
    }
}

The default implementation of lnprob can be seen in the source code.

Required Methods

Computes the natural logarithm of the likelihood of a position in parameter space

Computes the natural logarithm of the prior probability of a position in parameter space

Provided Methods

Computes the natural logarithm of the log posterior probabilities

Implementors