U
    Ãmœd  ã                   @   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rŒd | _|| _	d S )Nr   r   )ÚddofÚnF)
ÚnpÚasarrayÚmeanZstdÚscaleZnonzeroÚlenÚintZsqueezeÚ	const_idx)ÚselfÚdatar   r   Zdemean© r   úZ/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/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   Únumpyr   r   r   r   r   r   Ú<module>   s   