'Computes GLS weights based on percentage of data fit'

def _compute_gls_weights(self):

    errors = (self.transformed_data - np.asarray(self.projection))
    if (self._ncomp == self._nvar):
        raise ValueError('gls    can    only    be    used    when    ncomp    <    nvar    so    that    residuals    have    non-zero    variance')
    var = (errors ** 2.0).mean(0)
    weights = (1.0 / var)
    weights = (weights / np.sqrt((weights ** 2.0).mean()))
    nvar = self._nvar
    eff_series_perc = ((1.0 / sum(((weights / weights.sum()) ** 2.0))) / nvar)
    if (eff_series_perc < 0.1):
        eff_series = int(np.round((eff_series_perc * nvar)))
        import warnings
        warn = 'Many    series    are    being    down    weighted    by    GLS.    Of    the    {original}    series,    the    GLS    estimates    are    based    on    only    {effective}    (effective)    series.'.format(original=nvar, effective=eff_series)
        warnings.warn(warn, EstimationWarning)
    self.weights = weights
