fuzzy-logic-toolkit/0000775000175000017500000000000012354653605013776 5ustar lindalindafuzzy-logic-toolkit/NEWS0000664000175000017500000000446512354652714014506 0ustar lindalindaSummary of important user-visible changes for fuzzy-logic-toolkit 0.4.5: ------------------------------------------------------------------------ ** Bug #38018 was fixed (typo in function setfis.m -- wrong function name). Summary of important user-visible changes for fuzzy-logic-toolkit 0.4.4: ------------------------------------------------------------------------ ** The function readfis was modified to workaround the change to strsplit beginning in Octave 3.8.0. Without the modification, readfis will not work with Octave versions >= 3.8.0. The new version of readfis works with all versions of Octave >= 3.2.4 by first checking for the version number of Octave and then selecting either ostrsplit (for Octave >= 3.8.0) or strsplit (for Octave < 3.8.0). ** The files writefis.m and evalmf.m were edited to maintain compatibility with future versions of Octave. Two occurrences of the continuation "..." within double quoted strings in writefis.m were changed to "\". One occurrence of "..." in evalmf.m was removed by writing the instruction on a single line. Summary of important user-visible changes for fuzzy-logic-toolkit 0.4.2: ------------------------------------------------------------------------ ** The demos embedded in partition_coeff.m, partition_entropy.m, and xie_beni_index.m were merged with the embedded demos in fcm.m and gustafson_kessel.m. Summary of important user-visible changes for fuzzy-logic-toolkit 0.4.1: ------------------------------------------------------------------------ ** The package is no longer automatically loaded. ** The following demo scripts were rewritten and embedded in fcm.m, gustafson_kessel.m, partition_coeff.m, partition_entropy.m, and xie_beni_index.m: fcm_demo_1 fcm_demo_2 gustafson_kessel_demo_1 gustafson_kessel_demo_2 (The separate demo script files have been removed.) Summary of important user-visible changes for fuzzy-logic-toolkit 0.4.0: ------------------------------------------------------------------------ ** The following functions are new: fcm gustafson_kessel partition_coeff partition_entropy xie_beni_index ** The following demo scripts are new: fcm_demo_1 fcm_demo_2 gustafson_kessel_demo_1 gustafson_kessel_demo_2 fuzzy-logic-toolkit/inst/0000775000175000017500000000000012354651643014753 5ustar lindalindafuzzy-logic-toolkit/inst/pimf.m0000664000175000017500000001307112354647032016063 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} pimf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} pimf (@var{[x1 x2 ... xn]}, @var{[a b c d]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b c d]}), ## return the corresponding @var{y} values for the pi-shaped membership ## function. ## ## The argument @var{x} must be a real number or a non-empty vector of real ## numbers, and @var{a}, @var{b}, @var{c}, and @var{d} must be real numbers, ## with @var{a} < @var{b} <= @var{c} < @var{d}. This membership function ## satisfies: ## @example ## @group ## 0 if x <= a ## 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 1 - 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## f(x) = 1 if b <= x <= c ## 1 - 2 * ((x - c)/(d - c))^2 if c < x <= (c + d)/2 ## 2 * ((x - d)/(d - c))^2 if (c + d)/2 < x < d ## 0 if x >= d ## @end group ## @end example ## ## @noindent ## which always returns values in the range [0, 1]. ## ## @noindent ## To run the demonstration code, type @t{demo('pimf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, psigmf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership pi-shaped pi ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: pimf.m ## Last-Modified: 19 August 2012 function y = pimf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if ((nargin != 2)) puts ("Type 'help pimf' for more information.\n"); error ("pimf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help pimf' for more information.\n"); error ("pimf's first argument must be a valid domain\n"); elseif (!are_mf_params ('pimf', params)) puts ("Type 'help pimf' for more information.\n"); error ("pimf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a = params(1); b = params(2); c = params(3); d = params(4); a_b_ave = (a + b) / 2; b_minus_a = b - a; c_d_ave = (c + d) / 2; d_minus_c = d - c; y_val = @(x_val) pimf_val (x_val, a, b, c, d, a_b_ave, b_minus_a, ... c_d_ave, d_minus_c); y = arrayfun (y_val, x); endfunction ##---------------------------------------------------------------------- ## Usage: y = pimf_val (x_val, a, b, c, d, a_b_ave, b_minus_a, c_d_ave, ## d_minus_c) ## ## pimf_val returns one value of the S-shaped membership function, which ## satisfies: ## 0 if x <= a ## 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 1 - 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## f(x) = 1 if b <= x <= c ## 1 - 2 * ((x - c)/(d - c))^2 if c < x <= (c + d)/2 ## 2 * ((x - d)/(d - c))^2 if (c + d)/2 < x < d ## 0 if x >= d ## ## pimf_val is a private function, called only by pimf. Because pimf_val ## is not intended for general use -- and because the parameters a, b, ## c, and d are checked for errors in the function pimf (defined above), ## the parameters are not checked for errors again here. ##---------------------------------------------------------------------- function y_val = pimf_val (x_val, a, b, c, d, a_b_ave, b_minus_a, ... c_d_ave, d_minus_c) ## Calculate and return a single y value of the pi-shaped membership ## function for the given x value and parameters specified by the ## arguments. if (x_val <= a) y_val = 0; elseif (x_val <= a_b_ave) y_val = 2 * ((x_val - a)/b_minus_a)^2; elseif (x_val < b) y_val = 1 - 2 * ((x_val - b) / b_minus_a)^2; elseif (x_val <= c) y_val = 1; elseif (x_val <= c_d_ave) y_val = 1 - 2 * ((x_val - c) / d_minus_c)^2; elseif (x_val < d) y_val = 2 * ((x_val - d) / d_minus_c)^2; else y_val = 0; endif endfunction %!demo %! x = 0:255; %! params = [70 80 100 140]; %! y1 = pimf(x, params); %! params = [50 75 105 175]; %! y2 = pimf(x, params); %! params = [30 70 110 200]; %! y3 = pimf(x, params); %! figure('NumberTitle', 'off', 'Name', 'pimf demo'); %! plot(x, y1, 'r;params = [70 80 100 140];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [50 75 105 175];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [30 70 110 200];', 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/addrule.m0000664000175000017500000001036212354647032016550 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} addrule (@var{fis}, @var{rule_matrix}) ## ## Add a list of rules to an existing FIS structure and return ## the updated FIS. ## ## Each row of the @var{rule_matrix} represents one rule and has the form: ## @example ## [in1_mf ... inM_mf out1_mf ... outN_mf weight connect] ## @end example ## ## @noindent ## where: ## ## @itemize @w ## @item ## in_mf == membership function index for input i ## @item ## out_mf == membership function index for output j ## @item ## weight == relative weight of the rule (0 <= weight <= 1) ## @item ## connect == antecedent connective (1 == and; 2 == or) ## @end itemize ## ## To express: ## @itemize @w ## @item ## "not" -- prepend a minus sign to the membership function index ## @item ## "somewhat" -- append ".05" to the membership function index ## @item ## "very" -- append ".20" to the membership function index ## @item ## "extremely" -- append ".30" to the membership function index ## @item ## "very very" -- append ".40" to the membership function index ## @item ## custom hedge -- append .xy, where x.y is the degree to which the membership ## value should be raised, to the membership function index ## @end itemize ## ## To omit an input or output, use 0 for the membership function index. ## The consequent connective is always "and". ## ## @noindent ## For example, to express: ## @example ## "If (input_1 is mf_2) or (input_3 is not mf_1) or (input_4 is very mf_1), ## then (output_1 is mf_2) and (output_2 is mf_1^0.3)." ## @end example ## ## @noindent ## with weight 1, the corresponding row of @var{rule_matrix} would be: ## @example ## [2 0 -1 4.2 2 1.03 1 2] ## @end example ## ## @noindent ## For a complete example that uses addrule, see heart_disease_demo_1.m. ## ## @seealso{heart_disease_demo_1, showrule} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy rule ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addrule.m ## Last-Modified: 18 Aug 2012 function fis = addrule (fis, rule_matrix) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help addrule' for more information.\n"); error ("addrule requires 2 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help addrule' for more information.\n"); error ("addrule's first argument must be an FIS structure\n"); elseif (!is_real_matrix (rule_matrix)) puts ("Type 'help addrule' for more information. addrule's \n"); error ("second argument must be a matrix of real numbers\n"); endif ## For each row in the rule_matrix, create a new rule struct and ## update the FIS structure. num_inputs = columns (fis.input); num_outputs = columns (fis.output); for i = 1 : rows (rule_matrix) antecedent = rule_matrix(i, 1 : num_inputs); consequent = rule_matrix(i, ... (num_inputs+1) : (num_inputs+num_outputs)); weight = rule_matrix(i, num_inputs + num_outputs + 1); connection = rule_matrix(i, num_inputs + num_outputs + 2); new_rules(i) = struct ('antecedent', antecedent, ... 'consequent', consequent, ... 'weight', weight, ... 'connection', connection); endfor if (length (fis.rule) == 0) fis.rule = new_rules; else fis.rule = [fis.rule, new_rules]; endif endfunction fuzzy-logic-toolkit/inst/bounded_sum.m0000664000175000017500000000537412354647032017443 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} bounded_sum (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} bounded_sum (@var{x}, @var{y}) ## ## Return the bounded sum of the input. ## The bounded sum of two real scalars x and y is: min (1, x + y) ## ## For one vector argument, apply the bounded sum to all of elements of ## the vector. (The bounded sum is associative.) For one two-dimensional ## matrix argument, return a vector of the bounded sum of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise bounded sum. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy bounded_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: bounded_sum.m ## Last-Modified: 18 Aug 2012 function retval = bounded_sum (x, y = 0) if (!(isreal (x) && isreal (y))) puts ("Type 'help bounded_sum' for more information.\n"); error ("bounded_sum requires real scalar or matrix arguments\n"); elseif (nargin == 2 && ... (isscalar (x) || isscalar (y) || ... isequal (size (x), size (y)))) retval = min (1, (x .+ y)); elseif (nargin == 1 && isvector (x)) retval = bounded_sum_of_vector (x); elseif (nargin == 1 && ndims (x) == 2) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = bounded_sum_of_vector (x(:, i)); endfor else puts ("Type 'help bounded_sum' for more information.\n"); error ("invalid arguments to function bounded_sum\n"); endif endfunction function retval = bounded_sum_of_vector (real_vector) x = 0; for i = 1 : length (real_vector) y = real_vector(i); x = min (1, (x + y)); endfor retval = x; endfunction fuzzy-logic-toolkit/inst/sigmf.m0000664000175000017500000000674512354647032016247 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} sigmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} sigmf (@var{[x1 x2 ... xn]}, @var{[a c]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a c]}), ## return the corresponding @var{y} values for the sigmoidal membership ## function. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{a} and @var{c} must be real numbers. This ## membership function satisfies the equation: ## @itemize @w ## @item ## f(x) = 1/(1 + exp(-a*(x - c))) ## @end itemize ## ## @noindent ## which always returns values in the range [0, 1]. ## ## The parameters a and c specify: ## @itemize @w ## @item ## a == the slope at c ## @item ## c == the inflection point ## @end itemize ## ## @noindent ## and at the inflection point, the value of the function is 0.5: ## @itemize @w ## @item ## f(c) == 0.5. ## @end itemize ## ## @noindent ## To run the demonstration code, type @t{demo('sigmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership sigmoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: sigmf.m ## Last-Modified: 19 Aug 2012 function y = sigmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help sigmf' for more information.\n"); error ("sigmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help sigmf' for more information.\n"); error ("sigmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('sigmf', params)) puts ("Type 'help sigmf' for more information.\n"); error ("sigmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a = params(1); c = params(2); y_val = @(x_val) 1 / (1 + exp (-a * (x_val - c))); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:100; %! params = [0.3 40]; %! y1 = sigmf(x, params); %! params = [0.2 40]; %! y2 = sigmf(x, params); %! params = [0.1 40]; %! y3 = sigmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'sigmf demo'); %! plot(x, y1, 'r;params = [0.3 40];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [0.2 40];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [0.1 40];', 'LineWidth', 2) %! ylim([-0.1 1.2]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/writefis.m0000664000175000017500000002362012354647032016765 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {} writefis (@var{fis}) ## @deftypefnx {Function File} {} writefis (@var{fis}, @var{filename}) ## @deftypefnx {Function File} {} writefis (@var{fis}, @var{filename}, @var{dialog}) ## ## Save the specified FIS currently in the Octave workspace to a file ## named by the user. There are three forms of writefis: ## ## @table @asis ## @item # Arguments ## Action Taken ## @item 1 ## Open a dialog GUI to help the user choose a directory and name ## for the output file. ## @item 2 ## Do not open a dialog GUI. Save the FIS to a file in the ## current directory with the specified @var{filename}. If the ## specified @var{filename} does not end in '.fis', append '.fis' ## to the @var{filename}. ## @item 3 ## Open a dialog GUI with the specified @var{filename} in the ## 'filename' textbox of the GUI. If the specified @var{filename} ## does not end in '.fis', append '.fis' to the @var{filename}. ## @end table ## ## The types of the arguments are expected to be: ## @table @var ## @item fis ## an FIS structure satisfying is_fis (see private/is_fis.m) ## @item filename ## a string; if the string does not already end with the extension ## ".fis", then ".fis" is added ## @item dialog ## the string 'dialog' (case insensitive) ## @end table ## ## @noindent ## Note: ## The GUI dialog requires zenity to be installed on the system. ## ## @noindent ## Known error: ## When using the file dialog, if the user clicks "Cancel" instead of ## saving the file, an error message is generated. ## ## @seealso{readfis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: writefis.m ## Last-Modified: 26 Jun 2014 function writefis (fis, filename = 'filename.fis', dialog = 'dummy') ## If writefis was not called with between 1 and 3 arguments, or if ## the argument values were of the wrong type, print an error message ## and halt. if (!(nargin >= 1 && nargin <= 3)) puts ("Type 'help writefis' for more information.\n"); error ("writefis requires between 1 and 3 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help writefis' for more information.\n"); error ("writefis's first argument must be an FIS structure\n"); elseif ((nargin >= 2) && !is_string (filename)) puts ("Type 'help writefis' for more information.\n"); error ("writefis's second argument must be a string\n"); elseif ((nargin == 3) && ... !(is_string (dialog) && strcmpi (dialog, 'dialog'))) puts ("Type 'help writefis' for more information.\n"); error ("writefis's third argument must the string 'dialog'\n"); endif ## Open the output file. use_gui = (nargin != 2); fid = open_output_file (filename, use_gui); ## Write the [System], [Input], [Output], and [Rules] ## sections of the output file. write_system_section (fid, fis); write_input_sections (fid, fis); write_output_sections (fid, fis); write_rules_section (fid, fis); ## Close the output file. fclose (fid); endfunction ##---------------------------------------------------------------------- ## Function: open_output_file ## Purpose: Open the output file. Return the fid if successful. ## Otherwise, print an error message and halt. ##---------------------------------------------------------------------- function fid = open_output_file (filename, use_gui) ## If the filename is not empty, and if the last four characters of ## the filename are not '.fis', append '.fis' to the filename. fn_len = length (filename); if (((fn_len >= 4) && ... !strcmp(".fis",filename(fn_len-3:fn_len))) || ... ((fn_len > 0) && (fn_len < 4))) filename = [filename ".fis"]; endif ## If writefis was called with 1 or 3 arguments, use a dialog to ## choose an output filename. if (use_gui) system_command = sprintf ("zenity --file-selection --filename=%s \ --save --confirm-overwrite; \ echo $file", filename); [dialog_error, filename] = system (file=system_command); if (dialog_error) puts ("Type 'help writefis' for more information.\n"); error ("error selecting file using dialog\n"); endif filename = strtrim (filename); endif ## Open output file. [fid, msg] = fopen (filename, "w"); if (fid == -1) if (use_gui) system ('zenity --error --text "Error opening output file."'); endif puts ("Type 'help writefis' for more information.\n"); error ("error opening output file: %s\n", msg); endif endfunction ##---------------------------------------------------------------------- ## Function: write_system_section ## Purpose: Write [System] section of the output file. ##---------------------------------------------------------------------- function write_system_section (fid, fis) fprintf (fid, "[System]\n"); fprintf (fid, "Name='%s'\n", fis.name); fprintf (fid, "Type='%s'\n", fis.type); fprintf (fid, "Version=%.1f\n", fis.version); fprintf (fid, "NumInputs=%d\n", columns(fis.input)); fprintf (fid, "NumOutputs=%d\n", columns(fis.output)); fprintf (fid, "NumRules=%d\n", columns(fis.rule)); fprintf (fid, "AndMethod='%s'\n", fis.andMethod); fprintf (fid, "OrMethod='%s'\n", fis.orMethod); fprintf (fid, "ImpMethod='%s'\n", fis.impMethod); fprintf (fid, "AggMethod='%s'\n", fis.aggMethod); fprintf (fid, "DefuzzMethod='%s'\n", fis.defuzzMethod); endfunction ##---------------------------------------------------------------------- ## Function: write_input_sections ## Purpose: For each FIS input, write [Input] section to ## output file. ##---------------------------------------------------------------------- function write_input_sections (fid, fis) num_inputs = columns (fis.input); for i = 1 : num_inputs num_mfs = columns (fis.input(i).mf); fprintf (fid, "\n[Input%d]\n", i); fprintf (fid, "Name='%s'\n", fis.input(i).name); fprintf (fid, "Range=%s\n", ... strrep (mat2str (fis.input(i).range),","," ")); fprintf (fid, "NumMFs=%d\n", num_mfs); for j = 1 : num_mfs fprintf (fid, "MF%d='%s':'%s',%s\n", j, ... fis.input(i).mf(j).name, fis.input(i).mf(j).type, ... params2str (fis.input(i).mf(j).params)); endfor endfor endfunction ##---------------------------------------------------------------------- ## Function: write_output_sections ## Purpose: For each FIS output, write [Output] section to ## output file. ##---------------------------------------------------------------------- function write_output_sections (fid, fis) num_outputs = columns (fis.output); for i = 1 : num_outputs num_mfs = columns (fis.output(i).mf); fprintf (fid, "\n[Output%d]\n", i); fprintf (fid, "Name='%s'\n", fis.output(i).name); fprintf (fid, "Range=%s\n", ... strrep(mat2str(fis.output(i).range),","," ")); fprintf (fid, "NumMFs=%d\n", num_mfs); for j = 1 : num_mfs fprintf (fid, "MF%d='%s':'%s',%s\n", j, ... fis.output(i).mf(j).name, fis.output(i).mf(j).type, ... params2str (fis.output(i).mf(j).params)); endfor endfor endfunction ##---------------------------------------------------------------------- ## Function: write_rules_section ## Purpose: Write [Rules] section to output file. ##---------------------------------------------------------------------- function write_rules_section (fid, fis) num_inputs = columns (fis.input); num_outputs = columns (fis.output); num_rules = columns (fis.rule); fprintf (fid, "\n[Rules]\n"); for i = 1 : num_rules next_ant = fis.rule(i).antecedent; next_con = fis.rule(i).consequent; next_wt = fis.rule(i).weight; next_connect = fis.rule(i).connection; ## Print membership functions for the inputs. if (num_inputs > 0) if (is_int (next_ant(1))) fprintf (fid, "%d", next_ant(1)); else fprintf (fid, "%.2f", next_ant(1)); endif endif for j = 2 : num_inputs if (is_int (next_ant(j))) fprintf (fid, " %d", next_ant(j)); else fprintf (fid, " %.2f", next_ant(j)); endif endfor fprintf(fid, ", "); ## Print membership functions for the outputs. for j = 1 : num_outputs if (is_int (next_con(j))) fprintf (fid, "%d ", next_con(j)); else fprintf (fid, "%.2f ", next_con(j)); endif endfor ## Print the weight in parens. if (is_int (next_wt)) fprintf (fid, "(%d) : ", next_wt); else fprintf (fid, "(%.4f) : ", next_wt); endif ## Print the connection and a newline. fprintf (fid, "%d\n", next_connect); endfor endfunction ##---------------------------------------------------------------------- ## Function: params2str ## Purpose: Convert membership function parameters to string ## representation. ##---------------------------------------------------------------------- function str = params2str (params) if (length (params) < 2) str = ['[' num2str(params) ']']; else str = strrep (mat2str (params), ",", " "); endif endfunction fuzzy-logic-toolkit/inst/rmvar.m0000664000175000017500000000560112354647032016257 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} rmvar (@var{fis}, @var{in_or_out}, @var{var_index}) ## ## Remove an input or output variable from an existing FIS ## structure and return the updated FIS. ## ## The types of the arguments are expected to be: ## @itemize @bullet ## @item ## @var{fis} - an FIS structure ## @item ## @var{in_or_out} - either 'input' or 'output' (case-insensitive) ## @item ## @var{var_index} - an FIS input or output variable index ## @end itemize ## ## Note that rmvar will allow the user to delete an input or output variable ## that is currently in use by rules in the FIS. ## ## @seealso{addvar, rmmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy variable ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: rmvar.m ## Last-Modified: 20 Aug 2012 function fis = rmvar (fis, in_or_out, var_index) ## If the caller did not supply 3 argument values with the correct ## types, print an error message and halt. if (nargin != 3) puts ("Type 'help rmvar' for more information.\n"); error ("rmvar requires 3 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help rmvar' for more information.\n"); error ("rmvar's first argument must be an FIS structure\n"); elseif (!(is_string (in_or_out) && ... ismember (tolower (in_or_out), {'input', 'output'}))) puts ("Type 'help rmvar' for more information.\n"); error ("rmvar's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, in_or_out, var_index)) puts ("Type 'help rmvar' for more information.\n"); error ("rmvar's third argument must be a variable index\n"); endif ## Delete the variable struct and update the FIS structure. if (strcmp (tolower (in_or_out), 'input')) all_vars = fis.input; fis.input = [all_vars(1 : var_index - 1), ... all_vars(var_index + 1 : numel (all_vars))]; else all_vars = fis.output; fis.output = [all_vars(1 : var_index - 1), ... all_vars(var_index + 1 : numel (all_vars))]; endif endfunction fuzzy-logic-toolkit/inst/hamacher_sum.m0000664000175000017500000000634012354647032017565 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} hamacher_sum (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} hamacher_sum (@var{x}, @var{y}) ## ## Return the Hamacher sum of the input. ## The Hamacher sum of two real scalars x and y is: ## (x + y - 2 * x * y) / (1 - x * y) ## ## For one vector argument, apply the Hamacher sum to all of the elements ## of the vector. (The Hamacher sum is associative.) For one ## two-dimensional matrix argument, return a vector of the Hamacher sum ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise Hamacher sum. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_product} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy hamacher_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: hamacher_sum.m ## Last-Modified: 20 Aug 2012 function retval = hamacher_sum (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) retval = (x + y - 2 * x * y) / (1 - x * y); endfunction function retval = vector_arg (real_vector) x = 0; for i = 1 : length (real_vector) y = real_vector(i); if (x == 1 && y == 1) x = 1; else x = (x + y - 2 * x * y) / (1 - x * y); endif endfor retval = x; endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help hamacher_sum' for more information.\n"); error ("invalid arguments to function hamacher_sum\n"); endfunction fuzzy-logic-toolkit/inst/algebraic_product.m0000664000175000017500000000500212354647032020574 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} algebraic_product (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} algebraic_product (@var{x}, @var{y}) ## ## Return the algebraic product of the input. ## The algebraic product of two real scalars x and y is: x * y ## ## For one vector argument, apply the algebraic product to all of elements of ## the vector. (The algebraic product is associative.) For one two-dimensional ## matrix argument, return a vector of the algebraic product of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise product. ## ## @seealso{algebraic_sum, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy algebraic_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: algebraic_product.m ## Last-Modified: 18 Aug 2012 function retval = algebraic_product (x, y = 0) if (!(isreal (x) && isreal (y))) puts ("Arguments to algebraic_product must be real scalars "); puts ("or matrices.\n"); puts ("Type 'help algebraic_product' for more information.\n"); error ("invalid arguments to function algebraic_product\n"); elseif (nargin == 2 && ... (isscalar (x) || isscalar (y) || ... isequal (size (x), size (y)))) retval = x .* y; elseif (nargin == 1 && ndims (x) <= 2) retval = prod (x); else puts ("Type 'help algebraic_product' for more information.\n"); error ("invalid arguments to function algebraic_product\n"); endif endfunction fuzzy-logic-toolkit/inst/trapmf.m0000664000175000017500000000745212354647032016427 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} trapmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} trapmf (@var{[x1 x2 ... xn]}, @var{[a b c d]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b c d]}), ## return the corresponding @var{y} values for the trapezoidal membership ## function. The argument @var{x} must be a real number or a non-empty vector of ## strictly increasing real numbers, and parameters @var{a}, @var{b}, @var{c}, ## and @var{d} must satisfy the inequalities: ## @var{a} < @var{b} <= @var{c} < @var{d}. None of the parameters @var{a}, ## @var{b}, @var{c}, @var{d} are required to be in the domain @var{x}. The ## minimum and maximum values of the trapezoid are assumed to be 0 and 1. ## ## The parameters @var{[a b c d]} correspond to the x values ## of the corners of the trapezoid: ## ## @example ## @group ## 1-| -------- ## | / \ ## | / \ ## | / \ ## 0----------------------- ## a b c d ## @end group ## @end example ## ## @noindent ## To run the demonstration code, type @t{demo('trapmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, sigmf, smf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership trapezoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: trapmf.m ## Last-Modified: 19 Aug 2012 function y = trapmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help trapmf' for more information.\n"); error ("trapmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help trapmf' for more information.\n"); error ("trapmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('trapmf', params)) puts ("Type 'help trapmf' for more information.\n"); error ("trapmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the trapezoid on the domain x. a = params(1); b = params(2); c = params(3); d = params(4); b_minus_a = b - a; d_minus_c = d - c; y_val = @(x_val) max (0, min (min (1, (x_val - a) / b_minus_a), ... (d - x_val) / d_minus_c)); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:100; %! params = [-1 0 20 40]; %! y1 = trapmf(x, params); %! params = [20 40 60 80]; %! y2 = trapmf(x, params); %! params = [60 80 100 101]; %! y3 = trapmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'trapmf demo'); %! plot(x, y1, 'r;params = [-1 0 20 40];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [20 40 60 80];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [60 80 100 101];', 'LineWidth', 2) %! ylim([-0.1 1.2]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/sugeno_tip_demo.m0000664000175000017500000000540412354647032020311 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} sugeno_tip_demo ## ## Demonstrate the use of the Octave Fuzzy Logic Toolkit to read and ## evaluate a Sugeno-type FIS with multiple outputs stored in a text ## file. Also demonstrate the use of hedges in the FIS rules and the ## Einstein product and sum as the T-norm/S-norm pair. ## ## The demo: ## @itemize @minus ## @item ## reads the FIS structure from a file ## @item ## plots the input membership functions ## @item ## plots the (constant) output functions ## @item ## plots each of the three FIS outputs as a function of the inputs ## @item ## displays the FIS rules in verbose format in the Octave window ## @item ## evaluates the Sugeno-type FIS for six inputs ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Note: This example is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: sugeno_tip_demo.m ## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('sugeno_tip_calculator.fis'); ## Plot the input and output membership functions. plotmf (fis, 'input', 1); plotmf (fis, 'input', 2); plotmf (fis, 'output', 1); plotmf (fis, 'output', 2); plotmf (fis, 'output', 3); ## Plot the cheap, average, and generous tips as a function of ## Food-Quality and Service. gensurf (fis, [1 2], 1); gensurf (fis, [1 2], 2); gensurf (fis, [1 2], 3); ## Demonstrate showrule with hedges. showrule (fis); ## Calculate the Tip for 6 sets of input values: puts ("\nFor the following values of (Food Quality, Service):\n\n"); food_service = [1 1; 5 5; 10 10; 4 6; 6 4; 7 4] puts ("\nThe cheap, average, and generous tips are:\n\n"); tip = evalfis (food_service, fis, 1001) fuzzy-logic-toolkit/inst/investment_portfolio.fis0000664000175000017500000000325712354647032021753 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: investment_portfolio.fis ## Last-Modified: 28 Aug 2012 [System] Name='Investment-Portfolio' Type='mamdani' Version=2.0 NumInputs=2 NumOutputs=1 NumRules=4 AndMethod='einstein_product' OrMethod='einstein_sum' ImpMethod='einstein_product' AggMethod='einstein_sum' DefuzzMethod='centroid' [Input1] Name='Age' Range=[20 100] NumMFs=2 MF1='Young':'zmf',[30 90] MF2='Old':'smf',[30 90] [Input2] Name='Risk-Tolerance' Range=[0 10] NumMFs=2 MF1='Low':'zmf',[2 8] MF2='High':'smf',[2 8] [Output1] Name='Percentage-In-Stocks' Range=[0 100] NumMFs=3 MF1='About-Fifteen':'gaussmf',[10 15] MF2='About-Fifty':'gaussmf',[10 50] MF3='About-Eighty-Five':'gaussmf',[10 85] [Rules] 1 2, 3 (1) : 2 2 1, 1 (1) : 2 -2.3 -1.3, 2 (0.5) : 1 -1.3 -2.3, 2 (0.5) : 1 fuzzy-logic-toolkit/inst/zmf.m0000664000175000017500000001177612354647032015736 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} zmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} zmf (@var{[x1 x2 ... xn]}, @var{[a b]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b]}), ## return the corresponding @var{y} values for the Z-shaped membership function. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{a} and @var{b} must be real numbers, with ## @var{a} < @var{b}. This membership function satisfies: ## @example ## @group ## 1 if x <= a ## f(x) = 1 - 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## 0 if x >= b ## @end group ## @end example ## ## @noindent ## which always returns values in the range [0, 1]. ## ## The parameters a and b specify: ## @itemize @w ## @item ## a == the rightmost point at which f(x) = 1 ## @item ## b == the leftmost point at which f(x) = 0 ## @end itemize ## ## @noindent ## At the midpoint of the segment [a, b], the function value is 0.5: ## @itemize @w ## @item ## f((a + b)/2) = 0.5 ## @end itemize ## ## @noindent ## To run the demonstration code, type @t{demo('zmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, sigmf, smf, trapmf, trimf, zmf_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership z-shaped ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: zmf.m ## Last-Modified: 19 Aug 2012 function y = zmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help zmf' for more informaion.\n"); error ("zmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help zmf' for more informaion.\n"); error ("zmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('zmf', params)) puts ("Type 'help zmf' for more informaion.\n"); error ("zmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a = params(1); b = params(2); a_b_ave = (a + b) / 2; b_minus_a = b - a; y_val = @(x_val) zmf_val (x_val, a, b, a_b_ave, b_minus_a); y = arrayfun (y_val, x); endfunction ##---------------------------------------------------------------------- ## Usage: y_val = zmf_val (x_val, a, b, a_b_ave, b_minus_a) ## ## zmf_val returns one value of the Z-shaped membership function, which ## satisfies: ## 1 if x <= a ## f(x) = 1 - 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## 0 if x >= b ## ## zmf_val is a private function, called only by zmf. Because zmf_val ## is not intended for general use -- and because the parameters a and b ## are checked for errors in the function zmf (defined above), the ## parameters are not checked for errors again here. ##---------------------------------------------------------------------- function y_val = zmf_val (x_val, a, b, a_b_ave, b_minus_a) ## Calculate and return a single y value of the Z-shaped membership ## function for the given x value and parameters specified by the ## arguments. if (x_val <= a) y_val = 1; elseif (x_val <= a_b_ave) y_val = 1 - 2 * ((x_val - a) / b_minus_a)^2; elseif (x_val < b) y_val = 2 * ((x_val - b) / b_minus_a)^2; else y_val = 0; endif endfunction %!demo %! x = 0:100; %! params = [40 60]; %! y1 = zmf(x, params); %! params = [25 75]; %! y2 = zmf(x, params); %! params = [10 90]; %! y3 = zmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'zmf demo'); %! plot(x, y1, 'r;params = [40 60];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [25 75];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [10 90];', 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/heart_disease_risk.fis0000664000175000017500000000450612354647032021310 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: heart_disease_risk.fis ## Last-Modified: 28 Aug 2012 ## Heart Disease Risk FIS [System] Name = 'Heart-Disease-Risk' Type = 'sugeno' Version = 2.0 NumInputs = 2 NumOutputs = 1 NumRules = 15 AndMethod = 'min' OrMethod = 'max' ImpMethod = 'min' AggMethod = 'max' DefuzzMethod = 'wtaver' [Input1] Name = 'LDL-Level' Range = [0 300] NumMFs = 5 MF1 = 'Low' : 'trapmf', [-1 0 90 110] MF2 = 'Low-Borderline' : 'trapmf', [90 110 120 140] MF3 = 'Borderline' : 'trapmf', [120 140 150 170] MF4 = 'High-Borderline' : 'trapmf', [150 170 180 200] MF5 = 'High' : 'trapmf', [180 200 300 301] [Input2] Name = 'HDL-Level' Range = [0 100] NumMFs = 3 MF1 = 'Low-HDL' : 'trapmf', [-1 0 35 45] MF2 = 'Moderate-HDL' : 'trapmf', [35 45 55 65] MF3 = 'High-HDL' : 'trapmf', [55 65 100 101] [Output1] Name = 'Heart-Disease-Risk' Range = [0 10] NumMFs = 5 MF1 = 'No-Risk' : 'constant', [0] MF2 = 'Low-Risk' : 'constant', [2.5] MF3 = 'Medium-Risk' : 'constant', [5] MF4 = 'High-Risk' : 'constant', [7.5] MF5 = 'Extreme-Risk' : 'constant', [10] [Rules] 1 1, 3 (1) : 1 1 2, 2 (1) : 1 1 3, 1 (1) : 1 2 1, 3 (1) : 1 2 2, 2 (1) : 1 2 3, 2 (1) : 1 3 1, 4 (1) : 1 3 2, 3 (1) : 1 3 3, 2 (1) : 1 4 1, 4 (1) : 1 4 2, 4 (1) : 1 4 3, 3 (1) : 1 5 1, 5 (1) : 1 5 2, 4 (1) : 1 5 3, 3 (1) : 1 fuzzy-logic-toolkit/inst/fcm.m0000664000175000017500000003405112354647032015676 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{cluster_centers} =} fcm (@var{input_data}, @var{num_clusters}) ## @deftypefnx {Function File} {@var{cluster_centers} =} fcm (@var{input_data}, @var{num_clusters}, @var{options}) ## @deftypefnx {Function File} {@var{cluster_centers} =} fcm (@var{input_data}, @var{num_clusters}, [@var{m}, @var{max_iterations}, @var{epsilon}, @var{display_intermediate_results}]) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} fcm (@var{input_data}, @var{num_clusters}) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} fcm (@var{input_data}, @var{num_clusters}, @var{options}) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} fcm (@var{input_data}, @var{num_clusters}, [@var{m}, @var{max_iterations}, @var{epsilon}, @var{display_intermediate_results}]) ## ## Using the Fuzzy C-Means algorithm, calculate and return the soft partition ## of a set of unlabeled data points. ## ## Also, if @var{display_intermediate_results} is true, display intermediate ## results after each iteration. Note that because the initial cluster ## prototypes are randomly selected locations in the ranges determined by the ## input data, the results of this function are nondeterministic. ## ## The required arguments to fcm are: ## @itemize @w ## @item ## @var{input_data} - a matrix of input data points; each row corresponds to one point ## @item ## @var{num_clusters} - the number of clusters to form ## @end itemize ## ## The optional arguments to fcm are: ## @itemize @w ## @item ## @var{m} - the parameter (exponent) in the objective function; default = 2.0 ## @item ## @var{max_iterations} - the maximum number of iterations before stopping; default = 100 ## @item ## @var{epsilon} - the stopping criteria; default = 1e-5 ## @item ## @var{display_intermediate_results} - if 1, display results after each iteration, and if 0, do not; default = 1 ## @end itemize ## ## The default values are used if any of the optional arguments are missing or ## evaluate to NaN. ## ## The return values are: ## @itemize @w ## @item ## @var{cluster_centers} - a matrix of the cluster centers; each row corresponds to one point ## @item ## @var{soft_partition} - a constrained soft partition matrix ## @item ## @var{obj_fcn_history} - the values of the objective function after each iteration ## @end itemize ## ## Three important matrices used in the calculation are X (the input points ## to be clustered), V (the cluster centers), and Mu (the membership of each ## data point in each cluster). Each row of X and V denotes a single point, ## and Mu(i, j) denotes the membership degree of input point X(j, :) in the ## cluster having center V(i, :). ## ## X is identical to the required argument @var{input_data}; V is identical ## to the output @var{cluster_centers}; and Mu is identical to the output ## @var{soft_partition}. ## ## If n denotes the number of input points and k denotes the number of ## clusters to be formed, then X, V, and Mu have the dimensions: ## ## @example ## @group ## 1 2 ... #features ## 1 [ ] ## X = input_data = 2 [ ] ## ... [ ] ## n [ ] ## @end group ## @end example ## ## @example ## @group ## 1 2 ... #features ## 1 [ ] ## V = cluster_centers = 2 [ ] ## ... [ ] ## k [ ] ## @end group ## @end example ## ## @example ## @group ## 1 2 ... n ## 1 [ ] ## Mu = soft_partition = 2 [ ] ## ... [ ] ## k [ ] ## @end group ## @end example ## ## @seealso{gustafson_kessel, partition_coeff, partition_entropy, xie_beni_index} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm.m ## Last-Modified: 5 Sep 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... fcm (input_data, num_clusters, options = [2.0, 100, 1e-5, 1]) ## If fcm was called with an incorrect number of arguments, or the ## arguments do not have the correct type, print an error message ## and halt. if ((nargin != 2) && (nargin != 3)) puts ("Type 'help fcm' for more information.\n"); error ("fcm requires 2 or 3 arguments\n"); elseif (!is_real_matrix (input_data)) puts ("Type 'help fcm' for more information.\n"); error ("fcm's first argument must be matrix of real numbers\n"); elseif (!(is_int (num_clusters) && (num_clusters > 1))) puts ("Type 'help fcm' for more information.\n"); error ("fcm's second argument must be an integer greater than 1\n"); elseif (!(isreal (options) && isvector (options))) puts ("Type 'help fcm' for more information.\n"); error ("fcm's third argument must be a vector of real numbers\n"); endif ## Assign options to the more readable variable names: m, ## max_iterations, epsilon, and display_intermediate_results. ## If options are missing or NaN (not a number), use the default ## values. default_options = [2.0, 100, 1e-5, 1]; for i = 1 : 4 if ((length (options) < i) || ... isna (options(i)) || isnan (options(i))) options(i) = default_options(i); endif endfor m = options(1); max_iterations = options(2); epsilon = options(3); display_intermediate_results = options(4); ## Call a private function to compute the output. [cluster_centers, soft_partition, obj_fcn_history] = ... fcm_private (input_data, num_clusters, m, max_iterations, epsilon, display_intermediate_results); endfunction ##---------------------------------------------------------------------- ## Note: This function (fcm_private) is an implementation of Figure 13.4 ## in Fuzzy Logic: Intelligence, Control and Information, by ## J. Yen and R. Langari, Prentice Hall, 1999, page 380 ## (International Edition) and Algorithm 4.1 in Fuzzy and Neural ## Control, by Robert Babuska, November 2009, p. 63. ##---------------------------------------------------------------------- function [V, Mu, obj_fcn_history] = ... fcm_private (X, k, m, max_iterations, epsilon, ... display_intermediate_results) ## Initialize the prototypes and the calculation. V = init_cluster_prototypes (X, k); obj_fcn_history = zeros (max_iterations); convergence_criterion = epsilon + 1; iteration = 0; ## Calculate a few numbers here to reduce redundant computation. k = rows (V); n = rows (X); sqr_dist = square_distance_matrix (X, V); ## Loop until the objective function is within tolerance or the ## maximum number of iterations has been reached. while (convergence_criterion > epsilon && ... ++iteration <= max_iterations) V_previous = V; Mu = update_cluster_membership (V, X, m, k, n, sqr_dist); Mu_m = Mu .^ m; V = update_cluster_prototypes (Mu_m, X, k); sqr_dist = square_distance_matrix (X, V); obj_fcn_history(iteration) = ... compute_cluster_obj_fcn (Mu_m, sqr_dist); if (display_intermediate_results) printf ("Iteration count = %d, Objective fcn = %8.6f\n", ... iteration, obj_fcn_history(iteration)); endif convergence_criterion = ... compute_cluster_convergence (V, V_previous); endwhile ## Remove extraneous entries from the tail of the objective ## function history. if (convergence_criterion <= epsilon) obj_fcn_history = obj_fcn_history(1 : iteration); endif endfunction ##---------------------------------------------------------------------- ## FCM Demo #1 ##---------------------------------------------------------------------- %!demo %! ## This demo: %! ## - classifies a small set of unlabeled data points using %! ## the Fuzzy C-Means algorithm into two fuzzy clusters %! ## - plots the input points together with the cluster centers %! ## - evaluates the quality of the resulting clusters using %! ## three validity measures: the partition coefficient, the %! ## partition entropy, and the Xie-Beni validity index %! ## %! ## Note: The input_data is taken from Chapter 13, Example 17 in %! ## Fuzzy Logic: Intelligence, Control and Information, by %! ## J. Yen and R. Langari, Prentice Hall, 1999, page 381 %! ## (International Edition). %! %! ## Use fcm to classify the input_data. %! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4]; %! number_of_clusters = 2; %! [cluster_centers, soft_partition, obj_fcn_history] = ... %! fcm (input_data, number_of_clusters) %! %! ## Plot the data points as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'FCM Demo 1'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 2'); %! grid %! hold %! %! ## Calculate and print the three validity measures. %! printf ("Partition Coefficient: %f\n", ... %! partition_coeff (soft_partition)); %! printf ("Partition Entropy (with a = 2): %f\n", ... %! partition_entropy (soft_partition, 2)); %! printf ("Xie-Beni Index: %f\n\n", ... %! xie_beni_index (input_data, cluster_centers, ... %! soft_partition)); ##---------------------------------------------------------------------- ## FCM Demo #2 ##---------------------------------------------------------------------- %!demo %! ## This demo: %! ## - classifies three-dimensional unlabeled data points using %! ## the Fuzzy C-Means algorithm into three fuzzy clusters %! ## - plots the input points together with the cluster centers %! ## - evaluates the quality of the resulting clusters using %! ## three validity measures: the partition coefficient, the %! ## partition entropy, and the Xie-Beni validity index %! ## %! ## Note: The input_data was selected to form three areas of %! ## different shapes. %! %! ## Use fcm to classify the input_data. %! input_data = [1 11 5; 1 12 6; 1 13 5; 2 11 7; 2 12 6; 2 13 7; %! 3 11 6; 3 12 5; 3 13 7; 1 1 10; 1 3 9; 2 2 11; %! 3 1 9; 3 3 10; 3 5 11; 4 4 9; 4 6 8; 5 5 8; 5 7 9; %! 6 6 10; 9 10 12; 9 12 13; 9 13 14; 10 9 13; 10 13 12; %! 11 10 14; 11 12 13; 12 6 12; 12 7 15; 12 9 15; %! 14 6 14; 14 8 13]; %! number_of_clusters = 3; %! [cluster_centers, soft_partition, obj_fcn_history] = ... %! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]) %! %! ## Plot the data points in two dimensions (using features 1 & 2) %! ## as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'FCM Demo 2'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers in two dimensions %! ## (using features 1 & 2) as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 2'); %! grid %! hold %! %! ## Plot the data points in two dimensions %! ## (using features 1 & 3) as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'FCM Demo 2'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 3), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers in two dimensions %! ## (using features 1 & 3) as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 3), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 3'); %! grid %! hold %! %! ## Calculate and print the three validity measures. %! printf ("Partition Coefficient: %f\n", ... %! partition_coeff (soft_partition)); %! printf ("Partition Entropy (with a = 2): %f\n", ... %! partition_entropy (soft_partition, 2)); %! printf ("Xie-Beni Index: %f\n\n", ... %! xie_beni_index (input_data, cluster_centers, ... %! soft_partition)); fuzzy-logic-toolkit/inst/defuzz.m0000664000175000017500000002172712354647032016446 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{crisp_x} =} defuzz (@var{x}, @var{y}, @var{defuzz_method}) ## @deftypefnx {Function File} {@var{crisp_x} =} defuzz (@var{[x1 x2 ... xn]}, @var{[y1 y2 ... yn]}, @var{defuzz_method}) ## ## For a given domain, set of fuzzy function values, and defuzzification method, ## return the defuzzified (crisp) value of the fuzzy function. ## ## The arguments @var{x} and @var{y} must be either two real numbers or ## two equal-length, non-empty vectors of reals, with the elements of @var{x} ## strictly increasing. @var{defuzz_method} must be a (case-sensitive) string ## corresponding to a defuzzification method. Defuzz handles both built-in ## and custom defuzzification methods. ## ## The built-in defuzzification methods are: ## @table @samp ## @item centroid ## Return the x-value of the centroid. ## @item bisector ## Return the x-value of the vertical bisector of the area. ## @item mom ## Return the mean x-value of the points with maximum y-values. ## @item som ## Return the smallest (absolute) x-value of the points with maximum y-values. ## @item lom ## Return the largest (absolute) x-value of the points with maximum y-values. ## @item wtaver ## Return the weighted average of the x-values, with the y-values used as ## weights. ## @item wtsum ## Return the weighted sum of the x-values, with the y-values used as weights. ## @end table ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy defuzzification ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: defuzz.m ## Last-Modified: 18 Aug 2012 ##---------------------------------------------------------------------- function crisp_x = defuzz (x, y, defuzz_method) ## If the caller did not supply 3 argument values with the correct ## types, print an error message and halt. if (nargin != 3) puts ("Type 'help defuzz' for more information.\n"); error ("defuzz requires 3 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help defuzz' for more information.\n"); error ("defuzz's first argument must be a valid domain\n"); elseif (!(isvector (y) && isreal (y) && length (x) == length (y))) puts ("Type 'help defuzz' for more information.\n"); error ("defuzz's 2nd argument must be a real number or vector\n"); elseif (!is_string (defuzz_method)) puts ("Type 'help defuzz' for more information.\n"); error ("defuzz's third argument must be a string\n"); endif ## Calculate and return the defuzzified (crisp_x) value using the ## method specified by the argument defuzz_method. crisp_x = str2func (defuzz_method) (x, y); endfunction ##---------------------------------------------------------------------- ## Usage: crisp_x = centroid (x, y) ## crisp_x = centroid ([x1 x2 ... xn], [y1 y2 ... yn]) ## ## For a given domain (x or [x1 x2 ... xn]) and corresponding y-values ## (y or [y1 y2 ... yn]), return the x-value of the centroid of the ## region described by the points (xi, yi). ## ## Both arguments are assumed to be reals or non-empty vectors of reals. ## In addition, x is assumed to be strictly increasing, and x and y are ## assumed to be of equal length. ##---------------------------------------------------------------------- function crisp_x = centroid (x, y) crisp_x = trapz (x, x.*y) / trapz (x, y); endfunction ##---------------------------------------------------------------------- ## Usage: crisp_x = bisector (x, y) ## crisp_x = bisector ([x1 x2 ... xn], [y1 y2 ... yn]) ## ## For a given domain (x or [x1 x2 ... xn]) and corresponding y-values ## (y or [y1 y2 ... yn]), return the x-value of a bisector of the region ## described by the points (xi, yi). ## ## Both arguments are assumed to be reals or non-empty vectors of reals. ## In addition, x is assumed to be strictly increasing, and x and y are ## assumed to be of equal length. ##---------------------------------------------------------------------- function crisp_x = bisector (x, y) ## Find the bisector using a binary search. To ensure that the ## function terminates, add a counter to limit the iterations to the ## length of the vectors x and y. half_area = trapz (x, y) / 2; x_len = length (x); upper = x_len; lower = 1; count = 1; while ((lower <= upper) && (count++ < x_len)) midpoint = round ((lower + upper)/2); left_domain = [ones(1, midpoint), zeros(1, x_len-midpoint)]; left_y_vals = left_domain .* y; left_area = trapz (x, left_y_vals); error = left_area - half_area; if (error > 0) upper = midpoint; else lower = midpoint; endif endwhile crisp_x = midpoint; endfunction ##---------------------------------------------------------------------- ## Usage: crisp_x = mom (x, y) ## crisp_x = mom ([x1 x2 ... xn], [y1 y2 ... yn]) ## ## For a given domain (x or [x1 x2 ... xn]) and corresponding y-values ## (y or [y1 y2 ... yn]), return the "Mean of Maximum"; that is, return ## the average of the x-values corresponding to the maximum y-value ## in y. ## ## Both arguments are assumed to be reals or non-empty vectors of reals. ## In addition, x is assumed to be strictly increasing, and x and y are ## assumed to be of equal length. ##---------------------------------------------------------------------- function crisp_x = mom (x, y) max_y = max (y); y_val = @(y_val) if (y_val == max_y) 1 else 0 endif; max_y_locations = arrayfun (y_val, y); crisp_x = sum (x .* max_y_locations) / sum (max_y_locations); endfunction ##---------------------------------------------------------------------- ## Usage: crisp_x = som (x, y) ## crisp_x = som ([x1 x2 ... xn], [y1 y2 ... yn]) ## ## For a given domain (x or [x1 x2 ... xn]) and corresponding y-values ## (y or [y1 y2 ... yn]), return the "Smallest of Maximum"; that is, ## return the smallest x-value corresponding to the maximum y-value ## in y. ## ## Both arguments are assumed to be reals or non-empty vectors of reals. ## In addition, x is assumed to be strictly increasing, and x and y are ## assumed to be of equal length. ##---------------------------------------------------------------------- function crisp_x = som (x, y) max_y = max (y); y_val = @(y_val) if (y_val == max_y) 1 else (NaN) endif; max_y_locations = arrayfun (y_val, y); crisp_x = min (x .* max_y_locations); endfunction ##---------------------------------------------------------------------- ## Usage: crisp_x = lom (x, y) ## crisp_x = lom ([x1 x2 ... xn], [y1 y2 ... yn]) ## ## For a given domain (x or [x1 x2 ... xn]) and corresponding y-values ## (y or [y1 y2 ... yn]), return the "Largest of Maximum"; that is, ## return the largest x-value corresponding to the maximum y-value in y. ## ## Both arguments are assumed to be reals or non-empty vectors of reals. ## In addition, x is assumed to be strictly increasing, and x and y are ## assumed to be of equal length. ##---------------------------------------------------------------------- function crisp_x = lom (x, y) max_y = max (y); y_val = @(y_val) if (y_val == max_y) 1 else (NaN) endif; max_y_locations = arrayfun (y_val, y); crisp_x = max (x .* max_y_locations); endfunction ##---------------------------------------------------------------------- ## Usage: retval = wtaver (values, weights) ## ## Return the weighted average of the values. The parameters are assumed ## to be equal-length vectors of real numbers. ## ## Examples: ## wtaver ([1 2 3 4], [1 1 1 1]) ==> 2.5 ## wtaver ([1 2 3 4], [1 2 3 4]) ==> 3 ## wtaver ([1 2 3 4], [0 0 1 1]) ==> 3.5 ##---------------------------------------------------------------------- function retval = wtaver (values, weights) retval = sum (weights .* values) / sum (weights); endfunction ##---------------------------------------------------------------------- ## Usage: retval = wtsum (values, weights) ## ## Return the weighted sum of the values. The parameters are assumed to ## be equal-length vectors of real numbers. ## ## Examples: ## wtsum ([1 2 3 4], [1 1 1 1]) ==> 10 ## wtsum ([1 2 3 4], [1 2 3 4]) ==> 30 ## wtsum ([1 2 3 4], [0 0 1 1]) ==> 7 ##---------------------------------------------------------------------- function retval = wtsum (values, weights) retval = sum (weights .* values); endfunction fuzzy-logic-toolkit/inst/setfis.m0000664000175000017500000002403412354651642016430 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} setfis (@var{fis}, @var{property}, @var{property_value}) ## @deftypefnx {Function File} {@var{fis} =} setfis (@var{fis}, @var{in_or_out}, @var{var_index}, @var{var_property}, @var{var_property_value}) ## @deftypefnx {Function File} {@var{fis} =} setfis (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf}, @var{mf_index}, @var{mf_property}, @var{mf_property_value}) ## ## Set a property (field) value of an FIS structure and return the ## updated FIS. There are three forms of setfis: ## ## @table @asis ## @item # Arguments ## Action Taken ## @item 3 ## Set a property of the FIS structure. The properties that may ## be set are: name, type, andmethod, ormethod, impmethod, ## addmethod, defuzzmethod, and version. ## @item 5 ## Set a property of an input or output variable of the FIS ## structure. The properties that may be set are: name and range. ## @item 7 ## Set a property of a membership function. The properties that ## may be set are: name, type, and params. ## @end table ## ## The types of the arguments are expected to be: ## @table @var ## @item fis ## an FIS structure ## @item property ## a string; one of 'name', 'type', 'andmethod', ## 'ormethod', 'impmethod', 'addmethod', ## 'defuzzmethod', and 'version' (case-insensitive) ## @item property_value ## a number (if property is 'version'); a string (otherwise) ## @item in_or_out ## either 'input' or 'output' (case-insensitive) ## @item var_index ## a valid integer index of an input or output FIS variable ## @item var_property ## a string; either 'name' or 'range' ## @item var_property_value ## a string (if var_property is 'name') or ## a vector range (if var_property is 'range') ## @item mf ## the string 'mf' ## @item mf_index ## a valid integer index of a membership function ## @item mf_property ## a string; one of 'name', 'type', or 'params' ## @item mf_property_value ## a string (if mf_property is 'name' or 'type'); ## an array (if mf_property is 'params') ## @end table ## ## @noindent ## Note that all of the strings representing properties above are case ## insensitive. ## ## @seealso{newfis, getfis, showfis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: setfis.m ## Last-Modified: 1 Jul 2014 ##---------------------------------------------------------------------- function fis = setfis (fis, arg2, arg3, arg4 = 'dummy', ... arg5 = 'dummy', arg6 = 'dummy', arg7 = 'dummy') switch (nargin) case 3 fis = setfis_three_args (fis, arg2, arg3); case 5 fis = setfis_five_args (fis, arg2, arg3, arg4, arg5); case 7 fis = setfis_seven_args (fis, arg2, arg3, arg4, arg5, ... arg6, arg7); otherwise puts ("Type 'help setfis' for more information.\n"); error ("setfis requires 3, 5, or 7 arguments\n"); endswitch endfunction ##---------------------------------------------------------------------- ## Function: setfis_three_args ## Purpose: Handle calls to setfis that have 3 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function fis = setfis_three_args (fis, arg2, arg3) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's first argument must be an FIS structure\n"); elseif (!(is_string (arg2) && ismember (tolower (arg2), ... {'name', 'type', 'andmethod', 'ormethod', 'impmethod', ... 'aggmethod', 'defuzzmethod', 'version'}))) puts ("Type 'help setfis' for more information.\n"); error ("incorrect second argument to setfis\n"); elseif (strcmp(tolower (arg2), 'version') && !is_real (arg3)) puts ("Type 'help setfis' for more information.\n"); error ("the third argument to setfis must be a number\n"); elseif (!strcmp(tolower (arg2), 'version') && !is_string (arg3)) puts ("Type 'help setfis' for more information.\n"); error ("the third argument to setfis must be a string\n"); endif ## Set the property (arg2) of the FIS to the property value (arg3). switch (tolower(arg2)) case 'name' fis.name = arg3; case 'version' fis.version = arg3; case 'type' fis.type = arg3; case 'andmethod' fis.andMethod = arg3; case 'ormethod' fis.orMethod = arg3; case 'impmethod' fis.impMethod = arg3; case 'aggmethod' fis.aggMethod = arg3; case 'defuzzmethod' fis.defuzzMethod = arg3; endswitch endfunction ##---------------------------------------------------------------------- ## Function: setfis_five_args ## Purpose: Handle calls to setfis that have 5 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function fis = setfis_five_args (fis, arg2, arg3, arg4, arg5) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's first argument must be an FIS structure\n"); elseif (!(is_string (arg2) && ... ismember (tolower (arg2), {'input','output'}))) puts ("Type 'help setfis' for more information.\n"); error ("setfis's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, arg2, arg3)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's third argument must be a variable index\n"); elseif (!(is_string (arg4) && ... ismember (tolower (arg4), {'name', 'range'}))) puts ("Type 'help setfis' for more information.\n"); error ("setfis's fourth argument must be 'name' or 'range'\n"); elseif (strcmp (arg4, 'name') && !is_string (arg5)) puts ("Type 'help setfis' for more information.\n"); error ("incorrect fifth argument to setfis\n"); elseif (strcmp (arg4, 'range') && !is_real_matrix (arg5)) puts ("Type 'help setfis' for more information.\n"); error ("incorrect fifth argument to setfis\n"); endif ## Set the input or output variable property (arg4) to the ## value (arg5). switch (tolower (arg2)) case 'input' switch (tolower (arg4)) case 'name' fis.input(arg3).name = arg5; case 'range' fis.input(arg3).range = arg5; endswitch case 'output' switch (tolower (arg4)) case 'name' fis.output(arg3).name = arg5; case 'range' fis.output(arg3).range = arg5; endswitch endswitch endfunction ##---------------------------------------------------------------------- ## Function: setfis_seven_args ## Purpose: Handle calls to setfis that have 7 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function fis = setfis_seven_args (fis, arg2, arg3, arg4, arg5, ... arg6, arg7) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's first argument must be an FIS structure\n"); elseif (!(is_string (arg2) && ... ismember (tolower (arg2), {'input','output'}))) puts ("Type 'help setfis' for more information.\n"); error ("setfis's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, arg2, arg3)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's third argument must be a variable index\n"); elseif (!(is_string (arg4) && strcmp (tolower (arg4), 'mf'))) puts ("Type 'help setfis' for more information.\n"); error ("setfis's fourth argument must be 'mf'\n"); elseif (!is_mf_index (fis, arg2, arg3, arg5)) puts ("Type 'help setfis' for more information.\n"); error ("setfis's fifth arg must be a membership function index\n"); elseif (!(is_string (arg6) && ismember (tolower(arg6), ... {'name', 'type', 'params'}))) puts ("Type 'help setfis' for more information.\n"); error ("incorrect sixth argument to setfis\n"); elseif (ismember (tolower (arg6), {'name', 'type'}) && ... !is_string (arg7)) puts ("Type 'help setfis' for more information.\n"); error ("incorrect seventh argument to setfis\n"); elseif (strcmp (tolower (arg6), 'params') && !is_real_matrix (arg7)) puts ("Type 'help setfis' for more information.\n"); error ("incorrect seventh argument to setfis\n"); endif ## Set the membership function property (arg6) to the value (arg7). switch (tolower (arg2)) case 'input' switch (tolower (arg6)) case 'name' fis.input(arg3).mf(arg5).name = arg7; case 'type' fis.input(arg3).mf(arg5).type = arg7; case 'params' fis.input(arg3).mf(arg5).params = arg7; endswitch case 'output' switch (tolower (arg6)) case 'name' fis.output(arg3).mf(arg5).name = arg7; case 'type' fis.output(arg3).mf(arg5).type = arg7; case 'params' fis.output(arg3).mf(arg5).params = arg7; endswitch endswitch endfunction fuzzy-logic-toolkit/inst/bounded_difference.m0000664000175000017500000000574212354647032020730 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} bounded_difference (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} bounded_difference (@var{x}, @var{y}) ## ## Return the bounded difference of the input. ## The bounded difference of two real scalars x and y is: max (0, x + y - 1) ## ## For one vector argument, apply the bounded difference to all of the elements ## of the vector. (The bounded difference is associative.) For one ## two-dimensional matrix argument, return a vector of the bounded difference ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise bounded difference. ## ## @seealso{algebraic_product, algebraic_sum, bounded_sum, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy bounded_difference ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: bounded_difference.m ## Last-Modified: 18 Aug 2012 function retval = bounded_difference (x, y = 0) if (!(isreal (x) && isreal (y))) puts ("Function 'bounded_difference' requires real scalar "); puts ("or matrix arguments.\n"); puts ("Type 'help bounded_difference' for more information.\n"); error ("invalid arguments to function bounded_difference\n"); elseif (nargin == 2 && ... (isscalar (x) || isscalar (y) || ... isequal (size (x), size (y)))) retval = max (0, (x .+ y - 1)); elseif (nargin == 1 && isvector (x)) retval = bounded_difference_of_vector (x); elseif (nargin == 1 && ndims (x) == 2) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = bounded_difference_of_vector (x(:, i)); endfor else puts ("Type 'help bounded_difference' for more information.\n"); error ("invalid arguments to function bounded_difference\n"); endif endfunction function retval = bounded_difference_of_vector (real_vector) x = 1; for i = 1 : length (real_vector) y = real_vector(i); x = max (0, (x + y - 1)); endfor retval = x; endfunction fuzzy-logic-toolkit/inst/investment_portfolio_demo.m0000664000175000017500000000733012354647032022426 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} investment_portfolio_demo ## Demonstrate the use of the Octave Fuzzy Logic Toolkit to read and evaluate ## a Mamdani-type FIS stored in a file. Also demonstrate the use of hedges and ## weights in the FIS rules, the use of the Einstein product and sum as the ## T-norm/S-norm pair, and the non-standard use of the Einstein sum as the ## aggregation method. ## ## The demo: ## @itemize @minus ## @item ## reads the FIS structure from a file ## @item ## plots the input and output membership functions ## @item ## plots the FIS output as a function of the inputs ## @item ## plots the output of the 4 individual rules for (Age, Risk-Tolerance) = (40, 7) ## @item ## plots the aggregated fuzzy output and the crisp output for ## (Age, Risk-Tolerance) = (40, 7) ## @item ## shows the rules in verbose format in the Octave window ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Directory: fuzzy-logic-toolkit/inst ## Filename: investment_portfolio_demo.m ## Last-Modified: 19 Aug 2012 ## Read the FIS structure from a file. fis=readfis ('investment_portfolio'); ## Plot the input and output membership functions. plotmf (fis, 'input', 1); plotmf (fis, 'input', 2); plotmf (fis, 'output', 1); ## Plot the Percentage-In-Stocks a function of Age and Risk-Tolerance. gensurf (fis, [1 2], 1); ## Calculate the Percentage-In-Stocks using ## (Age, Risk-Tolerance) = (40, 7). [output, rule_input, rule_output, fuzzy_output] = ... evalfis ([40 7], fis, 1001); ## Plot the output (Percentage-In-Stocks) of the individual fuzzy rules ## on one set of axes. x_axis = linspace (fis.output(1).range(1), ... fis.output(1).range(2), 1001); colors = ['r' 'b' 'm' 'g']; figure ('NumberTitle', 'off', 'Name', ... 'Output of Fuzzy Rules 1-4 for (Age, Risk Tolerance) = (40, 7)'); for i = 1 : 4 y_label = [colors(i) ";Rule " num2str(i) ";"]; plot (x_axis, rule_output(:,i), y_label, 'LineWidth', 2); hold on; endfor ylim ([-0.1, 1.1]); xlabel ('Percentage in Stocks', 'FontWeight', 'bold'); grid; hold; ## Plot the first aggregated fuzzy output and the crisp output ## (Percentage-In-Stocks) on one set of axes. figure('NumberTitle', 'off', 'Name', ... 'Aggregation and Defuzzification for (Age, Risk Tolerace) = (40, 7)'); plot (x_axis, fuzzy_output(:, 1), "b;Aggregated Fuzzy Output;", ... 'LineWidth', 2); hold on; crisp_output = evalmf(x_axis, output(1), 'constant'); y_label = ["r;Crisp Output = " num2str(output(1)) "%;"]; plot (x_axis, crisp_output, y_label, 'LineWidth', 2); ylim ([-0.1, 1.1]); xlabel ('Percentage in Stocks', 'FontWeight', 'bold'); grid; hold; ## Show the rules in English. puts ("\nInvestment Portfolio Calculator Rules:\n\n"); showrule (fis); fuzzy-logic-toolkit/inst/heart_disease_demo_2.m0000664000175000017500000000474112354647032021161 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} heart_disease_demo_2 ## ## Demonstrate the use of the Octave Fuzzy Logic Toolkit to read and evaluate a ## Sugeno-type FIS stored in a file. ## ## The demo: ## @itemize @minus ## @item ## reads the FIS structure from a file ## @item ## plots the input membership functions ## @item ## plots the (constant) output functions ## @item ## plots the FIS output as a function of the inputs ## @item ## evaluates the Sugeno-type FIS for four inputs ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Note: This example is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: heart_disease_demo_2.m ## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. ## (Alternatively, to select heart_disease_risk.fis using the dialog, ## replace the following line with ## fis = readfis (); fis = readfis('heart_disease_risk.fis'); ## Plot the input and output membership functions. plotmf (fis, 'input', 1); plotmf (fis, 'input', 2); plotmf (fis, 'output', 1); ## Plot the Heart Disease Risk as a function of LDL-Level and HDL-Level. gensurf (fis); ## Calculate the Heart Disease Risk for 4 sets of LDL-HDL values: puts ("\nFor the following four sets of LDL-HDL values:\n\n"); ldl_hdl = [129 59; 130 60; 90 65; 205 40] puts ("\nThe Heart Disease Risk is:\n\n"); heart_disease_risk = evalfis (ldl_hdl, fis, 1001) fuzzy-logic-toolkit/inst/hamacher_product.m0000664000175000017500000000637012354647032020444 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} hamacher_product (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} hamacher_product (@var{x}, @var{y}) ## ## Return the Hamacher product of the input. ## The Hamacher product of two real scalars x and y is: ## (x * y) / (x + y - x * y) ## ## For one vector argument, apply the Hamacher product to all of the elements ## of the vector. (The Hamacher product is associative.) For one ## two-dimensional matrix argument, return a vector of the Hamacher product ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise Hamacher product. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy hamacher_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: hamacher_product.m ## Last-Modified: 20 Aug 2012 function retval = hamacher_product (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) retval = (x * y) / (x + y - x * y); endfunction function retval = vector_arg (real_vector) x = 1; for i = 1 : length (real_vector) y = real_vector(i); if (x == 0 && y == 0) x = 0; else x = (x * y) / (x + y - x * y); endif endfor retval = x; endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help hamacher_product' for more information.\n"); error ("invalid arguments to function hamacher_product\n"); endfunction fuzzy-logic-toolkit/inst/xie_beni_index.m0000664000175000017500000001157112354647032020104 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{vxb} =} xie_beni_index (@var{input_data}, @var{cluster_centers}, @var{soft_partition}) ## ## Return the Xie-Beni validity index for a given soft partition. ## ## The arguments to xie_beni_index are: ## @itemize @w ## @item ## @var{input_data} - a matrix of input data points; each row corresponds to one point ## @item ## @var{cluster_centers} - a matrix of cluster centers; each row corresponds to one point ## @item ## @var{soft_partition} - the membership degree of each input data point in each cluster ## @end itemize ## ## The return value is: ## @itemize @w ## @item ## @var{vxb} - the Xie-Beni validity index for the given partition ## @end itemize ## ## For demos of this function, please type: ## @example ## demo 'fcm' ## demo 'gustafson_kessel' ## @end example ## ## For more information about the @var{input_data}, @var{cluster_centers}, ## and @var{soft_partition} matrices, please see the documentation for function ## fcm. ## ## @seealso{fcm, gustafson_kessel, partition_coeff, partition_entropy} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy xie beni cluster validity ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: xie_beni_index.m ## Last-Modified: 4 Sep 2012 function vxb = xie_beni_index (input_data, cluster_centers, ... soft_partition) ## If xie_beni_index was called with an incorrect number of arguments, ## or the argument does not have the correct type, print an error ## message and halt. if (nargin != 3) puts ("Type 'help xie_beni_index' for more information.\n"); error ("xie_beni_index requires 3 arguments\n"); elseif (!is_real_matrix (input_data)) puts ("Type 'help xie_beni_index' for more information.\n"); error ("xie_beni_index's first argument must be matrix of reals\n"); elseif (!(is_real_matrix (cluster_centers) && (columns (cluster_centers) == columns (input_data)))) puts ("Type 'help xie_beni_index' for more information.\n"); puts ("xie_beni_index's second argument must be matrix of reals\n"); puts ("with the same number of columns as the input_data\n"); error ("invalid second argument to xie_beni_index\n"); elseif (!(is_real_matrix (soft_partition) && (min (min (soft_partition)) >= 0) && (max (max (soft_partition)) <= 1))) puts ("Type 'help xie_beni_index' for more information.\n"); puts ("xie_beni_index's third argument must be a matrix of\n"); puts ("real numbers mu, with 0 <= mu <= 1\n"); error ("invalid third argument to xie_beni_index\n"); endif ## Compute and return the Xie-Beni index. vxb = xie_beni_private (input_data, cluster_centers, soft_partition); endfunction ##---------------------------------------------------------------------- ## Function: xie_beni_private ## Purpose: Return the Xie-Beni index for the given soft partition. ## Note: The following is an implementation of Equations 13.11, ## 13.12, and 13.13 in Fuzzy Logic: Intelligence, Control and ## Information, by J. Yen and R. Langari, Prentice Hall, 1999, ## page 384 (International Edition). ##---------------------------------------------------------------------- function vxb = xie_beni_private (X, V, Mu) sqr_dist = square_distance_matrix (X, V); sum_sigma = sum (sum (Mu .* sqr_dist)); n = rows (X); d_sqr_min = min_sqr_dist_between_centers (V); vxb = sum_sigma / (n * d_sqr_min); endfunction ##---------------------------------------------------------------------- ## Function: min_sqr_dist_between_centers ## Purpose: Return the square of the minimum distance between ## cluster centers. ##---------------------------------------------------------------------- function d_sqr_min = min_sqr_dist_between_centers (V) k = rows (V); d_sqr_matrix = NaN(k, k); for i = 1 : (k - 1) Vi = V(i, :); for j = (i + 1) : k Vi_to_Vj = V(j, :) - Vi; d_sqr_matrix(i, j) = sum (Vi_to_Vj .* Vi_to_Vj); endfor endfor d_sqr_min = min (min (d_sqr_matrix)); endfunction fuzzy-logic-toolkit/inst/evalmf.m0000664000175000017500000001064712354647032016410 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} evalmf (@var{x}, @var{param}, @var{mf_type}) ## @deftypefnx {Function File} {@var{y} =} evalmf (@var{x}, @var{param}, @var{mf_type}, @var{hedge}) ## @deftypefnx {Function File} {@var{y} =} evalmf (@var{x}, @var{param}, @var{mf_type}, @var{hedge}, @var{not_flag}) ## @deftypefnx {Function File} {@var{y} =} evalmf (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, @var{mf_type}) ## @deftypefnx {Function File} {@var{y} =} evalmf (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, @var{mf_type}, @var{hedge}) ## @deftypefnx {Function File} {@var{y} =} evalmf (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, @var{mf_type}, @var{hedge}, @var{not_flag}) ## ## For a given domain, set of parameters, membership function type, and ## optional hedge and not_flag, return the corresponding y-values for the ## membership function. ## ## The argument @var{x} must be a real number or a non-empty list of strictly ## increasing real numbers, @var{param} must be a valid parameter or a vector ## of valid parameters for @var{mf_type}, and @var{mf_type} must be a string ## corresponding to a membership function type. Evalmf handles both built-in and ## custom membership functions. ## ## For custom hedges and the four built-in hedges "somewhat", "very", ## "extremely", and "very very", raise the membership function values to ## the power corresponding to the hedge. ## ## @example ## @group ## (fraction == .05) <=> somewhat x <=> mu(x)^0.5 <=> sqrt(mu(x)) ## (fraction == .20) <=> very x <=> mu(x)^2 <=> sqr(mu(x)) ## (fraction == .30) <=> extremely x <=> mu(x)^3 <=> cube(mu(x)) ## (fraction == .40) <=> very very x <=> mu(x)^4 ## (fraction == .dd) <=> x <=> mu(x)^(dd/10) ## @end group ## @end example ## ## The @var{not_flag} negates the membership function using: ## @example ## mu(not(x)) = 1 - mu(x) ## @end example ## ## @noindent ## To run the demonstration code, type @t{demo('evalmf')} at the Octave prompt. ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership evaluate ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalmf.m ## Last-Modified: 26 Jun 2014 function y = evalmf (x, params, mf_type, hedge = 0, not_flag = false) ## If the caller did not supply 3 - 5 argument values with the correct ## types, print an error message and halt. if ((nargin < 3) || (nargin > 5)) puts ("Type 'help evalmf' for more information.\n"); error ("evalmf requires between 3 and 5 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help evalmf' for more information.\n"); error ("evalmf's first argument must be a valid domain\n"); elseif (!is_string (mf_type)) puts ("Type 'help evalmf' for more information.\n"); error ("evalmf's third argument must be a string\n"); elseif (!is_real (hedge)) puts ("Type 'help evalmf' for more information.\n"); error ("evalmf's fourth argument must be a real number\n"); elseif (!isbool (not_flag)) puts ("Type 'help evalmf' for more information.\n"); error ("evalmf's fifth argument must be a Boolean\n"); endif ## Calculate and return the y values of the membership function on ## the domain x. y = evalmf_private (x, params, mf_type, hedge, not_flag); endfunction %!demo %! x = 0:100; %! params = [25 50 75]; %! mf_type = 'trimf'; %! y = evalmf(x, params, mf_type); %! figure('NumberTitle', 'off', 'Name', "evalmf(0:100, [25 50 75], 'trimf')"); %! plot(x, y, 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/partition_coeff.m0000664000175000017500000000620612354647032020305 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{vpc} =} partition_coeff (@var{soft_partition}) ## ## Return the partition coefficient for a given soft partition. ## ## The argument to partition_coeff is: ## @itemize @w ## @item ## @var{soft_partition} - the membership degree of each input data point in each cluster ## @end itemize ## ## The return value is: ## @itemize @w ## @item ## @var{vpc} - the partition coefficient for the given soft partition ## @end itemize ## ## For demos of this function, please type: ## @example ## demo 'fcm' ## demo 'gustafson_kessel' ## @end example ## ## For more information about the @var{soft_partition} matrix, please see the ## documentation for function fcm. ## ## @seealso{fcm, gustafson_kessel, partition_entropy, xie_beni_index} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit partition coefficient cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_coeff.m ## Last-Modified: 4 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.9 (corrected ## -- the equation in the book omits the exponent 2) in ## Fuzzy Logic: Intelligence, Control and Information, by J. Yen ## and R. Langari, Prentice Hall, 1999, page 384 (International ## Edition). ##---------------------------------------------------------------------- function vpc = partition_coeff (soft_partition) ## If partition_coeff was called with an incorrect number of ## arguments, or the argument does not have the correct type, ## print an error message and halt. if (nargin != 1) puts ("Type 'help partition_coeff' for more information.\n"); error ("partition_coeff requires 1 argument\n"); elseif (!(is_real_matrix (soft_partition) && (min (min (soft_partition)) >= 0) && (max (max (soft_partition)) <= 1))) puts ("Type 'help partition_coeff' for more information.\n"); puts ("partition_coeff's argument must be a matrix of real "); puts ("numbers mu, with 0 <= mu <= 1\n"); error ("invalid argument to partition_coeff\n"); endif ## Compute and return the partition coefficient. soft_part_sqr = soft_partition .* soft_partition; vpc = (sum (sum (soft_part_sqr))) / columns (soft_partition); endfunction fuzzy-logic-toolkit/inst/showrule.m0000664000175000017500000004312212354647032017000 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {} showrule (@var{fis}) ## @deftypefnx {Function File} {} showrule (@var{fis}, @var{index_list}) ## @deftypefnx {Function File} {} showrule (@var{fis}, @var{index_list}, @var{format}) ## @deftypefnx {Function File} {} showrule (@var{fis}, @var{index_list}, @var{'verbose'}, @var{language}) ## @deftypefnx {Function File} {} showrule (@var{fis}, @var{index_list}, @var{'verbose'}, @var{'custom'}, @var{"and" "or" "If" "then" "is" "isn't" "somewhat" "very" "extremely" "very very"}) ## ## ## Show the rules for an FIS structure in verbose, symbolic, or indexed format. ## Built in languages for the 'verbose' format are: English, ## Chinese (or Mandarin, Pinyin), Russian (or Pycckii, Russkij), French (or Francais), ## Spanish (or Espanol), and German (or Deutsch). The names of the languages are ## case-insensitive, Chinese is written in Pinyin, and Russian is transliterated. ## ## To use a custom language, enter 'verbose' and 'custom' for the third and ## fourth parameters, respectively, and a cell array of ten strings (to specify ## the custom language) corresponding to the English @{"and" "or" "If" "then" ## "is" "isn't" "somewhat" "very" "extremely" "very very"@} for the fifth ## parameter. ## ## @noindent ## To run the demonstration code, type @t{demo('showrule')} at the ## Octave prompt. ## ## @seealso{addrule, getfis, showfis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy rule ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: showrule.m ## Last-Modified: 20 Aug 2012 function showrule (fis, index_list = [], format = 'verbose', ... language = 'english', ... verbose_strings = {"and" "or" "If" "then" "is" ... "isn't" "somewhat" "very" ... "extremely" "very very"}) ##-------------------------------------------------------------------- ## If the caller did not supply between 1 and 5 arguments with the ## correct types, print an error message and halt. ##-------------------------------------------------------------------- if (!(nargin >= 1 && nargin <= 5)) puts ("Type 'help showrule' for more information.\n"); error ("showrule requires between 1 and 5 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help showrule' for more information.\n"); error ("showrule's first argument must be an FIS structure\n"); elseif ((nargin >= 2) && ... !is_rule_index_list (index_list, length (fis.rule))) puts ("Type 'help showrule' for more information.\n"); error ("showrule's second arg must be a vector of rule indices\n"); elseif ((nargin >= 3) && !is_format (format)) puts ("Type 'help showrule' for more information.\n"); error ("showrule's third argument must specify the format\n"); elseif ((nargin == 4) && isequal (tolower (language), "custom")) puts ("Type 'help showrule' for more information.\n"); error ("please specify custom verbose strings in the fifth arg\n"); elseif ((nargin == 4) && !is_builtin_language (language)) puts ("Type 'help showrule' for more information.\n"); error ("showrule's fourth arg must specify a built-in language\n"); elseif ((nargin == 5) && !isequal (tolower (language), "custom")) puts ("Type 'help showrule' for more information.\n"); error ("use 'custom' for the 4th arg to specify custom strings\n"); endif ##-------------------------------------------------------------------- ## If showrule was called with only one argument, create the default ## index list (all rule indices, in ascending order). ##-------------------------------------------------------------------- if (nargin == 1) index_list = 1 : length (fis.rule); endif ##-------------------------------------------------------------------- ## Show the rules in indexed, symbolic, or verbose format. ##-------------------------------------------------------------------- switch (tolower (format)) case 'indexed' showrule_indexed_format (fis, index_list); case 'symbolic' showrule_symbolic_format (fis, index_list); case 'verbose' showrule_verbose_format (fis, index_list, language, ... verbose_strings); endswitch endfunction ##---------------------------------------------------------------------- ## Function: get_verbose_hedge ## Purpose: For no hedge, return the empty string. ## For the built-in hedges, return the verbose string in the ## language used in the cell array verbose_strings (the second ## parameter). For custom hedges, return the power (rounded to ## two digits) to which the membership function matching value ## will be raised. ##---------------------------------------------------------------------- function hedge = get_verbose_hedge (mf_index_and_hedge, verbose_strings) mf_index_and_hedge = abs (mf_index_and_hedge); mf_index = fix (mf_index_and_hedge); hedge_num = round (100 * (mf_index_and_hedge - mf_index)); switch (hedge_num) case 0 ## .00 <=> no hedge <=> mu(x) hedge = ""; case 5 ## .05 <=> somewhat x <=> mu(x)^0.5 hedge = verbose_strings{7}; case 20 ## .20 <=> very x <=> mu(x)^2 hedge = verbose_strings{8}; case 30 ## .30 <=> extremely x <=> mu(x)^3 hedge = verbose_strings{9}; case 40 ## .40 <=> very very x <=> mu(x)^4 hedge = verbose_strings{10}; otherwise ## For custom hedge, return the hedge = hedge_num / 10; ## power dd/10. That is: endswitch ## .dd <=> x ## <=> mu(x)^(dd/10) endfunction ##---------------------------------------------------------------------- ## Function: get_is_or_isnt ## Purpose: Return the verbose string for "is" or "isn't" for the given ## membership function value. If the membership function value ## is 0, return the empty string. ##---------------------------------------------------------------------- function is_or_isnt = get_is_or_isnt (mem_fcn_value, verbose_strings) if (mem_fcn_value > 0) is_or_isnt = verbose_strings{5}; elseif (mem_fcn_value < 0) is_or_isnt = verbose_strings{6}; else is_or_isnt = ""; endif endfunction ##---------------------------------------------------------------------- ## Function: get_mf_name ## Purpose: Return the specified membership function name. ##---------------------------------------------------------------------- function mf_name = get_mf_name (mem_fcn_value, fis_input_or_output) mf_name = fis_input_or_output.mf(abs(fix(mem_fcn_value))).name; endfunction ##---------------------------------------------------------------------- ## Function: get_verbose_strings ## Purpose: Return a cell array of ten strings corresponding to: ## {"and" "or" "If" "then" "is" "isn't" ... ## "somewhat" "very" "extremely" "very very"} ## for the (built-in) language specified by the argument. ## Custom verbose strings are specified by an argument to ## showrule -- they are not handled by this function. ##---------------------------------------------------------------------- function str = get_verbose_strings (language) switch (language) case 'english' str = {"and" "or" "If" "then" "is" "isn't" ... "somewhat" "very" "extremely" "very very"}; case {'chinese' 'mandarin' 'pinyin'} str = {"he" "huo" "Ruguo" "name" "shi" "bu shi" ... "youdian" "hen" "feichang" "feichang feichang"}; case {'russian' 'russkij' 'pycckii'} str = {"i" "ili" "ecli" "togda" "" "ne" ... "nemnogo" "ochen" "prevoshodnoye" "ochen ochen"}; case {'spanish' 'espanol'} str = {"y" "o" "Si" "entonces" "es" "no es" ... "un poco" "muy" "extremadamente" "muy muy"}; case {'francais' 'french'} str = {"et" "ou" "Si" "alors" "est" "n'est pas" ... "un peu" "tres" "extremement" "tres tres"}; case {'deutsch' 'german'} str = {"und" "oder" "Wenn" "dann" "ist" "ist nicht" ... "ein wenig" "sehr" "auBerst" "sehr sehr"}; endswitch endfunction ##---------------------------------------------------------------------- ## Function: showrule_indexed_format ## Purpose: Show the rules in indexed format. ##---------------------------------------------------------------------- function showrule_indexed_format (fis, index_list) num_inputs = columns (fis.input); num_outputs = columns (fis.output); for i = 1 : length (index_list) current_ant = fis.rule(index_list(i)).antecedent; current_con = fis.rule(index_list(i)).consequent; current_wt = fis.rule(index_list(i)).weight; current_connect = fis.rule(index_list(i)).connection; ##------------------------------------------------------------------ ## Print membership functions for the inputs. ##------------------------------------------------------------------ for j = 1 : num_inputs if (is_int (current_ant(j))) printf ("%d", current_ant(j)); else printf ("%.2f", current_ant(j)); endif if (j == num_inputs) puts (","); endif puts (" "); endfor ##------------------------------------------------------------------ ## Print membership functions for the outputs. ##------------------------------------------------------------------ for j = 1 : num_outputs if (is_int (current_con(j))) printf ("%d", current_con(j)); else printf ("%.2f", current_con(j)); endif if (j < num_outputs) puts (" "); endif endfor ##------------------------------------------------------------------ ## Print the weight in parens. ##------------------------------------------------------------------ if (is_int (current_wt)) printf (" (%d) : ", current_wt); else printf (" (%.4f) : ", current_wt); endif ##------------------------------------------------------------------ ## Print the connection and a newline. ##------------------------------------------------------------------ printf ("%d\n", current_connect); endfor endfunction ##---------------------------------------------------------------------- ## Function: showrule_symbolic_format ## Purpose: Show the rules in symbolic format. ##---------------------------------------------------------------------- function showrule_symbolic_format (fis, index_list) verbose_strings = {"&&" "||" "" "=>" "==" "!=" ... 0.5 2.0 3.0 4.0}; showrule_verbose_format (fis, index_list, "custom", ... verbose_strings, true); endfunction ##---------------------------------------------------------------------- ## Function: showrule_verbose_format ## Purpose: Show the rules in verbose format. ##---------------------------------------------------------------------- function showrule_verbose_format (fis, index_list, language, ... verbose_strings, ... suppress_comma = false) num_inputs = columns (fis.input); num_outputs = columns (fis.output); ##-------------------------------------------------------------------- ## Get verbose strings in the (built-in) language specified. Note ## that the strings for custom languages are supplied by the user. ##-------------------------------------------------------------------- language = tolower (language); if (isequal ("custom", language)) str = verbose_strings; else str = get_verbose_strings (language); endif and_str = str{1}; if_str = str{3}; then_str = str{4}; ##-------------------------------------------------------------------- ## For each index in the index_list, print the index number, the rule, ## and the weight. ##-------------------------------------------------------------------- for i = 1 : length (index_list) connect_str = str{fis.rule(index_list(i)).connection}; current_ant = fis.rule(index_list(i)).antecedent; current_con = fis.rule(index_list(i)).consequent; current_wt = fis.rule(index_list(i)).weight; ##------------------------------------------------------------------ ## For j = 1, print: ## . If ( [] ) ## and for 2 <= j <= num_inputs, print: ## ( [] ) ## in the specified language. Custom hedges are printed in the form: ## ( ^) ##------------------------------------------------------------------ first_input_printed = true; for j = 1 : num_inputs if (j == 1) printf ("%d.", index_list(i)); endif input_name = fis.input(j).name; is_or_isnt = get_is_or_isnt (current_ant(j), str); if (!isempty (is_or_isnt)) hedge = get_verbose_hedge (current_ant(j), str); mf_name = get_mf_name (current_ant(j), fis.input(j)); if (first_input_printed) first_input_printed = false; printf (" %s", if_str); else printf (" %s", connect_str); endif if (isempty (hedge)) printf (" (%s %s %s)", input_name, is_or_isnt, mf_name); elseif (ischar (hedge)) printf (" (%s %s %s %s)", input_name, is_or_isnt, hedge, ... mf_name); else printf (" (%s %s %s^%3.1f)", input_name, is_or_isnt, ... mf_name, hedge); endif endif endfor ##------------------------------------------------------------------ ## Print the consequent in the form: ## ", then (output-name is [hedge] mem-fcn-name) and ## (output-name is [hedge] mem-fcn-name) and ## ... ## (output-name is [hedge] mem-fcn-name)" ## ## Only the outputs for which the membership function index is ## non-zero are printed. Negative membership function indices ## indicate "isn't" instead of "is", and the fractional part of ## the membership function index indicates a hedge, which is also ## printed. ## ## For non-numeric and empty hedges, print each of the outputs ## using the form: ## ( [] ) ## For custom and numeric hedges, use the form: ## ( ^) ## ## The comma may be suppressed (as it is for symbolic output) by ## calling the function with suppress_comma == true. ##------------------------------------------------------------------ first_output_printed = true; for j = 1 : num_outputs output_name = fis.output(j).name; is_or_isnt = get_is_or_isnt (current_con(j), str); if (!isempty (is_or_isnt)) hedge = get_verbose_hedge (current_con(j), str); mf_name = get_mf_name (current_con(j), fis.output(j)); if (first_output_printed) first_output_printed = false; if (suppress_comma) printf (" %s", then_str); else printf (", %s", then_str); endif else printf (" %s", and_str); endif if (isempty (hedge)) printf (" (%s %s %s)", output_name, is_or_isnt, mf_name); elseif (ischar (hedge)) printf (" (%s %s %s %s)", output_name, is_or_isnt, hedge, ... mf_name); else printf (" (%s %s %s^%3.1f)", output_name, is_or_isnt, ... mf_name, hedge); endif endif endfor ##------------------------------------------------------------------ ## Finally, print the weight in parens and a newline: ## " ()" ##------------------------------------------------------------------ if is_int (current_wt) printf (" (%d)\n", current_wt); else printf (" (%.4f)\n", current_wt); endif endfor endfunction ##---------------------------------------------------------------------- ## Embedded Demos ##---------------------------------------------------------------------- %!demo %! fis = readfis ('sugeno_tip_calculator.fis'); %! puts ("Output of: showrule(fis)\n"); %! showrule (fis) %! puts ("\n"); %!demo %! fis = readfis ('sugeno_tip_calculator.fis'); %! puts ("Output of: showrule(fis, [2 4], 'symbolic')\n"); %! showrule (fis, [2 4], 'symbolic') %! puts ("\n"); %!demo %! fis = readfis ('sugeno_tip_calculator.fis'); %! puts ("Output of: showrule(fis, 1:4, 'indexed')\n"); %! showrule (fis, 1:4, 'indexed') %! puts ("\n"); %!demo %! fis = readfis ('sugeno_tip_calculator.fis'); %! puts ("Output of: showrule(fis, 1, 'verbose', 'francais')\n"); %! showrule (fis, 1, 'verbose', 'francais') %! puts ("\n"); fuzzy-logic-toolkit/inst/partition_entropy.m0000664000175000017500000000672412354647032020730 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{vpe} =} partition_entropy (@var{soft_partition}, @var{a}) ## ## Return the partition entropy for a given soft partition. ## ## The arguments to partition_entropy are: ## @itemize @w ## @item ## @var{soft_partition} - the membership degree of each input data point in each cluster ## @item ## @var{a} - the log base to use in the calculation; must be a real number a > 1 ## @end itemize ## ## The return value is: ## @itemize @w ## @item ## @var{vpe} - the partition entropy for the given soft partition ## @end itemize ## ## For demos of this function, please type: ## @example ## demo 'fcm' ## demo 'gustafson_kessel' ## @end example ## ## For more information about the @var{soft_partition} matrix, please see the ## documentation for function fcm. ## ## @seealso{fcm, gustafson_kessel, partition_coeff, xie_beni_index} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit partition entropy cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_entropy.m ## Last-Modified: 4 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.10 in ## Fuzzy Logic: Intelligence, Control and Information, by J. Yen ## and R. Langari, Prentice Hall, 1999, page 384 (International ## Edition). ##---------------------------------------------------------------------- function vpe = partition_entropy (soft_partition, a) ## If partition_entropy was called with an incorrect number of ## arguments, or the argument does not have the correct type, print an ## error message and halt. if (nargin != 2) puts ("Type 'help partition_entropy' for more information.\n"); error ("partition_entropy requires 2 arguments\n"); elseif (!(is_real_matrix (soft_partition) && (min (min (soft_partition)) >= 0) && (max (max (soft_partition)) <= 1))) puts ("Type 'help partition_entropy' for more information.\n"); puts ("partition_entropy's first argument must be a matrix of "); puts ("real numbers mu, with 0 <= mu <= 1\n"); error ("invalid first argument to partition_entropy\n"); elseif (!(is_real (a) && a > 1)) puts ("Type 'help partition_entropy' for more information.\n"); puts ("partition_entropy's second argument argument must be a "); puts ("real number a > 1\n"); error ("invalid second argument to partition_entropy\n"); endif ## Compute and return the partition entropy. n = columns (soft_partition); Mu = soft_partition; log_a_Mu = log (Mu) / log (a); vpe = -(sum (sum (Mu .* log_a_Mu))) / n; endfunction fuzzy-logic-toolkit/inst/linear_tip_calculator.fis0000664000175000017500000000317312354647032022016 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: linear_tip_calculator.fis ## Last-Modified: 28 Aug 2012 [System] Name='Linear-Tip-Calculator' Type='sugeno' Version=2.0 NumInputs=2 NumOutputs=1 NumRules=4 AndMethod='min' OrMethod='max' ImpMethod='min' AggMethod='max' DefuzzMethod='wtaver' [Input1] Name='Food-Quality' Range=[1 10] NumMFs=2 MF1='Bad':'trapmf',[0 1 3 7] MF2='Good':'trapmf',[3 7 10 11] [Input2] Name='Service' Range=[1 10] NumMFs=2 MF1='Bad':'trapmf',[0 1 3 7] MF2='Good':'trapmf',[3 7 10 11] [Output1] Name='Tip' Range=[10 20] NumMFs=3 MF1='Ten-Percent':'linear',[0 0 10] MF2='Fifteen-Percent':'linear',[0 0 15] MF3='Twenty-Percent':'linear',[0 0 20] [Rules] 1 1, 1 (1) : 1 1 2, 2 (1) : 1 2 1, 2 (1) : 1 2 2, 3 (1) : 1 fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis0000664000175000017500000000477512354647032022055 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: sugeno_tip_calculator.fis ## Last-Modified: 28 Aug 2012 % Sugeno Tip Calculator % Computes cheap, average, and generous tips % given food quality and service ratings. [System] Name = 'Sugeno-Tip-Calculator' Type = 'sugeno' Version = 1.0 NumInputs = 2 NumOutputs = 3 NumRules = 10 AndMethod = 'einstein_product' OrMethod = 'einstein_sum' ImpMethod = 'prod' AggMethod = 'sum' DefuzzMethod = 'wtaver' [Input1] Name = 'Food-Quality' Range = [1 10] NumMFs = 2 MF1 = 'Bad' : 'trapmf', [0 1 3 7] MF2 = 'Good' : 'trapmf', [3 7 10 11] [Input2] Name = 'Service' Range = [1 10] NumMFs = 2 MF1 = 'Bad' : 'trapmf', [0 1 3 7] MF2 = 'Good' : 'trapmf', [3 7 10 11] [Output1] Name = 'Cheap-Tip' Range = [5 25] NumMFs = 3 MF1 = 'Low' : 'constant', [10] MF2 = 'Medium' : 'constant', [15] MF3 = 'High' : 'constant', [20] [Output2] Name = 'Average-Tip' Range = [5 25] NumMFs = 3 MF1 = 'Low' : 'constant', [10] MF2 = 'Medium' : 'constant', [15] MF3 = 'High' : 'constant', [20] [Output3] Name = 'Generous-Tip' Range = [5 25] NumMFs = 3 MF1 = 'Low' : 'constant', [10] MF2 = 'Medium' : 'constant', [15] MF3 = 'High' : 'constant', [20] [Rules] 1.30 1.30, 1.30 1.20 1.00 (1) : 1 2.00 1.30, 1.00 1.00 2.00 (1) : 1 2.20 1.20, 1.00 2.00 3.00 (1) : 1 1.00 1.00, 1.00 1.00 2.00 (1) : 1 2.00 1.00, 1.00 2.00 3.00 (1) : 1 2.30 1.00, 1.00 2.00 3.20 (1) : 1 1.00 2.00, 1.00 2.00 3.00 (1) : 1 2.00 2.00, 2.00 2.00 3.20 (1) : 1 1.20 2.20, 1.00 2.00 3.00 (1) : 1 2.40 2.40, 3.00 3.20 3.30 (1) : 1 fuzzy-logic-toolkit/inst/cubic_approx_demo.m0000664000175000017500000000363612354647032020620 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} cubic_approx_demo ## ## Demonstrate the use of the Octave Fuzzy Logic Toolkit to approximate a ## non-linear function using a Sugeno-type FIS with linear output functions. ## ## The demo: ## @itemize @minus ## @item ## reads an FIS structure from a file ## @item ## plots the input membership functions ## @item ## plots the (linear) output functions ## @item ## plots the FIS output as a function of the input ## @end itemize ## ## @seealso{heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Directory: fuzzy-logic-toolkit/inst ## Filename: cubic_approx_demo.m ## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('cubic_approximator.fis'); ## Plot the input membership functions and linear output functions. plotmf (fis, 'input', 1); plotmf (fis, 'output', 1, -150, 150); ## Plot the FIS output y as a function of the input x. gensurf (fis); fuzzy-logic-toolkit/inst/gbellmf.m0000664000175000017500000001011112354647032016530 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} gbellmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} gbellmf (@var{[x1 x2 ... xn]}, @var{[a b c]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b c]}), ## return the corresponding @var{y} values for the generalized bell-shaped ## membership function. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, @var{a}, @var{b}, and @var{c} must be real numbers, ## @var{a} must be non-zero, and @var{b} must be an integer. This membership ## function satisfies the equation: ## @example ## f(x) = 1/(1 + (abs((x - c)/a))^(2 * b)) ## @end example ## which always returns values in the range [0, 1]. ## ## The parameters @var{a}, @var{b}, and @var{c} give: ## @example ## @group ## a == controls the width of the curve at f(x) = 0.5; ## f(c-a) = f(c+a) = 0.5 ## b == controls the slope of the curve at x = c-a and x = c+a; ## f'(c-a) = b/2a and f'(c+a) = -b/2a ## c == the center of the curve ## @end group ## @end example ## ## This membership function has a value of 0.5 at the two points c - a and ## c + a, and the width of the curve at f(x) == 0.5 is 2 * |a|: ## @example ## @group ## f(c - a) == f(c + a) == 0.5 ## 2 * |a| == the width of the curve at f(x) == 0.5 ## @end group ## @end example ## ## @noindent ## The generalized bell-shaped membership function is continuously ## differentiable and is symmetric about the line x = c. ## ## @noindent ## To run the demonstration code, type @t{demo('gbellmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, pimf, psigmf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership bell-shaped bell ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gbellmf.m ## Last-Modified: 19 Aug 2012 function y = gbellmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help gbellmf' for more information.\n"); error ("gbellmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help gbellmf' for more information.\n"); error ("gbellmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('gbellmf', params)) puts ("Type 'help gbellmf' for more information.\n"); error ("gbellmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a = params(1); b = params(2); c = params(3); y_val = @(x_val) 1 / (1 + (abs ((x_val - c)/a))^(2 * b)); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:255; %! params = [20 4 100]; %! y1 = gbellmf(x, params); %! params = [30 3 100]; %! y2 = gbellmf(x, params); %! params = [40 2 100]; %! y3 = gbellmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'gbellmf demo'); %! plot(x, y1, 'r;params = [20 4 100];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [30 3 100];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [40 2 100];', 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/newfis.m0000664000175000017500000001007112354647032016420 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- 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 arguments will be used: ## @itemize @bullet ## @item ## @var{fis_type} = 'mamdani' ## @item ## @var{and_method} = 'min' ## @item ## @var{or_method} = 'max' ## @item ## @var{imp_method} = 'min' ## @item ## @var{agg_method} = 'max' ## @item ## @var{defuzz_method} = 'centroid' ## @item ## @var{fis_version} = 1.0 ## @end itemize ## ## @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: 20 Aug 2012 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)) puts ("Type 'help newfis' for more information.\n"); 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))) puts ("Type 'help newfis' for more information.\n"); 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 fuzzy-logic-toolkit/inst/evalfis.m0000664000175000017500000002461212354647032016564 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{output} =} evalfis (@var{user_input}, @var{fis}) ## @deftypefnx {Function File} {@var{output} =} evalfis (@var{user_input}, @var{fis}, @var{num_points}) ## @deftypefnx {Function File} {[@var{output}, @var{rule_input}, @var{rule_output}, @var{fuzzy_output}] =} evalfis (@var{user_input}, @var{fis}) ## @deftypefnx {Function File} {[@var{output}, @var{rule_input}, @var{rule_output}, @var{fuzzy_output}] =} evalfis (@var{user_input}, @var{fis}, @var{num_points}) ## ## Return the crisp output(s) of an FIS for each row in a matrix of crisp input ## values. ## Also, for the last row of @var{user_input}, return the intermediate results: ## ## @table @var ## @item rule_input ## a matrix of the degree to which ## each FIS rule matches each FIS input variable ## @item rule_output ## a matrix of the fuzzy output for each (rule, FIS output) pair ## @item fuzzy_output ## a matrix of the aggregated output for each FIS output variable ## @end table ## ## The optional argument @var{num_points} specifies the number of points over ## which to evaluate the fuzzy values. The default value of @var{num_points} is ## 101. ## ## @noindent ## Argument @var{user_input}: ## ## @var{user_input} is a matrix of crisp input values. Each row ## represents one set of crisp FIS input values. For an FIS that has N inputs, ## an input matrix of z sets of input values will have the form: ## ## @example ## @group ## [input_11 input_12 ... input_1N] <-- 1st row is 1st set of inputs ## [input_21 input_22 ... input_2N] <-- 2nd row is 2nd set of inputs ## [ ... ] ... ## [input_z1 input_z2 ... input_zN] <-- zth row is zth set of inputs ## @end group ## @end example ## ## @noindent ## Return value @var{output}: ## ## @var{output} is a matrix of crisp output values. Each row represents ## the set of crisp FIS output values for the corresponding row of ## @var{user_input}. For an FIS that has M outputs, an @var{output} matrix ## corresponding to the preceding input matrix will have the form: ## ## @example ## @group ## [output_11 output_12 ... output_1M] <-- 1st row is 1st set of outputs ## [output_21 output_22 ... output_2M] <-- 2nd row is 2nd set of outputs ## [ ... ] ... ## [output_z1 output_z2 ... output_zM] <-- zth row is zth set of outputs ## @end group ## @end example ## ## @noindent ## The intermediate result @var{rule_input}: ## ## The matching degree for each (rule, input value) pair is specified by the ## @var{rule_input} matrix. For an FIS that has Q rules and N input variables, ## the matrix will have the form: ## @example ## @group ## in_1 in_2 ... in_N ## rule_1 [mu_11 mu_12 ... mu_1N] ## rule_2 [mu_21 mu_22 ... mu_2N] ## [ ... ] ## rule_Q [mu_Q1 mu_Q2 ... mu_QN] ## @end group ## @end example ## ## @noindent ## Evaluation of hedges and "not": ## ## Each element of each FIS rule antecedent and consequent indicates the ## corresponding membership function, hedge, and whether or not "not" should ## be applied to the result. The index of the membership function to be used is ## given by the positive whole number portion of the antecedent/consequent ## vector entry, the hedge is given by the fractional portion (if any), and ## "not" is indicated by a minus sign. A "0" as the integer portion in any ## position in the rule indicates that the corresponding FIS input or output ## variable is omitted from the rule. ## ## For custom hedges and the four built-in hedges "somewhat," "very," ## "extremely," and "very very," the membership function value (without the ## hedge or "not") is raised to the power corresponding to the hedge. All ## hedges are rounded to 2 digits. ## ## For example, if "mu(x)" denotes the matching degree of the input to the ## corresponding membership function without a hedge or "not," then the final ## matching degree recorded in @var{rule_input} will be computed by applying ## the hedge and "not" in two steps. First, the hedge is applied: ## ## @example ## @group ## (fraction == .05) <=> somewhat x <=> mu(x)^0.5 <=> sqrt(mu(x)) ## (fraction == .20) <=> very x <=> mu(x)^2 <=> sqr(mu(x)) ## (fraction == .30) <=> extremely x <=> mu(x)^3 <=> cube(mu(x)) ## (fraction == .40) <=> very very x <=> mu(x)^4 ## (fraction == .dd) <=> x <=> mu(x)^(dd/10) ## @end group ## @end example ## ## After applying the appropriate hedge, "not" is calculated by: ## @example ## minus sign present <=> not x <=> 1 - mu(x) ## minus sign and hedge present <=> not x <=> 1 - mu(x)^(dd/10) ## @end example ## ## Hedges and "not" in the consequent are handled similarly. ## ## @noindent ## The intermediate result @var{rule_output}: ## ## For either a Mamdani-type FIS (that is, an FIS that does not have constant or ## linear output membership functions) or a Sugeno-type FIS (that is, an FIS ## that has only constant and linear output membership functions), ## @var{rule_output} specifies the fuzzy output for each (rule, FIS output) pair. ## The format of rule_output depends on the FIS type. ## ## For a Mamdani-type FIS, @var{rule_output} is a @var{num_points} x (Q * M) ## matrix, where Q is the number of rules and M is the number of FIS output ## variables. Each column of this matrix gives the y-values of the fuzzy ## output for a single (rule, FIS output) pair. ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## For a Sugeno-type FIS, @var{rule_output} is a 2 x (Q * M) matrix. ## Each column of this matrix gives the (location, height) pair of the ## singleton output for a single (rule, FIS output) pair. ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## location [ ] ## height [ ] ## @end group ## @end example ## ## @noindent ## The intermediate result @var{fuzzy_output}: ## ## The format of @var{fuzzy_output} depends on the FIS type ('mamdani' or ## 'sugeno'). ## ## For either a Mamdani-type FIS or a Sugeno-type FIS, @var{fuzzy_output} ## specifies the aggregated fuzzy output for each FIS output. ## ## For a Mamdani-type FIS, the aggregated @var{fuzzy_output} is a ## @var{num_points} x M matrix. Each column of this matrix gives the y-values ## of the fuzzy output for a single FIS output, aggregated over all rules. ## ## @example ## @group ## out_1 out_2 ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## For a Sugeno-type FIS, the aggregated output for each FIS output is a 2 x L ## matrix, where L is the number of distinct singleton locations in the ## @var{rule_output} for that FIS output: ## ## @example ## @group ## singleton_1 singleton_2 ... singleton_L ## location [ ] ## height [ ] ## @end group ## @end example ## ## Then @var{fuzzy_output} is a vector of M structures, each of which has an index and ## one of these matrices. ## ## @noindent ## Examples: ## ## Seven examples of using evalfis are shown in: ## @itemize @bullet ## @item ## cubic_approx_demo.m ## @item ## heart_disease_demo_1.m ## @item ## heart_disease_demo_2.m ## @item ## investment_portfolio_demo.m ## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m ## @item ## sugeno_tip_demo.m ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalfis.m ## Last-Modified: 20 Aug 2012 function [output, rule_input, rule_output, fuzzy_output] = ... evalfis (user_input, fis, num_points = 101) ## If evalfis was called with an incorrect number of arguments, or ## the arguments do not have the correct type, print an error message ## and halt. if ((nargin != 2) && (nargin != 3)) puts ("Type 'help evalfis' for more information.\n"); error ("evalfis requires 2 or 3 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help evalfis' for more information.\n"); error ("evalfis's second argument must be an FIS structure\n"); elseif (!is_input_matrix (user_input, fis)) puts ("Type 'help evalfis' for more information.\n"); error ("evalfis's 1st argument must be a matrix of input values\n"); elseif (!is_pos_int (num_points)) puts ("Type 'help evalfis' for more information.\n"); error ("evalfis's third argument must be a positive integer\n"); endif ## Call a private function to compute the output. ## (The private function is also called by gensurf.) [output, rule_input, rule_output, fuzzy_output] = ... evalfis_private (user_input, fis, num_points); endfunction fuzzy-logic-toolkit/inst/mamdani_tip_calculator.fis0000664000175000017500000000355612354647032022157 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: mamdani_tip_calculator.fis ## Last-Modified: 28 Aug 2012 [System] Name='Mamdani-Tip-Calculator' Type='mamdani' Version=2.0 NumInputs=2 NumOutputs=2 NumRules=4 AndMethod='min' OrMethod='max' ImpMethod='min' AggMethod='max' DefuzzMethod='centroid' [Input1] Name='Food-Quality' Range=[1 10] NumMFs=2 MF1='Bad':'trapmf',[0 1 3 7] MF2='Good':'trapmf',[3 7 10 11] [Input2] Name='Service' Range=[1 10] NumMFs=2 MF1='Bad':'trapmf',[0 1 3 7] MF2='Good':'trapmf',[3 7 10 11] [Output1] Name='Tip' Range=[0 30] NumMFs=3 MF1='About-Ten-Percent':'gaussmf',[2 10] MF2='About-Fifteen-Percent':'gaussmf',[2 15] MF3='About-Twenty-Percent':'gaussmf',[2 20] [Output2] Name='Check-Plus-Tip' Range=[1 1.3] NumMFs=3 MF1='Plus-About-Ten-Percent':'gaussmf',[0.02 1.10] MF2='Plus-About-Fifteen-Percent':'gaussmf',[0.02 1.15] MF3='Plus-About-Twenty-Percent':'gaussmf',[0.02 1.20] [Rules] 1 1, 1 1 (1) : 1 1 2, 2 2 (1) : 1 2 1, 2 2 (1) : 1 2 2, 3 3 (1) : 1 fuzzy-logic-toolkit/inst/showfis.m0000664000175000017500000002164712354647032016622 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {} showfis (@var{fis}) ## ## Print all of the property (field) values of the FIS structure and its ## substructures. ## ## @seealso{getfis, showrule} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: showfis.m ## Last-Modified: 20 Aug 2012 function showfis (fis) ## If getfis was called with an incorrect number of arguments, ## or the argument does not have the correct type, print an error ## message and halt. if (nargin != 1) puts ("Type 'help showfis' for more information.\n"); error ("showfis requires 1 argument\n"); elseif (!is_fis (fis)) puts ("Type 'help showfis' for more information.\n"); error ("showfis's argument must be an FIS structure\n"); endif ## Print properties of the FIS structure. ## Determine: ## the number of input variables ## number of output variables ## number of rules ## input membership function names ## input membership function types ## input membership functions parameters ## number of input membership functions ## output membership function names ## output membership function types ## output membership function parameters ## number of output membership functions num_inputs = columns(fis.input); num_outputs = columns(fis.output); num_rules = columns(fis.rule); k = 1; in_mf_labels = {}; in_mf_types = {}; in_mf_params{k} = []; for i = 1 : num_inputs for j = 1 : columns (fis.input(i).mf) in_mf_labels{k} = fis.input(i).mf(j).name; in_mf_types{k} = fis.input(i).mf(j).type; in_mf_params{k++} = fis.input(i).mf(j).params; endfor endfor num_input_mf = k - 1; k = 1; out_mf_labels = {}; out_mf_types = {}; out_mf_params{k} = []; for i = 1 : num_outputs for j = 1 : columns (fis.output(i).mf) out_mf_labels{k} = fis.output(i).mf(j).name; out_mf_types{k} = fis.output(i).mf(j).type; out_mf_params{k++} = fis.output(i).mf(j).params; endfor endfor num_output_mf = k - 1; ## Print the name, type, and number of inputs/outputs. line = 1; printf ("%d. Name %s\n", line++, fis.name); printf ("%d. Type %s\n", line++, fis.type); printf ("%d. Inputs/Outputs [%d %d]\n", line++, num_inputs, ... num_outputs); ## Print the number of input membership functions. printf ("%d. NumInputMFs ", line++); if (num_inputs == 0) printf ("0\n"); elseif (num_inputs == 1) printf ("%d\n", columns(fis.input(1).mf)); else printf("["); for i = 1 : num_inputs-1 printf ("%d ", columns(fis.input(i).mf)); endfor printf ("%d]\n", columns(fis.input(num_inputs).mf)); endif ## Print the number of output membership functions. printf ("%d. NumOutputMFs ", line++); if (num_outputs == 0) printf("0\n"); elseif (num_outputs == 1) printf ("%d\n", columns(fis.output(1).mf)); else printf ("["); for i = 1 : num_outputs - 1 printf ("%d ", columns (fis.output(i).mf)); endfor printf ("%d]\n", columns (fis.output(num_outputs).mf)); endif ## Print the number of rules, 'And' method, 'Or' method, 'Implication' ## method, 'Aggregation' method, and 'Defuzzification' method. printf ("%d. NumRules %d\n", line++, num_rules); printf ("%d. AndMethod %s\n", line++, fis.andMethod); printf ("%d. OrMethod %s\n", line++, fis.orMethod); printf ("%d. ImpMethod %s\n", line++, fis.impMethod); printf ("%d. AggMethod %s\n", line++, fis.aggMethod); printf ("%d. DefuzzMethod %s\n", line++, fis.defuzzMethod); ## Print the input variable names (labels). printf ("%d. InLabels ", line++); if (num_inputs == 0) printf ("\n"); else printf ("%s\n", fis.input(1).name); for i = 2 : num_inputs printf ("%d. %s\n", line++, fis.input(i).name); endfor endif ## Print the output variable names (labels). printf ("%d. OutLabels ", line++); if (num_outputs == 0) printf ("\n"); else printf ("%s\n", fis.output(1).name); for i = 2 : num_outputs printf ("%d. %s\n", line++, fis.output(i).name); endfor endif ## Print the ranges of the input variables. printf ("%d. InRange ", line++); if (num_inputs == 0) printf ("\n"); else printf ("%s\n", mat2str(fis.input(1).range)); for i = 2 : num_inputs printf ("%d. ", line++); printf ("%s\n", mat2str(fis.input(i).range)); endfor endif ## Print the ranges of the output variables. printf ("%d. OutRange ", line++); if (num_outputs == 0) printf ("\n"); else printf ("%s\n", mat2str(fis.output(1).range)); for i = 2 : num_outputs printf ("%d. ", line++); printf ("%s\n", mat2str (fis.output(i).range)); endfor endif ## Print the input variables' membership function labels. printf ("%d. InMFLabels ", line++); if (num_input_mf == 0) printf ("\n"); else printf ("%s\n", in_mf_labels{1}); for i = 2 : num_input_mf printf ("%d. %s\n", line++, in_mf_labels{i}); endfor endif ## Print the output variables' membership function labels. printf ("%d. OutMFLabels ", line++); if (num_output_mf == 0) printf ("\n"); else printf ("%s\n", out_mf_labels{1}); for i = 2 : num_output_mf printf ("%d. %s\n", line++, out_mf_labels{i}); endfor endif ## Print the input variables' membership function types. printf ("%d. InMFTypes ", line++); if (num_input_mf == 0) printf ("\n"); else printf ("%s\n", in_mf_types{1}); for i = 2 : num_input_mf printf ("%d. %s\n", line++, in_mf_types{i}); endfor endif ## Print the output variables' membership function types. printf ("%d. OutMFTypes ", line++); if (num_output_mf == 0) printf ("\n"); else printf ("%s\n", out_mf_types{1}); for i = 2 : num_output_mf printf ("%d. %s\n", line++, out_mf_types{i}); endfor endif ## Print the input variables' membership function parameters. printf ("%d. InMFParams ", line++); if (num_input_mf == 0) printf ("\n"); else printf ("%s\n", mat2str(in_mf_params{1})); for i = 2 : num_input_mf printf ("%d. ", line++); printf ("%s\n", mat2str (in_mf_params{i})); endfor endif ## Print the output variables' membership function parameters. printf ("%d. OutMFParams ", line++); if (num_output_mf == 0) printf ("\n"); else printf ("%s\n", mat2str (out_mf_params{1})); for i = 2 : num_output_mf printf ("%d. ", line++); printf ("%s\n", mat2str (out_mf_params{i})); endfor endif ## Print the rule antecedents. printf("%d. Rule Antecedent ", line++); if (num_rules == 0) printf ("\n"); else printf ("%s\n", mat2str (fis.rule(1).antecedent)); for i = 2 : num_rules printf ("%d. ", line++); printf ("%s\n", mat2str (fis.rule(i).antecedent)); endfor endif ## Print the rule consequents. printf ("%d. Rule Consequent ", line++); if (num_rules == 0) printf ("\n"); else printf ("%s\n", mat2str (fis.rule(1).consequent)); for i = 2 : num_rules printf ("%d. ", line++); printf ("%s\n", mat2str (fis.rule(i).consequent)); endfor endif ## Print the rule weights. printf("%d. Rule Weight ", line++); if (num_rules == 0) printf ("\n"); else printf ("%d\n", fis.rule(1).weight); for i = 2 : num_rules printf ("%d. %d\n", line++, fis.rule(i).weight); endfor endif ## Print the rule connections. printf ("%d. Rule Connection ", line++); if (num_rules == 0) printf ("\n"); else printf ("%d\n", fis.rule(1).connection); for i = 2 : num_rules printf ("%d. %d\n", line++, ... fis.rule(i).connection); endfor endif endfunction fuzzy-logic-toolkit/inst/gensurf.m0000664000175000017500000002001612354647032016576 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {} gensurf (@var{fis}) ## @deftypefnx {Function File} {} gensurf (@var{fis}, @var{input_axes}) ## @deftypefnx {Function File} {} gensurf (@var{fis}, @var{input_axes}, @var{output_axes}) ## @deftypefnx {Function File} {} gensurf (@var{fis}, @var{input_axes}, @var{output_axes}, @var{grids}) ## @deftypefnx {Function File} {} gensurf (@var{fis}, @var{input_axes}, @var{output_axes}, @var{grids}, @var{ref_input}) ## @deftypefnx {Function File} {} gensurf (@var{fis}, @var{input_axes}, @var{output_axes}, @var{grids}, @var{ref_input}, @var{num_points}) ## @deftypefnx {Function File} {@var{[x, y, z]} =} gensurf (...) ## ## Generate and plot a surface (or 2-dimensional curve) showing one FIS output ## as a function of two (or one) of the FIS inputs. The reference input is used ## for all FIS inputs that are not in the input_axes vector. ## ## Grids, which specifies the number of grids to show on the input axes, may be ## a scalar or a vector of length 2. If a scalar, then both axes will use the ## same number of grids. If a vector of length 2, then the grids on the two axes ## are controlled separately. ## ## Num_points specifies the number of points to use when evaluating the FIS. ## ## The final form "[x, y, z] = gensurf(...)" suppresses plotting. ## ## Default values for arguments not supplied are: ## @itemize @bullet ## @item ## input_axes == [1 2] ## @item ## output_axis == 1 ## @item ## grids == [15 15] ## @item ## ref_input == [] ## @item ## num_points == 101 ## @end itemize ## ## Six demo scripts that use gensurf are: ## @itemize @bullet ## @item ## cubic_approx_demo.m ## @item ## heart_disease_demo_1.m ## @item ## heart_disease_demo_2.m ## @item ## investment_portfolio_demo.m ## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m ## @item ## sugeno_tip_demo.m ## @end itemize ## ## Current limitation: ## The form of gensurf that suppresses plotting (the final form above) is not yet ## implemented. ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo, plotmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis plot ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gensurf.m ## Last-Modified: 19 Aug 2012 function [x, y, z] = gensurf (fis, input_axes = [1 2], ... output_axis = 1, grids = [15 15], ... ref_input = [], num_points = 101) ## If gensurf was called with an incorrect number of arguments, ## or the arguments do not have the correct type, print an error ## message and halt. if ((nargin < 1) || (nargin > 6)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf requires between 1 and 6 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's first argument must be an FIS structure\n"); elseif ((nargin >= 2) && !are_input_indices (input_axes, fis)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's second argument must be valid input indices\n"); elseif ((nargin >= 3) && !is_output_index (output_axis, fis)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's third argument must be a valid output index\n"); elseif ((nargin >= 4) && !is_grid_spec (grids)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's 4th argument must be a grid specification\n"); elseif ((nargin >= 5) && !is_ref_input (ref_input, fis, input_axes)) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's 5th argument must be reference input values\n"); elseif ((nargin == 6) && ... !(is_pos_int (num_points) && (num_points >= 2))) puts ("Type 'help gensurf' for more information.\n"); error ("gensurf's sixth argument must be an integer >= 2\n"); endif if (length (input_axes) == 1 || columns (fis.input) == 1) generate_plot (fis, input_axes, output_axis, grids, ... ref_input, num_points); else generate_surface (fis, input_axes, output_axis, grids, ... ref_input, num_points); endif endfunction ##---------------------------------------------------------------------- ## Function: generate_plot ## Purpose: Generate a plot representing one of the FIS outputs as a ## function of one of the FIS inputs. ##---------------------------------------------------------------------- function [x, y, z] = generate_plot (fis, input_axis, output_axis, ... grids, ref_input, num_points) ## Create input to FIS using grid points and reference values. num_inputs = columns (fis.input); num_grid_pts = grids(1); fis_input = zeros (num_grid_pts, num_inputs); if (num_inputs == 1) input_axis = 1; endif for i = 1 : num_inputs if (i == input_axis) x_axis = (linspace (fis.input(i).range(1), ... fis.input(i).range(2), ... num_grid_pts))'; fis_input(:, i) = x_axis; else fis_input(:, i) = ref_input(i) * ones (num_grid_pts, 1); endif endfor ## Compute and plot the output. output = evalfis_private (fis_input, fis, num_points); figure ('NumberTitle', 'off', 'Name', fis.name); plot (x_axis, output, 'LineWidth', 2); xlabel (fis.input(input_axis).name, 'FontWeight', 'bold'); ylabel (fis.output(output_axis).name, 'FontWeight', 'bold'); grid; hold; endfunction ##---------------------------------------------------------------------- ## Function: generate_surface ## Purpose: Generate a surface representing one of the FIS outputs as ## a function of two of the FIS inputs. ##---------------------------------------------------------------------- function [x, y, z] = generate_surface (fis, input_axes, output_axis, ... grids, ref_input, num_points) ## Create input to FIS using grid points and reference values. num_inputs = columns (fis.input); if (length (grids) == 1) grids = [grids grids]; endif num_grid_pts = prod (grids); fis_input = zeros (num_grid_pts, num_inputs); for i = 1 : num_inputs if (i == input_axes(1)) x_axis = (linspace (fis.input(i).range(1), ... fis.input(i).range(2), ... grids(1)))'; elseif (i == input_axes(2)) y_axis = (linspace (fis.input(i).range(1), ... fis.input(i).range(2), ... grids(2)))'; else fis_input(:, i) = ref_input(i) * ones (num_grid_pts, 1); endif endfor [xx, yy] = meshgrid (x_axis, y_axis); fis_input(:, input_axes(1)) = xx(:); fis_input(:, input_axes(2)) = yy(:); ## Compute the output and reshape it to fit the grid. output = evalfis_private (fis_input, fis, num_points); z_matrix = reshape (output(:, output_axis), length (x_axis), ... length (y_axis)); ## Plot the surface. figure ('NumberTitle', 'off', 'Name', fis.name); surf (x_axis, y_axis, z_matrix); xlabel (fis.input(input_axes(1)).name); ylabel (fis.input(input_axes(2)).name); zlabel (fis.output(output_axis).name); endfunction fuzzy-logic-toolkit/inst/smf.m0000664000175000017500000001124212354647032015713 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} smf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} smf (@var{[x1 x2 ... xn]}, @var{[a b]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b]}), ## return the corresponding @var{y} values for the S-shaped membership function. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{a} and @var{b} must be real numbers, with ## @var{a} < @var{b}. This membership function satisfies: ## @example ## @group ## 0 if x <= a ## f(x) = 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 1 - 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## 1 if x >= b ## @end group ## @end example ## ## @noindent ## which always returns values in the range [0, 1]. ## ## @noindent ## To run the demonstration code, type @t{demo('smf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, sigmf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership s-shaped ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: smf.m ## Last-Modified: 19 Aug 2012 function y = smf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help smf' for more information.\n"); error ("smf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help smf' for more information.\n"); error ("smf's first argument must be a valid domain\n"); elseif (!are_mf_params ('smf', params)) puts ("Type 'help smf' for more information.\n"); error ("smf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a = params(1); b = params(2); a_b_ave = (a + b) / 2; b_minus_a = b - a; y_val = @(x_val) smf_val (x_val, a, b, a_b_ave, b_minus_a); y = arrayfun (y_val, x); endfunction ##---------------------------------------------------------------------- ## Usage: y = smf_val (x_val, a, b, a_b_ave, b_minus_a) ## ## smf_val returns one value of the S-shaped membership function, which ## satisfies: ## 0 if x <= a ## f(x) = 2 * ((x - a)/(b - a))^2 if a < x <= (a + b)/2 ## 1 - 2 * ((x - b)/(b - a))^2 if (a + b)/2 < x < b ## 1 if x >= b ## ## smf_val is a private function, called only by smf. Because smf_val ## is not intended for general use -- and because the parameters a and b ## are checked for errors in the function smf (defined above), the ## parameters are not checked for errors again here. ##---------------------------------------------------------------------- function y_val = smf_val (x_val, a, b, a_b_ave, b_minus_a) ## Calculate and return a single y value of the S-shaped membership ## function for the given x value and parameters specified by the ## arguments. if (x_val <= a) y_val = 0; elseif (x_val <= a_b_ave) y_val = 2 * ((x_val - a) / b_minus_a)^2; elseif (x_val < b) y_val = 1 - 2 * ((x_val - b) / b_minus_a)^2; else y_val = 1; endif endfunction %!demo %! x = 0:100; %! params = [40 60]; %! y1 = smf(x, params); %! params = [25 75]; %! y2 = smf(x, params); %! params = [10 90]; %! y3 = smf(x, params); %! figure('NumberTitle', 'off', 'Name', 'smf demo'); %! plot(x, y1, 'r;params = [40 60];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [25 75];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [10 90];', 'LineWidth', 2) %! ylim([-0.1 1.2]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/addmf.m0000664000175000017500000001272112354647032016204 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} addmf (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf_name}, @var{mf_type}, @var{mf_params}) ## ## Add a membership function to an existing FIS ## structure and return the updated FIS. ## ## The types of the arguments are expected to be: ## @itemize @w ## @item @var{fis}: ## an FIS structure ## @item @var{in_or_out}: ## 'input' or 'output' (case-insensitive) ## @item @var{var_index}: ## valid index of an FIS input/output variable ## @item @var{mf_name}: ## a string ## @item @var{mf_type}: ## a string ## @item @var{mf_params}: ## a vector ## @end itemize ## ## If @var{mf_type} is one of the built-in membership functions, then the ## number and values of the parameters must satisfy the membership function ## requirements for the specified @var{mf_type}. ## ## Note that addmf will allow the user to add membership functions or ## membership function names for a given input or output variable that ## duplicate mfs or mf names already entered. ## ## Also, constant and linear membership functions are not restricted to FIS ## structure outputs or to Sugeno-type FIS structures, and the result of using ## them for FIS inputs or Mamdani-type FIS outputs has not yet been tested. ## ## @noindent ## To run the demonstration code, type @t{demo('addmf')} at the Octave prompt. ## This demo creates two FIS input variables and associated membership functions ## and then produces two figures showing the term sets for the two FIS inputs. ## ## @seealso{rmmf, setfis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addmf.m ## Note: The demo code is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Last-Modified: 18 Aug 2012 function fis = addmf (fis, in_or_out, var_index, mf_name, mf_type, ... mf_params) ## If the caller did not supply 6 argument values with the correct ## types, print an error message and halt. if (nargin != 6) puts ("Type 'help addmf' for more information.\n"); error ("addmf requires 6 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help addmf' for more information.\n"); error ("addmf's first argument must be an FIS structure\n"); elseif (!(is_string (in_or_out) && ... ismember (tolower (in_or_out), {'input', 'output'}))) puts ("Type 'help addmf' for more information.\n"); error ("addmf's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, in_or_out, var_index)) puts ("Type 'help addmf' for more information.\n"); error ("addmf's third argument must be a variable index\n"); elseif (!(is_string (mf_name) && is_string (mf_type))) puts ("Type 'help addmf' for more information.\n"); error ("addmf's fourth and fifth arguments must be strings\n"); elseif (!are_mf_params (mf_type, mf_params)) puts ("Type 'help addmf' for more information.\n"); error ("addmf's sixth argument must be a vector of parameters\n"); endif ## Create a new membership function struct and update the ## FIS structure. new_mf = struct ('name', mf_name, 'type', mf_type, 'params', ... mf_params); if (strcmp (tolower (in_or_out), 'input')) if (length (fis.input(var_index).mf) == 0) fis.input(var_index).mf = new_mf; else fis.input(var_index).mf = [fis.input(var_index).mf, new_mf]; endif else if (length (fis.output(var_index).mf) == 0) fis.output(var_index).mf = new_mf; else fis.output(var_index).mf = [fis.output(var_index).mf, new_mf]; endif endif endfunction %!demo %! ## Create new FIS. %! a = newfis ('Heart-Disease-Risk', 'sugeno', ... %! 'min', 'max', 'min', 'max', 'wtaver'); %! %! ## Add two inputs and their membership functions. %! a = addvar (a, 'input', 'LDL-Level', [0 300]); %! a = addmf (a, 'input', 1, 'Low', 'trapmf', [-1 0 90 110]); %! a = addmf (a, 'input', 1, 'Low-Borderline', 'trapmf', ... %! [90 110 120 140]); %! a = addmf (a, 'input', 1, 'Borderline', 'trapmf', ... %! [120 140 150 170]); %! a = addmf (a, 'input', 1, 'High-Borderline', 'trapmf', ... %! [150 170 180 200]); %! a = addmf (a, 'input', 1, 'High', 'trapmf', [180 200 300 301]); %! %! a = addvar (a, 'input', 'HDL-Level', [0 100]); %! a = addmf (a, 'input', 2, 'Low-HDL', 'trapmf', [-1 0 35 45]); %! a = addmf (a, 'input', 2, 'Moderate-HDL', 'trapmf', [35 45 55 65]); %! a = addmf (a, 'input', 2, 'High-HDL', 'trapmf', [55 65 100 101]); %! %! ## Plot the input membership functions. %! plotmf (a, 'input', 1); %! plotmf (a, 'input', 2); fuzzy-logic-toolkit/inst/heart_disease_demo_1.m0000664000175000017500000000677212354647032021166 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} heart_disease_demo_1 ## ## Demonstrate the use of newfis, addvar, addmf, addrule, and evalfis ## to build and evaluate an FIS. Also demonstrate the use of the algebraic ## product and sum as the T-norm/S-norm pair, and demonstrate the use of ## hedges in the FIS rules. ## ## The demo: ## @itemize @minus ## @item ## builds an FIS ## @item ## plots the input membership functions ## @item ## plots the constant output functions ## @item ## displays the FIS rules in verbose format in the Octave window ## @item ## plots the FIS output as a function of the inputs ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Note: This example is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Directory: fuzzy-logic-toolkit/inst ## Filename: heart_disease_demo_1.m ## Last-Modified: 20 Aug 2012 ## Create new FIS. a = newfis ('Heart-Disease-Risk', 'sugeno', ... 'algebraic_product', 'algebraic_sum', ... 'min', 'max', 'wtaver'); ## Add two inputs and their membership functions. a = addvar (a, 'input', 'LDL-Level', [0 300]); a = addmf (a, 'input', 1, 'Low', 'trapmf', [-1 0 90 130]); a = addmf (a, 'input', 1, 'Moderate', 'trapmf', [90 130 160 200]); a = addmf (a, 'input', 1, 'High', 'trapmf', [160 200 300 301]); a = addvar (a, 'input', 'HDL-Level', [0 100]); a = addmf (a, 'input', 2, 'Low', 'trapmf', [-1 0 35 45]); a = addmf (a, 'input', 2, 'Moderate', 'trapmf', [35 45 55 65]); a = addmf (a, 'input', 2, 'High', 'trapmf', [55 65 100 101]); ## Add one output and its membership functions. a = addvar (a, 'output', 'Heart-Disease-Risk', [-2 12]); a = addmf (a, 'output', 1, 'Negligible', 'constant', 0); a = addmf (a, 'output', 1, 'Low', 'constant', 2.5); a = addmf (a, 'output', 1, 'Medium', 'constant', 5); a = addmf (a, 'output', 1, 'High', 'constant', 7.5); a = addmf (a, 'output', 1, 'Extreme', 'constant', 10); ## Plot the input and output membership functions. plotmf (a, 'input', 1); plotmf (a, 'input', 2); plotmf (a, 'output', 1); ## Add 15 rules and display them in verbose format. a = addrule (a, [1 1 3 1 1; 1 2 2 1 1; 1 3 1 1 1; ... 2 1 4 1 1; 2 2 3 1 1; 2 3 2 1 1; ... 3 1 5 1 1; 3 2 4 1 1; 3 3 3 1 1; ... 1.3 3.3 2 1 2; ... 3.05 1.05 4 1 2; ... -3.2 -1.2 3 1 1]); puts ("\nOutput of showrule(a):\n\n"); showrule (a); ## Plot the output as a function of the two inputs. gensurf (a); fuzzy-logic-toolkit/inst/linear_tip_demo.m0000664000175000017500000000432012354647032020257 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} linear_tip_demo ## ## Demonstrate the use of linear output membership functions to simulate ## constant membership functions. ## ## The demo: ## @itemize @minus ## @item ## reads the FIS structure from a file ## @item ## plots the input membership functions ## @item ## plots the FIS output as a function of the inputs ## @item ## evaluates the Sugeno-type FIS for six inputs ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, mamdani_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Note: This example is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: linear_tip_demo.m ## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('linear_tip_calculator.fis'); ## Plot the input membership functions. plotmf (fis, 'input', 1); plotmf (fis, 'input', 2); ## Plot the Tip as a function of Food-Quality and Service. gensurf (fis); ## Calculate the Tip for 6 sets of input values: puts ("\nFor the following values of (Food Quality, Service):\n\n"); food_service = [1 1; 5 5; 10 10; 4 6; 6 4; 7 4] puts ("\nThe Tip is:\n\n"); tip = evalfis (food_service, fis, 1001) fuzzy-logic-toolkit/inst/addvar.m0000664000175000017500000000670612354647032016400 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} addvar (@var{fis}, @var{in_or_out}, @var{var_name}, @var{var_range}) ## ## Add an input or output variable to an existing FIS ## structure and return the updated FIS. ## ## The types of the arguments are expected to be: ## @itemize @w ## @item ## @var{fis} - an FIS structure ## @item ## @var{in_or_out} - either 'input' or 'output' (case-insensitive) ## @item ## @var{var_name} - a string ## @item ## @var{var_range} - a vector [x1 x2] of two real numbers ## @end itemize ## ## The vector components x1 and x2, which must also satisfy x1 <= x2, ## specify the lower and upper bounds of the variable's domain. ## ## @noindent ## To run the demonstration code, type @t{demo('addvar')} at the Octave prompt. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy variable ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addvar.m ## Last-Modified: 18 Aug 2012 function fis = addvar (fis, in_or_out, var_name, var_range) ## If the caller did not supply 4 argument values with the correct ## types, print an error message and halt. if (nargin != 4) puts ("Type 'help addvar' for more information.\n"); error ("addvar requires 4 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help addvar' for more information.\n"); error ("addvar's first argument must be an FIS structure\n"); elseif (!(is_string (in_or_out) && ... ismember (tolower (in_or_out), {'input', 'output'}))) puts ("Type 'help addvar' for more information.\n"); error ("addvar's second argument must be 'input' or 'output'\n"); elseif (!is_string (var_name)) puts ("Type 'help addvar' for more information.\n"); error ("addvar's third argument must be a string\n\n"); elseif (!are_bounds (var_range)) puts ("Type 'help addvar' for more information.\n"); error ("addvar's fourth argument must specify variable bounds\n"); endif ## Create a new variable struct and update the FIS input or output ## variable list. new_variable = struct ('name', var_name, 'range', var_range, ... 'mf', []); if (strcmp (tolower (in_or_out), 'input')) if (length (fis.input) == 0) fis.input = new_variable; else fis.input = [fis.input, new_variable]; endif else if (length (fis.output) == 0) fis.output = new_variable; else fis.output = [fis.output, new_variable]; endif endif endfunction %!demo %! a = newfis ('Heart-Disease-Risk', 'sugeno', ... %! 'min', 'max', 'min', 'max', 'wtaver'); %! a = addvar (a, 'input', 'LDL-Level', [0 300]); %! getfis (a, 'input', 1); fuzzy-logic-toolkit/inst/drastic_sum.m0000664000175000017500000000635212354647032017451 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} drastic_sum (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} drastic_sum (@var{x}, @var{y}) ## ## Return the drastic sum of the input. ## The drastic sum of two real scalars x and y is: ## @example ## @group ## max (x, y) if min (x, y) == 0 ## 1 otherwise ## @end group ## @end example ## ## For one vector argument, apply the drastic sum to all of the elements ## of the vector. (The drastic sum is associative.) For one ## two-dimensional matrix argument, return a vector of the drastic sum ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise drastic sum. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_product, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy drastic_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: drastic_sum.m ## Last-Modified: 20 Aug 2012 function retval = drastic_sum (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) if (min (x, y) == 0) retval = max (x, y); else retval = 1; endif endfunction function retval = vector_arg (x) if (isempty (x)) retval = 0; elseif (min (x) == 0) retval = max (x); else retval = 1; endif endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help drastic_sum' for more information.\n"); error ("invalid arguments to function drastic_sum\n"); endfunction fuzzy-logic-toolkit/inst/cubic_approximator.fis0000664000175000017500000000450612354647032021352 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: cubic_approximator.fis ## Last-Modified: 28 Aug 2012 [System] Name='Cubic-Approximator' Type='sugeno' Version=2.0 NumInputs=1 NumOutputs=1 NumRules=11 AndMethod='min' OrMethod='max' ImpMethod='min' AggMethod='max' DefuzzMethod='wtaver' [Input1] Name='X' Range=[-5 5] NumMFs=11 MF1 = 'About-Neg-Five':'trimf', [-6 -5 -4] MF2 = 'About-Neg-Four':'trimf', [-5 -4 -3] MF3 = 'About-Neg-Three':'trimf', [-4 -3 -2] MF4 = 'About-Neg-Two':'trimf', [-3 -2 -1] MF5 = 'About-Neg-One':'trimf', [-2 -1 0] MF6 = 'About-Zero':'trimf', [-1 0 1] MF7 = 'About-One':'trimf', [0 1 2] MF8 = 'About-Two':'trimf', [1 2 3] MF9 = 'About-Three':'trimf', [2 3 4] MF10 = 'About-Four':'trimf', [3 4 5] MF11 = 'About-Five':'trimf', [4 5 6] [Output1] Name='Approx-X-Cubed' Range=[-5 5] NumMFs=11 MF1 = 'Tangent-at-Neg-Five':'linear', [75 250] MF2 = 'Tangent-at-Neg-Four':'linear', [48 128] MF3 = 'Tangent-at-Neg-Three':'linear', [27 54] MF4 = 'Tangent-at-Neg-Two':'linear', [12 16] MF5 = 'Tangent-at-Neg-One':'linear', [3 2] MF6 = 'Tangent-at-Zero':'linear', [0 0] MF7 = 'Tangent-at-One':'linear', [3 -2] MF8 = 'Tangent-at-Two':'linear', [12 -16] MF9 = 'Tangent-at-Three':'linear', [27 -54] MF10 = 'Tangent-at-Four':'linear', [48 -128] MF11 = 'Tangent-at-Five':'linear', [75 -250] [Rules] 1, 1 (1) : 1 2, 2 (1) : 1 3, 3 (1) : 1 4, 4 (1) : 1 5, 5 (1) : 1 6, 6 (1) : 1 7, 7 (1) : 1 8, 8 (1) : 1 9, 9 (1) : 1 10, 10 (1) : 1 11, 11 (1) : 1 fuzzy-logic-toolkit/inst/trimf.m0000664000175000017500000000726712354647032016263 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} trimf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} trimf (@var{[x1 x2 ... xn]}, @var{[a b c]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[a b c]}), ## return the corresponding @var{y} values for the triangular membership ## function. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and parameters @var{a}, @var{b}, and @var{c} must be ## real numbers that satisfy @var{a} < @var{b} < @var{c}. None of the parameters ## @var{a}, @var{b}, and @var{c} are required to be in the domain @var{x}. The ## minimum and maximum values of the triangle are assumed to be 0 and 1. ## ## The parameters [@var{a} @var{b} @var{c}] correspond to the x values of the ## vertices of the triangle: ## ## @example ## @group ## 1-| /\ ## | / \ ## | / \ ## | / \ ## 0----------------------- ## a b c ## @end group ## @end example ## ## @noindent ## To run the demonstration code, type @t{demo('trimf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, sigmf, smf, trapmf, trimf_demo, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership triangular ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: trimf.m ## Last-Modified: 20 Aug 2012 function y = trimf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help trimf' for more information.\n"); error ("trimf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help trimf' for more information.\n"); error ("trimf's first argument must be a valid domain\n"); elseif (!are_mf_params ('trimf', params)) puts ("Type 'help trimf' for more information.\n"); error ("trimf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the triangle on the domain x. a = params(1); b = params(2); c = params(3); b_minus_a = b - a; c_minus_b = c - b; y_val = @(x_val) max (0, min (min (1, (x_val - a) / b_minus_a), ... (c - x_val)/c_minus_b)); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:100; %! params = [-1 0 50]; %! y1 = trimf(x, params); %! params = [0 50 100]; %! y2 = trimf(x, params); %! params = [50 100 101]; %! y3 = trimf(x, params); %! figure('NumberTitle', 'off', 'Name', 'trimf demo'); %! plot(x, y1, 'r;params = [-1 0 50];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [0 50 100];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [50 100 101];', 'LineWidth', 2) %! ylim([-0.1 1.2]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/mamdani_tip_demo.m0000664000175000017500000000724312354647032020422 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Script File} {} mamdani_tip_demo ## Demonstrate the use of the Octave Fuzzy Logic Toolkit to read and evaluate a ## Mamdani-type FIS stored in a file. ## ## The demo: ## @itemize @minus ## @item ## reads the FIS structure from a file ## @item ## plots the input and output membership functions ## @item ## plots each of the two FIS outputs as a function of the inputs ## @item ## plots the output of the 4 individual rules for (Food-Quality, Service) = (4, 6) ## @item ## plots the aggregated fuzzy output and the crisp output for ## (Food-Quality, Service) = (4, 6) ## @item ## displays the FIS rules in symbolic format in the Octave window ## @end itemize ## ## @seealso{cubic_approx_demo, heart_disease_demo_1, heart_disease_demo_2, investment_portfolio_demo, linear_tip_demo, sugeno_tip_demo} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Note: This example is based on an assignment written by ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: mamdani_tip_demo.m ## Last-Modified: 19 Aug 2012 ## Read the FIS structure from a file. fis=readfis ('mamdani_tip_calculator'); ## Plot the input and output membership functions. plotmf (fis, 'input', 1); plotmf (fis, 'input', 2); plotmf (fis, 'output', 1); plotmf (fis, 'output', 2); ## Plot the Tip and Check + Tip as functions of Food-Quality ## and Service. gensurf (fis, [1 2], 1); gensurf (fis, [1 2], 2); ## Calculate the Tip and Check + Tip using ## (Food-Quality, Service) = (4, 6). [output, rule_input, rule_output, fuzzy_output] = ... evalfis ([4 6], fis, 1001); ## Plot the first output (Tip) of the individual fuzzy rules ## on one set of axes. x_axis = linspace (fis.output(1).range(1), ... fis.output(1).range(2), 1001); colors = ['r' 'b' 'm' 'g']; figure ('NumberTitle', 'off', 'Name', ... 'Output of Fuzzy Rules 1-4 for Input = (4, 6)'); for i = 1 : 4 y_label = [colors(i) ";Rule " num2str(i) ";"]; plot (x_axis, rule_output(:,i), y_label, 'LineWidth', 2); hold on; endfor ylim ([-0.1, 1.1]); xlabel ('Tip', 'FontWeight', 'bold'); grid; hold; ## Plot the first aggregated fuzzy output and the first crisp output ## (Tip) on one set of axes. figure('NumberTitle', 'off', 'Name', ... 'Aggregation and Defuzzification for Input = (4, 6)'); plot (x_axis, fuzzy_output(:, 1), "b;Aggregated Fuzzy Output;", ... 'LineWidth', 2); hold on; crisp_output = evalmf(x_axis, output(1), 'constant'); y_label = ["r;Crisp Output = " num2str(output(1)) "%;"]; plot (x_axis, crisp_output, y_label, 'LineWidth', 2); ylim ([-0.1, 1.1]); xlabel ('Tip', 'FontWeight', 'bold'); grid; hold; ## Show the rules in symbolic format. puts ("\nMamdani Tip Calculator Rules:\n\n"); showrule (fis, 1:columns(fis.rule), 'symbolic'); fuzzy-logic-toolkit/inst/gauss2mf.m0000664000175000017500000001105012354647032016652 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} gauss2mf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} gauss2mf (@var{[x1 x2 ... xn]}, @var{[sig1 c1 sig2 c2]}) ## ## For a given domain @var{x} and parameters @var{params} (or ## @var{[sig1 c1 sig2 c2]}), return the corresponding @var{y} values for the ## two-sided Gaussian composite membership function. This membership function is ## a smooth curve calculated from two Gaussian membership functions as follows: ## ## Given parameters @var{sig1}, @var{c1}, @var{sig2}, and @var{c2}, that define ## two Gaussian membership functions, let: ## ## @example ## @group ## f1(x) = exp((-(x - c1)^2)/(2 * sig1^2)) if x <= c1 ## 1 otherwise ## ## f2(x) = 1 if x <= c2 ## exp((-(x - c2)^2)/(2 * sig2^2)) otherwise ## @end group ## @end example ## ## @noindent ## Then gauss2mf is given by: ## ## @example ## f(x) = f1(x) * f2(x) ## @end example ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{sig1}, @var{c1}, @var{sig2}, and @var{c2} ## must be real numbers. ## Gauss2mf always returns a continuously differentiable curve with values in ## the range [0, 1]. ## ## If @var{c1} < @var{c2}, gauss2mf is a normal membership function (has a ## maximum value of 1), with the rising curve identical to that of f1(x) and a ## falling curve identical to that of f2(x), above. If @var{c1} >= @var{c2}, ## gauss2mf returns a subnormal membership function (has a maximum value less ## than 1). ## ## @noindent ## To run the demonstration code, type @t{demo('gauss2mf')} at the Octave prompt. ## ## @seealso{dsigmf, gaussmf, gbellmf, pimf, psigmf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gauss2mf.m ## Last-Modified: 19 Aug 2012 function y = gauss2mf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help gauss2mf' for more information.\n"); error ("gauss2mf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help gauss2mf' for more information.\n"); error ("gauss2mf's first argument must be a valid domain\n"); elseif (!are_mf_params ('gauss2mf', params)) puts ("Type 'help gauss2mf' for more information.\n"); error ("gauss2mf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on ## the domain x according to the definition of gauss2mf given in the ## comment above. sig1 = params(1); c1 = params(2); sig2 = params(3); c2 = params(4); f1_val = @(x_val) (x_val <= c1) * ... exp ((-(x_val - c1)^2)/(2 * sig1^2)) + ... (x_val > c1); f2_val = @(x_val) (x_val <= c2) + ... (x_val > c2) * exp ((-(x_val - c2)^2)/(2 * sig2^2)); f1 = arrayfun (f1_val, x); f2 = arrayfun (f2_val, x); y = f1 .* f2; endfunction %!demo %! x = -10:0.2:10; %! params = [3 0 1.5 2]; %! y1 = gauss2mf(x, params); %! params = [1.5 0 3 2]; %! y2 = gauss2mf(x, params); %! params = [1.5 2 3 0]; %! y3 = gauss2mf(x, params); %! figure('NumberTitle', 'off', 'Name', 'gauss2mf demo'); %! plot(x, y1, 'r;params = [3 0 1.5 2];', 'LineWidth', 2); %! hold on ; %! plot(x, y2, 'b;params = [1.5 0 3 2];', 'LineWidth', 2); %! hold on ; %! plot(x, y3, 'g;params = [1.5 2 3 0];', 'LineWidth', 2); %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; %! hold; fuzzy-logic-toolkit/inst/gustafson_kessel.m0000664000175000017500000004156312354647032020516 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{cluster_centers} =} gustafson_kessel (@var{input_data}, @var{num_clusters}) ## @deftypefnx {Function File} {@var{cluster_centers} =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}) ## @deftypefnx {Function File} {@var{cluster_centers} =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}, @var{options}) ## @deftypefnx {Function File} {@var{cluster_centers} =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}, [@var{m}, @var{max_iterations}, @var{epsilon}, @var{display_intermediate_results}]) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} gustafson_kessel (@var{input_data}, @var{num_clusters}) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}, @var{options}) ## @deftypefnx {Function File} {[@var{cluster_centers}, @var{soft_partition}, @var{obj_fcn_history}] =} gustafson_kessel (@var{input_data}, @var{num_clusters}, @var{cluster_volume}, [@var{m}, @var{max_iterations}, @var{epsilon}, @var{display_intermediate_results}]) ## ## Using the Gustafson-Kessel algorithm, calculate and return the soft partition ## of a set of unlabeled data points. ## ## Also, if @var{display_intermediate_results} is true, display intermediate ## results after each iteration. Note that because the initial cluster ## prototypes are randomly selected locations in the ranges determined by the ## input data, the results of this function are nondeterministic. ## ## The required arguments to gustafson_kessel are: ## @itemize @w ## @item ## @var{input_data} - a matrix of input data points; each row corresponds to one point ## @item ## @var{num_clusters} - the number of clusters to form ## @end itemize ## ## The third (optional) argument to gustafson_kessel is a vector of cluster volumes. ## If omitted, a vector of 1's will be used as the default. ## ## The fourth (optional) argument to gustafson_kessel is a vector consisting of: ## @itemize @w ## @item ## @var{m} - the parameter (exponent) in the objective function; default = 2.0 ## @item ## @var{max_iterations} - the maximum number of iterations before stopping; default = 100 ## @item ## @var{epsilon} - the stopping criteria; default = 1e-5 ## @item ## @var{display_intermediate_results} - if 1, display results after each iteration, and if 0, do not; default = 1 ## @end itemize ## ## The default values are used if any of the four elements of the vector are missing or ## evaluate to NaN. ## ## The return values are: ## @itemize @w ## @item ## @var{cluster_centers} - a matrix of the cluster centers; each row corresponds to one point ## @item ## @var{soft_partition} - a constrained soft partition matrix ## @item ## @var{obj_fcn_history} - the values of the objective function after each iteration ## @end itemize ## ## Three important matrices used in the calculation are X (the input points ## to be clustered), V (the cluster centers), and Mu (the membership of each ## data point in each cluster). Each row of X and V denotes a single point, ## and Mu(i, j) denotes the membership degree of input point X(j, :) in the ## cluster having center V(i, :). ## ## X is identical to the required argument @var{input_data}; V is identical ## to the output @var{cluster_centers}; and Mu is identical to the output ## @var{soft_partition}. ## ## If n denotes the number of input points and k denotes the number of ## clusters to be formed, then X, V, and Mu have the dimensions: ## ## @example ## @group ## 1 2 ... #features ## 1 [ ] ## X = input_data = 2 [ ] ## ... [ ] ## n [ ] ## @end group ## @end example ## ## @example ## @group ## 1 2 ... #features ## 1 [ ] ## V = cluster_centers = 2 [ ] ## ... [ ] ## k [ ] ## @end group ## @end example ## ## @example ## @group ## 1 2 ... n ## 1 [ ] ## Mu = soft_partition = 2 [ ] ## ... [ ] ## k [ ] ## @end group ## @end example ## ## @seealso{fcm, partition_coeff, partition_entropy, xie_beni_index} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel.m ## Last-Modified: 5 Sep 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... gustafson_kessel (input_data, num_clusters, ... cluster_volume = [], options = [2.0, 100, 1e-5, 1]) ## If gustafson_kessel was called with an incorrect number of ## arguments, or the arguments do not have the correct type, print ## an error message and halt. if ((nargin < 2) || (nargin > 4)) puts ("Type 'help gustafson_kessel' for more information.\n"); error ("gustafson_kessel requires 2, 3, or 4 arguments\n"); elseif (!is_real_matrix (input_data)) puts ("Type 'help gustafson_kessel' for more information.\n"); error ("gustafson_kessel's 1st argument must be matrix of reals\n"); elseif (!(is_int (num_clusters) && (num_clusters > 1))) puts ("Type 'help gustafson_kessel' for more information.\n"); error ("gustafson_kessel's 2nd argument must be an integer > 1\n"); elseif (!(isequal (cluster_volume, []) || ... (isreal (cluster_volume) && isvector (cluster_volume)))) puts ("Type 'help gustafson_kessel' for more information.\n"); error ("gustafson_kessel's 3rd arg must be a vector of reals\n"); elseif (!(isreal (options) && isvector (options))) puts ("Type 'help gustafson_kessel' for more information.\n"); error ("gustafson_kessel's 4th arg must be a vector of reals\n"); endif ## If the cluster volume matrix was not entered, create a default ## value (a vector of 1's). if (isequal (cluster_volume, [])) cluster_volume = ones (1, num_clusters); endif ## Assign options to the more readable variable names: m, ## max_iterations, epsilon, and display_intermediate_results. ## If options are missing or NaN (not a number), use the default ## values. default_options = [2.0, 100, 1e-5, 1]; for i = 1 : 4 if ((length (options) < i) || ... isna (options(i)) || isnan (options(i))) options(i) = default_options(i); endif endfor m = options(1); max_iterations = options(2); epsilon = options(3); display_intermediate_results = options(4); ## Call a private function to compute the output. [cluster_centers, soft_partition, obj_fcn_history] = ... gustafson_kessel_private (input_data, num_clusters, ... cluster_volume, m, max_iterations, ... epsilon, display_intermediate_results); endfunction ##---------------------------------------------------------------------- ## Function: gustafson_kessel_private ## Purpose: Classify unlabeled data points using the Gustafson-Kessel ## algorithm. ## Note: This function (gustafson_kessel_private) is an ## implementation of Algorithm 4.2 in Fuzzy and Neural ## Control, by Robert Babuska, November 2009, p. 69. ##---------------------------------------------------------------------- function [V, Mu, obj_fcn_history] = ... gustafson_kessel_private (X, k, cluster_volume, m, max_iterations, ... epsilon, display_intermediate_results) ## Initialize the prototypes and the calculation. V = init_cluster_prototypes (X, k); obj_fcn_history = zeros (max_iterations); convergence_criterion = epsilon + 1; iteration = 0; ## Calculate a few numbers here to reduce redundant computation. k = rows (V); n = rows (X); sqr_dist = square_distance_matrix (X, V); ## Loop until the objective function is within tolerance or the ## maximum number of iterations has been reached. while (convergence_criterion > epsilon && ... ++iteration <= max_iterations) V_previous = V; Mu = update_cluster_membership (V, X, m, k, n, sqr_dist); Mu_m = Mu .^ m; V = update_cluster_prototypes (Mu_m, X, k); sqr_dist = gk_square_distance_matrix (X, V, Mu_m, cluster_volume); obj_fcn_history(iteration) = ... compute_cluster_obj_fcn (Mu_m, sqr_dist); if (display_intermediate_results) printf ("Iteration count = %d, Objective fcn = %8.6f\n", ... iteration, obj_fcn_history(iteration)); endif convergence_criterion = ... compute_cluster_convergence (V, V_previous); endwhile ## Remove extraneous entries from the tail of the objective ... ## function history. if (convergence_criterion <= epsilon) obj_fcn_history = obj_fcn_history(1 : iteration); endif endfunction ##---------------------------------------------------------------------- ## Function: gk_square_distance_matrix ##---------------------------------------------------------------------- function sqr_dist = gk_square_distance_matrix (X, V, Mu_m, ... cluster_volume) k = rows (V); n = rows (X); num_features = columns (X); sqr_dist = zeros (k, n); for i = 1 : k Vi = V(i, :); covariance_matrix = compute_covariance_matrix (X, V, Mu_m, i); for j = 1 : n Vi_to_Xj = X(j, :) - Vi; A = cluster_volume(i) * ... det (covariance_matrix) ^ (1.0 / num_features) * ... inv (covariance_matrix); sqr_dist(i, j) = sum (Vi_to_Xj .* (A * Vi_to_Xj')'); endfor endfor endfunction ##---------------------------------------------------------------------- ## Function: compute_covariance_matrix ##---------------------------------------------------------------------- function covariance_matrix = compute_covariance_matrix (X, V, Mu_m, i) num_features = columns (V); n = rows (X); num = zeros (num_features); denom = 0.0; Vi = V(i, :); for j = 1 : n Vi_to_Xj = X(j, :) - Vi; num += Mu_m(i, j) * Vi_to_Xj' * Vi_to_Xj; denom += Mu_m(i, j); endfor covariance_matrix = num / denom; endfunction ##---------------------------------------------------------------------- ## Gustafson-Kessel Demo #1 ##---------------------------------------------------------------------- %!demo %! ## This demo: %! ## - classifies a small set of unlabeled data points using %! ## the Gustafson-Kessel algorithm into two fuzzy clusters %! ## - plots the input points together with the cluster centers %! ## - evaluates the quality of the resulting clusters using %! ## three validity measures: the partition coefficient, the %! ## partition entropy, and the Xie-Beni validity index %! ## %! ## Note: The input_data is taken from Chapter 13, Example 17 in %! ## Fuzzy Logic: Intelligence, Control and Information, by %! ## J. Yen and R. Langari, Prentice Hall, 1999, page 381 %! ## (International Edition). %! %! ## Use gustafson_kessel to classify the input_data. %! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4]; %! number_of_clusters = 2; %! [cluster_centers, soft_partition, obj_fcn_history] = ... %! gustafson_kessel (input_data, number_of_clusters) %! %! ## Plot the data points as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 1'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 2'); %! grid %! hold %! %! ## Calculate and print the three validity measures. %! printf ("Partition Coefficient: %f\n", ... %! partition_coeff (soft_partition)); %! printf ("Partition Entropy (with a = 2): %f\n", ... %! partition_entropy (soft_partition, 2)); %! printf ("Xie-Beni Index: %f\n\n", ... %! xie_beni_index (input_data, cluster_centers, ... %! soft_partition)); ##---------------------------------------------------------------------- ## Gustafson-Kessel Demo #2 ##---------------------------------------------------------------------- %!demo %! ## This demo: %! ## - classifies three-dimensional unlabeled data points using %! ## the Gustafson-Kessel algorithm into three fuzzy clusters %! ## - plots the input points together with the cluster centers %! ## - evaluates the quality of the resulting clusters using %! ## three validity measures: the partition coefficient, the %! ## partition entropy, and the Xie-Beni validity index %! ## %! ## Note: The input_data was selected to form three areas of %! ## different shapes. %! %! ## Use gustafson_kessel to classify the input_data. %! input_data = [1 11 5; 1 12 6; 1 13 5; 2 11 7; 2 12 6; 2 13 7; %! 3 11 6; 3 12 5; 3 13 7; 1 1 10; 1 3 9; 2 2 11; %! 3 1 9; 3 3 10; 3 5 11; 4 4 9; 4 6 8; 5 5 8; 5 7 9; %! 6 6 10; 9 10 12; 9 12 13; 9 13 14; 10 9 13; 10 13 12; %! 11 10 14; 11 12 13; 12 6 12; 12 7 15; 12 9 15; %! 14 6 14; 14 8 13]; %! number_of_clusters = 3; %! [cluster_centers, soft_partition, obj_fcn_history] = ... %! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... %! [NaN NaN NaN 0]) %! %! ## Plot the data points in two dimensions (using features 1 & 2) %! ## as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 2'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 2), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers in two dimensions %! ## (using features 1 & 2) as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 2'); %! grid %! %! ## Plot the data points in two dimensions %! ## (using features 1 & 3) as small blue x's. %! figure ('NumberTitle', 'off', 'Name', 'Gustafson-Kessel Demo 2'); %! for i = 1 : rows (input_data) %! plot (input_data(i, 1), input_data(i, 3), 'LineWidth', 2, ... %! 'marker', 'x', 'color', 'b'); %! hold on; %! endfor %! %! ## Plot the cluster centers in two dimensions %! ## (using features 1 & 3) as larger red *'s. %! for i = 1 : number_of_clusters %! plot (cluster_centers(i, 1), cluster_centers(i, 3), ... %! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! %! ## Make the figure look a little better: %! ## - scale and label the axes %! ## - show gridlines %! xlim ([0 15]); %! ylim ([0 15]); %! xlabel ('Feature 1'); %! ylabel ('Feature 3'); %! grid %! hold %! %! ## Calculate and print the three validity measures. %! printf ("Partition Coefficient: %f\n", ... %! partition_coeff (soft_partition)); %! printf ("Partition Entropy (with a = 2): %f\n", ... %! partition_entropy (soft_partition, 2)); %! printf ("Xie-Beni Index: %f\n\n", ... %! xie_beni_index (input_data, cluster_centers, ... %! soft_partition)); fuzzy-logic-toolkit/inst/algebraic_sum.m0000664000175000017500000000542612354647032017732 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} algebraic_sum (@var{x, y}) ## @deftypefnx {Function File} {@var{retval} =} algebraic_sum (@var{x, y}) ## ## Return the algebraic sum of the input. ## The algebraic sum of two real scalars x and y is: x + y - x * y ## ## For one vector argument, apply the algebraic sum to all of elements of ## the vector. (The algebraic sum is associative.) For one two-dimensional ## matrix argument, return a vector of the algebraic sum of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise algebraic sum. ## ## @seealso{algebraic_product, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy algebraic_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: algebraic_sum.m ## Last-Modified: 18 Aug 2012 function retval = algebraic_sum (x, y = 0) if (!(isreal (x) && isreal (y))) puts ("Type 'help algebraic_sum' for more information.\n"); error ("algebraic_sum requires real scalar or matrix arguments\n"); elseif (nargin == 2 && ... (isscalar (x) || isscalar (y) || ... isequal (size (x), size (y)))) retval = x .+ y .- x .* y; elseif (nargin == 1 && isvector (x)) retval = algebraic_sum_of_vector (x); elseif (nargin == 1 && ndims (x) == 2) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = algebraic_sum_of_vector (x(:, i)); endfor else puts ("Type 'help algebraic_sum' for more information.\n"); error ("invalid arguments to function algebraic_sum\n"); endif endfunction function retval = algebraic_sum_of_vector (real_vector) x = 0; for i = 1 : length (real_vector) y = real_vector(i); x = x + y - x * y; endfor retval = x; endfunction fuzzy-logic-toolkit/inst/einstein_product.m0000664000175000017500000000631612354647032020512 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} einstein_product (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} einstein_product (@var{x}, @var{y}) ## ## Return the Einstein product of the input. ## The Einstein product of two real scalars x and y is: ## (x * y) / (2 - (x + y - x * y)) ## ## For one vector argument, apply the Einstein product to all of the elements ## of the vector. (The Einstein product is associative.) For one ## two-dimensional matrix argument, return a vector of the Einstein product ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise Einstein product. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy einstein_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: einstein_product.m ## Last-Modified: 20 Aug 2012 function retval = einstein_product (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) retval = (x * y) / (2 - (x + y - x * y)); endfunction function retval = vector_arg (real_vector) x = 1; for i = 1 : length (real_vector) y = real_vector(i); x = (x * y) / (2 - (x + y - x * y)); endfor retval = x; endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help einstein_product' for more information.\n"); error ("invalid arguments to function einstein_product\n"); endfunction fuzzy-logic-toolkit/inst/private/0000775000175000017500000000000012354647032016422 5ustar lindalindafuzzy-logic-toolkit/inst/private/square_distance_matrix.m0000664000175000017500000000341112354647032023335 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{sqr_dist} =} square_distance_matrix (@var{X}, @var{V}) ## ## Return a k x n matrix of ||x - v||^2 values (the squares of the ## distances between input data points x and cluster centers v), where ## k is the number of cluster centers and n is the number of data points. ## ## The element sqr_dist(i, j) will contain the square of the distance ## between the cluster center V(i, :) and the data point X(j, :). ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: square_dist_matrix.m ## Last-Modified: 20 Aug 2012 function sqr_dist = square_distance_matrix (X, V) k = rows (V); n = rows (X); sqr_dist = zeros (k, n); for i = 1 : k Vi = V(i, :); for j = 1 : n Vi_to_Xj = X(j, :) - Vi; sqr_dist(i, j) = sum (Vi_to_Xj .* Vi_to_Xj); endfor endfor endfunction fuzzy-logic-toolkit/inst/private/is_builtin_language.m0000664000175000017500000000350612354647032022610 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_builtin_language (@var{x}) ## ## Return 1 if @var{x} is one of the strings representing the ## built-in languages, and return 0 otherwise. The comparison is ## case-insensitive. ## ## is_builtin_language is a private function that localizes the test ## for languages handled by showrule. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_builtin_language.m ## Last-Modified: 3 Sep 2012 function y = is_builtin_language (x) y = ischar (x) && isvector (x) && ... ismember (tolower (x), {'english', ... 'chinese', 'mandarin', 'pinyin', ... 'russian', 'russkij', 'pycckii', ... 'french', 'francais', ... 'spanish', 'espanol', ... 'german', 'deutsch'}); endfunction fuzzy-logic-toolkit/inst/private/aggregate_output_sugeno.m0000664000175000017500000001324212354647032023530 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fuzzy_output} =} aggregate_output_sugeno (@var{fis}, @var{rule_output}) ## ## @noindent ## Given the: ## @itemize @bullet ## @item @var{fis.aggMethod} ## the aggregation method for the given @var{fis} ## @item @var{rule_output} ## a matrix of the singleton output of each (rule, FIS output) pair ## @end itemize ## ## @noindent ## Return: ## @itemize @bullet ## @item @var{fuzzy_output} ## a vector of structures containing the aggregated output for each FIS output ## @end itemize ## ## @var{rule_output} is a 2 x (Q * M) matrix, where Q is the number of rules ## and M is the number of FIS output variables. Each column of @var{rule_output} ## gives the (location, height) pair of the singleton output for one ## (rule, FIS output) pair: ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## location [ ] ## height [ ] ## @end group ## @end example ## ## The return value @var{fuzzy_output} is a vector of M structures, ## each of which has an index i and a matrix of singletons that form the ## aggregated output for the ith FIS output variable. ## For each FIS output variable, the matrix of singletons is a 2 x L matrix ## where L is the number of distinct singleton locations in the fuzzy output ## for that FIS output variable. The first row gives the (distinct) locations, ## and the second gives the (non-zero) heights: ## ## @example ## @group ## singleton_1 singleton_2 ... singleton_L ## location [ ] ## height [ ] ## @end group ## @end example ## ## Because aggregate_output_sugeno 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_sugeno.m ## Last-Modified: 20 Aug 2012 ##---------------------------------------------------------------------- function fuzzy_output = aggregate_output_sugeno (fis, rule_output) fuzzy_output = []; num_outputs = columns (fis.output); num_rules = columns (fis.rule); ## For each FIS output, aggregate the slice of the rule_output matrix, ## then store the result as a structure in fuzzy_output. for i = 1 : num_outputs unagg_output = rule_output(:, (i-1)*num_rules+1 : i*num_rules); aggregated_output = aggregate_fis_output (fis.aggMethod, ... unagg_output); next_agg_output = struct ('index', i, ... 'aggregated_output', aggregated_output); if (i == 1) fuzzy_output = next_agg_output; else fuzzy_output = [fuzzy_output, next_agg_output]; endif endfor endfunction ##---------------------------------------------------------------------- ## Function: aggregate_fis_output ## Purpose: Aggregate the multiple singletons for one FIS output. ##---------------------------------------------------------------------- function mult_singletons = aggregate_fis_output (fis_aggmethod, ... rule_output) ## Initialize output matrix (multiple_singletons). mult_singletons = sortrows (rule_output', 1); ## If adjacent rows represent singletons at the same location, then ## combine them using the FIS aggregation method. for i = 1 : rows (mult_singletons) - 1 if (mult_singletons(i, 1) == mult_singletons(i+1, 1)) switch (fis_aggmethod) case 'sum' mult_singletons(i + 1, 2) = mult_singletons(i, 2) + ... mult_singletons(i + 1, 2); otherwise mult_singletons(i + 1, 2) = str2func (fis_aggmethod) ... (mult_singletons(i, 2), ... mult_singletons(i + 1, 2)); endswitch mult_singletons(i, 2) = 0; endif endfor ## Return the transpose of the matrix after removing 0-height ## singletons. mult_singletons = (remove_null_rows (mult_singletons))'; endfunction ##---------------------------------------------------------------------- ## Function: remove_null_rows ## Purpose: Return the argument without the rows with a 0 in the ## second column. ##---------------------------------------------------------------------- function y = remove_null_rows (x) y = []; for i = 1 : rows (x) if (x(i, 2) != 0) if (isequal (y, [])) y = x(i, :); else y = [y; x(i, :)]; endif endif endfor endfunction fuzzy-logic-toolkit/inst/private/init_cluster_prototypes.m0000664000175000017500000000337512354647032023624 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} init_cluster_prototypes (@var{X}, @var{k}) ## ## Initialize k cluster centers to random locations in the ranges ## given by the min/max values of each feature of the dataset. ## ## @seealso{fcm, gustafson_kessel, update_cluster_membership, update_cluster_prototypes, compute_cluster_obj_fcn, compute_cluster_convergence} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: init_cluster_prototypes.m ## Last-Modified: 2 Sep 2012 function V = init_cluster_prototypes (X, k) num_features = columns (X); min_feature_value = min (X); max_feature_value = max (X); V = rand (k, num_features); for i = 1 : num_features V(:, i) = (max_feature_value(i) - min_feature_value(i)) * ... V(:, i) + min_feature_value(i); endfor endfunction fuzzy-logic-toolkit/inst/private/is_pos_int.m0000664000175000017500000000300112354647032020740 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_pos_int (@var{x}) ## ## Return 1 if @var{x} is a positive integer-valued real scalar, and return 0 ## otherwise. ## ## Examples: ## @example ## @group ## is_pos_int(6) ==> 1 ## is_pos_int(6.2) ==> 0 ## is_pos_int(ones(2)) ==> 0 ## is_pos_int(6 + 0i) ==> 1 ## is_pos_int(0) ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_pos_int.m ## Last-Modified: 20 Aug 2012 function y = is_pos_int (x) y = is_int (x) && (x > 0); endfunction fuzzy-logic-toolkit/inst/private/is_domain.m0000664000175000017500000000321612354647032020544 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_domain (@var{x}) ## @deftypefnx {Function File} {@var{y} =} is_domain (@var{[x1 x2 ... xn]}) ## ## Return 1 if @var{x} is a real number of a vector of strictly increasing real ## numbers, and return 0 otherwise. ## ## is_domain is a private function that localizes the test for validity of FIS ## input variable domains. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_domain.m ## Last-Modified: 20 Aug 2012 function y = is_domain (x) y = 1; if (!(isvector (x) && isreal (x))) y = 0; elseif (length(x) > 1) for i = 1 : length (x) - 1 if (x(i) >= x(i + 1)) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/compute_cluster_obj_fcn.m0000664000175000017500000000356612354647032023507 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{obj_fcn} =} compute_cluster_obj_fcn (@var{Mu_m}, @var{sqr_dist}) ## ## Compute the objective function for the current iteration. ## ## @seealso{fcm, gustafson_kessel, init_cluster_prototypes, update_cluster_membership, update_cluster_prototypes, compute_cluster_convergence} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: compute_cluster_obj_fcn.m ## Last-Modified: 2 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.3 in ## Fuzzy Logic: Intelligence, Control and Information, by ## J. Yen and R. Langari, Prentice Hall, 1999, page 379 ## (International Edition). ##---------------------------------------------------------------------- function obj_fcn = compute_cluster_obj_fcn (Mu_m, sqr_dist) obj_fcn = sum (sum (Mu_m .* sqr_dist)); endfunction fuzzy-logic-toolkit/inst/private/evalfis_private.m0000664000175000017500000000577412354647032022000 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{output} =} evalfis_private (@var{input}, @var{fis}) ## @deftypefnx {Function File} {@var{output} =} evalfis_private (@var{input}, @var{fis}, @var{num_points}) ## @deftypefnx {Function File} {[@var{output}, @var{rule_input}, @var{rule_output}, @var{fuzzy_output}] =} evalfis_private (@var{input}, @var{fis}) ## @deftypefnx {Function File} {[@var{output}, @var{rule_input}, @var{rule_output}, @var{fuzzy_output}] =} evalfis_private (@var{input}, @var{fis}, @var{num_points}) ## ## This function localizes the FIS evaluation common to the public functions ## evalfis and gensurf. All of the arguments to evalfis_private are assumed to ## be valid (limiting the inefficiency of the tests to the calling function). ## ## For more information, see the comments at the top of evalfis.m and gensurf.m. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: evalfis_private.m ## Last-Modified: 20 Aug 2012 function [output, rule_input, rule_output, fuzzy_output] = ... evalfis_private (user_input, fis, num_points = 101) ## Initialize output matrix (to prevent repeated resizing). output = zeros (rows (user_input), columns (fis.output)); ## Process one set of inputs at a time. For each row of crisp input ## values in the input matrix, add a row of crisp output values to the ## output matrix. for i = 1 : rows (user_input) rule_input = fuzzify_input (fis, user_input(i, :)); firing_strength = eval_firing_strength (fis, rule_input); if (strcmp (fis.type, 'mamdani')) rule_output = eval_rules_mamdani (fis, firing_strength, ... num_points); fuzzy_output = aggregate_output_mamdani (fis, rule_output); output(i, :) = defuzzify_output_mamdani (fis, fuzzy_output); else rule_output = eval_rules_sugeno (fis, firing_strength, ... user_input(i, :)); fuzzy_output = aggregate_output_sugeno (fis, rule_output); output(i, :) = defuzzify_output_sugeno (fis, fuzzy_output); endif endfor endfunction fuzzy-logic-toolkit/inst/private/is_real.m0000664000175000017500000000320612354647032020217 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_real (@var{x}) ## ## Return 1 if @var{x} is an real scalar, and return 0 otherwise. ## ## is_real is a private function that localizes the test for real scalars. ## ## Examples: ## @example ## @group ## is_real(6) ==> 1 ## is_real(6.2) ==> 1 ## is_real(ones(2)) ==> 0 ## is_real(6 + 0i) ==> 1 ## is_real(6 + i) ==> 0 ## is_real([0]) ==> 1 ## is_real([0 0]) ==> 0 ## is_real('h') ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_real.m ## Last-Modified: 20 Aug 2012 function y = is_real (x) y = isnumeric(x) && isscalar (x) && isreal (x); endfunction fuzzy-logic-toolkit/inst/private/get_mf_index_and_hedge.m0000664000175000017500000000503612354647032023212 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{[mf_index hedge not_flag]} =} get_mf_index_and_hedge (@var{mf_index_and_hedge}) ## ## Return the membership function index, hedge, and flag indicating "not" ## indicated by the argument. ## ## The membership function index, @var{mf_index}, is the positive whole number ## portion of the argument. The @var{hedge} is the fractional part of the ## argument, rounded to 2 digits and multiplied by 10. The @var{not_flag}, ## a Boolean, is true iff the argument is negative. ## ## Because get_mf_index_and_hedge is a private function, it does no error ## checking of its argument. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: get_mf_index_and_hedge.m ## Last-Modified: 20 Aug 2012 function [mf_index hedge not_flag] = ... get_mf_index_and_hedge (mf_index_and_hedge) ## Set flag to handle "not", indicated by a minus sign in the ## antecedent. if (mf_index_and_hedge < 0) not_flag = true; mf_index_and_hedge = -mf_index_and_hedge; else not_flag = false; endif ## The membership function index is the positive whole number portion ## of an element in the antecedent. mf_index = fix (mf_index_and_hedge); ## For custom hedges and the four built-in hedges "somewhat", "very", ## "extremely", and "very very", return the power to which the ## membership value should be raised. The hedges are indicated by the ## fractional part of the corresponding rule_matrix entry (rounded to ## 2 digits). if (mf_index != 0) hedge = round (100 * (mf_index_and_hedge - mf_index)) / 10; else hedge = 0; endif endfunction fuzzy-logic-toolkit/inst/private/fuzzify_input.m0000664000175000017500000000623212354647032021530 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{rule_input} =} fuzzify_input (@var{fis}, @var{user_input}) ## ## Return the matching degree for each (rule, input value) pair. ## For an FIS that has Q rules and N FIS input variables, the return value ## will be a Q x N matrix. ## ## @noindent ## The crisp input values are given by a row vector: ## ## @example ## user_input: [input_1 input_2 ... input_N] ## @end example ## ## @noindent ## The rule antecedents are stored in the FIS structure as row vectors: ## ## @example ## @group ## rule 1 antecedent: [in_11 in_12 ... in_1N] ## rule 2 antecedent: [in_21 in_22 ... in_2N] ## ... ... ## rule Q antecedent: [in_Q1 in_Q2 ... in_QN] ## @end group ## @end example ## ## @noindent ## Finally, the output of the function gives the matching degree ## for each (rule, input value) pair as an Q x N matrix: ## ## @example ## @group ## in_1 in_2 ... in_N ## rule_1 [mu_11 mu_12 ... mu_1N] ## rule_2 [mu_21 mu_22 ... mu_2N] ## [ ... ] ## rule_Q [mu_Q1 mu_Q2 ... mu_QN] ## @end group ## @end example ## ## Because fuzzify_input 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: fuzzify_input.m ## Last-Modified: 20 Aug 2012 function rule_input = fuzzify_input (fis, user_input) num_rules = columns (fis.rule); ## num_rules == Q (above) num_inputs = columns (fis.input); ## num_inputs == N rule_input = zeros (num_rules, num_inputs); ## to prevent resizing ## For each rule i and each input j, compute the value of mu ## in the result. for i = 1 : num_rules antecedent = fis.rule(i).antecedent; for j = 1 : num_inputs mu = 0; crisp_x = user_input(j); ## Get the value of mu (with adjustment for the hedge ## and not_flag). [mf_index hedge not_flag] = ... get_mf_index_and_hedge (antecedent(j)); if (mf_index != 0) mf = fis.input(j).mf(mf_index); mu = evalmf (crisp_x, mf.params, mf.type, hedge, not_flag); endif ## Store the fuzzified input in rule_input. rule_input(i, j) = mu; endfor endfor endfunction fuzzy-logic-toolkit/inst/private/is_row_vector.m0000664000175000017500000000272012354647032021465 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_row_vector (@var{x}) ## ## Return 1 if @var{x} is a non-empty row vector, and return 0 otherwise. ## ## Examples: ## @example ## @group ## is_row_vector([]) ==> 0 ## is_row_vector([1 2 3]) ==> 1 ## is_row_vector([1; 2; 3]) ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_row_vector.m ## Last-Modified: 20 Aug 2012 function y = is_row_vector (x) y = isvector (x) && (rows (x) == 1); endfunction fuzzy-logic-toolkit/inst/private/is_format.m0000664000175000017500000000301412354647032020561 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_format (@var{x}) ## ## Return 1 if @var{x} is one of the strings 'verbose', 'symbolic', and ## 'indexed', and return 0 otherwise. The comparison is case-insensitive. ## ## is_format is a private function that localizes the test for valid fis rule ## input/output formats. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_format.m ## Last-Modified: 20 Aug 2012 function y = is_format (x) y = ischar (x) && isvector (x) && ... ismember (tolower (x), {'verbose', 'symbolic', 'indexed'}); endfunction fuzzy-logic-toolkit/inst/private/evalmf_private.m0000664000175000017500000001025612354647032021610 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} evalmf_private (@var{x}, @var{param}, @var{mf_type}) ## @deftypefnx {Function File} {@var{y} =} evalmf_private (@var{x}, @var{param}, @var{mf_type}, @var{hedge}) ## @deftypefnx {Function File} {@var{y} =} evalmf_private (@var{x}, @var{param}, @var{mf_type}, @var{hedge}, @var{not_flag}) ## @deftypefnx {Function File} {@var{y} =} evalmf_private (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, '<@var{mf_type}>') ## @deftypefnx {Function File} {@var{y} =} evalmf_private (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, '<@var{mf_type}>', @var{hedge}) ## @deftypefnx {Function File} {@var{y} =} evalmf_private (@var{[x1 x2 ... xn]}, @var{[param1 ... ]}, '<@var{mf_type}>', @var{hedge}, @var{not_flag}) ## ## This function localizes the membership function evaluation without the ## parameter tests. It is called by evalmf and plotmf. For more information, ## see the comment at the top of evalmf.m. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership-function evaluate ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: evalmf_private.m ## Last-Modified: 3 Sep 2012 function y = evalmf_private (x, params, mf_type, hedge = 0, ... not_flag = false) ## Calculate and return the y values of the membership function on ## the domain x. First, get the value of the membership function ## without correcting for the hedge and not_flag. Then, for non-linear ## functions, adjust the function values for non-zero hedge and ## not_flag. switch (mf_type) case 'constant' y = eval_constant (x, params); if (not_flag) y = 1 - y; endif case 'linear' y = eval_linear (x, params); otherwise y = str2func (mf_type) (x, params); if (hedge != 0) y = y .^ hedge; endif if (not_flag) y = 1 - y; endif endswitch endfunction ##---------------------------------------------------------------------- ## Function: eval_constant ## Purpose: Return the y-values corresponding to the x-values in ## the domain for the constant function specified by the ## parameter c. ##---------------------------------------------------------------------- function y = eval_constant (x, c) y = zeros (length (x)); delta = x(2) - x(1); y_val = @(x_val) ((abs (c - x_val) < delta) * 1); y = arrayfun (y_val, x); endfunction ##---------------------------------------------------------------------- ## Function: eval_linear ## Purpose: For the parameters [a ... c]), return the y-values ## corresponding to the linear function y = a*x + c, where x ## takes on the the x-values in the domain. The remaining ## coefficients in the parameter list are not used -- this ## creates a two-dimensional intersection of the linear output ## membership function suitable for display together with ## other membership functions, but does not fully represent ## the output membership function. ##---------------------------------------------------------------------- function y = eval_linear (x, params) if (length (params) == 1) a = 0; c = params; else a = params(1); c = params(length (params)); endif y = zeros (length (x)); y_val = @(x_val) (a * x_val + c); y = arrayfun (y_val, x); endfunction fuzzy-logic-toolkit/inst/private/is_var_index.m0000664000175000017500000000363212354647032021256 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_var_index (@var{fis}, @var{in_or_out}, @var{var_index}) ## ## If @var{in_or_out} == 'input', return 1 if @var{var_index} is a valid input ## variable index for the given FIS structure, and return 0 otherwise. ## ## If @var{in_or_out} == 'output', return 1 if @var{var_index} is a valid output ## variable index for the given FIS structure, and return 0 otherwise. ## ## is_var_index is a private function that localizes the test for valid FIS ## input and output variable indices. The arguments @var{fis} and ## @var{in_or_out} are assumed to be valid. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_var_index.m ## Last-Modified: 20 Aug 2012 function y = is_var_index (fis, in_or_out, var_index) y = is_int (var_index) && (var_index >= 1); if (strcmp (in_or_out, 'input')) y = y && (var_index <= length (fis.input)); else y = y && (var_index <= length (fis.output)); endif endfunction fuzzy-logic-toolkit/inst/private/is_input_matrix.m0000664000175000017500000000335612354647032022025 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_input_matrix (@var{x}, @var{fis}) ## ## Return 1 if @var{x} is a valid matrix of input values for the given FIS ## structure, and return 0 otherwise. The FIS structure @var{fis} is assumed ## to be valid. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_input_matrix.m ## Last-Modified: 20 Aug 2012 function y = is_input_matrix (x, fis) if (!(ismatrix (x) && isreal (x) && ... (columns (x) == columns (fis.input)))) y = 0; else y = 1; for j = 1 : columns (x) range = fis.input(j).range; for i = 1 : rows(x) if (!(isscalar (x(i, j)) && ... x(i,j) >= range(1) && ... x(i,j) <= range(2))) y = 0; endif endfor endfor endif endfunction fuzzy-logic-toolkit/inst/private/compute_cluster_convergence.m0000664000175000017500000000317412354647032024400 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{convergence_criterion} =} compute_cluster_convergence (@var{V}, @var{V_previous}) ## ## Compute the sum of the changes in position (using the Euclidean ## distance) of the cluster prototypes. ## ## @seealso{fcm, gustafson_kessel, init_cluster_prototypes, update_cluster_membership, update_cluster_prototypes, compute_cluster_obj_fcn} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: compute_cluster_convergence.m ## Last-Modified: 2 Sep 2012 function convergence_criterion = ... compute_cluster_convergence (V, V_previous) V_delta = V - V_previous; convergence_criterion = sum (sqrt (sum (V_delta .* V_delta)')); endfunction fuzzy-logic-toolkit/inst/private/is_mf_struct.m0000664000175000017500000000327712354647032021312 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_mf_struct (@var{x}) ## ## Return 1 if the argument @var{x} is a valid FIS (Fuzzy Inference System) ## membership function structure, and return 0 otherwise. ## ## is_mf_struct is a private function that localizes the test for valid FIS ## membership function structs. For efficiency, is_mf_struct only determines if ## the argument @var{x} is a structure with the expected fields, but the types ## of the fields are not verified. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_mf_struct.m ## Last-Modified: 20 Aug 2012 function y = is_mf_struct (x) y = isstruct (x) && ... isfield (x, 'name') && ... isfield (x, 'type') && ... isfield (x, 'params'); endfunction fuzzy-logic-toolkit/inst/private/is_fis.m0000664000175000017500000000453512354647032020063 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_fis (@var{x}) ## ## Return 1 if the argument @var{x} is a valid FIS (Fuzzy Inference System) ## structure, and return 0 otherwise. ## ## is_fis is a private function that localizes the test for valid FIS structs. ## For efficiency, is_fis only determines if the argument @var{x} is a structure ## with the expected fields, and that these fields have the expected types. ## ## Examples: ## @example ## @group ## fis = newfis('FIS'); ## is_fis(fis) ==> 1 ## @end group ## @end example ## ## @example ## @group ## x = pi; ## is_fis(x) ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_fis.m ## Last-Modified: 20 Aug 2012 function y = is_fis (x) y = isstruct (x) && ... isfield (x, 'name') && is_string (x.name) && ... isfield (x, 'type') && is_string (x.type) && ... isfield (x, 'andMethod') && is_string (x.andMethod) && ... isfield (x, 'orMethod') && is_string (x.orMethod) && ... isfield (x, 'impMethod') && is_string (x.impMethod) && ... isfield (x, 'aggMethod') && is_string (x.aggMethod) && ... isfield (x, 'defuzzMethod') && is_string (x.defuzzMethod) && ... isfield (x, 'input') && is_io_vector (x.input) && ... isfield (x, 'output') && is_io_vector (x.output) && ... isfield (x, 'rule') && is_rule_vector (x.rule); endfunction fuzzy-logic-toolkit/inst/private/are_bounds.m0000664000175000017500000000306012354647032020720 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} are_bounds (@var{x}) ## @deftypefnx {Function File} {@var{y} =} are_bounds (@var{[x1 x2]}) ## ## Return 1 if @var{x} is a vector of 2 real numbers @var{[x1 x2]}, ## with @var{x1} <= @var{x2}, and return 0 otherwise. ## ## are_bounds is a private function that localizes the test for validity of ## bounds imposed on FIS input/output domains. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: are_bounds.m ## Last-Modified: 20 Aug 2012 function y = are_bounds (x) y = isvector (x) && isreal (x) && (length (x) == 2) && (x(1) <= x(2)); endfunction fuzzy-logic-toolkit/inst/private/is_mf_vector.m0000664000175000017500000000305412354647032021261 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_mf_vector (@var{x}) ## ## Return 1 if @var{x} is a vector of FIS membership function structures, and ## return 0 otherwise. ## ## is_mf_vector is a private function that localizes the test for validity. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_mf_vector.m ## Last-Modified: 20 Aug 2012 function y = is_mf_vector (x) y = 1; if (isequal(x, [])) y = 1; elseif (!isvector (x)) y = 0; else y = 1; for i = 1 : length (x) if (!is_mf_struct (x(i))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/are_input_indices.m0000664000175000017500000000321212354647032022262 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} are_input_indices (@var{x}, @var{fis}) ## ## Return 1 if @var{x} is a valid input index or a vector of two valid input ## indices for the given FIS structure, and return 0 otherwise. The FIS ## structure @var{fis} is assumed to be valid. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: are_input_indices.m ## Last-Modified: 20 Aug 2012 function y = are_input_indices (x, fis) if (!(isreal (x) && isvector (x) && (length (x) <= 2))) y = 0; else y = 1; num_inputs = columns (fis.input); for next_x = x if (!(is_pos_int (next_x) && next_x <= num_inputs)) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/eval_rules_sugeno.m0000664000175000017500000001200012354647032022312 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{rule_output} =} eval_rules_sugeno (@var{fis}, @var{firing_strength}, @var{user_input}) ## ## Return the fuzzy output for each (rule, FIS output) pair for a ## Sugeno-type FIS (an FIS that has only constant and linear output ## membership functions). ## ## The firing strength of each rule is given by a row vector of length Q, where ## Q is the number of rules in the FIS: ## @example ## @group ## rule_1 rule_2 ... rule_Q ## [firing_strength(1) firing_strength(2) ... firing_strength(Q)] ## @end group ## @end example ## ## The consequent for each rule is given by: ## @example ## fis.rule(i).consequent for i = 1..Q ## @end example ## ## The return value of the function is a 2 x (Q * M) matrix, where ## M is the number of FIS output variables. ## Each column of this matrix gives the (location, height) pair of the ## singleton output for a single (rule, FIS output) pair. ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## location [ ] ## height [ ] ## @end group ## @end example ## ## Note that for Sugeno FISs, the hedge and not flag are handled by ## adjusting the height of the singletons for each (rule, output) pair. ## ## Because eval_rules_sugeno 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: eval_rules_sugeno.m ## Last-Modified: 20 Aug 2012 function rule_output = eval_rules_sugeno (fis, firing_strength, ... user_input) num_rules = columns (fis.rule); ## num_rules == Q (above) num_outputs = columns (fis.output); ## num_outputs == L ## Initialize output matrix to prevent inefficient resizing. rule_output = zeros (2, num_rules * num_outputs); ## Compute the (location, height) of the singleton output by each ## (rule, output) pair: ## 1. The height is given by the firing strength of the rule, and ## by the hedge and the not flag for the (rule, output) pair. ## 2. If the consequent membership function is constant, then the ## membership function's parameter gives the location of the ## singleton. If the consequent membership function is linear, ## then the location is the inner product of the the membership ## function's parameters and the vector formed by appending a 1 ## to the user input vector. for i = 1 : num_rules rule = fis.rule(i); rule_firing_strength = firing_strength(i); if (rule_firing_strength != 0) for j = 1 : num_outputs ## Compute the singleton height for this (rule, output) pair. ## Note that for Sugeno FISs, the hedge and not flag are handled ## by adjusting the height of the singletons for each ## (rule, output) pair. [mf_index hedge not_flag] = ... get_mf_index_and_hedge (rule.consequent(j)); height = rule_firing_strength; if (hedge != 0) height = height ^ (1 / hedge); endif if (not_flag) height = 1 - height; endif ## Compute the singleton location for this (rule, output) pair. if (mf_index != 0) mf = fis.output(j).mf(mf_index); switch (mf.type) case 'constant' location = mf.params; case 'linear' location = mf.params * [user_input 1]'; otherwise location = str2func (mf.type) (mf.params, user_input); endswitch ## Store result in column of rule_output corresponding ## to the (rule, output) pair. rule_output(1, (j - 1) * num_rules + i) = location; rule_output(2, (j - 1) * num_rules + i) = height; endif endfor endif endfor endfunction fuzzy-logic-toolkit/inst/private/is_grid_spec.m0000664000175000017500000000272112354647032021234 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_grid_spec (@var{x}) ## ## Return 1 if @var{x} is an integer or vector of two integers, each >= 2, ## and return 0 otherwise. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_grid_spec.m ## Last-Modified: 20 Aug 2012 function y = is_grid_spec (x, fis) if (!(isvector (x) && (length (x) <= 2))) y = 0; else y = 1; for next_x = x if (!(is_int (next_x) && next_x >= 2)) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/update_cluster_prototypes.m0000664000175000017500000000404712354647032024140 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{V} =} update_cluster_prototypes (@var{Mu_m}, @var{X}, @var{k}) ## ## Update the cluster centers to correspond to the given membership ## function values. ## ## @seealso{fcm, gustafson_kessel, init_cluster_prototypes, update_cluster_membership, compute_cluster_obj_fcn, compute_cluster_convergence} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: update_cluster_prototypes.m ## Last-Modified: 2 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.5 in ## Fuzzy Logic: Intelligence, Control and Information, by ## J. Yen and R. Langari, Prentice Hall, 1999, page 380 ## (International Edition). ##---------------------------------------------------------------------- function V = update_cluster_prototypes (Mu_m, X, k) V = Mu_m * X; sum_Mu_m = sum (Mu_m'); if (prod (sum_Mu_m) == 0) error ("division by 0 in function update_cluster_prototypes\n"); endif for i = 1 : k V(i, :) /= sum_Mu_m(i); endfor endfunction fuzzy-logic-toolkit/inst/private/eval_rules_mamdani.m0000664000175000017500000001131312354647032022426 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{rule_output} =} eval_rules_mamdani (@var{fis}, @var{firing_strength}, @var{num_points}) ## ## @noindent ## Return the fuzzy output for each (rule, FIS output) pair ## for a Mamdani-type FIS (an FIS that does not have constant or linear ## output membership functions). ## ## The firing strength of each rule is given by a row vector of length Q, where ## Q is the number of rules in the FIS: ## @example ## @group ## rule_1 rule_2 ... rule_Q ## [firing_strength(1) firing_strength(2) ... firing_strength(Q)] ## @end group ## @end example ## ## The implication method and fuzzy consequent for each rule are given by: ## @example ## @group ## fis.impMethod ## fis.rule(i).consequent for i = 1..Q ## @end group ## @end example ## ## The return value, @var{rule_output}, is a @var{num_points} x (Q * M) ## matrix, where Q is the number of rules and M is the number of FIS output ## variables. Each column of this matrix gives the y-values of the fuzzy ## output for a single (rule, FIS output) pair. ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## Because eval_rules_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: eval_rules_mamdani.m ## Last-Modified: 20 Aug 2012 function rule_output = eval_rules_mamdani (fis, firing_strength, ... num_points) num_rules = columns (fis.rule); ## num_rules == Q (above) num_outputs = columns (fis.output); ## num_outputs == L ## Initialize output matrix to prevent inefficient resizing. rule_output = zeros (num_points, num_rules*num_outputs); ## Compute the fuzzy output for each (rule, output) pair: ## 1. Apply the FIS implication method to find the fuzzy outputs ## for the current (rule, output) pair. ## 2. Store the result as a column in the rule_output matrix. for i = 1 : num_rules rule = fis.rule(i); rule_matching_degree = firing_strength(i); if (rule_matching_degree != 0) for j = 1 : num_outputs ## Compute the fuzzy output for this (rule, output) pair. [mf_index hedge not_flag] = ... get_mf_index_and_hedge (rule.consequent(j)); if (mf_index != 0) ## First, get the fuzzy output, adjusting for the hedge and ## not_flag, but not for the rule matching degree. range = fis.output(j).range; mf = fis.output(j).mf(mf_index); x = linspace (range(1), range(2), num_points); fuzzy_out = evalmf (x, mf.params, mf.type, hedge, not_flag); ## Adjust the fuzzy output for the rule matching degree. switch (fis.impMethod) case 'min' fuzzy_out = min (rule_matching_degree, fuzzy_out); case 'prod' fuzzy_out *= rule_matching_degree; otherwise fuzzy_out = str2func (fis.impMethod) ... (rule_matching_degree, fuzzy_out); endswitch ## Store result in column of rule_output corresponding ## to the (rule, output) pair. rule_output(:, (j - 1) * num_rules + i) = fuzzy_out'; endif endfor endif endfor endfunction fuzzy-logic-toolkit/inst/private/is_int.m0000664000175000017500000000324312354647032020067 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_int (@var{x}) ## ## Return 1 if @var{x} is an integer-valued real scalar, and return 0 otherwise. ## ## is_int is a private function that localizes the test for integers. ## In Octave, integer constants such as 1 are not represented by ints ## internally: isinteger(1) returns 0. ## ## Examples: ## @example ## @group ## is_int(6) ==> 1 ## is_int(6.2) ==> 0 ## is_int(ones(2)) ==> 0 ## is_int(6 + 0i) ==> 1 ## is_int(0) ==> 1 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_int.m ## Last-Modified: 20 Aug 2012 function y = is_int (x) y = isscalar (x) && isreal (x) && (fix (x) == x); endfunction fuzzy-logic-toolkit/inst/private/update_cluster_membership.m0000664000175000017500000000516512354647032024045 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{Mu} =} update_cluster_membership (@var{V}, @var{X}, @var{m}, @var{k}, @var{n}, @var{sqr_dist}) ## ## Compute Mu for each (cluster center, input point) pair. ## ## @seealso{fcm, gustafson_kessel, init_cluster_prototypes, update_cluster_prototypes, compute_cluster_obj_fcn, compute_cluster_convergence} ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: update_cluster_membership.m ## Last-Modified: 2 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.4 in ## Fuzzy Logic: Intelligence, Control and Information, by ## J. Yen and R. Langari, Prentice Hall, 1999, page 380 ## (International Edition) and Step 3 of Algorithm 4.1 in ## Fuzzy and Neural Control, by Robert Babuska, November 2009, ## p. 63. ##---------------------------------------------------------------------- function Mu = update_cluster_membership (V, X, m, k, n, sqr_dist) Mu = zeros (k, n); if (min (min (sqr_dist)) > 0) exponent = 1.0 / (m - 1); for i = 1 : k for j = 1 : n summation = 0.0; for l = 1 : k summation += (sqr_dist(i, j) / sqr_dist(l, j))^exponent; endfor if (summation != 0) Mu(i, j) = 1.0 / summation; else error ("division by 0 in update_cluster_membership'\n"); endif endfor endfor else num_zeros = 0; for i = 1 : k for j = 1 : n if (sqr_dist(i, j) == 0) num_zeros++; Mu(i, j) = 1.0; endif endfor endfor Mu = Mu / num_zeros; endif endfunction fuzzy-logic-toolkit/inst/private/is_mf_index.m0000664000175000017500000000401612354647032021065 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_mf_index (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf_index}) ## ## If @var{in_or_out} == 'input', return 1 if @var{mf_index} is a valid ## membership function index for the input variable with index @var{var_index}, ## and return 0 otherwise. ## ## If @var{in_or_out} == 'output', return 1 if @var{mf_index} is a valid ## membership function index for the output variable with index @var{var_index}, ## and return 0 otherwise. ## ## is_mf_index is a private function that localizes the test for valid FIS ## membership function indices. The arguments @var{fis}, @var{in_or_out}, and ## @var{var_index} are assumed to be valid. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_mf_index.m ## Last-Modified: 20 Aug 2012 function y = is_mf_index (fis, in_or_out, var_index, mf_index) y = is_int (mf_index) && (mf_index >= 1); if (strcmp (in_or_out, 'input')) y = y && (mf_index <= length (fis.input(var_index).mf)); else y = y && (mf_index <= length (fis.output(var_index).mf)); endif endfunction fuzzy-logic-toolkit/inst/private/is_output_index.m0000664000175000017500000000263012354647032022023 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_output_index (@var{x}, @var{fis}) ## ## Return 1 if @var{x} is a valid output index for the given FIS structure, and ## return 0 otherwise. The FIS structure @var{fis} is assumed to be valid. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_output_index.m ## Last-Modified: 20 Aug 2012 function y = is_output_index (x, fis) y = is_pos_int (x) && (x <= columns (fis.output)); endfunction fuzzy-logic-toolkit/inst/private/is_rule_index_list.m0000664000175000017500000000362112354647032022466 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_rule_index_list (@var{x}, @var{max_index}) ## ## Return 1 if @var{x} is a valid rule index or a vector of valid rule indices, ## and return 0 otherwise. ## ## Examples: ## @example ## @group ## is_rule_index_list(2, 5) ==> 1 ## is_rule_index_list([1 2], 5) ==> 1 ## is_rule_index_list([1, 2], 5) ==> 1 ## is_rule_index_list([1; 2], 5) ==> 1 ## is_rule_index_list(0, 0) ==> 0 ## is_rule_index_list([4 5], 2) ==> 0 ## is_rule_index_list([], 2) ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_rule_index_list.m ## Last-Modified: 20 Aug 2012 function y = is_rule_index_list (x, max_index) if (is_pos_int (x)) y = (x <= max_index); elseif (!isvector (x)) y = 0; else y = 1; for i = 1 : length (x) if (!(is_pos_int (x(i)) && (x(i) <= max_index))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/defuzzify_output_sugeno.m0000664000175000017500000000601012354647032023614 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{output} =} defuzzify_output_sugeno (@var{fis}, @var{aggregated_output}) ## ## @noindent ## Given the: ## @itemize @bullet ## @item @var{fis.defuzzMethod} ## the defuzzification method for the given @var{fis} ## @item @var{aggregated_output} ## a vector of structures containing the aggregated output for each FIS output variable ## @end itemize ## ## @noindent ## Return: ## @itemize @bullet ## @item @var{output} ## a vector of crisp output values ## @end itemize ## ## The @var{aggregated_output} is a vector of M structures, where M is the ## number of FIS output variables. Each structure contains an index i and a ## matrix of singletons that form the aggregated output for the ith FIS output. ## For each FIS output variable, the matrix of singletons is a 2 x L matrix ## where L is the number of distinct singleton locations in the fuzzy output ## for that FIS output variable. The first row gives the (distinct) locations, ## and the second gives the (non-zero) heights: ## ## @example ## @group ## singleton_1 singleton_2 ... singleton_L ## location [ ] ## height [ ] ## @end group ## @end example ## ## The crisp @var{output} values are computed from the corresponding fuzzy ## values using the FIS defuzzification method. The @var{output} ## vector has the form: ## ## @example ## output: [output_1 output_2 ... output_M] ## @end example ## ## Because defuzzify_output_sugeno 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: defuzzify_output_sugeno.m ## Last-Modified: 20 Aug 2012 function output = defuzzify_output_sugeno (fis, aggregated_output) num_outputs = columns (fis.output); output = zeros (1, num_outputs); for i = 1 : num_outputs next_agg_output = aggregated_output(i).aggregated_output; x = next_agg_output(1, :); y = next_agg_output(2, :); output(i) = defuzz (x, y, fis.defuzzMethod); endfor endfunction fuzzy-logic-toolkit/inst/private/eval_firing_strength.m0000664000175000017500000001204412354647032023004 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{firing_strength} =} eval_firing_strength (@var{fis}, @var{rule_input}) ## ## Return the firing strength for each FIS rule given a matrix of matching ## degrees for each (rule, rule_input) pair. ## ## The second argument (@var{rule_input}) gives the fuzzified input values to ## the FIS rules as a Q x N matrix: ## ## @example ## @group ## in_1 in_2 ... in_N ## rule_1 [mu_11 mu_12 ... mu_1N] ## rule_2 [mu_21 mu_22 ... mu_2N] ## [ ... ] ## rule_Q [mu_Q1 mu_Q2 ... mu_QN] ## @end group ## @end example ## ## @noindent ## where Q is the number of rules and N is the number of FIS input variables. ## ## For i = 1 .. Q, the fuzzy antecedent, connection, and weight for rule i ## are given by: ## @itemize @bullet ## @item ## @var{fis.rule(i).antecedent} ## @item ## @var{fis.rule(i).connection} ## @item ## @var{fis.rule(i).weight} ## @end itemize ## ## The output is a row vector of length Q. ## ## Because eval_firing_strength 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: eval_firing_strength.m ## Last-Modified: 20 Aug 2012 function firing_strength = eval_firing_strength (fis, rule_input) num_rules = columns (fis.rule); ## num_rules == Q (above) num_inputs = columns (fis.input); ## num_inputs == N ## Initialize output matrix to prevent inefficient resizing. firing_strength = zeros (1, num_rules); ## For each rule ## 1. Apply connection to find matching degree of the antecedent. ## 2. Multiply by weight of the rule to find degree of the rule. for i = 1 : num_rules rule = fis.rule(i); ## Collect mu values for all input variables in the antecedent. antecedent_mus = []; for j = 1 : num_inputs if (rule.antecedent(j) != 0) mu = rule_input(i, j); antecedent_mus = [antecedent_mus mu]; endif endfor ## Compute matching degree of the rule. if (rule.connection == 1) connect = fis.andMethod; else connect = fis.orMethod; endif switch (connect) case 'min' firing_strength(i) = rule.weight * ... min (antecedent_mus); case 'max' firing_strength(i) = rule.weight * ... max (antecedent_mus); case 'prod' firing_strength(i) = rule.weight * ... prod (antecedent_mus); case 'sum' firing_strength(i) = rule.weight * ... sum (antecedent_mus); case 'algebraic_product' firing_strength(i) = rule.weight * ... prod (antecedent_mus); case 'algebraic_sum' firing_strength(i) = rule.weight * ... algebraic_sum (antecedent_mus); case 'bounded_difference' firing_strength(i) = rule.weight * ... bounded_difference (antecedent_mus); case 'bounded_sum' firing_strength(i) = rule.weight * ... bounded_sum (antecedent_mus); case 'einstein_product' firing_strength(i) = rule.weight * ... einstein_product (antecedent_mus); case 'einstein_sum' firing_strength(i) = rule.weight * ... einstein_sum (antecedent_mus); case 'hamacher_product' firing_strength(i) = rule.weight * ... hamacher_product (antecedent_mus); case 'hamacher_sum' firing_strength(i) = rule.weight * ... hamacher_sum (antecedent_mus); case 'drastic_product' firing_strength(i) = rule.weight * ... drastic_product (antecedent_mus); case 'drastic_sum' firing_strength(i) = rule.weight * ... drastic_sum (antecedent_mus); otherwise firing_strength(i) = rule.weight * ... str2func (connect) (antecedent_mus); endswitch endfor endfunction fuzzy-logic-toolkit/inst/private/is_io_struct.m0000664000175000017500000000337612354647032021317 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_io_struct (@var{x}) ## ## Return 1 if the argument @var{x} is a valid input or output structure for an ## FIS (Fuzzy Inference System), and return 0 otherwise. ## ## is_io_struct is a private function that localizes the test for valid input ## and output structs. For efficiency, is_io_struct only determines if the ## argument @var{x} is a structure with the expected fields, and that these ## fields have the expected types. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_io_struct.m ## Last-Modified: 20 Aug 2012 function y = is_io_struct (x) y = isstruct (x) && ... isfield (x, 'name') && is_string (x.name) && ... isfield (x, 'range') && are_bounds (x.range) && ... isfield (x, 'mf') && is_mf_vector (x.mf); endfunction fuzzy-logic-toolkit/inst/private/is_real_matrix.m0000664000175000017500000000340512354647032021604 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_real_matrix (@var{x}) ## ## Return 1 if @var{x} is a non-empty matrix of real or integer-valued scalars, ## and return 0 otherwise. ## ## Examples: ## @example ## @group ## is_real_matrix(6) ==> 0 ## is_real_matrix([]) ==> 0 ## is_real_matrix([1 2; 3 4]) ==> 1 ## is_real_matrix([1 2 3]) ==> 1 ## is_real_matrix([i 2 3]) ==> 0 ## is_real_matrix("hello") ==> 0 ## @end group ## @end example ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_real_matrix.m ## Last-Modified: 20 Aug 2012 function y = is_real_matrix (x) if (!ismatrix (x)) y = 0; else y = 1; for i = 1 : numel (x) if (!(isnumeric (x(i)) && isscalar (x(i)) && isreal (x(i)))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/is_io_vector.m0000664000175000017500000000313012354647032021261 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_io_vector (@var{x}) ## ## Return 1 if @var{x} is a vector of FIS input/output variable structures, ## and return 0 otherwise. ## ## is_io_vector is a private function that localizes the test for valid FIS ## structure members 'input' and 'output'. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_io_vector.m ## Last-Modified: 20 Aug 2012 function y = is_io_vector (x) y = 1; if (isequal(x, [])) y = 1; elseif (!isvector(x)) y = 0; else y = 1; for i = 1 : length (x) if (!is_io_struct (x(i))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/is_rule_vector.m0000664000175000017500000000306112354647032021624 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_rule_vector (@var{x}) ## ## Return 1 if @var{x} is a vector of FIS rule structures, and return 0 ## otherwise. ## ## is_rule_vector is a private function that localizes the test for valid FIS ## 'rule' members. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_rule_vector.m ## Last-Modified: 20 Aug 2012 function y = is_rule_vector (x) if (isequal(x, [])) y = 1; elseif (!isvector (x)) y = 0; else y = 1; for i = 1 : length (x) if (!is_rule_struct (x(i))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/are_mf_params.m0000664000175000017500000001464112354647032021402 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} are_mf_params (@var{type}, @var{params}) ## ## Return 0 if @var{type} is a built-in membership function and @var{params} ## are not valid parameters for that type, and return 1 otherwise. ## ## are_mf_params is a private function that localizes the test for validity of ## membership function parameters. Note that for a custom membership function, ## this function always returns 1. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: are_mf_params.m ## Last-Modified: 20 Aug 2012 function y = are_mf_params (type, params) switch (type) case 'constant' y = real_vector (params); case 'dsigmf' y = four_reals (params); case 'gauss2mf' y = four_reals (params); case 'gaussmf' y = two_reals (params); case 'gbellmf' y = gbellmf_params (params); case 'linear' y = real_vector (params); case 'pimf' y = pimf_params (params); case 'psigmf' y = four_reals (params); case 'sigmf' y = two_reals (params); case 'smf' y = smf_params (params); case 'trapmf' y = trapmf_params (params); case 'trimf' y = trimf_params (params); case 'zmf' y = zmf_params (params); otherwise y = 1; endswitch endfunction ##---------------------------------------------------------------------- ## Usage: y = real_vector (params) ## ## Return 1 if params is a vector of real numbers, and ## return 0 otherwise. ##---------------------------------------------------------------------- function y = real_vector (params) y = isvector (params) && isreal (params); endfunction ##---------------------------------------------------------------------- ## Usage: y = two_reals (params) ## ## Return 1 if params is a vector of 2 real numbers, and ## return 0 otherwise. ##---------------------------------------------------------------------- function y = two_reals (params) y = isvector (params) && isreal (params) && (length (params) == 2); endfunction ##---------------------------------------------------------------------- ## Usage: y = three_reals (params) ## ## Return 1 if params is a vector of 3 real numbers, and ## return 0 otherwise. ##---------------------------------------------------------------------- function y = three_reals (params) y = isvector (params) && isreal (params) && (length (params) == 3); endfunction ##---------------------------------------------------------------------- ## Usage: y = four_reals (params) ## ## Return 1 if params is a vector of 4 real numbers, and ## return 0 otherwise. ##---------------------------------------------------------------------- function y = four_reals (params) y = isvector (params) && isreal (params) && (length (params) == 4); endfunction ##---------------------------------------------------------------------- ## Usage: y = gbellmf_params (params) ## y = gbellmf_params ([a b c]) ## ## Return 1 if params is a vector of 3 real numbers, [a b c], with ## a != 0 and integral-valued b, and return 0 otherwise. ##---------------------------------------------------------------------- function y = gbellmf_params (params) y = three_reals (params) && (params(1) != 0) && is_int (params(2)); endfunction ##---------------------------------------------------------------------- ## Usage: y = pimf_params (params) ## y = pimf_params ([a b c d]) ## ## Return 1 if params is a vector of 4 real numbers, [a b c d], with ## a < b <= c < d, and return 0 otherwise. ##---------------------------------------------------------------------- function y = pimf_params (params) y = four_reals (params) && ... (params(1) < params(2)) && ... (params(2) <= params(3)) && ... (params(3) < params(4)); endfunction ##---------------------------------------------------------------------- ## Usage: y = smf_params (params) ## y = smf_params ([a b]) ## ## Return 1 if params is a vector of 2 real numbers, [a b], with a < b, ## and return 0 otherwise. ##---------------------------------------------------------------------- function y = smf_params (params) y = two_reals (params) && (params(1) < params(2)); endfunction ##---------------------------------------------------------------------- ## Usage: y = trapmf_params (params) ## y = trapmf_params ([a b c d]) ## ## Return 1 if params is a vector of 4 real numbers, [a b c d], with ## a < b <= c < d, and return 0 otherwise. ##---------------------------------------------------------------------- function y = trapmf_params (params) y = four_reals (params) && ... (params(1) < params(2)) && ... (params(2) <= params(3)) && ... (params(3) < params(4)); endfunction ##---------------------------------------------------------------------- ## Usage: y = trimf_params (params) ## y = trimf_params ([a b c]) ## ## Return 1 if params is a vector of 3 real numbers, [a b c], with ## a < b < c, and return 0 otherwise. ##---------------------------------------------------------------------- function y = trimf_params (params) y = three_reals (params) && ... (params(1) < params(2)) && ... (params(2) < params(3)); endfunction ##---------------------------------------------------------------------- ## Usage: y = zmf_params (params) ## y = zmf_params ([a b]) ## ## Return 1 if params is a vector of 2 real numbers, [a b], with a < b, ## and return 0 otherwise. ##---------------------------------------------------------------------- function y = zmf_params (params) y = two_reals (params) && (params(1) < params(2)); endfunction fuzzy-logic-toolkit/inst/private/aggregate_output_mamdani.m0000664000175000017500000000736112354647032023643 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fuzzy_output} =} aggregate_output_mamdani (@var{fis}, @var{rule_output}) ## ## @noindent ## 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 ## ## @noindent ## 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: ## ## @example ## @group ## Q cols Q cols Q cols ## --------------- --------------- --------------- ## out_1 ... out_1 out_2 ... out_2 ... out_M ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## 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: ## ## @example ## @group ## out_1 out_2 ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## 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: 20 Aug 2012 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 fuzzy-logic-toolkit/inst/private/is_string.m0000664000175000017500000000314312354647032020602 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_string (@var{x}) ## ## Return 1 if @var{x} is a character vector, and return 0 otherwise. ## ## is_string is a private function that localizes the test for valid Octave ## strings, which may need to be changed in the future. Octave 3.2.4 implements ## strings as character vectors. In subsequent versions of Octave, the internal ## implementation of strings may change, or a built-in Octave test 'isstring' ## may be implemented. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_string.m ## Last-Modified: 20 Aug 2012 function y = is_string (x) y = ischar (x) && isvector (x); endfunction fuzzy-logic-toolkit/inst/private/defuzzify_output_mamdani.m0000664000175000017500000000563312354647032023734 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{output} =} defuzzify_output_mamdani (@var{fis}, @var{fuzzy_output}) ## ## @noindent ## Given the: ## @itemize @bullet ## @item @var{fis.defuzzMethod} ## the defuzzification method for the given @var{fis} ## @item @var{fuzzy_output} ## a matrix of the aggregated output for each FIS output variable ## @end itemize ## ## @noindent ## Return: ## @itemize @bullet ## @item @var{output} ## a vector of crisp output values ## @end itemize ## ## @var{fuzzy_output} is a @var{num_points} x M matrix, where @var{num_points} ## is the number of points over which fuzzy values are evaluated and M is the ## number of FIS output variables. Each ## column of @var{fuzzy_output} gives the y-values of the fuzzy output for a ## single FIS output variable, aggregated over all rules: ## ## @example ## @group ## out_1 out_2 ... out_M ## 1 [ ] ## 2 [ ] ## ... [ ] ## num_points [ ] ## @end group ## @end example ## ## The crisp @var{output} values are computed from the corresponding fuzzy ## values using the FIS defuzzification method. The @var{output} ## vector has the form: ## ## @example ## output: [output_1 output_2 ... output_M] ## @end example ## ## Because defuzzify_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: defuzzify_output_mamdani.m ## Last-Modified: 20 Aug 2012 function output = defuzzify_output_mamdani (fis, fuzzy_output) num_outputs = columns (fis.output); ## num_outputs == L (above) num_points = rows (fuzzy_output); output = zeros (1, num_outputs); for i = 1 : num_outputs range = fis.output(i).range; x = linspace (range(1), range(2), num_points); y = (fuzzy_output(:, i))'; output(i) = defuzz (x, y, fis.defuzzMethod); endfor endfunction fuzzy-logic-toolkit/inst/private/is_ref_input.m0000664000175000017500000000347712354647032021301 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_ref_input (@var{x}, @var{fis}, @var{graphed_inputs}) ## ## Return 1 if @var{x} is a vector of constants for the FIS structure inputs ## that are not included in the list of inputs, and return 0 otherwise. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_ref_input.m ## Last-Modified: 20 Aug 2012 function y = is_ref_input (x, fis, graphed_inputs) y = 1; num_fis_inputs = columns (fis.input); num_graphed_inputs = length (graphed_inputs); if (!(is_row_vector (x) && (length (x) == num_fis_inputs))) y = 0; else for i = 1 : num_fis_inputs range = fis.input(i).range; if (!(isreal (x(i)) && isscalar (x(i)))) y = 0; elseif (!ismember (i, graphed_inputs) && ... (x(i) < range(1) || x(i) > range(2))) y = 0; endif endfor endif endfunction fuzzy-logic-toolkit/inst/private/is_rule_struct.m0000664000175000017500000000333612354647032021653 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} is_rule_struct (@var{x}) ## ## Return 1 if the argument @var{x} is a valid FIS (Fuzzy Inference System) rule ## structure, and return 0 otherwise. ## ## is_rule_struct is a private function that localizes the test for valid FIS ## rule structs. For efficiency, is_rule_struct only determines if the argument ## @var{x} is a structure with the expected fields, but the types of the fields ## are not verified. ## ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy private parameter-test ## Directory: fuzzy-logic-toolkit/inst/private/ ## Filename: is_rule_struct.m ## Last-Modified: 20 Aug 2012 function y = is_rule_struct (x) y = isstruct (x) && ... isfield (x, 'antecedent') && ... isfield (x, 'consequent') && ... isfield (x, 'weight') && ... isfield (x, 'connection'); endfunction fuzzy-logic-toolkit/inst/readfis.m0000664000175000017500000005246512354647032016557 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} readfis () ## @deftypefnx {Function File} {@var{fis} =} readfis (@var{filename}) ## ## Read the information in an FIS file, and using this information, create and ## return an FIS structure. If called without any arguments or with an empty ## string as an argument, present the user with a file dialog GUI. If called ## with a @var{filename} that does not end with '.fis', append '.fis' to the ## @var{filename}. The @var{filename} is expected to be a string. ## ## Three examples of the input file format: ## @itemize @bullet ## @item ## heart_disease_risk.fis ## @item ## mamdani_tip_calculator.fis ## @item ## sugeno_tip_calculator.fis ## @end itemize ## ## Six example scripts that use readfis: ## @itemize @bullet ## @item ## cubic_approx_demo.m ## @item ## heart_disease_demo_2.m ## @item ## investment_portfolio_demo.m ## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m ## @item ## sugeno_tip_demo.m ## @end itemize ## ## @seealso{writefis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: readfis.m ## Last-Modified: 14 Jun 2014 function fis = readfis (filename = '') ## If readfis was not called with 0 or 1 arguments, or if the argument ## is not a string, print an error message and halt. if (nargin > 1) puts ("Type 'help readfis' for more information.\n"); error ("readfis requires 0 or 1 arguments\n"); elseif ((nargin == 1) && !is_string (filename)) puts ("Type 'help readfis' for more information.\n"); error ("readfis's argument must be a string\n"); endif ## Open the input file. fid = open_input_file (filename); ## Read the [System], [Input], [Output], and [Rules] ## sections of the input file. [fis, num_inputs, num_outputs, num_rules, line_num] = ... init_fis_struct (fid); [fis, line_num] = read_fis_inputs (fid, fis, num_inputs, line_num); [fis, line_num] = read_fis_outputs (fid, fis, num_outputs, line_num); fis = read_rules (fid, fis, num_inputs, num_outputs, num_rules, ... line_num); ## Close the input file. fclose (fid); endfunction ##---------------------------------------------------------------------- ## Function: open_input_file ## Purpose: Open the input file specified by the filename. If the ## filename does not end with ".fis", then append ".fis" to ## the filename before opening. Return an fid if successful. ## Otherwise, print an error message and halt. ##---------------------------------------------------------------------- function fid = open_input_file (filename) ##-------------------------------------------------------------------- ## If the filename is not empty, and if the last four characters of ## the filename are not '.fis', append '.fis' to the filename. If the ## filename is empty, use a dialog to select the input file. ##-------------------------------------------------------------------- fn_len = length (filename); if (fn_len == 0) dialog = 1; else dialog = 0; endif if (((fn_len >= 4) && ... !strcmp(".fis",filename(fn_len-3:fn_len))) || ... ((fn_len > 0) && (fn_len < 4))) filename = [filename ".fis"]; elseif (dialog) system_command = sprintf ("zenity --file-selection; echo $file", ... filename); [dialog_error, filename] = system (file = system_command); if (dialog_error) puts ("Type 'help readfis' for more information.\n"); error ("error selecting file using dialog\n"); endif filename = strtrim (filename); endif ##-------------------------------------------------------------------- ## Open input file. ##-------------------------------------------------------------------- [fid, msg] = fopen (filename, "r"); if (fid == -1) if (dialog) system ('zenity --error --text "Error opening input file."'); endif puts ("Type 'help readfis' for more information.\n"); printf ("Error opening input file: %s\n", msg); error ("error opening input file\n"); endif endfunction ##---------------------------------------------------------------------- ## Function: init_fis_struct ## Purpose: Read the [System] section of the input file. Using the ## strings read from the input file, create a new FIS. If an ## error in the format of the input file is found, print an ## error message and halt. ##---------------------------------------------------------------------- function [fis, num_inputs, num_outputs, num_rules, line_num] = ... init_fis_struct (fid) ##-------------------------------------------------------------------- ## Read the [System] section. ##-------------------------------------------------------------------- line_num = 1; [line, line_num] = get_line (fid, line_num); [line, line_num] = get_line (fid, line_num); [fis_name, count] = sscanf (line, "Name = '%s", "C"); if (count != 1) error ("line %d: name of FIS expected\n", --line_num); endif fis_name = trim_last_char (fis_name); [line, line_num] = get_line (fid, line_num); [fis_type, count] = sscanf (line, "Type = '%s", "C"); if (count != 1) error ("line %d: type of FIS expected\n", --line_num); endif fis_type = trim_last_char (fis_type); [line, line_num] = get_line (fid, line_num); [fis_version, count] = sscanf (line, "Version = %f", "C"); if (count != 1) error ("line %d: version of FIS expected\n", --line_num); endif [line, line_num] = get_line (fid, line_num); [num_inputs, count] = sscanf (line, "NumInputs = %d", "C"); if (count != 1) error ("line %d: number of inputs expected\n", --line_num); endif [line, line_num] = get_line (fid, line_num); [num_outputs, count] = sscanf (line, "NumOutputs = %d", "C"); if (count != 1) error ("line %d: number of oututs expected\n", --line_num); endif [line, line_num] = get_line (fid, line_num); [num_rules, count] = sscanf (line, "NumRules = %d", "C"); if (count != 1) error ("line %d: number of rules expected\n", --line_num); endif [line, line_num] = get_line (fid, line_num); [and_method, count] = sscanf (line, "AndMethod = '%s", "C"); if (count != 1) error ("line %d: and method expected\n", --line_num); endif and_method = trim_last_char (and_method); [line, line_num] = get_line (fid, line_num); [or_method, count] = sscanf (line, "OrMethod = '%s", "C"); if (count != 1) error ("line %d: or method expected\n", --line_num); endif or_method = trim_last_char (or_method); [line, line_num] = get_line (fid, line_num); [imp_method, count] = sscanf (line, "ImpMethod = '%s", "C"); if (count != 1) error ("line %d: implication method expected\n", --line_num); endif imp_method = trim_last_char (imp_method); [line, line_num] = get_line (fid, line_num); [agg_method, count] = sscanf (line, "AggMethod = '%s", "C"); if (count != 1) error ("line %d: aggregation method expected\n", --line_num); endif agg_method = trim_last_char (agg_method); [line, line_num] = get_line (fid, line_num); [defuzz_method, count] = sscanf (line, "DefuzzMethod = '%s", "C"); if (count != 1) error ("line %d: defuzzification method expected\n", --line_num); endif defuzz_method = trim_last_char (defuzz_method); ##-------------------------------------------------------------------- ## Create a new FIS structure using the strings read from the ## input file. ##-------------------------------------------------------------------- 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 ##---------------------------------------------------------------------- ## Function: read_fis_inputs ## Purpose: For each FIS input, read the [Input] section from ## file. Add each new input and its membership functions to ## the FIS structure. ##---------------------------------------------------------------------- function [fis, line_num] = read_fis_inputs (fid, fis, num_inputs, ... line_num) for i = 1 : num_inputs [next_fis_input, num_mfs, line_num] = ... get_next_fis_io (fid, line_num, i, 'input'); if (i == 1) fis.input = next_fis_input; else fis.input = [fis.input, next_fis_input]; endif ##------------------------------------------------------------------ ## Read membership function info for the current FIS input from ## file. Add each new membership function to the FIS struct. ##------------------------------------------------------------------ for j = 1 : num_mfs [next_mf, line_num] = get_next_mf (fid, line_num, i, j, 'input'); if (j == 1) fis.input(i).mf = next_mf; else fis.input(i).mf = [fis.input(i).mf, next_mf]; endif endfor endfor endfunction ##---------------------------------------------------------------------- ## Function: read_fis_outputs ## Purpose: For each FIS output, read the [Output] section from ## file. Add each new output and its membership functions to ## the FIS structure. ##---------------------------------------------------------------------- function [fis, line_num] = read_fis_outputs (fid, fis, num_outputs, ... line_num) for i = 1 : num_outputs [next_fis_output, num_mfs, line_num] = ... get_next_fis_io (fid, line_num, i, 'output'); if (i == 1) fis.output = next_fis_output; else fis.output = [fis.output, next_fis_output]; endif ##------------------------------------------------------------------ ## Read membership function info for the current FIS output from ## file. Add each new membership function to the FIS struct. ##------------------------------------------------------------------ for j = 1 : num_mfs [next_mf, line_num] = get_next_mf (fid, line_num, i, j, 'output'); if (j == 1) fis.output(i).mf = next_mf; else fis.output(i).mf = [fis.output(i).mf, next_mf]; endif endfor endfor endfunction ##---------------------------------------------------------------------- ## Function: read_rules ## Purpose: Read the [Rules] section from file, and add the rules to ## the FIS. ##---------------------------------------------------------------------- function fis = read_rules (fid, fis, num_inputs, num_outputs, ... num_rules, line_num) [line, line_num] = get_line (fid, line_num); for i = 1 : num_rules [next_rule, line_num] = ... get_next_rule (fid, line_num, num_inputs, num_outputs); if (i == 1) fis.rule = next_rule; else fis.rule = [fis.rule, next_rule]; endif endfor endfunction ##---------------------------------------------------------------------- ## Function: get_next_fis_io ## Purpose: Read the next [Input] or [Output] section of the ## input file. Using the info read from the input file, create ## a new FIS input or output structure. If an error in the ## format of the input file is found, print an error message ## and halt. ##---------------------------------------------------------------------- function [next_fis_io, num_mfs, line_num] = ... get_next_fis_io (fid, line_num, i, in_or_out) ##-------------------------------------------------------------------- ## Read [Input] or [Output] section from file. ##-------------------------------------------------------------------- [line, line_num] = get_line (fid, line_num); if (strcmp ('input', in_or_out)) [io_index, count] = sscanf (line, "[Input %d", "C"); else [io_index, count] = sscanf (line, "[Output %d", "C"); endif if ((count != 1) || (io_index != i)) error ("line %d: next input or output expected\n", --line_num); endif [line, line_num] = get_line (fid, line_num); [var_name, count] = sscanf (line, "Name = '%s", "C"); if (count != 1) error ("line %d: name of %s %d expected\n", --line_num, ... in_or_out, i); endif var_name = trim_last_char (var_name); [line, line_num] = get_line (fid, line_num); [range_low, range_high, count] = sscanf (line, ... "Range = [ %f %f ]", "C"); if ((count != 2) || (range_low > range_high)) error ("line %d: range for %s %d expected\n", --line_num, ... in_or_out, i); endif [line, line_num] = get_line (fid, line_num); [num_mfs, count] = sscanf (line, "NumMFs = %d", "C"); if (count != 1) error ("line %d: number of MFs for %s %d expected\n", ... --line_num, in_or_out, i); endif ##-------------------------------------------------------------------- ## Create a new FIS input or output structure. ##-------------------------------------------------------------------- next_fis_io = struct ('name', var_name, 'range', ... [range_low, range_high], 'mf', []); endfunction ##---------------------------------------------------------------------- ## Function: get_next_mf ## Purpose: Read information specifying the jth membership function for ## Input or Output (if in_or_out is 'input' or 'output', ## respectively) from the input file. Create a new membership ## function structure using the info read. If an error in the ## format of the input file is found, print an error message ## and halt. ##---------------------------------------------------------------------- function [next_mf, line_num] = get_next_mf (fid, line_num, i, j, ... in_or_out) ##-------------------------------------------------------------------- ## Read membership function info for the new FIS input or output ## from file. ##-------------------------------------------------------------------- [line, line_num] = get_line (fid, line_num); if (compare_versions (OCTAVE_VERSION(), "3.8.0", ">=")) line_vec = discard_empty_strings (ostrsplit (line, "=':,[] \t", true)); else line_vec = discard_empty_strings (strsplit (line, "=':,[] \t", true)); endif mf_index = sscanf (line_vec{1}, "MF %d", "C"); mf_name = line_vec{2}; mf_type = line_vec{3}; if (mf_index != j) error ("line %d: next MF for %s %d expected\n", --line_num, in_or_out, i); endif j = 1; for i = 4 : length (line_vec) [mf_params(j++), count] = sscanf (line_vec{i}, "%f", "C"); if (count != 1) error ("line %d: %s %d MF%d params expected\n", --line_num, in_or_out, i, j); endif endfor ##-------------------------------------------------------------------- ## Create a new membership function structure. ##-------------------------------------------------------------------- next_mf = struct ('name', mf_name, 'type', mf_type, 'params', ... mf_params); endfunction ##---------------------------------------------------------------------- ## Function: get_next_rule ## Purpose: Read the next rule from the input file. Create a struct for ## the new rule. If an error in the format of the input file ## is found, print an error message and halt. ##---------------------------------------------------------------------- function [next_rule, line_num] = get_next_rule (fid, line_num, ... num_inputs, num_outputs) [line, line_num] = get_line (fid, line_num); if (compare_versions (OCTAVE_VERSION(), "3.8.0", ">=")) line_vec = ostrsplit (line, ",():", true); else line_vec = strsplit (line, ",():", true); endif ##-------------------------------------------------------------------- ## Read antecedent. ##-------------------------------------------------------------------- format_str = ""; for j = 1 : num_inputs format_str = [format_str " %f"]; endfor [antecedent, count] = sscanf (line_vec{1}, format_str, ... [1, num_inputs]); if (length (antecedent) != num_inputs) error ("Line %d: Rule antecedent expected.\n", line_num); endif ##-------------------------------------------------------------------- ## Read consequent. ##-------------------------------------------------------------------- format_str = ""; for j = 1 : num_outputs format_str = [format_str " %f"]; endfor [consequent, count] = sscanf (line_vec{2}, format_str, ... [1, num_outputs]); if (length (consequent) != num_outputs) error ("Line %d: Rule consequent expected.\n", line_num); endif ##-------------------------------------------------------------------- ## Read weight. ##-------------------------------------------------------------------- [weight, count] = sscanf (line_vec{3}, "%f", "C"); if (count != 1) error ("Line %d: Rule weight expected.\n", line_num); endif ##-------------------------------------------------------------------- ## Read connection. ##-------------------------------------------------------------------- [connection, count] = sscanf (line_vec{5}, "%d", "C"); if ((count != 1) || (connection < 1) || (connection > 2)) error ("Line %d: Antecedent connection expected.\n", line_num); endif ##-------------------------------------------------------------------- ## Create a new rule struct. ##-------------------------------------------------------------------- next_rule = struct ('antecedent', antecedent, ... 'consequent', consequent, ... 'weight', weight, ... 'connection', connection); endfunction ##---------------------------------------------------------------------- ## Function: get_line ## Purpose: Read the next line of the input file (without the newline) ## into line. Print an error message and halt on eof. ##---------------------------------------------------------------------- function [line, line_num] = get_line (fid, line_num) do line = fgetl (fid); if (isequal (line, -1)) error ("unexpected end of file at line %d", line_num); endif line = trim_leading_whitespace (line); line_num++; until (!comment_or_empty (line)) endfunction ##---------------------------------------------------------------------- ## Function: discard_empty_strings ## Purpose: Return a copy of the input cell array without any ## empty string elements. ##---------------------------------------------------------------------- function ret_val = discard_empty_strings (cell_array) ret_val = {}; j = 1; for i = 1 : length (cell_array) if (!strcmp (cell_array{i}, "")) ret_val{j++} = cell_array{i}; endif endfor endfunction ##---------------------------------------------------------------------- ## Function: trim_last_char ## Purpose: Return a copy of the input string without its final ## character. ##---------------------------------------------------------------------- function str = trim_last_char (str) str = str(1 : length (str) - 1); endfunction ##---------------------------------------------------------------------- ## Function: trim_leading_whitespace ## Purpose: Return a copy of the input string without leading ## whitespace. ##---------------------------------------------------------------------- function str = trim_leading_whitespace (str) str_length = length (str); i = 1; while (i <= str_length && ... (str (i) == ' ' || str (i) == '\t' || str (i) == '\n' || ... str (i) == '\f' || str (i) == '\r' || str (i) == '\v')) i++; endwhile if (i > str_length) str = ""; else str = str (i : str_length); endif endfunction ##---------------------------------------------------------------------- ## Function: comment_or_empty ## Purpose: Return true if the line is a comment (that is, it begins ## with '#' or '%') or an empty line, and return false ## otherwise. It is assumed that leading whitespace has been ## removed from the input line. ##---------------------------------------------------------------------- function ret_val = comment_or_empty (line) ret_val = (length (line) == 0) || (line (1) == '#') || ... (line (1) == '%'); endfunction fuzzy-logic-toolkit/inst/psigmf.m0000664000175000017500000000776612354647032016433 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} psigmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} psigmf (@var{[x1 x2 ... xn]}, @var{[a1 c1 a2 c2]}) ## ## For a given domain @var{x} and parameters @var{params} (or ## @var{[a1 c1 a2 c2]}), return the corresponding @var{y} values for the product ## of two sigmoidal membership functions. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{a1}, @var{c1}, @var{a2}, and @var{c2} must ## be real numbers. This membership function satisfies the equation: ## @example ## f(x) = (1/(1 + exp(-a1*(x - c1)))) * (1/(1 + exp(-a2*(x - c2)))) ## @end example ## ## @noindent ## The function is bounded above by 1 and below by 0. ## ## If @var{a1} is positive, @var{a2} is negative, and @var{c1} and @var{c2} are ## far enough apart with @var{c1} < @var{c2}, then: ## @itemize @w ## @item ## (a1)/4 ~ the rising slope at c1 ## @item ## c1 ~ the left inflection point ## @item ## (a2)/4 ~ the falling slope at c2 ## @item ## c2 ~ the right inflection point ## @end itemize ## ## @noindent ## and at each inflection point, the value of the function is about 0.5: ## @itemize @w ## @item ## f(c1) ~ f(c2) ~ 0.5. ## @end itemize ## ## @noindent ## (Here, the symbol ~ means "approximately equal".) ## ## @noindent ## To run the demonstration code, type @t{demo('psigmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership sigmoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: psigmf.m ## Last-Modified: 19 Aug 2012 function y = psigmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help psigmf' for more information.\n"); error ("psigmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help psigmf' for more information.\n"); error ("psigmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('psigmf', params)) puts ("Type 'help psigmf' for more information.\n"); error ("psigmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on ## the domain x. a1 = params(1); c1 = params(2); a2 = params(3); c2 = params(4); y_val = @(x_val) 1 / (1 + exp (-a1 * (x_val - c1))) * ... 1 / (1 + exp (-a2 * (x_val - c2))); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:100; %! params = [0.5 20 -0.3 60]; %! y1 = psigmf(x, params); %! params = [0.3 20 -0.2 60]; %! y2 = psigmf(x, params); %! params = [0.2 20 -0.1 60]; %! y3 = psigmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'psigmf demo'); %! plot(x, y1, 'r;params = [0.5 20 -0.3 60];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [0.3 20 -0.2 60];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [0.2 20 -0.1 60];', 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/drastic_product.m0000664000175000017500000000643112354647032020323 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} drastic_product (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} drastic_product (@var{x}, @var{y}) ## ## Return the drastic product of the input. ## The drastic product of two real scalars x and y is: ## @example ## @group ## min (x, y) if max (x, y) == 1 ## 0 otherwise ## @end group ## @end example ## ## For one vector argument, apply the drastic product to all of the elements ## of the vector. (The drastic product is associative.) For one ## two-dimensional matrix argument, return a vector of the drastic product ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise drastic product. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_sum, einstein_product, einstein_sum, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy drastic_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: drastic_product.m ## Last-Modified: 20 Aug 2012 function retval = drastic_product (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) if (max (x, y) == 1) retval = min (x, y); else retval = 0; endif endfunction function retval = vector_arg (x) if (isempty (x)) retval = 1; elseif (max (x) == 1) retval = min (x); else retval = 0; endif endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help drastic_product' for more information.\n"); error ("invalid arguments to function drastic_product\n"); endfunction fuzzy-logic-toolkit/inst/getfis.m0000664000175000017500000005010312354647032016406 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} getfis (@var{fis}) ## @deftypefnx {Function File} {@var{retval} =} getfis (@var{fis}, @var{property}) ## @deftypefnx {Function File} {@var{retval} =} getfis (@var{fis}, @var{in_or_out}, @var{var_index}) ## @deftypefnx {Function File} {@var{retval} =} getfis (@var{fis}, @var{in_or_out}, @var{var_index}, @var{var_property}) ## @deftypefnx {Function File} {@var{retval} =} getfis (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf}, @var{mf_index}) ## @deftypefnx {Function File} {@var{retval} =} getfis (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf}, @var{mf_index}, @var{mf_property}) ## ## Return or print the property (field) values of an FIS structure ## specified by the arguments. There are six forms of getfis: ## ## @table @asis ## @item # Arguments ## Action Taken ## @item 1 ## Print (some) properties of an FIS structure on standard output. ## Return the empty set. ## @item 2 ## Return a specified property of the FIS structure. The properties ## that may be specified are: name, type, version, numinputs, numoutputs, ## numinputmfs, numoutputmfs, numrules, andmethod, ormethod, ## impmethod, addmethod, defuzzmethod, inlabels, outlabels, ## inrange, outrange, inmfs, outmfs, inmflabels, outmflabels, ## inmftypes, outmftypes, inmfparams, outmfparams, and rulelist. ## @item 3 ## Print the properties of a specified input or output variable ## of the FIS structure. Return the empty set. ## @item 4 ## Return a specified property of an input or output variable. ## The properties that may be specified are: name, range, nummfs, ## and mflabels. ## @item 5 ## Print the properties of a specified membership function of the ## FIS structure. Return the empty set. ## @item 6 ## Return a specified property of a membership function. The ## properties that may be specified are: name, type, and params. ## @end table ## ## The types of the arguments are expected to be: ## @table @var ## @item fis ## an FIS structure ## @item property ## a string; one of: 'name', 'type', 'version', 'numinputs', ## 'numoutputs', 'numinputmfs', 'numoutputmfs', ## 'numrules', 'andmethod', 'ormethod', 'impmethod', ## 'addmethod', 'defuzzmethod' 'inlabels', 'outlabels', ## 'inrange', 'outrange', 'inmfs', 'outmfs', ## 'inmflabels', 'outmflabels', 'inmftypes', ## 'outmftypes', 'inmfparams', 'outmfparams', and ## 'rulelist' (case-insensitive) ## @item in_or_out ## either 'input' or 'output' (case-insensitive) ## @item var_index ## a valid integer index of an input or output FIS variable ## @item var_property ## a string; one of: 'name', 'range', 'nummfs', and 'mflabels' ## @item mf ## the string 'mf' ## @item mf_index ## a valid integer index of a membership function ## @item mf_property ## a string; one of 'name', 'type', or 'params' ## @end table ## ## @noindent ## Note that all of the strings representing properties above are case ## insensitive. ## ## @seealso{setfis, showfis} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: getfis.m ## Last-Modified: 20 Aug 2012 ##---------------------------------------------------------------------- function retval = getfis (fis, arg2 = 'dummy', arg3 = 'dummy', ... arg4 = 'dummy', arg5 = 'dummy', ... arg6 = 'dummy') switch (nargin) case 1 retval = getfis_one_arg (fis); case 2 retval = getfis_two_args (fis, arg2); case 3 retval = getfis_three_args (fis, arg2, arg3); case 4 retval = getfis_four_args (fis, arg2, arg3, arg4); case 5 retval = getfis_five_args (fis, arg2, arg3, arg4, arg5); case 6 retval = getfis_six_args (fis, arg2, arg3, arg4, arg5, ... arg6); otherwise puts ("Type 'help getfis' for more information.\n"); error ("getfis requires 1-6 arguments\n"); endswitch endfunction ##---------------------------------------------------------------------- ## Function: getfis_one_arg ## Purpose: Handle calls to getfis that have 1 argument. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_one_arg (fis) ## If the argument does not have the correct type, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); endif ## Print (some) properties of the FIS structure. Return the empty set. printf ("Name = %s\n", fis.name); printf ("Type = %s\n", fis.type); printf ("NumInputs = %d\n", columns(fis.input)); printf ("InLabels = \n"); for i = 1 : columns (fis.input) printf ("\t%s\n", fis.input(i).name); endfor printf ("NumOutputs = %d\n", columns(fis.output)); printf ("OutLabels = \n"); for i = 1 : columns (fis.output) printf ("\t%s\n", fis.output(i).name); endfor printf ("NumRules = %d\n", columns(fis.rule)); printf ("AndMethod = %s\n", fis.andMethod); printf ("OrMethod = %s\n", fis.orMethod); printf ("ImpMethod = %s\n", fis.impMethod); printf ("AggMethod = %s\n", fis.aggMethod); printf ("DefuzzMethod = %s\n", fis.defuzzMethod); retval = []; endfunction ##---------------------------------------------------------------------- ## Function: getfis_two_args ## Purpose: Handle calls to getfis that have 2 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_two_args (fis, arg2) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); elseif (!(is_string (arg2) && ismember (tolower (arg2), {'name', ... 'type', 'version', 'numinputs', 'numoutputs', ... 'numinputmfs', 'numoutputmfs', 'numrules', 'andmethod', ... 'ormethod', 'impmethod', 'aggmethod', 'defuzzmethod', ... 'inlabels', 'outlabels', 'inrange', 'outrange', 'inmfs', ... 'outmfs', 'inmflabels', 'outmflabels', 'inmftypes', ... 'outmftypes', 'inmfparams', 'outmfparams', 'rulelist'}))) puts ("Type 'help getfis' for more information.\n"); error ("unknown second argument to getfis\n"); endif ## Return the specified property of the FIS structure. switch (tolower (arg2)) case 'name' retval = fis.name; case 'type' retval = fis.type; case 'version' retval = fis.version; case 'numinputs' retval = columns (fis.input); case 'numoutputs' retval = columns (fis.output); case 'numrules' retval = columns(fis.rule); case 'andmethod' retval = fis.andMethod; case 'ormethod' retval = fis.orMethod; case 'impmethod' retval = fis.impMethod; case 'aggmethod' retval = fis.aggMethod; case 'defuzzmethod' retval = fis.defuzzMethod; case 'numinputmfs' retval = []; for i = 1 : columns (fis.input) if (i == 1) retval = columns(fis.input(i).mf); else retval = [retval columns(fis.input(i).mf)]; endif endfor case 'numoutputmfs' retval = []; for i = 1 : columns (fis.output) if (i == 1) retval = columns(fis.output(i).mf); else retval = [retval columns(fis.output(i).mf)]; endif endfor case 'inlabels' retval = []; for i = 1 : columns (fis.input) if (i == 1) retval = fis.input(i).name; else retval = [retval; fis.input(i).name]; endif endfor case 'outlabels' retval = []; for i = 1 : columns (fis.output) if (i == 1) retval = fis.output(i).name; else retval = [retval; fis.output(i).name]; endif endfor case 'inrange' retval = []; for i = 1 : columns (fis.input) if (i == 1) retval = fis.input(i).range; else retval = [retval; fis.input(i).range]; endif endfor case 'outrange' retval = []; for i = 1 : columns (fis.output) if (i == 1) retval = fis.output(i).range; else retval = [retval; fis.output(i).range]; endif endfor case 'inmfs' retval = []; for i = 1 : columns (fis.input) if (i == 1) retval = columns(fis.input(i).mf); else retval = [retval columns(fis.input(i).mf)]; endif endfor case 'outmfs' retval = []; for i = 1 : columns (fis.output) if (i == 1) retval = columns(fis.output(i).mf); else retval = [retval columns(fis.output(i).mf)]; endif endfor case 'inmflabels' retval = []; for i = 1 : columns (fis.input) for j = 1 : columns (fis.input(i).mf) if (i == 1 && y == 1) retval = fis.input(i).mf(j).name; else retval = [retval; fis.input(i).mf(j).name]; endif endfor endfor case 'outmflabels' retval = []; for i = 1 : columns (fis.output) for j = 1 : columns (fis.output(i).mf) if (i == 1 && y == 1) retval = fis.output(i).mf(j).name; else retval = [retval; fis.output(i).mf(j).name]; endif endfor endfor case 'inmftypes' retval = []; for i = 1 : columns (fis.input) for j = 1 : columns (fis.input(i).mf) if (i == 1 && y == 1) retval = fis.input(i).mf(j).type; else retval = [retval; fis.input(i).mf(j).type]; endif endfor endfor case 'outmftypes' retval = []; for i = 1 : columns (fis.output) for j = 1 : columns (fis.output(i).mf) if (i == 1 && y == 1) retval = fis.output(i).mf(j).type; else retval = [retval; fis.output(i).mf(j).type]; endif endfor endfor case 'inmfparams' ## Determine the dimensions of the matrix to return. max_len = 0; num_inputs = columns (fis.input); num_mfs = 0; for i = 1 : num_inputs num_var_i_mfs = columns (fis.input(i).mf); num_mfs += num_var_i_mfs; for j = 1 : num_var_i_mfs max_len = max (max_len, length (fis.input(i).mf(j).params)); endfor endfor ## Assemble the matrix of params to return. Pad with zeros. retval = zeros (num_mfs, max_len); for i = 1 : num_inputs for j = 1 : columns (fis.input(i).mf) next_row_index = (i - 1) * max_len + j; next_row = fis.input(i).mf(j).params; retval(next_row_index, 1 : length (next_row)) = next_row; endfor endfor case 'outmfparams' ## Determine the dimensions of the matrix to return. max_len = 0; num_outputs = columns (fis.output); num_mfs = 0; for i = 1 : num_outputs num_var_i_mfs = columns (fis.output(i).mf); num_mfs += num_var_i_mfs; for j = 1 : num_var_i_mfs max_len = max (max_len, length (fis.output(i).mf(j).params)); endfor endfor ## Assemble the matrix of params to return. Pad with zeros. retval = zeros (num_mfs, max_len); for i = 1 : num_outputs for j = 1 : columns (fis.output(i).mf) next_row_index = (i - 1) * max_len + j; next_row = fis.output(i).mf(j).params; retval(next_row_index, 1 : length (next_row)) = next_row; endfor endfor case 'rulelist' ## Determine the dimensions of the matrix to return. num_inputs = columns (fis.input); num_outputs = columns (fis.output); num_rules = columns (fis.rule); ## Assemble the matrix of rules to return. retval = zeros (num_rules, num_inputs + num_outputs + 2); for i = 1 : num_rules retval(i, 1:num_inputs) = fis.rule(i).antecedent; retval(i, num_inputs+1:num_inputs+num_outputs) = ... fis.rule(i).consequent; retval(i, num_inputs+num_outputs+1) = fis.rule(i).weight; retval(i, num_inputs+num_outputs+2) = fis.rule(i).connection; endfor otherwise error ("internal error in getfis_two_args"); endswitch endfunction ##---------------------------------------------------------------------- ## Function: getfis_three_args ## Purpose: Handle calls to getfis that have 3 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_three_args (fis, arg2, arg3) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); elseif (!(is_string (arg2) && ... ismember (tolower (arg2), {'input','output'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect second argument to getfis\n"); elseif (!is_var_index (fis, arg2, arg3)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect third argument to getfis\n"); endif ## Print the properties of a specified input or output variable of the ## FIS structure. Return the empty set. var_str = ["fis." tolower(arg2) "(" num2str(arg3) ")"]; var_mf_str = [var_str ".mf"]; num_mfs = columns (eval (var_mf_str)); printf ("Name = %s\n", eval ([var_str ".name"])); printf ("NumMFs = %d\n", num_mfs); printf ("MFLabels = \n"); for i = 1 : num_mfs printf ("\t%s\n", eval ([var_mf_str "(" num2str(i) ").name"])); endfor printf ("Range = %s\n", mat2str (eval ([var_str ".range"]))); retval = []; endfunction ##---------------------------------------------------------------------- ## Function: getfis_four_args ## Purpose: Handle calls to getfis that have 4 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_four_args (fis, arg2, arg3, arg4) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); elseif (!(is_string (arg2) && ... ismember (tolower (arg2), {'input','output'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect second argument to getfis\n"); elseif (!is_var_index (fis, arg2, arg3)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect third argument to getfis\n"); elseif (!(is_string (arg4) && ismember (tolower (arg4), ... {'name', 'range', 'nummfs', 'mflabels'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect fourth argument to getfis\n"); endif ## Return the specified property of the FIS input or output variable. arg2 = tolower (arg2); arg4 = tolower (arg4); if (ismember (arg4, {'name', 'range'})) retval = eval (["fis." arg2 "(" num2str(arg3) ")." arg4]); elseif (strcmp (arg4, 'nummfs')) retval = columns (eval (["fis." arg2 "(" num2str(arg3) ").mf"])); elseif (strcmp (arg2, 'input') && strcmp (arg4, 'mflabels')) retval = []; for i = 1 : columns (fis.input) for j = 1 : columns (fis.input(i).mf) retval = [retval; fis.input(i).mf(j).name]; endfor endfor elseif (strcmp (arg2, 'output') && strcmp (arg4, 'mflabels')) retval = []; for i = 1 : columns (fis.output) for j = 1 : columns (fis.output(i).mf) retval = [retval; fis.output(i).mf(j).name]; endfor endfor endif endfunction ##---------------------------------------------------------------------- ## Function: getfis_five_args ## Purpose: Handle calls to getfis that have 5 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_five_args (fis, arg2, arg3, arg4, arg5) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); elseif (!(is_string(arg2) && ... ismember(tolower(arg2), {'input','output'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect second argument to getfis\n"); elseif (!is_var_index(fis, arg2, arg3)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect third argument to getfis\n"); elseif (!(is_string(arg4) && isequal(tolower(arg4), 'mf'))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect fourth argument to getfis\n"); elseif (!is_mf_index(fis, arg2, arg3, arg5)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect fifth argument to getfis\n"); endif ## Print the properties of a specified membership function of the ## FIS structure. Return the empty set. var_mf_str = ["fis." tolower(arg2) "(" num2str(arg3) ").mf(" ... num2str(arg5) ")"]; printf ("Name = %s\n", eval ([var_mf_str ".name"])); printf ("Type = %s\n", eval ([var_mf_str ".type"])); printf ("Params = "); disp (eval ([var_mf_str ".params"])); retval = []; endfunction ##---------------------------------------------------------------------- ## Function: getfis_six_args ## Purpose: Handle calls to getfis that have 6 arguments. See the ## comment at the top of this file for more complete info. ##---------------------------------------------------------------------- function retval = getfis_six_args (fis, arg2, arg3, arg4, arg5, arg6) ## If not all of the arguments have the correct types, print an error ## message and halt. if (!is_fis (fis)) puts ("Type 'help getfis' for more information.\n"); error ("the first argument to getfis must be an FIS structure\n"); elseif (!(is_string (arg2) && ... ismember (tolower (arg2), {'input','output'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect second argument to getfis\n"); elseif (!is_var_index (fis, arg2, arg3)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect third argument to getfis\n"); elseif (!(is_string (arg4) && isequal (tolower (arg4), 'mf'))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect fourth argument to getfis\n"); elseif (!is_mf_index (fis, arg2, arg3, arg5)) puts ("Type 'help getfis' for more information.\n"); error ("incorrect fifth argument to getfis\n"); elseif (!(is_string (arg6) && ismember (tolower (arg6), ... {'name', 'type', 'params'}))) puts ("Type 'help getfis' for more information.\n"); error ("incorrect sixth argument to getfis\n"); endif ## Return the specified membership function property. retval = eval (["fis." tolower(arg2) "(" num2str(arg3) ").mf(" ... num2str(arg5) ")." tolower(arg6)]); endfunction fuzzy-logic-toolkit/inst/dsigmf.m0000664000175000017500000001015712354647032016403 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} dsigmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} dsigmf (@var{[x1 x2 ... xn]}, @var{[a1 c1 a2 c2]}) ## ## For a given domain @var{x} and parameters @var{params} (or ## @var{[a1 c1 a2 c2]}), return the corresponding @var{y} values for the ## difference between two sigmoidal membership functions. ## ## The argument @var{x} must be a real number or a non-empty list of strictly ## increasing real numbers, and @var{a1}, @var{c1}, @var{a2}, and @var{c2} must ## be real numbers. This membership function satisfies the equation: ## @example ## f(x) = 1/(1 + exp(-a1*(x - c1))) - 1/(1 + exp(-a2*(x - c2))) ## @end example ## ## @noindent ## and in addition, is bounded above and below by 1 and 0 (regardless of the ## value given by the formula above). ## ## If the parameters @var{a1} and @var{a2} are positive and @var{c1} and ## @var{c2} are far enough apart with @var{c1} < @var{c2}, then: ## @itemize @w ## @item ## (a1)/4 ~ the rising slope at c1 ## @item ## c1 ~ the left inflection point ## @item ## (-a2)/4 ~ the falling slope at c2 ## @item ## c2 ~ the right inflection point ## @end itemize ## ## @noindent ## and at each inflection point, the value of the function is about 0.5: ## @itemize @w ## @item ## f(c1) ~ f(c2) ~ 0.5. ## @end itemize ## ## @noindent ## Here, the symbol ~ means "approximately equal". ## ## @noindent ## To run the demonstration code, type @t{demo('dsigmf')} at the Octave prompt. ## ## @seealso{gauss2mf, gaussmf, gbellmf, pimf, psigmf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership sigmoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: dsigmf.m ## Last-Modified: 20 Aug 2012 function y = dsigmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help dsigmf' for more information.\n"); error ("dsigmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help dsigmf' for more information.\n"); error ("dsigmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('dsigmf', params)) puts ("Type 'help dsigmf' for more information.\n"); error ("dsigmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. a1 = params(1); c1 = params(2); a2 = params(3); c2 = params(4); y_val = @(x_val) max (0, ... min (1, 1 / (1 + exp (-a1 * (x_val - c1))) - ... 1 / (1 + exp (-a2 * (x_val - c2))))); y = arrayfun (y_val, x); endfunction %!demo %! x = 0:100; %! params = [0.5 20 0.3 60]; %! y1 = dsigmf(x, params); %! params = [0.3 20 0.2 60]; %! y2 = dsigmf(x, params); %! params = [0.2 20 0.1 60]; %! y3 = dsigmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'dsigmf demo'); %! plot(x, y1, 'r;params = [0.5 20 0.3 60];', 'LineWidth', 2) %! hold on; %! plot(x, y2, 'b;params = [0.3 20 0.2 60];', 'LineWidth', 2) %! hold on; %! plot(x, y3, 'g;params = [0.2 20 0.1 60];', 'LineWidth', 2) %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value', 'FontWeight', 'bold'); %! ylabel('Degree of Membership', 'FontWeight', 'bold'); %! grid; fuzzy-logic-toolkit/inst/rmmf.m0000664000175000017500000000652512354647032016077 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{fis} =} rmmf (@var{fis}, @var{in_or_out}, @var{var_index}, @var{mf}, @var{mf_index}) ## ## Remove a membership function from an existing FIS ## structure and return the updated FIS. ## ## The types of the arguments are expected to be: ## @itemize @bullet ## @item ## @var{fis} - an FIS structure ## @item ## @var{in_or_out} - either 'input' or 'output' (case-insensitive) ## @item ## @var{var_index} - an FIS input or output variable index ## @item ## @var{mf} - the string 'mf' ## @item ## @var{mf_index} - a string ## @end itemize ## ## Note that rmmf will allow the user to delete membership functions that are ## currently in use by rules in the FIS. ## ## @seealso{addmf, rmvar} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: rmmf.m ## Last-Modified: 20 Aug 2012 function fis = rmmf (fis, in_or_out, var_index, mf, mf_index) ## If the caller did not supply 5 argument values with the correct ## types, print an error message and halt. if (nargin != 5) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf requires 5 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf's first argument must be an FIS structure\n"); elseif (!(is_string(in_or_out) && ... ismember (tolower (in_or_out), {'input', 'output'}))) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, in_or_out, var_index)) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf's third argument must be a variable index\n"); elseif (!isequal (mf, 'mf')) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf's fourth argument must be the string 'mf'\n"); elseif (!is_int (mf_index)) puts ("Type 'help rmmf' for more information.\n"); error ("rmmf's fifth argument must be an integer\n"); endif ## Delete the membership function struct and update the FIS structure. if (strcmp (tolower (in_or_out), 'input')) all_mfs = fis.input(var_index).mf; fis.input(var_index).mf = [all_mfs(1 : mf_index - 1), ... all_mfs(mf_index + 1 : numel(all_mfs))]; else all_mfs = fis.output(var_index).mf; fis.output(var_index).mf = [all_mfs(1 : mf_index - 1), ... all_mfs(mf_index + 1 : numel(all_mfs))]; endif endfunction fuzzy-logic-toolkit/inst/gaussmf.m0000664000175000017500000000757112354647032016605 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{y} =} gaussmf (@var{x}, @var{params}) ## @deftypefnx {Function File} {@var{y} =} gaussmf (@var{[x1 x2 ... xn]}, @var{[sig c]}) ## ## For a given domain @var{x} and parameters @var{params} (or @var{[sig c]}), ## return the corresponding @var{y} values for the Gaussian membership ## function. This membership function is shaped like the Gaussian (normal) ## distribution, but scaled to have a maximum value of 1. By contrast, the ## area under the Gaussian distribution curve is 1. ## ## The argument @var{x} must be a real number or a non-empty vector of strictly ## increasing real numbers, and @var{sig} and @var{c} must be real numbers. ## This membership function satisfies the equation: ## @example ## f(x) = exp((-(x - c)^2)/(2 * sig^2)) ## @end example ## ## @noindent ## which always returns values in the range [0, 1]. ## ## Just as for the Gaussian (normal) distribution, the parameters @var{sig} and ## @var{c} represent: ## @itemize @w ## @item ## sig^2 == the variance (a measure of the width of the curve) ## @item ## c == the center (the mean; the x value of the peak) ## @end itemize ## ## @noindent ## For larger values of @var{sig}, the curve is flatter, and for smaller values ## of sig, the curve is narrower. The @var{y} value at the center is always 1: ## @itemize @w ## @item ## f(c) == 1 ## @end itemize ## ## @noindent ## To run the demonstration code, type @t{demo('gaussmf')} at the Octave prompt. ## ## @seealso{dsigmf, gauss2mf, gbellmf, pimf, psigmf, sigmf, smf, trapmf, trimf, zmf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gaussmf.m ## Last-Modified: 19 Aug 2012 function y = gaussmf (x, params) ## If the caller did not supply 2 argument values with the correct ## types, print an error message and halt. if (nargin != 2) puts ("Type 'help gaussmf' for more information.\n"); error ("gaussmf requires 2 arguments\n"); elseif (!is_domain (x)) puts ("Type 'help gaussmf' for more information.\n"); error ("gaussmf's first argument must be a valid domain\n"); elseif (!are_mf_params ('gaussmf', params)) puts ("Type 'help gaussmf' for more information.\n"); error ("gaussmf's second argument must be a parameter vector\n"); endif ## Calculate and return the y values of the membership function on the ## domain x. sig = params(1); c = params(2); y_val = @(x_val) exp ((-(x_val - c)^2)/(2 * sig^2)); y = arrayfun (y_val, x); endfunction %!demo %! x = -5:0.1:5; %! params = [0.5 0]; %! y1 = gaussmf(x, params); %! params = [1 0]; %! y2 = gaussmf(x, params); %! params = [2 0]; %! y3 = gaussmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'gaussmf demo'); %! plot(x, y1, 'r;params = [0.5 0];', 'LineWidth', 2); %! hold on ; %! plot(x, y2, 'b;params = [1 0];', 'LineWidth', 2); %! hold on ; %! plot(x, y3, 'g;params = [2 0];', 'LineWidth', 2); %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value'); %! ylabel('Degree of Membership'); %! grid; %! hold; fuzzy-logic-toolkit/inst/plotmf.m0000664000175000017500000001501212354647032016426 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {} plotmf (@var{fis}, @var{in_or_out}, @var{var_index}) ## @deftypefnx {Function File} {} plotmf (@var{fis}, @var{in_or_out}, @var{var_index}, @var{y_lower_limit}) ## @deftypefnx {Function File} {} plotmf (@var{fis}, @var{in_or_out}, @var{var_index}, @var{y_lower_limit}, @var{y_upper_limit}) ## ## Plot the membership functions defined for the specified FIS input or output ## variable on a single set of axes. Fuzzy output membership functions are ## represented by the [0, 1]-valued fuzzy functions, and constant output ## membership functions are represented by unit-valued singleton spikes. ## Linear output membership functions, however, are represented by ## two-dimensional lines y = ax + c, regardless of how many dimensions the ## linear function is defined to have. In effect, all of the other dimensions ## of the linear function are set to 0. ## ## If both constant and linear membership functions are used for a single FIS ## output, then two sets of axes are used: one for the constant membership ## functions, and another for the linear membership functions. To plot both ## constant and linear membership functions together, or to plot constant ## membership functions as horizontal lines instead of unit-valued spikes, ## represent the constant membership functions using 'linear' functions, with ## 0 for all except the last parameter, and with the desired constant value as ## the last parameter. ## ## The types of the arguments are expected to be: ## @itemize @bullet ## @item ## @var{fis} - an FIS structure ## @item ## @var{in_or_out} - either 'input' or 'output' (case-insensitive) ## @item ## @var{var_index} - an FIS input or output variable index ## @item ## @var{y_lower_limit} - a real scalar (default value = -0.1) ## @item ## @var{y_upper_limit} - a real scalar (default value = 1.1) ## @end itemize ## ## Six examples that use plotmf are: ## @itemize @bullet ## @item ## cubic_approx_demo.m ## @item ## heart_disease_demo_1.m ## @item ## heart_disease_demo_2.m ## @item ## investment_portfolio_demo.m ## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m ## @item ## sugeno_tip_demo.m ## @end itemize ## ## @seealso{gensurf} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership plot ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: plotmf.m ## Last-Modified: 19 Aug 2012 function plotmf (fis, in_or_out, var_index, ... y_lower_limit = -0.1, y_upper_limit = 1.1) ## If the caller did not supply 3 argument values with the correct ## types, print an error message and halt. if ((nargin < 3) || (nargin > 5)) puts ("Type 'help plotmf' for more information.\n"); error ("plotmf requires 3 - 5 arguments\n"); elseif (!is_fis (fis)) puts ("Type 'help plotmf' for more information.\n"); error ("plotmf's first argument must be an FIS structure\n"); elseif (!(is_string (in_or_out) && ... ismember (tolower (in_or_out), {'input', 'output'}))) puts ("Type 'help plotmf' for more information.\n"); error ("plotmf's second argument must be 'input' or 'output'\n"); elseif (!is_var_index (fis, in_or_out, var_index)) puts ("Type 'help plotmf' for more information.\n"); error ("plotmf's third argument must be a variable index\n"); elseif (!(is_real (y_lower_limit) && is_real (y_upper_limit))) puts ("Type 'help plotmf' for more information.\n"); error ("plotmf's 4th and 5th arguments must be real scalars\n"); endif ## Select specified variable and construct the window title. if (strcmpi (in_or_out, 'input')) var = fis.input(var_index); window_title = [' Input ' num2str(var_index) ' Term Set']; else var = fis.output(var_index); window_title = [' Output ' num2str(var_index) ' Term Set']; endif ## Plot the membership functions for the specified variable. ## Cycle through the five colors: red, blue, green, magenta, cyan. ## Display the membership function names in a legend. colors = ["r" "b" "g" "m" "c"]; x = linspace (var.range(1), var.range(2), 1001); num_mfs = columns (var.mf); ## Define vectors to keep track of linear and non-linear mfs. linear_mfs = zeros (1, num_mfs); for i = 1 : num_mfs if (strcmp ('linear', var.mf(i).type)) linear_mfs(i) = 1; endif endfor fuzzy_and_constant_mfs = 1 - linear_mfs; ## Plot the fuzzy or constant membership functions together on a set ## of axes. if (sum (fuzzy_and_constant_mfs)) figure ('NumberTitle', 'off', 'Name', window_title); ## Plot the mfs. for i = 1 : num_mfs if (fuzzy_and_constant_mfs(i)) y = evalmf_private (x, var.mf(i).params, var.mf(i).type); y_label = [colors(mod(i-1,5)+1) ";" var.mf(i).name ";"]; plot (x, y, y_label, 'LineWidth', 2); hold on; endif endfor ## Adjust the y-axis, label both axes, and display a dotted grid. ylim ([y_lower_limit y_upper_limit]); xlabel (var.name, 'FontWeight', 'bold'); ylabel ('Degree of Membership', 'FontWeight', 'bold'); grid; hold; endif ## Plot the linear membership functions together on a separate set ## of axes. if (sum (linear_mfs)) figure ('NumberTitle', 'off', 'Name', window_title); ## Plot the mfs. for i = 1 : num_mfs if (linear_mfs(i)) y = evalmf_private (x, var.mf(i).params, var.mf(i).type); y_label = [colors(mod(i-1,5)+1) ";" var.mf(i).name ";"]; plot (x, y, y_label, 'LineWidth', 2); hold on; endif endfor ## Adjust the y-axis, label both axes, and display a dotted grid. ylim ([y_lower_limit y_upper_limit]); xlabel ('X', 'FontWeight', 'bold'); ylabel (var.name, 'FontWeight', 'bold'); grid; hold; endif endfunction fuzzy-logic-toolkit/inst/einstein_sum.m0000664000175000017500000000617512354647032017641 0ustar lindalinda## Copyright (C) 2011-2014 L. Markowsky ## ## 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 . ## -*- texinfo -*- ## @deftypefn {Function File} {@var{retval} =} einstein_sum (@var{x}) ## @deftypefnx {Function File} {@var{retval} =} einstein_sum (@var{x}, @var{y}) ## ## Return the Einstein sum of the input. ## The Einstein sum of two real scalars x and y is: (x + y) / (1 + x * y) ## ## For one vector argument, apply the Einstein sum to all of the elements ## of the vector. (The Einstein sum is associative.) For one ## two-dimensional matrix argument, return a vector of the Einstein sum ## of each column. ## ## For two vectors or matrices of identical dimensions, or for one scalar and ## one vector or matrix argument, return the pair-wise Einstein sum. ## ## @seealso{algebraic_product, algebraic_sum, bounded_difference, bounded_sum, drastic_product, drastic_sum, einstein_product, hamacher_product, hamacher_sum} ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy einstein_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: einstein_sum.m ## Last-Modified: 20 Aug 2012 function retval = einstein_sum (x, y = 0) if (nargin == 0 || nargin > 2 || !is_real_matrix (x) || !is_real_matrix (y)) argument_error elseif (nargin == 1) if (isvector (x)) retval = vector_arg (x); elseif (ndims (x) == 2) retval = matrix_arg (x); else argument_error; endif elseif (nargin == 2) if (isequal (size (x), size (y))) retval = arrayfun (@scalar_args, x, y); elseif (isscalar (x) && ismatrix (y)) x = x * ones (size (y)); retval = arrayfun (@scalar_args, x, y); elseif (ismatrix (x) && isscalar (y)) y = y * ones (size (x)); retval = arrayfun (@scalar_args, x, y); else argument_error; endif endif endfunction function retval = scalar_args (x, y) retval = (x + y) / (1 + x * y); endfunction function retval = vector_arg (real_vector) x = 0; for i = 1 : length (real_vector) y = real_vector(i); x = (x + y) / (1 + x * y); endfor retval = x; endfunction function retval = matrix_arg (x) num_cols = columns (x); retval = zeros (1, num_cols); for i = 1 : num_cols retval(i) = vector_arg (x(:, i)); endfor endfunction function argument_error puts ("Type 'help einstein_sum' for more information.\n"); error ("invalid arguments to function einstein_sum\n"); endfunction fuzzy-logic-toolkit/CITATION0000664000175000017500000000226412354647032015134 0ustar lindalindaTo cite the fuzzy-logic-toolkit in publications, please use: L. Markowsky and B. Segee. "The Octave Fuzzy Logic Toolkit," Proceedings of the 2011 IEEE International Workshop on Open-Source Software for Scientific Computation (OSSC-2011), pp. 118-125, October 2011. L. Markowsky and B. Segee. "Unsupervised Clustering With the Octave Fuzzy Logic Toolkit," Proceedings of the 2013 IEEE 10th International Conference on Fuzzy Systems and Knowledge Discovery (FSKD-2013), pp. 207-212, July 2013. The BibTex entries for LaTex users: @inproceedings{octavefuzzy01, author = "L. Markowsky and B. Segee", title = {{The Octave Fuzzy Logic Toolkit}}, booktitle = "Proceedings of the 2011 IEEE International Workshop on Open-Source Software for Scientific Computation", month = "October", year = 2011, pages = {118--125} } @inproceedings{octavefuzzy02, author = "L. Markowsky and B. Segee", title = {{Unsupervised Clustering With the Octave Fuzzy Logic Toolkit}}, booktitle = "Proceedings of the 2013 IEEE 10th International Conference on Fuzzy Systems and Knowledge Discovery", month = "July", year = 2013, pages = {207--212} } fuzzy-logic-toolkit/INDEX0000664000175000017500000000171112354647032014565 0ustar lindalindafuzzy-logic-toolkit >> Octave Fuzzy Logic Toolkit Evaluation defuzz evalfis evalmf Plotting gensurf plotmf File Input/Output of Fuzzy Inference Systems readfis writefis Command-Line Creation and Modification of Fuzzy Inference Systems addmf addrule addvar newfis rmmf rmvar setfis Text Representation of Fuzzy Inference Systems getfis showfis showrule Membership Functions dsigmf gauss2mf gaussmf gbellmf pimf psigmf sigmf smf trapmf trimf zmf T-Norms and S-Norms (in addition to max/min) algebraic_product algebraic_sum bounded_difference bounded_sum drastic_product drastic_sum einstein_product einstein_sum hamacher_product hamacher_sum Complete Fuzzy Inference System Demos cubic_approx_demo heart_disease_demo_1 heart_disease_demo_2 investment_portfolio_demo linear_tip_demo mamdani_tip_demo sugeno_tip_demo Fuzzy Clustering Functions fcm gustafson_kessel partition_coeff partition_entropy xie_beni_index fuzzy-logic-toolkit/ChangeLog0000664000175000017500000003177512354653021015555 0ustar lindalinda2014-07-01 L. Markowsky * Version 0.4.5 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * NEWS: Updated file. * inst/setfis.m: Bug #38018 was fixed (typo in function setfis.m -- wrong function name). 2014-06-26 L. Markowsky * Version 0.4.4 released. * ChangeLog: Updated file. * CITATION: New file. References to two published papers about the fuzzy-logic-toolkit. * DESCRIPTION: Updated file. * NEWS: Updated file. * inst/readfis.m: Modified to workaround change to strsplit beginning in Octave 3.8.0. * inst/evalmf.m: Removed continuation "..." within double quoted string by writing instruction on one line to maintain compatibility with future versions of Octave. * inst/writefis.m: Changed continuation within double quoted string from "..." to "\" to maintain compatibility with future versions of Octave. * inst/*.m: Updated copyright notices. * inst/*.fis: Updated copyright notices. * inst/private/*.m: Updated copyright notices. * Demos tested under: Fedora 20/Octave 3.8.1 * Demos tested under: Fedora 20/Octave 3.8.0 * Demos tested under: Fedora 20/Octave 3.6.4 2012-10-02 L. Markowsky * Version 0.4.2 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * NEWS: Updated file. * inst/*.m: Some trivial changes to line length and comments. * inst/fcm.m: Edited to reflect the five renamed private functions. Edited the demos to calculate and print the three cluster validity indices. Edited comment. * inst/gustafson_kessel.m: Edited to reflect the five renamed private functions. Edited the demos to calculate and print the three cluster validity indices. Edited comment. * inst/partition_coeff.m: Demos were merged with the demos in fcm.m and gustafson_kessel.m and then removed. Edited comment. * inst/partition_entropy.m: Demos were merged with the demos in fcm.m and gustafson_kessel.m and then removed. Edited comment. * inst/xie_beni_index.m: Demos were merged with the demos in fcm.m and gustafson_kessel.m and then removed. Edited comment. * inst/private/evalmf_private.m: Edited comment. * inst/private/is_builtin_language.m: Edited comment. * inst/private/fcm_compute_convergence_criterion.m: Edited and renamed compute_cluster_convergence.m. * inst/private/fcm_compute_objective_fcn.m: Edited and renamed compute_cluster_obj_fcn.m. * inst/private/fcm_init_prototype.m: Edited and renamed init_cluster_prototypes.m. * inst/private/fcm_update_cluster_centers.m: Edited and renamed update_cluster_prototypes.m. * inst/private/fcm_update_membership_fcn.m: Edited and renamed update_cluster_membership.m. * inst/private/probor.m: Removed unused private function. * Demos tested under: Fedora 17/Octave 3.6.2 * Demos tested under: Fedora 16/Octave 3.4.3 * Demos tested under: Windows 7/Octave 3.2.4 2012-08-26 L. Markowsky * Version 0.4.1 released. * ChangeLog: Updated file. * COPYING: Replaced GPLv2 with GPLv3 (to fix inconsistency with source files). * DESCRIPTION: Updated file. * INDEX: Updated file. * NEWS: Updated file. * inst/fcm.m: Rewrote and embedded the demos previously contained in fcm_demo_1.m and fcm_demo_2.m. * inst/fcm_demo_1.m: Removed script file. * inst/fcm_demo_2.m: Removed script file. * inst/gustafson_kessel.m: Rewrote and embedded the demos previously contained in gustafson_kessel_demo_1.m and gustafson_kessel_demo_2.m. * inst/gustafson_kessel_demo_1.m: Removed script file. * inst/gustafson_kessel_demo_2.m: Removed script file. * inst/*.m: Many trivial changes to line length and copyright notices. * inst/private/*.m: Many trivial changes to line length and copyright notice. * All demos tested under: Fedora 17/Octave 3.6.2 2012-07-10 L. Markowsky * Version 0.4.0 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * INDEX: Updated file. * NEWS: New file. * inst/fcm.m: New file. Addition of the Fuzzy C-Means clustering algorithm to the toolkit. * inst/fcm_demo_1.m: New file. Addition of demo script. * inst/fcm_demo_2.m: New file. Addition of demo script. * inst/gustafson_kessel.m: New file. Addition of the Gustafson-Kessel clustering algorithm to the toolkit. * inst/gustafson_kessel_demo_1.m: New file. Addition of demo script. * inst/gustafson_kessel_demo_2.m: New file. Addition of demo script. * inst/partition_coeff.m: New file. Addition of a measure of cluster validity. * inst/partition_entropy.m: New file. Addition of a measure of cluster validity. * inst/xie_beni_index.m: New file. Addition of a measure of cluster validity. * inst/private/fcm_compute_convergence_criterion.m: New file. * inst/private/fcm_compute_objective_fcn.m: New file. * inst/private/fcm_init_prototype.m: New file. * inst/private/fcm_update_cluster_centers.m: New file. * inst/private/fcm_update_membership_fcn.m: New file. * inst/private/square_dist_matrix.m: New file. * New demos tested under: Fedora 16/Octave 3.4.3 2011-11-12 L. Markowsky * Version 0.3.0 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * inst/*.m: Many trivial changes to comments and spacing in parameter lists. * inst/addrule.m: Edited comment to describe use with hedges. * inst/algebraic_product.m: New file. * inst/algebraic_sum.m: New file. * inst/bounded_difference.m: New file. * inst/bounded_sum.m: New file. * inst/cubic_approx_demo.m: Added plot of output membership functions. * inst/cubic_approximator.fis: Corrected range for FIS output. * inst/drastic_product.m: New file. * inst/drastic_sum.m: New file. * inst/einstein_product.m: New file. * inst/einstein_sum.m: New file. * inst/evalmf.m: Edited to add custom and new built-in hedge support. * inst/hamacher_product.m: New file. * inst/hamacher_sum.m: New file. * inst/heart_disease_demo_1.m : Edited and renamed heart_demo_1.m. Edited script to demonstrate hedges and new T-norm/S-norm pairs. * inst/heart_disease_demo_2.m : Renamed heart_demo_2.m. * inst/investment_portfolio.fis: New file. * inst/investment_portfolio_demo.m: New file. * inst/plotmf.m: Edited to add support for linear output membership functions and to support optional y-limit arguments. * inst/readfis.m: Edited to add custom and built-in hedge support. * inst/showrule.m: Edited to add Chinese, Russian, and Spanish to the built-in languages and to add custom language support. Also edited to add custom hedge support and to implement the hedges "somewhat", "very", "extremely", and "very very". * inst/sugeno_tip_calculator.fis: Edited to demonstrate hedges. * inst/sugeno_tip_demo.m: Edited to demonstrate hedges. * inst/writefis.m: Edited comment to note that zenity is required by the GUI. Code edited to support hedges. * inst/private/*.m: Many trivial changes to spacing in parameter lists. * inst/private/aggregate_output_mamdani.m: Edited to support new built-in T-norm/S-norm pairs when used as the FIS aggregation method. * inst/private/eval_firing_strength.m: Edited to support new built-in T-norm/S-norm pairs when used as the FIS 'and' or 'or' method. * inst/private/evalmf_private.m: Edited to evaluate linear membership functions and to add custom and new built-in hedge support. * inst/private/eval_rules_mamdani.m: Edited to add custom and built-in hedge support. * inst/private/eval_rules_sugeno.m: Edited to add custom and built-in hedge support. * inst/private/fuzzify_input.m: Edited to add custom and built-in hedge support. * inst/private/get_mf_index_and_hedge.m: New file to add hedge support. * inst/private/is_real.m: Improved test. * inst/private/is_real_matrix.m: Improved test. * inst/private/is_builtin_language.m: Renamed is_language.m. Edited test to add 'chinese', 'mandarin', 'pinyin', 'russian', 'pycckii', 'russkij', 'spanish', 'french', and 'german' to the strings specifying built-in languages. * Demos tested under: Fedora 15/Octave 3.4.2 * Demos tested under: Windows 7/Octave 3.2.4 2011-09-01 L. Markowsky * Version 0.2.4 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * INDEX: Updated file. * inst/*.m: Numerous trivial changes. * inst/addmf_demo.m: Merged into addmf.m as an embedded demo and then removed. * inst/addvar_demo.m: Merged into addvar.m as an embedded demo and then removed. * inst/showrule_demo.m: Merged into showrule.m as four embedded demos and then removed. * inst/gensurf.m: Edited to permit scalar grids argument. * inst/getfis.m: Edited to implement "version" field in the FIS. * inst/newfis.m: Edited to implement "version" field in the FIS. * inst/readfis.m: Edited to implement "version" field in the FIS and to handle comments, whitespace, and variable number of membership function parameters. * inst/setfis.m: Edited to implement "version" field in the FIS. Fixed several bugs. * inst/writefis.m: Edited to implement "version" field in the FIS. * inst/cubic_approximator.fis: Renamed cubic-approximator.fis. * inst/heart_disease_risk.fis: Renamed heart-disease-risk.fis. Added comments and whitespace. * inst/linear_tip_calculator.fis: Renamed linear-tip-calculator.fis. * inst/mamdani_tip_calculator.fis: Renamed mamdani-tip-calculator.fis and edited to have multiple outputs. * inst/mamdani_tip_demo.m: Edited to demonstrate multiple outputs. * inst/sugeno_tip_calculator.fis: Renamed sugeno-tip-calculator.fis and edited to have multiple outputs. * inst/sugeno_tip_demo.m: Edited to demonstrate multiple outputs. * inst/private/defuzzify_output_mamdani.m: Bug fix (to handle an FIS with multiple outputs). * inst/private/defuzzify_output_sugeno.m: Bug fix (to handle an FIS with multiple outputs). * inst/private/eval_firing_strength.m: Bug fix. * inst/private/eval_rules_mamdani.m: Bug fix (to handle an FIS with multiple outputs). * inst/private/eval_rules_sugeno.m: Bug fix (to handle an FIS with multiple outputs). * inst/private/is_grid_spec.m: Edited test to make more efficient. * inst/private/is_real.m: New file. * Demos tested under: Fedora 15/Octave 3.4.2 * Demos tested under: Fedora 15/Octave 3.2.4 * Demos tested under: Windows 7/Octave 3.2.4 2011-07-19 L. Markowsky * Version 0.2.3 released. * ChangeLog: Updated file. * DESCRIPTION: Updated file. * INDEX: Updated file. * inst/*.m: Edited numerous comments and texinfo comment blocks. * inst/private/*.m: Edited numerous comments and texinfo comment blocks. * inst/cubic_approx_demo.m: New file. * inst/cubic-approximator.fis: New file. * inst/linear-tip-calculator.fis: New file. * inst/linear_tip_demo.m: New file. * inst/heart_demo_1.m: Renamed commandline_demo.m. * inst/heart_demo_2.m: Renamed heart_demo.m. * inst/mamdani_tip_demo.m: Renamed mamdani_demo.m. * inst/sugeno_tip_demo.m: Renamed tipping_demo.m. * inst/gensurf.m: Edited to handle 2-dimensional plots. * inst/private/eval_rules_sugeno.m: Edited to handle linear output membership functions. * Demos tested under: Fedora 15/Octave 3.4.0 * Demos tested under: Fedora 15/Octave 3.2.4 2011-06-21 L. Markowsky * Version 0.2.2 released. * ChangeLog: New file. * DESCRIPTION: Updated file. * inst/addmf.m: Modified to workaround a bug in Octave 3.4.0. * inst/addrule.m: Modified to workaround a bug in Octave 3.4.0. * inst/addvar.m: Modified to workaround a bug in Octave 3.4.0. * inst/gaussmf.m: Modified demo and texinfo comment string. * inst/getfis.m: Modified to workaround a bug in Octave 3.4.0. * inst/readfis.m: Modified to workaround a bug in Octave 3.4.0. * inst/private/aggregate_output_mamdani.m: Modified to workaround a bug in Octave 3.4.0. * inst/private/evalmf_private.m: Modified to workaround a bug in Octave 3.4.0. * Demos tested under: Fedora 15/Octave 3.4.0 * Demos tested under: Fedora 15/Octave 3.2.4 2011-06-08 L. Markowsky * Version 0.2.1 released. * Initial release on Octave-Forge. * Merged membership function demos into related function files. * Created documentation for Octave-Forge website. * DESCRIPTION: Updated file. * Demos tested under: Fedora 13/Octave 3.2.4 2011-05-25 L. Markowsky * Version 0.2 released. * Moved tests/demos/* and tests/fis/* to inst/*. * Changed indentation and spacing to conform to Octave style. * Converted comments to texinfo. * DESCRIPTION: Update file. * Demos tested under: Fedora 13/Octave 3.2.4 2011-04-19 L. Markowsky * Version 0.1 released. * Initial release on SourceForge. * Demos tested under: Fedora 13/Octave 3.2.4 fuzzy-logic-toolkit/COPYING0000664000175000017500000010451312354647032015032 0ustar lindalinda GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program 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. This program 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 this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . fuzzy-logic-toolkit/DESCRIPTION0000664000175000017500000000061112354651775015510 0ustar lindalindaName: fuzzy-logic-toolkit Version: 0.4.5 Date: 2014-07-01 Author: L. Markowsky Maintainer: L. Markowsky Title: Octave Fuzzy Logic Toolkit Description: A mostly MATLAB-compatible fuzzy logic toolkit for Octave. Depends: octave (>= 3.2.4) Autoload: no License: GPLv3+ Url: http://octave.sf.net http://sf.net/projects/octave-fuzzy