a
    >e9                     @   s   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Zdd Zdd ZdddZdd Zdd Zdd ZdddZdddZdS )    N)r2_score)	curve_fit)tc                 C   s   |t ||   S N)npexp)xab r   #/var/www/html/exp_data_generator.pyexponential_function	   s    r   c                 C   s(   t ddd}| t ||  }||fS )N      r   linspacer   )r	   r
   r   	y_perfectr   r   r    generate_target_exponential_line   s    r   normal   c                 C   s   t |}t||d  }tt jj||dd}	t|D ]}
|dkrTt jd|}n:|dkrnt j| |}n |dkrt j	d|}nt
d|
|	v r||9 }|d u st||kr<|||
< q8q<q8| | }|S )	Nd   F)replacer   r   uniformlaplacez=Invalid noise type. Choose 'normal', 'uniform', or 'laplace'.)r   zerosintsetrandomchoiceranger   r   r   
ValueErrorabs)r   std_devn
noise_typeoutlier_percentageoutlier_multiplierrejection_thresholdnoisenum_outliersoutlier_indicesinoise_sampley_noisyr   r   r   generate_noisy_data   s$    
r/   c                 C   s<   t t| |dd\}}|\}}t| ||}t||}|||fS )N)r   g?)p0)r   r   r   )r   r.   poptpcova_fittedb_fittedy_pred	r_squaredr   r   r   fit_noisy_exponential_data0   s
    
r7   c                 C   s0   t | | }| d d | }|d d | }||fS r   )len)r   r.   r$   stepx_subsety_subsetr   r   r   subset_noisy_data8   s    r<   c                 C   s2   | \}}}t dd|}|t ||  }||fS )Nr   r   r   )final_coeffsr$   r	   r
   _x_refy_refr   r   r   generate_exp_reference_line?   s    
rA   ffffff?c              	   C   s   |\}}t t |\}}td| d t| d }|t t ||  | d ||  t ||   | d   }	t| g|R  }
|
|	 }|
|	 }||fS )Nr      )r   sqrtdiagr   ppfr8   r   r   )r   r1   r2   confidence_levelr3   r4   Zse_aZse_bt_valuecir5   ci_lowerci_upperr   r   r   "calculate_exp_confidence_intervalsE   s    >rL   
   c	                 C   s   t | |\}	}
t|
|d||||}t|	||\}}t||\}}}t||||\}}|\}}|	 |
 | | | t|g|R   | | |||d}t| ||fS )Nr   )	x_perfectr   x_noisyr.   x_referencey_referencerJ   rK   r6   r3   r4   )r   r/   r<   r7   rL   tolistr   print)r	   r
   r#   r$   r%   r&   r'   	thresholdrG   rN   r   r.   x_noisy_subsety_noisy_subsetr1   r2   r6   rJ   rK   r3   r4   datar   r   r   exp_fit_and_store_resultsT   s(    rX   )r   r   r   N)rB   )r   rM   NrB   )numpyr   matplotlib.pyplotpyplotpltsklearn.metricsr   scipy.optimizer   scipy.statsr   timer   r   r/   r7   r<   rA   rL   rX   r   r   r   r   <module>   s   

