DiscriminativeNetwork
class DiscriminativeNetwork
Bases: abc.ABC
Base class for discriminative Quantum or Classical Neural Networks.
This method should initialize the module but raise an exception if a required component of the module is not available.
Methods
get_label
abstract DiscriminativeNetwork.get_label(x)
Apply quantum/classical neural network to the given input sample and compute the respective data label
Parameters
x (Discriminator) – input, i.e. data sample.
Raises
NotImplementedError – not implemented
loss
abstract DiscriminativeNetwork.loss(x, y, weights=None)
Loss function used for optimization
Parameters
- x (
Iterable
) – output. - y (
Iterable
) – the data point - weights (
Optional
[ndarray
]) – Data weights.
Returns
Loss w.r.t to the generated data points.
Raises
NotImplementedError – not implemented
save_model
abstract DiscriminativeNetwork.save_model(snapshot_dir)
Save discriminator model
Parameters
snapshot_dir (str
) – Directory to save the model
Raises
NotImplementedError – not implemented
set_seed
abstract DiscriminativeNetwork.set_seed(seed)
Set seed.
Parameters
seed (int) – seed
Raises
NotImplementedError – not implemented
train
abstract DiscriminativeNetwork.train(data, weights, penalty=False, quantum_instance=None, shots=None)
Perform one training step w.r.t to the discriminator’s parameters
Parameters
- data (
Iterable
) – Data batch. - weights (
Iterable
) – Data sample weights. - penalty (
bool
) – Indicate whether or not penalty function is applied to the loss function. Ignored if no penalty function defined. - quantum_instance (QuantumInstance) – used to run Quantum network. Ignored for a classical network.
- shots (
Optional
[int
]) – Number of shots for hardware or qasm execution. Ignored for classical network
Returns
with discriminator loss and updated parameters.
Return type
dict
Raises
NotImplementedError – not implemented