Package prompt :: Module model_selection
[hide private]
[frames] | no frames]

Source Code for Module prompt.model_selection

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2003, 2004 Edward d'Auvergne                                  # 
  4  #                                                                             # 
  5  # This file is part of the program relax.                                     # 
  6  #                                                                             # 
  7  # relax is free software; you can redistribute it and/or modify               # 
  8  # it under the terms of the GNU General Public License as published by        # 
  9  # the Free Software Foundation; either version 2 of the License, or           # 
 10  # (at your option) any later version.                                         # 
 11  #                                                                             # 
 12  # relax is distributed in the hope that it will be useful,                    # 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 15  # GNU General Public License for more details.                                # 
 16  #                                                                             # 
 17  # You should have received a copy of the GNU General Public License           # 
 18  # along with relax; if not, write to the Free Software                        # 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 20  #                                                                             # 
 21  ############################################################################### 
 22   
 23  import sys 
 24   
 25   
26 -class Modsel:
27 - def __init__(self, relax):
28 """Class containing the function for selecting which model selection method should be used.""" 29 30 self.relax = relax
31 32
33 - def model_selection(self, method=None, modsel_run=None, runs=None):
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 # Function intro text. 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 # Method. 99 if type(method) != str: 100 raise RelaxStrError, ('model selection method', method) 101 102 # New run modsel_run. 103 if type(modsel_run) != str: 104 raise RelaxStrError, ('modsel_run', modsel_run) 105 106 # Runs. 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 # Execute the functional code. 121 self.relax.generic.model_selection.select(method=method, modsel_run=modsel_run, runs=runs)
122