def setUp(self): filename = "./Example/Example.xlsx" set0 = data.read_sets_from_Excel(filename, 2, 0, 2)[0] equation = Linear('Linear') self.fs = SingleFitSession(set0, equation) self.fs.fit() self.fs.calculate_errors()
class TestRegressionLinearFit: """ """ def setUp(self): filename = "./Example/Example.xlsx" set0 = data.read_sets_from_Excel(filename, 2, 0, 2)[0] equation = Linear('Linear') self.fs = SingleFitSession(set0, equation) self.fs.fit() self.fs.calculate_errors() def test_degree_of_feedom(self): assert self.fs.ndf == 8 def test_fitted_parameters(self): np.testing.assert_almost_equal(self.fs.eq.pars[0], 3.666, 3) np.testing.assert_almost_equal(self.fs.eq.pars[1], 5.204, 3) def test_approximate_SD(self): np.testing.assert_almost_equal(self.fs.aproxSD[0], 5.216871572087441, 9) np.testing.assert_almost_equal(self.fs.aproxSD[1], 1.5729459621912463, 9) def test_Smin(self): np.testing.assert_almost_equal(self.fs.Smin, 395.8654399999999, 9) def test_maxLogLik(self): np.testing.assert_almost_equal(self.fs.Lmax, -32.581831644727835, 9) def test_lik_limits(self): self.fs.Llimits[0][0] is None np.testing.assert_almost_equal(self.fs.Llimits[0][1], 16.001557751460275, 9) np.testing.assert_almost_equal(self.fs.Llimits[1][0], 1.4776049950866297, 9) np.testing.assert_almost_equal(self.fs.Llimits[1][1], 8.923310603763344, 9)
import os import pylab as plt from cvfit import data from cvfit.equations import GHK as eqfit from cvfit.fitting import SingleFitSession from cvfit.data import XYDataSet if __name__ == "__main__": filename = "./Example/Example.xlsx" set0 = data.read_sets_from_Excel(filename, 2, 0, 3)[0] print("Loaded: " + os.path.split(str(filename))[1]) print (str(set0)) equation = eqfit('GHK', pars=[1.0, 150.0, 145.0, 5.0]) fsession = SingleFitSession(set0, equation) fsession.fit() fsession.calculate_errors() print(fsession.string_estimates()) fsession.calculate_errors() print(fsession.string_liklimits()) plX, plY = equation.calculate_plot(set0.X, equation.pars) rlim = fsession.Llimits[0] plX1, plY1 = equation.calculate_plot(set0.X, [rlim[0], 150.0, 145.0, 5.0]) plX2, plY2 = equation.calculate_plot(set0.X, [rlim[1], 150.0, 145.0, 5.0]) #avdat = XYDataSet() #avdat.pool(set0.X, set0.Y, seto.S) set0.average_pooled()
from cvfit.equations import Hill from cvfit.data import XYDataSet from cvfit.fitting import SingleFitSession if __name__ == "__main__": conc = np.array([0.1, 0.3, 1.0, 3.0, 10.0]) # , 30.0, 100.0 sd = 0.1 res = [] for i in range(100): eq = Hill('Hill', pars=[0.0, 1.0, 1.0, 1.0]) resp = eq.calculate_random(conc, sd) set = XYDataSet() set.from_columns(conc, resp) #print (set) fs = SingleFitSession(set, eq) fs.fit() res.append(eq.pars) results = np.array(res) plt.subplot(231) plt.hist(results[:, 1]) plt.xlabel('Ymax') plt.ylabel('Number') plt.xlim(0,2) plt.subplot(232) plt.hist(results[:, 2]) plt.xlabel('K') plt.ylabel('Number') plt.xlim(0,7)
def return_equation(self): fits = MultipleFitSession(self.log) for i in range(len(self.data)): fits.add( SingleFitSession(self.data[i], self.equations[i], self.log)) return fits
print('File {0} loaded'.format(fname)) print('{0:d} sets found.'.format(len(datasets))) for i in range(len(datasets)): print('\nSet #{0:d}:'.format(i + 1)) print(datasets[i]) # load equation eqname = 'Hill' if eqname == 'Hill' or eqname == 'Langmuir': from cvfit.equations import Hill # initiate fitting sessions, fit data and print results fitsessions = MultipleFitSession() for each in datasets: equation = Hill(eqname) fs = SingleFitSession(each, equation) fs.fit() fs.calculate_errors() print('\n*************************************************') print('\t' + fs.data.title + ' fit finished') print(fs.string_estimates()) print(fs.string_liklimits()) fitsessions.add(fs) print('\n*************************************************') print('\tAverage of all fits:') print(fitsessions.string_average_estimates()) # plot fitted fplots = fitsessions.prepare_fplot('fit') fig = plots.cvfit_plot(datasets, fig=None,