- class StatCalculator#
Helper class to compute mean and variance of a set of inputs.
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).
Adds a sample.
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.
- property var#
the unbiased variance of all samples added so far.
- approximation2endo(op, nsamples)#
- probe_diagonal(op, nprobes, random_type='pm1')#
Probes the diagonal of an endomorphic operator.
The operator is called on a user-specified number of randomly generated input vectors , producing . The estimated diagonal is the mean of .
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.
The estimated diagonal.
- Return type:
- probe_with_posterior_samples(op, post_op, nprobes, dtype)#