ó
áp7]c           @   s,   d  Z  d d l Z d e f d     YZ d S(   sM   
Created on Tue May 27 13:23:24 2014

Author: Josef Perktold
License: BSD-3

i˙˙˙˙Nt   StandardizeTransformc           B   s8   e  Z d  Z d d e d  Z d   Z d   Z e Z RS(   sC  class to reparameterize a model for standardized exog

    Parameters
    ----------
    data : array_like
        data that is standardized along axis=0
    ddof : None or int
        degrees of freedom for calculation of standard deviation.
        default is 1, in contrast to numpy.std
    const_idx : None or int
        If None, then the presence of a constant is detected if the standard
        deviation of a column is **equal** to zero. A constant column is
        not transformed. If this is an integer, then the corresponding column
        will not be transformed.
    demean : bool, default is True
        If demean is true, then the data will be demeaned, otherwise it will
        only be rescaled.

    Notes
    -----
    Warning: Not all options are tested and it is written for one use case.
    API changes are expected.

    This can be used to transform only the design matrix, exog, in a model,
    which is required in some discrete models when the endog cannot be rescaled
    or demeaned.
    The transformation is full rank and does not drop the constant.

    i   c         C   sŮ   t  j |  } | j d  |  _ | j d d d |  _ | d  k r t  j |  j d k  d } t |  d k r| d } q t |  } n  | d k r´ d |  j | <d |  j | <n  | t	 k rĚ d  |  _ n  | |  _
 d  S(   Ni    t   ddofi   t   nc(   t   npt   asarrayt   meant   stdt   scalet   Nonet   nonzerot   lent   intt   Falset	   const_idx(   t   selft   dataR   R   t   demean(    (    s@   lib/python2.7/site-packages/statsmodels/tools/transform_model.pyt   __init__,   s    	c         C   sB   |  j  d k r# t j |  |  j St j |  |  j  |  j Sd S(   s>   standardize the data using the stored transformation

        N(   R   R   R   R   R   (   R   R   (    (    s@   lib/python2.7/site-packages/statsmodels/tools/transform_model.pyt	   transformB   s    c         C   sC   | |  j  } |  j d k r? | |  j c | |  j j   8<n  | S(   sf  Transform parameters of the standardized model to the original model

        Parameters
        ----------
        params : ndarray
            parameters estimated with the standardized model

        Returns
        -------
        params_new : ndarray
            parameters transformed to the parameterization of the original
            model

        R   (   R   R   R   t   sum(   R   t   paramst
   params_new(    (    s@   lib/python2.7/site-packages/statsmodels/tools/transform_model.pyt   transform_paramsL   s    #N(	   t   __name__t
   __module__t   __doc__R   t   TrueR   R   R   t   __call__(    (    (    s@   lib/python2.7/site-packages/statsmodels/tools/transform_model.pyR       s
   	
	(   R   t   numpyR   t   objectR    (    (    (    s@   lib/python2.7/site-packages/statsmodels/tools/transform_model.pyt   <module>   s   