quivers.formulas.compile¶
The FormulaToQVRModule lens turns a Formula into a quivers.dsl.ast_nodes.Module, expanding
formula terms into explicit QVR declarations and program steps
(inspect the generated QVR).
A group intercept becomes a set of group effects and a lookup of each observation's group. The
generated module shows exactly which priors, axes, and likelihood the formula produced.
Its optional distributional mapping takes parsed Formula values for auxiliary
parameters, giving each predictor its own coefficient namespace while sharing group
coding. The lens complement still reconstructs the primary location formula;
auxiliary formulas are retained in the configured lens. Offset and exposure
columns enter native predictor bindings without coefficient draws; their arrays
are retained by FormulaData.source and returned by fixed_column_observations.
A retained Formula.modifiers.weights column becomes an explicitly typed row
input and an observation-only [weights=formula_weights] option. The lens binds
its data without coefficient or prior sites and preserves the column through
backward. A decision modifier additionally provides a typed binary row input;
the generated program visibly combines it with the raw response before scoring
the joint law. Modifier declarations describe inputs and do not add effects.
Censoring and truncation become typed row inputs and explicit observation
event metadata. Censoring selects the recorded event; truncation normalizes
the sampling law before that event is scored. Standard-error roles modify
the family scale, and sigma=False removes the residual-scale site.
The same role record provides retained columns for fresh prediction; the
compiler does not create a second response-data schema.
reparameterize selects coordinates for all Gaussian group blocks,
including scalar, category-specific, and component-valued members of one
shared correlation. A correlated centered block emits one
MultivariateNormal draw; independent coefficients use their scalar or
indexed Normal laws. Noncentered blocks retain their standard Normal
innovation sites.
The lens's immutable group_layouts records the coefficient slices used
by posterior replay. FormulaData.group_layouts retains the matching tuple
for formula reconstruction, so reusing the lens for a second forward pass
does not alter an earlier module's complement.
Grouped cumulative thresholds use the same hierarchical log-slack law
under both choices. Flexible and sum-to-zero policies have one shape
coordinate per gap; equidistant profiles have one shared gap per group.
The one varying group location is reused or added once, including for
binary responses. The existing named prior catalog accepts
cutpoint_log_spacing_mean and cutpoint_log_spacing_scale overrides;
scale priors are conditioned on nonnegative values. See the identified construction.
The optional predictor_graph retains named nonlinear additive designs,
deterministic intermediates, and family-output expressions. The compiler
emits their dependency order through the existing QVR value AST and applies
the family link at each output once. Shared group blocks collect members
across these leaves through the same layout as ordinary distributional
regression; nonlinear compilation does not introduce a second group emitter.
compile
¶
Bidirectional didactic.api.Lens from Formula to a
QVR quivers.dsl.ast_nodes.Module AST.
The compilation from a formula to a QVR program is a panproto-style
lens. The forward direction produces (module, formula_data): the module
states which terms the model has, and FormulaData holds what a program
cannot state (the data, the authored names, the original formula string) with
the binding by which each authored element is recognized. The backward
direction reads the terms from the module and their content from the
complement.
The lens target is a Module
that the existing quivers.dsl.compiler.Compiler consumes
directly, identical in shape to one produced by
quivers.dsl.parser.parse.
Authored prior strings enter through that parser once per distinct expression
within a forward preparation; emission and specialization retain their source AST.
Emitted structure (one named scalar coefficient per design-matrix
column, matching the brms / lme4 canonical layout in which
poly(x, 2) produces two coefficients poly(x, 2)_1 and
poly(x, 2)_2):
- One
object Resp : Ndeclaration per response plate. - One
object G : Kdeclaration per random-effect grouping factor (withKlevels). - For each fixed-design column
c: one scalar latent draw inside the program body,beta_c <- Normal(0, fixed_prior), whose scale is autoscaled by1 / rms(c)so the nominal value reads in contribution space and means the same thing on a raw predictor and on an orthonormalpolycolumn. An explicit per-name prior is emitted as written. The per-row covariate values forcflow in as a free variable via the host-data channel (observations[c]). - For each random-effect group
(slope | g): aHalfNormalscale latent plus a per-level plate draw, with the per-row contribution as a plate-gatheralpha_g[g_idx](orbeta_g_slope[g_idx] * slopefor a random slope). Single-bar blocks couple coefficients through an LKJ Cholesky factor; double bars retain independent effects. Explicit shared IDs can couple location and auxiliary coefficients. - One
observestep closes the program with the family's observation kernel applied to the inverse-link of the linear predictor. - Categorical responses use category zero as an identified reference
and lift every fixed and random term over the remaining
K - 1logits before applying softmax. - Finite mixtures emit each component as a nested response block and
observe the components' laws under one native
Mixture(quivers.formulas._mixture).
GetPut holds for every Formula f: backward(*forward(f)) == f.
FormulaToQVRModule
¶
FormulaToQVRModule(family: Family, *, fixed_prior: str = 'Normal(0.0, 5.0)', random_scale_prior: str = 'HalfNormal(1.0)', user_priors: PriorInput | None = None, reparameterize: Literal['centered', 'noncentered'] = 'noncentered', binomial_trials: int | str | None = None, thresholds_by: str | None = None, mixture_components: int = 2, predictor_name: str | None = None, distributional: Mapping[str, Formula] | None = None, predictor_graph: PredictorGraph | None = None, correlation_prior: str = 'LKJCholesky(1.0)', group_covariances: Mapping[str, GroupCovariance] | None = None, fixed_parameters: Mapping[str, float] | None = None, default_priors: DefaultPriorPolicy = 'quivers', center: bool | None = None, decomp: Literal['none', 'QR'] = 'none')
Bases: Lens[Formula, Module, FormulaData]
Translate a Formula to a QVR Module AST.
A typed didactic.api.Lens whose complement is a FormulaData: the
source formula and the program binding of each of its elements. Which
terms a formula has is read back from the module.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
Response family from
TYPE:
|
fixed_prior
|
Default prior for fixed-effect coefficients, in the surface
form
TYPE:
|
random_scale_prior
|
Default prior for random-effect scale parameters.
TYPE:
|
correlation_prior
|
Default LKJ Cholesky prior for correlated coefficient blocks.
TYPE:
|
group_covariances
|
Known covariance between labeled levels of each grouping factor. Coefficient correlations retain their existing LKJ hierarchy.
TYPE:
|
user_priors
|
Exact-name overrides or typed role selectors. More specific selectors refine broader rules; ambiguous and unused rules raise an error.
TYPE:
|
reparameterize
|
Conditional Gaussian coordinates for scalar, category-specific and component-valued group effects, and grouped threshold log slacks.
TYPE:
|
binomial_trials
|
Nonnegative common trial count or a per-row trial-count column.
TYPE:
|
thresholds_by
|
Grouping factor whose levels receive partially pooled ordinal cutpoint spacings.
TYPE:
|
mixture_components
|
Number of components for
TYPE:
|
predictor_name
|
Host-data name for an external differentiable predictor.
TYPE:
|
distributional
|
Auxiliary-parameter formulas on the same response rows. Each
predictor receives its own coefficients, covariates, and group effects;
a
TYPE:
|
fixed_parameters
|
Auxiliary parameters bound to constants on their natural scale, without latent sites or priors. Cannot overlap distributional formulas.
TYPE:
|
default_priors
|
Default policy for sites no prior rule selects: the proper, autoscaled
quivers defaults, or
TYPE:
|
center
|
brms
TYPE:
|
decomp
|
brms
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If an option is out of range or does not apply to |
Notes
GetPut: backward (forward(f)) = f for every
Formula f. PutGet holds on pairs (t, c) for
which t is in the image of forward and c is the
corresponding FormulaData.
Source code in src/quivers/formulas/compile.py
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 | |
group_covariances
property
¶
group_covariances: dict[str, GroupCovariance]
Read the known level covariances of this emission's grouping factors.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, GroupCovariance]
|
Covariances given directly and those read from |
group_layouts
property
¶
group_layouts: tuple[GroupBlockLayout, ...]
Read the raw-coordinate layouts emitted by the latest forward pass.
| RETURNS | DESCRIPTION |
|---|---|
tuple[GroupBlockLayout, ...]
|
Immutable group blocks shared with retained prediction plans. |
level_sites
property
¶
Return the sites of the latest forward pass indexed by levels.
| RETURNS | DESCRIPTION |
|---|---|
tuple[LevelSite, ...]
|
Every level-indexed site once, of the group blocks and of a grouped baseline hazard. |
predictors
property
¶
Return the linear predictors of the latest forward pass.
| RETURNS | DESCRIPTION |
|---|---|
tuple[Predictor, ...]
|
The location, the distributional parameters, and the nonlinear parameters. Empty for a mixture, whose components have their own. |
group_laws
property
¶
Return the law of each group block of the latest forward pass.
| RETURNS | DESCRIPTION |
|---|---|
tuple[GroupBlockLaw, ...]
|
Laws in emission order: the program's own, then those of its nested blocks. |
rows
property
¶
Return the rows the latest forward pass covers.
| RETURNS | DESCRIPTION |
|---|---|
RowSource or None
|
Fresh rows of a request, or None for the training rows. |
site_priors
property
¶
Return the priors configured for exact sites.
| RETURNS | DESCRIPTION |
|---|---|
Mapping[str, str]
|
Prior source by site name. |
observation
property
¶
Return the observation of the latest forward pass.
| RETURNS | DESCRIPTION |
|---|---|
Observation or None
|
The observation of the response, or None before a pass. |
names
property
¶
Return the names the latest forward pass gives columns and bindings.
| RETURNS | DESCRIPTION |
|---|---|
ProgramNames
|
The names that differ from the terms' own. |
term_laws
property
¶
term_laws: FamilyCatalog | None
Return the laws the terms of the latest forward pass draw from.
| RETURNS | DESCRIPTION |
|---|---|
FamilyCatalog or None
|
Compilation-local laws, or None when every law is built in. |
prior_targets
property
¶
prior_targets: tuple[PriorTarget, ...]
Read immutable role and axis metadata from the latest emitted model.
prior_set
property
¶
prior_set: PriorSet
Read the canonical authored prior rules retained for replay.
response_laws
property
¶
response_laws: FamilyCatalog | None
Return the compilation-local laws of the response.
| RETURNS | DESCRIPTION |
|---|---|
FamilyCatalog or None
|
The catalog of a custom family joined with that of the residual law, or None when the response law is built in. |
families
¶
families(response: FamilyCatalog | None = None) -> FamilyCatalog | None
Return every compilation-local law of the latest forward pass.
| PARAMETER | DESCRIPTION |
|---|---|
response
|
Laws of the response on the rows in use; None for those of the fitted family.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FamilyCatalog or None
|
The response laws joined with those of the terms. |
Source code in src/quivers/formulas/compile.py
forward
¶
forward(formula: Formula) -> tuple[Module, FormulaData]
Compile one formula through the shared response emitter.
| PARAMETER | DESCRIPTION |
|---|---|
formula
|
Evaluated response and design metadata.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Module, FormulaData]
|
Existing QVR program and its retained formula complement. |
Source code in src/quivers/formulas/compile.py
get_prior
¶
get_prior(formula: Formula) -> dict[str, str]
Inspect the effective priors without compiling or fitting a model.
| PARAMETER | DESCRIPTION |
|---|---|
formula
|
Evaluated response and predictor columns.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, str]
|
Overrideable parameter names and their canonical distribution
calls, including the actual scales after column autoscaling.
Sampled shrinkage includes hyperprior calls and conditional scale
references; retain |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a prior override does not name an available parameter. |
Source code in src/quivers/formulas/compile.py
backward
¶
backward(target: Module, complement: FormulaData) -> Formula
Recover a formula from a QVR module and its complement.
The terms are those the module states; their data and authored names come from the complement.
| PARAMETER | DESCRIPTION |
|---|---|
target
|
A QVR module in the image of
TYPE:
|
complement
|
The complement
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Formula
|
The complement's formula without the elements whose bindings the module lacks. |
Source code in src/quivers/formulas/compile.py
symbolic_column_expressions
¶
symbolic_column_expressions(formula: Formula) -> dict[str, LetExprNode]
Read declared latent-dependent inputs using the ordinary predictor layout.
| PARAMETER | DESCRIPTION |
|---|---|
formula
|
Primary predictor, together with configured auxiliary and graph leaves.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, LetExprNode]
|
Actual local input names and canonical expressions. Fixed and random uses of one column retain their existing, separately declared aliases. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If two uses assign different expressions to the same local input. |
Source code in src/quivers/formulas/compile.py
fixed_column_observations
¶
Bind retained covariates, offsets, and response likelihood weights.
| PARAMETER | DESCRIPTION |
|---|---|
formula
|
The formula whose fixed-effect columns are bound.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dict[str, Tensor]
|
Numeric predictor and offset columns as |
Source code in src/quivers/formulas/compile.py
GroupMemberLayout
didactic-model
¶
GroupMemberLayout(*, prefix: str, slope: str, axis: str | None, width: int, offset: int, coefficient: str, raw_site: str | None, scale_site: str | None = None, mean_site: str | None = None)
Bases: ValueModel
Locate one named coefficient within its joint Gaussian block.
| PARAMETER | DESCRIPTION |
|---|---|
prefix
|
Predictor namespace and expanded slope label.
TYPE:
|
slope
|
Predictor namespace and expanded slope label.
TYPE:
|
axis
|
Component axis; None denotes a scalar coefficient.
TYPE:
|
width
|
Component count and first coordinate in the joint block.
TYPE:
|
offset
|
Component count and first coordinate in the joint block.
TYPE:
|
coefficient
|
Retained deterministic coefficient binding.
TYPE:
|
raw_site
|
Sample site supplying this member's coordinates; None denotes a deterministic zero-rank deviation.
TYPE:
|
scale_site
|
Actual emitted conditional scale site for noncentered reconstruction.
TYPE:
|
mean_site
|
Optional affine hypermean, retained outside the supported deviation subspace for grouped threshold log-spacing profiles.
TYPE:
|
GroupBlockLayout
didactic-model
¶
GroupBlockLayout(*, group: str, identity: str, coordinate_axis: str | None, parameterization: Literal['centered', 'noncentered'], members: tuple[GroupMemberLayout, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), correlation_site: str | None = None, level_covariance: GroupCovarianceBasis | None = field(default=None, opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
Share Gaussian coefficient slices between compilation and prediction.
| PARAMETER | DESCRIPTION |
|---|---|
group
|
Original grouping factor and correlation-block identity.
TYPE:
|
identity
|
Original grouping factor and correlation-block identity.
TYPE:
|
coordinate_axis
|
Joint finite coordinate axis, absent for one scalar coefficient.
TYPE:
|
parameterization
|
Whether raw sites contain coefficients or standard-normal innovations.
TYPE:
|
members
|
Ordered nonoverlapping coefficient slices.
TYPE:
|
correlation_site
|
Actual emitted Cholesky site; None denotes an independent block.
TYPE:
|
level_covariance
|
Known covariance support over labeled levels. Its raw coordinates index this support rather than physical levels. Centered coordinates carry Gaussian deviations; noncentered coordinates are standardized.
TYPE:
|
width
property
¶
Return the joint coordinate count.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Sum of the retained member widths. |
raw_sites
property
¶
Read the number of coordinates per group at each raw site.
| RETURNS | DESCRIPTION |
|---|---|
dict[str, int]
|
Sum of member widths at each retained sample-site name. Joint centered members share one site; independent members need not. |
group_covariances retains labeled known level covariance independently of
coefficient correlations. Gaussian blocks use the existing MatrixNormal law
on explicit support coordinates; positive-semidefinite rank declarations keep
only genuine stochastic dimensions. Prediction shares the same layout and
conditions new levels through the retained covariance. See the
known-covariance workflow.
GroupCovariance
didactic-model
¶
GroupCovariance(*, levels: tuple[str, ...], matrix: tuple[tuple[float, ...], ...] | Tensor = field(opaque=True, extras=opaque_by_value(_matrix_values)), rank: int | None = None)
Bases: ValueModel
A known covariance between explicitly labeled grouping levels.
| PARAMETER | DESCRIPTION |
|---|---|
levels
|
Unique authored labels in matrix row and column order. The matrix can include future levels absent from the fitting data.
TYPE:
|
matrix
|
Finite symmetric covariance, copied from nested numeric sequences or a fixed Tensor. Its scale is retained; it need not be a correlation.
TYPE:
|
rank
|
None requires positive definiteness. An explicit nonnegative rank declares a positive-semidefinite law on its actual affine support. Eigenvalues below the declared rank must vanish within a relative Double-precision eigensolver tolerance; negative eigenvalues beyond that tolerance are rejected.
TYPE:
|
tensor
¶
tensor() -> Tensor
Read a fresh Double-precision covariance matrix.
| RETURNS | DESCRIPTION |
|---|---|
Tensor
|
Independent CPU storage; modifying it cannot change this value. |
Source code in src/quivers/formulas/_group_covariance.py
subset
¶
subset(levels: Sequence[str]) -> GroupCovariance
Retain a labeled principal submatrix in the requested order.
| PARAMETER | DESCRIPTION |
|---|---|
levels
|
Unique known grouping labels.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GroupCovariance
|
Reordered covariance, retaining explicit PSD support when declared. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If a requested label is unknown or repeated. |
Source code in src/quivers/formulas/_group_covariance.py
basis
¶
basis(levels: Sequence[str]) -> GroupCovarianceBasis
Factor a principal covariance without adding artificial dimensions.
| PARAMETER | DESCRIPTION |
|---|---|
levels
|
Ordered labels used by one emitted Gaussian block.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
GroupCovarianceBasis
|
Orthogonal support projection and exact positive coordinate law. |
Source code in src/quivers/formulas/_group_covariance.py
conditional
¶
conditional(fitted_levels: Sequence[str], new_levels: Sequence[str]) -> tuple[Tensor, GroupCovarianceBasis]
Condition new Gaussian levels on the complete fitted level vector.
| PARAMETER | DESCRIPTION |
|---|---|
fitted_levels
|
Disjoint known labels, in retained and requested order.
TYPE:
|
new_levels
|
Disjoint known labels, in retained and requested order.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, GroupCovarianceBasis]
|
Mean map |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If labels overlap or the conditional covariance is not PSD. |
Source code in src/quivers/formulas/_group_covariance.py
GroupCovarianceBasis
didactic-model
¶
GroupCovarianceBasis(*, levels: tuple[str, ...], projection: tuple[tuple[float, ...], ...] = field(opaque=True, extras=opaque_by_value(_matrix_values)), covariance: tuple[tuple[float, ...], ...] = field(opaque=True, extras=opaque_by_value(_matrix_values)), coordinate_factor: tuple[tuple[float, ...], ...] = field(opaque=True, extras=opaque_by_value(_matrix_values)), sampling_factor: tuple[tuple[float, ...], ...] = field(opaque=True, extras=opaque_by_value(_matrix_values)))
Bases: ValueModel
Retain the physical-level map and a nonsingular support-coordinate law.
| PARAMETER | DESCRIPTION |
|---|---|
levels
|
Physical grouping labels.
TYPE:
|
projection
|
Orthonormal columns mapping support coordinates to physical levels.
TYPE:
|
covariance
|
Positive-definite support covariance; an empty matrix denotes rank zero.
TYPE:
|
coordinate_factor
|
Cached Cholesky factor of the support covariance.
TYPE:
|
sampling_factor
|
Cached projection times coordinate_factor. Prediction materializes this factor without repeating an eigendecomposition or Cholesky.
TYPE:
|
rank
property
¶
Return the number of stochastic level coordinates.
| RETURNS | DESCRIPTION |
|---|---|
int
|
Support dimension, including zero for a deterministic deviation. |
tensors
¶
Materialize projection, coordinate covariance, and sampling factor.
| PARAMETER | DESCRIPTION |
|---|---|
like
|
Optional floating dtype and device context.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Tensor, Tensor, Tensor]
|
|
Source code in src/quivers/formulas/_group_covariance.py
Typed prior plans¶
user_priors accepts an exact-name mapping, PriorSpec, PriorSet, or a
sequence of specs. The compiler resolves selectors against one immutable
PriorTarget catalogue built from the same design and group layouts as the
model. prior_targets and FormulaData.prior_targets expose that catalogue;
prior_set retains the authored specification. Ordinary priors use the existing
compositional distribution parser, including normalized restrictions.
Sampled horseshoe and R2D2 hierarchies add hyperprior sites while preserving
coefficient binders and conditional group geometry. See the
prior workflow.
PriorSpec
didactic-model
¶
PriorSpec(*, distribution: PriorDistribution = field(opaque=True, extras=OPAQUE_BY_VALUE), class_: str | None = 'b', coef: str | None = None, group: str | None = None, dpar: str | None = None, nlpar: str | None = None, site: str | None = None, response: str | None = None, lower: float | None = None, upper: float | None = None, block: str | None = None, tag: str | None = None)
Bases: ValueModel
Select a prior using authored formula labels rather than generated names.
| PARAMETER | DESCRIPTION |
|---|---|
distribution
|
A compositional QVR distribution or a sampled shrinkage hierarchy.
TYPE:
|
class_
|
Parameter class: b excludes intercepts, except the intercept of a nonlinear parameter, which brms names class b with coefficient Intercept; Intercept, sd, cor, and auxiliary parameter names select their corresponding roles.
TYPE:
|
coef
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
group
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
dpar
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
nlpar
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
site
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
response
|
Expanded coefficient label, original group name, distributional or nonlinear parameter name, exact generated site, or authored joint-response label. None is a wildcard.
TYPE:
|
lower
|
Optional finite bounds, intersected with the target's domain.
TYPE:
|
upper
|
Optional finite bounds, intersected with the target's domain.
TYPE:
|
block
|
Shared shrinkage identity. Rules with the same block share global hyperparameters and allocations and must specify identical hierarchies.
TYPE:
|
tag
|
brms
TYPE:
|
selector
property
¶
Return exactly the explicitly selected role coordinates.
PriorSet
didactic-model
¶
PriorSet(*, rules: tuple[PriorSpec, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: ValueModel
An immutable collection of prior rules with explicit override semantics.
| PARAMETER | DESCRIPTION |
|---|---|
rules
|
Ordered rules. A strict selector refinement overrides a broader rule; ambiguous competing rules and unused rules are errors.
TYPE:
|
PriorTarget
didactic-model
¶
PriorTarget(*, site: str, class_: str, coef: str | None = None, group: str | None = None, dpar: str | None = None, nlpar: str | None = None, response: str | None = None, axes: tuple[str, ...] = (), shape: tuple[int, ...] = (), lower: float | None = None, upper: float | None = None, event_rank: int = 0, component_labels: tuple[str, ...] = (), parameters: tuple[str, ...] = (), partition_labels: tuple[str, ...] = (), partition_axis: str | None = None, vector: str | None = None, whole: str | None = None)
Bases: ValueModel
One overrideable site with semantic labels and nominal component axes.
| PARAMETER | DESCRIPTION |
|---|---|
site
|
Generated binder and semantic parameter class.
TYPE:
|
class_
|
Generated binder and semantic parameter class.
TYPE:
|
coef
|
Authored coefficient, grouping, predictor, and joint-response labels.
TYPE:
|
group
|
Authored coefficient, grouping, predictor, and joint-response labels.
TYPE:
|
dpar
|
Authored coefficient, grouping, predictor, and joint-response labels.
TYPE:
|
nlpar
|
Authored coefficient, grouping, predictor, and joint-response labels.
TYPE:
|
response
|
Authored coefficient, grouping, predictor, and joint-response labels.
TYPE:
|
axes
|
Nominal independent coefficient axes in source order.
TYPE:
|
shape
|
Their declared cardinalities, distinct from native event dimensions.
TYPE:
|
lower
|
Admissible coefficient-domain bounds.
TYPE:
|
upper
|
Admissible coefficient-domain bounds.
TYPE:
|
event_rank
|
Native distribution event rank, separate from independent axes.
TYPE:
|
component_labels
|
Free response-component labels in the retained coefficient order.
TYPE:
|
parameters
|
Parameter of each component, when every component belongs to a
parameter of its own, as
TYPE:
|
partition_labels
|
Levels of the
TYPE:
|
partition_axis
|
Axis over those levels.
TYPE:
|
vector
|
Parameter
TYPE:
|
whole
|
Site the component is part of.
TYPE:
|
sites
property
¶
Return the target's site and the site it is part of.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
One or two names. |
component_site
¶
Name the site of one component drawn on its own.
| PARAMETER | DESCRIPTION |
|---|---|
parameter
|
Parameter of the component.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Site name. |
Source code in src/quivers/formulas/_priors.py
components
¶
components() -> tuple[PriorTarget, ...]
Return the target of each component drawn on its own.
| RETURNS | DESCRIPTION |
|---|---|
tuple[PriorTarget, ...]
|
One target per parameter, with the component's own site. |
Source code in src/quivers/formulas/_priors.py
RegularizedHorseshoe
didactic-model
¶
RegularizedHorseshoe(*, df: float = 1.0, scale_global: float = 1.0, df_global: float = 1.0, scale_slab: float = 2.0, df_slab: float = 4.0, par_ratio: float | None = None, autoscale: bool = True, main: bool = False)
Bases: ValueModel
A sampled global/local shrinkage hierarchy with a Student-t slab.
| PARAMETER | DESCRIPTION |
|---|---|
df
|
Positive degrees of freedom for local, global, and slab priors.
TYPE:
|
df_global
|
Positive degrees of freedom for local, global, and slab priors.
TYPE:
|
df_slab
|
Positive degrees of freedom for local, global, and slab priors.
TYPE:
|
scale_global
|
Positive global and slab scales.
TYPE:
|
scale_slab
|
Positive global and slab scales.
TYPE:
|
par_ratio
|
If supplied, replace scale_global by par_ratio/sqrt(training_rows).
TYPE:
|
autoscale
|
Multiply the global scale by a scalar residual sigma when available. Distributional-parameter coefficients are not autoscaled.
TYPE:
|
main
|
brms
TYPE:
|
R2D2
didactic-model
¶
R2D2(*, mean_R2: float = 0.5, prec_R2: float = 2.0, cons_D2: float | tuple[float, ...] = field(default=0.5, opaque=True, extras=OPAQUE_BY_VALUE), autoscale: bool = True, main: bool = False)
Bases: ValueModel
A Gaussian-kernel R2D2 variance-allocation hierarchy.
| PARAMETER | DESCRIPTION |
|---|---|
mean_R2
|
Mean of the Beta prior on explained-variance fraction, in (0,1).
TYPE:
|
prec_R2
|
Positive Beta precision.
TYPE:
|
cons_D2
|
Positive Dirichlet concentration, shared or per selected coordinate.
TYPE:
|
autoscale
|
Multiply coefficient scales by a scalar residual sigma when available.
TYPE:
|
main
|
brms
TYPE:
|
normalize_priors
¶
normalize_priors(value: PriorInput | None) -> PriorSet
Adapt legacy named priors and typed rules into one immutable representation.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Exact-name mapping, one rule, or a collection of typed rules.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PriorSet
|
The canonical representation retained for compilation and replay. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If values are neither named distribution strings nor typed rules. |
Source code in src/quivers/formulas/_priors.py
PriorInput
¶
Authored exact-name overrides or typed rules normalized to one immutable PriorSet.
PriorDistribution
¶
PriorDistribution = str | RegularizedHorseshoe | R2D2 | ImproperFlat | ConstantPrior
A compositional QVR prior expression, a sampled shrinkage hierarchy, the improper flat prior, or a constant.