annotate toolboxes/MIRtoolbox1.3.2/somtoolbox/sompak_rb_control.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function varargout=sompak_rb_control(str)
wolffd@0 2
wolffd@0 3 %SOMPAK_RB_CONTROL An auxiliary function for SOMPAK_*_GUI functions.
wolffd@0 4 %
wolffd@0 5 % This is an auxiliary function for SOMPAK_GUI, SOMPAK_INIT_GUI,
wolffd@0 6 % SOMPAK_SAMMON_GUI and SOMPAK_TRAIN_GUI functions. It controls the
wolffd@0 7 % radio buttons in the GUIs.
wolffd@0 8 %
wolffd@0 9 % See also SOMPAK_GUI, SOMPAK_INIT_GUI, SOMPAK_SAMMON_GUI, SOMPAK_TRAIN_GUI.
wolffd@0 10
wolffd@0 11 % Contributed to SOM Toolbox vs2, February 2nd, 2000 by Juha Parhankangas
wolffd@0 12 % Copyright (c) by Juha Parhankangas
wolffd@0 13 % http://www.cis.hut.fi/projects/somtoolbox/
wolffd@0 14
wolffd@0 15 % Juha Parhankangas 050100
wolffd@0 16
wolffd@0 17 data=get(gcf,'UserData');
wolffd@0 18 switch str
wolffd@0 19 case {'rand','linear'}
wolffd@0 20 h=cat(2,findobj(get(gcf,'Children'),'Tag','RANDOM'),...
wolffd@0 21 findobj(get(gcf,'Children'),'Tag','LINEAR'));
wolffd@0 22 set(h,'Value',0);
wolffd@0 23 set(gcbo,'Value',1);
wolffd@0 24 data.inittype=str;
wolffd@0 25 case {'bubble','gaussian'}
wolffd@0 26 h=cat(2,findobj(get(gcf,'Children'),'Tag','BUBBLE'),...
wolffd@0 27 findobj(get(gcf,'Children'),'Tag','GAUSSIAN'));
wolffd@0 28 set(h,'Value',0);
wolffd@0 29 set(gcbo,'Value',1);
wolffd@0 30 data.neigh=str;
wolffd@0 31 case {'hexa','rect'}
wolffd@0 32 h=cat(2,findobj(get(gcf,'Children'),'Tag','HEXA'),...
wolffd@0 33 findobj(get(gcf,'Children'),'Tag','RECT'));
wolffd@0 34 set(h,'Value',0);
wolffd@0 35 set(gcbo,'Value',1);
wolffd@0 36 data.topol=str;
wolffd@0 37 case {'out_ft'}
wolffd@0 38 value=get(gcbo,'Value');
wolffd@0 39 switch value
wolffd@0 40 case 1
wolffd@0 41 h=findobj(get(gcf,'Children'),'Tag','OUT_FILE');
wolffd@0 42 data.out_file_type='';
wolffd@0 43 set(h,'String','');
wolffd@0 44 case 2
wolffd@0 45 data.out_file_type='box';
wolffd@0 46 case 3
wolffd@0 47 data.out_file_type='pak';
wolffd@0 48 end
wolffd@0 49 case {'input_ft'}
wolffd@0 50 value=get(gcbo,'Value');
wolffd@0 51 switch value
wolffd@0 52 case 1
wolffd@0 53 data.input_file_type='';
wolffd@0 54 case 2
wolffd@0 55 data.input_file_type='box';
wolffd@0 56 case 3
wolffd@0 57 data.input_file_type='pak';
wolffd@0 58 end
wolffd@0 59 case {'map_ft'}
wolffd@0 60 value=get(gcbo,'Value');
wolffd@0 61 switch value
wolffd@0 62 case 1
wolffd@0 63 data.map_type='';
wolffd@0 64 case 2
wolffd@0 65 data.map_type='box';
wolffd@0 66 case 3
wolffd@0 67 data.map_type='pak';
wolffd@0 68 end
wolffd@0 69 case {'out_file'}
wolffd@0 70 if isempty(data.out_file_type)
wolffd@0 71 data.out_file='';
wolffd@0 72 h=findobj(get(gcf,'Children'),'Tag','OUT_FILE');
wolffd@0 73 set(h,'String','');
wolffd@0 74 else
wolffd@0 75 data.out_file=get(findobj(get(gcf,'Children'),'Tag','OUT_FILE'),'String');
wolffd@0 76 if isempty(data.out_file)
wolffd@0 77 h=findobj(get(gcf,'Children'),'Tag','OUT_FILE_TYPE');
wolffd@0 78 set(h,'Value',1);
wolffd@0 79 end
wolffd@0 80 end
wolffd@0 81
wolffd@0 82 case {'out_var'}
wolffd@0 83 h=findobj(get(gcf,'Children'),'Tag','OUT_VAR');
wolffd@0 84 if ~isempty(get(h,'String'))
wolffd@0 85 data.out_var=get(h,'String');
wolffd@0 86 else
wolffd@0 87 data.out_var=[];
wolffd@0 88 set(h,'String','''ans''');
wolffd@0 89 end
wolffd@0 90 case {'xdim'}
wolffd@0 91 h=findobj(get(gcf,'Children'),'Tag','XDIM');
wolffd@0 92 data.xdim=str2num(get(h,'String'));
wolffd@0 93 case {'ydim'}
wolffd@0 94 h=findobj(get(gcf,'Children'),'Tag','YDIM');
wolffd@0 95 data.ydim=str2num(get(h,'String'));
wolffd@0 96 case {'radius'}
wolffd@0 97 h=findobj(get(gcf,'Children'),'Tag','RADIUS');
wolffd@0 98 data.radius=str2num(get(h,'String'));
wolffd@0 99 case {'data'}
wolffd@0 100 h=findobj(get(gcf,'Children'),'Tag','DATA');
wolffd@0 101 data.data=get(h,'String');
wolffd@0 102 case {'rlen'}
wolffd@0 103 h=findobj(get(gcf,'Children'),'Tag','RLEN');
wolffd@0 104 data.rlen=str2num(get(h,'String'));
wolffd@0 105 case {'alpha'}
wolffd@0 106 h=findobj(get(gcf,'Children'),'Tag','ALPHA');
wolffd@0 107 data.alpha=str2num(get(h,'String'));
wolffd@0 108 case {'map'}
wolffd@0 109 h=findobj(get(gcf,'Children'),'Tag','MAP');
wolffd@0 110 data.map=get(h,'String');
wolffd@0 111 case 'init_ok'
wolffd@0 112 if isempty(data.xdim) | ~is_positive_integer(data.xdim)
wolffd@0 113 errordlg('Argument ''xdim'' must be positive integer.');
wolffd@0 114 return;
wolffd@0 115 end
wolffd@0 116 if isempty(data.ydim) | ~is_positive_integer(data.ydim)
wolffd@0 117 errordlg('Argument ''ydim'' must be positive integer.');
wolffd@0 118 return;
wolffd@0 119 end
wolffd@0 120 if isempty(data.data)
wolffd@0 121 errordlg('Argument ''Workspace data'' must be a string.');
wolffd@0 122 return;
wolffd@0 123 end
wolffd@0 124
wolffd@0 125 if isempty(data.input_file_type)
wolffd@0 126 sData=evalin('base',data.data);
wolffd@0 127 else
wolffd@0 128 sData=data.data;
wolffd@0 129 end
wolffd@0 130 if isempty(data.out_file)
wolffd@0 131 if ~isempty(data.out_file_type)
wolffd@0 132 errordlg('Argument ''Output file'' is not defined.');
wolffd@0 133 return;
wolffd@0 134 end
wolffd@0 135 data.out_file=[];
wolffd@0 136 end
wolffd@0 137 answer=sompak_init(sData,...
wolffd@0 138 data.input_file_type,...
wolffd@0 139 data.inittype,...
wolffd@0 140 data.out_file,...
wolffd@0 141 data.out_file_type,...
wolffd@0 142 data.xdim,...
wolffd@0 143 data.ydim,...
wolffd@0 144 data.topol,...
wolffd@0 145 data.neigh);
wolffd@0 146 if any(strcmp(data.out_var,{'ans','''ans'''})) | isstr(answer)
wolffd@0 147 varargout{1}=answer;
wolffd@0 148 else
wolffd@0 149 assignin('base',data.out_var,answer);
wolffd@0 150 disp(sprintf('Map is set to workspace as ''%s''.',data.out_var));
wolffd@0 151 end
wolffd@0 152 close(findobj(get(0,'Children'),'Tag','InitGUI'));
wolffd@0 153 return;
wolffd@0 154 case 'train_ok'
wolffd@0 155 if isempty(data.rlen) | ~is_positive_integer(data.rlen)
wolffd@0 156 errordlg('Argument ''Running Length'' must be positive integer.');
wolffd@0 157 return;
wolffd@0 158 end
wolffd@0 159 if isempty(data.alpha) | data.alpha <= 0
wolffd@0 160 errordlg('Argument ''Initial Alpha Value'' must be a positive float.');
wolffd@0 161 return;
wolffd@0 162 end
wolffd@0 163 if isempty(data.radius) | data.radius <= 0
wolffd@0 164 errordlg('Argument ''Neighborhood Radius'' must be a positive float.');
wolffd@0 165 return;
wolffd@0 166 end
wolffd@0 167 if isempty(data.data)
wolffd@0 168 errordlg('Argument ''Teaching Data'' must be a string.');
wolffd@0 169 return;
wolffd@0 170 end
wolffd@0 171 if isempty(data.input_file_type)
wolffd@0 172 sData=evalin('base',data.data);
wolffd@0 173 else
wolffd@0 174 sData=data.data;
wolffd@0 175 end
wolffd@0 176 if isempty(data.out_file);
wolffd@0 177 data.outfile = [];
wolffd@0 178 end
wolffd@0 179 if isempty(data.map)
wolffd@0 180 errordlg('Argument ''Workspace Map'' must be a string.');
wolffd@0 181 return;
wolffd@0 182 end
wolffd@0 183 if isempty(data.map_type)
wolffd@0 184 sMap=evalin('base',data.map);
wolffd@0 185 else
wolffd@0 186 sMap=data.map;
wolffd@0 187 end
wolffd@0 188
wolffd@0 189 answer=sompak_train(sMap,...
wolffd@0 190 data.map_type,...
wolffd@0 191 data.out_file,...
wolffd@0 192 data.out_file_type,...
wolffd@0 193 data.data,...
wolffd@0 194 data.input_file_type,...
wolffd@0 195 data.rlen,...
wolffd@0 196 data.alpha,...
wolffd@0 197 data.radius);
wolffd@0 198 if any(strcmp(data.out_var,{'''ans''','ans'})) | isstr(answer)
wolffd@0 199 varargout{1}=answer;
wolffd@0 200 else
wolffd@0 201 assignin('base',data.out_var,answer);
wolffd@0 202 disp(sprintf('Map is set to workspace as ''%s''.',data.out_var));
wolffd@0 203 end
wolffd@0 204 close(findobj(get(0,'Children'),'Tag','TrainGUI'));
wolffd@0 205 return;
wolffd@0 206 case 'sammon_ok'
wolffd@0 207 if isempty(data.map)
wolffd@0 208 errordlg('Argument ''Workspace Map'' must be a string.');
wolffd@0 209 return;
wolffd@0 210 end
wolffd@0 211 if isempty(data.map_type)
wolffd@0 212 sMap=evalin('base',data.map);
wolffd@0 213 else
wolffd@0 214 sMap=data.map;
wolffd@0 215 end
wolffd@0 216 if isempty(data.out_file);
wolffd@0 217 data.outfile = [];
wolffd@0 218 end
wolffd@0 219 answer=sompak_sammon(sMap,...
wolffd@0 220 data.map_type,...
wolffd@0 221 data.out_file,...
wolffd@0 222 data.out_file_type,...
wolffd@0 223 data.rlen);
wolffd@0 224 if strcmp(data.out_var,'''ans''')|strcmp(data.out_var,'ans')|isstr(answer)
wolffd@0 225 varargout{1}=answer;
wolffd@0 226 else
wolffd@0 227 assignin('base',data.out_var,answer);
wolffd@0 228 disp(sprintf('Codebook is set to workspace as ''%s''.',data.out_var));
wolffd@0 229 end
wolffd@0 230 close(findobj(get(0,'Children'),'Tag','SammonGUI'));
wolffd@0 231 return;
wolffd@0 232 end
wolffd@0 233
wolffd@0 234 set(gcf,'UserData',data);
wolffd@0 235
wolffd@0 236 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 237
wolffd@0 238 function bool = is_positive_integer(x)
wolffd@0 239
wolffd@0 240 bool = ~isempty(x) & isreal(x) & all(size(x) == 1) & x > 0;
wolffd@0 241 if ~isempty(bool)
wolffd@0 242 if bool & x~=round(x)
wolffd@0 243 bool = 0;
wolffd@0 244 end
wolffd@0 245 else
wolffd@0 246 bool = 0;
wolffd@0 247 end
wolffd@0 248
wolffd@0 249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
wolffd@0 250
wolffd@0 251
wolffd@0 252