Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellewell14 committed May 2, 2024
1 parent 2782bca commit 4a8edd5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 27 deletions.
23 changes: 0 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ use crate::tree::Tree;
extern crate nalgebra as na;
pub mod cli;
use crate::cli::*;
use crate::mutation::{to_mutation, Mutation};
use logaddexp::{LogAddExp, LogSumExp};

pub fn main() {
let args = cli_args();
Expand All @@ -29,27 +27,6 @@ pub fn main() {
1.0 / 3.0, 1.0 / 3.0, 1.0 / 3.0, -1.0,
);

let mut m1: Mutation = Mutation(0.25, 0.1, 0.5, 0.15);
let p1 = na::Matrix::exp(&(q * 1.0));

let mut outmut: Mutation = Mutation(0.0, 0.0, 0.0, 0.0);
println!("{:?}", m1);

for i in 0..=3 {
if let Some(mut val) = outmut.get_mut(i) {
*val = p1.row(i).iter().zip(m1.iter()).map(|(a, b)| a.ln() + b).reduce(|a, b| a.ln_add_exp(b)).unwrap();
}
}

println!("{:?}", outmut);


// for

// let y1: Mutation = to_mutation((0..=3).into_iter().map(|ind| {
// hi: Option<f64> = p1.row(ind).iter().zip(m1.iter()).map(|(a, b)| a.ln() + b).reduce(|a, b| a.ln_add_exp(b));
// }).collect());

let mut tr = vector_to_tree(&random_vector(27));

// let end = Instant::now();
Expand Down
8 changes: 4 additions & 4 deletions src/likelihoods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ pub fn calculate_likelihood(
}

// LogSumExp function
pub fn logse(x: Vec<f64>) -> f64 {
let xstar = x.iter().max_by(|x, y| x.total_cmp(y)).unwrap();
xstar + x.iter().fold(0.0,|acc, el| acc + f64::exp(el - xstar)).ln()
}
// pub fn logse(x: Vec<f64>) -> f64 {
// let xstar = x.iter().max_by(|x, y| x.total_cmp(y)).unwrap();
// xstar + x.iter().fold(0.0,|acc, el| acc + f64::exp(el - xstar)).ln()
// }

// LogSumExp function that includes base frequency values for final likelihood calculation
pub fn base_freq_logse(muta: &Mutation, bf: [f64; 4]) -> f64 {
Expand Down

0 comments on commit 4a8edd5

Please sign in to comment.