# Fitting experimental data to thermodynamic models

Besides calculating and visualizing phase equilibria using known models, **pycalphad** also enables you to fit experimental data to a parameterized thermodynamic model. While pycalphad handles construction of the energy functions and equilibrium calculation, a separate module handles the numerical details of fitting disparate sources of data to the thermodynamic functions.

Here we consider the case study of the **Al-Mg-Zn** system. First, we use a TDB file as the setup for our model parameterizations. Note that not all of the parameters have not been filled in. These are what we will fit.

A+BT+CTln(T)+DT2+E/T+FT3

**Model parametrization:** Liang, H., Chen, S. L., & Chang, Y. A. (1997). A thermodynamic description of the Al-Mg-Zn system. _Metallurgical and Materials Transactions A_, 28(9), 1725-1734.

```python
%matplotlib inline

TDB_STR = """
$=============================================================================
$
$  Al-Mg-Zn System, almgzn.tdb
$  Parameterized by R. Otis from an Al-Cu-Mg-Zn database, 04-13-2015
$  Last updated: 01-07-1997 by H. Liang
$
$  Based on Al-Mg-Zn[96Liang]
$
$=============================================================================
$
 ELEMENT /-   ELECTRON_GAS              0.0000E+00  0.0000E+00  0.0000E+00!
 ELEMENT VA   VACUUM                    0.0000E+00  0.0000E+00  0.0000E+00!
 ELEMENT AL   FCC_A1                    2.6982E+01  4.5773E+03  2.8322E+01!
 ELEMENT MG   HCP_A3                    2.4305E+01  4.9980E+03  3.2671E+01!
 ELEMENT ZN   HCP_A3                    6.5380E+01  5.6567E+03  4.1631E+01!

 FUNCTION UN_ASS     2.98140E+02 0.0; 3.00000E+02  N !
 FUNCTION GHSERAL    2.98130E+02  -7976.15+137.071542*T-24.3671976*T*LN(T)
     -.001884662*T**2-8.77664E-07*T**3+74092*T**(-1);  7.00000E+02  Y
      -11276.24+223.02695*T-38.5844296*T*LN(T)+.018531982*T**2
     -5.764227E-06*T**3+74092*T**(-1);  9.33600E+02  Y
      -11277.683+188.661987*T-31.748192*T*LN(T)-1.234264E+28*T**(-9);
     2.90000E+03  N !
 FUNCTION GHSERMG    2.98130E+02  -8367.34+143.677875*T-26.1849782*T*LN(T)
     +4.858E-04*T**2-1.393669E-06*T**3+78950*T**(-1);  9.23000E+02  Y
      -14130.185+204.718543*T-34.3088*T*LN(T)+1.038192E+28*T**(-9);
     3.00000E+03  N !
 FUNCTION GHSERZN    2.98140E+02  -7285.787+118.470069*T-23.701314*T*LN(T)
   -.001712034*T**2-1.264963E-06*T**3;  6.92680E+02  Y
   -11070.559+172.34566*T-31.38*T*LN(T)+4.70514E+26*T**(-9);
     1.70000E+03  N !
$
 FUNCTION GALLIQ     2.98130E+02  +11005.553-11.840873*T+7.9401E-20*T**7
     +GHSERAL#;  9.33600E+02  Y
      +10481.974-11.252014*T+1.234264E+28*T**(-9)+GHSERAL#;
     2.90000E+03  N !
 FUNCTION GMGLIQ     2.98130E+02  +8202.24-8.83693*T-8.01759E-20*T**7
     +GHSERMG#;  9.23000E+02  Y
      +8690.32-9.39216*T-1.03819E+28*T**(-9)+GHSERMG#;  3.00000E+03  N !
 FUNCTION GZNLIQ     2.70000E+02  -128.517+108.176926*T-23.701314*T*LN(T)
     -.001712034*T**2-1.264963E-06*T**3-3.58652E-19*T**7;  6.92730E+02  Y
      -3620.474+161.608677*T-31.38*T*LN(T);  2.90000E+03  N !
$
 FUNCTION GBCCAL  2.98150E+02  +10083-4.813*T+GHSERAL#; 6.00000E+03  N !
 FUNCTION GBCCZN  2.98150E+02  +2886.96-2.5104*T+GHSERZN#;
		  6.00000E+03  N !
 FUNCTION GFCCZN  2.98150E+02  +2969.82-1.56968*T+GHSERZN#;
		  6.00000E+03  N !
 FUNCTION GFCCMG  2.98150E+02  2600-0.9*T+GHSERMG#;
		  6.00000E+03 N !

 TYPE_DEFINITION % SEQ *!
 DEFINE_SYSTEM_DEFAULT SPECIE 2 !
 DEFAULT_COMMAND DEF_SYS_ELEMENT VA !

 PHASE LIQUID:L %  1  1.0  !
    CONSTITUENT LIQUID:L :AL,MG,ZN :  !

   PARAMETER G(LIQUID,AL;0)  2.98130E+02  +GALLIQ#;
			     3.00000E+03  N REF: 0 !
   PARAMETER G(LIQUID,MG;0)  2.98130E+02  +GMGLIQ#;
			     3.00000E+03  N REF: 0 !
   PARAMETER G(LIQUID,ZN;0)  2.98130E+02  +GZNLIQ#;
			     3.00000E+03  N REF: 0 !
   PARAMETER G(LIQUID,AL,MG;0)  2.98150E+02  LIQALMG0A+LIQALMG0B*T;
				6.00000E+03  N REF: 0 !
   PARAMETER G(LIQUID,AL,ZN;0)  2.98150E+02  LIQALZN0A+LIQALZN0B*T;
				6.00000E+03   N REF: 3 !
   PARAMETER G(LIQUID,AL,ZN;1)  2.98150E+02  LIQALZN1A+LIQALZN1B*T;
				6.00000E+03   N REF: 3 !
   PARAMETER G(LIQUID,MG,ZN;0) 298.15  LIQMGZN0A+LIQMGZN0B*T+LIQMGZN0C*T*LN(T);
			       6000.0   N REF: 4 !
   PARAMETER G(LIQUID,MG,ZN;1) 298.15  LIQMGZN1A+LIQMGZN1B*T;
			       6000.0 N REF: 4 !
   PARAMETER G(LIQUID,MG,ZN;2) 298.15  LIQMGZN2A;
			       6000.0   N REF:   4 !
$
   PARAMETER G(LIQUID,AL,MG,ZN;0) 298.15 LIQALMGZN0A;
				  6000.0  N REF:  0 !
   PARAMETER G(LIQUID,AL,MG,ZN;1) 298.15 LIQALMGZN1A;
				  6000.0 N REF:  0 !
   PARAMETER G(LIQUID,AL,MG,ZN;2) 298.15 LIQALMGZN2A;
				  6000.0  N REF:  0 !

$----------------------------------------------------------------------
 TYPE_DEFINITION ' GES A_P_D FCC_A1 MAGNETIC  -3.0    2.80000E-01 !

 PHASE FCC_A1  %'  2 1   1 !
    CONSTITUENT FCC_A1  :AL%,MG,ZN : VA% :  !

   PARAMETER G(FCC_A1,AL:VA;0)  2.98130E+02  +GHSERAL#;
				2.90000E+03  N REF:  0 !
   PARAMETER G(FCC_A1,MG:VA;0)  2.98130E+02  +2600-.9*T+GHSERMG#;
				3.00000E+03  N REF: 0 !
   PARAMETER G(FCC_A1,ZN:VA;0)  2.98150E+02  +2969.82-1.56968*T+GHSERZN#;
				6.00000E+03   N REF: 1 !
   PARAMETER G(FCC_A1,AL,MG:VA;0)  2.98150E+02  FCCALMG0A+FCCALMG0B*T;
				   6.00000E+03   N REF: 0 !
   PARAMETER G(FCC_A1,AL,MG:VA;1)  2.98150E+02  0+0*T;
				   6.00000E+03   N REF: 0 !
   PARAMETER G(FCC_A1,AL,ZN:VA;0)  2.98150E+02  FCCALZN0A+FCCALZN0B*T;
				   6.00000E+03   N REF: 3 !
   PARAMETER G(FCC_A1,AL,ZN:VA;1)  2.98150E+02  FCCALZN1A+FCCALZN1B*T;
				   6.00000E+03   N REF: 3 !
   PARAMETER G(FCC_A1,AL,ZN:VA;2)  2.98150E+02  FCCALZN2A+FCCALZN2B*T;
				   6.00000E+03   N REF: 3 !
   PARAMETER G(FCC_A1,MG,ZN:VA;0)  2.98150E+02  FCCMGZN0A;
				   6000.0        N REF: 4 !
   PARAMETER G(FCC_A1,AL,MG,ZN:VA;0) 298.15 FCCALMGZN0A;
				     6000.0  N REF:  0 !

$----------------------------------------------------------------------

 TYPE_DEFINITION ( GES A_P_D HCP_A3 MAGNETIC  -3.0    2.80000E-01 !

 PHASE HCP_A3  %(  2 1   .5 !
    CONSTITUENT HCP_A3  :AL,MG%,ZN : VA% :  !

   PARAMETER G(HCP_A3,AL:VA;0)  2.98130E+02  +5481-1.8*T+GHSERAL#;
				2.90000E+03  N REF: 0 !
   PARAMETER G(HCP_A3,MG:VA;0)  2.98130E+02  +GHSERMG#;
				3.00000E+03  N REF:  0 !
   PARAMETER G(HCP_A3,ZN:VA;0)  2.98150E+02  +GHSERZN#;
				6.00000E+03   N REF: 1 !
   PARAMETER G(HCP_A3,AL,MG:VA;0)  2.98150E+02  HCPALMG0A+HCPALMG0B*T;
				   6.00000E+03   N REF: 0 !
   PARAMETER G(HCP_A3,AL,MG:VA;1)  2.98150E+02  HCPALMG1A;
				   6.00000E+03   N  REF: 0 !
   PARAMETER G(HCP_A3,AL,ZN:VA;0)  2.98150E+02  HCPALZN0A;
				   6.00000E+03   N REF: 3 !
   PARAMETER G(HCP_A3,MG,ZN:VA;0) 298.15  HCPMGZN0A+HCPMGZN0B*T;
				  6000.0 N REF: 4 !
   PARAMETER G(HCP_A3,MG,ZN:VA;1) 298.15  HCPMGZN1A+HCPMGZN1B*T;
				  6000.0 N REF: 4 !

$-------------------------------------------------------------------

  PHASE SIGMA  %  2 .66667    .33333 !
    CONSTITUENT SIGMA  :AL,ZN : MG :  !

   PARAMETER G(SIGMA,AL:MG;0)  2.98150E+02  +20133.73+6.3946*T
			       +.66667*GALLIQ#+.33333*GMGLIQ#;
			       3.00000E+03  N REF: 0 !
   PARAMETER G(SIGMA,ZN:MG;0)  2.98150E+02  -19389.65+13.644*T
			       +.66667*GZNLIQ#+.33333*GMGLIQ#;
			       3.00000E+03  N REF: 0 !
   PARAMETER G(SIGMA,AL,ZN:MG;0) 2.98150E+02  SIGALZN0A;
				 3.00000E+03  N  REF: 0 !
   PARAMETER G(SIGMA,AL,ZN:MG;1) 2.98150E+02  SIGALZN1A;
				 3.00000E+03  N  REF: 0 !

$----------------------------------------------------------------

 PHASE T  %  2 .605   .395 !
    CONSTITUENT T  :AL,ZN : MG :  !

   PARAMETER G(T,AL:MG;0)  2.98150E+02  -10910.836+8.71*T
			   +.605*GALLIQ#+.395*GMGLIQ#;
			   3.00000E+03  N REF: 0 !
   PARAMETER G(T,ZN:MG;0)  2.98150E+02  -15733.501+12.6746*T
			   +.605*GZNLIQ#+.395*GMGLIQ#;
			   3.00000E+03  N REF: 0 !
   PARAMETER G(T,AL,ZN:MG;0)  2.98150E+02  TALZN0A+TALZN0B*T;
			      3.00000E+03  N  REF: 0 !
   PARAMETER G(T,AL,ZN:MG;1)  2.98150E+02  TALZN1A;
			      3.00000E+03  N REF:   0 !
$-----------------------------------------------------------------

 PHASE EPS  %  2 1   1 !
    CONSTITUENT EPS  :AL,MG,ZN : VA :  !

   PARAMETER G(EPS,AL:VA;0)  2.98150E+02   5481-1.8*T+GHSERAL#;
			     6.00000E+03 N REF: 0 !
   PARAMETER G(EPS,MG:VA;0)  2.98150E+02  +10+GFCCMG#;
			     6.00000E+03 N REF: 0 !
   PARAMETER G(EPS,ZN:VA;0)  2.98150E+02  +GFCCZN#;
			     6.00000E+03   N REF: 0 !
   PARAMETER G(EPS,AL,ZN:VA;0)  2.98150E+02   EPSALZN0A;
				6.00000E+03   N REF: 0 !

$-----------------------------------------------------------------

 TYPE_DEFINITION & GES A_P_D BCC_A2 MAGNETIC  -1.0    4.00000E-01 !

  PHASE BCC_A2  %  2 1   3 !
    CONSTITUENT BCC_A2  :AL,ZN : VA% :  !

   PARAMETER G(BCC_A2,AL:VA;0)  2.98150E+02  +10083-4.813*T+GHSERAL#;
				6.00000E+03   N REF: 1 !
   PARAMETER G(BCC_A2,ZN:VA;0)  2.98150E+02  +2886.96-2.5104*T+GHSERZN#;
				6.00000E+03   N REF: 1 !
   PARAMETER G(BCC_A2,AL,ZN:VA;0)  2.98150E+02   BCCALZN0A;
				   6.00000E+03  N REF: 0 !

$------------------------------------------------------------------

PHASE GAMMA  %  2 1   1 !
    CONSTITUENT GAMMA  :AL,ZN : VA :  !

   PARAMETER G(GAMMA,AL:VA;0)  2.98150E+02  +GHSERAL#+10.0;
			       6.00000E+03  N  REF: 0 !
   PARAMETER G(GAMMA,ZN:VA;0)  2.98150E+02  +GHSERZN#+10.0;
			       6.00000E+03  N  REF: 0 !
   PARAMETER G(GAMMA,AL,ZN:VA;0)  2.98150E+02  GAMALZN0A;
				  6.00000E+03  N REF: 0 !
$---------------------------------------------------------------------

 PHASE PHI  %  3  2  5  2 !
    CONSTITUENT PHI  :AL : MG : ZN :  !

  PARAMETER G(PHI,AL:MG:ZN;0)    298.15  -169985.46+136.8*T
	+2*GALLIQ#+5*GMGLIQ#+2*GZNLIQ#;  6000.0 N REF: 0 !

$======================================================================
$              Binary Intermetallic Phases
$======================================================================

$---------------------------------------------------------------------

 PHASE ALMG_BETA  %  2 .615   .385 !
    CONSTITUENT ALMG_BETA  :AL : MG :  !

   PARAMETER G(ALMG_BETA,AL:MG;0)  2.98150E+02  -1451.1-1.907*T
	      +.615*GHSERAL#+.385*GHSERMG#;   6.00000E+03   N REF: 0 !

$---------------------------------------------------------------------

 PHASE ALMG_EPSILON  %  2 .56   .44 !
    CONSTITUENT ALMG_EPSILON  :AL : MG :  !
   PARAMETER G(ALMG_EPSILON,AL:MG;0)  2.98150E+02  ALMG_EPSILONALMG0A+ALMG_EPSILONALMG0B*T
	       +.56*GHSERAL#+.44*GHSERMG#;   6.00000E+03   N REF: 0 !

$----------------------------------------------------------------------

 PHASE ALMG_GAMMA  %  3 .4483   .1379   .4138 !
    CONSTITUENT ALMG_GAMMA  :MG : AL,MG : AL,MG :  !

   PARAMETER G(ALMG_GAMMA,MG:AL:AL;0)  2.98150E+02  ALMG_GAMMAMGALAL0A+ALMG_GAMMAMGALAL0B*T
	   +.5517*GHSERAL#+.4483*GHSERMG#;  6.00000E+03   N REF: 0 !
   PARAMETER G(ALMG_GAMMA,MG:MG:AL;0)  2.98150E+02  ALMG_GAMMAMGMGAL0A+ALMG_GAMMAMGMGAL0B*T
	   +.4138*GHSERAL#+.5862*GHSERMG#;   6.00000E+03   N REF: 0 !
   PARAMETER G(ALMG_GAMMA,MG:AL:MG;0)  2.98150E+02  ALMG_GAMMAMGALMG0A+ALMG_GAMMAMGALMG0B*T
	   +.1379*GHSERAL#+.8621*GHSERMG#;   6.00000E+03   N REF: 0 !
   PARAMETER G(ALMG_GAMMA,MG:MG:MG;0)  2.98150E+02  ALMG_GAMMAMGMGMG0A+GHSERMG#;
	   6.00000E+03   N REF: 0 !

$----------------------------------------------------------------------
$
 PHASE ALMG_ZETA  %  2 .525   .475 !
    CONSTITUENT ALMG_ZETA  :AL : MG :  !

   PARAMETER G(ALMG_ZETA,AL:MG;0)  2.98150E+02  -837.8-3.163*T
	    +.525*GHSERAL#+.475*GHSERMG#;   6.00000E+03   N REF: 0 !

$----------------------------------------------------------------------
$
 PHASE MG2ZN11  %  2 .153846   .846154 !
    CONSTITUENT MG2ZN11  :MG : ZN :  !

  PARAMETER G(MG2ZN11,MG:ZN;0)  298.15  -5823.05+1.94323*T
  +0.153846154*GHSERMG#+0.846153846*GHSERZN#;   6000.0   N REF: 4 !
$
$-----------------------------------------------------------------------
$
 PHASE MG2ZN3  %  2 .4   .6 !
    CONSTITUENT MG2ZN3  :MG : ZN :  !

  PARAMETER G(MG2ZN3,MG:ZN;0)  298.15  -11014.5+3.67151*T+0.4*GHSERMG#
			       +0.6*GHSERZN#;   6000.0   N REF: 4 !
$
$-----------------------------------------------------------------------
$
 PHASE MG7ZN3  %  2 .71831   .28169 !
    CONSTITUENT MG7ZN3  :MG : ZN :  !

  PARAMETER G(MG7ZN3,MG:ZN;0)  298.15  -4814.11+T+0.71831*GHSERMG#
			       +0.28169*GHSERZN#;   6000.0   N REF: 4 !
$
$-----------------------------------------------------------------------
$
 PHASE MGZN  %  2 .48   .52 !
    CONSTITUENT MGZN  :MG : ZN :  !

  PARAMETER G(MGZN,MG:ZN;0)  298.15  -9590.44+3.19681*T+0.48*GHSERMG#
			     +0.52*GHSERZN#;   6000.0   N REF: 4 !
$

$===========================================================================
"""

from pycalphad import Database, Model, binplot
import pycalphad.variables as v
import matplotlib
matplotlib.style.use('ggplot')
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from sympy import Symbol
import numpy as np

dbf = Database(TDB_STR)
```

