Skip to content

Commit

Permalink
put update_missing_ranks into Augmentation class
Browse files Browse the repository at this point in the history
  • Loading branch information
osorensen committed Nov 23, 2023
1 parent 2a4e679 commit 393ce11
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 31 deletions.
21 changes: 21 additions & 0 deletions src/classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,24 @@ void Augmentation::augment_pairwise(
}
}
}


void Augmentation::update_missing_ranks(
Data& dat,
const Clustering& clus,
const Parameters& pars) {

if(!any_missing) return;

for(int i = 0; i < dat.n_assessors; ++i){

int cluster = clus.current_cluster_assignment(i);

dat.rankings.col(i) = make_new_augmentation(
dat.rankings.col(i), missing_indicator.col(i),
pars.alpha_old(cluster), pars.rho_old.col(cluster),
pars.metric
);

}
}
7 changes: 7 additions & 0 deletions src/classes.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ struct Augmentation {
void augment_pairwise(Data& dat, const Parameters& pars,
const Clustering& clus, const Priors& pris);

void update_missing_ranks(
Data& dat,
const Clustering& clus,
const Parameters& pars
);


};


Expand Down
19 changes: 0 additions & 19 deletions src/missing_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,6 @@ void initialize_missing_ranks(mat& rankings, const umat& missing_indicator) {
}
}

void update_missing_ranks(mat& rankings, const uvec& current_cluster_assignment,
const umat& missing_indicator,
const vec& alpha, const mat& rho,
const std::string& metric) {

int n_assessors = rankings.n_cols;

for(int i = 0; i < n_assessors; ++i){

int cluster = current_cluster_assignment(i);

rankings.col(i) = make_new_augmentation(
rankings.col(i), missing_indicator.col(i),
alpha(cluster), rho.col(cluster), metric
);

}
}

vec make_new_augmentation(const vec& rankings, const uvec& missing_indicator,
const double& alpha, const vec& rho,
const std::string& metric, bool pseudo) {
Expand Down
4 changes: 0 additions & 4 deletions src/missing_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ void set_up_missing(arma::mat& rankings, arma::umat& missing_indicator);

void initialize_missing_ranks(arma::mat& rankings, const arma::umat& missing_indicator);

void update_missing_ranks(arma::mat& rankings, const arma::uvec& current_cluster_assignment,
const arma::umat& missing_indicator,
const arma::vec& alpha, const arma::mat& rho,
const std::string& metric);

Rcpp::List make_pseudo_proposal(
arma::uvec unranked_items, arma::vec rankings, const double& alpha,
Expand Down
9 changes: 1 addition & 8 deletions src/run_mcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,9 @@ Rcpp::List run_mcmc(Rcpp::List data,

clus.update_wcd(t);

// Perform data augmentation of missing ranks, if needed
if(aug.any_missing){
update_missing_ranks(dat.rankings, clus.current_cluster_assignment, aug.missing_indicator,
pars.alpha_old, pars.rho_old, pars.metric);
}

// Perform data augmentation of pairwise comparisons, if needed
aug.update_missing_ranks(dat, clus, pars);
aug.augment_pairwise(dat, pars, clus, pris);

// Save augmented data if the user wants this. Uses the same index as rho.
if(aug.save_aug & (t % aug.aug_thinning == 0)){
++aug_index;
aug.augmented_data.slice(aug_index) = dat.rankings;
Expand Down

0 comments on commit 393ce11

Please sign in to comment.