Skip to contents

The mixing measure is a finite_dist, whose atoms are in the order they joined it (a new atom is appended last). part records which part of the null each atom belongs to, since parts may overlap.

Usage

ripr_state(
  mixing = finite_dist(),
  part = integer(0),
  alternative = distribution(),
  null = null_model(),
  engine = quadrature(),
  control = list(),
  trace_rows = list(),
  snapshots = list(),
  oracle = NULL
)

Arguments

mixing

The current mixture, a finite_dist over the null.

part

Integer vector with one entry per atom of mixing: the part of the null region holding each atom.

alternative

The alternative \(Q\).

null

A null_model.

engine

A resolved quadrature.

control

From ripr_control().

trace_rows

List of trace rows, one per step, each a named list; read them through trace.

snapshots

List of recorded mixtures, each list(step, phase, mixing, part): the trace row and verb it was taken at, and the mixture then.

oracle

The linear oracle's verdict on the current mixture, or NULL when nothing has measured it: list(value, theta, part, elapsed), with \(\sup G = 1 + \mathrm{gap}\), its argmax, part, and search seconds. A cache: any step that changes the mixture clears it, a record_gap = TRUE sweep sets it, and the next fw_step() consumes it. gap_below() reads it.

Value

A ripr_state.

Details

ripr_init() builds the state and the step verbs advance it. The constructor is not public.

Trace

state@trace is a read-only data frame with one row per step, the first being ripr_init()'s; see oracles for the columns.

Examples

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))
state <- ripr_init(Q, plurality)
state
#> <ripr_state>
#>   null     multinomial_family in 2 parts
#>   iterate  2 atoms, KL 0.0245115
#>   gap      none recorded
#>   steps    fw 0, lb 0, em 0, weight 0, sfw 0, ct 0 (0.002s)
#>   trace    1 row, 0 snapshots
state@mixing
#> <finite_dist>
#>   2 atoms in R^3
#>      theta1 theta2 theta3 weight
#> [1,]  0.375  0.375  0.250    0.5
#> [2,]  0.325  0.350  0.325    0.5
state@part
#> [1] 1 2

# Nothing has measured the starting mixture yet.
is.null(state@oracle)
#> [1] TRUE
# We may pass `record_gap = TRUE` to `ripr_init()` to sweep the oracle over
# the initial state.
state <- ripr_init(Q, plurality, record_gap = TRUE)
state@oracle$value - 1
#> [1] 0.2134123
state@trace$gap_after
#> [1] 0.2134123