% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/bbni.r
\name{run_bbni}
\alias{run_bbni}
\title{Execute Metropolis-within-Gibbs MCMC Sampler for Boolean Networks}
\usage{
run_bbni(
  GeneData,
  num.node = nrow(GeneData),
  SampleSize = ncol(GeneData),
  prior_para = NULL,
  num_update = 4000,
  penalty = 0.1,
  prop.ratio = 0.1,
  verbose = FALSE,
  timeseries = TRUE,
  burn_in = 0.7
)
}
\arguments{
\item{GeneData}{A binary empirical observation matrix (\eqn{G}{G}), where rows represent individual network nodes (genes) and columns represent independent samples or sequential time points.}

\item{num.node}{An integer representing the total number of network nodes. Defaults to \code{nrow(GeneData)} if not specified.)}

\item{SampleSize}{An integer representing the total number of time points or independent samples in the dataset. Defaults to \code{ncol(GeneData)} if not specified.}

\item{prior_para}{A matrix (with dimensions \verb{(num.node + 1) x 2}) of Beta prior hyperparameters \eqn{\alpha}{\alpha} and \eqn{\beta}{\beta} for root node probabilities and the global noise parameter \eqn{e}{e}. Defaults to a flat prior if not specified.}

\item{num_update}{An integer representing the total number of MCMC iterations to perform. Defaults to 4000 if not specified.}

\item{penalty}{Structural-prior hyperparameter in \eqn{(0, 1]}{(0, 1]}. A value of \code{1} corresponds to a uniform prior over valid network topologies; values below \code{1} apply an edge-count penalty that favors sparser networks. Defaults to 0.1 if not specified.}

\item{prop.ratio}{A numeric value between 0 and 1 giving the final probability of using the empirical proposal distribution after the first 10\% of outer iterations. During the first 10\% of outer iterations, the empirical proposal is used with probability 0.9. Defaults to 0.1.}

\item{verbose}{Logical. If TRUE, prints verbose MCMC iteration progress to the console. Default is FALSE.}

\item{timeseries}{Logical. If TRUE, the algorithm assumes a time-series dataset. If FALSE, the algorithm assumes independent samples. Default is TRUE.}

\item{burn_in}{A numeric value between 0 and 1 representing the proportion of initial MCMC samples to discard as burn-in. Defaults to 0.7 if not specified.}
}
\value{
A list containing the full trajectory of the MCMC chain. Specifically, \code{networks} (a list of sampled transition function matrices) and \code{log_posterior} (a numeric vector of log-posterior scores for each iteration). These represent samples drawn from the marginal posterior distribution \eqn{P(T,F|G)}{P(T,F|G)} used for Bayesian model averaging. Additionally, the \code{post_edge_prob} (matrix of marginal posterior edge probabilities) and \code{burn_in} ratio are returned in the list.
}
\description{
Executes a Metropolis-within-Gibbs Markov chain Monte Carlo (MCMC) algorithm to sample
from the joint posterior distribution of Directed Acyclic Graph (DAG) topologies (\eqn{T}{T}) and
Boolean logic transition functions (\eqn{F}{F}). The algorithm iterates through individual
network nodes and proposes parent set mutations (edge additions, removals, or swaps)
paired with transition function reassignments to one of 14 candidate Boolean rules (stored as codes 1-12 in the transition matrix).
Proposed states transitions are strictly verified to follow the DAG constraint and
evaluated with a Metropolis-Hastings acceptance threshold using log-posterior values.
}
\details{
Posterior edge probabilities (\code{post_edge_prob}) are computed from one
thinned sample per outer iteration (a full Gibbs sweep) after discarding
\code{burn_in}, as designed in the original method paper.
}
\examples{
# 1. Define network parameters
set.seed(235)
num_nodes <- 8
sample_size <- 50

# 2. Generate true network and simulate data
true_network <- GenerateNetwork(num.node = num_nodes)

# Set up Beta priors for root-node probabilities and the noise rate
prior_para <- matrix(3, nrow = num_nodes + 1, ncol = 2)
prior_para[num_nodes + 1, 1] <- 2
prior_para[num_nodes + 1, 2] <- 100

# Simulate parameters
para <- numeric(num_nodes + 1)
for (i in 1:(num_nodes + 1)) {
  para[i] <- stats::rbeta(1, prior_para[i, 1], prior_para[i, 2])
}
para[num_nodes + 1] <- 0.1 # Fixed noise rate for simulation

error_matrix <- matrix(stats::rbinom(num_nodes * sample_size, 1, para[num_nodes + 1]),
  nrow = num_nodes, ncol = sample_size
)

dummy_data <- GenerateSample(
  trans_matrix = true_network,
  SampleSize = sample_size,
  para = para,
  error = error_matrix
)

# 3. Run the MCMC sampler (silently)
mcmc_results <- run_bbni(
  GeneData = dummy_data,
  prior_para = prior_para,
  num_update = 80, # Scaled down for example speed
  prop.ratio = 0.1
)

# 4. Visualize results
plot_bbni(mcmc_results, true_network = true_network, threshold = 0.5)
plot_trace(mcmc_results)

}
