qiskit.aqua.components.neural_networks.PyTorchDiscriminator¶
-
class
PyTorchDiscriminator
(n_features=1, n_out=1)[ソース]¶ Discriminator based on PyTorch
- パラメータ
n_features (
int
) – Dimension of input data vector.n_out (
int
) – Dimension of the discriminator’s output vector.
- 例外
MissingOptionalLibraryError – Pytorch not installed
-
__init__
(n_features=1, n_out=1)[ソース]¶ - パラメータ
n_features (
int
) – Dimension of input data vector.n_out (
int
) – Dimension of the discriminator’s output vector.
- 例外
MissingOptionalLibraryError – Pytorch not installed
Methods
__init__
([n_features, n_out])- type n_features
int
get_label
(x[, detach])Get data sample labels, i.e. true or fake.
gradient_penalty
(x[, lambda_, k, c])Compute gradient penalty for discriminator optimization
load_model
(load_dir)Load discriminator model
loss
(x, y[, weights])Loss function
save_model
(snapshot_dir)Save discriminator model
set_seed
(seed)Set seed.
train
(data, weights[, penalty, …])Perform one training step w.r.t.
Attributes
Get discriminator
-
property
discriminator_net
¶ Get discriminator
- 戻り値
discriminator object
- 戻り値の型
object
-
get_label
(x, detach=False)[ソース]¶ Get data sample labels, i.e. true or fake.
- パラメータ
x (Union(numpy.ndarray, torch.Tensor)) – Discriminator input, i.e. data sample.
detach (bool) – if None detach from torch tensor variable (optional)
- 戻り値
Discriminator output, i.e. data label
- 戻り値の型
torch.Tensor
-
gradient_penalty
(x, lambda_=5.0, k=0.01, c=1.0)[ソース]¶ Compute gradient penalty for discriminator optimization
- パラメータ
x (numpy.ndarray) – Generated data sample.
lambda (float) – Gradient penalty coefficient 1.
k (float) – Gradient penalty coefficient 2.
c (float) – Gradient penalty coefficient 3.
- 戻り値
Gradient penalty.
- 戻り値の型
torch.Tensor
-
load_model
(load_dir)[ソース]¶ Load discriminator model
- パラメータ
load_dir (
str
) – file with stored pytorch discriminator model to be loaded
-
loss
(x, y, weights=None)[ソース]¶ Loss function
- パラメータ
x (torch.Tensor) – Discriminator output.
y (torch.Tensor) – Label of the data point
weights (torch.Tensor) – Data weights.
- 戻り値
Loss w.r.t to the generated data points.
- 戻り値の型
torch.Tensor
-
save_model
(snapshot_dir)[ソース]¶ Save discriminator model
- パラメータ
snapshot_dir (
str
) – directory path for saving the model
-
train
(data, weights, penalty=True, quantum_instance=None, shots=None)[ソース]¶ Perform one training step w.r.t. to the discriminator’s parameters
- パラメータ
data (tuple) – real_batch: torch.Tensor, Training data batch. generated_batch: numpy array, Generated data batch.
weights (tuple) – real problem, generated problem
penalty (bool) – Indicate whether or not penalty function is applied to the loss function.
quantum_instance (QuantumInstance) – Quantum Instance (depreciated)
shots (int) – Number of shots for hardware or qasm execution. Not used for classical network (only quantum ones)
- 戻り値
with Discriminator loss (torch.Tensor) and updated parameters (array).
- 戻り値の型
dict