## Performing a fit

We perform the fit using the **fit_model** routine in pycalphad.

```python
import pandas as pd
from pycalphad.residuals import fit_model

liang96_almg_parameters = {
    'FCCALMG0A':   1000,
    'FCCALMG0B':   10,
}
import lmfit
phase_eq = pd.read_csv('almg_fcc_enthalpy.csv')
#phases = ['LIQUID', 'FCC_A1', 'HCP_A3', 'ALMG_EPSILON', 'ALMG_BETA', 'ALMG_GAMMA']
phases = ['FCC_A1']
comps = ['AL', 'MG', 'VA']
start_models = {name: Model(dbf, comps, name, parameters=liang96_almg_parameters) for name in phases}
%time result, mi = fit_model(liang96_almg_parameters, phase_eq, dbf, comps, phases, maxfev=50)
fit_models = {name: Model(dbf, comps, name, parameters=result) for name in phases}
```

    [[[[ 0.75076519  0.24923481  1.        ]]]]
    res 0 184.883182334
    [[[[ 0.50266554  0.49733446  1.        ]]]]
    res 1 144.007105662
    [[[[ 0.2503411  0.7496589  1.       ]]]]
    res 2 -41.6704333344
    [[[[ 0.75076519  0.24923481  1.        ]]]]
    res 0 184.883182334
    [[[[ 0.50266554  0.49733446  1.        ]]]]
    res 1 144.007105662
    [[[[ 0.2503411  0.7496589  1.       ]]]]
    res 2 -41.6704333344
    [[[[ 0.75076519  0.24923481  1.        ]]]]
    res 0 184.883182334
    [[[[ 0.50266554  0.49733446  1.        ]]]]
    res 1 144.007105662
    [[[[ 0.2503411  0.7496589  1.       ]]]]
    res 2 -41.6704333344
    [[[[ 0.75076519  0.24923481  1.        ]]]]
    res 0 184.883179609
    [[[[ 0.50266554  0.49733446  1.        ]]]]
    res 1 144.007101396
    [[[[ 0.2503411  0.7496589  1.       ]]]]
    res 2 -41.6704368582
    [[[[ 0.75076519  0.24923481  1.        ]]]]
    res 0 184.883182322
    [[[[ 0.50266554  0.49733446  1.        ]]]]
    res 1 144.00710512
    [[[[ 0.2503411  0.7496589  1.       ]]]]
    res 2 -41.6704324219
    [[[[ 0.97951885  0.02048115  1.        ]]]]
    res 0 343.440110561
    [[[[ 0.97951885  0.02048115  1.        ]]]]
    res 1 365.440110561
    [[[[ 0.97951885  0.02048115  1.        ]]]]
    res 2 117.440110561
    [[[[ 0.75114931  0.24885069  1.        ]]]]
    res 0 173.293607359
    [[[[ 0.51979132  0.48020868  1.        ]]]]
    res 1 128.658151412
    [[[[ 0.25048244  0.74951756  1.        ]]]]
    res 2 -53.5748557206
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293607258
    [[[[ 0.51979132  0.48020868  1.        ]]]]
    res 1 128.658147451
    [[[[ 0.2502095  0.7497905  1.       ]]]]
    res 2 -53.4299853652
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293610125
    [[[[ 0.51979132  0.48020868  1.        ]]]]
    res 1 128.658151389
    [[[[ 0.2502095  0.7497905  1.       ]]]]
    res 2 -53.42998219
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.293150319
    [[[[ 0.51979121  0.48020879  1.        ]]]]
    res 1 128.657527181
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.5753160141
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293380177
    [[[[ 0.51979127  0.48020873  1.        ]]]]
    res 1 128.657839391
    [[[[ 0.25020945  0.74979055  1.        ]]]]
    res 2 -53.4301866254
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293377192
    [[[[ 0.51979127  0.48020873  1.        ]]]]
    res 1 128.657835432
    [[[[ 0.25020945  0.74979055  1.        ]]]]
    res 2 -53.4301895684
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293380359
    [[[[ 0.51979127  0.48020873  1.        ]]]]
    res 1 128.657839371
    [[[[ 0.25020945  0.74979055  1.        ]]]]
    res 2 -53.4301861988
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293215261
    [[[[ 0.51979126  0.48020874  1.        ]]]]
    res 1 128.657620077
    [[[[ 0.25020944  0.74979056  1.        ]]]]
    res 2 -53.4303469219
    [[[[ 0.75114931  0.24885069  1.        ]]]]
    res 0 173.293207737
    [[[[ 0.51979126  0.48020874  1.        ]]]]
    res 1 128.657616114
    [[[[ 0.25020944  0.74979056  1.        ]]]]
    res 2 -53.4303498086
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.293216731
    [[[[ 0.51979126  0.48020874  1.        ]]]]
    res 1 128.657620053
    [[[[ 0.25020944  0.74979056  1.        ]]]]
    res 2 -53.430346733
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292892084
    [[[[ 0.51979125  0.48020875  1.        ]]]]
    res 1 128.65718636
    [[[[ 0.25020943  0.74979057  1.        ]]]]
    res 2 -53.4306688058
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292889501
    [[[[ 0.51979125  0.48020875  1.        ]]]]
    res 1 128.657182397
    [[[[ 0.25020943  0.74979057  1.        ]]]]
    res 2 -53.4306716302
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292888785
    [[[[ 0.51979125  0.48020875  1.        ]]]]
    res 1 128.657186335
    [[[[ 0.25020943  0.74979057  1.        ]]]]
    res 2 -53.4306682023
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292632301
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656834354
    [[[[ 0.25020938  0.74979062  1.        ]]]]
    res 2 -53.4309053421
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292626218
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656830394
    [[[[ 0.25020938  0.74979062  1.        ]]]]
    res 2 -53.4309085559
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292632371
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656834332
    [[[[ 0.25020938  0.74979062  1.        ]]]]
    res 2 -53.4309057026
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292301617
    [[[[ 0.51979119  0.48020881  1.        ]]]]
    res 1 128.656395839
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.576164315
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.29259799
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656790503
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.5758683264
    CPU times: user 1min 11s, sys: 15 ms, total: 1min 11s
    Wall time: 1min 11s

    :0: FutureWarning: IPython widgets are experimental and may change in the future.

