Nothing
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
#' Log-sum-exp trick for numerical stability
#'
#' @param x Vector of log values
#' @return log(sum(exp(x)))
#' @keywords internal
NULL
#' Hidden State Sampler (C++ version)
#'
#' Sample hidden states from hidden Markov multilinear model using
#' forward filtering backward sampling algorithm.
#'
#' @param m Number of breaks
#' @param s Current state vector (not used, kept for interface)
#' @param ZMUt List of (Z - MU) matrices for each state
#' @param s2 Vector of error variances for each state
#' @param P Transition probability matrix
#' @param SOS_random Whether to apply single observation state randomization
#' @return List containing: s (state vector), ps (state probabilities), SOS (flag)
#' @keywords internal
ULUstateSample_cpp <- function(m, s, ZMUt, s2, P, SOS_random) {
.Call(`_NetworkChange_ULUstateSample_cpp`, m, s, ZMUt, s2, P, SOS_random)
}
#' Create 3D Array from Factor Matrices (C++ version)
#'
#' Computes M(i,j,t) = sum_r U1(i,r) * U2(j,r) * V(t,r)
#' This is the core tensor reconstruction operation used in NetworkChange.
#'
#' @param U1 First factor matrix (N1 x R)
#' @param U2 Second factor matrix (N2 x R), typically same as U1 for undirected networks
#' @param V Third factor matrix (T x R)
#' @return 3D array of dimension (N1 x N2 x T)
#' @keywords internal
M_U_cpp <- function(U1, U2, V) {
.Call(`_NetworkChange_M_U_cpp`, U1, U2, V)
}
#' Create 3D Array from List of Factor Matrices (C++ version)
#'
#' General version that takes a list of factor matrices.
#' For NetworkChange, typically called with list(U, U, V) for undirected networks.
#'
#' @param U_list List of factor matrices
#' @return Array with dimensions corresponding to the rows of each factor matrix
#' @keywords internal
M_U_list_cpp <- function(U_list) {
.Call(`_NetworkChange_M_U_list_cpp`, U_list)
}
#' Compute diagonal correction for V update (C++ version)
#'
#' Computes the diagonal correction term sum_i U_sq(i,r1) * U_sq(i,r2)
#' used in updateV and updateVm functions.
#'
#' @param U Factor matrix
#' @return R x R diagonal correction matrix
#' @keywords internal
compute_diag_correction_cpp <- function(U) {
.Call(`_NetworkChange_compute_diag_correction_cpp`, U)
}
#' Compute L matrix for V update (C++ version)
#'
#' Computes L(t, r) = sum over i less than j of Z(i,j,t) * U(i,r) * U(j,r)
#' This is a key bottleneck in updateV.
#'
#' @param Z 3D array (N x N x T), already zeroed below diagonal
#' @param U Factor matrix (N x R)
#' @param T_dim Number of time points
#' @param R Number of latent dimensions
#' @return T_dim x R matrix L
#' @keywords internal
compute_L_matrix_cpp <- function(Z, U, T_dim, R) {
.Call(`_NetworkChange_compute_L_matrix_cpp`, Z, U, T_dim, R)
}
#' Update Time-constant Latent Node Positions (C++ version)
#'
#' Updates U using optimized matrix operations with pre-computed invariants.
#'
#' @param K Dimensions of Z (N, N, T)
#' @param U Current latent node positions (N x R)
#' @param V Layer-specific network generation rule (T x R)
#' @param R Dimension of latent space
#' @param Zb 3D array (Z - beta)
#' @param s2 Error variance (scalar)
#' @param eU Prior mean vector for U
#' @param iVU Prior precision matrix for U
#' @return Updated U matrix (N x R)
#' @keywords internal
updateU_cpp <- function(K, U, V, R, Zb, s2, eU, iVU) {
.Call(`_NetworkChange_updateU_cpp`, K, U, V, R, Zb, s2, eU, iVU)
}
#' Update Regime-specific Latent Node Positions (C++ version)
#'
#' Updates U for each regime using optimized matrix operations.
#'
#' @param ns Number of hidden states
#' @param U List of regime-specific latent node positions
#' @param V Combined V matrix
#' @param R Dimension of latent space
#' @param Zm List of regime-specific (Z - beta) arrays
#' @param Km List of regime-specific dimensions
#' @param ej List of regime indicators (binary vectors)
#' @param s2 Vector of regime-specific error variances
#' @param eU List of regime-specific prior means for U
#' @param iVU List of regime-specific prior precision matrices for U
#' @param UL_Normal Normalization method: "Normal" or "Orthonormal"
#' @return List of updated regime-specific U matrices
#' @keywords internal
updateUm_cpp <- function(ns, U, V, R, Zm, Km, ej, s2, eU, iVU, UL_Normal) {
.Call(`_NetworkChange_updateUm_cpp`, ns, U, V, R, Zm, Km, ej, s2, eU, iVU, UL_Normal)
}
#' Update Layer-specific Network Generation Rules (C++ version)
#'
#' Updates V using optimized matrix operations.
#'
#' @param Zb 3D array (Z - beta), already zeroed below diagonal
#' @param U Latent node positions matrix (N x R)
#' @param R Dimension of latent space
#' @param K Dimensions of Z (N, N, T)
#' @param s2 Error variance (scalar)
#' @param eV Prior mean vector for V
#' @param iVV Prior precision matrix for V
#' @return Updated V matrix (T x R)
#' @keywords internal
updateV_cpp <- function(Zb, U, R, K, s2, eV, iVV) {
.Call(`_NetworkChange_updateV_cpp`, Zb, U, R, K, s2, eV, iVV)
}
#' Update V from Change-point Network Process (C++ version)
#'
#' Updates regime-specific V matrices using optimized operations.
#'
#' @param ns Number of hidden regimes
#' @param U List of regime-specific latent node positions
#' @param V Current V matrix (not used, kept for interface compatibility)
#' @param Zm List of regime-specific (Z - beta) arrays, zeroed below diagonal
#' @param Km List of regime-specific dimensions
#' @param R Dimension of latent space
#' @param s2 Vector of regime-specific error variances
#' @param eV List of regime-specific prior means for V
#' @param iVV List of regime-specific prior precision matrices for V
#' @return List of regime-specific V matrices
#' @keywords internal
updateVm_cpp <- function(ns, U, V, Zm, Km, R, s2, eV, iVV) {
.Call(`_NetworkChange_updateVm_cpp`, ns, U, V, Zm, Km, R, s2, eV, iVV)
}
#' Multivariate Normal Random Sampling (C++ version)
#'
#' @param n Number of samples
#' @param mu Mean vector
#' @param Sigma Covariance matrix
#' @return Matrix of n samples (rows) from MVN(mu, Sigma)
#' @keywords internal
rMVNorm_cpp <- function(n, mu, Sigma) {
.Call(`_NetworkChange_rMVNorm_cpp`, n, mu, Sigma)
}
#' Matrix Normal Random Sampling (C++ version)
#'
#' @param M Mean matrix
#' @param Srow Row covariance matrix
#' @param Scol Column covariance matrix
#' @return Random matrix from Matrix Normal(M, Srow, Scol)
#' @keywords internal
rmn_cpp <- function(M, Srow, Scol) {
.Call(`_NetworkChange_rmn_cpp`, M, Srow, Scol)
}
#' Gram-Schmidt Orthogonalization (C++ version)
#'
#' @param U Input matrix to orthogonalize
#' @return Orthonormalized matrix
#' @keywords internal
GramSchmidt_cpp <- function(U) {
.Call(`_NetworkChange_GramSchmidt_cpp`, U)
}
#' Column Normalization (C++ version)
#'
#' Normalize columns of a matrix to have unit Euclidean norm.
#'
#' @param U1 Input matrix
#' @return Matrix with normalized columns
#' @keywords internal
Unormal_cpp <- function(U1) {
.Call(`_NetworkChange_Unormal_cpp`, U1)
}
#' Standard Normal Matrix Generator (C++ version)
#'
#' @param m Number of rows
#' @param n Number of columns
#' @return m x n matrix of standard normal random values
#' @keywords internal
rsmn_cpp <- function(m, n) {
.Call(`_NetworkChange_rsmn_cpp`, m, n)
}
#' Update Regime-specific Variance (C++ version)
#'
#' Updates regime-specific variance parameters using inverse gamma sampling.
#'
#' @param ns Number of hidden states
#' @param Zm List of regime-specific (Z - beta) arrays
#' @param MU List of mean arrays
#' @param c0 Shape parameter prior
#' @param d0 Scale parameter prior
#' @param Km List of regime-specific dimensions
#' @return Vector of regime-specific variances
#' @keywords internal
updates2m_cpp <- function(ns, Zm, MU, c0, d0, Km) {
.Call(`_NetworkChange_updates2m_cpp`, ns, Zm, MU, c0, d0, Km)
}
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.