0001 function [effective_vary_indices, linked_indices] = dsCheckCovary(vary_lengths, vary_params, varargin)
0002
0003
0004
0005 if ~nargin
0006 effective_vary_indices = localfunctions;
0007 return
0008 end
0009
0010
0011 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0012 if options.auto_gen_test_data_flag
0013 varargs = varargin;
0014 varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0015 varargs(end+1:end+2) = {'unit_test_flag',1};
0016 argin = [{vary_lengths}, {data_length}, varargs];
0017 end
0018
0019
0020 data_length = size(vary_params, 1);
0021
0022
0023 non_singleton_vary_indices = vary_lengths > 1;
0024 non_singleton_vary_lengths = vary_lengths(non_singleton_vary_indices);
0025 non_singleton_vary_params = vary_params(:, non_singleton_vary_indices);
0026 n_varied = length(non_singleton_vary_lengths);
0027
0028
0029
0030 full_rank_choices = {};
0031 index = 1;
0032
0033 for n_chosen = 1:n_varied
0034
0035 choices = nchoosek(1:n_varied, n_chosen);
0036 n_choices = nchoosek(n_varied, n_chosen);
0037
0038
0039
0040 for choice = 1:n_choices
0041 estimated_data_length = prod(non_singleton_vary_lengths(choices(choice, :)));
0042 if estimated_data_length == data_length
0043 full_rank_choices{index} = choices(choice, :);
0044 index = index + 1;
0045 end
0046 end
0047
0048 end
0049
0050 linked_indices = {};
0051
0052
0053 if isempty(full_rank_choices)
0054
0055
0056 linked_indices{1} = 1:n_varied;
0057
0058 else
0059
0060
0061 no_full_rank_choices = length(full_rank_choices);
0062
0063
0064 full_rank_participation = zeros(no_full_rank_choices, n_varied);
0065 for frc = 1:no_full_rank_choices
0066 full_rank_participation(frc, full_rank_choices{frc}) = 1;
0067 end
0068
0069
0070
0071 index = 1;
0072 non_participating_parameters = find(all(full_rank_participation == 0, 1));
0073 if ~isempty(non_participating_parameters)
0074 linked_indices{index} = [0 non_participating_parameters];
0075 index = index + 1;
0076 end
0077
0078 if no_full_rank_choices > 1
0079
0080
0081
0082
0083 param_indices = find(sum(full_rank_participation, 1) > 0);
0084
0085 iteration_number = 1;
0086 while length(param_indices) > 1
0087 [linked_set, param_indices] = find_linked_params(param_indices, non_singleton_vary_params, varargin{:});
0088
0089 if ~isempty(linked_set)
0090 linked_indices{index} = linked_set;
0091 index = index + 1;
0092 end
0093
0094 iteration_number = iteration_number + 1;
0095 if iteration_number > 10
0096 return
0097 end
0098 end
0099
0100 end
0101
0102 end
0103
0104
0105 marked_for_removal = zeros(size(non_singleton_vary_lengths));
0106 for l = 1:length(linked_indices)
0107 marked_for_removal(linked_indices{l}(2:end)) = 1;
0108 end
0109
0110
0111 effective_non_singleton_vary_indices = ~marked_for_removal;
0112
0113 effective_vary_indices = false(size(vary_lengths));
0114
0115 effective_vary_indices(non_singleton_vary_indices) = logical(effective_non_singleton_vary_indices);
0116
0117
0118 if options.auto_gen_test_data_flag
0119 argout = {effective_vary_lengths, linked_indices};
0120
0121 dsUnitSaveAutoGenTestData(argin, argout);
0122 end
0123
0124 end
0125
0126 function [linked_indices, non_linked_indices] = find_linked_params(param_indices, vary_params, varargin)
0127
0128
0129 options = dsCheckOptions(varargin,{'auto_gen_test_data_flag',0,{0,1}},false);
0130 if options.auto_gen_test_data_flag
0131 varargs = varargin;
0132 varargs{find(strcmp(varargs, 'auto_gen_test_data_flag'))+1} = 0;
0133 varargs(end+1:end+2) = {'unit_test_flag',1};
0134 argin = [{param_indices},{vary_params}, varargs];
0135 end
0136
0137 param1_index = param_indices(1);
0138
0139 if iscellstr(vary_params)
0140 params_at_value1 = vary_params(strcmp(vary_params(:, param1_index),vary_params(1, param1_index)), :);
0141
0142
0143 elseif isnumeric(vary_params)
0144 params_at_value1 = vary_params(vary_params(:, param1_index) == vary_params(1, param1_index), :);
0145 elseif iscellnum(vary_params)
0146 vary_params2 = cell2mat(vary_params);
0147 params_at_value1 = vary_params(vary_params2(:, param1_index) == vary_params2(1, param1_index), :);
0148 else
0149 try
0150 params_at_value1 = vary_params(vary_params(:, param1_index) == vary_params(1, param1_index), :);
0151 catch
0152 error('case not implemented. vary_params must all cell array of chars of all numeric');
0153 end
0154 end
0155
0156 no_values_at_value1 = nan(size(param_indices));
0157
0158 no_values_at_value1(1) = 1;
0159
0160 for p = 2:length(param_indices)
0161
0162 param_index = param_indices(p);
0163
0164 no_values_at_value1(p) = length(unique(params_at_value1(:, param_index)));
0165
0166 end
0167
0168 linked_indices = param_indices(no_values_at_value1 == 1);
0169
0170 non_linked_indices = param_indices(no_values_at_value1 > 1);
0171
0172
0173
0174 if options.auto_gen_test_data_flag
0175 argout = {linked_indices, non_linked_indices};
0176
0177 dsUnitSaveAutoGenTestDataLocalFn(argin, argout);
0178 end
0179
0180 end