File: newfis.m

package info (click to toggle)
octave-fuzzy-logic-toolkit 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,024 kB
  • sloc: makefile: 147
file content (127 lines) | stat: -rw-r--r-- 5,738 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
## Copyright (C) 2011-2025 L. Markowsky <lmarkowsky@gmail.com>
##
## This file is part of the fuzzy-logic-toolkit.
##
## The fuzzy-logic-toolkit is free software; you can redistribute it
## and/or modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; either version 3 of
## the License, or (at your option) any later version.
##
## The fuzzy-logic-toolkit is distributed in the hope that it will be
## useful, but WITHOUT ANY WARRANTY; without even the implied warranty
## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with the fuzzy-logic-toolkit; see the file COPYING.  If not,
## see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn {Function File} {@var{a} =} newfis (@var{fis_name})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method}, @var{or_method})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method}, @var{or_method}, @var{imp_method})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method}, @var{or_method}, @var{imp_method}, @var{agg_method})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method}, @var{or_method}, @var{imp_method}, @var{agg_method}, @var{defuzz_method})
## @deftypefnx {Function File} {@var{a} =} newfis (@var{fis_name}, @var{fis_type}, @var{and_method}, @var{or_method}, @var{imp_method}, @var{agg_method}, @var{defuzz_method}, @var{fis_version})
##
## Create and return a new FIS structure using the argument values provided.
## Only the first argument is required. If fewer than eight arguments are given,
## then some or all of the following default values will be used:
##
## @multitable @columnfractions .30 .30
## @headitem Argument @tab Default Value
## @item @var{fis_type}
## @tab  'mamdani'
## @item @var{and_method}
## @tab  'min'
## @item @var{or_method}
## @tab  'max'
## @item @var{imp_method}
## @tab  'min'
## @item @var{agg_method}
## @tab  'max'
## @item @var{defuzz_method}
## @tab  'centroid'
## @item @var{fis_version}
## @tab  1.0
## @end multitable
## @sp 1
## @seealso{addmf, addrule, addvar, setfis}
## @end deftypefn

## Author:        L. Markowsky
## Keywords:      fuzzy-logic-toolkit fuzzy inference system fis
## Directory:     fuzzy-logic-toolkit/inst/
## Filename:      newfis.m
## Last-Modified: 12 Jun 2024

function fis = newfis (fis_name, fis_type = 'mamdani', ...
                       and_method = 'min', or_method = 'max', ...
                       imp_method = 'min', agg_method = 'max', ...
                       defuzz_method = 'centroid', fis_version = 1.0)

  ## If the caller did not supply the between 1 and 8 argument values,
  ## or if any of the argument values were not strings, print an error
  ## message and halt.

  if (!(nargin >= 1 && nargin <= 8))
    error ("newfis requires between 1 and 8 arguments\n");
  elseif (!(is_string (fis_name) && is_string (fis_type) && ...
           is_string (and_method) && is_string (or_method) && ...
           is_string (imp_method) && is_string (agg_method) && ...
           is_string (defuzz_method) && isfloat (fis_version)))
    error ("incorrect argument type in newfis argument list\n");
  endif

  ## Create and return the new FIS structure.

  fis = struct ('name', fis_name, ...
                'type', fis_type, ...
                'version', fis_version, ...
                'andMethod', and_method, ...
                'orMethod', or_method, ...
                'impMethod', imp_method, ...
                'aggMethod', agg_method, ...
                'defuzzMethod', defuzz_method, ...
                'input', [], ...
                'output', [], ...
                'rule', []);
endfunction

%!shared fis
%! fis = newfis ('Heart-Disease-Risk', 'sugeno', ...
%!               'min', 'max', 'min', 'max', 'wtaver');

%!assert(fis.name == 'Heart-Disease-Risk');
%!assert(fis.type == 'sugeno');
%!assert(fis.andMethod == 'min');
%!assert(fis.orMethod == 'max');
%!assert(fis.impMethod == 'min');
%!assert(fis.aggMethod == 'max');
%!assert(fis.defuzzMethod == 'wtaver');

## Test input validation
%!error <newfis requires between 1 and 8 arguments>
%! newfis()
%!error <newfis: function called with too many inputs>
%! newfis(1, 2, 3, 4, 5, 6, 7, 8, 9)
%!error <incorrect argument type in newfis argument list>
%! newfis(1, 'str', 'str', 'str', 'str', 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis(1, 'str', 'str', 'str', 'str', 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 2, 'str', 'str', 'str', 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 3, 'str', 'str', 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 'str', 4,  'str', 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 'str', 'str', 5, 'str', 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 'str', 'str', 'str', 6, 'str', 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 'str', 'str', 'str', 'str', 7, 8)
%!error <incorrect argument type in newfis argument list>
%! newfis('str', 'str', 'str', 'str', 'str', 'str', 'str', 'str')