DataBindingMixin¶
- class DataBindingMixin[source]¶
Bases:
objectShared data-axis behavior for VQA subclasses that fan a feature batch out.
Mixed in before
VariationalQuantumAlgorithmso its_build_cost_pipeline()cooperatively wraps the base one (mirroring howObservableMeasuringMixinsits ahead ofQuantumProgram). It owns the orchestration common toQNNandCustomVQA; each subclass still constructs the_data_symbols/_weight_symbolssplit and the_composed_circuititself and sets the attributesbuild_data_binding_stagereads.The mixin declares no
__init__: the data-binding state is populated during each subclass’s own construction, so there is no init ordering to coordinate.Methods Summary
predict(features[, params, return_scores])Predict for a feature batch with trained weights.
Methods Documentation
- predict(features, params=None, *, return_scores=False)[source]¶
Predict for a feature batch with trained weights.
Each row of
featuresis bound into the composed circuit alongside the weights and the cost observable’s expectation is estimated from shots — the same score the loss optimizes, includingloss_constantso it matches the full observable. By default the sign of that score is the class label:+1for a non-negative score,-1otherwise. Passreturn_scores=Trueto get the continuous scores instead (e.g. for a custom decision threshold or a regression-style output).This works for any observable (the expectation is measured directly, with no computational-basis decoding), and shares the measurement machinery the rest of the program uses.
- Parameters:
features (
TypeAliasType) – Shape(n_samples, n_data_params)(or a single(n_data_params,)row) feature batch.params (
ndarray[tuple[Any,...],dtype[double]] |None) – Trained weights of shape(n_layers * n_params_per_layer,). Defaults toself.best_params.return_scores (
bool) – WhenTrue, return the continuous per-sample score⟨H⟩ + loss_constantinstead of the sign-thresholded label.
- Returns:
- Shape
(n_samples,)— class labels in {-1.0, +1.0}by default, or continuous scores whenreturn_scoresisTrue.
- Shape
- Return type:
- Raises:
RuntimeError – If the program has no data axis, or if
paramsisNoneand the program has not been trained yet.ValueError – On a feature-column or weight-length mismatch.