English
Languages
English
Italian
Japanese
Korean
Malayalam
Russian
Spanish
Tamil
Turkish
Vietnamese
Shortcuts



SamplingNeuralNetwork

class SamplingNeuralNetwork(num_inputs, num_weights, sparse, sampling, output_shape, input_gradients=False)[source]

Bases: qiskit_machine_learning.neural_networks.neural_network.NeuralNetwork

A Sampling Neural Network abstract class for all (quantum) neural networks within Qiskit’s machine learning module that generate samples instead of (expected) values.

Parameters
  • num_inputs (int) – The number of input features.

  • num_weights (int) – The number of trainable weights.

  • sparse (bool) – Returns whether the output is sparse or not.

  • sampling (bool) – Determines whether the network returns a batch of samples or (possibly sparse) array of probabilities in its forward pass. In case of probabilities, the backward pass returns the probability gradients, while it returns (None, None) in the case of samples.

  • output_shape (Union[int, Tuple[int, …]]) – The shape of the output.

  • input_gradients (bool) – Determines whether to compute gradients with respect to input data. Note that this parameter is False by default, and must be explicitly set to True for a proper gradient computation when using TorchConnector.

Raises

QiskitMachineLearningError – Invalid parameter values.

Attributes

sampling

Returns: True if the network returns a batch of samples and False if a sparse vector (dictionary) of probabilities in its forward pass.

Methods

probabilities(input_data, weights)

Histogram (as dict) of the samples from the network.

probability_gradients(input_data, weights)

Probability gradients of histogram resulting from the network.

sample(input_data, weights)

Samples from the network.