fn make_w<R: Rng>(
    rng: &mut R,
    fitted_y: &Matrix,
    sigma: &Matrix,
    sample_sums: &[f64],
    base_taxa: usize,
) -> Matrix {
    let makew_start = SystemTime::now();

    // sigma.ncols() -> NT-1

    let num_samples = fitted_y.ncols();
    let num_taxa = fitted_y.nrows() + 1; // NT-1 w.r.t. W (count matrix)

    assert_eq!(sample_sums.len(), num_samples);

    if sigma.ncols() != fitted_y.nrows() {
        panic!("bad dimensions for sigma and fitted_y");
    }

    let mut new_y = Matrix::zeros(num_taxa - 1, num_samples);

    for sample_idx in 0..num_samples {
        let sample = fitted_y.col(sample_idx);
        // will be 1 x num_taxa

        let norm_vals = mvrnorm(rng, 1, &sample, &sigma);

        assert_eq!((1, num_taxa - 1), norm_vals.dim());

        for (taxa_idx, &x) in norm_vals.row(0).iter().enumerate() {
            new_y.set(taxa_idx, sample_idx, x);
        }
    }

    let compositions = to_composition_matrix(&new_y, base_taxa);
    assert_eq!(compositions.dim(), (num_taxa, num_samples));

    let mut bootstrap_counts = Matrix::zeros(num_taxa, num_samples);

    unsafe {
        for sample_idx in 0..compositions.ncols() {
            //i is also the sample index
            let sample_sum = sample_sums[sample_idx].round() as usize;

            let probs = compositions.col(sample_idx);

            // Each draw specifies a taxa to sample.
            let draws = multinomial::multinomial(rng, 1, sample_sum, &probs);

            for taxa_idx in 0..draws.len() {
                let old_val = bootstrap_counts.get_unchecked(taxa_idx, sample_idx);
                let new_val = old_val + draws[taxa_idx];
                bootstrap_counts.set_unchecked(taxa_idx, sample_idx, new_val);
            }
        }
    }

    log::debug!("`make_w` took {:?}", makew_start.elapsed().unwrap());

    bootstrap_counts
}
/// output should be same dim as fitted_y
output should be same dim as fitted_y
output should be same dim as fitted_y
fn make_w<R: Rng>(
    rng: &mut R,
    fitted_y: &Matrix,
    sigma: &Matrix,
    sample_sums: &[f64],
    base_taxa: usize,
) -> Matrix {
    let makew_start = SystemTime::now();
    // sigma.ncols() -> NT-1
    let num_samples = fitted_y.ncols();
    let num_taxa = fitted_y.nrows() + 1; // NT-1 w.r.t. W (count matrix)
    assert_eq!(sample_sums.len(), num_samples);
    if sigma.ncols() != fitted_y.nrows() {
        panic!("bad dimensions for sigma and fitted_y");
    }
    let mut new_y = Matrix::zeros(num_taxa - 1, num_samples);
    for sample_idx in 0..num_samples {
        let sample = fitted_y.col(sample_idx);
        // will be 1 x num_taxa
        let norm_vals = mvrnorm(rng, 1, &sample, &sigma);
        assert_eq!((1, num_taxa - 1), norm_vals.dim());
        for (taxa_idx, &x) in norm_vals.row(0).iter().enumerate() {
            new_y.set(taxa_idx, sample_idx, x);
        }
    }
    let compositions = to_composition_matrix(&new_y, base_taxa);
    assert_eq!(compositions.dim(), (num_taxa, num_samples));
    let mut bootstrap_counts = Matrix::zeros(num_taxa, num_samples);
    unsafe {
        for sample_idx in 0..compositions.ncols() {
            //i is also the sample index
            let sample_sum = sample_sums[sample_idx].round() as usize;
            let probs = compositions.col(sample_idx);
            // Each draw specifies a taxa to sample.
            let draws = multinomial::multinomial(rng, 1, sample_sum, &probs);
            for taxa_idx in 0..draws.len() {
                let old_val = bootstrap_counts.get_unchecked(taxa_idx, sample_idx);
                let new_val = old_val + draws[taxa_idx];
                bootstrap_counts.set_unchecked(taxa_idx, sample_idx, new_val);
            }
        }
    }
    log::debug!("`make_w` took {:?}", makew_start.elapsed().unwrap());
    bootstrap_counts
}
fn make_w < R : Rng > ( rng : & mut R , fitted_y : & Matrix , sigma : & Matrix , sample_sums : & [ f64 ] , base_taxa : usize , ) -> Matrix { let makew_start = SystemTime :: now ( ) ; // sigma.ncols() -> NT-1 let num_samples = fitted_y . ncols ( ) ; let num_taxa = fitted_y . nrows ( ) + 1 ; // NT-1 w.r.t. W (count matrix) assert_eq ! ( sample_sums len ( ) num_samples ) ; if sigma . ncols ( ) != fitted_y . nrows ( ) { panic ! ( " " ) ; } let mut new_y = Matrix :: zeros ( num_taxa - 1 , num_samples ) ; for sample_idx in 0 .. num_samples { let sample = fitted_y . col ( sample_idx ) ; // will be 1 x num_taxa let norm_vals = mvrnorm ( rng , 1 , & sample , & sigma ) ; assert_eq ! ( ( 1 num_taxa 1 ) norm_vals dim ( ) ) ; for ( taxa_idx , & x ) in norm_vals . row ( 0 ) . iter ( ) . enumerate ( ) { new_y . set ( taxa_idx , sample_idx , x ) ; } } let compositions = to_composition_matrix ( & new_y , base_taxa ) ; assert_eq ! ( compositions dim ( ) ( num_taxa num_samples ) ) ; let mut bootstrap_counts = Matrix :: zeros ( num_taxa , num_samples ) ; unsafe { for sample_idx in 0 .. compositions . ncols ( ) { //i is also the sample index let sample_sum = sample_sums [ sample_idx ] . round ( ) as usize ; let probs = compositions . col ( sample_idx ) ; // Each draw specifies a taxa to sample. let draws = multinomial :: multinomial ( rng , 1 , sample_sum , & probs ) ; for taxa_idx in 0 .. draws . len ( ) { let old_val = bootstrap_counts . get_unchecked ( taxa_idx , sample_idx ) ; let new_val = old_val + draws [ taxa_idx ] ; bootstrap_counts . set_unchecked ( taxa_idx , sample_idx , new_val ) ; } } } log :: debug ! ( " " makew_start elapsed ( ) unwrap ( ) ) ; bootstrap_counts }
output should be same dim as fitted_y
output should be same dim as fitted_y
rng
&mut R
fitted_y
&Matrix
sigma
&Matrix
sample_sums
&[f64]
base_taxa
usize