function perf = mypf(e,x,pp)
%MYPF Example custom performance function.
%
%	Use this function as a template to write your own function.
%	
%	Calculation Syntax
%
%	  perf = mypf(E,X,PP)
%	    E  - Matrix or cell array of error vector(s).
%	    X  - Vector of all weight and bias values.
%	    PP - Performance parameter.
%
%	  perf = mypf(E,net)
%
%	Information Syntax
%
%	  info = mytf(code) returns useful information for each CODE string:
%	    'version' - Returns the Neural Network Toolbox version (3.0).
%	    'deriv'   - Returns the name of the associated derivative function.
%	    'output'  - Returns the output range.
%	    'active'  - Returns the active input range.
%
%	Example
%
%	  e = rand(4,5);
%	  x = rand(12,1);
%	  pp = mypf('pdefaults')
%	  perf = mypf(e,x,pp)
% $Revision: 1.1 $

if nargin < 1, error('Not enough arguments.'); end

if isstr(e)
  switch (e)
    case 'version'
	  perf = 3.0;         % <-- Must be 3.0.
	  
    case 'deriv',
	  perf = 'mydpf';     % <-- Replace with the name of your
	                      %     associated function or ''

    case 'pdefaults'
	  perf.x = 1;         % <-- Replace with the your own performance
	  perf.y = 0.5;       % <-- parameter structure or null matrix [].
					  
    otherwise, error('Unrecognized code.')
  end

else

  if isa(e,'cell')
    e = cell2mat(e);
  end

  % ** delete the first expression below if you don't use PP, and
  % ** the second if you don't use the weight and bias vector X.
  
  if nargin == 2
    pp = x.performParam;
	x = getx(net);
  end
  
  % ** Replace the following calculation with your own
  % ** measure of performance.
  
  numErrors = prod(size(e));
  numWeightsBiases = length(x);
  perf =  sum(sum(abs(e))) * pp.x/numErrors + ...
     sum(abs(x)) * pp.y/numWeightsBiases;

end
