Skip to contents

The density method that a parametric_family implements. Compiling lets the family precompute whatever depends on x. For the density at one parameter, use log_density(family(theta), x).

Usage

compile_loglik(family, x)

Arguments

family

A parametric_family.

x

(M, K) matrix of outcomes, where M is the number of outcomes and K the dimension of the sample space.

Value

A function of theta_mat, a (C, d) matrix with one parameter vector per row, returning the (M, C) matrix of log densities at x: one row per outcome, one column per parameter.

Examples

fam <- multinomial_family(n_trials = 4L, k = 3L)
x <- rbind(c(2L, 1L, 1L), c(4L, 0L, 0L))
ll <- compile_loglik(fam, x)
ll(rbind(c(0.5, 0.3, 0.2), c(0.25, 0.25, 0.5)))
#>           [,1]      [,2]
#> [1,] -1.714798 -2.367124
#> [2,] -2.772589 -5.545177