예제 #1
0
proto_model::proto_model(ast_manager & m, simplifier & s, params_ref const & p):
    model_core(m),
    m_asts(m),
    m_simplifier(s),
    m_afid(m.mk_family_id(symbol("array"))) {
    register_factory(alloc(basic_factory, m));
    m_user_sort_factory = alloc(user_sort_factory, m);
    register_factory(m_user_sort_factory);
    
    m_model_partial = model_params(p).partial();
}
예제 #2
0
//' Generate Latent Time Series based on Model (Internal)
//' 
//' Create a latent time series based on a supplied time series model.
//' @param N       An \code{interger} containing the amount of observations for the time series.
//' @param theta   A \code{vec} containing the parameters to use to generate the model.
//' @param desc    A \code{vector<string>} containing the different model types (AR1, WN, etc..).
//' @param objdesc A \code{field<vec>} containing the different model objects e.g. AR1 = c(1,1)
//' @return A \code{mat} containing data for each decomposed and combined time series.
//' @backref src/gen_process.cpp
//' @backref src/gen_process.h
//' @keywords internal
//' @examples
//' # AR
//' set.seed(1336)
//' gen_lts(10, c(.9,1), "AR1", list(c(1,1)))
// [[Rcpp::export]]
arma::mat gen_lts(unsigned int N, const arma::vec& theta, const std::vector<std::string>& desc, const arma::field<arma::vec>& objdesc){
  unsigned int i_theta = 0;
  unsigned int num_desc = desc.size();
  arma::mat x = arma::zeros<arma::mat>(N, num_desc+1);
  
  for(unsigned int i = 0; i < num_desc; i++){
    double theta_value = theta(i_theta);
    std::string element_type = desc[i];
    
    // AR 1
    if(element_type == "AR1" || element_type == "GM"){
      
      // First value is phi, increment for sigma2
      ++i_theta;
      
      // Get sigma2, this increment is taken care of at the end.
      double sig2 = theta(i_theta);
      
      // Compute theoretical WV
      // Store it into cube x
      x.col(i) = gen_ar1(N, theta_value, sig2);
      x.col(num_desc) += x.col(i);
      
    } 
    // WN
    else if(element_type == "WN") {
      x.col(i) = gen_wn(N, theta_value);
      x.col(num_desc) += x.col(i);
    }
    // DR
    else if(element_type == "DR"){
      x.col(i) = gen_dr(N, theta_value);
      x.col(num_desc) += x.col(i);

    }
    // QN
    else if(element_type == "QN"){
      x.col(i) = gen_qn(N, theta_value);
      x.col(num_desc) += x.col(i);
    }
    // RW
    else if(element_type == "RW"){
      x.col(i) = gen_rw(N, theta_value);
      x.col(num_desc) += x.col(i);
    }
    // ARMA
    else {
      // Unpackage ARMA model parameter
      arma::vec model_params = objdesc(i);
      
      // Get position numbers (AR,MA,SIGMA2)
      unsigned int p = model_params(0);
      unsigned int q = model_params(1);
      
      // Set up temp storage
      arma::vec ar;
      arma::vec ma;
      
      // Get AR values
      if(p == 0){
        ar = arma::zeros<arma::vec>(0);
      }else{
        ar = theta.rows(i_theta,i_theta+p-1);
      }
      
      // Account for the number of P values
      i_theta += p;
      
      // Get MA values
      if(q == 0){
        ma = arma::zeros<arma::vec>(0); 
      }else{
        ma = theta.rows(i_theta,i_theta+q-1);
      }
      
      // Account for Q values
      i_theta += q;
      
      // Extract sigma2
      double sig2 = theta(i_theta);
      
      // Modified arima.sim
      x.col(i) = gen_arma(N, ar, ma, sig2, 0);
      x.col(num_desc) += x.col(i);
    }
    
    // Increment theta once to account for popped value
    ++i_theta;
  }  
  
  return x;
}