Skip to content

Commit e008ffd

Browse files
Small change for naming consistency
1 parent ae27b72 commit e008ffd

File tree

10 files changed

+67
-66
lines changed

10 files changed

+67
-66
lines changed

R/RcppExports.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ run_bgmCompare_parallel <- function(observations, num_groups, counts_per_categor
55
.Call(`_bgms_run_bgmCompare_parallel`, observations, num_groups, counts_per_category, blume_capel_stats, pairwise_stats, num_categories, main_alpha, main_beta, pairwise_scale, difference_scale, difference_selection_alpha, difference_selection_beta, difference_prior, iter, burnin, na_impute, missing_data_indices, is_ordinal_variable, baseline_category, difference_selection, main_effect_indices, pairwise_effect_indices, target_accept, nuts_max_depth, learn_mass_matrix, projection, group_membership, group_indices, interaction_index_matrix, inclusion_probability, num_chains, nThreads, seed, update_method, hmc_num_leapfrogs)
66
}
77

8-
run_bgm_parallel <- function(observations, num_categories, interaction_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed) {
9-
.Call(`_bgms_run_bgm_parallel`, observations, num_categories, interaction_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed)
8+
run_bgm_parallel <- function(observations, num_categories, pairwise_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed) {
9+
.Call(`_bgms_run_bgm_parallel`, observations, num_categories, pairwise_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed)
1010
}
1111

1212
sample_omrf_gibbs <- function(no_states, no_variables, no_categories, interactions, thresholds, iter) {

R/bgm.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ bgm = function(
503503

504504
out = run_bgm_parallel(
505505
observations = x, num_categories = num_categories,
506-
interaction_scale = interaction_scale, edge_prior = edge_prior,
506+
pairwise_scale = interaction_scale, edge_prior = edge_prior,
507507
inclusion_probability = inclusion_probability,
508508
beta_bernoulli_alpha = beta_bernoulli_alpha,
509509
beta_bernoulli_beta = beta_bernoulli_beta,

R/bgmCompare.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ bgmCompare = function(
7878
x,
7979
y,
8080
group_indicator,
81-
difference_selection = FALSE,
81+
difference_selection = TRUE,
8282
variable_type = "ordinal",
8383
baseline_category,
8484
difference_scale = 1,

man/bgmCompare.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/RcppExports.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@ BEGIN_RCPP
5757
END_RCPP
5858
}
5959
// run_bgm_parallel
60-
Rcpp::List run_bgm_parallel(const arma::imat& observations, const arma::ivec& num_categories, double interaction_scale, const std::string& edge_prior, const arma::mat& inclusion_probability, double beta_bernoulli_alpha, double beta_bernoulli_beta, double dirichlet_alpha, double lambda, const arma::imat& interaction_index_matrix, int iter, int burnin, const arma::imat& counts_per_category, const arma::imat& blume_capel_stats, double main_alpha, double main_beta, bool na_impute, const arma::imat& missing_index, const arma::uvec& is_ordinal_variable, const arma::ivec& baseline_category, bool edge_selection, const std::string& update_method, const arma::imat& pairwise_effect_indices, double target_accept, const arma::imat& pairwise_stats, int hmc_num_leapfrogs, int nuts_max_depth, bool learn_mass_matrix, int num_chains, int nThreads, uint64_t seed);
61-
RcppExport SEXP _bgms_run_bgm_parallel(SEXP observationsSEXP, SEXP num_categoriesSEXP, SEXP interaction_scaleSEXP, SEXP edge_priorSEXP, SEXP inclusion_probabilitySEXP, SEXP beta_bernoulli_alphaSEXP, SEXP beta_bernoulli_betaSEXP, SEXP dirichlet_alphaSEXP, SEXP lambdaSEXP, SEXP interaction_index_matrixSEXP, SEXP iterSEXP, SEXP burninSEXP, SEXP counts_per_categorySEXP, SEXP blume_capel_statsSEXP, SEXP main_alphaSEXP, SEXP main_betaSEXP, SEXP na_imputeSEXP, SEXP missing_indexSEXP, SEXP is_ordinal_variableSEXP, SEXP baseline_categorySEXP, SEXP edge_selectionSEXP, SEXP update_methodSEXP, SEXP pairwise_effect_indicesSEXP, SEXP target_acceptSEXP, SEXP pairwise_statsSEXP, SEXP hmc_num_leapfrogsSEXP, SEXP nuts_max_depthSEXP, SEXP learn_mass_matrixSEXP, SEXP num_chainsSEXP, SEXP nThreadsSEXP, SEXP seedSEXP) {
60+
Rcpp::List run_bgm_parallel(const arma::imat& observations, const arma::ivec& num_categories, double pairwise_scale, const std::string& edge_prior, const arma::mat& inclusion_probability, double beta_bernoulli_alpha, double beta_bernoulli_beta, double dirichlet_alpha, double lambda, const arma::imat& interaction_index_matrix, int iter, int burnin, const arma::imat& counts_per_category, const arma::imat& blume_capel_stats, double main_alpha, double main_beta, bool na_impute, const arma::imat& missing_index, const arma::uvec& is_ordinal_variable, const arma::ivec& baseline_category, bool edge_selection, const std::string& update_method, const arma::imat& pairwise_effect_indices, double target_accept, const arma::imat& pairwise_stats, int hmc_num_leapfrogs, int nuts_max_depth, bool learn_mass_matrix, int num_chains, int nThreads, uint64_t seed);
61+
RcppExport SEXP _bgms_run_bgm_parallel(SEXP observationsSEXP, SEXP num_categoriesSEXP, SEXP pairwise_scaleSEXP, SEXP edge_priorSEXP, SEXP inclusion_probabilitySEXP, SEXP beta_bernoulli_alphaSEXP, SEXP beta_bernoulli_betaSEXP, SEXP dirichlet_alphaSEXP, SEXP lambdaSEXP, SEXP interaction_index_matrixSEXP, SEXP iterSEXP, SEXP burninSEXP, SEXP counts_per_categorySEXP, SEXP blume_capel_statsSEXP, SEXP main_alphaSEXP, SEXP main_betaSEXP, SEXP na_imputeSEXP, SEXP missing_indexSEXP, SEXP is_ordinal_variableSEXP, SEXP baseline_categorySEXP, SEXP edge_selectionSEXP, SEXP update_methodSEXP, SEXP pairwise_effect_indicesSEXP, SEXP target_acceptSEXP, SEXP pairwise_statsSEXP, SEXP hmc_num_leapfrogsSEXP, SEXP nuts_max_depthSEXP, SEXP learn_mass_matrixSEXP, SEXP num_chainsSEXP, SEXP nThreadsSEXP, SEXP seedSEXP) {
6262
BEGIN_RCPP
6363
Rcpp::RObject rcpp_result_gen;
6464
Rcpp::RNGScope rcpp_rngScope_gen;
6565
Rcpp::traits::input_parameter< const arma::imat& >::type observations(observationsSEXP);
6666
Rcpp::traits::input_parameter< const arma::ivec& >::type num_categories(num_categoriesSEXP);
67-
Rcpp::traits::input_parameter< double >::type interaction_scale(interaction_scaleSEXP);
67+
Rcpp::traits::input_parameter< double >::type pairwise_scale(pairwise_scaleSEXP);
6868
Rcpp::traits::input_parameter< const std::string& >::type edge_prior(edge_priorSEXP);
6969
Rcpp::traits::input_parameter< const arma::mat& >::type inclusion_probability(inclusion_probabilitySEXP);
7070
Rcpp::traits::input_parameter< double >::type beta_bernoulli_alpha(beta_bernoulli_alphaSEXP);
@@ -93,7 +93,7 @@ BEGIN_RCPP
9393
Rcpp::traits::input_parameter< int >::type num_chains(num_chainsSEXP);
9494
Rcpp::traits::input_parameter< int >::type nThreads(nThreadsSEXP);
9595
Rcpp::traits::input_parameter< uint64_t >::type seed(seedSEXP);
96-
rcpp_result_gen = Rcpp::wrap(run_bgm_parallel(observations, num_categories, interaction_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed));
96+
rcpp_result_gen = Rcpp::wrap(run_bgm_parallel(observations, num_categories, pairwise_scale, edge_prior, inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta, dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin, counts_per_category, blume_capel_stats, main_alpha, main_beta, na_impute, missing_index, is_ordinal_variable, baseline_category, edge_selection, update_method, pairwise_effect_indices, target_accept, pairwise_stats, hmc_num_leapfrogs, nuts_max_depth, learn_mass_matrix, num_chains, nThreads, seed));
9797
return rcpp_result_gen;
9898
END_RCPP
9999
}

src/bgm_logp_and_grad.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "bgm_helper.h"
33
#include "bgm_logp_and_grad.h"
44
#include "common_helpers.h"
5+
56
using namespace Rcpp;
67

78

@@ -145,7 +146,7 @@ double log_pseudoposterior_main_effects_component (
145146
* - inclusion_indicator: Symmetric binary matrix of active pairwise effects.
146147
* - is_ordinal_variable: Indicator (1 = ordinal, 0 = Blume–Capel).
147148
* - baseline_category: Reference categories for Blume–Capel variables.
148-
* - interaction_scale: Scale parameter of the Cauchy prior on interactions.
149+
* - pairwise_scale: Scale parameter of the Cauchy prior on interactions.
149150
* - pairwise_stats: Sufficient statistics for pairwise counts.
150151
* - var1, var2: Indices of the variable pair being updated.
151152
*
@@ -165,7 +166,7 @@ double log_pseudoposterior_interactions_component (
165166
const arma::imat& inclusion_indicator,
166167
const arma::uvec& is_ordinal_variable,
167168
const arma::ivec& baseline_category,
168-
const double interaction_scale,
169+
const double pairwise_scale,
169170
const arma::imat& pairwise_stats,
170171
const int var1,
171172
const int var2
@@ -210,7 +211,7 @@ double log_pseudoposterior_interactions_component (
210211

211212
// Add Cauchy prior terms for included pairwise effects
212213
if (inclusion_indicator (var1, var2) == 1) {
213-
log_pseudo_posterior += R::dcauchy (pairwise_effects (var1, var2), 0.0, interaction_scale, true);
214+
log_pseudo_posterior += R::dcauchy (pairwise_effects (var1, var2), 0.0, pairwise_scale, true);
214215
}
215216

216217
return log_pseudo_posterior;
@@ -241,7 +242,7 @@ double log_pseudoposterior_interactions_component (
241242
* - baseline_category: Reference categories for Blume–Capel variables.
242243
* - is_ordinal_variable: Indicator (1 = ordinal, 0 = Blume–Capel).
243244
* - main_alpha, main_beta: Hyperparameters for the Beta priors.
244-
* - interaction_scale: Scale parameter of the Cauchy prior on interactions.
245+
* - pairwise_scale: Scale parameter of the Cauchy prior on interactions.
245246
* - pairwise_stats: Pairwise sufficient statistics.
246247
* - residual_matrix: Matrix of residual scores (persons × variables).
247248
*
@@ -265,7 +266,7 @@ double log_pseudoposterior (
265266
const arma::uvec& is_ordinal_variable,
266267
const double main_alpha,
267268
const double main_beta,
268-
const double interaction_scale,
269+
const double pairwise_scale,
269270
const arma::imat& pairwise_stats,
270271
const arma::mat& residual_matrix
271272
) {
@@ -304,7 +305,7 @@ double log_pseudoposterior (
304305

305306
double value = pairwise_effects(var1, var2);
306307
log_pseudoposterior += 2.0 * pairwise_stats(var1, var2) * value;
307-
log_pseudoposterior += R::dcauchy(value, 0.0, interaction_scale, true); // Cauchy prior
308+
log_pseudoposterior += R::dcauchy(value, 0.0, pairwise_scale, true); // Cauchy prior
308309
}
309310
}
310311

@@ -371,7 +372,7 @@ double log_pseudoposterior (
371372
* - baseline_category: Reference categories for Blume–Capel variables.
372373
* - is_ordinal_variable: Indicator (1 = ordinal, 0 = Blume–Capel).
373374
* - main_alpha, main_beta: Hyperparameters for Beta priors.
374-
* - interaction_scale: Scale parameter of the Cauchy prior on interactions.
375+
* - pairwise_scale: Scale parameter of the Cauchy prior on interactions.
375376
* - pairwise_stats: Sufficient statistics for pairwise effects.
376377
* - residual_matrix: Matrix of residual scores (persons × variables).
377378
*
@@ -396,7 +397,7 @@ arma::vec gradient_log_pseudoposterior (
396397
const arma::uvec& is_ordinal_variable,
397398
const double main_alpha,
398399
const double main_beta,
399-
const double interaction_scale,
400+
const double pairwise_scale,
400401
const arma::imat& pairwise_stats,
401402
const arma::mat& residual_matrix
402403
) {
@@ -551,7 +552,7 @@ arma::vec gradient_log_pseudoposterior (
551552
// ---- Gradient contribution from Cauchy prior
552553
int location = index_matrix(var1, var2);
553554
const double effect = pairwise_effects (var1, var2);
554-
gradient (location) -= 2.0 * effect / (effect * effect + interaction_scale * interaction_scale);
555+
gradient (location) -= 2.0 * effect / (effect * effect + pairwise_scale * pairwise_scale);
555556
}
556557
}
557558

@@ -579,7 +580,7 @@ arma::vec gradient_log_pseudoposterior (
579580
* - baseline_category: Reference categories for Blume–Capel variables.
580581
* - is_ordinal_variable: Indicator (1 = ordinal, 0 = Blume–Capel).
581582
* - main_alpha, main_beta: Hyperparameters for Beta priors.
582-
* - interaction_scale: Scale parameter of the Cauchy prior on interactions.
583+
* - pairwise_scale: Scale parameter of the Cauchy prior on interactions.
583584
* - pairwise_stats: Sufficient statistics for pairwise effects.
584585
* - residual_matrix: Matrix of residual scores (persons × variables).
585586
*
@@ -603,7 +604,7 @@ arma::vec gradient_log_pseudoposterior_active (
603604
const arma::uvec& is_ordinal_variable,
604605
const double main_alpha,
605606
const double main_beta,
606-
const double interaction_scale,
607+
const double pairwise_scale,
607608
const arma::imat& pairwise_stats,
608609
const arma::mat& residual_matrix
609610
) {
@@ -613,7 +614,7 @@ arma::vec gradient_log_pseudoposterior_active (
613614
main_effects, pairwise_effects, inclusion_indicator, observations,
614615
num_categories, counts_per_category, blume_capel_stats,
615616
baseline_category, is_ordinal_variable, main_alpha, main_beta,
616-
interaction_scale, pairwise_stats, residual_matrix
617+
pairwise_scale, pairwise_stats, residual_matrix
617618
);
618619

619620
// Step 2: Extract compressed gradient (same layout as new vectorizer)

src/bgm_logp_and_grad.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ double log_pseudoposterior_interactions_component (
2727
const arma::imat& inclusion_indicator,
2828
const arma::uvec& is_ordinal_variable,
2929
const arma::ivec& baseline_category,
30-
const double interaction_scale,
30+
const double pairwise_scale,
3131
const arma::imat& pairwise_stats,
3232
const int var1,
3333
const int var2
@@ -46,7 +46,7 @@ double log_pseudoposterior (
4646
const arma::uvec& is_ordinal_variable,
4747
const double main_alpha,
4848
const double main_beta,
49-
const double interaction_scale,
49+
const double pairwise_scale,
5050
const arma::imat& pairwise_stats,
5151
const arma::mat& residual_matrix
5252
);
@@ -64,7 +64,7 @@ arma::vec gradient_log_pseudoposterior (
6464
const arma::uvec& is_ordinal_variable,
6565
const double main_alpha,
6666
const double main_beta,
67-
const double interaction_scale,
67+
const double pairwise_scale,
6868
const arma::imat& pairwise_stats,
6969
const arma::mat& residual_matrix
7070
);
@@ -82,7 +82,7 @@ arma::vec gradient_log_pseudoposterior_active (
8282
const arma::uvec& is_ordinal_variable,
8383
const double main_alpha,
8484
const double main_beta,
85-
const double interaction_scale,
85+
const double pairwise_scale,
8686
const arma::imat& pairwise_stats,
8787
const arma::mat& residual_matrix
8888
);

src/bgm_parallel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ChainResult {
5858
struct GibbsChainRunner : public Worker {
5959
const arma::imat& observations;
6060
const arma::ivec& num_categories;
61-
double interaction_scale;
61+
double pairwise_scale;
6262
const std::string& edge_prior;
6363
const arma::mat& inclusion_probability;
6464
double beta_bernoulli_alpha;
@@ -94,7 +94,7 @@ struct GibbsChainRunner : public Worker {
9494
GibbsChainRunner(
9595
const arma::imat& observations,
9696
const arma::ivec& num_categories,
97-
double interaction_scale,
97+
double pairwise_scale,
9898
const std::string& edge_prior,
9999
const arma::mat& inclusion_probability,
100100
double beta_bernoulli_alpha,
@@ -125,7 +125,7 @@ struct GibbsChainRunner : public Worker {
125125
) :
126126
observations(observations),
127127
num_categories(num_categories),
128-
interaction_scale(interaction_scale),
128+
pairwise_scale( pairwise_scale),
129129
edge_prior(edge_prior),
130130
inclusion_probability(inclusion_probability),
131131
beta_bernoulli_alpha(beta_bernoulli_alpha),
@@ -168,7 +168,7 @@ struct GibbsChainRunner : public Worker {
168168
out.chain_id,
169169
observations,
170170
num_categories,
171-
interaction_scale,
171+
pairwise_scale,
172172
edge_prior,
173173
inclusion_probability,
174174
beta_bernoulli_alpha,
@@ -222,7 +222,7 @@ struct GibbsChainRunner : public Worker {
222222
* Inputs:
223223
* - observations: Matrix of categorical observations (persons × variables).
224224
* - num_categories: Number of categories per variable.
225-
* - interaction_scale: Scale parameter of the Cauchy prior on pairwise effects.
225+
* - pairwise_scale: Scale parameter of the Cauchy prior on pairwise effects.
226226
* - edge_prior: Prior specification for edge inclusion.
227227
* - inclusion_probability: Matrix of prior inclusion probabilities.
228228
* - beta_bernoulli_alpha, beta_bernoulli_beta: Hyperparameters for Bernoulli priors.
@@ -263,7 +263,7 @@ struct GibbsChainRunner : public Worker {
263263
Rcpp::List run_bgm_parallel(
264264
const arma::imat& observations,
265265
const arma::ivec& num_categories,
266-
double interaction_scale,
266+
double pairwise_scale,
267267
const std::string& edge_prior,
268268
const arma::mat& inclusion_probability,
269269
double beta_bernoulli_alpha,
@@ -302,7 +302,7 @@ Rcpp::List run_bgm_parallel(
302302
}
303303

304304
GibbsChainRunner worker(
305-
observations, num_categories, interaction_scale, edge_prior,
305+
observations, num_categories, pairwise_scale, edge_prior,
306306
inclusion_probability, beta_bernoulli_alpha, beta_bernoulli_beta,
307307
dirichlet_alpha, lambda, interaction_index_matrix, iter, burnin,
308308
counts_per_category, blume_capel_stats, main_alpha, main_beta,

0 commit comments

Comments
 (0)