In [1]:
%matplotlib inline
from pylab import*
import numpy as np

In [2]:
from cvfit import fitting
from cvfit.fitting import SingleFitSession
from cvfit.fitting import MultipleFitSession

In [3]:
datasets, fname = fitting.load_data(example=True)
print('File {0} loaded'.format(fname))
print('{0:d} sets found.'.format(len(datasets)))
#sets = fitting.set_weights(sets)
for i in range(len(datasets)):
    print ('\nSet #{0:d}:'.format(i+1))
    print (datasets[i])


File C:\DCPROGS\CVFIT./Example/Example.xlsx loaded
5 sets found.

Set #1:

X	Y	s(Y)	weight
30	54	0	1
100	538	0	1
300	2745	0	1
1000	6493	0	1
3000	8450	0	1
3000	9793	0	1
3000	9647	0	1
3000	10023	0	1
3000	9025	0	1
3000	9341	0	1
10000	10349	0	1
10000	10467	0	1
30000	11527	0	1
30000	10946	0	1


Set #2:

X	Y	s(Y)	weight
30	91	0	1
100	645	0	1
300	2460	0	1
600	3592	0	1
1000	4369	0	1
1000	4598	0	1
1000	4752	0	1
1000	4724	0	1
1000	4412	0	1
3000	6430	0	1
10000	7227	0	1
30000	7970	0	1
30000	7976	0	1


Set #3:

X	Y	s(Y)	weight
100	1731	0	1
300	7829	0	1
600	11922	0	1
1000	14397	0	1
3000	16500	0	1
3000	17804	0	1
3000	18528	0	1
3000	18820	0	1
10000	18818	0	1
30000	19593.5	0	1


Set #4:

X	Y	s(Y)	weight
30	305	0	1
100	1856	0	1
300	7834.5	0	1
600	8970	0	1
600	9534	0	1
600	11256	0	1
600	10424	0	1
600	12133	0	1
1000	13201	0	1
3000	16686	0	1
10000	17145	0	1
30000	16329	0	1


Set #5:

X	Y	s(Y)	weight
100	980	0	1
300	3193	0	1
600	4949	0	1
1000	4806	0	1
1000	6183	0	1
1000	6188	0	1
1000	6162	0	1
1000	6355	0	1
1000	6190	0	1
3000	8658	0	1
10000	9165	0	1
10000	9284	0	1
10000	9000	0	1
30000	9276	0	1
30000	9492	0	1
30000	9674	0	1

Example of single fit session.


In [4]:
from cvfit.equations import Hill
eq = Hill('Hill')
fs = SingleFitSession(datasets[0], eq)


	Fitting session for Set 1 initialised!

In [5]:
fs.fit()
fs.calculate_errors()
print(fs.string_estimates())
print(fs.string_liklimits())


Number of point fitted = 14
Number of parameters estimated = 3
Degrees of freedom = 11
Residual error SD = 446.029      (variance = 198941.810)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 11124.1  	  Approx SD = 297.241	  CV = 2.7
Parameter 3: EC50  	= 773.58  	  Approx SD = 80.5618	  CV = 10.4
Parameter 4: nH    	= 1.23848  	  Approx SD = 0.118585	  CV = 9.6
Minimum SSD = 2188359.915; 
Max log-likelihood = -103.582
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.42-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.2)
Lmax= -103.582;   Lcrit= -106.005
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 11124.1	  LOWER = 10528.6	  UPPER = 11807.7
Parameter 3:   EC50	= 773.58	  LOWER = 614.965	  UPPER = 958.862
Parameter 4:   nH  	= 1.23848	  LOWER = 1.01316	  UPPER = 1.5316

Example of multiple fit session


In [6]:
fits = MultipleFitSession()
for each in datasets:
    eq = Hill('Hill')
    fs = SingleFitSession(each, eq)
    fits.add(fs)


	Fitting session for Set 1 initialised!
	Fitting session for Set 2 initialised!
	Fitting session for Set 3 initialised!
	Fitting session for Set 4 initialised!
	Fitting session for Set 5 initialised!

In [7]:
for fs in fits.list:
    print("\n\tSTART FITTING ===============")
    fs.fit()
    fs.calculate_errors()
    print(fs.string_estimates())
    print(fs.string_liklimits())
    print("\n\tFITTING FINISHED ============")
print ("\nFINISHED FITTING ALL SETS")


	START FITTING ===============
Number of point fitted = 14
Number of parameters estimated = 3
Degrees of freedom = 11
Residual error SD = 446.029      (variance = 198941.810)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 11124.1  	  Approx SD = 297.241	  CV = 2.7
Parameter 3: EC50  	= 773.58  	  Approx SD = 80.5618	  CV = 10.4
Parameter 4: nH    	= 1.23848  	  Approx SD = 0.118585	  CV = 9.6
Minimum SSD = 2188359.915; 
Max log-likelihood = -103.582
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.42-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.2)
Lmax= -103.582;   Lcrit= -106.005
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 11124.1	  LOWER = 10528.6	  UPPER = 11807.7
Parameter 3:   EC50	= 773.58	  LOWER = 614.965	  UPPER = 958.862
Parameter 4:   nH  	= 1.23848	  LOWER = 1.01316	  UPPER = 1.5316

	FITTING FINISHED ============

	START FITTING ===============
