📄 visualize_map.m
字号:
function varargout = visualize_map(varargin)
% visualize_maps opens a graphical interface for visaulising MOLMAP results
%
% see the HTML HELP files (help.htm) for extensive explanations, details and examples
%
% The toolbox is freeware and may be used (but not modified)
% if proper reference is given to the authors. Preferably refer to:
% D. Ballabio, V. Consonni, R. Todeschini
% Classification of multiway analytical data based on MOLMAP approach
% Analytica Chimica Acta, in press
%
% version 1.0 - november 2007
% Davide Ballabio
% Milano Chemometrics and QSAR Research Group
% www.disat.unimib.it/chm
% Edit the above text to modify the response to help visualize_map
% Last Modified by GUIDE v2.5 02-Jul-2007 13:31:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @visualize_map_OpeningFcn, ...
'gui_OutputFcn', @visualize_map_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before visualize_map is made visible.
function visualize_map_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
movegui(handles.visualize,'center');
handles.model = varargin{1};
% set temp arrays
handles.temp.top_map = handles.model.res.top_map;
handles.temp.W = handles.model.net.W;
% set variable combo
num_var = size(handles.model.net.W,3);
str_layer{1} = 'none';
for j=1:num_var
str_layer{j+1} = ['variable' num2str(j)];
end
set(handles.pop_layer,'String',str_layer);
set(handles.pop_layer,'Value',1);
% set label combo
str_disp{1} = 'none';
str_disp{2} = 'ID';
str_disp{3} = 'sample identifier';
str_disp{4} = 'profile labels';
handles.sample_label = handles.model.label.label_profile;
if size(varargin{2},1) > 0
str_disp{5} = 'optional labels';
ind = 1;
class = varargin{2};
size_data_1 = size(handles.model.res.score,1);
size_data_2 = size(handles.model.res.top_map,1)/size_data_1;
for k=1:size_data_1; label_class(ind:ind + size_data_2 - 1)=class(k); ind = ind + size_data_2; end;
handles.optional_sample_label = label_class';
end
set(handles.pop_label,'String',str_disp);
set(handles.pop_label,'Value',2);
% set pop_profile
str_prof{1} = 'none';
set(handles.pop_profile,'Enable','on');
set(handles.pop_profile_text,'Enable','on');
num_profiles = length(handles.model.label.label_sample)/size(handles.model.res.score,1);
for j=1:num_profiles
str_prof{j+1} = ['profile ' num2str(j)];
end
set(handles.pop_profile,'String',str_prof);
set(handles.pop_profile,'Value',1);
plot([0 0],'r.')
disp_grid(size(handles.model.net.W,1))
handles = update_plot(handles);
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = visualize_map_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in update_botton.
function update_botton_Callback(hObject, eventdata, handles)
handles = update_plot(handles);
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function pop_layer_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
guidata(hObject,handles)
% --- Executes on selection change in popupmenu
function pop_layer_Callback(hObject, eventdata, handles)
% --- Executes during object creation, after setting all properties.function pop_label_CreateFcn(hObject, eventdata, handles)if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end
% --- Executes during object creation, after setting all properties.
function list_labels_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in pop_label.function pop_label_Callback(hObject, eventdata, handles)
% --- Executes on selection change in pop_label.
function list_labels_Callback(hObject, eventdata, handles)
% --- Executes on button press in button_up.
function button_up_Callback(hObject, eventdata, handles)
handles = move_map(handles,'up');
guidata(hObject,handles)
% --- Executes on button press in botton_down.
function button_down_Callback(hObject, eventdata, handles)
handles = move_map(handles,'down');
guidata(hObject,handles)
% --- Executes on button press in botton_right.
function button_right_Callback(hObject, eventdata, handles)
handles = move_map(handles,'right');
guidata(hObject,handles)
% --- Executes on button press in button_left.
function button_left_Callback(hObject, eventdata, handles)
handles = move_map(handles,'left');
guidata(hObject,handles)
% --- Executes on button press in get_lab_neuron.
function get_lab_neuron_Callback(hObject, eventdata, handles)
handles = set_list_labels(handles);
guidata(hObject,handles)
% --- Executes on button press in get_weight_neuron.
function get_weight_neuron_Callback(hObject, eventdata, handles)
handles = show_weight_neuron(handles);
guidata(hObject,handles)
% --- Executes during object creation, after setting all properties.
function pop_profile_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in pop_profile.
function pop_profile_Callback(hObject, eventdata, handles)
% --- Executes on button press in save_figure.
function save_figure_Callback(hObject, eventdata, handles)
handles = update_plot(handles);
figure
plot([0 0],'r.')
handles = update_plot(handles);
guidata(hObject,handles)
% ---------------------------------------------------------
function disp_grid(n)
axis([0.5 (n + 0.4999) 0.5 (n + 0.5)])
tick_pos = 0.5:1:(n + 0.5);
set(gca,'YTick',tick_pos)
set(gca,'XTick',tick_pos)
grid on
set(gca,'YTickLabel','')
set(gca,'XTickLabel','')
% ---------------------------------------------------------
function handles = update_plot(handles)
cla;
pop_layer_index = get(handles.pop_layer, 'Value');
pop_label_index = get(handles.pop_label, 'Value');
% display weights
if pop_layer_index > 1
var_in = pop_layer_index - 1;
disp_weights(handles,var_in);
end
% display samples
if pop_label_index > 1
handles = disp_samples(handles,pop_label_index);
else
handles.disp_label = [];
end
% display grid
disp_grid(size(handles.model.net.W,1))
% ---------------------------------------------------------function handles = disp_samples(handles,pop_label_index)
pos = handles.temp.top_map;
col_in = get(handles.pop_layer, 'Value');
if col_in > 1
text_color = 'red';
else
text_color = 'black';
end
disp_label = [];
if pop_label_index == 2
for j=1:size(pos,1)
disp_label{j} = num2str(j);
end
elseif pop_label_index == 3 & strcmp(handles.model.type,'multiway')
count = 0;
label_sam = handles.model.label.label_sample;
for i=1:max(label_sam)
for j=1:length(find(label_sam == i))
count = count + 1;
disp_label{count} = [num2str(j) '-s' num2str(i)];
end
end
elseif pop_label_index == 4 & strcmp(handles.model.type,'multiway')
for j=1:size(handles.sample_label,1)
disp_label{j} = num2str(handles.sample_label(j));
end
elseif pop_label_index == 5 & strcmp(handles.model.type,'multiway')
for j=1:size(handles.optional_sample_label,1)
disp_label{j} = num2str(handles.optional_sample_label(j));
end
end
for i=1:size(pos,1)
y_pos = size(handles.model.net.W,1) + 1 - pos(i,1) + 0.3 - rand*0.6;
x_pos = pos(i,2) + 0.3 - rand*0.6;
text(x_pos,y_pos,disp_label{i},'color',text_color,'FontSize',8);
if get(handles.pop_profile, 'Value') > 1
profile_in = get(handles.pop_profile, 'Value') - 1;
if handles.sample_label(i) == profile_in
text(x_pos,y_pos,disp_label{i},'color','b','FontSize',8);
end
end
end
handles.disp_label = disp_label;
% ---------------------------------------------------------
function disp_weights(handles,var_in)
W = squeeze(handles.temp.W(:,:,var_in));
type = 'var';
hold on
for k=1:size(W,1)
for j=1:size(W,2)
if strcmp(type,'ass')
color_in = col_ass(handles.temp.neuron_ass(j,k) + 1,:);
else
color_in = [(1-W(j,k)) (1-W(j,k)) (1-W(j,k))];
end
pos_x = k;
pos_y = size(W,2) + 1 - j;
area([(pos_x - 0.5) (pos_x + 0.5)],[(pos_y + 0.5) (pos_y + 0.5)],pos_y - 0.5,'FaceColor',color_in);
end
end
hold off
% ---------------------------------------------------------function handles = move_map(handles,where)
if strcmp(where,'up')
for i=1:size(handles.temp.top_map,1)
handles.temp.top_map(i,1) = handles.temp.top_map(i,1) - 1;
if handles.temp.top_map(i,1) == 0
handles.temp.top_map(i,1) = size(handles.model.net.W,1);
end
end
for i=1:size(handles.temp.W,1) - 1
temp_W(i,:,:) = handles.temp.W(i + 1,:,:);
end
temp_W(size(handles.temp.W,1),:,:) = handles.temp.W(1,:,:);
handles.temp.W = temp_W;
elseif strcmp(where,'down')
for i=1:size(handles.temp.top_map,1)
handles.temp.top_map(i,1) = handles.temp.top_map(i,1) + 1;
if handles.temp.top_map(i,1) > size(handles.model.net.W,1)
handles.temp.top_map(i,1) = 1;
end
end
for i=1:size(handles.temp.W,1) - 1
temp_W(i+1,:,:) = handles.temp.W(i,:,:);
end
temp_W(1,:,:) = handles.temp.W(size(handles.temp.W,1),:,:);
handles.temp.W = temp_W;
elseif strcmp(where,'right')
for i=1:size(handles.temp.top_map,1)
handles.temp.top_map(i,2) = handles.temp.top_map(i,2) + 1;
if handles.temp.top_map(i,2) > size(handles.model.net.W,2)
handles.temp.top_map(i,2) = 1;
end
end
for i=1:size(handles.temp.W,2) - 1
temp_W(:,i+1,:) = handles.temp.W(:,i,:);
end
temp_W(:,1,:) = handles.temp.W(:,size(handles.temp.W,2),:);
handles.temp.W = temp_W;
elseif strcmp(where,'left')
for i=1:size(handles.temp.top_map,1)
handles.temp.top_map(i,2) = handles.temp.top_map(i,2) - 1;
if handles.temp.top_map(i,2) == 0
handles.temp.top_map(i,2) = size(handles.model.net.W,2);
end
end
for i=1:size(handles.temp.W,2) - 1
temp_W(:,i,:) = handles.temp.W(:,i+1,:);
end
temp_W(:,size(handles.temp.W,2),:) = handles.temp.W(:,1,:);
handles.temp.W = temp_W;
end
handles = update_plot(handles);% ---------------------------------------------------------
function handles = set_list_labels(handles)
[y,x] = ginput(1);
[cord_y,cord_x] = find_neuron(y,x,handles);
in = find(handles.temp.top_map(:,1) == cord_x & handles.temp.top_map(:,2) == cord_y);
if length(in > 0) & length(handles.disp_label) > 0
cur_labs = handles.disp_label(in);
visualize_labels(cur_labs);
end
% ---------------------------------------------------------
function handles = show_weight_neuron(handles)
[y,x] = ginput(1);
[cord_y,cord_x] = find_neuron(y,x,handles);
if cord_y > 0 & cord_y <= size(handles.temp.W,1) & cord_x > 0 & cord_x <= size(handles.temp.W,1)
w = squeeze(handles.temp.W(cord_x,cord_y,:));
figure
if length(w) < 20
bar(w,'r')
else
plot(w,'r')
end
ind = som_which_col(cord_x,cord_y,size(handles.model.net.W,1)^2);
title(['weights of neuron ' num2str(ind) ' (row ' num2str(cord_x) ' - column ' num2str(cord_y) ')'])
axis([0.5 length(w)+0.5 0 1])
xlabel('variables')
ylabel('weight')
end
% ---------------------------------------------------------
function [cord_y,cord_x] = find_neuron(y,x,handles)
x = abs(x - size(handles.model.net.W,1)) + 1;
cord_x = round(x);
cord_y = round(y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -