EffectiveDimension#

class EffectiveDimension(qnn, weight_samples=1, input_samples=1)[ソース]#

ベースクラス: object

This class computes the global effective dimension for a Qiskit NeuralNetwork following the definition used in [1].

References [1]: Abbas et al., The power of quantum neural networks. The power of QNNs.

パラメータ:
  • qnn (NeuralNetwork) – A Qiskit NeuralNetwork, with a specific dimension (num_weights) that will determine the shape of the Fisher Information Matrix (num_input_samples * num_weight_samples, num_weights, num_weights) used to compute the global effective dimension for a set of input_samples, of shape (num_input_samples, qnn_input_size), and weight_samples, of shape (num_weight_samples, num_weights).

  • weight_samples (ndarray | int) – An array of neural network parameters (weights), of shape (num_weight_samples, num_weights), or an int to indicate the number of parameter sets to sample randomly from a uniform distribution. By default, weight_samples = 1.

  • input_samples (ndarray | int) – An array of samples to the neural network, of shape (num_input_samples, qnn_input_size), or an int to indicate the number of input sets to sample randomly from a normal distribution. By default, input_samples = 1.

Attributes

input_samples#

Returns network input samples.

weight_samples#

Returns network weight samples.

Methods

get_effective_dimension(dataset_size)[ソース]#

This method computes the effective dimension for a dataset of size dataset_size. If an array is passed, then effective dimension computed for each value in the array.

パラメータ:

dataset_size (List[int] | ndarray | int) – array of data sizes or a single integer value.

戻り値:

array of effective dimensions for each dataset size in num_data.

戻り値の型:

effective_dim

get_fisher_information(gradients, model_outputs)[ソース]#

This method computes the average Jacobian for every set of gradients and model output as shown in Abbas et al.

パラメータ:
  • gradients (ndarray) – A numpy array, result of the neural network’s backward pass, of shape (num_input_samples * num_weight_samples, output_size, num_weights).

  • model_outputs (ndarray) – A numpy array, result of the neural networks』 forward pass, of shape (num_input_samples * num_weight_samples, output_size).

戻り値:

A numpy array of shape

(num_input_samples * num_weight_samples, num_weights, num_weights) with the average Jacobian for every set of gradients and model output given.

戻り値の型:

fisher

get_normalized_fisher(normalized_fisher)[ソース]#

This method computes the normalized Fisher Information Matrix and extracts its trace.

パラメータ:

normalized_fisher (ndarray) – The Fisher Information Matrix to be normalized.

戻り値:

The normalized Fisher Information Matrix, a numpy array of size

(num_input_samples, num_weights, num_weights).

fisher_trace: The trace of the Fisher Information Matrix

(before normalizing).

戻り値の型:

normalized_fisher

run_monte_carlo()[ソース]#

This method computes the model’s Monte Carlo sampling for a set of input samples and weight samples.

戻り値:

QNN gradient vector, result of backward passes, of shape

(num_input_samples * num_weight_samples, output_size, num_weights).

outputs: QNN output vector, result of forward passes, of shape

(num_input_samples * num_weight_samples, output_size).

戻り値の型:

grads