compare.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. %{/*
  2. Author: Juan Rada-Vilela, Ph.D.
  3. Copyright (C) 2010-2014 FuzzyLite Limited
  4. All rights reserved
  5. This file is part of fuzzylite.
  6. fuzzylite is free software: you can redistribute it and/or modify it under
  7. the terms of the GNU Lesser General Public License as published by the Free
  8. Software Foundation, either version 3 of the License, or (at your option)
  9. any later version.
  10. fuzzylite is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
  13. for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with fuzzylite. If not, see <http://www.gnu.org/licenses/>.
  16. fuzzylite (R) is a registered trademark of FuzzyLite Limited.
  17. */
  18. }%
  19. function [engine] = compare(fisFile, fldFile, delimiter, hasMetadata)
  20. if (nargin < 3)
  21. delimiter = ' ';
  22. end
  23. if (nargin < 4)
  24. hasMetadata = true;
  25. end
  26. engine = readfis(fisFile);
  27. flMatrix = dlmread(fldFile, delimiter, hasMetadata ~ = 0, 0);
  28. if (length(engine.input) + length(engine.output) ~ = size(flMatrix, 2))
  29. error('fuzzylite:compare.m', 'Number of inputs and outputs in engine differ from FLD matrix');
  30. end
  31. if (isempty(engine.andMethod))
  32. engine.andMethod = 'min';
  33. end
  34. if (isempty(engine.orMethod))
  35. engine.orMethod = 'max';
  36. end
  37. engine.inputValues = flMatrix(1 : end, 1 : length(engine.input));
  38. engine.outputValues = evalfis(engine.inputValues, engine);
  39. engine.flOutputValues = flMatrix(1 : end, (length(engine.input) + 1) : (length(engine.input) + length(engine.output)));
  40. engine.outputDiff = engine.outputValues - engine.flOutputValues;
  41. engine.fld = [engine.inputValues engine.outputValues engine.flOutputValues engine.outputDiff];
  42. engine.nanfreeDiff = engine.outputDiff;
  43. engine.nanfreeDiff(find(isnan(engine.nanfreeDiff))) = 0;
  44. engine.mse = nansum(engine.outputDiff.^2) / size(engine.outputDiff, 1);
  45. engine.quantiles = prctile(engine.nanfreeDiff, 0 : 25 : 100);
  46. end