use ndarray::{Array, Ix2};
use ndarray_rand::RandomExt;
use rand::distributions::WeightedIndex;
pub fn generate_g_matrix(num_people: usize, num_snps: usize, zero_prob: f64, two_prob: f64) -> Result<Array<u8, Ix2>, String> {
if zero_prob < 0. || two_prob < 0. || zero_prob + two_prob > 1. {
return Err(format!("invalid probabilities {} {} {}", zero_prob, 1. - zero_prob - two_prob, two_prob));
}
let weights = [zero_prob, 1. - zero_prob - two_prob, two_prob];
let dist = WeightedIndex::new(&weights).unwrap();
Ok(Array::random((num_people, num_snps), dist).mapv(|e| e as u8))
}
pub fn get_gxg_arr(geno_arr: &Array<f32, Ix2>) -> Array<f32, Ix2> {
let (num_rows, num_cols) = geno_arr.dim();
let num_cols_gxg = num_cols * (num_cols - 1) / 2;
let mut gxg = Array::zeros((num_rows, num_cols_gxg));
let mut k = 0;
for row in geno_arr.genrows() {
let mut gxg_col_j = 0usize;
for i in 0..num_cols {
for j in i + 1..num_cols {
gxg[[k, gxg_col_j]] = row[i] * row[j];
gxg_col_j += 1;
}
}
k += 1;
}
gxg
}