permu-rs

Crates.iopermu-rs
lib.rspermu-rs
version0.2.0
sourcesrc
created_at2019-10-14 20:39:58.41443
updated_at2020-09-11 08:04:46.170153
descriptionA collection of utilities for permutations. It contains useful tools to create, manage and experiment with permutations.
homepage
repositoryhttps://github.com/mikelma/permu-rs/tree/master
max_upload_size
id172537
size227,395
mikel (mikelma)

documentation

README

permu-rs

A collection of utilities for permutations. It contains useful tools to create, manage and experiment with permutations.

Build status

Documentation

You can find the documentation with examples here.

Usage

Add this to your Cargo.toml:

[dependencies]
permu-rs = "0.2.0"

Here's a simple example in order to illustrate how to transform populations from one representation space to another and how to learn and sample distributions:

use permu_rs::permutation::PermuPopulation;
use permu_rs::inversion::InversionPopulation;
use permu_rs::Population;

fn main() {
    let length = 5;     // Length of permutations
    let pop_size = 5;   // Number of individuals in the population

    // Create an identity permutation population
    let identity = PermuPopulation::<u8>::identity(pop_size, length);
    println!("Identity permutation population:\n{}", identity);

    // Initialize an inversion population to hold the inversion vector
    // representation of the population of permutations
    let mut invs = InversionPopulation::<u8>::zeros(pop_size, length-1);

    // Convert the permutation population into its inversion representation
    identity.to_inversion(&mut invs).unwrap();
    println!("Inversion population from permutations:\n{}", invs);

    // Learn a distritibution over the inversion vector population
    let mut distr = invs.learn();
    println!("Distribution of the inversion population:\n{}", distr);

    // Sample the learned distribution creating a new inversion population
    let mut samples = InversionPopulation::<u8>::zeros(pop_size, length-1);
    InversionPopulation::sample(&mut distr, &mut samples).unwrap();
    // Note that the distribution has changed. The distribution was
    // soften inside the sampling procedure.
    println!("Soften distribution of the inversion population:\n{}", distr);
    println!("Sampled solutions from the distribution:\n{}", samples);

    // Create a permutation population to hold the new permutation population
    let mut recovered = PermuPopulation::<u8>::identity(pop_size, length);

    // Convert the sampled inversion vectors to their permutation representation
    samples.to_permus(&mut recovered).unwrap();
    println!("Permutation representation of samples:\n{}", recovered);
}

License

This project is licensed under either of

at your option.

Commit count: 0

cargo fmt