pyqpanda_alg.QSVR

Submodules

Classes

Quantum_SVR

This class implements a Quantum Support Vector Regression (QSVR) framework using a custom

Package Contents

class pyqpanda_alg.QSVR.Quantum_SVR(x, y)

This class implements a Quantum Support Vector Regression (QSVR) framework using a custom quantum kernel based on variational quantum circuits.

Parameters

x : array_like

Input features for training. If the number of features is less than 2, it will be padded; if more than 2, dimensionality reduction via PCA will be applied to reduce to 2D.

y : array_like

Target regression labels.

Attributes

x : ndarray

2-dimensional input features after scaling and dimensionality adjustment.

y : ndarray

Corresponding regression target values.

Methods
cir_real(qb, cs)

Builds a real-valued parameterized quantum circuit for encoding input vectors into quantum states.

dist(x, y)

Computes the fidelity between two quantum-encoded states derived from input vectors x and y, used as a quantum kernel value.

k_kernel(X, Y)

Constructs the custom quantum kernel matrix based on all pairwise fidelity distances between samples in X and Y.

get_res()

Trains the quantum SVR model using the quantum kernel and returns both predicted and actual values on the training set.

show_res()

Visualizes the regression surface predicted by the QSVR model along with original training data, assuming the input has been reduced to 2D.

Note

This QSVR model uses pyQPanda to simulate quantum circuits and SciKit-Learn’s SVR as the classical regression backend with a quantum-defined kernel.

References
[1] Schuld M., Sinayskiy I., Petruccione F. “An introduction to quantum machine learning.”

Contemporary Physics 56.2 (2015): 172-185.

Examples:

>>> from pyqpanda_alg import QSVR
>>> import numpy as np
>>> if __name__ == '__main__':
>>>     n_samples = 100
>>>     n_features = 2
>>>     X = np.random.rand(n_samples, n_features) * 10
>>>     y = (2 * np.sin(X[:, 0]) +
>>>         1.5 * np.cos(X[:, 1]))
>>>     QSVR.Quantum_SVR(X, y).show_res()
x
y
static cir_real(qb, cs)
dist(x, y)
k_kernel(X, Y)
get_res()
show_res()