当前位置: 首页>>代码示例>>C++>>正文


C++ NumericVector::names方法代码示例

本文整理汇总了C++中NumericVector::names方法的典型用法代码示例。如果您正苦于以下问题:C++ NumericVector::names方法的具体用法?C++ NumericVector::names怎么用?C++ NumericVector::names使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NumericVector的用法示例。


在下文中一共展示了NumericVector::names方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: attribs

// [[Rcpp::export]]
NumericVector attribs() {
  NumericVector out = NumericVector::create(1, 2, 3);

  out.names() = CharacterVector::create("a", "b", "c");
  out.attr("my-attr") = "my-value";
  out.attr("class") = "my-class";

  return out;
}
开发者ID:Maddocent,项目名称:TeachingMaterial,代码行数:10,代码来源:ex.cpp

示例2: map

// [[Rcpp::export]]
std::unordered_map<std::string, Node*> internal_huffman_map(NumericVector probabilities) {
  std::unordered_map<std::string, Node*> map(probabilities.size());
  CharacterVector items = probabilities.names();
  visitNodes(internal_huffman_encode(probabilities), "", [&items, &map] (Node *n, string s) {
    if (n->index >= 0) {
      map[(const string) items[n->index]] = n;
    }
  });
  return map;
}
开发者ID:bskaggs,项目名称:huffmanr,代码行数:11,代码来源:priority_queue.cpp

示例3: huffman_encode

// [[Rcpp::export]]
Environment huffman_encode(NumericVector probabilities) {
  CharacterVector items = probabilities.names();
  Environment env = Environment::empty_env().new_child(true);
  
  visitNodes(internal_huffman_encode(probabilities), "", [&items, &env] (Node *n, string s) {
    if (n->index >= 0) {
      env.assign((const string) items[n->index], s);
    }
    delete n;
  });
  return env;
}
开发者ID:bskaggs,项目名称:huffmanr,代码行数:13,代码来源:priority_queue.cpp

示例4: mse_compare_cpp

// [[Rcpp::export]]
NumericVector mse_compare_cpp(double b, colvec p, mat Ve, 
              mat Vz, int n, int n_reps){
//Function to run n_reps of the simulation study and calculate the MSE
//of various estimators

  colvec ols(n_reps);
  colvec tsls(n_reps);
  colvec fmsc(n_reps);
  colvec DHW90(n_reps);
  colvec DHW95(n_reps);
  colvec AVG(n_reps);

  for(int i = 0; i < n_reps; i++){
    
    dgp_OLS_IV sim_data(b, p, Ve, Vz, n);
    fmsc_OLS_IV sim_results(sim_data.x, sim_data.y, sim_data.z);

    ols(i) = sim_results.b_ols();
    tsls(i) = sim_results.b_tsls();
    fmsc(i) = sim_results.b_fmsc();
    DHW90(i) = sim_results.b_DHW(0.1);
    DHW95(i) = sim_results.b_DHW(0.05);
    AVG(i) = sim_results.b_AVG();
    
  }
  
  double const trim_frac = 0; //Change this if you want trimmed MSE
  
  double MSE_ols = MSE_trim(ols, b, trim_frac);
  double MSE_tsls = MSE_trim(tsls, b, trim_frac);
  double MSE_fmsc = MSE_trim(fmsc, b, trim_frac);
  double MSE_DHW90 = MSE_trim(DHW90, b, trim_frac);
  double MSE_DHW95 = MSE_trim(DHW95, b, trim_frac);
  double MSE_star = MSE_trim(AVG, b, trim_frac);
  
  //Create and return vector of results
  NumericVector out = NumericVector::create(MSE_ols, MSE_tsls, MSE_fmsc, 
                        MSE_star, MSE_DHW90, MSE_DHW95);
  out.names() = CharacterVector::create("OLS", "TSLS", "FMSC", 
                        "AVG", "DHW90", "DHW95");
  return(out);  

  
}
开发者ID:fditraglia,项目名称:fmsc,代码行数:45,代码来源:functions.cpp

示例5: CIs_compare_default_cpp

