Skip to content

solvi.strategist

The strategist: the functions and checks of a catalog assembled into a flow per request (Flow, PlanError).

Strategist: given the questions and init_state, picks functions AND checks from the catalog and assembles the flow.

Targets for each question

• it has a rule → the rule's arguments; • an answer head is fitted → the facts selected during fitting; • otherwise → the uses hint; otherwise everything computable from init_state (marked "flow not narrowed").

Then it walks back through signatures down to what init_state provides; the question's required parts (requires) are always added. Checks: besides those the targets need, the strategist takes every catalog check whose inputs are all already in the flow and that touches at least one COMPUTED (non-input) fact — a check on computed facts. Nothing else from the catalog is executed. Typed facts: the flow records the type of each fact it uses (flow.types: a producer's return type, or for a given fact the type its typed readers expect); producer / consumer types were already checked when the parts were registered. Decisions with a model: decision parts that read the same facts with the same model, when the model can answer several questions in one forward pass, are grouped (flow.batches); the executor scores each group in one pass.

Binary

Binary(min_rows=20, refit_every=50, ring=2000, prior=0.5)

P(y = 1 | row), learned online.

observe

observe(row, y)

Deprecated (removed in 0.9): teach(row, y).

teach

teach(row, y)

One labelled row: y is True or False.

OrderModel

OrderModel(features=None, min_rows=20, refit_every=50)

P(hard check fails | cheap facts), one online model per hard check.

ProducerPolicy

ProducerPolicy(quality=0.9, explore=0.1, seed=0, min_rows=20, refit_every=50)

Chooses the order of a fact's alternative producers per input and learns from outcomes.

Alternatives whose predicted agreement with the reference (the last declared producer, normally the most trusted) is at least quality are tried first, cheapest expected cost first (cost ÷ P(accepted)); the rest follow in the same order. With probability explore the remaining producers also run after the accepted one, as a shadow: their outputs are never used, only compared, which gives agreement labels for producers the policy would otherwise stop trying.

plan

plan(group, row, costs)

→ (ordered alternatives, notes per alternative, shadow?)

observe

observe(group, row, outcomes)

outcomes: {producer: (accepted, value)} for the producers that ran on this input.

computable

computable(catalog, init_keys)

All facts computable from init_state (closure over signatures).

given_facts

given_facts(catalog, questions=())

The facts the catalog reads but no part produces — what init_state has to provide: arguments of parts and rules, and the questions' uses hints. (A rule that reads a question's name reads a given fact: answers are not facts.)

scalar_row

scalar_row(values, keys=None)

Cheap features from a dict of facts: numbers, booleans and short strings as they are; a long string gives its length; a list / tuple / dict gives its length. Anything else is left out.