A parametric_family is the model \(p_\theta(x)\): a
parameter space \(\Theta\) (a convex_region), a sample space,
and the map \(\theta \mapsto p_\theta\) between them.
It provides a log-likelihood compiler, score and sampler.
format() gives the two spaces on one line, without the class
banner print() adds.
Arguments
- sample_space
The space that outcomes belong to.
- parameter_space
The convex_region that parameter lives in. For instance, the standard simplex for Multinomial proportions.
Details
Families are callable: fam(theta) is the distribution
\(p_\theta\), and fam(W) for a distribution W over the
parameter space is the mixture() \(P_W\).
This is effectively an abstract class. It has no compile_loglik() method,
so use a concrete family instead.
Examples
fam <- multinomial_family(n_trials = 4L, k = 3L)
S7::S7_inherits(fam, parametric_family)
#> [1] TRUE
# The map theta -> p_theta, and its extension to mixing measures.
fam(c(0.5, 0.3, 0.2))
#> <mixture> multinomial_family at theta = (0.5, 0.3, 0.2)
fam(finite_dist(
atoms = rbind(c(0.6, 0.2, 0.2), c(0.2, 0.6, 0.2)),
weights = c(0.5, 0.5)
))
#> <mixture> multinomial_family mixed over 2 atoms
# Properties and other generics are unaffected by being callable.
enumerate_space(fam@sample_space)
#> [,1] [,2] [,3]
#> [1,] 0 0 4
#> [2,] 0 1 3
#> [3,] 0 2 2
#> [4,] 0 3 1
#> [5,] 0 4 0
#> [6,] 1 0 3
#> [7,] 1 1 2
#> [8,] 1 2 1
#> [9,] 1 3 0
#> [10,] 2 0 2
#> [11,] 2 1 1
#> [12,] 2 2 0
#> [13,] 3 0 1
#> [14,] 3 1 0
#> [15,] 4 0 0