qrc
eigenkit.qml.qrc
Quantum reservoir computing (QRC) estimators, compatible with scikit-learn.
A reservoir is a circuit with fixed random weights, which are never trained.
These estimators sample the weights once (with the seed random_state), run the
circuit over the input sequences with
reservoir.run_reservoir(), extract classical
features, and train only a linear readout. This split into a fixed reservoir and
a linear readout is the standard form of QRC. So these estimators belong with the
scikit-learn estimators (next to QSVC and QSVR), and not in the PyTorch
package.
They are thin wrappers around the functions of the reservoir package. For full
control (custom processing of the features, custom readouts), call
run_reservoir and the feature extractors directly.
Data shapes: X has shape (n_sequences, n_timesteps, n_features), and y has
shape (n_sequences, n_timesteps), with one target per timestep (sequence to
sequence). washout drops the first timesteps from the fit of the readout, so
that the reservoir can forget its initial state. Predictions are still made for
every timestep.
QuantumReservoirClassifier
Bases: _ReservoirMixin, BaseQuantumClassifier
Quantum reservoir classifier: a fixed random reservoir and a logistic readout.
It uses the same reservoir as
QuantumReservoirRegressor.
The readout is a scikit-learn LogisticRegression on the features of each
timestep. y holds integer or label targets, of shape
(n_sequences, n_timesteps).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blocks
|
list
|
The architecture of the reservoir circuit, a list of blocks that
is assembled once. Its |
required |
state_policy
|
str
|
|
'carry'
|
window
|
int
|
The length of the sliding window, for |
1
|
leak
|
float
|
The mixing coefficient |
1.0
|
features
|
FeaturesSpec
|
The features read from the reservoir. It is |
'z'
|
C
|
float
|
The inverse regularisation strength of the logistic readout, passed
to scikit-learn. Smaller values regularise more. This is the only
argument that the regressor does not have: there, the readout is a
ridge regression controlled by |
1.0
|
washout
|
int
|
The number of timesteps dropped from the fit of the readout. They are not dropped from the predictions. |
0
|
weight_scale
|
float
|
The standard deviation of the sampled reservoir weights. |
1.0
|
provider
|
ProviderSpec
|
The backend, which must give access to the statevector.
Default: |
'numpy'
|
random_state
|
int | None
|
The seed of the fixed reservoir weights. |
42
|
__sklearn_is_fitted__()
Return True when the readout has been fitted.
fit(X, y)
Fit the estimator on X and y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
y
|
ndarray
|
One target for each timestep, of shape
|
required |
Returns:
| Type | Description |
|---|---|
'QuantumReservoirClassifier'
|
This estimator, so that calls can be chained. |
predict(X)
Predict a label for every timestep of every sequence in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The predicted labels, of shape |
predict_proba(X)
Predict the class probabilities for every timestep of every sequence in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The probabilities, of shape |
score(X, y)
Score the estimator on X against y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
y
|
ndarray
|
One target for each timestep, of shape
|
required |
Returns:
| Type | Description |
|---|---|
float
|
The accuracy of the predictions, over every timestep of every sequence. |
QuantumReservoirRegressor
Bases: _ReservoirMixin, BaseQuantumRegressor
Quantum reservoir regressor: a fixed random reservoir and a ridge readout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
blocks
|
list
|
The architecture of the reservoir circuit, a list of blocks that
is assembled once. Its |
required |
state_policy
|
str
|
|
'carry'
|
window
|
int
|
The length of the sliding window, for |
1
|
leak
|
float
|
The mixing coefficient |
1.0
|
features
|
FeaturesSpec
|
The features read from the reservoir. It is |
'z'
|
ridge
|
float
|
The strength of the L2 penalty of the linear readout, which is solved in closed form. |
1e-06
|
washout
|
int
|
The number of timesteps dropped from the fit of the readout. They are not dropped from the predictions. |
0
|
weight_scale
|
float
|
The standard deviation of the sampled reservoir weights. |
1.0
|
provider
|
ProviderSpec
|
The backend, which must give access to the statevector.
Default: |
'numpy'
|
random_state
|
int | None
|
The seed of the fixed reservoir weights. |
42
|
__sklearn_is_fitted__()
Return True when the readout has been fitted.
fit(X, y)
Fit the estimator on X and y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
y
|
ndarray
|
One target for each timestep, of shape
|
required |
Returns:
| Type | Description |
|---|---|
'QuantumReservoirRegressor'
|
This estimator, so that calls can be chained. |
predict(X)
Predict a value for every timestep of every sequence in X.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The predictions, of shape |
score(X, y)
Score the estimator on X against y.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
The sequences, of shape
|
required |
y
|
ndarray
|
One target for each timestep, of shape
|
required |
Returns:
| Type | Description |
|---|---|
float
|
The coefficient of determination |