Number of point fitted = 13
Number of parameters estimated = 3
Degrees of freedom = 10
Residual error SD = 194.615      (variance = 37874.957)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 8032.03  	  Approx SD = 155.083	  CV = 1.9
Parameter 3: EC50  	= 758.976  	  Approx SD = 42.5827	  CV = 5.6
Parameter 4: nH    	= 1.02066  	  Approx SD = 0.0677128	  CV = 6.6
Minimum SSD = 378749.571; 
Max log-likelihood = -85.264
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.48-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.23)
Lmax= -85.2641;   Lcrit= -87.7461
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 8032.03	  LOWER = 7714.85	  UPPER = 8389.7
Parameter 3:   EC50	= 758.976	  LOWER = 674.479	  UPPER = 862.745
Parameter 4:   nH  	= 1.02066	  LOWER = 0.883941	  UPPER = 1.1783

	FITTING FINISHED ============

	START FITTING ===============
Number of point fitted = 10
Number of parameters estimated = 3
Degrees of freedom = 7
Residual error SD = 764.743      (variance = 584831.601)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 19236.4  	  Approx SD = 518.044	  CV = 2.7
Parameter 3: EC50  	= 425.338  	  Approx SD = 39.063	  CV = 9.2
Parameter 4: nH    	= 1.35863  	  Approx SD = 0.162675	  CV = 12.0
Minimum SSD = 4093821.205; 
Max log-likelihood = -78.801
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.8-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.37)
Lmax= -78.8014;   Lcrit= -81.598
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 19236.4	  LOWER = 18164.4	  UPPER = 20588.4
Parameter 3:   EC50	= 425.338	  LOWER = 345.585	  UPPER = 529.992
Parameter 4:   nH  	= 1.35863	  LOWER = 1.04003	  UPPER = 1.80572

	FITTING FINISHED ============

	START FITTING ===============
Number of point fitted = 12
Number of parameters estimated = 3
Degrees of freedom = 9
Residual error SD = 1006.919      (variance = 1013886.688)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 17059.3  	  Approx SD = 687.795	  CV = 4.0
Parameter 3: EC50  	= 408.194  	  Approx SD = 42.3857	  CV = 10.4
Parameter 4: nH    	= 1.34394  	  Approx SD = 0.203167	  CV = 15.1
Minimum SSD = 9124980.194; 
Max log-likelihood = -98.277
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.56-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.26)
Lmax= -98.277;   Lcrit= -100.835
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 17059.3	  LOWER = 15625	  UPPER = 18669.7
Parameter 3:   EC50	= 408.194	  LOWER = 318.684	  UPPER = 508.845
Parameter 4:   nH  	= 1.34394	  LOWER = 0.965161	  UPPER = 1.88698

	FITTING FINISHED ============

	START FITTING ===============
Number of point fitted = 16
Number of parameters estimated = 3
Degrees of freedom = 13
Residual error SD = 409.071      (variance = 167339.261)
Parameter 1: Ymin  	= 0  	  (fixed)
Parameter 2: Ymax  	= 9617.18  	  Approx SD = 221.539	  CV = 2.3
Parameter 3: EC50  	= 615.621  	  Approx SD = 45.689	  CV = 7.4
Parameter 4: nH    	= 1.11171  	  Approx SD = 0.123225	  CV = 11.1
Minimum SSD = 2175410.395; 
Max log-likelihood = -117.264
Correlation matrix = [!!!! PRINTOUT OF CORRELATION MATRIX NOT IMPLEMENTED YET. SORRY.


LIKELIHOOD INTERVALS
2.33-unit Likelihood Intervals  (equivalent SD for Gaussian- 2.16)
Lmax= -117.264;   Lcrit= -119.597
Parameter 1:   Ymin	= 0	  (fixed)
Parameter 2:   Ymax	= 9617.18	  LOWER = 9181.65	  UPPER = 10135.9
Parameter 3:   EC50	= 615.621	  LOWER = 523.1	  UPPER = 718.742
Parameter 4:   nH  	= 1.11171	  LOWER = 0.874653	  UPPER = 1.39763

	FITTING FINISHED ============

FINISHED FITTING ALL SETS

In [8]:
fplots = fitsessions.prepare_fplot('fit')
fig = plots.cvfit_plot(datasets, fig=None, 
    fplotsets=fplots, fplotline='b-',
    logX=True, logY=False, legend=True)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-0a4ac2551546> in <module>()
----> 1 fplots = fitsessions.prepare_fplot('fit')
      2 fig = plots.cvfit_plot(datasets, fig=None, 
      3     fplotsets=fplots, fplotline='b-',
      4     logX=True, logY=False, legend=True)

NameError: name 'fitsessions' is not defined

In [ ]: