gusucode.com > Matlab脸部识别程序源码 > code/code/perceptron.m

    

  function [outputs] = perceptron(weights,data)
  % function [outputs] = perceptron(weights,data)
  %
  %  Compute the class predictions for perceptron (linear classifier)
  %                            A. Student, ICS 175A
  %
  %  Inputs
  %     weights: 1 x (d+1) row vector of weights
  %     data:  N x (d+1) matrix of training data
  %
  %  Outputs
  %     outputs: N x 1 vector of perceptron outputs
 
  % error checking
  if size(weights,1) ~= 1
      error('The first argument (weights) should be a row vector');
  end
  if size(data,2) ~= size(weights,2)
      error('The arguments (weights and data) should have the same number of columns');
  end

  % calculate the thresholded output of the perceptron
  outputs = sign(data*weights');