function NeuralNetDecisionBoundaryPlot(syn_wts,plot_symbol_str,bounding_box) % Plot decision boundaries of two-input (plus threshold) neurons. % % Decision boundary = line where sum of wts * inputs = 0. % syn_wts = 3 cols for w0, w1, w2 and one row for each neuron. % plot_symbol_str = 'r-' (red line) or similar string for plot command. % bounding_box = [x1min, x1max, x2min, x2max] % Extract bounding box parameters for clarity. x1min = bounding_box(1); x1max = bounding_box(2); x2min = bounding_box(3); x2max = bounding_box(4); % Plot the x1 and x2 axes in black inside bounding box. plot([x1min, x1max],[0,0],'k-') hold on plot([0,0],[x2min, x2max],'k-') axis(bounding_box) % Step through neurons. for neuron_index = 1:size(syn_wts,1) % Extract wts for this neuron, for convenience and clarity. w0 = syn_wts(neuron_index,1); w1 = syn_wts(neuron_index,2); w2 = syn_wts(neuron_index,3); % Determine endpoints of decision boundary intersect bounding box. if abs(w2) < 10*eps % vertical decision boundary, solve for x1 values at endpts. x1_left = -w0/w1; x2_left = x2min; x1_right = -w0/w1; x2_right = x2max; else x1_left = x1min; x2_left = (-w0 -w1*x1min)/w2; x1_right = x1max; x2_right = (-w0 -w1*x1max)/w2; end plot([x1_left,x1_right],[x2_left,x2_right],plot_symbol_str) end hold off return