Ejemplo n.º 1
0
arma::mat exact_trans2(arma::cube joint_means_trans, Rcpp::List eigen_decomp, double time_int, arma::ivec absorb_states, int start_state, int end_state, int exact_time_index){
	arma::mat rate_matrix=Rcpp::as<arma::mat>(eigen_decomp["rate"]);
	arma::mat out=arma::zeros<arma::mat>(rate_matrix.n_rows,rate_matrix.n_rows);
	
	arma::mat temp=arma::zeros<arma::mat>(rate_matrix.n_rows,rate_matrix.n_rows);
	
	int i=start_state-1;
	int j=end_state-1;
	int k=0;  
	
	bool i_in_A=0;
	bool j_in_A=0;
	
	//std::cout<<absorb_states;
	
	while(i_in_A==0 && k<absorb_states.size()){
		int test=absorb_states[k]-1;
		if(test==i){
			i_in_A=1;
		}
		k++;
	}
	
	k=0;
	while(j_in_A==0 && k<absorb_states.size()){
		int test=absorb_states[k]-1;
		if(test==j){
			j_in_A=1;
		}
		k++;
	}
	
	int in_either=i_in_A+j_in_A;

	
	if(in_either==0){
		for(int l=0;l<absorb_states.size();l++){
			int absorb_state=absorb_states[l]-1;
			temp.col(absorb_state)=rate_matrix.col(absorb_state);
		}
		out=joint_means_trans.slice(exact_time_index)*temp;
	}
	if(i_in_A==0 && j_in_A==1){
		arma::mat prob_mat=mat_exp_eigen_cpp(eigen_decomp,time_int);
		out.col(j)=prob_mat.col(i)*rate_matrix(i,j);
	}
	
	
	return(out);
}	
Ejemplo n.º 2
0
arma::mat joint_dur_dur_exact_time(int i,int j, double interval_len, arma::ivec absorb_states,Rcpp::List eigen_decomp){
	arma::cx_mat Q=Rcpp::as<arma::cx_mat>(eigen_decomp["rate"]);
	double t=interval_len;
	arma::mat joint_dur=joint_duration_2moment(i, j,eigen_decomp,t);
	arma::cx_mat temp=arma::zeros<arma::cx_mat>(Q.n_rows,Q.n_rows);
	
	bool i_in_A=0;
	bool j_in_A=0;
	int k=0;	
	//std::cout<<absorb_states;
	
	while(i_in_A==0 && k<absorb_states.size()){
		int test=absorb_states[k];
		if(test==i){
			i_in_A=1;
		}
		k++;
	}
	
	k=0;
	while(j_in_A==0 && k<absorb_states.size()){
		int test=absorb_states[k];
		if(test==j){
			j_in_A=1;
		}
		k++;
	}
	
	int in_either=i_in_A+j_in_A;
	
	if(i_in_A+j_in_A==0){
		
		for(int l=0;l<absorb_states.size();l++){
			int absorb_state=absorb_states[l];
			temp.col(absorb_state)=Q.col(absorb_state);
		}
		
		temp=joint_dur*temp;
		
		
	}else{
		temp=arma::zeros<arma::cx_mat>(Q.n_rows,Q.n_rows);
	}
	arma::mat out=arma::real(temp);   
	return(out);
	
}