EmSite

Trait EmSite 

Source
pub trait EmSite<const D: usize> {
    // Required methods
    fn likelihood(&self, sfs: &Sfs<D>) -> Likelihood;
    fn posterior_into(
        &self,
        sfs: &Sfs<D>,
        posterior: &mut USfs<D>,
        buf: &mut USfs<D>,
    ) -> Likelihood;

    // Provided method
    fn log_likelihood(&self, sfs: &Sfs<D>) -> LogLikelihood { ... }
}
Expand description

A type of SAF site that can be used as input for EM.

This trait should not typically be used in user code, except as a trait bound where code has to be written that is generic over different EM input types.

Required Methods§

Source

fn likelihood(&self, sfs: &Sfs<D>) -> Likelihood

Returns the likelihood of a single site given the SFS.

§Panics

Panics if the shape of the SFS does not fit the shape of self.

§Examples
use winsfs_core::{em::{likelihood::LogLikelihood, EmSite}, saf::Site, sfs::Sfs};
let sfs = Sfs::uniform([5]);
let site = Site::new(vec![1.0, 0.0, 0.0, 0.0, 0.0], [5]).unwrap();
assert_eq!(site.log_likelihood(&sfs), LogLikelihood::from(0.2f64.ln()));
Source

fn posterior_into( &self, sfs: &Sfs<D>, posterior: &mut USfs<D>, buf: &mut USfs<D>, ) -> Likelihood

Adds the posterior counts for the site into the provided posterior buffer, using the extra buf to avoid extraneous allocations.

The buf will be overwritten, and so it’s state is unimportant. The shape of the site will be matched against the shape of the SFS, and a panic will be thrown if they do not match. The shapes of posterior and buf are unchecked, but must match the shape of self.

The likelihood of the site given the SFS is returned.

§Panics

Panics if the shape of the SFS does not fit the shape of self.

Provided Methods§

Source

fn log_likelihood(&self, sfs: &Sfs<D>) -> LogLikelihood

Returns the log-likelihood of a single site given the SFS.

§Panics

Panics if the shape of the SFS does not fit the shape of self.

§Examples
use winsfs_core::{em::{likelihood::LogLikelihood, EmSite}, saf::Site, sfs::Sfs};
let sfs = Sfs::uniform([5]);
let site = Site::new(vec![1.0, 0.0, 0.0, 0.0, 0.0], [5]).unwrap();
assert_eq!(site.log_likelihood(&sfs), LogLikelihood::from(0.2f64.ln()));

Implementors§

Source§

impl<const D: usize, T> EmSite<D> for T
where T: AsSiteView<D>,