<s> from __future__ import division , print_function <EOL> import numpy as np <EOL> from scipy . special import gamma as scipy_gamma_func <EOL> def alpha_func ( tau , eta , Gamma , s ) : <EOL> return eta * ( Gamma / ( <NUM_LIT:1> + <NUM_LIT> * tau ) ) ** ( s + <NUM_LIT:1> ) * scipy_gamma_func ( s ) <EOL> def x_to_g_w ( x ) : <EOL> n = len ( x ) // <NUM_LIT:3> <EOL> g_re = x [ <NUM_LIT:0> * n : <NUM_LIT:1> * n ] <EOL> g_im = x [ <NUM_LIT:1> * n : <NUM_LIT:2> * n ] <EOL> w = x [ <NUM_LIT:2> * n : <NUM_LIT:3> * n ] <EOL> return g_re + <NUM_LIT> * g_im , w , n <EOL> def alpha_apprx ( tau , g , w ) : <EOL> """<STR_LIT>""" <EOL> n_tau = len ( tau ) <EOL> tau = tau . reshape ( ( n_tau , <NUM_LIT:1> ) ) <EOL> res = np . sum ( g * np . exp ( - w * tau ) , axis = <NUM_LIT:1> ) <EOL> return res <EOL> def alpha_apprx_x ( tau , x ) : <EOL> g , w , n = x_to_g_w ( x ) <EOL> g = g . reshape ( ( <NUM_LIT:1> , n ) ) <EOL> w = w . reshape ( ( <NUM_LIT:1> , n ) ) <EOL> return alpha_apprx ( tau , g , w ) <EOL> def diff ( x , tau , alpha_true , p ) : <EOL> alpha = alpha_apprx_x ( tau , x ) <EOL> rel_diff = np . abs ( alpha_true - alpha ) / np . abs ( alpha_true ) <EOL> max_diff = np . max ( rel_diff ) <EOL> mean_rel_diff = np . mean ( rel_diff ) <EOL> return p * mean_rel_diff + ( <NUM_LIT:1> - p ) * max_diff </s>
