% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/MCIS_helpers.R
\name{compute_weight_update}
\alias{compute_weight_update}
\title{Internal weight accumulation for Monte Carlo Importance Sampling (System Case)}
\usage{
compute_weight_update(all_log_w, all_I_vals, stability_mode, sys_type, state)
}
\arguments{
\item{all_log_w}{Numeric vector of log-weights for the current batch.}

\item{all_I_vals}{Numeric vector of failure indicators (0/1).}

\item{stability_mode}{Character string: `"fast"` or `"robust"`.}

\item{sys_type}{Character string: `"serial"` or `"parallel"`.}

\item{state}{List containing current accumulated sums:
\describe{
  \item{total_sum_w}{Cumulative sum of weights.}
  \item{total_sum_Iw}{Cumulative weighted failure sum.}
  \item{total_sum_w2}{Cumulative sum of squared weights.}
  \item{log_total_sum_w}{Log-domain cumulative weight sum (robust mode).}
  \item{log_total_sum_Iw}{Log-domain cumulative failure-weight sum (robust mode).}
  \item{log_total_sum_w2}{Log-domain cumulative squared-weight sum (robust mode).}
  \item{n_sim}{Total number of samples processed.}
}}
}
\value{
Updated `state` list with accumulated statistics.
}
\description{
Internal helper used by `MC_IS_system()` to accumulate importance sampling
weights and update running Monte Carlo statistics.

The function performs numerically stable accumulation of:
\itemize{
  \item \eqn{\sum w},
  \item \eqn{\sum I w},
  \item \eqn{\sum w^2},
  \item and (in robust mode) their log-domain equivalents.
}

Two stabilization modes are supported:

\describe{
  \item{\code{"fast"}}{
    Batch-level stabilization using a max-log shift:
    \deqn{w_i = \exp(\log w_i - \max(\log w))}
    Suitable for most engineering applications.
  }
  \item{\code{"robust"}}{
    Global log-sum-exp accumulation across iterations:
    \deqn{\log \sum w = m + \log \sum \exp(\log w - m)}
    Recommended for rare-event simulation or very small failure probabilities.
  }
}

The function updates the running state object and returns it.
}
\details{
This function is internal and not intended to be called directly by users.
It is part of the system-level importance sampling implementation
in `MC_IS_system()`.
}
\keyword{internal}
