-
Notifications
You must be signed in to change notification settings - Fork 8
SBM implementation in the new version of bgms #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MaartenMarsman
merged 13 commits into
Bayesian-Graphical-Modelling-Lab:main
from
sekulovskin:developer_SBM
Feb 6, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6caf7fc
Update on the SBM prior: (1) now we save the sampled block allocation…
sekulovskin 6633a70
update the restriction on Kmax
sekulovskin f74e723
changes: (1) take out the option to save out_cluster_prob and (2) cha…
sekulovskin 4543486
take out saving K within the Gibbs sampler
sekulovskin f25e2f0
Include the option to calculate the number of clusters and cluster al…
sekulovskin 21bedbc
Merge branch 'main' of https://github.com/sekulovskin/bgms
sekulovskin 02be0e9
update the references
sekulovskin b83fc61
Merge branch 'MaartenMarsman:main' into main
sekulovskin 7c86629
Merge branch 'MaartenMarsman:main' into main
sekulovskin ad28297
Update: SBM implementation in the updated version of bgms
sekulovskin 4f4b7bc
fixed the prior inclusion probability in the arguments output
sekulovskin 32a2076
addressing review comments
sekulovskin 80614a7
Addressing review comments
sekulovskin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,10 @@ | |
| #' beta prior for the unknown inclusion probability with shape parameters | ||
| #' \code{beta_bernoulli_alpha} and \code{beta_bernoulli_beta}, and a Dirichlet | ||
| #' prior on the cluster assignment probabilities with a common concentration | ||
| #' parameter \code{dirichlet_alpha}. The default is | ||
| #' parameter \code{dirichlet_alpha} and a zero-truncated Poisson prior on the | ||
| #' number of clusters with a rate parameter \code{lambda}, indicating the | ||
| #' expected number of clusters. | ||
| #' The default is | ||
| #' \code{edge_prior = "Bernoulli"}. | ||
| #' @param inclusion_probability The prior edge inclusion probability for the | ||
| #' Bernoulli model. Can be a single probability, or a matrix of \code{p} rows | ||
|
|
@@ -130,6 +133,8 @@ | |
| #' \code{beta_bernoulli_beta = 1}. | ||
| #' @param dirichlet_alpha The shape of the Dirichlet prior on the node-to-block | ||
| #' allocation probabilities for the Stochastic Block model. | ||
| #' @param lambda The rate parameter of the zero-truncated Poisson prior on the | ||
| #' number of cluster for the Stochastic Block model. | ||
| #' @param na_action How do you want the function to handle missing data? If | ||
| #' \code{na_action = "listwise"}, listwise deletion is used. If | ||
| #' \code{na_action = "impute"}, missing data are imputed iteratively during the | ||
|
|
@@ -158,13 +163,20 @@ | |
| #' ``blume-capel'' variables, the first entry is the parameter for the linear | ||
| #' effect and the second entry is the parameter for the quadratic effect, which | ||
| #' models the offset to the reference category. | ||
| #' \item In the case of | ||
| #' \code{edge_prior = "Stochastic-Block"} two additional elements are returned: | ||
| #' a vector \code{allocations} with the estimated cluster assignments of the nodes and an | ||
| #' table \code{clusters} with the estimated posterior probability of the number | ||
| #' of clusters in the network. The vector of node allocations is calculated using | ||
| #' a method proposed by \insertCite{Dahl2009}{bgms} and also used by | ||
| #' \insertCite{GengEtAl_2019}{bgms}. | ||
| #' \item In the case of \code{edge_prior = "Stochastic-Block"}, two additional | ||
| #' elements are returned: | ||
| #' \itemize{ | ||
| #' \item A vector \code{allocations} with the estimated cluster assignments | ||
| #' of the nodes, calculated using a method proposed by \insertCite{@Dahl2009}{bgms} and | ||
| #' also used by \insertCite{@GengEtAl_2019}{bgms}. | ||
| #' \item A matrix \code{components} with the estimated posterior probability | ||
| #' of the number of components (clusters) in the network. These probabilities | ||
| #' are calculated based on Equation 3.7 in \insertCite{@miller2018mixture}{bgms}, which computes | ||
| #' the conditional probability of the number of components given the | ||
| #' number of clusters. The number of clusters is derived from the | ||
| #' cardinality of the sampled \code{allocations} vector for each iteration of | ||
| #' the MCMC sampler (see \code{save = TRUE}). | ||
| #' } | ||
| #' } | ||
| #' If \code{save = TRUE}, the result is a list of class ``bgms'' containing: | ||
| #' \itemize{ | ||
|
|
@@ -181,7 +193,7 @@ | |
| #' \code{edge_prior = "Stochastic-Block"} a matrix \code{allocations} with the | ||
| #' cluster assignments of the nodes from each iteration is returned. This matrix | ||
| #' can be used to calculate the posterior probability of the number of clusters | ||
| #' by utilizing the \code{summary_SBM(bgm_output[["allocations"]])} function. | ||
| #' by utilizing the \code{summary_SBM} function. | ||
| #' } | ||
| #' Column averages of these matrices provide the model-averaged posterior means. | ||
| #' Except for the \code{allocations} matrix, for which the \code{summary_SBM} | ||
|
|
@@ -296,6 +308,7 @@ bgm = function(x, | |
| beta_bernoulli_alpha = 1, | ||
| beta_bernoulli_beta = 1, | ||
| dirichlet_alpha = 1, | ||
| lambda = 1, | ||
| na_action = c("listwise", "impute"), | ||
| save = FALSE, | ||
| display_progress = TRUE) { | ||
|
|
@@ -322,7 +335,8 @@ bgm = function(x, | |
| inclusion_probability = inclusion_probability, | ||
| beta_bernoulli_alpha = beta_bernoulli_alpha, | ||
| beta_bernoulli_beta = beta_bernoulli_beta, | ||
| dirichlet_alpha = dirichlet_alpha) | ||
| dirichlet_alpha = dirichlet_alpha, | ||
| lambda = lambda) | ||
|
|
||
| # ---------------------------------------------------------------------------- | ||
| # The vector variable_type is now coded as boolean. | ||
|
|
@@ -451,6 +465,7 @@ bgm = function(x, | |
| beta_bernoulli_alpha = beta_bernoulli_alpha , | ||
| beta_bernoulli_beta = beta_bernoulli_beta, | ||
| dirichlet_alpha = dirichlet_alpha, | ||
| lambda = lambda, | ||
| na_action = na_action, | ||
| save = save, | ||
| version = packageVersion("bgms") | ||
|
|
@@ -470,6 +485,7 @@ bgm = function(x, | |
| beta_bernoulli_alpha = beta_bernoulli_alpha, | ||
| beta_bernoulli_beta = beta_bernoulli_beta, | ||
| dirichlet_alpha = dirichlet_alpha, | ||
| lambda = lambda, | ||
| Index = Index, | ||
| iter = iter, | ||
| burnin = burnin, | ||
|
|
@@ -524,13 +540,15 @@ bgm = function(x, | |
| if(edge_selection == TRUE) { | ||
| if(edge_prior == "Stochastic-Block"){ | ||
|
|
||
| summarySbm <- summary_SBM(cluster_allocations = out$allocations) | ||
| summarySbm = summary_SBM(cluster_allocations = out$allocations, | ||
| dirichlet_alpha = dirichlet_alpha, | ||
| lambda = lambda) | ||
|
|
||
sekulovskin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| output = list(indicator = indicator, | ||
| interactions = interactions, | ||
| thresholds = thresholds, | ||
| components = summarySbm$components, | ||
| allocations = summarySbm$allocations, | ||
| clusters = summarySbm$no_clusters, | ||
| arguments = arguments) | ||
| } else { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to check if components has names.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use insertCite for the references.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I already fixed that