scoreC13Fit

PURPOSE ^

SYNOPSIS ^

function [output] = scoreC13Fit(flux,expdata,model, namesset, method)

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [output] = scoreC13Fit(flux,expdata,model, namesset, method)
0002 
0003 std = expdata.std2;
0004 
0005 %this function (1) computes the theoretical mdv distribution vector for
0006 %a given flux vector, v, (2) and then computes an error score by taking a
0007 %running sum of the squared difference between the theortical and
0008 %experimental mdv vectors.
0009 
0010 %v - flux vector array
0011 %expdata - experimental data structure
0012 %     e.g.
0013 %       ala57
0014 %          - met = xalaL
0015 %          - fragment = [1,1,1]'
0016 %          - data = [0.238,0.098,0.017]'
0017 % glc_cdv is a sugar distribution in cuomer format (see idv2cdv).
0018 
0019 % output contains fields:
0020 %        - error - the calculated error sum value
0021 %        - theory - theoretical mdv vector
0022 %        - experimental - experimental mdv vector
0023 
0024 
0025 max_attempt = 2; % keep this at two to try both methods
0026 
0027 isV = length(flux) == length(model.lb);
0028 if nargin < 6
0029     method = 2; % method 1 = cumomer.  method 2 = CMU
0030 end
0031 
0032 %check if flux is alpha factor or v
0033 %if flux is v then make appropriate assignments
0034 if(isV)
0035     v = flux; 
0036 else
0037     v = (model.N)*flux;
0038 end
0039 
0040 if nargin < 5 || isempty(namesset)
0041     namesset = false;
0042 end
0043           
0044 
0045 
0046 attempt = 1;
0047 names = fields(expdata.fragments);
0048 expdata2 = expdata.fragments;  
0049 
0050 while attempt <= max_attempt
0051     tmdv = zeros(0,1);
0052     emdv = zeros(0,1);
0053     if method == 1 %cumomer
0054         glc_input = expdata.input;
0055         o = slvrCumomer_fast(v, glc_input);
0056         for l = 1:length(names)
0057             name = names{l};
0058             tname = expdata2.(name).met;
0059             tfragment = expdata2.(name).fragment;
0060             tresult = idv2mdv(length(tfragment), tfragment)*o.(tname);
0061             eresult = expdata2.(name).data;
0062             tmdv = [tmdv; tresult];
0063             emdv = [emdv; eresult];
0064         end
0065     elseif method == 2 %newer/faster
0066         glc_input = expdata.inputfrag;
0067         o = slvrEMU_fast(v, glc_input);
0068         for l = 1:length(names)
0069             name = names{l};
0070             tname = expdata2.(name).metfrag;
0071             tresult = o.(tname);
0072             eresult = expdata2.(name).data;
0073             tmdv = [tmdv; tresult];
0074             emdv = [emdv; eresult];
0075         end
0076     end
0077     
0078     if any(isnan(tmdv)) && attempt < max_attempt
0079         attempt = attempt + 1;
0080         if method == 1
0081             method = 2;
0082         else
0083             method = 1;
0084         end
0085     else
0086 %         if attempt == 2 % aka it worked the second time
0087 %             fprintf('s');
0088 %             pause;
0089 %         end
0090         break;
0091     end
0092 end
0093 if any(isnan(tmdv))
0094     save errorFile flux
0095 end
0096 %iterate through both the theoretical and experimental vectors and compute
0097 %a running error value
0098 
0099 variation = (tmdv - emdv).^2; 
0100 
0101 output = struct;
0102 output.error = sum(variation)/(std^2); 
0103 output.theory = tmdv;
0104 output.experimental = emdv;
0105 if(namesset)
0106     k = 1;
0107     for l = 1:length(names)
0108         name = names{l};
0109         if method == 1
0110             tname = expdata2.(name).met; 
0111         else
0112             tname = expdata2.(name).metfrag;
0113         end
0114         %tresult = o.(tname);
0115         for i = 1:length(expdata2.(name).fragment)
0116             newname = strcat(name, num2str(i-1));
0117             mdvnames{k,1} = newname;
0118             k = k+1;
0119         end
0120     end
0121     output.mdvnames = mdvnames;
0122 end
0123 return

Generated on Thu 21-Jun-2012 15:39:23 by m2html © 2003