1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for the statistical concept of model selection."""
24
25
26 from math import log
27
28
29 from lib.errors import RelaxError
30
31
33 """Akaike's Information Criteria (AIC).
34
35 The formula is::
36
37 AIC = chi2 + 2k
38
39
40 @param chi2: The minimised chi-squared value.
41 @type chi2: float
42 @param k: The number of parameters in the model.
43 @type k: int
44 @param n: The dimension of the relaxation data set.
45 @type n: int
46 @return: The AIC value.
47 @rtype: float
48 """
49
50 return chi2 + 2.0*k
51
52
53 -def aicc(chi2, k, n):
54 """Small sample size corrected AIC.
55
56 The formula is::
57
58 2k(k + 1)
59 AICc = chi2 + 2k + ---------
60 n - k - 1
61
62
63 @param chi2: The minimised chi-squared value.
64 @type chi2: float
65 @param k: The number of parameters in the model.
66 @type k: int
67 @param n: The dimension of the relaxation data set.
68 @type n: int
69 @return: The AIC value.
70 @rtype: float
71 """
72
73 if n > (k+1):
74 return chi2 + 2.0*k + 2.0*k*(k + 1.0) / (n - k - 1.0)
75 elif n == (k+1):
76 raise RelaxError("The size of the dataset, n=%s, is too small for this model of size k=%s. This situation causes a fatal division by zero as:\n AICc = chi2 + 2k + 2k*(k + 1) / (n - k - 1).\n\nPlease use AIC model selection instead." % (n, k))
77 elif n < (k+1):
78 raise RelaxError("The size of the dataset, n=%s, is too small for this model of size k=%s. This situation produces a negative, and hence nonsense, AICc score as:\n AICc = chi2 + 2k + 2k*(k + 1) / (n - k - 1).\n\nPlease use AIC model selection instead." % (n, k))
79
80
82 """Bayesian or Schwarz Information Criteria.
83
84 The formula is::
85
86 BIC = chi2 + k ln n
87
88
89 @param chi2: The minimised chi-squared value.
90 @type chi2: float
91 @param k: The number of parameters in the model.
92 @type k: int
93 @param n: The dimension of the relaxation data set.
94 @type n: int
95 @return: The AIC value.
96 @rtype: float
97 """
98
99 return chi2 + k * log(n)
100