Skip to contents

ripr_finish() returns the fitted mixing measure, the mixture it induces, fit diagnostics, and the state it came from. The constructor is internal.

print() shows the returned mixture, its KL, the gaps that were measured, and how much history the state carries.

format() gives the atom count and KL on one line.

Usage

ripr_fit(
  W0 = finite_dist(),
  P_star = mixture(),
  part = integer(0),
  kl = integer(0),
  gap_fit = integer(0),
  gap_final = integer(0),
  rounds = integer(0),
  state = ripr_state()
)

Arguments

W0

The fitted mixing measure, a finite_dist over the null.

P_star

The mixture W0 induces through the null's family, the approximate RIPr.

part

Integer vector, the part of the null holding each atom of W0. Atoms are grouped in part order, so part is non-decreasing.

kl

\(KL(Q \| P^*)\) of the returned mixture, under the state's quadrature rule.

gap_fit

The last Frank–Wolfe gap recorded during fitting, which may describe an earlier iterate than the returned mixture; NA if none was.

gap_final

The Frank–Wolfe gap over the returned mixture, NA unless ripr_finish() was called with record_gap = TRUE.

rounds

Number of refinement rounds ripr_finish() ran; 0 when neither correct_weights nor identify was on.

state

The ripr_state the fit was finished from.

Value

A ripr_fit.

Details

The trace, snapshots and pre-finish mixture stay on fit@state. Finishing may reorder, reweight or drop atoms, so use W0 and part, not fit@state@mixing.

See also

Examples

set.seed(1)
fam <- multinomial_family(n_trials = 4L, k = 3L)
plurality <- null_model(
  fam,
  list(
    simplex_region(vertices = rbind(c(0.5, 0.5, 0), c(0, 1, 0), c(0, 0, 1))),
    simplex_region(vertices = rbind(c(0.5, 0, 0.5), c(0, 1, 0), c(0, 0, 1)))
  )
)
Q <- fam(c(0.4, 0.35, 0.25))
fit <- ripr_init(Q, plurality) |>
  fw_step(times = 10L) |>
  ripr_finish(record_gap = TRUE)
fit
#> <ripr_fit>
#>   mixture  multinomial_family mixed over 11 atoms
#>   KL       0.00589595
#>   gap      0.0168 final, 0.00937 while fitting
#>   refined  no
#>   trace    11 rows, 0 snapshots
fit@W0
#> <finite_dist>
#>   11 atoms in R^3
#>   heaviest atom (0.371, 0.371, 0.257) with weight 0.613
fit@part
#>  [1] 1 1 1 1 1 1 2 2 2 2 2
utils::tail(fit@state@trace$kl)
#> [1] 0.010669095 0.009956367 0.009264086 0.006123735 0.006009159 0.005895949