-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_fitter.py
executable file
·79 lines (67 loc) · 1.77 KB
/
test_fitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import numpy as np
import bindfit
import pprint
import pandas as pd
# Parameters and options
params = {
"k": {
"init": 100.0,
"bounds": {
"min": 0.0,
"max": None,
},
},
}
fitter_name = "nmr1to1"
method = "Nelder-Mead"
normalise = True
dilute = False
flavour = "none"
# Load raw data
data = pd.read_csv("input.csv")
# Set index as per fitter
data = data.set_index(["Host", "Guest"])
# Dilution correction is already in fitter
# if dilute:
# data_y = bindfit.helpers.dilute(data_x[0], data_y)
function = bindfit.functions.construct(
fitter_name,
normalise=normalise,
flavour=flavour,
)
fitter = bindfit.fitter.Fitter(
data, function, normalise=normalise, params=params
)
fitter.run_scipy(params, method=method)
summary = {
"fitter": fitter_name,
"fit": {
"y": fitter.fit,
"coeffs_raw": fitter.coeffs_raw,
"coeffs": fitter.coeffs,
"molefrac_raw": fitter.molefrac_raw,
"molefrac": fitter.molefrac,
"params": fitter.params,
"n_y": np.array(fitter.fit).size,
"n_params": len(fitter.params) + np.array(fitter.coeffs_raw).size,
},
"qof": {
"residuals": fitter.residuals,
"ssr": bindfit.helpers.ssr(fitter.residuals),
"rms": bindfit.helpers.rms(fitter.residuals),
"cov": bindfit.helpers.cov(fitter.ydata, fitter.residuals),
"rms_total": bindfit.helpers.rms(fitter.residuals, total=True),
"cov_total": bindfit.helpers.cov(
fitter.ydata, fitter.residuals, total=True
),
},
"time": fitter.time,
"options": {
"dilute": dilute,
"normalise": normalise,
"method": method,
"flavour": flavour,
},
}
pprint.pprint(summary)