U
    Kvf                     @   s   d Z ddlZG dd dZdS )zM
Created on Tue May 27 13:23:24 2014

Author: Josef Perktold
License: BSD-3

    Nc                   @   s.   e Zd ZdZdddZdd Zd	d
 ZeZdS )StandardizeTransformaB  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.
       NTc                 C   s   t |}|d| _|jddd| _|d krbt | jdkd }t|dkrTd}ntt |}|dkr~d| j|< d| j|< |dkrd | _|| _	d S )Nr   r   )ddofnF)
npasarraymeanZstdscaleZnonzerolenintZsqueeze	const_idx)selfdatar   r   Zdemean r   E/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/tools/transform_model.py__init__+   s    


zStandardizeTransform.__init__c                 C   s4   | j dkrt|| j S t|| j  | j S dS )z=standardize the data using the stored transformation
        N)r   r   r   r	   )r   r   r   r   r   	transformA   s    
zStandardizeTransform.transformc                 C   s4   || j  }| jdkr0|| j  || j  8  < |S )ae  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   sum)r   paramsZ
params_newr   r   r   transform_paramsJ   s    

z%StandardizeTransform.transform_params)r   NT)__name__
__module____qualname____doc__r   r   r   __call__r   r   r   r   r      s
   
	r   )r   Znumpyr   r   r   r   r   r   <module>   s   