<s> from lmfit import Parameters , Minimizer , conf_interval , conf_interval2d , minimize <EOL> import numpy as np <EOL> from scipy . interpolate import interp1d <EOL> try : <EOL> import pylab <EOL> HASPYLAB = True <EOL> except ImportError : <EOL> HASPYLAB = False <EOL> np . random . seed ( <NUM_LIT:1> ) <EOL> p_true = Parameters ( ) <EOL> p_true . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> p_true . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> p_true . add ( '<STR_LIT>' , value = - <NUM_LIT> ) <EOL> p_true . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> def residual ( pars , x , data = None ) : <EOL> amp = pars [ '<STR_LIT>' ] . value <EOL> decay = pars [ '<STR_LIT>' ] . value <EOL> amp2 = pars [ '<STR_LIT>' ] . value <EOL> decay2 = pars [ '<STR_LIT>' ] . value <EOL> model = amp * np . exp ( - x * decay ) + amp2 * np . exp ( - x * decay2 ) <EOL> if data is None : <EOL> return model <EOL> return ( model - data ) <EOL> n = <NUM_LIT:200> <EOL> xmin = <NUM_LIT:0.> <EOL> xmax = <NUM_LIT> <EOL> noise = np . random . normal ( scale = <NUM_LIT> , size = n ) <EOL> x = np . linspace ( xmin , xmax , n ) <EOL> data = residual ( p_true , x ) + noise <EOL> fit_params = Parameters ( ) <EOL> fit_params . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> fit_params . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> fit_params . add ( '<STR_LIT>' , value = - <NUM_LIT> ) <EOL> fit_params . add ( '<STR_LIT>' , value = <NUM_LIT> ) <EOL> mini = Minimizer ( residual , fit_params , <EOL> fcn_args = ( x , ) , fcn_kws = { '<STR_LIT:data>' : data } ) <EOL> out = mini . leastsq ( ) <EOL> ci , trace = conf_interval ( mini , out , trace = True ) <EOL> names = out . params . keys ( ) <EOL> if HASPYLAB : <EOL> pylab . rcParams [ '<STR_LIT>' ] = <NUM_LIT:8> <EOL> pylab . plot ( x , data ) <EOL> pylab . figure ( ) <EOL> cm = pylab . cm . coolwarm <EOL> for i in range ( <NUM_LIT:4> ) : <EOL> for j in range ( <NUM_LIT:4> ) : <EOL> pylab . subplot ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:16> - j * <NUM_LIT:4> - i ) <EOL> if i != j : <EOL> x , y , m = conf_interval2d ( mini , out , names [ i ] , names [ j ] , <NUM_LIT:20> , <NUM_LIT:20> ) <EOL> pylab . contourf ( x , y , m , np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ) , cmap = cm ) <EOL> pylab . xlabel ( names [ i ] ) <EOL> pylab . ylabel ( names [ j ] ) <EOL> x = trace [ names [ i ] ] [ names [ i ] ] <EOL> y = trace [ names [ i ] ] [ names [ j ] ] <EOL> pr = trace [ names [ i ] ] [ '<STR_LIT>' ] <EOL> s = np . argsort ( x ) <EOL> pylab . scatter ( x [ s ] , y [ s ] , c = pr [ s ] , s = <NUM_LIT:30> , lw = <NUM_LIT:1> , cmap = cm ) <EOL> else : <EOL> x = trace [ names [ i ] ] [ names [ i ] ] <EOL> y = trace [ names [ i ] ] [ '<STR_LIT>' ] <EOL> t , s = np . unique ( x , True ) <EOL> f = interp1d ( t , y [ s ] , '<STR_LIT>' ) <EOL> xn = np . linspace ( x . min ( ) , x . max ( ) , <NUM_LIT:50> ) <EOL> pylab . plot ( xn , f ( xn ) , '<STR_LIT:g>' , lw = <NUM_LIT:1> ) <EOL> pylab . xlabel ( names [ i ] ) <EOL> pylab . ylabel ( '<STR_LIT>' ) <EOL> pylab . show ( ) </s>
