quivers.formulas fit entry point¶
User-facing fit entry, formula_to_qvr source emit, and the
BayesianFit result wrapper.
_fit
¶
User-facing fit entry point and the
BayesianFit result wrapper.
The compilation path is fully AST-driven: the formula lens emits a
quivers.dsl.ast_nodes.Module, the existing
quivers.dsl.compiler.Compiler consumes it directly (no
source-string round-trip), and inference runs on the resulting
quivers.continuous.programs.MonadicProgram. Source text
is generated only when the user requests it via
formula_to_qvr or BayesianFit.dump_qvr, in which
case quivers.dsl.emit.module_to_source walks the same AST
to produce canonical .qvr source.
BayesianFit
¶
Bases: Model
A fitted Bayesian regression: the compiled program, the parsed formula, the family, the user-supplied data, and the posterior samples.
| ATTRIBUTE | DESCRIPTION |
|---|---|
formula |
Parsed formula IR.
TYPE:
|
family |
Response family used at compile time.
TYPE:
|
program |
The compiled program.
TYPE:
|
posterior |
TYPE:
|
observations |
Inference-time observations dict (response + per-column covariates + per-group plate indices).
TYPE:
|
dump_qvr
¶
dump_qvr(path: str | Path) -> Path
Write the AST-equivalent .qvr source to path and
return the resulting Path.
Source code in src/quivers/formulas/_fit.py
79 80 81 82 83 84 85 | |
fit
¶
fit(formula: str, *, data: IntoDataFrame, family: str | Family = 'gaussian', method: Literal['nuts', 'hmc', 'svi'] = 'nuts', num_warmup: int = 500, num_samples: int = 1000, num_chains: int = 4, fixed_prior: str = 'Normal(0.0, 5.0)', random_scale_prior: str = 'HalfNormal(1.0)', priors: Mapping[str, str] | None = None, guide: type | None = None, reparameterize: Literal['centered', 'noncentered'] = 'noncentered', seed: int = 0) -> BayesianFit
Compile a brms-style formula, fit it, and return the result.
See quivers.formulas for surface details. This entry
point composes formula_from_data, FormulaToQVRModule,
Compiler, and the inference layer in one call.
Source code in src/quivers/formulas/_fit.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
formula_to_qvr
¶
formula_to_qvr(formula: str, *, data: IntoDataFrame, family: str | Family = 'gaussian', fixed_prior: str = 'Normal(0.0, 5.0)', random_scale_prior: str = 'HalfNormal(1.0)', priors: Mapping[str, str] | None = None, reparameterize: Literal['centered', 'noncentered'] = 'noncentered', path: str | Path | None = None) -> str
Emit .qvr source for a brms-style formula without fitting.
Builds the formula AST → QVR Module via FormulaToQVRModule,
then serialises the module via quivers.dsl.emit.module_to_source.
Optionally writes the result to path.
Source code in src/quivers/formulas/_fit.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |