⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nnd13h.m

📁 Martin T.Hagan等著,戴葵等译,神经网络设计,机械工业出版社,一书的所有例程
💻 M
📖 第 1 页 / 共 2 页
字号:
      'color',nndkblue)
  end

  % SCAN FRUIT
  pause2(0.5)
  set(fig,'nextplot','add')
  h1 = fill([170 130 130 170],[35 35 39 39],[1 1 1],...
    'edgecolor','none',...
    'erasemode','none');
  h2 = fill([170 130 130 170],[41 41 58 58],[1 1 1],...
    'edgecolor','none',...
    'erasemode','none');
  set(fruit,...
   'facecolor',[1 1 1])

  t1 = clock;
  sound(scan,Fs);
  while etime(clock,t1) < 1, end

  set(h1,'facecolor',nnltgray)
  set(h2,'facecolor',nnltgray)
  delete(h1)
  delete(h2)
  set(fruit,...
    'facecolor',fruit_c)
  set(fig,'nextplot','new')
  pause2(0.5)

  % MOVE DATA FROM SCANNER TO NETWORK & DISPLAY
  xx = [157 188 NaN 162 188 NaN 167 188 NaN, ...
        142 140 140 NaN 137 130 130 NaN 132 120 120];
  yy = [90 90 NaN 80 80 NaN 70 70 NaN, ...
        90 90 110 NaN 80 80 110 NaN 70 70 110];
  set(fig,'nextplot','add')

  sound(blip,Fs);
  data = plot(xx,yy,...
    'color',[1 1 1],...
    'erasemode','none',...
    'linewidth',2);
  for j=1:3
    if j == 1, str = 'SHAPE: ';
    elseif j == 2, str = 'TEXTURE: ';
    else str = 'WEIGHT: '; end

    if p(j) >= 0
      sign = '+';
    else
      sign = '-';
    end

    set(p_text(j),...
      'color',nndkblue)
    set(p_text(j),...
      'string',[str,sign,num2str(abs(p(j)))],...
      'color',nngreen)
  end

  pause2(0.5);
  sound(bloop,Fs);
  set(data,...
    'color',nndkblue)
  delete(data);

  % CLASSIFY FRUIT
  pause2(0.5)
  sound(blip,Fs);
  set(nnet(1),...
    'edgecolor',[1 1 1],...
    'facecolor',nndkblue)
  set(nnet(2:3),...
    'color',[1 1 1])
  axes(fig_axis);
  pause2(0.5)
  sound(bloop,Fs);
  set(nnet(1),...
    'edgecolor',[1 0 0],...
    'facecolor',nndkblue)
  set(nnet(2:3),...
    'color',[0 1 0])

  % CALL CLASSIFICATION ROUTINE
  t1 = clock;
  sound(classify,Fs);
  while etime(clock,t1) < 2, end

  feval(me,'classify')
  pause2(0.5)

  % MOVE DATA FROM NETWORK TO EXIT
  xx = [252 268];
  yy = [80 80];
  set(fig,'nextplot','add')
  sound(blip,Fs);
  data = plot(xx,yy,...
    'color',[1 1 1],...
    'erasemode','none',...
    'linewidth',2);
  set(indicators(fruit_id+1),...
     'color',[1 1 1])
  axes(fig_axis)
  if fruit_id == 1
    box_x = 84;
  else
    box_x = 62;
  end
  box = plot([0 62 62 0 0]+314,[0 0 14 14 0]+box_x,...
    'color',[1 1 1],...
    'erasemode','none');

  pause2(0.5);
  sound(bloop,Fs);
  set(data,...
    'color',nndkblue)
  delete(data);
    
  % MOVE FRUIT TO EXIT
  for dx=70:10:200
    t1 = clock;
    sound(blp,Fs);
    while etime(clock,t1) < 0.1, end
    set(fruit, ...
      'facecolor',nnltgray, ...
      'edgecolor',nnltgray);
    set(fruit, ...
      'facecolor',fruit_c, ...
      'edgecolor',fruit_c*0.5, ...
      'xdata',fruit_x + x + dx)
    angle = angle + 20;
    adata = [0 pi]-angle*deg;
    xdata = cos(adata)*8;
    ydata = sin(adata)*8+30;
    set(lines,'color',nnred);
    set(lines(1),...
      'xdata',xdata+50,...
      'ydata',ydata,...
      'color',nndkblue)
    set(lines(2),...
      'xdata',xdata+330,...
      'ydata',ydata,...
      'color',nndkblue)
  end

  % REMOVE FRUIT
  pause(1)
  sound(blip,Fs);
  set(fruit,...
    'facecolor',nnltgray,...
    'edgecolor',nnltgray);
  delete(fruit)
  set(arrows(2),...
    'facecolor',nnred)
  sound(wind,Fs);
  set(arrows(2),...
    'facecolor',nndkblue)

  % UNLIGHT APPROPRIATE INDICATOR
  pause(1)
  sound(bloop,Fs);
  set(indicators(fruit_id+1),...
    'color',fruit_c)
  set(box,...
    'color',nndkblue)
  delete(box)
  set(fig,'nextplot','new')

  % SAVE DATA
  set(angle_ptr,'userdata',angle);
  set(fruit_ptr,'userdata',fruit);
  set(id_ptr,'userdata',fruit_id);

