1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import sys
24
25
28 """Class containing the function for selecting which model selection method should be used."""
29
30 self.relax = relax
31
32
34 """Function for model selection.
35
36 Keyword arguments
37 ~~~~~~~~~~~~~~~~~
38
39 method: The model selection technique (see below).
40
41 modsel_run: The run name to assign to the results of model selection.
42
43 runs: An array containing the names of all runs to include in model selection.
44
45
46 Description
47 ~~~~~~~~~~~
48
49 The following model selection methods are supported:
50
51 AIC: Akaike's Information Criteria.
52
53 AICc: Small sample size corrected AIC.
54
55 BIC: Bayesian or Schwarz Information Criteria.
56
57 Bootstrap: Bootstrap model selection.
58
59 CV: Single-item-out cross-validation.
60
61 Expect: The expected overall discrepancy (the true values of the parameters are required).
62
63 Farrow: Old model-free method by Farrow et al., 1994.
64
65 Palmer: Old model-free method by Mandel et al., 1995.
66
67 Overall: The realised overall discrepancy (the true values of the parameters are required).
68
69 For the methods 'Bootstrap', 'Expect', and 'Overall', the function 'monte_carlo' should have
70 previously been run with the type argument set to the appropriate value to modify its
71 behaviour.
72
73 If the runs argument is not supplied then all runs currently set or loaded will be used for
74 model selection, although this could cause problems.
75
76
77 Example
78 ~~~~~~~
79
80 For model-free analysis, if the preset models 1 to 5 are minimised and loaded into the
81 program, the following commands will carry out AIC model selection and assign the results
82 to the run name 'mixed':
83
84 relax> model_selection('AIC', 'mixed')
85 relax> model_selection(method='AIC', modsel_run='mixed')
86 relax> model_selection('AIC', 'mixed', ['m1', 'm2', 'm3', 'm4', 'm5'])
87 relax> model_selection(method='AIC', modsel_run='mixed', runs=['m1', 'm2', 'm3', 'm4', 'm5'])
88 """
89
90
91 if self.relax.interpreter.intro:
92 text = sys.ps3 + "model_selection("
93 text = text + "method=" + `method`
94 text = text + ", modsel_run=" + `modsel_run`
95 text = text + ", runs=" + `runs` + ")"
96 print text
97
98
99 if type(method) != str:
100 raise RelaxStrError, ('model selection method', method)
101
102
103 if type(modsel_run) != str:
104 raise RelaxStrError, ('modsel_run', modsel_run)
105
106
107 if runs == None:
108 pass
109 elif type(runs) != list:
110 raise RelaxNoneListError, ('runs', runs)
111 else:
112 for name in runs:
113 if type(name) == list:
114 for name2 in name:
115 if type(name2) != str:
116 raise RelaxError, "The elements of the second dimension of the runs argument must be strings."
117 elif type(name) != str:
118 raise RelaxError, "The elements of the first dimension of the runs argument must be either strings or arrays."
119
120
121 self.relax.generic.model_selection.select(method=method, modsel_run=modsel_run, runs=runs)
122