ó
áp7]c           @   s6   d  d l  Z d  d l m Z d e f d     YZ d S(   i˙˙˙˙N(   t   Buncht   _MinimalWLSc           B   s2   e  Z d  Z d Z d e e d  Z d d  Z RS(   sÍ  
    Minimal implementation of WLS optimized for performance.

    Parameters
    ----------
    endog : array-like
        1-d endogenous response variable. The dependent variable.
    exog : array-like
        A nobs x k array where `nobs` is the number of observations and `k`
        is the number of regressors. An intercept is not included by default
        and should be added by the user. See
        :func:`statsmodels.tools.add_constant`.
    weights : array-like, optional
        1d array of weights.  If you supply 1/W then the variables are pre-
        multiplied by 1/sqrt(W).  If no weights are supplied the default value
        is 1 and WLS reults are the same as OLS.
    check_endog : bool, optional
        Flag indicating whether to check for inf/nan in endog.
        If True and any are found, ValueError is raised.
    check_weights : bool, optional
        Flag indicating whether to check for inf/nan in weights.
        If True and any are found, ValueError is raised.

    Notes
    -----
    Provides only resid, scale, fittedvalues, model.weights which are used by
    methods that iteratively apply WLS.

    Does not perform any checks on the input data for type or shape
    compatibility
    sA   NaN, inf or invalid value detected in {0}, estimation infeasible.g      đ?c         C   sď   | |  _  | |  _ | |  _ t j |  } | rf t j t j |   sf t |  j j	 d    qf n  | r˘ t j t j |   s˘ t |  j j	 d    q˘ n  | | |  _
 t j |  rÎ | | |  _ n | d  d   d  f | |  _ d  S(   Nt   weightst   endog(   R   t   exogR   t   npt   sqrtt   allt   isfinitet
   ValueErrort   msgt   formatt   wendogt   isscalart   wexogt   None(   t   selfR   R   R   t   check_endogt   check_weightst   w_half(    (    s<   lib/python2.7/site-packages/statsmodels/regression/_tools.pyt   __init__(   s    			t   pinvc         C   sE  | d k r6 t  j j |  j  } | j |  j  } n~ | d k r t  j j |  j  \ } } t  j j | t  j | j |  j   } n- t  j j	 |  j |  j d d \ } } } } |  j
 j |  } |  j | } |  j |  j j |  }	 |  j j d |  j j d }
 t  j |	 |	  |
 } t d | d | d	 | d
 |  d |  S(   sK  
        Minimal implementation of WLS optimized for performance.

        Parameters
        ----------
        method : str, optional
            Method to use to estimate parameters.  "pinv", "qr" or "lstsq"

              * "pinv" uses the Moore-Penrose pseudoinverse
                 to solve the least squares problem.
              * "qr" uses the QR factorization.
              * "lstsq" uses the least squares implementation in numpy.linalg

        Returns
        -------
        results : namedtuple
            Named tuple containing the fewest terms needed to implement
            iterative estimation in models. Currently

              * params : Estimated parameters
              * fittedvalues : Fit values using original data
              * resid : Residuals using original data
              * model : namedtuple with one field, weights
              * scale : scale computed using weighted residuals

        Notes
        -----
        Does not perform and checks on the input data

        See Also
        --------
        statsmodels.regression.linear_model.WLS
        R   t   qrt   rcondi˙˙˙˙i    i   t   paramst   fittedvaluest   residt   modelt   scale(   R   t   linalgR   R   t   dotR   R   t   solvet   Tt   lstsqR   R   t   shapeR    (   R   t   methodt
   pinv_wexogR   t   Qt   Rt   _t   fitted_valuesR   t   wresidt   df_residR   (    (    s<   lib/python2.7/site-packages/statsmodels/regression/_tools.pyt   fit<   s    "*(   t   __name__t
   __module__t   __doc__R
   t   FalseR   R+   (    (    (    s<   lib/python2.7/site-packages/statsmodels/regression/_tools.pyR      s
   (   t   numpyR   t   statsmodels.tools.toolsR    t   objectR   (    (    (    s<   lib/python2.7/site-packages/statsmodels/regression/_tools.pyt   <module>   s   