double getSimilarity(double t,substitution::MultiModel& SM) { double S = 0; for(int m=0;m<SM.n_base_models();m++) { // We can't use models with more than one part Matrix Q = SM.transition_p(t,0,m); double Sm = 0; for(int i=0;i<Q.size1();i++) Sm += SM.base_model(m).frequencies()[i]*Q(i,i); S += Sm * SM.distribution()[m]; } return S; }
void show_frequencies(std::ostream& o,const substitution::MultiModel& MModel) { const alphabet& a = MModel.Alphabet(); if (MModel.n_base_models() == 1) { const valarray<double>& f = MModel.base_model(0).frequencies(); for(int i=0;i<a.size();i++) o<<"f"<<a.lookup(i)<<" = "<<f[i]<<"\n"; } else { for(int i=0;i<a.size();i++) { double total = 0; for(int m=0;m<MModel.n_base_models();m++) { const valarray<double>& f = MModel.base_model(m).frequencies(); o<<"f"<<a.lookup(i)<<m+1<<" = "<<f[i]<<" "; total += MModel.distribution()[m] * f[i]; } o<<"f"<<a.lookup(i)<<" = "<<total<<"\n"; } } }
void analyze_rates(const alignment& A,const SequenceTree& T, const substitution::MultiModel& smodel) { if (smodel.n_base_models() == 1) return; data_partition DP("DP",A,T,smodel); vector< vector<double> > rate_probs = substitution::get_model_probabilities_by_alignment_column(DP); vector<double> prior_bin_f = smodel.distribution(); vector<double> post_bin_f = get_post_rate_probs(rate_probs); show_rate_probs(cout,rate_probs,smodel); double prior_rate=0; double post_rate=0; for(int i=0;i<prior_bin_f.size();i++) { prior_rate += prior_bin_f[i]*smodel.base_model(i).rate(); post_rate += post_bin_f[i]*smodel.base_model(i).rate(); } for(int i=0;i<smodel.n_base_models();i++) cout<<" rate"<<i<<" = "<<smodel.base_model(i).rate(); cout<<endl<<endl; cout<<" Prior rate = "<<prior_rate<<endl;; for(int i=0;i<smodel.n_base_models();i++) cout<<" prior_bin_f"<<i<<" = "<<prior_bin_f[i]; cout<<endl<<endl; cout<<" Posterior rate = "<<post_rate<<endl;; for(int i=0;i<smodel.n_base_models();i++) cout<<" post_bin_f"<<i<<" = "<<post_bin_f[i]; cout<<endl<<endl; for(int i=0;i<smodel.n_base_models();i++) cout<<" odds_ratio"<<i<<" = "<<post_bin_f[i]/prior_bin_f[i]; cout<<endl<<endl; }