Beispiel #1
0
arma::mat uniformization_prob2(double t, arma::mat rate){
	
	arma::colvec the_diag=-1*rate.diag();
	double mu=the_diag.max();
	arma::mat A=arma::eye<arma::mat>(rate.n_cols,rate.n_cols)+rate/mu;
	
	int s=0;
	arma::mat out_sum=arma::zeros<arma::mat>(rate.n_cols,rate.n_cols);
	double error=(1-exp(-mu*t));
	arma::mat A_s=arma::eye<arma::mat>(rate.n_cols,rate.n_cols);
	
	while(error>1e-9){
		double mu_t=mu*t;
		out_sum=out_sum+exp(-mu*t)*A_s*pow(mu_t,s)/(Rcpp::internal::factorial(s)); 
		A_s=A_s*A;
		s++;
		error=error-exp(-mu*t)*pow(mu*t,s)/(Rcpp::internal::factorial(s));
	}
	return(out_sum);
}
Beispiel #2
0
 //! Force a covariance matrix to be diagonal.
 static void ApplyConstraint(arma::mat& covariance)
 {
   // Save the diagonal only.
   arma::vec diagonal = covariance.diag();
   covariance = arma::diagmat(diagonal);
 }
 double cholesky_determinant(const arma::mat& R) {
   return arma::prod(square(R.diag()));
 }