%==================================================================
% Remove previous fruit (activated by hitting "Clear" button).
%
% ME('remove')
%==================================================================

elseif strcmp(cmd,'remove') & (fig) & (nargin == 1)
  
  % GET DATA
  wind = get(sounds(1),'userdata');
  blip = get(sounds(5),'userdata');
  bloop = get(sounds(6),'userdata');
  fruit = get(fruit_ptr,'userdata');
  fruit_id = get(id_ptr,'userdata');
  axes(fig_axis);

  % GET RID OF PREVIOUS FRUIT
  if length(fruit) > 0

    % FRUIT COLOR
    if (fruit_id == 1)
      fruit_c = [1 0.5 0];
    else
      fruit_c = [1 0 0];
    end

    % UNLIGHT APPROPRIATE INDICATOR
    pause(1)
    sound(bloop,Fs);
    set(indicators(fruit_id+1),...
      'color',fruit_c)

    % CLEAR VALUES
    set(p_text,...
      'color',nndkblue)
    set(p_text(1),...
      'string','SHAPE: ?',...
      'color',nnltgray)
    set(p_text(2),...
      'string','TEXTURE: ?',...
      'color',nnltgray)
    set(p_text(3),...
      'string','WEIGHT: ?',...
      'color',nnltgray)

    % CLEAR NETWORK DEPENDENT STUFF
    feval(me,'clear')

    % STORE DATA
    set(fruit_ptr,'userdata',[]);
  end

%==================================================================
% Setup network specific parts of window.
%
% ME('setup')
%==================================================================

elseif strcmp(cmd,'setup') & (fig) & (nargin == 1)

  set(fig,'nextplot','add')

  % EXPRESSION
  x = 230;
  text(x,340,'W = [0 1 0]',...
    'color',nndkblue,...
    'fontweight','bold')
  text(x,310,'b = 0',...
    'color',nndkblue,...
    'fontweight','bold')
  line1 = text(x,280,'p = [?; ?; ?]',...
    'color',nnltgray,...
    'erasemode','none',...
    'fontweight','bold');
  line2 = text(x,250,'a = hardlims(W*p+b)',...
    'color',nnltgray,...
    'erasemode','none',...
    'fontweight','bold');
  line3 = text(x,220,'a = hardlims(?)',...
    'color',nnltgray,...
    'erasemode','none',...
    'fontweight','bold');
  line4 = text(x,190,'a = ?',...
    'color',nnltgray,...
    'erasemode','none',...
    'fontweight','bold');
  line5 = text(x,160,'Fruit = ?',...
    'color',nnltgray,...
    'erasemode','none',...
    'fontweight','bold');

  % INPUT SPACE AXES
  %ext = 1.25;
  %input_axis = nnsfo('a4','Input Space','shape','texture','weight');
  %set(input_axis,...
  %  'xlim',[-1 1]*ext,'xtick',[-1 1],...
  %  'ylim',[-1 1]*ext,'ytick',[-1 1],...
  %  'zlim',[-1 1]*ext,'ztick',[-1 1],...
  %  'pos',[48 175 140 140],...
  %  'box','off');
  %view(3)
  %
  % EDGE
  %edge = plot3([-1 -1 -1 1 1 1 -1]*ext,[-1 1 1 1 -1 -1 -1]*ext,...
  %  [-1 -1 1 1 1 -1 -1]*ext,...
  %  'color',nndkblue,...
  %  'erasemode','none');
  %
  % BOX
  %box1 = plot3([-1 1 1 -1 -1],[-1 -1 -1 -1 -1],[-1 -1 1 1 -1],':',...
  %  'color',nndkblue,...
  %  'erasemode','none');
  %box2 = plot3([-1 1 1 -1 -1],[1 1 1 1 1],[-1 -1 1 1 -1],':',...
  %  'color',nndkblue,...
  %  'erasemode','none');
  %box3 = plot3([-1 -1 -1 -1 -1],[-1 1 1 -1 -1],[-1 -1 1 1 -1],':',...
  %  'color',nndkblue,...
  %  'erasemode','none');
  %box4 = plot3([1 1 1 1 1],[-1 1 1 -1 -1],[-1 -1 1 1 -1],':',...
  %  'color',nndkblue,...
  %  'erasemode','none');
  %
  %boundary = plot3([-1 1 1 -1 -1],[0 0 0 0 0],[-1 -1 1 1 -1],...
  %  'color',nndkblue,...
  %  'linewidth',2,...
  %  'erasemode','none');
  %
  % PROTOTYPE ORANGE
  %orange_dot = plot3(1,-1,-1,'.',...
  %  'markersize',25,...
  %  'color',[1 0.5 0],...
  %  'erasemode','none');
  %
  % PROTOTYPE APPLE
  %apple_dot = plot3(1,1,-1,'.',...
  %  'markersize',25,...
  %  'color',[1 0 0],...
  %  'erasemode','none');
  %
  % STORE DATA
  %p_mark_ptr = uicontrol('visible','off','userdata',[]);
  %H = [input_axis, ...
  %     orange_dot apple_dot,...
  %     edge box1 box2 box3 box4 boundary,...
  %     line1 line2 line3 line4 line5,...
  %     p_mark_ptr];
  %set(net_ptr,'userdata',H);

  set(fig,'nextplot','new')

