U
    ½mœd3
  ã                   @   sÚ   d dl Zd dlmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ eƒ Ze
dƒZe ejjd  ¡Ze e¡ eje Zeje Ze e¡Ze ¡  G dd	„ d	ƒZd
d„ Zdd„ Zdd„ Zdd„ Z dS )é    N)Úassert_allclose)Úassert_array_almost_equal)Úcheck_random_state)Ú	load_iris)Ú
Perceptroné   c                   @   s.   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
S )ÚMyPerceptroné   c                 C   s
   || _ d S ©N©Ún_iter)Úselfr   © r   úc/home/sam/Atlas/atlas_env/lib/python3.8/site-packages/sklearn/linear_model/tests/test_perceptron.pyÚ__init__   s    zMyPerceptron.__init__c                 C   sŠ   |j \}}tj|tjd�| _d| _t| jƒD ]X}t|ƒD ]J}|  || ¡d || kr8|  j|| ||  7  _|  j|| 7  _q8q,d S )N)Zdtypeg        r   )	ÚshapeÚnpZzerosZfloat64ÚwÚbÚranger   Úpredict)r   ÚXÚyZ	n_samplesZ
n_featuresÚtÚir   r   r   Úfit   s    
zMyPerceptron.fitc                 C   s   t  || j¡| j S r
   )r   Údotr   r   ©r   r   r   r   r   Úproject$   s    zMyPerceptron.projectc                 C   s   t  |¡}t  |  |¡¡S r
   )r   Z
atleast_2dÚsignr   r   r   r   r   r   '   s    
zMyPerceptron.predictN)r	   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r      s   
r   c                  C   sD   t tfD ]6} tdd dd�}| | t¡ | | t¡}|dkst‚qd S )Néd   F)Úmax_iterÚtolÚshufflegffffffæ?)r   ÚX_csrr   r   r   ÚscoreÚAssertionError)ÚdataÚclfr(   r   r   r   Útest_perceptron_accuracy,   s
    r,   c                  C   sZ   t  ¡ } d| t dk< tdd�}| t| ¡ tddd d�}| t| ¡ t|j|j 	¡ ƒ d S )Néÿÿÿÿr	   é   r   F)r$   r&   r%   )
r   Úcopyr   r   r   r   r   r   Úcoef_Zravel)Zy_binÚclf1Úclf2r   r   r   Útest_perceptron_correctness4   s    
r3   c               
   C   s8   t dd�} dD ]$}t t¡� t| |ƒ W 5 Q R X qd S )Nr#   )r$   )Zpredict_probaZpredict_log_proba)r   ÚpytestZraisesÚAttributeErrorÚgetattr)r+   Úmethr   r   r   Útest_undefined_methodsA   s    
r8   c                  C   s¸   t ddd�} |  tt¡ t ddd�}| tt¡ |  tt¡| tt¡ksLt‚t dd� tt¡}t ddd� tt¡}t|j|jƒ t dd� tt¡}t ddd� tt¡}t|j|jƒ d	S )
z?Check that `l1_ratio` has an impact when `penalty='elasticnet'`r   Z
elasticnet)Zl1_ratioÚpenaltyg333333Ã?Úl1)r9   r	   Úl2N)r   r   r   r   r(   r)   r   r0   )r1   r2   Zclf_l1Zclf_elasticnetZclf_l2r   r   r   Útest_perceptron_l1_ratioH   s    r<   )!Únumpyr   Zscipy.sparseÚsparseÚspr4   Zsklearn.utils._testingr   r   Zsklearn.utilsr   Zsklearn.datasetsr   Zsklearn.linear_modelr   ZirisZrandom_stateZaranger*   r   Úindicesr&   r   Útargetr   Z
csr_matrixr'   Zsort_indicesr   r,   r3   r8   r<   r   r   r   r   Ú<module>   s(   



