def __leastsq_fit(tomo_data, weights=None, trace=None, beta=None):
    '\n    Reconstruct a state from unconstrained least-squares fitting.\n\n    Args:\n        tomo_data (list[dict]): state or process tomography data.\n        weights (list or array or None): weights to use for least squares\n            fitting. The default is standard deviation from a binomial\n            distribution.\n        trace (float or None): trace of returned operator. The default is 1.\n        beta (float or None): hedge parameter (>=0) for computing frequencies\n            from zero-count data. The default value is 0.50922.\n\n    Returns:\n        numpy.array: A numpy array of the reconstructed operator.\n    '
    if (trace is None):
        trace = 1.0
    data = tomo_data['data']
    keys = data[0]['circuit'].keys()
    counts = []
    shots = []
    ops = []
    for dat in data:
        for key in keys:
            counts.append(dat['counts'][key])
            shots.append(dat['shots'])
            projectors = dat['circuit'][key]
            op = __projector(projectors['meas'], tomo_data['meas_basis'])
            if ('prep' in projectors):
                op_prep = __projector(projectors['prep'], tomo_data['prep_basis'])
                op = np.kron(op_prep.conj(), op)
            ops.append(op)
    counts = np.array(counts)
    shots = np.array(shots)
    freqs = (counts / shots)
    if (weights is None):
        if (beta is None):
            beta = 0.50922
        K = len(keys)
        freqs_hedged = ((counts + beta) / (shots + (K * beta)))
        weights = np.sqrt((shots / (freqs_hedged * (1 - freqs_hedged))))
    return __tomo_linear_inv(freqs, ops, weights, trace=trace)
Reconstruct a state from unconstrained least-squares fitting.

Args:
    tomo_data (list[dict]): state or process tomography data.
    weights (list or array or None): weights to use for least squares
        fitting. The default is standard deviation from a binomial
        distribution.
    trace (float or None): trace of returned operator. The default is 1.
    beta (float or None): hedge parameter (>=0) for computing frequencies
        from zero-count data. The default value is 0.50922.

Returns:
    numpy.array: A numpy array of the reconstructed operator.
def __leastsq_fit(tomo_data, weights=None, trace=None, beta=None):
    '\n    Reconstruct a state from unconstrained least-squares fitting.\n\n    Args:\n        tomo_data (list[dict]): state or process tomography data.\n        weights (list or array or None): weights to use for least squares\n            fitting. The default is standard deviation from a binomial\n            distribution.\n        trace (float or None): trace of returned operator. The default is 1.\n        beta (float or None): hedge parameter (>=0) for computing frequencies\n            from zero-count data. The default value is 0.50922.\n\n    Returns:\n        numpy.array: A numpy array of the reconstructed operator.\n    '
    if (trace is None):
        trace = 1.0
    data = tomo_data['data']
    keys = data[0]['circuit'].keys()
    counts = []
    shots = []
    ops = []
    for dat in data:
        for key in keys:
            counts.append(dat['counts'][key])
            shots.append(dat['shots'])
            projectors = dat['circuit'][key]
            op = __projector(projectors['meas'], tomo_data['meas_basis'])
            if ('prep' in projectors):
                op_prep = __projector(projectors['prep'], tomo_data['prep_basis'])
                op = np.kron(op_prep.conj(), op)
            ops.append(op)
    counts = np.array(counts)
    shots = np.array(shots)
    freqs = (counts / shots)
    if (weights is None):
        if (beta is None):
            beta = 0.50922
        K = len(keys)
        freqs_hedged = ((counts + beta) / (shots + (K * beta)))
        weights = np.sqrt((shots / (freqs_hedged * (1 - freqs_hedged))))
    return __tomo_linear_inv(freqs, ops, weights, trace=trace)