```python
print(lmfit.report_fit(mi.params))
print(lmfit.conf_interval(mi))
```

    [[Variables]]
        FCCALMG0A:   1063.03837 +/- 462.3112 (43.49%) (init= 1000)
        FCCALMG0B:   12.6330418 +/- 118.5284 (938.24%) (init= 10)
    [[Correlations]] (unreported correlations are <  0.100)
        C(FCCALMG0A, FCCALMG0B)      = -0.281
    None
    [[[[ 0.75006344  0.24993656  1.        ]]]]
    res 0 259.382717234
    [[[[ 0.50231047  0.49768953  1.        ]]]]
    res 1 243.821418812
    [[[[ 0.2507218  0.7492782  1.       ]]]]
    res 2 33.1471697466
    [[[[ 0.75006344  0.24993656  1.        ]]]]
    res 0 259.382717234
    [[[[ 0.50231047  0.49768953  1.        ]]]]
    res 1 243.821418812
    [[[[ 0.2507218  0.7492782  1.       ]]]]
    res 2 33.1471697466
    [[[[ 0.75006344  0.24993656  1.        ]]]]
    res 0 259.382717234
    [[[[ 0.50231047  0.49768953  1.        ]]]]
    res 1 243.821418812
    [[[[ 0.2507218  0.7492782  1.       ]]]]
    res 2 33.1471697466
    [[[[ 0.75006344  0.24993656  1.        ]]]]
    res 0 259.382717323
    [[[[ 0.50231047  0.49768953  1.        ]]]]
    res 1 243.821418813
    [[[[ 0.2507218  0.7492782  1.       ]]]]
    res 2 33.1471695615
    [[[[ 0.7500463  0.2499537  1.       ]]]]
    res 0 259.377566012
    [[[[ 0.5000899  0.4999101  1.       ]]]]
    res 1 243.818216826
    [[[[ 0.25003142  0.74996858  1.        ]]]]
    res 2 33.3542233173
    [[[[ 0.75011597  0.24988403  1.        ]]]]
    res 0 259.398499737
    [[[[ 0.50006517  0.49993483  1.        ]]]]
    res 1 243.818214524
    [[[[ 0.2500573  0.7499427  1.       ]]]]
    res 2 33.3464498152
    [[[[ 0.75001502  0.24998498  1.        ]]]]
    res 0 259.368171653
    [[[[ 0.50030247  0.49969753  1.        ]]]]
    res 1 243.818266934
    [[[[ 0.25038605  0.74961395  1.        ]]]]
    res 2 33.2477924227
    [[[[ 0.75001501  0.24998499  1.        ]]]]
    res 0 259.368168262
    [[[[ 0.50030247  0.49969753  1.        ]]]]
    res 1 243.818266973
    [[[[ 0.25038605  0.74961395  1.        ]]]]
    res 2 33.247792424
    [[[[ 0.75001806  0.24998194  1.        ]]]]
    res 0 259.369082365
    [[[[ 0.50030108  0.49969892  1.        ]]]]
    res 1 243.818266427
    [[[[ 0.25035195  0.74964805  1.        ]]]]
    res 2 33.258021761
    [[[[ 0.75001652  0.24998348  1.        ]]]]
    res 0 259.368620413
    [[[[ 0.50030178  0.49969822  1.        ]]]]
    res 1 243.818266786
    [[[[ 0.2503691  0.7496309  1.       ]]]]
    res 2 33.2528759284
    [[[[ 0.75001574  0.24998426  1.        ]]]]
    res 0 259.368388127
    [[[[ 0.50030212  0.49969788  1.        ]]]]
    res 1 243.818266807
    [[[[ 0.2503776  0.7496224  1.       ]]]]
    res 2 33.2503261747
    [[[[ 0.75001536  0.24998464  1.        ]]]]
    res 0 259.368274177
    [[[[ 0.5003023  0.4996977  1.       ]]]]
    res 1 243.818266878
    [[[[ 0.25038184  0.74961816  1.        ]]]]
    res 2 33.249057196
    [[[[ 0.75001518  0.24998482  1.        ]]]]
    res 0 259.368219313
    [[[[ 0.50030238  0.49969762  1.        ]]]]
    res 1 243.818266901
    [[[[ 0.25038395  0.74961605  1.        ]]]]
    res 2 33.2484242367
    [[[[ 0.75001512  0.24998488  1.        ]]]]
    res 0 259.368200482
    [[[[ 0.50030242  0.49969758  1.        ]]]]
    res 1 243.818266916
    [[[[ 0.250385  0.749615  1.      ]]]]
    res 2 33.2481082145
    [[[[ 0.75001507  0.24998493  1.        ]]]]
    res 0 259.368186471
    [[[[ 0.50030245  0.49969755  1.        ]]]]
    res 1 243.818266959
    [[[[ 0.25038553  0.74961447  1.        ]]]]
    res 2 33.2479502766
    [[[[ 0.75001502  0.24998498  1.        ]]]]
    res 0 259.368170955
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266972
    [[[[ 0.25038579  0.74961421  1.        ]]]]
    res 2 33.2478713234
    [[[[ 0.75001501  0.24998499  1.        ]]]]
    res 0 259.36816899
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266939
    [[[[ 0.25038592  0.74961408  1.        ]]]]
    res 2 33.2478319283
    [[[[ 0.75001486  0.24998513  1.        ]]]]
    res 0 259.368125684
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.81826693
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.247812208
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.368174113
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266933
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478122316
    [[[[ 0.75001498  0.24998502  1.        ]]]]
    res 0 259.368159863
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266931
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478115114
    [[[[ 0.75001501  0.24998499  1.        ]]]]
    res 0 259.368166666
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266948
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478118416
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.368174281
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.81826693
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478120589
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.368174047
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266938
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478120986
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.36817404
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266967
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478121473
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.368173902
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.81826693
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478121732
    [[[[ 0.75001502  0.24998498  1.        ]]]]
    res 0 259.3681712
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.818266973
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.2478120666
    [[[[ 0.75001503  0.24998497  1.        ]]]]
    res 0 259.368174061
    [[[[ 0.50030246  0.49969754  1.        ]]]]
    res 1 243.81826693
    [[[[ 0.25038599  0.74961401  1.        ]]]]
    res 2 33.24781206
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049318
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029853
    [[[[ 0.25016039  0.74983961  1.        ]]]]
    res 2 120.035916023
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049318
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029853
    [[[[ 0.25016039  0.74983961  1.        ]]]]
    res 2 120.035916023
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049318
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029853
    [[[[ 0.25016039  0.74983961  1.        ]]]]
    res 2 120.035916023
    [[[[ 0.75000043  0.24999956  1.        ]]]]
    res 0 346.047042743
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016039  0.74983961  1.        ]]]]
    res 2 120.035916029
    [[[[ 0.7502678  0.2497322  1.       ]]]]
    res 0 346.065556531
    [[[[ 0.50028283  0.49971717  1.        ]]]]
    res 1 359.396027708
    [[[[ 0.25030734  0.74969266  1.        ]]]]
    res 2 120.025755
    [[[[ 0.75023717  0.24976283  1.        ]]]]
    res 0 346.063434557
    [[[[ 0.50029758  0.49970242  1.        ]]]]
    res 1 359.396029045
    [[[[ 0.25026695  0.74973305  1.        ]]]]
    res 2 120.02854707
    [[[[ 0.75001247  0.24998753  1.        ]]]]
    res 0 346.04787537
    [[[[ 0.50030363  0.49969637  1.        ]]]]
    res 1 359.396029397
    [[[[ 0.25002669  0.74997331  1.        ]]]]
    res 2 120.045165744
    [[[[ 0.75000616  0.24999384  1.        ]]]]
    res 0 346.047438462
    [[[[ 0.50030639  0.49969361  1.        ]]]]
    res 1 359.39602963
    [[[[ 0.25009513  0.74990487  1.        ]]]]
    res 2 120.040429668
    [[[[ 0.75000302  0.24999696  1.        ]]]]
    res 0 346.047223144
    [[[[ 0.50030771  0.49969229  1.        ]]]]
    res 1 359.396029742
    [[[[ 0.25012815  0.74987185  1.        ]]]]
    res 2 120.038145984
    [[[[ 0.75000177  0.24999822  1.        ]]]]
    res 0 346.047135951
    [[[[ 0.50030836  0.49969164  1.        ]]]]
    res 1 359.396029797
    [[[[ 0.25014436  0.74985564  1.        ]]]]
    res 2 120.037024376
    [[[[ 0.75000125  0.24999875  1.        ]]]]
    res 0 346.047098684
    [[[[ 0.50030868  0.49969132  1.        ]]]]
    res 1 359.396029825
    [[[[ 0.2501524  0.7498476  1.       ]]]]
    res 2 120.036468551
    [[[[ 0.75000089  0.24999911  1.        ]]]]
    res 0 346.047073997
    [[[[ 0.50030884  0.49969116  1.        ]]]]
    res 1 359.396029838
    [[[[ 0.2501564  0.7498436  1.       ]]]]
    res 2 120.03619187
    [[[[ 0.75000071  0.24999929  1.        ]]]]
    res 0 346.04706161
    [[[[ 0.50030892  0.49969108  1.        ]]]]
    res 1 359.396029845
    [[[[ 0.25015839  0.74984161  1.        ]]]]
    res 2 120.036053841
    [[[[ 0.75000054  0.24999945  1.        ]]]]
    res 0 346.047050395
    [[[[ 0.50030896  0.49969104  1.        ]]]]
    res 1 359.396029848
    [[[[ 0.25015939  0.74984061  1.        ]]]]
    res 2 120.035984902
    [[[[ 0.75000058  0.24999942  1.        ]]]]
    res 0 346.04705239
    [[[[ 0.50030898  0.49969102  1.        ]]]]
    res 1 359.39602985
    [[[[ 0.25015989  0.74984011  1.        ]]]]
    res 2 120.035950459
    [[[[ 0.75000052  0.24999948  1.        ]]]]
    res 0 346.047048319
    [[[[ 0.50030899  0.49969101  1.        ]]]]
    res 1 359.396029851
    [[[[ 0.25016014  0.74983986  1.        ]]]]
    res 2 120.035933238
    [[[[ 0.75000051  0.24999949  1.        ]]]]
    res 0 346.047047666
    [[[[ 0.50030899  0.49969101  1.        ]]]]
    res 1 359.396029852
    [[[[ 0.25016026  0.74983974  1.        ]]]]
    res 2 120.035924635
    [[[[ 0.75000046  0.24999954  1.        ]]]]
    res 0 346.047044739
    [[[[ 0.50030899  0.49969101  1.        ]]]]
    res 1 359.396029852
    [[[[ 0.25016032  0.74983968  1.        ]]]]
    res 2 120.035920324
    [[[[ 0.7500005  0.2499995  1.       ]]]]
    res 0 346.04704742
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016036  0.74983964  1.        ]]]]
    res 2 120.03591817
    [[[[ 0.75000048  0.24999951  1.        ]]]]
    res 0 346.047046238
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016037  0.74983963  1.        ]]]]
    res 2 120.035917101
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049372
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016037  0.74983963  1.        ]]]]
    res 2 120.035917103
    [[[[ 0.75000048  0.24999951  1.        ]]]]
    res 0 346.047046105
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029853
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916558
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049272
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916562
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049305
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916291
    [[[[ 0.75000049  0.24999951  1.        ]]]]
    res 0 346.047046458
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916429
    [[[[ 0.75000044  0.24999955  1.        ]]]]
    res 0 346.047043603
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916494
    [[[[ 0.7500005  0.2499995  1.       ]]]]
    res 0 346.047046894
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916497
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049307
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916461
    [[[[ 0.75000053  0.24999947  1.        ]]]]
    res 0 346.047049378
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916474
    [[[[ 0.75000051  0.24999948  1.        ]]]]
    res 0 346.047048156
    [[[[ 0.500309  0.499691  1.      ]]]]
    res 1 359.396029852
    [[[[ 0.25016038  0.74983962  1.        ]]]]
    res 2 120.035916491
    [[[[ 0.75019918  0.24980082  1.        ]]]]
    res 0 432.698096874
    [[[[ 0.5003147  0.4996853  1.       ]]]]
    res 1 474.973789222
    [[[[ 0.2501112  0.7498888  1.       ]]]]
    res 2 206.748370594
    [[[[ 0.75019918  0.24980082  1.        ]]]]
    res 0 432.698096874
    [[[[ 0.5003147  0.4996853  1.       ]]]]
    res 1 474.973789222
    [[[[ 0.2501112  0.7498888  1.       ]]]]
    res 2 206.748370594
    [[[[ 0.75019918  0.24980082  1.        ]]]]
    res 0 432.698096874
    [[[[ 0.5003147  0.4996853  1.       ]]]]
    res 1 474.973789222
    [[[[ 0.2501112  0.7498888  1.       ]]]]
    res 2 206.748370594
    [[[[ 0.75019918  0.24980082  1.        ]]]]
    res 0 432.698096841
    [[[[ 0.5003147  0.4996853  1.       ]]]]
    res 1 474.973789222
    [[[[ 0.2501112  0.7498888  1.       ]]]]
    res 2 206.748370549
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.29259799
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656790503
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.5758683264
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.29259799
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656790503
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.5758683264
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.29259799
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.656790503
    [[[[ 0.25048243  0.74951757  1.        ]]]]
    res 2 -53.5758683264
    [[[[ 0.75114932  0.24885068  1.        ]]]]
    res 0 173.292595799
    [[[[ 0.5197912  0.4802088  1.       ]]]]
    res 1 128.65679048
    [[[[ 0.25020938  0.74979062  1.        ]]]]
    res 2 -53.4309374201
    [[[[ 0.75114934  0.24885066  1.        ]]]]
    res 0 173.292606586
    [[[[ 0.519791  0.480209  1.      ]]]]
    res 1 128.656781985
    [[[[ 0.25048241  0.74951759  1.        ]]]]
    res 2 -53.5758581938
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292603264
    [[[[ 0.5197911  0.4802089  1.       ]]]]
    res 1 128.656786243
    [[[[ 0.25020928  0.74979072  1.        ]]]]
    res 2 -53.4308851083
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292603036
    [[[[ 0.5197911  0.4802089  1.       ]]]]
    res 1 128.656786221
    [[[[ 0.25020928  0.74979072  1.        ]]]]
    res 2 -53.430884384
    [[[[ 0.75114934  0.24885066  1.        ]]]]
    res 0 173.2926049
    [[[[ 0.51979105  0.48020895  1.        ]]]]
    res 1 128.656784115
    [[[[ 0.25020923  0.74979077  1.        ]]]]
    res 2 -53.4308594215
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292601738
    [[[[ 0.51979105  0.48020895  1.        ]]]]
    res 1 128.656784092
    [[[[ 0.25048242  0.74951758  1.        ]]]]
    res 2 -53.5758604091
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292600241
    [[[[ 0.51979107  0.48020893  1.        ]]]]
    res 1 128.656785178
    [[[[ 0.25020926  0.74979074  1.        ]]]]
    res 2 -53.4308711788
    [[[[ 0.75114933  0.24885067  1.        ]]]]
    res 0 173.292602418
    [[[[ 0.51979106  0.48020894  1.        ]]]]
    res 1 128.656784646
    [[[[ 0.25020925  0.74979075  1.        ]]]]
    res 2 -53.4308658454
    [[[[ 0.75114934  0.24885066  1.        ]]]]
    res 0 173.292603604
    [[[[ 0.51979105  0.48020895  1.        ]]]]
    res 1 128.65678438
    [[[[ 0.25048242  0.74951758  1.        ]]]]
    res 2 -53.5758606883
    [[[[ 0.75054312  0.24945688  1.        ]]]]
    res 0 519.199985745
    [[[[ 0.50066394  0.49933606  1.        ]]]]
    res 1 590.551279328
    [[[[ 0.25013059  0.74986941  1.        ]]]]
    res 2 293.465043308
    [[[[ 0.75054312  0.24945688  1.        ]]]]
    res 0 519.199985745
    [[[[ 0.50066394  0.49933606  1.        ]]]]
    res 1 590.551279328
    [[[[ 0.25013059  0.74986941  1.        ]]]]
    res 2 293.465043308
    [[[[ 0.75054312  0.24945688  1.        ]]]]
    res 0 519.199985745
    [[[[ 0.50066394  0.49933606  1.        ]]]]
    res 1 590.551279328
    [[[[ 0.25013059  0.74986941  1.        ]]]]
    res 2 293.465043308
    [[[[ 0.75054312  0.24945688  1.        ]]]]
    res 0 519.199985847
    [[[[ 0.50066391  0.49933609  1.        ]]]]
    res 1 590.551279425
    [[[[ 0.25013059  0.74986941  1.        ]]]]
    res 2 293.465043232
    [[[[ 0.75000036  0.24999964  1.        ]]]]
    res 0 519.413578714
    [[[[ 0.50000677  0.49999323  1.        ]]]]
    res 1 590.551626001
    [[[[ 0.2500076  0.7499924  1.       ]]]]
    res 2 293.41670665
    [[[[ 0.75001059  0.24998941  1.        ]]]]
    res 0 519.409555874
    [[[[ 0.50000366  0.49999634  1.        ]]]]
    res 1 590.551625995
    [[[[ 0.25000937  0.74999063  1.        ]]]]
    res 2 293.41740156
    [[[[ 0.75000359  0.24999642  1.        ]]]]
    res 0 519.412312623
    [[[[ 0.50003304  0.49996696  1.        ]]]]
    res 1 590.55162512
    [[[[ 0.25004795  0.74995205  1.        ]]]]
    res 2 293.432567763
    [[[[ 0.75003875  0.24996125  1.        ]]]]
    res 0 519.398484017
    [[[[ 0.50009241  0.49990759  1.        ]]]]
    res 1 590.551619254
    [[[[ 0.25001458  0.74998542  1.        ]]]]
    res 2 293.419449888
    [[[[ 0.7500971  0.2499029  1.       ]]]]
    res 0 519.375540057
    [[[[ 0.50007216  0.49992784  1.        ]]]]
    res 1 590.551621868
    [[[[ 0.25006802  0.74993198  1.        ]]]]
    res 2 293.440456393
    [[[[ 0.75018135  0.24981865  1.        ]]]]
    res 0 519.342402228
    [[[[ 0.5003223  0.4996777  1.       ]]]]
    res 1 590.551544292
    [[[[ 0.25011524  0.74988476  1.        ]]]]
    res 2 293.459010363
    [[[[ 0.75028138  0.24971862  1.        ]]]]
    res 0 519.303047464
    [[[[ 0.500276  0.499724  1.      ]]]]
    res 1 590.551566074
    [[[[ 0.2501528  0.7498472  1.       ]]]]
    res 2 293.473765705
    [[[[ 0.75037555  0.24962445  1.        ]]]]
    res 0 519.265976783
    [[[[ 0.50079105  0.49920895  1.        ]]]]
    res 1 590.551133986
    [[[[ 0.2502222  0.7497778  1.       ]]]]
    res 2 293.5010301
    [[[[ 0.7500244  0.2499756  1.       ]]]]
    res 0 519.404125817
    [[[[ 0.50074346  0.49925654  1.        ]]]]
    res 1 590.551191399
    [[[[ 0.25014931  0.74985069  1.        ]]]]
    res 2 293.472394406
    [[[[ 0.75007264  0.24992736  1.        ]]]]
    res 0 519.385159005
    [[[[ 0.50070633  0.49929367  1.        ]]]]
    res 1 590.551233718
    [[[[ 0.25071739  0.74928261  1.        ]]]]
    res 2 293.695324274
    [[[[ 0.75052378  0.24947622  1.        ]]]]
    res 0 519.207605699
    [[[[ 0.50068156  0.49931844  1.        ]]]]
    res 1 590.551260746
    [[[[ 0.25036595  0.74963405  1.        ]]]]
    res 2 293.557471971
    [[[[ 0.75053461  0.24946539  1.        ]]]]
    res 0 519.203337022
    [[[[ 0.50067178  0.49932822  1.        ]]]]
    res 1 590.551271152
    [[[[ 0.25023419  0.74976581  1.        ]]]]
    res 2 293.5057389
    [[[[ 0.75053943  0.24946057  1.        ]]]]
    res 0 519.20143989
    [[[[ 0.50066735  0.49933265  1.        ]]]]
    res 1 590.551275822
    [[[[ 0.25017556  0.74982444  1.        ]]]]
    res 2 293.482709863
    [[[[ 0.75054153  0.24945847  1.        ]]]]
    res 0 519.200612934
    [[[[ 0.5006654  0.4993346  1.       ]]]]
    res 1 590.551277851
    [[[[ 0.25014999  0.74985001  1.        ]]]]
    res 2 293.472664568
    [[[[ 0.75054243  0.24945757  1.        ]]]]
    res 0 519.200255573
    [[[[ 0.50066455  0.49933545  1.        ]]]]
    res 1 590.551278757
    [[[[ 0.25013894  0.74986106  1.        ]]]]
    res 2 293.468322226
    [[[[ 0.75054282  0.24945718  1.        ]]]]
    res 0 519.200101697
    [[[[ 0.50066418  0.49933582  1.        ]]]]
    res 1 590.551279133
    [[[[ 0.25013418  0.74986582  1.        ]]]]
    res 2 293.466452371
    [[[[ 0.75054299  0.24945701  1.        ]]]]
    res 0 519.200035656
    [[[[ 0.50066404  0.49933596  1.        ]]]]
    res 1 590.551279258
    [[[[ 0.25013214  0.74986786  1.        ]]]]
    res 2 293.465648454
    [[[[ 0.75054306  0.24945694  1.        ]]]]
    res 0 519.200007149
    [[[[ 0.50066397  0.49933603  1.        ]]]]
    res 1 590.551279349
    [[[[ 0.25013126  0.74986874  1.        ]]]]
    res 2 293.465302916
    [[[[ 0.7505431  0.2494569  1.       ]]]]
    res 0 519.199994998
    [[[[ 0.50066393  0.49933607  1.        ]]]]
    res 1 590.551279403
    [[[[ 0.25013088  0.74986912  1.        ]]]]
    res 2 293.465154976
    [[[[ 0.75054311  0.24945689  1.        ]]]]
    res 0 519.19998977
    [[[[ 0.50066392  0.49933608  1.        ]]]]
    res 1 590.551279388
    [[[[ 0.25013072  0.74986928  1.        ]]]]
    res 2 293.465091059
    [[[[ 0.75054311  0.24945689  1.        ]]]]
    res 0 519.199987452
    [[[[ 0.50066391  0.49933609  1.        ]]]]
    res 1 590.551279415
    [[[[ 0.25013065  0.74986935  1.        ]]]]
    res 2 293.465063798
    [[[[ 0.75054312  0.24945688  1.        ]]]]
    res 0 519.199986435
    [[[[ 0.50066391  0.49933609  1.        ]]]]
    res 1 590.551279424
    [[[[ 0.25013062  0.74986938  1.        ]]]]
    res 2 293.465051968
    [[[[ 0.75060457  0.24939543  1.        ]]]]
    res 0 454.345012627
    [[[[ 0.50060088  0.49939912  1.        ]]]]
    res 1 503.970699547
    [[[[ 0.25013122  0.74986878  1.        ]]]]
    res 2 228.506996731
    [[[[ 0.75060457  0.24939543  1.        ]]]]
    res 0 454.345012627
    [[[[ 0.50060088  0.49939912  1.        ]]]]
    res 1 503.970699547
    [[[[ 0.25013122  0.74986878  1.        ]]]]
    res 2 228.506996731
    [[[[ 0.75060457  0.24939543  1.        ]]]]
    res 0 454.345012627
    [[[[ 0.50060088  0.49939912  1.        ]]]]
    res 1 503.970699547
    [[[[ 0.25013122  0.74986878  1.        ]]]]
    res 2 228.506996731
    [[[[ 0.75060457  0.24939543  1.        ]]]]
    res 0 454.345012606
    [[[[ 0.50060089  0.49939911  1.        ]]]]
    res 1 503.970699526
    [[[[ 0.25013122  0.74986878  1.        ]]]]
    res 2 228.506996659
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 0.75156655  0.24843345  1.        ]]]]
    res 0 87.1954660014
    [[[[ 0.71200058  0.28799942  1.        ]]]]
    res 1 81.2182882629
    [[[[ 0.25093884  0.74906116  1.        ]]]]
    res 2 -140.717736416
    [[[[ 0.75156655  0.24843345  1.        ]]]]
    res 0 87.1954660014
    [[[[ 0.71200058  0.28799942  1.        ]]]]
    res 1 81.2182882629
    [[[[ 0.25093884  0.74906116  1.        ]]]]
    res 2 -140.717736416
    [[[[ 0.75156655  0.24843345  1.        ]]]]
    res 0 87.1954660014
    [[[[ 0.71200058  0.28799942  1.        ]]]]
    res 1 81.2182882629
    [[[[ 0.25093884  0.74906116  1.        ]]]]
    res 2 -140.717736416
    [[[[ 0.75156655  0.24843345  1.        ]]]]
    res 0 87.1954669888
    [[[[ 0.71200059  0.28799941  1.        ]]]]
    res 1 81.2182984275
    [[[[ 0.25093884  0.74906116  1.        ]]]]
    res 2 -140.717735639
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927714319
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130995  0.74869005  1.        ]]]]
    res 2 -140.999497654
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927715905
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25066994  0.74933006  1.        ]]]]
    res 2 -140.513308305
    [[[[ 0.75117184  0.24882816  1.        ]]]]
    res 0 86.8927785984
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130981  0.74869019  1.        ]]]]
    res 2 -140.999387792
    [[[[ 0.75117184  0.24882816  1.        ]]]]
    res 0 86.8927759382
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130987  0.74869013  1.        ]]]]
    res 2 -140.999436673
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927705987
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130991  0.74869009  1.        ]]]]
    res 2 -140.999467236
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.892772294
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130993  0.74869007  1.        ]]]]
    res 2 -140.999482404
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927714018
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130994  0.74869006  1.        ]]]]
    res 2 -140.999490097
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927717381
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25130995  0.74869005  1.        ]]]]
    res 2 -140.999493999
    [[[[ 0.75117183  0.24882817  1.        ]]]]
    res 0 86.8927711233
    [[[[ 0.53939409  0.46060591  1.        ]]]]
    res 1 15.0297840742
    [[[[ 0.25066994  0.74933006  1.        ]]]]

    /home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/lmfit/confidence.py:296: UserWarning: Warning, rel_change=0.0 < 0.01  at iteration 4 and prob(FCCALMG0A=-786.2065038504686) = 0.7406549412820442 < max(sigmas).
      warn(errmsg)
    /home/rotis/.virtualenvs/calphad/lib/python3.4/site-packages/lmfit/confidence.py:296: UserWarning: Warning, rel_change=0.0 < 0.01  at iteration 1 and prob(FCCALMG0A=1525.3495894180069) = 0.0 < max(sigmas).
      warn(errmsg)

    res 2 -140.513310307
    [[[[ 0.75079534  0.24920466  1.        ]]]]
    res 0 173.103715305
    [[[[ 0.50260656  0.49739344  1.        ]]]]
    res 1 128.247629785
    [[[[ 0.25069021  0.74930979  1.        ]]]]
    res 2 -53.6860486873
    [[[[ 0.75079534  0.24920466  1.        ]]]]
    res 0 173.103715305
    [[[[ 0.50260656  0.49739344  1.        ]]]]
    res 1 128.247629785
    [[[[ 0.25069021  0.74930979  1.        ]]]]
    res 2 -53.6860486873
    [[[[ 0.75079534  0.24920466  1.        ]]]]
    res 0 173.103715305
    [[[[ 0.50260656  0.49739344  1.        ]]]]
    res 1 128.247629785
    [[[[ 0.25069021  0.74930979  1.        ]]]]
    res 2 -53.6860486873
    [[[[ 0.75079534  0.24920466  1.        ]]]]
    res 0 173.103712679
    [[[[ 0.50260656  0.49739344  1.        ]]]]
    res 1 128.247625824
    [[[[ 0.25069021  0.74930979  1.        ]]]]
    res 2 -53.6860515806
    [[[[ 0.75011848  0.24988152  1.        ]]]]
    res 0 95.3219428853
    [[[[ 0.5020807  0.4979193  1.       ]]]]
    res 1 24.9856910132
    [[[[ 0.25144319  0.74855681  1.        ]]]]
    res 2 -131.82758503
    [[[[ 0.75011849  0.24988151  1.        ]]]]
    res 0 95.3219389263
    [[[[ 0.5020807  0.4979193  1.       ]]]]
    res 1 24.9856855146
    [[[[ 0.25144319  0.74855681  1.        ]]]]
    res 2 -131.82758969
    [[[[ 0.75010327  0.24989673  1.        ]]]]
    res 0 101.377849012
    [[[[ 0.50215217  0.49784783  1.        ]]]]
    res 1 33.0777333855
    [[[[ 0.25019006  0.74980994  1.        ]]]]
    res 2 -124.833861719
    [[[[ 0.75010328  0.24989672  1.        ]]]]
    res 0 101.377846702
    [[[[ 0.50215217  0.49784783  1.        ]]]]
    res 1 33.077728007
    [[[[ 0.25019006  0.74980994  1.        ]]]]
    res 2 -124.833866408
    [[[[ 0.75007355  0.24992645  1.        ]]]]
    res 0 113.772586393
    [[[[ 0.50227377  0.49772623  1.        ]]]]
    res 1 49.6363516594
    [[[[ 0.25058714  0.74941286  1.        ]]]]
    res 2 -112.681992603
    [[[[ 0.75009612  0.24990388  1.        ]]]]
    res 0 104.291654012
    [[[[ 0.50218347  0.49781653  1.        ]]]]
    res 1 36.9708126475
    [[[[ 0.25028572  0.74971428  1.        ]]]]
    res 2 -121.980903525
    [[[[ 0.75010112  0.24989888  1.        ]]]]
    res 0 102.250512815
    [[[[ 0.50216174  0.49783826  1.        ]]]]
    res 1 34.2437109309
    [[[[ 0.25021886  0.74978114  1.        ]]]]
    res 2 -123.979668714
    [[[[ 0.75010259  0.24989741  1.        ]]]]
    res 0 101.653751622
    [[[[ 0.50215522  0.49784478  1.        ]]]]
    res 1 33.4463717385
    [[[[ 0.25019918  0.74980082  1.        ]]]]
    res 2 -124.563820681
    [[[[ 0.75010306  0.24989694  1.        ]]]]
    res 0 101.466528389
    [[[[ 0.50215315  0.49784685  1.        ]]]]
    res 1 33.1962106997
    [[[[ 0.25019299  0.74980701  1.        ]]]]
    res 2 -124.747073794
    [[[[ 0.75010322  0.24989678  1.        ]]]]
    res 0 101.406509437
    [[[[ 0.50215249  0.49784751  1.        ]]]]
    res 1 33.1160062703
    [[[[ 0.25019101  0.74980899  1.        ]]]]
    res 2 -124.80582447
    [[[[ 0.75010325  0.24989675  1.        ]]]]
    res 0 101.387110797
    [[[[ 0.50215228  0.49784772  1.        ]]]]
    res 1 33.0901101266
    [[[[ 0.25019037  0.74980963  1.        ]]]]
    res 2 -124.824796346
    [[[[ 0.75010327  0.24989673  1.        ]]]]
    res 0 101.380850191
    [[[[ 0.50215221  0.49784779  1.        ]]]]
    res 1 33.0817411454
    [[[[ 0.25019016  0.74980984  1.        ]]]]
    res 2 -124.830923076
    [[[[ 0.75010327  0.24989673  1.        ]]]]
    res 0 101.378823086
    [[[[ 0.50215218  0.49784782  1.        ]]]]
    res 1 33.0790325694
    [[[[ 0.25019009  0.74980991  1.        ]]]]
    res 2 -124.832906409
    [[[[ 0.75010327  0.24989673  1.        ]]]]
    res 0 101.378164566
    [[[[ 0.50215218  0.49784782  1.        ]]]]
    res 1 33.0781559778
    [[[[ 0.25019007  0.74980993  1.        ]]]]
    res 2 -124.833551304
    [[[[ 0.75010328  0.24989672  1.        ]]]]
    res 0 101.377953721
    [[[[ 0.50215218  0.49784782  1.        ]]]]
    res 1 33.0778714425
    [[[[ 0.25019007  0.74980993  1.        ]]]]
    res 2 -124.833760903
    [[[[ 0.75010328  0.24989672  1.        ]]]]
    res 0 101.377889744
    [[[[ 0.50215217  0.49784783  1.        ]]]]
    res 1 33.0777769616
    [[[[ 0.25019006  0.74980994  1.        ]]]]
    res 2 -124.833827274
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 0 187.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 1 209.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 2 -38.4752968872
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 0 187.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 1 209.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 2 -38.4752968872
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 0 187.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 1 209.524703113
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 2 -38.4752968872
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 0 187.524702002
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 1 209.524702002
    [[[[ 0.77652147  0.22347853  1.        ]]]]
    res 2 -38.4752979984
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 263.839944299
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 285.839944299
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 37.8399442986
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 0 166.899061535
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 1 188.899061535
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 2 -59.1009384651
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 0 166.899061045
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 1 188.899061045
    [[[[ 0.8399266  0.1600734  1.       ]]]]
    res 2 -59.1009389545
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 0 162.897609712
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 1 184.897609712
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 2 -63.1023902885
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 0 162.897609799
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 1 184.897609799
    [[[[ 0.87752726  0.12247274  1.        ]]]]
    res 2 -63.1023902012
    [[[[ 0.83823758  0.16176242  1.        ]]]]
    res 0 169.981101825
    [[[[ 0.83823758  0.16176242  1.        ]]]]
    res 1 191.981101825
    [[[[ 0.83823758  0.16176242  1.        ]]]]
    res 2 -56.0188981748
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 0 162.506450958
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 1 184.506450958
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 2 -63.4935490416
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 0 162.50644966
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 1 184.50644966
    [[[[ 0.87377555  0.12622445  1.        ]]]]
    res 2 -63.4935503403
    [[[[ 0.88092689  0.11907311  1.        ]]]]
    res 0 163.07064978
    [[[[ 0.88092689  0.11907311  1.        ]]]]
    res 1 185.07064978
    [[[[ 0.88092689  0.11907311  1.        ]]]]
    res 2 -62.9293502205
    [[[[ 0.8771171  0.1228829  1.       ]]]]
    res 0 162.8817562
    [[[[ 0.8771171  0.1228829  1.       ]]]]
    res 1 184.8817562
    [[[[ 0.8771171  0.1228829  1.       ]]]]
    res 2 -63.1182437996
    [[[[ 0.87530013  0.12469987  1.        ]]]]
    res 0 162.82486399
    [[[[ 0.87530013  0.12469987  1.        ]]]]
    res 1 184.82486399
    [[[[ 0.87530013  0.12469987  1.        ]]]]
    res 2 -63.1751360105
    [[[[ 0.87445063  0.12554937  1.        ]]]]
    res 0 162.805715188
    [[[[ 0.87445063  0.12554937  1.        ]]]]
    res 1 184.805715188
    [[[[ 0.87445063  0.12554937  1.        ]]]]
    res 2 -63.1942848116
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 0 162.359384644
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 1 184.359384644
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 2 -63.6406153557
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 0 162.359379239
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 1 184.359379239
    [[[[ 0.8737839  0.1262161  1.       ]]]]
    res 2 -63.6406207612
    [[[[ 0.87417607  0.12582393  1.        ]]]]
    res 0 162.800449345
    [[[[ 0.87417607  0.12582393  1.        ]]]]
    res 1 184.800449345
    [[[[ 0.87417607  0.12582393  1.        ]]]]
    res 2 -63.1995506553
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 0 162.316413807
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 1 184.316413807
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 2 -63.6835861933
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 0 162.31640312
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 1 184.31640312
    [[[[ 0.87376656  0.12623344  1.        ]]]]
    res 2 -63.6835968799
    [[[[ 0.87411931  0.12588069  1.        ]]]]
    res 0 162.799455681
    [[[[ 0.87411931  0.12588069  1.        ]]]]
    res 1 184.799455681
    [[[[ 0.87411931  0.12588069  1.        ]]]]
    res 2 -63.2005443191
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 0 162.309656644
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 1 184.309656644
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 2 -63.6903433558
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 0 162.309644483
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 1 184.309644483
    [[[[ 0.87376311  0.12623689  1.        ]]]]
    res 2 -63.6903555168
    [[[[ 0.87375507  0.12624493  1.        ]]]]
    res 0 162.294968872
    [[[[ 0.87375507  0.12624493  1.        ]]]]
    res 1 184.294968872
    [[[[ 0.87375507  0.12624493  1.        ]]]]
    res 2 -63.7050311278
    [[[[ 0.87375506  0.12624494  1.        ]]]]
    res 0 162.294952326
    [[[[ 0.87375506  0.12624494  1.        ]]]]
    res 1 184.294952326
    [[[[ 0.87375506  0.12624494  1.        ]]]]
    res 2 -63.7050476743
    [[[[ 0.87373008  0.12626992  1.        ]]]]
    res 0 162.254657996
    [[[[ 0.87373008  0.12626992  1.        ]]]]
    res 1 184.254657996
    [[[[ 0.87373008  0.12626992  1.        ]]]]
    res 2 -63.7453420039
    [[[[ 0.87373004  0.12626996  1.        ]]]]
    res 0 162.254608476
    [[[[ 0.87373004  0.12626996  1.        ]]]]
    res 1 184.254608476
    [[[[ 0.87373004  0.12626996  1.        ]]]]
    res 2 -63.7453915242
    [[[[ 0.87411546  0.12588454  1.        ]]]]
    res 0 162.799386841
    [[[[ 0.87411546  0.12588454  1.        ]]]]
    res 1 184.799386841
    [[[[ 0.87411546  0.12588454  1.        ]]]]
    res 2 -63.2006131588
    [[[[ 0.87372639  0.12627361  1.        ]]]]
    res 0 162.249101294
    [[[[ 0.87372639  0.12627361  1.        ]]]]
    res 1 184.249101294
    [[[[ 0.87372639  0.12627361  1.        ]]]]
    res 2 -63.7508987058
    [[[[ 0.87372635  0.12627365  1.        ]]]]
    res 0 162.249041463
    [[[[ 0.87372635  0.12627365  1.        ]]]]
    res 1 184.249041463
    [[[[ 0.87372635  0.12627365  1.        ]]]]
    res 2 -63.7509585371
    [[[[ 0.87371785  0.12628215  1.        ]]]]
    res 0 162.236439156
    [[[[ 0.87371785  0.12628215  1.        ]]]]
    res 1 184.236439156
    [[[[ 0.87371785  0.12628215  1.        ]]]]
    res 2 -63.7635608443
    [[[[ 0.87371779  0.12628221  1.        ]]]]
    res 0 162.236342807
    [[[[ 0.87371779  0.12628221  1.        ]]]]
    res 1 184.236342807
    [[[[ 0.87371779  0.12628221  1.        ]]]]
    res 2 -63.7636571929
    [[[[ 0.87411425  0.12588575  1.        ]]]]
    res 0 162.799365428
    [[[[ 0.87411425  0.12588575  1.        ]]]]
    res 1 184.799365428
    [[[[ 0.87411425  0.12588575  1.        ]]]]
    res 2 -63.2006345722
    [[[[ 0.87371641  0.12628359  1.        ]]]]
    res 0 162.234326432
    [[[[ 0.87371641  0.12628359  1.        ]]]]
    res 1 184.234326432
    [[[[ 0.87371641  0.12628359  1.        ]]]]
    res 2 -63.7656735682
    [[[[ 0.87371634  0.12628366  1.        ]]]]
    res 0 162.234221399
    [[[[ 0.87371634  0.12628366  1.        ]]]]
    res 1 184.234221399
    [[[[ 0.87371634  0.12628366  1.        ]]]]
    res 2 -63.7657786007
    [[[[ 0.87371337  0.12628663  1.        ]]]]
    res 0 162.229889592
    [[[[ 0.87371337  0.12628663  1.        ]]]]
    res 1 184.229889592
    [[[[ 0.87371337  0.12628663  1.        ]]]]
    res 2 -63.7701104081
    [[[[ 0.87371329  0.12628671  1.        ]]]]
    res 0 162.229762783
    [[[[ 0.87371329  0.12628671  1.        ]]]]
    res 1 184.229762783
    [[[[ 0.87371329  0.12628671  1.        ]]]]
    res 2 -63.7702372167
    [[[[ 0.87370643  0.12629357  1.        ]]]]
    res 0 162.219821713
    [[[[ 0.87370643  0.12629357  1.        ]]]]
    res 1 184.219821713
    [[[[ 0.87370643  0.12629357  1.        ]]]]
    res 2 -63.7801782872
    [[[[ 0.87370629  0.12629371  1.        ]]]]
    res 0 162.219619503
    [[[[ 0.87370629  0.12629371  1.        ]]]]
    res 1 184.219619503
    [[[[ 0.87370629  0.12629371  1.        ]]]]
    res 2 -63.7803804967
    [[[[ 0.87367579  0.12632421  1.        ]]]]
    res 0 162.176034677
    [[[[ 0.87367579  0.12632421  1.        ]]]]
    res 1 184.176034677
    [[[[ 0.87367579  0.12632421  1.        ]]]]
    res 2 -63.8239653231
    [[[[ 0.87367261  0.12632739  1.        ]]]]
    res 0 162.171520478
    [[[[ 0.87367261  0.12632739  1.        ]]]]
    res 1 184.171520478
    [[[[ 0.87367261  0.12632739  1.        ]]]]
    res 2 -63.8284795215
    [[[[ 0.87411426  0.12588574  1.        ]]]]
    res 0 162.79936545
    [[[[ 0.87411426  0.12588574  1.        ]]]]
    res 1 184.79936545
    [[[[ 0.87411426  0.12588574  1.        ]]]]
    res 2 -63.2006345495
    [[[[ 0.87367365  0.12632635  1.        ]]]]
    res 0 162.172993263
    [[[[ 0.87367365  0.12632635  1.        ]]]]
    res 1 184.172993263
    [[[[ 0.87367365  0.12632635  1.        ]]]]
    res 2 -63.8270067372
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6845712459
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6845712459
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6845712459
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.684570139
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.684570139
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6845701385
    [[[[ 1.  0.  1.]]]]
    res 0 372.0
    [[[[ 1.  0.  1.]]]]
    res 1 394.0
    [[[[ 1.  0.  1.]]]]
    res 2 146.0
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 0 258.382077845
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 1 280.382077845
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 2 32.3820778452
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 0 258.382079356
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 1 280.382079356
    [[[[ 0.97101161  0.02898839  1.        ]]]]
    res 2 32.3820793564
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.684571246
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6845712459
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 0 243.535232029
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 1 265.535232029
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 2 17.5352320295
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 0 243.535233319
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 1 265.535233319
    [[[[ 0.96121655  0.03878345  1.        ]]]]
    res 2 17.5352333189
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 283.456262794
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 305.456262794
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 57.4562627944
    [[[[ 0.95840358  0.04159642  1.        ]]]]
    res 0 244.038409517
    [[[[ 0.95840358  0.04159642  1.        ]]]]
    res 1 266.038409517
    [[[[ 0.95840358  0.04159642  1.        ]]]]
    res 2 18.0384095169
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 0 240.819180761
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 1 262.819180761
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 2 14.819180761
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 0 240.819182221
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 1 262.819182221
    [[[[ 0.95901053  0.04098947  1.        ]]]]
    res 2 14.8191822211
    [[[[ 0.95652612  0.04347388  1.        ]]]]
    res 0 242.282813619
    [[[[ 0.95652612  0.04347388  1.        ]]]]
    res 1 264.282813619
    [[[[ 0.95652612  0.04347388  1.        ]]]]
    res 2 16.282813619
    [[[[ 0.95918237  0.04081763  1.        ]]]]
    res 0 244.811274251
    [[[[ 0.95918237  0.04081763  1.        ]]]]
    res 1 266.811274251
    [[[[ 0.95918237  0.04081763  1.        ]]]]
    res 2 18.8112742509
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 0 240.389824053
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 1 262.389824053
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 2 14.3898240534
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 0 240.389825275
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 1 262.389825275
    [[[[ 0.95864596  0.04135404  1.        ]]]]
    res 2 14.3898252753
    [[[[ 0.95990347  0.04009653  1.        ]]]]
    res 0 245.552010138
    [[[[ 0.95990347  0.04009653  1.        ]]]]
    res 1 267.552010138
    [[[[ 0.95990347  0.04009653  1.        ]]]]
    res 2 19.5520101377
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 0 240.304289477
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 1 262.304289477
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 2 14.304289477
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 0 240.304290697
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 1 262.304290697
    [[[[ 0.95857269  0.04142731  1.        ]]]]
    res 2 14.3042906967
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 0 240.133486353
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 1 262.133486353
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 2 14.1334863526
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 0 240.13348757
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 1 262.13348757
    [[[[ 0.95842583  0.04157417  1.        ]]]]
    res 2 14.1334875703
    [[[[ 0.96010302  0.03989698  1.        ]]]]
    res 0 245.761333101
    [[[[ 0.96010302  0.03989698  1.        ]]]]
    res 1 267.761333101
    [[[[ 0.96010302  0.03989698  1.        ]]]]
    res 2 19.7613331011
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 0 240.099259131
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 1 262.099259131
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 2 14.0992591313
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 0 240.099260352
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 1 262.099260352
    [[[[ 0.95839635  0.04160365  1.        ]]]]
    res 2 14.0992603521
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 0 240.029801027
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 1 262.029801027
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 2 14.0298010267
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 0 240.029802296
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 1 262.029802296
    [[[[ 0.95833699  0.04166301  1.        ]]]]
    res 2 14.0298022955
    [[[[ 0.96018292  0.03981708  1.        ]]]]
    res 0 245.845678559
    [[[[ 0.96018292  0.03981708  1.        ]]]]
    res 1 267.845678559
    [[[[ 0.96018292  0.03981708  1.        ]]]]
    res 2 19.8456785593
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 0 240.015363061
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 1 262.015363061
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 2 14.0153630609
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 0 240.015364363
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 1 262.015364363
    [[[[ 0.95832493  0.04167507  1.        ]]]]
    res 2 14.0153643628
    [[[[ 0.96025772  0.03974228  1.        ]]]]
    res 0 245.924911856
    [[[[ 0.96025772  0.03974228  1.        ]]]]
    res 1 267.924911856
    [[[[ 0.96025772  0.03974228  1.        ]]]]
    res 2 19.9249118557
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 0 240.012424962
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 1 262.012424962
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 2 14.0124249623
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 0 240.012426273
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 1 262.012426273
    [[[[ 0.9583225  0.0416775  1.       ]]]]
    res 2 14.0124262731
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 0 240.006482817
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 1 262.006482817
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 2 14.0064828168
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 0 240.006484149
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 1 262.006484149
    [[[[ 0.95831762  0.04168238  1.        ]]]]
    res 2 14.0064841485
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 0 239.994258335
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 1 261.994258335
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 2 13.9942583347
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 0 239.994259724
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 1 261.994259724
    [[[[ 0.95830774  0.04169226  1.        ]]]]
    res 2 13.9942597244
    [[[[ 0.96024704  0.03975296  1.        ]]]]
    res 0 245.913586325
    [[[[ 0.96024704  0.03975296  1.        ]]]]
    res 1 267.913586325
    [[[[ 0.96024704  0.03975296  1.        ]]]]
    res 2 19.9135863249
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 0 239.991743948
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 1 261.991743948
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 2 13.9917439484
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 0 239.991745353
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 1 261.991745353
    [[[[ 0.95830574  0.04169426  1.        ]]]]
    res 2 13.9917453531
    [[[[ 0.960259  0.039741  1.      ]]]]
    res 0 245.926271066
    [[[[ 0.960259  0.039741  1.      ]]]]
    res 1 267.926271066
    [[[[ 0.960259  0.039741  1.      ]]]]
    res 2 19.9262710656
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 0 239.991237748
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 1 261.991237748
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 2 13.9912377479
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 0 239.991239156
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 1 261.991239156
    [[[[ 0.95830534  0.04169466  1.        ]]]]
    res 2 13.9912391559
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 0 239.990221858
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 1 261.990221858
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 2 13.9902218585
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 0 239.990223273
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 1 261.990223273
    [[[[ 0.95830453  0.04169547  1.        ]]]]
    res 2 13.9902232729
    [[[[ 0.96026002  0.03973998  1.        ]]]]
    res 0 245.927358455
    [[[[ 0.96026002  0.03973998  1.        ]]]]
    res 1 267.927358455
    [[[[ 0.96026002  0.03973998  1.        ]]]]
    res 2 19.9273584553
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 0 239.990018111
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 1 261.990018111
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 2 13.9900181106
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 0 239.990019526
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 1 261.990019526
    [[[[ 0.95830437  0.04169563  1.        ]]]]
    res 2 13.9900195264
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 0 239.989610034
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 1 261.989610034
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 2 13.9896100336
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 0 239.989611452
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 1 261.989611452
    [[[[ 0.95830405  0.04169595  1.        ]]]]
    res 2 13.989611452
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 0 239.988791514
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 1 261.988791514
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 2 13.9887915137
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 0 239.988792938
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 1 261.988792938
    [[[[ 0.95830341  0.04169659  1.        ]]]]
    res 2 13.9887929377
    [[[[ 0.96025934  0.03974066  1.        ]]]]
    res 0 245.926633526
    [[[[ 0.96025934  0.03974066  1.        ]]]]
    res 1 267.926633526
    [[[[ 0.96025934  0.03974066  1.        ]]]]
    res 2 19.9266335262
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 0 239.988627425
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 1 261.988627425
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 2 13.9886274248
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 0 239.98862885
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 1 261.98862885
    [[[[ 0.95830328  0.04169672  1.        ]]]]
    res 2 13.9886288498
    [[[[ 0.96026011  0.03973989  1.        ]]]]
    res 0 245.927445446
    [[[[ 0.96026011  0.03973989  1.        ]]]]
    res 1 267.927445446
    [[[[ 0.96026011  0.03973989  1.        ]]]]
    res 2 19.9274454462
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 0 239.988594591
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 1 261.988594591
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 2 13.9885945914
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 0 239.988596017
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 1 261.988596017
    [[[[ 0.95830325  0.04169675  1.        ]]]]
    res 2 13.9885960167
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 0 239.988528909
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 1 261.988528909
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 2 13.988528909
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 0 239.988530335
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 1 261.988530335
    [[[[ 0.9583032  0.0416968  1.       ]]]]
    res 2 13.9885303347
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 0 239.988397481
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 1 261.988397481
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 2 13.9883974814
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 0 239.988398908
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 1 261.988398908
    [[[[ 0.9583031  0.0416969  1.       ]]]]
    res 2 13.9883989081
    [[[[ 0.96026  0.03974  1.     ]]]]
    res 0 245.927329457
    [[[[ 0.96026  0.03974  1.     ]]]]
    res 1 267.927329457
    [[[[ 0.96026  0.03974  1.     ]]]]
    res 2 19.9273294573
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 0 239.988371186
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 1 261.988371186
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 2 13.9883711859
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 0 239.988372613
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 1 261.988372613
    [[[[ 0.95830308  0.04169692  1.        ]]]]
    res 2 13.9883726127
    [[[[ 0.96026012  0.03973988  1.        ]]]]
    res 0 245.927459366
    [[[[ 0.96026012  0.03973988  1.        ]]]]
    res 1 267.927459366
    [[[[ 0.96026012  0.03973988  1.        ]]]]
    res 2 19.9274593664
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 0 279.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 1 301.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 2 53.8980497946
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 0 279.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 1 301.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 2 53.8980497946
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 0 279.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 1 301.898049795
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 2 53.8980497946
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 0 279.898050538
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 1 301.898050538
    [[[[ 0.97129806  0.02870194  1.        ]]]]
    res 2 53.8980505385
    [[[[ 0.75014881  0.24985119  1.        ]]]]
    res 0 2381.18145682
    [[[[ 0.50005244  0.49994756  1.        ]]]]
    res 1 3073.97235676
    [[[[ 0.25008655  0.74991345  1.        ]]]]
    res 2 2156.44309689
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 297.676226864
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 319.676226864
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 71.6762268636
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 0 274.596996966
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 1 296.596996966
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 2 48.5969969664
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 0 274.596997558
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 1 296.596997558
    [[[[ 0.96556656  0.03443344  1.        ]]]]
    res 2 48.5969975584
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 0 273.120376153
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 1 295.120376153
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 2 47.1203761528
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 0 273.120376217
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 1 295.120376217
    [[[[ 0.95319662  0.04680338  1.        ]]]]
    res 2 47.1203762172
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 0 299.93460545
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 1 321.93460545
    [[[[ 0.95924987  0.04075013  1.        ]]]]
    res 2 73.9346054502
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 0 273.059043331
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 1 295.059043331
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 2 47.0590433306
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 0 273.059043372
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 1 295.059043372
    [[[[ 0.95231993  0.04768007  1.        ]]]]
    res 2 47.0590433719
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 0 273.015805307
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 1 295.015805307
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 2 47.0158053068
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 0 273.015805302
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 1 295.015805302
    [[[[ 0.95051023  0.04948977  1.        ]]]]
    res 2 47.0158053018
    [[[[ 0.95232065  0.04767935  1.        ]]]]
    res 0 273.059082699
    [[[[ 0.95232065  0.04767935  1.        ]]]]
    res 1 295.059082699
    [[[[ 0.95232065  0.04767935  1.        ]]]]