%==================================================================
% Classify fruit with network.
%
% ME('classify')
%==================================================================

elseif strcmp(cmd,'classify') & (fig) & (nargin == 1)

  % GET DATA
  p = get(p_ptr,'userdata');
  H = get(net_ptr,'userdata');
  input_axis = H(1);           % handle to input space axis
  dots = H(2:3);               % handles to orange & apple dots
  frame = H(4:9);              % frame & boundary
  lines = H(10:14);            % lines of text (starting with "p = ...")
  p_mark_ptr = H(15);          % pointer to input marks

  axes(input_axis);
  set(fig,'nextplot','add')

  % SHOW INPUT LINES
  p1 = p(1);
  p2 = p(2);
  p3 = p(3);
  p_marks = plot3([p1 p1 NaN p1 p1 NaN -1 1],[p2 p2 NaN -1 1 NaN p2 p2],...
    [-1 1 NaN p3 p3 NaN p3 p3],'-',...
    'color',nngreen,...
    'erasemode','none',...
    'markersize',15);
  
  % FLASH INPUT LINES
  for i=1:8
    pause2(0.15)
    set(p_marks,...
      'color',nnltyell)
    set(dots(1),...
      'color',[1 0.5 0])
    set(dots(2),...
      'color',[1 0 0])
    set(frame,...
      'color',nndkblue)
    pause2(0.1)
    set(p_marks,...
      'color',nngreen)
  end

  % PERFORM CALCULATION
  n = [0 1 0]*p+0;
  n = round(n*100)/100;
  a = hardlims(n);
  if (a<0)
    fruit_str = 'Orange';
    fruit_c = [1 0.5 0];
  else
    fruit_str = 'Apple';
    fruit_c = [1 0 0];
  end

  % SHOW CALCULATION
  for i=1:5
    if i == 1
      str = ['p = [',num2str(p1),';',num2str(p2),';',num2str(p3),']'];
    elseif i == 2
      str = 'a = hardlims(W*p+b)';
    elseif i == 3
      str = ['a = hardlims(' num2str(n) ')'];
    elseif i == 4
      str = ['a = ' num2str(a)];
    else
      str = ['Fruit = ' fruit_str];
    end
    pause(2)
    set(lines(i),...
      'string',str,...
      'color',nndkblue)
  end

  set(p_mark_ptr,'userdata',p_marks)
  set(fig,'nextplot','new')

%==================================================================
% Clear fruit calculations.
%
% ME('clear')
%==================================================================

elseif strcmp(cmd,'clear') & (fig) & (nargin == 1)

  % GET DATA
  p = get(p_ptr,'userdata');
  H = get(net_ptr,'userdata');
  input_axis = H(1);           % handle to input space axis
  dots = H(2:3);               % handles to orange & apple dots
  frame = H(4:9);              % frame & boundary
  lines = H(10:14);            % lines of text (starting with "p = ...")
  p_mark_ptr = H(15);          % pointer to input marks

  % HIDE INPUT LINES
  p_marks = get(p_mark_ptr,'userdata');
  set(p_marks,...
    'color',nnltyell)
  delete(p_marks)
  set(dots(1),...
    'color',[1 0.5 0])
  set(dots(2),...
    'color',[1 0 0])
  set(frame,...
    'color',nndkblue)
  
  % HIDE CALCULATION
  set(lines,...
    'color',nnltgray)
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -