PageRenderTime 52ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/matlab_tools/Converted/kcsigappend.m

http://github.com/aludnam/MATLAB
Objective C | 199 lines | 196 code | 3 blank | 0 comment | 59 complexity | 0dda46216685706f06e9796971285fe2 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. %kcsigappend 'Append and labels signatures of variable sizes'
  2. % This MatLab function was automatically generated by a converter (KhorosToMatLab) from the Khoros csigappend.pane file
  3. %
  4. % Parameters:
  5. % InputFile: ipre 'Input Pre-appended', optional: 'input pre-appended file'
  6. % InputFile: i1 'Input 1', required: 'First Input data object'
  7. % InputFile: i2 'Input 2', optional: 'Input data object 2'
  8. % InputFile: i3 'Input 3', optional: 'Input data object 3'
  9. % InputFile: i4 'Input 4', optional: 'Input data object 4'
  10. % InputFile: i5 'Input 5', optional: 'Input data object 5'
  11. % InputFile: i6 'Input 6', optional: 'Input data object 6'
  12. % InputFile: i7 'Input 7', optional: 'Input data object 7'
  13. % InputFile: i8 'Input 8', optional: 'Input data object 8'
  14. % InputFile: i9 'Input 9', optional: 'Input data object 9'
  15. % InputFile: i10 'Input 10', optional: 'Input data object 10'
  16. % OutputFile: o 'Output', required: 'Resulting output data object'
  17. %
  18. % Example: o = kcsigappend({ipre, i1, i2, i3, i4, i5, i6, i7, i8, i9, i10}, {'ipre','';'i1','';'i2','';'i3','';'i4','';'i5','';'i6','';'i7','';'i8','';'i9','';'i10','';'o',''})
  19. %
  20. % Khoros helpfile follows below:
  21. %
  22. % PROGRAM
  23. % csigappend - Append and labels signatures of variable sizes
  24. %
  25. % DESCRIPTION
  26. % This routine is used to append and label signatures of variable size in a single block for classification. It should be used to concatenate signatures for the classifiers which signatures aren't of the same size - e.g. the K-Nearest Neighbors classifier signatures can be of different sizes.
  27. % Its input are several individual-classes signature files ([-i1], [-i2] ... [-i10] parameters). Each signature will also be labelled by the operator so the classifier can later identify which data belongs to which class. Labels are determined by the order the data is appended (considering also if a pre-appended, pre-labeled object was passed with the parameter [-ipre]). Output will be in the file specified by the parameter [-o].
  28. % If there are more than 10 signatures to be appended, this operator's result can be used as the input of another copy of this operator (using the parameter [-ipre]), and the labelling will be done based on the labels already used. In other words, to connect more than 10 signatures use a net of these operators together, but don't concatenate their results together.
  29. % The main differences from this operator to kappend are:
  30. % * The objects are appended in the width dimension only, no map or mask is expected
  31. % * The objects are labelled prior to appending
  32. %
  33. %
  34. %
  35. % EXAMPLES
  36. % All examples for the Classify toolbox are listed on the Classify Toolbox Manual. For an example of this routine, please see the Classify:workspaces:KNN and Classify:workspaces:KNN-Signatures example workspaces.
  37. %
  38. % "SEE ALSO"
  39. % kappend, cknn_signature, cknn_classify
  40. %
  41. % RESTRICTIONS
  42. % Expects the input data files to be in the expected dimensions.
  43. %
  44. % REFERENCES
  45. % All references for the Classify toolbox are listed on the Classify Toolbox Manual.
  46. %
  47. % COPYRIGHT
  48. % Copyright (C) 1997 Rafael Santos. Khoros (C) Khoral Research, Inc.
  49. %
  50. function varargout = kcsigappend(varargin)
  51. if nargin ==0
  52. Inputs={};arglist={'',''};
  53. elseif nargin ==1
  54. Inputs=varargin{1};arglist={'',''};
  55. elseif nargin ==2
  56. Inputs=varargin{1}; arglist=varargin{2};
  57. else error('Usage: [out1,..] = kcsigappend(Inputs,arglist).');
  58. end
  59. if size(arglist,2)~=2
  60. error('arglist must be of form {''ParameterTag1'',value1;''ParameterTag2'',value2}')
  61. end
  62. narglist={'ipre', '__input';'i1', '__input';'i2', '__input';'i3', '__input';'i4', '__input';'i5', '__input';'i6', '__input';'i7', '__input';'i8', '__input';'i9', '__input';'i10', '__input';'o', '__output'};
  63. maxval={1,0,1,1,1,1,1,1,1,1,1,0};
  64. minval={1,0,1,1,1,1,1,1,1,1,1,0};
  65. istoggle=[1,0,1,1,1,1,1,1,1,1,1,0];
  66. was_set=istoggle * 0;
  67. paramtype={'InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','InputFile','OutputFile'};
  68. % identify the input arrays and assign them to the arguments as stated by the user
  69. if ~iscell(Inputs)
  70. Inputs = {Inputs};
  71. end
  72. NumReqOutputs=1; nextinput=1; nextoutput=1;
  73. for ii=1:size(arglist,1)
  74. wasmatched=0;
  75. for jj=1:size(narglist,1)
  76. if strcmp(arglist{ii,1},narglist{jj,1}) % a given argument was matched to the possible arguments
  77. wasmatched = 1;
  78. was_set(jj) = 1;
  79. if strcmp(narglist{jj,2}, '__input')
  80. if (nextinput > length(Inputs))
  81. error(['Input ' narglist{jj,1} ' has no corresponding input!']);
  82. end
  83. narglist{jj,2} = 'OK_in';
  84. nextinput = nextinput + 1;
  85. elseif strcmp(narglist{jj,2}, '__output')
  86. if (nextoutput > nargout)
  87. error(['Output nr. ' narglist{jj,1} ' is not present in the assignment list of outputs !']);
  88. end
  89. if (isempty(arglist{ii,2}))
  90. narglist{jj,2} = 'OK_out';
  91. else
  92. narglist{jj,2} = arglist{ii,2};
  93. end
  94. nextoutput = nextoutput + 1;
  95. if (minval{jj} == 0)
  96. NumReqOutputs = NumReqOutputs - 1;
  97. end
  98. elseif isstr(arglist{ii,2})
  99. narglist{jj,2} = arglist{ii,2};
  100. else
  101. if strcmp(paramtype{jj}, 'Integer') & (round(arglist{ii,2}) ~= arglist{ii,2})
  102. error(['Argument ' arglist{ii,1} ' is of integer type but non-integer number ' arglist{ii,2} ' was supplied']);
  103. end
  104. if (minval{jj} ~= 0 | maxval{jj} ~= 0)
  105. if (minval{jj} == 1 & maxval{jj} == 1 & arglist{ii,2} < 0)
  106. error(['Argument ' arglist{ii,1} ' must be bigger or equal to zero!']);
  107. elseif (minval{jj} == -1 & maxval{jj} == -1 & arglist{ii,2} > 0)
  108. error(['Argument ' arglist{ii,1} ' must be smaller or equal to zero!']);
  109. elseif (minval{jj} == 2 & maxval{jj} == 2 & arglist{ii,2} <= 0)
  110. error(['Argument ' arglist{ii,1} ' must be bigger than zero!']);
  111. elseif (minval{jj} == -2 & maxval{jj} == -2 & arglist{ii,2} >= 0)
  112. error(['Argument ' arglist{ii,1} ' must be smaller than zero!']);
  113. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} < minval{jj})
  114. error(['Argument ' arglist{ii,1} ' must be bigger than ' num2str(minval{jj})]);
  115. elseif (minval{jj} ~= maxval{jj} & arglist{ii,2} > maxval{jj})
  116. error(['Argument ' arglist{ii,1} ' must be smaller than ' num2str(maxval{jj})]);
  117. end
  118. end
  119. end
  120. if ~strcmp(narglist{jj,2},'OK_out') & ~strcmp(narglist{jj,2},'OK_in')
  121. narglist{jj,2} = arglist{ii,2};
  122. end
  123. end
  124. end
  125. if (wasmatched == 0 & ~strcmp(arglist{ii,1},''))
  126. error(['Argument ' arglist{ii,1} ' is not a valid argument for this function']);
  127. end
  128. end
  129. % match the remaining inputs/outputs to the unused arguments and test for missing required inputs
  130. for jj=1:size(narglist,1)
  131. if strcmp(paramtype{jj}, 'Toggle')
  132. if (narglist{jj,2} ==0)
  133. narglist{jj,1} = '';
  134. end;
  135. narglist{jj,2} = '';
  136. end;
  137. if ~strcmp(narglist{jj,2},'__input') && ~strcmp(narglist{jj,2},'__output') && istoggle(jj) && ~ was_set(jj)
  138. narglist{jj,1} = '';
  139. narglist{jj,2} = '';
  140. end;
  141. if strcmp(narglist{jj,2}, '__input')
  142. if (minval{jj} == 0) % meaning this input is required
  143. if (nextinput > size(Inputs))
  144. error(['Required input ' narglist{jj,1} ' has no corresponding input in the list!']);
  145. else
  146. narglist{jj,2} = 'OK_in';
  147. nextinput = nextinput + 1;
  148. end
  149. else % this is an optional input
  150. if (nextinput <= length(Inputs))
  151. narglist{jj,2} = 'OK_in';
  152. nextinput = nextinput + 1;
  153. else
  154. narglist{jj,1} = '';
  155. narglist{jj,2} = '';
  156. end;
  157. end;
  158. else
  159. if strcmp(narglist{jj,2}, '__output')
  160. if (minval{jj} == 0) % this is a required output
  161. if (nextoutput > nargout & nargout > 1)
  162. error(['Required output ' narglist{jj,1} ' is not stated in the assignment list!']);
  163. else
  164. narglist{jj,2} = 'OK_out';
  165. nextoutput = nextoutput + 1;
  166. NumReqOutputs = NumReqOutputs-1;
  167. end
  168. else % this is an optional output
  169. if (nargout - nextoutput >= NumReqOutputs)
  170. narglist{jj,2} = 'OK_out';
  171. nextoutput = nextoutput + 1;
  172. else
  173. narglist{jj,1} = '';
  174. narglist{jj,2} = '';
  175. end;
  176. end
  177. end
  178. end
  179. end
  180. if nargout
  181. varargout = cell(1,nargout);
  182. else
  183. varargout = cell(1,1);
  184. end
  185. global KhorosRoot
  186. if exist('KhorosRoot') && ~isempty(KhorosRoot)
  187. w=['"' KhorosRoot];
  188. else
  189. if ispc
  190. w='"C:\Program Files\dip\khorosBin\';
  191. else
  192. [s,w] = system('which cantata');
  193. w=['"' w(1:end-8)];
  194. end
  195. end
  196. [varargout{:}]=callKhoros([w 'csigappend" '],Inputs,narglist);