# Generating the input-output function $P(g\mid R, c)$ for varying repressor copy number $R$.

```python
import pickle
import os
import glob
import datetime

# Our numerical workhorses
import numpy as np
from sympy import mpmath
import scipy.optimize
import scipy.special
import scipy.integrate
import pandas as pd
import itertools

# Import libraries to parallelize processes
from joblib import Parallel, delayed

# Import the utils for this project
import chann_cap_utils as chann_cap
```

# Pre-computing analytical distributions of gene expession.

Since the computation of the mRNA and protein steady-state probability distributions are computationally expensive, we can pre-compute the distribution for different repressor copy number and save the results as a lookup table to compute any desired quantity out of these distributions including the channel capacity and the variability in gene expression due to the stochasticity of the allosteric molecules.

This notebook achieves the simple task of computing the mRNA and protein distribution for different repressor copy numbers saving the result into csv files that we can read with `numpy`.

The matrices are arranged such that each row's index is given by the number of repressors and each column index indicates either the mRNA or protein count.

## Pre-computing the mRNA distribution

Let's start by saving the distribution for mRNA molecules.

```python
# Define the parameters
k0 = 2.7E-3 # Used by Jones and Brewster

# The MWC parameters come from the global fit to the O2 data
mRNA_params = dict(ka=0.199, ki=0.00064, omega=np.exp(-4.5),
                   k0=k0, gamma=0.00284, r_gamma=15.7)
```

