Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2015 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax (http://www.nmr-relax.com). # 6 # # 7 # This program 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 3 of the License, or # 10 # (at your option) any later version. # 11 # # 12 # This program 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 this program. If not, see <http://www.gnu.org/licenses/>. # 19 # # 20 ############################################################################### 21 22 # Module docstring. 23 """Module for handling statistics.""" 24 25 # Python module imports. 26 import sys 27 28 # relax module imports. 29 from lib.io import write_data 30 from pipe_control.pipes import check_pipe 31 from specific_analyses.api import return_api 32 3335 """Calculate and store Akaike's Information Criterion (AIC) for each model.""" 36 37 # Checks. 38 check_pipe() 39 40 # The specific analysis API object. 41 api = return_api() 42 43 # Calculate the chi2. 44 print("Calculating the chi-squared value for the current parameter values.") 45 api.calculate() 46 47 # Loop over the base models. 48 print("\nStoring the model statistics.") 49 for model_info in api.model_loop(): 50 # Title printout. 51 api.print_model_title(model_info=model_info) 52 53 # Get the model statistics. 54 k, n, chi2 = api.model_statistics(model_info=model_info) 55 56 # Calculate the AIC value. 57 aic = chi2 + 2.0*k 58 59 # The model container. 60 container = api.get_model_container(model_info=model_info) 61 62 # Store the statistics. 63 container.chi2 = chi2 64 container.num_params = k 65 container.aic = aic 66 67 # Statistics printout. 68 data = [ 69 ["Chi-squared value:", "%20f" % chi2], 70 ["Number of parameters (k):", "%20i" % k], 71 ["Akaike's Information Criterion (AIC):", "%20f" % aic] 72 ] 73 write_data(out=sys.stdout, data=data)74 7577 """Calculate and store the model statistics.""" 78 79 # Checks. 80 check_pipe() 81 82 # The specific analysis API object. 83 api = return_api() 84 85 # Calculate the chi2. 86 print("Calculating the chi-squared value for the current parameter values.") 87 api.calculate() 88 89 # Loop over the base models. 90 print("\nStoring the model statistics.") 91 for model_info in api.model_loop(): 92 # Title printout. 93 api.print_model_title(model_info=model_info) 94 95 # Get the model statistics. 96 k, n, chi2 = api.model_statistics(model_info=model_info) 97 98 # The model container. 99 container = api.get_model_container(model_info=model_info) 100 101 # Store the values. 102 container.chi2 = chi2 103 container.num_params = k 104 container.num_data_points = n 105 106 # Statistics printout. 107 data = [ 108 ['Chi-squared value:', "%20f" % chi2], 109 ['Number of parameters (k):', "%20i" % k], 110 ['Number of data points (n):', "%20i" % n] 111 ] 112 write_data(out=sys.stdout, data=data)113
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Sat Jun 8 10:45:34 2024 | http://epydoc.sourceforge.net |