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