7 releases
0.2.0 | Sep 11, 2020 |
---|---|
0.1.4 | Nov 13, 2019 |
0.1.3 | Oct 21, 2019 |
#385 in Science
21 downloads per month
88KB
1.5K
SLoC
permu-rs
A collection of utilities for permutations. It contains useful tools to create, manage and experiment with permutations.
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
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Dependencies
~330–520KB