mailr7638 - /1.3/generic_fns/model_selection.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on October 12, 2008 - 12:27:
Author: bugman
Date: Sun Oct 12 12:27:23 2008
New Revision: 7638

URL: http://svn.gna.org/viewcvs/relax?rev=7638&view=rev
Log:
Shifted to the use of the model_loop().


Modified:
    1.3/generic_fns/model_selection.py

Modified: 1.3/generic_fns/model_selection.py
URL: 
http://svn.gna.org/viewcvs/relax/1.3/generic_fns/model_selection.py?rev=7638&r1=7637&r2=7638&view=diff
==============================================================================
--- 1.3/generic_fns/model_selection.py (original)
+++ 1.3/generic_fns/model_selection.py Sun Oct 12 12:27:23 2008
@@ -27,7 +27,7 @@
 from math import log
 
 # relax module imports.
-from pipes import get_type, has_pipe, pipe_names, switch
+from pipes import cdp_name, get_type, has_pipe, pipe_names, switch
 from relax_errors import RelaxError, RelaxPipeError
 from specific_fns.setup import get_specific_fn
 
@@ -145,7 +145,7 @@
 
     # Initialise.
     function_type = {}
-    count_num_instances = {}
+    model_loop = {}
     duplicate_data = {}
     model_statistics = {}
     skip_function = {}
@@ -159,8 +159,8 @@
         # Loop over the data pipes.
         for i in xrange(len(pipes)):
             for j in xrange(len(pipes[i])):
-                # Specific duplicate data, number of instances, and model 
statistics functions.
-                count_num_instances[pipes[i][j]] = 
get_specific_fn('num_instances', get_type(pipes[i][j]))
+                # Specific functions.
+                model_loop[pipes[i][j]] = get_specific_fn('model_loop', 
get_type(pipes[i][j]))
                 duplicate_data[pipes[i][j]] = 
get_specific_fn('duplicate_data', get_type(pipes[i][j]))
                 model_statistics[pipes[i][j]] = 
get_specific_fn('model_stats', get_type(pipes[i][j]))
                 skip_function[pipes[i][j]] = 
get_specific_fn('skip_function', get_type(pipes[i][j]))
@@ -169,53 +169,25 @@
     else:
         # Loop over the data pipes.
         for i in xrange(len(pipes)):
-            # Specific duplicate data, number of instances, and model 
statistics functions.
-            count_num_instances[pipes[i]] = get_specific_fn('num_instances', 
get_type(pipes[i]))
+            # Specific functions.
+            model_loop[pipes[i]] = get_specific_fn('model_loop', 
get_type(pipes[i]))
             duplicate_data[pipes[i]] = get_specific_fn('duplicate_data', 
get_type(pipes[i]))
             model_statistics[pipes[i]] = get_specific_fn('model_stats', 
get_type(pipes[i]))
             skip_function[pipes[i]] = get_specific_fn('skip_function', 
get_type(pipes[i]))
 
-    # Number of instances.  If the number is not the same for each data 
pipe, then the minimum
-    # number will give the specific function model_statistics the 
opportunity to consolidate the
-    # instances to the minimum number if possible.
-    min_instances = 1e99
-    num_instances = []
-    for i in xrange(len(pipes)):
-        # An array of arrays - for cross validation model selection.
-        if type(pipes[i]) == list:
-            num_instances.append([])
-
-            # Loop over the nested array.
-            for j in xrange(len(pipes[i])):
-                # Switch pipes.
-                switch(pipes[i][j])
-
-                # Number of instances.
-                num = count_num_instances[pipes[i][j]]()
-                num_instances[i].append(num)
-
-                # Minimum.
-                if num < min_instances:
-                    min_instances = num
-
-        # All other model selection techniques.
-        else:
-            # Switch pipes.
-            switch(pipes[i])
-
-            # Number of instances.
-            num = count_num_instances[pipes[i]]()
-            num_instances.append(num)
-
-            # Minimum.
-            if num < min_instances:
-                min_instances = num
-
-
-    # Loop over the number of instances.
-    for i in xrange(min_instances):
+    # The model loop should be the same for all data pipes!
+    for j in xrange(len(pipes)):
+        if model_loop[pipes[0]] != model_loop[pipes[j]]:
+            raise RelaxError, "The models for each data pipes should be the 
same."
+    model_loop = model_loop[pipes[0]]
+
+    # The model description.
+    model_desc = get_specific_fn('model_desc', get_type(pipes[0]))
+
+    # Loop over the base models.
+    for model_info in model_loop():
         # Print out.
-        print "\nModel index " + `i` + ".\n"
+        print "\nModel: " + `model_desc(model_info)` + ".\n"
         print "%-20s %-20s %-20s %-20s %-20s" % ("Data pipe", 
"Num_params_(k)", "Num_data_sets_(n)", "Chi2", "Criterion")
 
         # Initial model.




Related Messages


Powered by MHonArc, Updated Sun Oct 12 12:40:02 2008