```python
# Define the mRNA copy numbers to evaluate
# It is break up in blocks to run the process in parallel
mRNA_grid = np.reshape(np.arange(0, 50), [-1, 10])

# define the array of repressor copy numbers to evaluate the function in
R_array = np.arange(0, 1001)

kon_array = [chann_cap.kon_fn(-17, mRNA_params['k0']),
             chann_cap.kon_fn(-15.3, mRNA_params['k0']),
             chann_cap.kon_fn(-13.9, mRNA_params['k0']),
             chann_cap.kon_fn(-9.7, mRNA_params['k0'])]
kon_operators = ['Oid', 'O1', 'O2', 'O3']

compute_matrix = True
if compute_matrix:
    for j, kon in enumerate(kon_array):
        print('operator : ' + kon_operators[j])
        # Set the value for the kon
        mRNA_params['kon'] = kon
        # Initialize transition matrix
        QmR = np.zeros([mRNA_grid.size, len(R_array)])
        for i, r in enumerate(R_array):
            if r%100==0:
                print('repressors : {:d}'.format(r))
            mRNA_params['rep'] = r * 1.66
            # -- Parallel computation of distribution -- #
            lnm_list = list()
            # loop through the concentrations
            # define a function to run in parallel the computation
            def lnm_parallel(m):
                lnm = chann_cap.log_p_m_mid_C(C=0, mRNA=m, **mRNA_params)
                return lnm
            lnm_list.append(Parallel(n_jobs=7)(delayed(lnm_parallel)(m) \
                                               for m in mRNA_grid))
            # -- Building and cleaning the transition matrix -- #
            for k, lnm in enumerate(lnm_list):
                # Initialize the matrix of zeros where the normalized
                # distribution will live
                p_norm = np.zeros_like(lnm)
                p = np.exp(lnm)
                # Compute the cumulative sum of the protein copy number
                p_sum = np.cumsum(np.sum(p, axis=1))
                # Find the first block that is already normalized given
                # the tolerance value
                norm_idx = np.where((p_sum <= 1 + 1E-5) & \
                                    (p_sum >= 1 - 1E-5))[0][-1]
                # add all the probability values of these blocks to our matrix
                p_norm[0:norm_idx, :] = p[0:norm_idx, :]
            QmR[:, i] = p_norm.ravel()
            # Check that all distributions for each concentration are normalized
        np.savetxt('../../tmp/QmR_' + kon_operators[j] +\
                   '_0_1000_literature_param.csv', QmR, delimiter=",")
```

