qiskit.aqua.components.neural_networks.NumPyDiscriminator¶
-
class
NumPyDiscriminator
(n_features=1, n_out=1)[source]¶ Discriminator based on NumPy
- Parameters
n_features (
int
) – Dimension of input data vector.n_out (
int
) – Dimension of the discriminator’s output vector.
-
__init__
(n_features=1, n_out=1)[source]¶ - Parameters
n_features (
int
) – Dimension of input data vector.n_out (
int
) – Dimension of the discriminator’s output vector.
Methods
__init__
([n_features, n_out])- type n_features
int
get_label
(x[, detach])Get data sample labels, i.e. true or fake.
load_model
(load_dir)Load discriminator model
loss
(x, y[, weights])Loss function :param x: sample label (equivalent to discriminator output) :type x: numpy.ndarray :param y: target label :type y: numpy.ndarray :param weights: customized scaling for each sample (optional) :type weights: numpy.ndarray
save_model
(snapshot_dir)Save discriminator model
set_seed
(seed)Set seed.
train
(data, weights[, penalty, …])Perform one training step w.r.t to the discriminator’s parameters
Attributes
Get discriminator
-
property
discriminator_net
¶ Get discriminator
- Returns
discriminator object
- Return type
DiscriminatorNet
-
get_label
(x, detach=False)[source]¶ Get data sample labels, i.e. true or fake.
- Parameters
x (numpy.ndarray) – Discriminator input, i.e. data sample.
detach (bool) – depreciated for numpy network
- Returns
Discriminator output, i.e. data label
- Return type
numpy.ndarray
-
load_model
(load_dir)[source]¶ Load discriminator model
- Parameters
load_dir (str) – file with stored pytorch discriminator model to be loaded
-
loss
(x, y, weights=None)[source]¶ Loss function :param x: sample label (equivalent to discriminator output) :type x: numpy.ndarray :param y: target label :type y: numpy.ndarray :param weights: customized scaling for each sample (optional) :type weights: numpy.ndarray
- Returns
loss function
- Return type
float
-
save_model
(snapshot_dir)[source]¶ Save discriminator model
- Parameters
snapshot_dir (str) – directory path for saving the model
-
train
(data, weights, penalty=False, quantum_instance=None, shots=None)[source]¶ Perform one training step w.r.t to the discriminator’s parameters
- Parameters
data (tuple(numpy.ndarray, numpy.ndarray)) – real_batch: array, Training data batch. generated_batch: array, Generated data batch.
weights (tuple) – real problem, generated problem
penalty (bool) – Depreciated for classical networks.
quantum_instance (QuantumInstance) – Depreciated for classical networks.
shots (int) – Number of shots for hardware or qasm execution. Ignored for classical networks.
- Returns
with Discriminator loss and updated parameters.
- Return type
dict