qiskit.aqua.algorithms.VQC¶
-
class
VQC
(optimizer, feature_map, var_form, training_dataset, test_dataset=None, datapoints=None, max_evals_grouped=1, minibatch_size=- 1, callback=None, quantum_instance=None)[소스]¶ The Variational Quantum Classifier algorithm.
Similar to
QSVM
, the VQC algorithm also applies to classification problems. VQC uses the variational method to solve such problems in a quantum processor. Specifically, it optimizes a parameterized quantum circuit to provide a solution that cleanly separates the data.참고
The VQC stores the parameters of var_form and feature_map sorted by name to map the values provided by the optimizer to the circuit. This is done to ensure reproducible results, for example such that running the optimization twice with same random seeds yields the same result.
- 매개변수
optimizer (
Optimizer
) – The classical optimizer to use.feature_map (
Union
[QuantumCircuit
,FeatureMap
]) – The FeatureMap instance to use.var_form (
Union
[QuantumCircuit
,VariationalForm
]) – The variational form instance.training_dataset (
Dict
[str
,ndarray
]) – The training dataset, in the format {‘A’: np.ndarray, ‘B’: np.ndarray, …}.test_dataset (
Optional
[Dict
[str
,ndarray
]]) – The test dataset, in same format as training_dataset.datapoints (
Optional
[ndarray
]) – NxD array, N is the number of data and D is data dimension.max_evals_grouped (
int
) – The maximum number of evaluations to perform simultaneously.minibatch_size (
int
) – The size of a mini-batch.callback (
Optional
[Callable
[[int
,ndarray
,float
,int
],None
]]) – a callback that can access the intermediate data during the optimization. Four parameter values are passed to the callback as follows during each evaluation. These are: the evaluation count, parameters of the variational form, the evaluated value, the index of data batch.quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – Quantum Instance or Backend
참고
We use label to denotes numeric results and class the class names (str).
- 예외
AquaError – Missing feature map or missing training dataset.
-
__init__
(optimizer, feature_map, var_form, training_dataset, test_dataset=None, datapoints=None, max_evals_grouped=1, minibatch_size=- 1, callback=None, quantum_instance=None)[소스]¶ - 매개변수
optimizer (
Optimizer
) – The classical optimizer to use.feature_map (
Union
[QuantumCircuit
,FeatureMap
]) – The FeatureMap instance to use.var_form (
Union
[QuantumCircuit
,VariationalForm
]) – The variational form instance.training_dataset (
Dict
[str
,ndarray
]) – The training dataset, in the format {‘A’: np.ndarray, ‘B’: np.ndarray, …}.test_dataset (
Optional
[Dict
[str
,ndarray
]]) – The test dataset, in same format as training_dataset.datapoints (
Optional
[ndarray
]) – NxD array, N is the number of data and D is data dimension.max_evals_grouped (
int
) – The maximum number of evaluations to perform simultaneously.minibatch_size (
int
) – The size of a mini-batch.callback (
Optional
[Callable
[[int
,ndarray
,float
,int
],None
]]) – a callback that can access the intermediate data during the optimization. Four parameter values are passed to the callback as follows during each evaluation. These are: the evaluation count, parameters of the variational form, the evaluated value, the index of data batch.quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – Quantum Instance or Backend
참고
We use label to denotes numeric results and class the class names (str).
- 예외
AquaError – Missing feature map or missing training dataset.
Methods
__init__
(optimizer, feature_map, var_form, …)- type optimizer
Optimizer
batch_data
(data[, labels, minibatch_size])batch data
set parameterized circuits to None
construct_circuit
(x, theta[, measurement])Construct circuit based on data and parameters in variational form.
find_minimum
([initial_point, var_form, …])Optimize to find the minimum cost value.
get optimal circuit
get optimal cost
get optimal vector
get_prob_vector_for_params
(…[, …])Helper function to get probability vectors for a set of params
get_probabilities_for_counts
(counts)get probabilities for counts
returns is gradient really supported
load_model
(file_path)load model
predict
(data[, quantum_instance, …])Predict the labels for the data.
run
([quantum_instance])Execute the algorithm with selected backend.
save_model
(file_path)save model
set_backend
(backend, **kwargs)Sets backend with configuration.
test
(data, labels[, quantum_instance, …])Predict the labels for the data, and test against with ground truth labels.
train
(data, labels[, quantum_instance, …])Train the models, and save results.
Attributes
Returns backend.
returns class to label
return data points
Return the feature map.
Returns initial point
returns label to class
returns optimal parameters
Returns optimizer
Returns quantum instance.
Return a numpy random.
returns result
returns test dataset
returns training dataset
Returns variational form
-
property
backend
¶ Returns backend.
- 반환 형식
Union
[Backend
,BaseBackend
]
-
property
class_to_label
¶ returns class to label
-
cleanup_parameterized_circuits
()¶ set parameterized circuits to None
-
construct_circuit
(x, theta, measurement=False)[소스]¶ Construct circuit based on data and parameters in variational form.
- 매개변수
x (numpy.ndarray) – 1-D array with D dimension
theta (list[numpy.ndarray]) – list of 1-D array, parameters sets for variational form
measurement (bool) – flag to add measurement
- 반환값
the circuit
- 반환 형식
- 예외
AquaError – If
x
andtheta
share parameters with the same name.
-
property
datapoints
¶ return data points
-
property
feature_map
¶ Return the feature map.
- 반환 형식
Union
[FeatureMap
,QuantumCircuit
,None
]
-
find_minimum
(initial_point=None, var_form=None, cost_fn=None, optimizer=None, gradient_fn=None)¶ Optimize to find the minimum cost value.
- 매개변수
initial_point (
Optional
[ndarray
]) – If not None will be used instead of any initial point supplied via constructor. If None and None was supplied to constructor then a random point will be used if the optimizer requires an initial point.var_form (
Union
[QuantumCircuit
,VariationalForm
,None
]) – If not None will be used instead of any variational form supplied via constructor.cost_fn (
Optional
[Callable
]) – If not None will be used instead of any cost_fn supplied via constructor.optimizer (
Optional
[Optimizer
]) – If not None will be used instead of any optimizer supplied via constructor.gradient_fn (
Optional
[Callable
]) – Optional gradient function for optimizer
- 반환값
Optimized variational parameters, and corresponding minimum cost value.
- 반환 형식
dict
- 예외
ValueError – invalid input
-
get_prob_vector_for_params
(construct_circuit_fn, params_s, quantum_instance, construct_circuit_args=None)¶ Helper function to get probability vectors for a set of params
-
get_probabilities_for_counts
(counts)¶ get probabilities for counts
-
property
initial_point
¶ Returns initial point
- 반환 형식
Optional
[ndarray
]
-
property
label_to_class
¶ returns label to class
-
property
optimal_params
¶ returns optimal parameters
-
property
optimizer
¶ Returns optimizer
- 반환 형식
Optional
[Optimizer
]
-
predict
(data, quantum_instance=None, minibatch_size=- 1, params=None)[소스]¶ Predict the labels for the data.
- 매개변수
data (numpy.ndarray) – NxD array, N is number of data, D is data dimension
quantum_instance (QuantumInstance) – quantum backend with all setting
minibatch_size (int) – the size of each minibatched accuracy evaluation
params (list) – list of parameters to populate in the variational form
- 반환값
for each data point, generates the predicted probability for each class list: for each data point, generates the predicted label (that with the highest prob)
- 반환 형식
list
-
property
quantum_instance
¶ Returns quantum instance.
- 반환 형식
Optional
[QuantumInstance
]
-
property
random
¶ Return a numpy random.
-
property
ret
¶ returns result
-
run
(quantum_instance=None, **kwargs)¶ Execute the algorithm with selected backend.
- 매개변수
quantum_instance (
Union
[QuantumInstance
,Backend
,BaseBackend
,None
]) – the experimental setting.kwargs (dict) – kwargs
- 반환값
results of an algorithm.
- 반환 형식
dict
- 예외
AquaError – If a quantum instance or backend has not been provided
-
set_backend
(backend, **kwargs)¶ Sets backend with configuration.
- 반환 형식
None
-
test
(data, labels, quantum_instance=None, minibatch_size=- 1, params=None)[소스]¶ Predict the labels for the data, and test against with ground truth labels.
- 매개변수
data (numpy.ndarray) – NxD array, N is number of data and D is data dimension
labels (numpy.ndarray) – Nx1 array, N is number of data
quantum_instance (QuantumInstance) – quantum backend with all setting
minibatch_size (int) – the size of each minibatched accuracy evaluation
params (list) – list of parameters to populate in the variational form
- 반환값
classification accuracy
- 반환 형식
float
-
property
test_dataset
¶ returns test dataset
-
train
(data, labels, quantum_instance=None, minibatch_size=- 1)[소스]¶ Train the models, and save results.
- 매개변수
data (numpy.ndarray) – NxD array, N is number of data and D is dimension
labels (numpy.ndarray) – Nx1 array, N is number of data
quantum_instance (QuantumInstance) – quantum backend with all setting
minibatch_size (int) – the size of each minibatched accuracy evaluation
-
property
training_dataset
¶ returns training dataset
-
property
var_form
¶ Returns variational form
- 반환 형식
Union
[QuantumCircuit
,VariationalForm
,None
]