[][src]Trait permu_rs::Population

pub trait Population<T>: Debug {
    fn learn(&self) -> Distribution;
fn sample(&mut self, distr: &mut Distribution) -> Result<(), Error>;
fn to_permus(&self, permus: &mut PermuPopulation<T>) -> Result<(), Error>;
fn from_permus(&mut self, permus: &PermuPopulation<T>) -> Result<(), Error>; }

Contains the methods a Population should have.

Required methods

fn learn(&self) -> Distribution

Returns a Distribution learned from the current population.

fn sample(&mut self, distr: &mut Distribution) -> Result<(), Error>

Fills the current population with samples sampled from a given Distribution.

fn to_permus(&self, permus: &mut PermuPopulation<T>) -> Result<(), Error>

Fills the given PermuPopulation with the permutation vector representation of the current population .

fn from_permus(&mut self, permus: &PermuPopulation<T>) -> Result<(), Error>

Maps a given PermuPopulation into the current Population's representation.

Loading content...

Implementors

impl<T> Population<T> for InversionPopulation<T> where
    T: Copy + From<u8> + TryFrom<usize> + TryInto<usize> + Eq + SampleRange + PartialOrd + Sub + Display + Debug
[src]

fn learn(&self) -> Distribution[src]

Implementation of learn method for InversionPopulation.

Example

use permu_rs::{Population, Distribution};
use permu_rs::inversion::{InversionPopulation, Inversion};
use InversionPopulation as invpop;
use Inversion as inv;
 
let pop: Vec<Vec<u8>> = vec![vec![2,1,0], vec![1,0,0], vec![0,0,0]];
let pop = InversionPopulation::from_vec(&pop).unwrap();

let target = vec![vec![1,1,1,0],vec![2,1,0,0],vec![3,0,0,0]];
let target = Distribution::InversionDistribution(target, false);

let distr = pop.learn();

assert_eq!(target, distr);

fn sample(&mut self, distr: &mut Distribution) -> Result<(), Error>[src]

Implementation of sample method for PermuPopulation.

Errors

Returns a LengthError if the length of the output population's Inversion's length is not equal to its population Inversions's. Returns an IncorrectDistrType error if the given distribution is not InversionPopulation.

Example

use permu_rs::{Population, Distribution};
use permu_rs::inversion::InversionPopulation;
 
// Initialize a custom distribution
let distr = vec![vec![1,1,1,0],vec![2,1,0,0],vec![3,0,0,0]];
let mut distr = Distribution::InversionDistribution(distr, false);
println!("Original distr:\n{}", distr);
// Init output population
let mut out = InversionPopulation::<u8>::zeros(10, 3); 
// Sample distribution
out.sample(&mut distr).unwrap();

// Now the original distribution has been changed in order to soften it
println!("Now distr:\n{}", distr);
println!("Out:\n{}", out); // Sampled population

impl<T> Population<T> for PermuPopulation<T> where
    T: Copy + From<u8> + TryFrom<usize> + TryInto<usize> + Eq + SampleRange + PartialOrd + Sub + Display + Debug
[src]

fn learn(&self) -> Distribution[src]

Implementation of learn method for PermuPopulation.

Example

use permu_rs::{Population, Distribution};
use permu_rs::permutation::{PermuPopulation, Permutation};

let v = vec![Permutation::<u8>::from_vec_unsec(vec![0,1,2,3]),
             Permutation::<u8>::from_vec_unsec(vec![1,2,0,3])];
let pop = PermuPopulation::from_vec(v); 
let distr = pop.learn();

let target = vec![vec![1,1,0,0],
                  vec![0,1,1,0],
                  vec![1,0,1,0],
                  vec![0,0,0,2]];

let target = Distribution::PermuDistribution(target, false);
assert_eq!(target, distr);

fn sample(&mut self, distr: &mut Distribution) -> Result<(), Error>[src]

Implementation of sample method for PermuPopulation.

Errors

Returns a LengthError if the length of the output population's Permutations length is not equal to its population Permutation's. Returns an IncorrectDistrType error if the given distribution is not PermuDistribution.

Example

use permu_rs::permutation::PermuPopulation;
use permu_rs::{Population, Distribution};

let pop = PermuPopulation::<u8>::random(1, 5); // Population to learn from
let mut samples = PermuPopulation::<u8>::zeros(10, 5); // Population to fill with samples
 
let mut distr = pop.learn();

samples.sample(&mut distr).unwrap();

println!("{}", samples);

impl<T> Population<T> for RimPopulation<T> where
    T: Copy + From<u8> + TryFrom<usize> + TryInto<usize> + Eq + SampleRange + PartialOrd + Sub + Display + Debug
[src]

fn learn(&self) -> Distribution[src]

Implementation of learn method for RimPopulation.

Example

use permu_rs::{Distribution, Population, rim::RimPopulation};
 
// Init a population of custom rim vectors
let pop: Vec<Vec<u8>> = vec![vec![2,1,0], vec![1,0,0], vec![0,0,0]];
let pop = RimPopulation::from_vec(&pop).unwrap();

// Cratethe target distribution for the created rim population
let target = vec![vec![1,1,1,0],vec![2,1,0,0],vec![3,0,0,0]];
let target = Distribution::RimDistribution(target, false);

let distr = pop.learn();
assert_eq!(target, distr);

fn sample(&mut self, distr: &mut Distribution) -> Result<(), Error>[src]

Implementation of sample method for RimPopulation.

Example

use permu_rs::{Distribution, Population, rim::RimPopulation};
 
// Init a population of custom rim vectors
let pop: Vec<Vec<u8>> = vec![vec![2,1,0], vec![1,0,0], vec![0,0,0]];
let pop = RimPopulation::from_vec(&pop).unwrap();

// Init a population to store the samples
let mut samples = RimPopulation::<u8>::zeros(7, 3);

let mut distr = pop.learn();
println!("Distribution:\n{}", distr);

samples.sample(&mut distr).unwrap();
println!("Distribution after sampling:\n{}", distr);

println!("Original population:\n{}", pop);
println!("Sampled population:\n{}", samples);
Loading content...