File: aggregate_output_mamdani.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 (93 lines) | stat: -rw-r--r-- 3,811 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
## 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{fuzzy_output} =} aggregate_output_mamdani (@var{fis}, @var{rule_output})
##
## Given the:
## @itemize @bullet
## @item @var{fis.aggMethod:}
## the aggregation method for the given @var{fis}
## @item @var{rule_output:}
## a matrix of the fuzzy output for each (rule, FIS output) pair
## @end itemize
##
## Return:
## @itemize @bullet
## @item @var{fuzzy_output:}
## a matrix of the aggregated output for each FIS output variable
## @end itemize
##
## @var{rule_output} is a @var{num_points} x (Q * M) matrix, where
## @var{num_points} is the number of points over which the fuzzy
## values are evaluated, Q is the number of rules and M is the number
## of FIS output variables. Each column of @var{rule_output} gives
## the y-values of the fuzzy output for a single (rule, FIS output)
## pair:
##
## @verbatim
##                       Q cols            Q cols              Q cols 
##                  ---------------   ---------------     ---------------
##                  out_1 ... out_1   out_2 ... out_2 ... out_M ... out_M
##              1 [[                                                     ]
##              2  [                                                     ]
##             ... [                                                     ]
##     num_points  [                                                     ]]
## @end verbatim
##
## The return value @var{fuzzy_output} is a @var{num_points} x M matrix. Each
## column of @var{fuzzy_output} gives the y-values of the fuzzy output for a
## single FIS output variable, aggregated over all rules:
##
## @verbatim
##                  out_1  out_2  ...  out_M
##              1 [[                        ]
##              2  [                        ]
##             ... [                        ]
##     num_points  [                        ]]
## @end verbatim
##
## Because aggregate_output_mamdani is called only by the private
## function evalfis_private, it does no error checking of the argument values.
## @end deftypefn

## Author:        L. Markowsky
## Keywords:      fuzzy-logic-toolkit fuzzy inference system fis
## Directory:     fuzzy-logic-toolkit/inst/private/
## Filename:      aggregate_output_mamdani.m
## Last-Modified: 26 Jul 2024

function fuzzy_output = aggregate_output_mamdani (fis, rule_output)

  num_rules = columns (fis.rule);            ## num_rules   == Q (above)
  num_outputs = columns (fis.output);        ## num_outputs == L
  num_points = rows (rule_output);

  ## Initialize output matrix to prevent inefficient resizing.
  fuzzy_output = zeros (num_points, num_outputs);

  ## Compute the ith fuzzy output values, then store the values in the
  ## ith column of the fuzzy_output matrix.
  for i = 1 : num_outputs
    indiv_fuzzy_out = ...
      rule_output(:, (i - 1) * num_rules + 1 : i * num_rules);
    agg_fuzzy_out = (str2func (fis.aggMethod) (indiv_fuzzy_out'))';
    fuzzy_output(:, i) = agg_fuzzy_out;
  endfor

endfunction