## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
set.seed(1)

## ----setup--------------------------------------------------------------------
library(kofn)
library(flexhaz)
library(dist.structure)

## ----eval = FALSE-------------------------------------------------------------
# # Pseudo-code of kofn's loglik.exp_kofn general-k path:
# function(df, par) {
#   dgp <- dist.structure::exp_kofn(k_dist, par)  # k_dist = m - k_kofn + 1
#   surv_fn <- algebraic.dist::surv(dgp)
#   cdf_fn  <- algebraic.dist::cdf(dgp)
#   dens_fn <- density(dgp)
#   # ... then loop over observations, accumulating log contributions.
# }

## -----------------------------------------------------------------------------
model <- kofn(k = 2, m = 3, component = dfr_exponential())
df <- rdata(model)(theta = c(1, 2, 3), n = 100)
result <- fit(model)(df, n_starts = 1)
rates_hat <- coef(result)

# Build the DGP from the fitted rates.
sys_fitted <- dist.structure::exp_kofn(
  k = model$m - model$k + 1,   # convert to :G convention
  rates = rates_hat
)

# Query structural and reliability properties.
dist.structure::system_signature(sys_fitted)
dist.structure::reliability(sys_fitted, 0.8)
sapply(seq_len(model$m), function(j)
  dist.structure::structural_importance(sys_fitted, j))

