Score units¶
A score step may declare that its contribution is a sum of one log weight per
unit. A
trace of the program then holds a SiteUnits at the score's site: the log
weight of each unit, the unit that each row of a response belongs to, and the log likelihood of
each row where the rows factor. UnfactoredObservationError says why a response has no log
likelihood per row and which program has one.
units
¶
The units of a score, read from one run.
A score step may declare that its contribution is a sum of one log weight
per unit (see
UnitFactorization).
SiteUnits is that declaration with the values of one run: it reads the
log weight of each unit, the unit of each row of a response, and, where
the rows factor, the log likelihood of each row.
UnfactoredObservationError
¶
Bases: TypeError
An observation's rows have no log likelihoods of their own.
The message says why the rows do not factor, and which program has a log likelihood per row.
SiteUnits
didactic-model
¶
SiteUnits(*, factorization: UnitFactorization = field(opaque=True, extras=OPAQUE_BY_VALUE), environment: dict[str, Tensor] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), occurrence: str = '')
Bases: ValueModel
The units of one score site, at the values of one run.
| PARAMETER | DESCRIPTION |
|---|---|
factorization
|
What the score step declares.
TYPE:
|
environment
|
The run's values the factorization reads.
TYPE:
|
occurrence
|
The suffix of the site's occurrence,
TYPE:
|
axes
property
¶
The objects whose product indexes the units.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The names, outermost first; empty for a score with one unit. |
sizes
property
¶
The extent of each unit axis.
| RETURNS | DESCRIPTION |
|---|---|
tuple[int, ...]
|
The extents. |
responses
property
¶
The labels of the responses whose rows the units hold.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
The labels, in the order the program observes them. |
log_weights
¶
log_weights() -> Tensor
The log weight of each unit, as the site scored it.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The weights, of shape |
Source code in src/quivers/effects/units.py
log_likelihood
¶
log_likelihood() -> Tensor
The log density of each unit's rows given the run's latents.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
The log densities, of shape |
| RAISES | DESCRIPTION |
|---|---|
UnfactoredObservationError
|
If the score's weights are not log densities. |
Source code in src/quivers/effects/units.py
row_units
¶
row_units(response: str) -> Tensor
The unit each row of a response belongs to.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
The response's label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the score reads no such response. |
Source code in src/quivers/effects/units.py
row_log_likelihood
¶
row_log_likelihood(response: str) -> Tensor
The log likelihood of each row of a response, where it exists.
A row has one when its unit holds that row and no other row of any response of the score. The log likelihood of the row is then the log weight of its unit.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
The response's label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
|
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If the score reads no such response. |
UnfactoredObservationError
|
If a unit holds several rows, or the score's weights are not log densities. |