This function updates the class weight vector by drawing from its posterior distribution.
Details
Let \(m=(m_1,\dots,m_C)\) be the frequencies of \(C\) classes.
Given the class weight (probability) vector \(s=(s_1,\dots,s_C)\), the distribution
of \(m\) is multinomial and its likelihood is $$L(m\mid s) \propto \prod_{i=1}^C s_i^{m_i}.$$
The conjugate prior \(p(s)\) for \(s\) is a Dirichlet distribution, which has a density function
proportional to $$\prod_{i=1}^C s_i^{\delta_i-1},$$ where \(\delta = (\delta_1,\dots,\delta_C)\)
is the concentration parameter vector.
Note that in {RprobitB}
, \(\delta_1=\dots=\delta_C\). This restriction is necessary because the class number \(C\) can change.
The posterior distribution of \(s\) is proportional to $$p(s) L(m\mid s) \propto \prod_{i=1}^C s_i^{\delta_i + m_i - 1},$$
which in turn is proportional to a Dirichlet distribution with parameters \(\delta+m\).
Examples
### number of classes
C <- 4
### current class sizes
m <- sample.int(C)
### concentration parameter for Dirichlet prior (single-valued)
delta <- 1
### updated class weight vector
update_s(delta = 1, m = m)
#> [,1]
#> [1,] 0.1839418
#> [2,] 0.1893315
#> [3,] 0.2454951
#> [4,] 0.3812317