### Pre-computing the protien distribution

```python
# Protein parameters
k0 = 2.7E-3 # From Jones & Brewster
prot_params = dict(ka=141.52, ki=0.56061, epsilon=4.5,
                   kon=chann_cap.kon_fn(-9.7, k0),
                   k0=k0,
                   gamma_m=0.00284, r_gamma_m=15.7,
                   gamma_p=0.000277, r_gamma_p=100)
```

```python
# Define the protein blocks to evaluate in parallel
# Break into blocks to compute the distributions in parallel
prot_grid = np.reshape(np.arange(0, 4000), [-1, 50])

# define the array of repressor copy numbers to evaluate the function in
R_array = np.arange(0, 1050)

# Setting the kon parameter based on k0 and the binding energies form stat. mech.
kon_array = [chann_cap.kon_fn(-13.9, prot_params['k0']),
             chann_cap.kon_fn(-15.3, prot_params['k0']),
             chann_cap.kon_fn(-9.7, prot_params['k0']),
             chann_cap.kon_fn(-17, prot_params['k0'])]
kon_operators = ['O2', 'O1', 'O3', 'Oid']
kon_dict = dict(zip(kon_operators, kon_array))

compute_matrix = True
if compute_matrix:
    for kon, op in enumerate(kon_operators):
        print('operator : ' + op)
        # Set the value for the kon
        prot_params['kon'] = kon_dict[op]
        # Define filename
        file = '../../data/csv_protein_dist/lnp_' + op + '_DJ_RB.csv'
    # If the file exists read the file, find the maximum number of repressors
    # And compute from this starting point.
        if os.path.isfile(file):
            df = pd.read_csv(file, index_col=0)
            max_rep = df.repressor.max()
            df = df[df.repressor != max_rep]
            df.to_csv(file)
            r_array = np.arange(max_rep, np.max(R_array) + 1)
        else:
            r_array = R_array

        # Loop through repressor copy numbers
        for i, r in enumerate(r_array):
            if r%50==0:
                print('repressors : {:d}'.format(r))
            prot_params['rep'] = r * 1.66
            # -- Parallel computation of distribution -- #
            # define a function to run in parallel the computation
            def lnp_parallel(p):
                lnp = chann_cap.log_p_p_mid_C(C=0, protein=p, **prot_params)
                df = pd.DataFrame([r] * len(p), index=p, columns=['repressor'])
                df.loc[:, 'protein'] = pd.Series(p, index=df.index)
                df.loc[:, 'lnp'] = lnp

                # if file does not exist write header
                if not os.path.isfile(file):
                    df.to_csv(file)
                else: # else it exists so append without writing the header
                    df.to_csv(file, mode='a', header=False)
            Parallel(n_jobs=40)(delayed(lnp_parallel)(p) for p in prot_grid)
```

    operator : O2
    repressors : 0

