def __leastsq_fit(tomo_data, weights=None, trace=None, beta=None):
if trace is None:<EOL><INDENT>trace = <NUM_LIT:1.>  <EOL><DEDENT>data = tomo_data['<STR_LIT:data>']<EOL>keys = data[<NUM_LIT:0>]['<STR_LIT>'].keys()<EOL>counts = []<EOL>shots = []<EOL>ops = []<EOL>for dat in data:<EOL><INDENT>for key in keys:<EOL><INDENT>counts.append(dat['<STR_LIT>'][key])<EOL>shots.append(dat['<STR_LIT>'])<EOL>projectors = dat['<STR_LIT>'][key]<EOL>op = __projector(projectors['<STR_LIT>'], tomo_data['<STR_LIT>'])<EOL>if '<STR_LIT>' in projectors:<EOL><INDENT>op_prep = __projector(projectors['<STR_LIT>'],<EOL>tomo_data['<STR_LIT>'])<EOL>op = np.kron(op_prep.conj(), op)<EOL><DEDENT>ops.append(op)<EOL><DEDENT><DEDENT>counts = np.array(counts)<EOL>shots = np.array(shots)<EOL>freqs = counts / shots<EOL>if weights is None:<EOL><INDENT>if beta is None:<EOL><INDENT>beta = <NUM_LIT><EOL><DEDENT>K = len(keys)<EOL>freqs_hedged = (counts + beta) / (shots + K * beta)<EOL>weights = np.sqrt(shots / (freqs_hedged * (<NUM_LIT:1> - freqs_hedged)))<EOL><DEDENT>return __tomo_linear_inv(freqs, ops, weights, trace=trace)<EOL>
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.