nifty7.probing module#

class StatCalculator[source]#

Bases: object

Helper class to compute mean and variance of a set of inputs.

Notes

  • The memory usage of this object is constant, i.e. it does not increase with the number of samples added.

  • The code computes the unbiased variance (which contains a 1./(n-1) term for n samples).

add(value)[source]#

Adds a sample.

Parameters:

value (any type that supports multiplication by a scalar and) – element-wise addition/subtraction/multiplication.

property mean#

the mean of all samples added so far.

Type:

value type

property var#

the unbiased variance of all samples added so far.

Type:

value type

approximation2endo(op, nsamples)[source]#
probe_diagonal(op, nprobes, random_type='pm1')[source]#

Probes the diagonal of an endomorphic operator.

The operator is called on a user-specified number of randomly generated input vectors v_i, producing r_i. The estimated diagonal is the mean of r_i^\dagger v_i.

Parameters:
  • op (EndomorphicOperator) – The operator to be probed.

  • nprobes (int) – The number of probes to be used.

  • random_type (str) – The kind of random number distribution to be used for the probing. The default value pm1 causes the probing vector to be randomly filled with values of +1 and -1.

Returns:

The estimated diagonal.

Return type:

Field

probe_with_posterior_samples(op, post_op, nprobes, dtype)[source]#

FIXME

Parameters:
  • op (EndomorphicOperator) – FIXME

  • post_op (Operator) – FIXME

  • nprobes (int) – Number of samples which shall be drawn.

  • dtype – the data type of the samples

Returns:

List of two fields: the mean and the variance.

Return type:

List of Field