// [[Rcpp::export]]
List CIs_compare_default_cpp(double p , double r, int n, 
                                        int n_reps){
//Function to test the confidence interval code with the same parameter
//values as in mse_compare_default_cpp
//In this specification there are three instruments (z1, z2, z3)
//which ensures that the finite-sample RMSE of the 2SLS estimator exists.
//Further, the design sets
//  var(x) = 1
//  corr(e,v) = r
//  cor(x, z1 + z2 + z3) = p
  double b = 0.5;
  colvec p_vec = p * ones(3);
  mat Vz = eye(3, 3) / 3;
  
  mat Ve;
  Ve << 1 << r * sqrt(1 - pow(p,2)) << endr
     << r * sqrt(1 - pow(p,2)) << 1 - pow(p, 2) << endr;

//Default to nominal 90% CIs
  double nominal_coverage = 0.9;
  double alpha_1step = 1 - nominal_coverage;
//Same level for each interval in the 2-step procedures
  double alpha_2step = alpha_1step / 2; 
//Number of simulations for sim-based CIs
  int n_CI_sims = 1000;
//Grid for tau
  int n_tau_grid = 100;

  mat OLS(n_reps, 2, fill::zeros);
  mat TSLS(n_reps, 2, fill::zeros);
  mat FMSC_naive(n_reps, 2, fill::zeros);
  mat FMSC_1step(n_reps, 2, fill::zeros);
  mat FMSC_correct(n_reps, 2, fill::zeros);
  mat AVG_1step(n_reps, 2, fill::zeros);
  mat AVG_correct(n_reps, 2, fill::zeros);
  
  for(int i = 0; i < n_reps; i++){
    
    //Simulate data and calculate estimators
    dgp_OLS_IV data(b, p_vec, Ve, Vz, n);
    fmsc_OLS_IV results(data.x, data.y, data.z);
    
    //CIs that do not require draw_CI_sims()
    OLS.row(i) = results.CI_ols(alpha_1step);
    TSLS.row(i) = results.CI_tsls(alpha_1step);
    FMSC_naive.row(i) = results.CI_fmsc_naive(alpha_1step);
    
    //Initialization for CIs constructed using simulations
    results.draw_CI_sims(n_CI_sims);
    
    //One-step simulation-based CIs
    FMSC_1step.row(i) = results.CI_fmsc_1step(alpha_1step);
    AVG_1step.row(i) = results.CI_AVG_1step(alpha_1step);
    
    //Two-step simulation-based CIs
    FMSC_correct.row(i) = results.CI_fmsc_correct(alpha_2step, 
                                                  alpha_2step,
                                                  n_tau_grid);
    AVG_correct.row(i) = results.CI_AVG_correct(alpha_2step, 
                                                alpha_2step,
                                                n_tau_grid);
    
  }

  CharacterVector col_names = CharacterVector::create("OLS",
                                                      "TSLS",
                                                      "FMSC_naive",
                                                      "FMSC_1step",
                                                      "FMSC_correct", 
                                                      "AVG_1step",  
                                                      "AVG_correct"); 
  
  NumericVector cover = NumericVector::create(coverage_prob(OLS, b),
                                              coverage_prob(TSLS, b),
                                              coverage_prob(FMSC_naive, b),
                                              coverage_prob(FMSC_1step, b),
                                              coverage_prob(FMSC_correct, b),
                                              coverage_prob(AVG_1step, b),
                                              coverage_prob(AVG_correct, b));
  cover.names() = col_names;
  
  NumericVector width = NumericVector::create(median_width(OLS),
                                              median_width(TSLS),
                                              median_width(FMSC_naive),
                                              median_width(FMSC_1step),
                                              median_width(FMSC_correct),
                                              median_width(AVG_1step),
                                              median_width(AVG_correct));
  width.names() = col_names;
  
  return List::create(Named("coverage.prob") = cover,
                      Named("median.width") = width);
}
开发者ID:fditraglia,项目名称:fmsc,代码行数:94,代码来源:functions.cpp


注:本文中的NumericVector::names方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。