# Cleaning up the lookup tables

These calculations can sometimes be numerically unstable due to the complicated confluent hypergeometric function. What can happen is that by the time the probability is basically zero (i.e. the $\ln P \ll 0$) there can be some "jumps" where the calcualtion overshoots. But this happens for probability values that should be very close to zero, so it is very easy to discard these values.

We will define a function to pre-process these lookup tables.

```python
def pre_process_lnp(df, group_col='repressor', lnp_col='lnp',
                    output_col='prob', tol=-20):
    '''
    Pre-processes the lookup tables containing the log probability of a protein
    copy number for different repressor copy numbers eliminating the values
    that were numerically unstable, and returning the data frame with a column
    containing the processed probability.
    Parameters
    ----------
    filename : df
        Data frame containing the log probabilities.
    group_col : str.
        Name of the column in the data frame to be used to group the distributions
    lnp_col : str.
        Name of the column containing the log probability
    output_col : str.
        Name of the column that will contain the processed probability
    tol : float.
        log probability under which to consider values as probability zero.
        This is important since some of the calculations goe to < -300

    Returns
    -------
    Pandas dataframe containing the processed probability.
    '''
    # Remove duplicated rows
    df = df[[not x for x in df.duplicated()]]

    # Group by group_col
    df_group = df.groupby(group_col)

    # Initialize data frame where to save the processed data
    df_clean = pd.DataFrame(columns=df.columns)
    # Loop through each group, computing the log probability making sure that
    # There is no numerical overshoot and that the very small lnp are set to 0
    # probability
    for group, data in df_group:
        data.sort(columns='protein', inplace=True)
        # Set the new column to be all probability zero
        data.loc[:, output_col] = [0.0] * len(data)
        # Exponentiate the good log probabilities
        data.loc[(data.lnp > tol) & (data.lnp < 0), output_col] =\
        pd.Series(np.exp(data.loc[(data.lnp > tol) & (data.lnp < 0), lnp_col]))
        # Make sure cumulative sum still adds to zero
        cumsum = np.cumsum(data[output_col])
        data.loc[cumsum > 1, output_col] = 0
        # Append to the clean data frame
        df_clean = pd.concat([df_clean, data])

    return df_clean
```

Having defined the function let's pre-process the matrices we generated.

```python
files = glob.glob('../../data/csv_protein_dist/*O3_all*.csv')
for f in files:
    print(f)
    df = pd.read_csv(f, header=0, index_col=0, comment='#')
    df_clean = pre_process_lnp(df)
    df_clean.to_csv(f)
```

    ../../data/csv_protein_dist/lnp_O3_all_RBS1027_fit.csv

    /Users/razo/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:38: FutureWarning: sort(columns=....) is deprecated, use sort_values(by=.....)
    /Users/razo/anaconda/lib/python3.5/site-packages/pandas/core/frame.py:3304: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
      na_position=na_position)
    /Users/razo/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py:297: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame.
    Try using .loc[row_indexer,col_indexer] = value instead

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
      self.obj[key] = _infer_fill_value(value)
    /Users/razo/anaconda/lib/python3.5/site-packages/pandas/core/indexing.py:477: SettingWithCopyWarning:
    A value is trying to be set on a copy of a slice from a DataFrame.
    Try using .loc[row_indexer,col_indexer] = value instead

    See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
      self.obj[item] = s

```python

```