RimPopulation

Struct RimPopulation 

Source
pub struct RimPopulation<T> {
    pub population: Vec<Rim<T>>,
    pub size: usize,
}
Expand description

Population of Rim vectors.

Fields§

§population: Vec<Rim<T>>§size: usize

Implementations§

Source§

impl<T> RimPopulation<T>

Source

pub fn from_vec(vec: &Vec<Vec<T>>) -> Result<RimPopulation<T>, Error>

Creates an InversionPopulation based on a given matrix.

§Errors

Returns a LengthError if the length of all vectors is not equal.

§Example
use permu_rs::rim::RimPopulation;
let pop_matrix: Vec<Vec<u16>> = vec![vec![0,2,0,0], vec![1,2,0,0], vec![0,0,0,0]];
let pop = RimPopulation::from_vec(&pop_matrix).unwrap();

println!("{}", pop);

// Now, the second vector contais one item less 
let pop_matrix: Vec<Vec<u16>> = vec![vec![0,2,0,0], vec![1,0,0], vec![0,0,0,0]];
let pop = RimPopulation::from_vec(&pop_matrix); // This should return a LengthError
assert!(pop.is_err());
Source

pub fn zeros(size: usize, length: usize) -> RimPopulation<T>

Creates a RimPopulation of zero valued Rim vectors of the size and length given.

§Example
use permu_rs::rim::RimPopulation;

let (size, length) = (7, 5);
let pop = RimPopulation::<u8>::zeros(size, length);
println!("{}", pop);
Source

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

Takes a PermuPopulation as an output and fills this population with the Permutation representation of each Rimvector in the RimPopulation. RimPopulation to its Permutation representation. Positions of vectors are respected.

§Errors

Returns a LengthError if the size of both population isn’t equal or the length of the Permutations isn’t the length of the Rim vectors + 1.

§Example
use permu_rs::{
    permutation::{ Permutation, PermuPopulation },
    rim::RimPopulation };

let (size, length) = (10, 5);
let rim_zeros = RimPopulation::<u16>::zeros(size, length-1);
let mut permus = PermuPopulation::<u16>::random(size, length);
// The output should look like this
let target = PermuPopulation::<u16>::from_vec(vec![
                Permutation::<u16>::from_vec(vec![4,3,2,1,0]).unwrap();size]);

// Convert the rim population to its permutation representation 
rim_zeros.to_permus(&mut permus).unwrap();
assert_eq!(target, permus);
Source

pub fn from_permus( permu_pop: &PermuPopulation<T>, rim_pop: &mut RimPopulation<T>, ) -> Result<(), Error>

Fills a RimPopulation with the rim vector representation of each permutation vector inside a given PermuPopulation. Note that the sizes of both populations must match and the length of permutations must be equal to the length of the rim vectors + 1.

§Errors

Returns a LengthError if the size of both population isn’t equal or the length of the Permutations isn’t the length of the Rim vectors + 1.

§Example
use permu_rs::{
    permutation::PermuPopulation,
    rim::RimPopulation,
};
// Create a target population of random permutations
let mut permus = PermuPopulation::<u8>::random(10, 5);
let target = permus.clone();
// Init rim population
let mut rims = RimPopulation::<u8>::zeros(10, 4);

// Convert the permutations into rim vectors and then recover the 
// original permutations from the rim vectors.
RimPopulation::from_permus(&permus, &mut rims).unwrap();
RimPopulation::to_permus(&rims, &mut permus).unwrap();

assert_eq!(target, permus);

Trait Implementations§

Source§

impl<T: Clone> Clone for RimPopulation<T>

Source§

fn clone(&self) -> RimPopulation<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for RimPopulation<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for RimPopulation<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: PartialEq> PartialEq for RimPopulation<T>

Source§

fn eq(&self, other: &RimPopulation<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Population<T> for RimPopulation<T>

Source§

fn learn(&self) -> Distribution

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);
Source§

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

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);
Source§

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

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

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

Maps a given PermuPopulation into the current Population’s representation.
Source§

impl<T> StructuralPartialEq for RimPopulation<T>

Auto Trait Implementations§

§

impl<T> Freeze for RimPopulation<T>

§

impl<T> RefUnwindSafe for RimPopulation<T>
where T: RefUnwindSafe,

§

impl<T> Send for RimPopulation<T>
where T: Send,

§

impl<T> Sync for RimPopulation<T>
where T: Sync,

§

impl<T> Unpin for RimPopulation<T>
where T: Unpin,

§

impl<T> UnwindSafe for RimPopulation<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.