7个版本
0.2.0 | 2020年9月11日 |
---|---|
0.1.4 | 2019年11月13日 |
0.1.3 | 2019年10月21日 |
#347 in 科学
每月 21 次下载
88KB
1.5K SLoC
permu-rs
排列工具集合。它包含创建、管理和实验排列的有用工具。
文档
您可以在此处找到带有示例的文档。
使用方法
将此内容添加到您的 Cargo.toml
[dependencies]
permu-rs = "0.2.0"
以下是一个简单的示例,说明如何将种群从一种表示空间转换到另一种表示空间,以及如何学习和采样分布。
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);
}
许可证
此项目可在以下任一许可证下使用:
- Apache License, Version 2.0, (LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT许可证 (LICENSE-MIT 或 http://opensource.org/licenses/MIT)
任选其一。
依赖关系
~320–500KB