Note
This is the documentation for the current state of the development branch of Qiskit Experiments. The documentation or APIs here can change prior to being released.
mean_xy_data¶
- mean_xy_data(xdata, ydata, sigma=None, shots=None, method='sample')[source]¶
Return (x, y_mean, sigma) data.
The mean is taken over all \(y\) data values with the same \(x\) data value using the specified method. For each \(x\) the mean \(\overline{y}\) and variance \(\sigma^2\) are computed as
"sample"(default): Sample mean and variance\(\overline{y} = \sum_{i=1}^N y_i / N\),
\(\sigma^2 = \sum_{i=1}^N ((\overline{y} - y_i)^2) / N\)
"iwv": Inverse-weighted variance\(\overline{y} = (\sum_{i=1}^N y_i / \sigma_i^2 ) \sigma^2\)
\(\sigma^2 = 1 / (\sum_{i=1}^N 1 / \sigma_i^2)\)
"shots_weighted_variance": Sample mean and variance with weights from shots\(\overline{y} = \sum_{i=1}^N n_i y_i / M\),
\(\sigma^2 = \sum_{i=1}^N (n_i \sigma_i / M)^2\), where \(n_i\) is the number of shots per data point and \(M = \sum_{i=1}^N n_i\) is a total number of shots from different circuit execution at the same \(x\) value. If
shotsis not provided, this applies uniform weights to all values.
- Parameters:
xdata (
ndarray) – 1D or 2D array of xdata from curve_fit_data or multi_curve_fit_dataydata (
ndarray) – array of ydata returned from curve_fit_data or multi_curve_fit_datasigma (
Optional[ndarray]) – Optional, array of standard deviations in ydata.shots (
Optional[ndarray]) – Optional, array of shots used to get a data point.method (
str) – The method to use for computing y means and standard deviations sigma (default: “sample”).
- Returns:
(x, y_mean, sigma, shots), wherexis an arrays of unique x-values,yis an array of sample mean y-values,sigmais an array of sample standard deviation of y values, andshotsare the total number of experiment shots used to evaluate the data point. Ifshotsin the function call isNone, the numbers appear in the returned value will represent just a number of duplicated x value entries.- Return type:
tuple
- Raises:
QiskitError – If the “ivw” method is used without providing a sigma.