From: <lm...@us...> - 2011-06-22 02:24:36
|
Revision: 8343 http://octave.svn.sourceforge.net/octave/?rev=8343&view=rev Author: lmarkov Date: 2011-06-22 01:51:28 +0000 (Wed, 22 Jun 2011) Log Message: ----------- M inst/addvar.m M inst/getfis.m M inst/gaussmf.m M inst/addmf.m M inst/readfis.m M inst/addrule.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -96,7 +96,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function membership ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addmf.m -## Last-Modified: 8 Jun 2011 +## Last-Modified: 20 Jun 2011 function fis = addmf (fis, in_or_out, var_index, mf_name, mf_type, mf_params) @@ -128,9 +128,17 @@ new_mf = struct ('name', mf_name, 'type', mf_type, 'params', mf_params); if (strcmp (tolower (in_or_out), 'input')) - fis.input(var_index).mf = [fis.input(var_index).mf, new_mf]; + 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 - fis.output(var_index).mf = [fis.output(var_index).mf, new_mf]; + 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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -69,7 +69,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy rule ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addrule.m -## Last-Modified: 19 May 2011 +## Last-Modified: 21 Jun 2011 function fis = addrule (fis, rule_matrix) @@ -104,6 +104,10 @@ 'connection', connection); endfor - fis.rule = [fis.rule, new_rules]; + if (length (fis.rule) == 0) + fis.rule = new_rules; + else + fis.rule = [fis.rule, new_rules]; + endif endfunction Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -61,7 +61,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy variable ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addvar.m -## Last-Modified: 8 Jun 2011 +## Last-Modified: 20 Jun 2011 function fis = addvar (fis, in_or_out, var_name, var_range) @@ -91,9 +91,17 @@ new_variable = struct ('name', var_name, 'range', var_range, 'mf', []); if (strcmp (tolower (in_or_out), 'input')) - fis.input = [fis.input, new_variable]; + if (length (fis.input) == 0) + fis.input = new_variable; + else + fis.input = [fis.input, new_variable]; + endif else - fis.output = [fis.output, new_variable]; + if (length (fis.output) == 0) + fis.output = new_variable; + else + fis.output = [fis.output, new_variable]; + endif endif endfunction Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -22,9 +22,9 @@ ## ## 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, a curve 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. +## 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. @@ -64,7 +64,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gaussmf.m -## Last-Modified: 7 Jun 2011 +## Last-Modified: 20 Jun 2011 function y = gaussmf (x, params) @@ -102,12 +102,13 @@ %! params = [2 0]; %! y3 = gaussmf(x, params); %! figure('NumberTitle', 'off', 'Name', 'gaussmf demo'); -%! plot(x, y1, 'r;params = [0.5 0];'); +%! plot(x, y1, 'r;params = [0.5 0];', 'LineWidth', 2); %! hold on ; -%! plot(x, y2, 'b;params = [1 0];'); +%! plot(x, y2, 'b;params = [1 0];', 'LineWidth', 2); %! hold on ; -%! plot(x, y3, 'g;params = [2 0];'); +%! plot(x, y3, 'g;params = [2 0];', 'LineWidth', 2); %! ylim([-0.1 1.1]); %! xlabel('Crisp Input Value'); %! ylabel('Degree of Membership'); +%! grid; %! hold; Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -93,7 +93,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: getfis.m -## Last-Modified: 19 May 2011 +## Last-Modified: 21 Jun 2011 ##------------------------------------------------------------------------------ @@ -196,56 +196,92 @@ case 'numinputmfs' retval = []; for i = 1 : columns (fis.input) - retval = [retval columns(fis.input(i).mf)]; + 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) - retval = [retval columns(fis.output(i).mf)]; + 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) - retval = [retval; fis.input(i).name]; + 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) - retval = [retval; fis.output(i).name]; + 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) - retval = [retval; fis.input(i).range]; + 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) - retval = [retval; fis.output(i).range]; + 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) - retval = [retval columns(fis.input(i).mf)]; + 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) - retval = [retval columns(fis.output(i).mf)]; + 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) - retval = [retval; fis.input(i).mf(j).name]; + if (i == 1 && y == 1) + retval = fis.input(i).mf(j).name; + else + retval = [retval; fis.input(i).mf(j).name]; + endif endfor endfor @@ -253,7 +289,11 @@ retval = []; for i = 1 : columns (fis.output) for j = 1 : columns (fis.output(i).mf) - retval = [retval; fis.output(i).mf(j).name]; + if (i == 1 && y == 1) + retval = fis.output(i).mf(j).name; + else + retval = [retval; fis.output(i).mf(j).name]; + endif endfor endfor @@ -261,7 +301,11 @@ retval = []; for i = 1 : columns (fis.input) for j = 1 : columns (fis.input(i).mf) - retval = [retval; fis.input(i).mf(j).type]; + if (i == 1 && y == 1) + retval = fis.input(i).mf(j).type; + else + retval = [retval; fis.input(i).mf(j).type]; + endif endfor endfor @@ -269,7 +313,11 @@ retval = []; for i = 1 : columns (fis.output) for j = 1 : columns (fis.output(i).mf) - retval = [retval; fis.output(i).mf(j).type]; + if (i == 1 && y == 1) + retval = fis.output(i).mf(j).type; + else + retval = [retval; fis.output(i).mf(j).type]; + endif endfor endfor Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m 2011-06-22 01:50:32 UTC (rev 8342) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m 2011-06-22 01:51:28 UTC (rev 8343) @@ -66,7 +66,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: readfis.m -## Last-Modified: 7 Jun 2011 +## Last-Modified: 20 Jun 2011 ##------------------------------------------------------------------------------ @@ -108,7 +108,11 @@ for i = 1 : num_inputs [next_fis_input, num_mfs, line_num] = ... get_next_fis_io (fid, line_num, i, 'input'); - fis.input = [fis.input, next_fis_input]; + if (i == 1) + fis.input = next_fis_input; + else + fis.input = [fis.input, next_fis_input]; + endif ##---------------------------------------------------------------------- ## Read membership function info for the new FIS input from file. @@ -117,7 +121,11 @@ for j = 1 : num_mfs [next_mf, line_num] = get_next_mf (fid, line_num, i, j, 'input'); - fis.input(i).mf = [fis.input(i).mf, next_mf]; + if (j == 1) + fis.input(i).mf = next_mf; + else + fis.input(i).mf = [fis.input(i).mf, next_mf]; + endif endfor endfor @@ -129,7 +137,11 @@ for i = 1 : num_outputs [next_fis_output, num_mfs, line_num] = ... get_next_fis_io (fid, line_num, i, 'output'); - fis.output = [fis.output, next_fis_output]; + if (i == 1) + fis.output = next_fis_output; + else + fis.output = [fis.output, next_fis_output]; + endif ##---------------------------------------------------------------------- ## Read membership function info for the new FIS output from file. @@ -138,7 +150,11 @@ for j = 1 : num_mfs [next_mf, line_num] = get_next_mf (fid, line_num, i, j, 'output'); - fis.output(i).mf = [fis.output(i).mf, next_mf]; + if (j == 1) + fis.output(i).mf = next_mf; + else + fis.output(i).mf = [fis.output(i).mf, next_mf]; + endif endfor endfor @@ -152,7 +168,11 @@ for i = 1 : num_rules [next_rule, line_num] = ... get_next_rule (fid, line_num, num_inputs, num_outputs); - fis.rule = [fis.rule, next_rule]; + if (i == 1) + fis.rule = next_rule; + else + fis.rule = [fis.rule, next_rule]; + endif endfor endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lm...@us...> - 2011-11-13 18:37:14
|
Revision: 9082 http://octave.svn.sourceforge.net/octave/?rev=9082&view=rev Author: lmarkov Date: 2011-11-13 18:37:05 +0000 (Sun, 13 Nov 2011) Log Message: ----------- A inst/heart_disease_demo_1.m M inst/smf.m A inst/heart_disease_demo_2.m M inst/mamdani_tip_demo.m M inst/gauss2mf.m M inst/writefis.m M inst/zmf.m M inst/addvar.m M inst/showrule.m M inst/gbellmf.m A inst/hamacher_product.m A inst/algebraic_product.m M inst/dsigmf.m M inst/gensurf.m A inst/einstein_product.m M inst/sugeno_tip_demo.m M inst/getfis.m M inst/trimf.m M inst/showfis.m M inst/cubic_approx_demo.m M inst/psigmf.m D inst/heart_demo_1.m D inst/heart_demo_2.m A inst/drastic_product.m M inst/evalfis.m M inst/trapmf.m A inst/bounded_difference.m M inst/linear_tip_demo.m M inst/newfis.m M inst/pimf.m A inst/hamacher_sum.m A inst/algebraic_sum.m A inst/investment_portfolio_demo.m M inst/plotmf.m A inst/einstein_sum.m A inst/bounded_sum.m M inst/sigmf.m M inst/gaussmf.m M inst/evalmf.m M inst/sugeno_tip_calculator.fis M inst/addmf.m M inst/readfis.m A inst/drastic_sum.m A inst/investment_portfolio.fis M inst/cubic_approximator.fis M inst/addrule.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/newfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/pimf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/plotmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/psigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/showfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/showrule.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/smf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/trapmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/trimf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/writefis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/zmf.m Added Paths: ----------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio_demo.m Removed Paths: ------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_demo_2.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -51,10 +51,9 @@ ## them for FIS inputs or Mamdani-type FIS outputs has not yet been tested. ## ## @noindent -## To run the demonstration code below, 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. +## 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 @@ -65,7 +64,7 @@ ## 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: 30 Aug 2011 +## Last-Modified: 28 Oct 2011 function fis = addmf (fis, in_or_out, var_index, mf_name, mf_type, mf_params) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -41,35 +41,50 @@ ## connect == antecedent connective (1 == and; 2 == or) ## @end itemize ## -## To express the hedge "not", prepend a minus sign to the membership function -## index. ("Not" is the only hedge supported.) To omit an input or output, use -## 0 for the membership function index. The consequent connective is always -## "and". +## 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, -## then output_2 is mf_1." +## "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 0 1 1 2] +## [2 0 -1 4.2 2 1.03 1 2] ## @end example ## ## @noindent -## For a complete example that uses addrule, see heart_demo_1.m. +## For a complete example that uses addrule, see heart_disease_demo_1.m. ## -## @seealso{heart_demo_1, showrule} +## @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: 16 Jul 2011 +## Last-Modified: 11 Nov 2011 function fis = addrule (fis, rule_matrix) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -38,8 +38,7 @@ ## specify the lower and upper bounds of the variable's domain. ## ## @noindent -## To run the demonstration code below, type @t{demo('addvar')} at the -## Octave prompt. +## To run the demonstration code, type @t{demo('addvar')} at the Octave prompt. ## ## @end deftypefn @@ -47,7 +46,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy variable ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addvar.m -## Last-Modified: 30 Aug 2011 +## Last-Modified: 28 Oct 2011 function fis = addvar (fis, in_or_out, var_name, var_range) Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,56 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +function retval = algebraic_product (x, y = 0) + if (!(isreal (x) && isreal (y))) + puts ("Type 'help algebraic_product' for more information.\n"); + error ("algebraic_product requires real scalar or matrix arguments\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 + Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,71 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 + Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,72 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +function retval = bounded_difference (x, y = 0) + if (!(isreal (x) && isreal (y))) + puts ("Type 'help bounded_difference' for more information.\n"); + error ("bounded_difference requires real scalar or matrix arguments\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 + Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,71 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 + Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -20,8 +20,7 @@ ## @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 membership -## functions. +## non-linear function using a Sugeno-type FIS with linear output functions. ## ## The demo: ## @itemize @minus @@ -30,23 +29,26 @@ ## @item ## plots the input membership functions ## @item -## plots the output as a function of the input +## plots the (linear) output functions +## @item +## plots the FIS output as a function of the input ## @end itemize ## -## @seealso{heart_demo_1, heart_demo_2, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} +## @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: 27 Aug 2011 +## Last-Modified: 12 Nov 2011 ## Read the FIS structure from a file. fis = readfis ('cubic_approximator.fis'); -## Plot the input membership functions. +## Plot the input membership functions and linear output functions. plotmf (fis, 'input', 1); +plotmf (fis, 'output', 1, -150, 150); -## Plot the output y as a function of the input x. +## Plot the FIS output y as a function of the input x. gensurf (fis); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis 2011-11-13 18:37:05 UTC (rev 9082) @@ -29,7 +29,7 @@ [Output1] Name='Approx-X-Cubed' -Range=[-130 130] +Range=[-5 5] NumMFs=11 MF1 = 'Tangent-at-Neg-Five':'linear', [75 250] MF2 = 'Tangent-at-Neg-Four':'linear', [48 128] Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,107 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,107 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -59,8 +59,7 @@ ## Here, the symbol ~ means "approximately equal". ## ## @noindent -## To run the demonstration code below, type @t{demo('dsigmf')} at the -## Octave prompt. +## 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 @@ -69,7 +68,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function sigmoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: dsigmf.m -## Last-Modified: 7 Jun 2011 +## Last-Modified: 28 Oct 2011 function y = dsigmf (x, params) Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,97 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,96 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -90,7 +90,45 @@ ## @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) <=> <custom hedge> 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 <hedge> x <=> 1 - mu(x)^(dd/10) +## @end example +## +## Hedges and "not" in the consequent are handled similarly. +## ## @noindent ## The intermediate result @var{rule_output}: ## @@ -172,15 +210,17 @@ ## @noindent ## Examples: ## -## Six examples of using evalfis are shown in: +## Seven examples of using evalfis are shown in: ## @itemize @bullet ## @item ## cubic_approx_demo.m ## @item -## heart_demo_1.m +## heart_disease_demo_1.m ## @item -## heart_demo_2.m +## heart_disease_demo_2.m ## @item +## investment_portfolio_demo.m +## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m @@ -188,17 +228,17 @@ ## sugeno_tip_demo.m ## @end itemize ## -## @seealso{cubic_approx_demo, heart_demo_1, heart_demo_2, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo} +## @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 fuzzy-inference-system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalfis.m -## Last-Modified: 16 Jul 2011 +## Last-Modified: 12 Nov 2011 function [output, rule_input, rule_output, fuzzy_output] = ... - evalfis (user_input, fis, num_points=101) + 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. Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -18,10 +18,15 @@ ## -*- 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, and membership function type, -## return the corresponding y-values for the membership function. +## 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 @@ -29,38 +34,61 @@ ## 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) <=> <custom hedge> 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 below, type @t{demo('evalmf')} at the Octave -## prompt. -## +## To run the demonstration code, type @t{demo('evalmf')} at the Octave prompt. ## @end deftypefn ## Author: L. Markowsky ## Keywords: fuzzy-logic-toolkit fuzzy membership-function evaluate ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalmf.m -## Last-Modified: 16 Jul 2011 +## Last-Modified: 13 Nov 2011 -function y = evalmf (x, params, mf_type) +function y = evalmf (x, params, mf_type, hedge = 0, not_flag = false) - ## If the caller did not supply 3 argument values with the correct types, + ## If the caller did not supply 3 - 5 argument values with the correct types, ## print an error message and halt. - if (nargin != 3) + if ((nargin < 3) || (nargin > 5)) puts ("Type 'help evalmf' for more information.\n"); - error ("evalmf requires 3 arguments\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 to evalmf must be a string\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); + y = evalmf_private (x, params, mf_type, hedge, not_flag); endfunction Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -58,8 +58,7 @@ ## than 1). ## ## @noindent -## To run the demonstration code below, type @t{demo('gauss2mf')} at the -## Octave prompt. +## 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 @@ -68,7 +67,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gauss2mf.m -## Last-Modified: 7 Jun 2011 +## Last-Modified: 28 Oct 2011 function y = gauss2mf (x, params) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -54,8 +54,7 @@ ## @end itemize ## ## @noindent -## To run the demonstration code below, type @t{demo('gaussmf')} at the -## Octave prompt. +## 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 @@ -64,7 +63,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gaussmf.m -## Last-Modified: 20 Jun 2011 +## Last-Modified: 28 Oct 2011 function y = gaussmf (x, params) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -58,8 +58,7 @@ ## differentiable and is symmetric about the line x = c. ## ## @noindent -## To run the demonstration code below, type @t{demo('gbellmf')} at the -## Octave prompt. +## 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 @@ -68,7 +67,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership-function bell-shaped bell ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gbellmf.m -## Last-Modified: 7 Jun 2011 +## Last-Modified: 28 Oct 2011 function y = gbellmf (x, params) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -57,10 +57,12 @@ ## @item ## cubic_approx_demo.m ## @item -## heart_demo_1.m +## heart_disease_demo_1.m ## @item -## heart_demo_2.m +## heart_disease_demo_2.m ## @item +## investment_portfolio_demo.m +## @item ## linear_tip_demo.m ## @item ## mamdani_tip_demo.m @@ -72,17 +74,17 @@ ## The form of gensurf that suppresses plotting (the final form above) is not yet ## implemented. ## -## @seealso{cubic_approx_demo, heart_demo_1, heart_demo_2, linear_tip_demo, mamdani_tip_demo, sugeno_tip_demo, plotmf} +## @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 fuzzy-inference-system fis plot ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gensurf.m -## Last-Modified: 30 Aug 2011 +## Last-Modified: 11 Nov 2011 -function [x, y, z] = gensurf (fis, input_axes=[1 2], output_axis=1, ... - grids=[15 15], ref_input=[], num_points=101) +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. Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2011-11-13 18:30:38 UTC (rev 9081) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -93,12 +93,12 @@ ## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: getfis.m -## Last-Modified: 31 Aug 2011 +## Last-Modified: 31 Oct 2011 ##------------------------------------------------------------------------------ -function retval = getfis (fis, arg2='dummy', arg3='dummy', arg4='dummy', ... - arg5='dummy', arg6='dummy') +function retval = getfis (fis, arg2 = 'dummy', arg3 = 'dummy', ... + arg4 = 'dummy', arg5 = 'dummy', arg6 = 'dummy') switch (nargin) case 1 retval = getfis_one_arg (fis); Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,101 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m 2011-11-13 18:37:05 UTC (rev 9082) @@ -0,0 +1,101 @@ +## Copyright (C) 2011 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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: 12 Nov 2011 + +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; + fo... [truncated message content] |
From: <lm...@us...> - 2012-07-10 14:20:13
|
Revision: 10740 http://octave.svn.sourceforge.net/octave/?rev=10740&view=rev Author: lmarkov Date: 2012-07-10 14:20:04 +0000 (Tue, 10 Jul 2012) Log Message: ----------- M inst/gustafson_kessel_demo_1.m M inst/gustafson_kessel_demo_2.m M inst/xie_beni_index.m M inst/gustafson_kessel.m M inst/fcm_demo_1.m M inst/fcm_demo_2.m M inst/fcm.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -24,7 +24,9 @@ ## @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}]) ## -## Return the soft partition of a set of unlabeled data points. +## 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. ## @@ -112,7 +114,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... fcm (input_data, num_clusters, options = [2.0, 100, 1e-5, 1]) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Script File} {} fcm_demo_1 -## Use the Fuzzy C-Means algorithm to classify unlabeled data points and -## evaluate the quality of the resulting clusters. +## Use the Fuzzy C-Means algorithm to classify a small set of unlabeled +## data points and evaluate the quality of the resulting clusters. ## ## This demo: ## @itemize @minus @@ -45,7 +45,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm_demo_1.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 ##------------------------------------------------------------------------------ ## Note: The input_data is taken from Chapter 13, Example 17 in Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Script File} {} fcm_demo_2 -## Use the Fuzzy C-Means algorithm to classify unlabeled data points and -## evaluate the quality of the resulting clusters. +## Use the Fuzzy C-Means algorithm to classify three-dimensional unlabeled +## data points and evaluate the quality of the resulting clusters. ## ## The demo: ## @itemize @minus @@ -45,7 +45,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm_demo_2.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 ##------------------------------------------------------------------------------ ## Note: The input_data was selected to form three areas of different shapes. Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -26,7 +26,9 @@ ## @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}]) ## -## Return the soft partition of a set of unlabeled data points. +## 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. ## @@ -117,7 +119,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering gustafson_kessel ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... gustafson_kessel (input_data, num_clusters, cluster_volume = [], options = [2.0, 100, 1e-5, 1]) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Script File} {} gustafson_kessel_demo_1 -## Use the Gustafson-Kessel algorithm to classify unlabeled data points and -## evaluate the quality of the resulting clusters. +## Use the Gustafson-Kessel algorithm to classify a small set of unlabeled +## data points and evaluate the quality of the resulting clusters. ## ## The demo: ## @itemize @minus @@ -45,7 +45,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering gustafson_kessel demo ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel_demo_1.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 ##------------------------------------------------------------------------------ ## Note: The input_data is taken from Chapter 13, Example 17 in Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -18,8 +18,8 @@ ## -*- texinfo -*- ## @deftypefn {Script File} {} gustafson_kessel_demo_2 -## Use the Gustafson-Kessel algorithm to classify unlabeled data points and -## evaluate the quality of the resulting clusters. +## Use the Gustafson-Kessel algorithm to classify three-dimensional unlabeled +## data points and evaluate the quality of the resulting clusters. ## ## The demo: ## @itemize @minus @@ -45,7 +45,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel_demo_2.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 ##------------------------------------------------------------------------------ ## Note: The input_data was selected to form three areas of different shapes. Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-07-09 13:17:11 UTC (rev 10739) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-07-10 14:20:04 UTC (rev 10740) @@ -19,7 +19,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{vxb} =} xie_beni_index (@var{input_data}, @var{cluster_centers}, @var{soft_partition}) ## -## Return the partition coefficient for a given soft partition. +## Return the Xie-Beni validity index for a given soft partition. ## ## The arguments to xie_beni_index are: ## @itemize @w @@ -49,7 +49,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy xie beni index cluster validity ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: xie_beni_index.m -## Last-Modified: 8 July 2012 +## Last-Modified: 10 July 2012 function vxb = xie_beni_index (input_data, cluster_centers, soft_partition) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lm...@us...> - 2012-08-26 14:54:19
|
Revision: 10915 http://octave.svn.sourceforge.net/octave/?rev=10915&view=rev Author: lmarkov Date: 2012-08-26 14:54:12 +0000 (Sun, 26 Aug 2012) Log Message: ----------- M inst/fcm.m M inst/xie_beni_index.m M inst/gustafson_kessel.m D inst/fcm_demo_1.m M inst/partition_entropy.m D inst/fcm_demo_2.m D inst/gustafson_kessel_demo_1.m D inst/gustafson_kessel_demo_2.m M inst/partition_coeff.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m Removed Paths: ------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -106,7 +106,7 @@ ## @end group ## @end example ## -## @seealso{fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index} +## @seealso{gustafson_kessel, partition_coeff, partition_entropy, xie_beni_index} ## ## @end deftypefn @@ -114,7 +114,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm.m -## Last-Modified: 19 Aug 2012 +## Last-Modified: 26 Aug 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... fcm (input_data, num_clusters, options = [2.0, 100, 1e-5, 1]) @@ -212,3 +212,126 @@ 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 +%! ## +%! ## 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 + +##---------------------------------------------------------------------- +## 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 +%! ## +%! ## 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 Deleted: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -1,94 +0,0 @@ -## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> -## -## This file is part of the fuzzy-logic-toolkit. -## -## The fuzzy-logic-toolkit is free software; you can redistribute it -## and/or modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either version 3 of -## the License, or (at your option) any later version. -## -## The fuzzy-logic-toolkit is distributed in the hope that it will be -## useful, but WITHOUT ANY WARRANTY; without even the implied warranty -## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with the fuzzy-logic-toolkit; see the file COPYING. If not, -## see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Script File} {} fcm_demo_1 -## Use the Fuzzy C-Means algorithm to classify a small set of unlabeled -## data points and evaluate the quality of the resulting clusters. -## -## This demo: -## @itemize @minus -## @item -## classifies a small set of unlabeled data points using the Fuzzy C-Means -## algorithm into two fuzzy clusters -## @item -## calculates and prints (on standard output) three validity measures: -## the partition coefficient, the partition entropy, and the Xie-Beni -## validity index -## @item -## plots the input points together with the cluster centers -## @end itemize -## -## For a description of the data structures used in the script, see the -## documentation for fcm. -## -## @seealso{fcm, fcm_demo_2, partition_coeff, partition_entropy, xie_beni_index, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2} -## -## @end deftypefn - -## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm -## Directory: fuzzy-logic-toolkit/inst/ -## Filename: fcm_demo_1.m -## Last-Modified: 19 Aug 2012 - -##---------------------------------------------------------------------- -## 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 data in matrix x. -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) - -## 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)); - -## 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 Deleted: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -1,125 +0,0 @@ -## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> -## -## This file is part of the fuzzy-logic-toolkit. -## -## The fuzzy-logic-toolkit is free software; you can redistribute it -## and/or modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either version 3 of -## the License, or (at your option) any later version. -## -## The fuzzy-logic-toolkit is distributed in the hope that it will be -## useful, but WITHOUT ANY WARRANTY; without even the implied warranty -## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with the fuzzy-logic-toolkit; see the file COPYING. If not, -## see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Script File} {} fcm_demo_2 -## Use the Fuzzy C-Means algorithm to classify three-dimensional unlabeled -## data points and evaluate the quality of the resulting clusters. -## -## The demo: -## @itemize @minus -## @item -## classifies three-dimensional unlabeled data points using the Fuzzy -## C-Means algorithm into three fuzzy clusters -## @item -## calculates and prints (on standard output) three validity measures: -## the partition coefficient, the partition entropy, and the Xie-Beni -## validity index -## @item -## plots the input points together with the cluster centers -## @end itemize -## -## For a description of the data structures used in the script, see the -## documentation for fcm. -## -## @seealso{fcm, fcm_demo_1, partition_coeff, partition_entropy, xie_beni_index, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2} -## -## @end deftypefn - -## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm -## Directory: fuzzy-logic-toolkit/inst/ -## Filename: fcm_demo_2.m -## Last-Modified: 19 Aug 2012 - -##---------------------------------------------------------------------- -## Note: The input_data was selected to form three areas of different -## shapes. -##---------------------------------------------------------------------- - -## Use fcm to classify the data in matrix x. -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]) - -## 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)); - -## Plot the data points in two dimensions (using features 1 and 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 and 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 and 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 and 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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -111,7 +111,7 @@ ## @end group ## @end example ## -## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index} +## @seealso{fcm, partition_coeff, partition_entropy, xie_beni_index} ## ## @end deftypefn @@ -119,7 +119,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel.m -## Last-Modified: 20 Aug 2012 +## Last-Modified: 26 Aug 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... gustafson_kessel (input_data, num_clusters, ... @@ -283,3 +283,125 @@ 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 +%! ## +%! ## 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 + +##---------------------------------------------------------------------- +## 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 +%! ## +%! ## 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 Deleted: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -1,94 +0,0 @@ -## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> -## -## This file is part of the fuzzy-logic-toolkit. -## -## The fuzzy-logic-toolkit is free software; you can redistribute it -## and/or modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either version 3 of -## the License, or (at your option) any later version. -## -## The fuzzy-logic-toolkit is distributed in the hope that it will be -## useful, but WITHOUT ANY WARRANTY; without even the implied warranty -## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with the fuzzy-logic-toolkit; see the file COPYING. If not, -## see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Script File} {} gustafson_kessel_demo_1 -## Use the Gustafson-Kessel algorithm to classify a small set of unlabeled -## data points and evaluate the quality of the resulting clusters. -## -## The demo: -## @itemize @minus -## @item -## classifies a small set of unlabeled data points using the Gustafson-Kessel -## algorithm into two fuzzy clusters -## @item -## calculates and prints (on standard output) three validity measures: -## the partition coefficient, the partition entropy, and the Xie-Beni -## validity index -## @item -## plots the input points together with the cluster centers -## @end itemize -## -## For a description of the data structures used in the script, see the -## documentation for gustafson_kessel. -## -## @seealso{gustafson_kessel, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index, fcm, fcm_demo_1, fcm_demo_2} -## -## @end deftypefn - -## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering -## Directory: fuzzy-logic-toolkit/inst/ -## Filename: gustafson_kessel_demo_1.m -## Last-Modified: 20 Aug 2012 - -##---------------------------------------------------------------------- -## 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 data in matrix x. -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) - -## 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)); - -## 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 Deleted: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -1,125 +0,0 @@ -## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> -## -## This file is part of the fuzzy-logic-toolkit. -## -## The fuzzy-logic-toolkit is free software; you can redistribute it -## and/or modify it under the terms of the GNU General Public License -## as published by the Free Software Foundation; either version 3 of -## the License, or (at your option) any later version. -## -## The fuzzy-logic-toolkit is distributed in the hope that it will be -## useful, but WITHOUT ANY WARRANTY; without even the implied warranty -## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -## General Public License for more details. -## -## You should have received a copy of the GNU General Public License -## along with the fuzzy-logic-toolkit; see the file COPYING. If not, -## see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Script File} {} gustafson_kessel_demo_2 -## Use the Gustafson-Kessel algorithm to classify three-dimensional unlabeled -## data points and evaluate the quality of the resulting clusters. -## -## The demo: -## @itemize @minus -## @item -## classifies three-dimensional unlabeled data points using the -## Gustafson-Kessel algorithm into three fuzzy clusters -## @item -## calculates and prints (on standard output) three validity measures: -## the partition coefficient, the partition entropy, and the Xie-Beni -## validity index -## @item -## plots the input points together with the cluster centers -## @end itemize -## -## For a description of the data structures used in the script, see the -## documentation for gustafson_kessel. -## -## @seealso{gustafson_kessel, gustafson_kessel_demo_1, partition_coeff, partition_entropy, xie_beni_index, fcm, fcm_demo_1, fcm_demo_2} -## -## @end deftypefn - -## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering -## Directory: fuzzy-logic-toolkit/inst/ -## Filename: gustafson_kessel_demo_2.m -## Last-Modified: 20 Aug 2012 - -##---------------------------------------------------------------------- -## Note: The input_data was selected to form three areas of -## different shapes. -##---------------------------------------------------------------------- - -## Use gustafson_kessel to classify the data in matrix x. -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]) - -## 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)); - -## Plot the data points in two dimensions (using features 1 and 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 and 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 and 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 and 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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -36,7 +36,7 @@ ## For more information about the @var{soft_partition} matrix, please see the ## documentation for function fcm. ## -## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_entropy, xie_beni_index} +## @seealso{fcm, gustafson_kessel, partition_entropy, xie_beni_index} ## ## @end deftypefn @@ -44,7 +44,7 @@ ## Keywords: fuzzy-logic-toolkit partition coefficient cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_coeff.m -## Last-Modified: 19 Aug 2012 +## Last-Modified: 26 Aug 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.9 (corrected @@ -78,3 +78,77 @@ vpc = (sum (sum (soft_part_sqr))) / columns (soft_partition); endfunction + +##---------------------------------------------------------------------- +## Partition Coefficient Demo #1 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## a small set of unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## 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). +%! +%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] +%! number_of_clusters = 2 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("partition coefficient: %f\n", ... +%! partition_coeff (soft_partition)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("partition coefficient: %f\n\n", ... +%! partition_coeff (soft_partition)); + +##---------------------------------------------------------------------- +## Partition Coefficient Demo #2 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## three-dimensional unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## Note: The input_data was selected to form three areas of +%! ## different shapes. +%! +%! 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 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("partition coefficient: %f\n", ... +%! partition_coeff (soft_partition)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("partition coefficient: %f\n\n", ... +%! partition_coeff (soft_partition)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -38,7 +38,7 @@ ## For more information about the @var{soft_partition} matrix, please see the ## documentation for function fcm. ## -## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, xie_beni_index} +## @seealso{fcm, gustafson_kessel, partition_coeff, xie_beni_index} ## ## @end deftypefn @@ -46,7 +46,7 @@ ## Keywords: fuzzy-logic-toolkit partition entropy cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_entropy.m -## Last-Modified: 19 Aug 2012 +## Last-Modified: 26 Aug 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.10 in @@ -86,3 +86,77 @@ vpe = -(sum (sum (Mu .* log_a_Mu))) / n; endfunction + +##---------------------------------------------------------------------- +## Partition Entropy Demo #1 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## a small set of unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## 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). +%! +%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] +%! number_of_clusters = 2 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("partition entropy (with a = 2): %f\n", ... +%! partition_entropy (soft_partition, 2)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("partition entropy (with a = 2): %f\n\n", ... +%! partition_entropy (soft_partition, 2)); + +##---------------------------------------------------------------------- +## Partition Entropy Demo #2 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## three-dimensional unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## Note: The input_data was selected to form three areas of +%! ## different shapes. +%! +%! 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 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("partition entropy (with a = 2): %f\n", ... +%! partition_entropy (soft_partition, 2)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("partition entropy (with a = 2): %f\n\n", ... +%! partition_entropy (soft_partition, 2)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-08-25 08:27:39 UTC (rev 10914) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-08-26 14:54:12 UTC (rev 10915) @@ -41,7 +41,7 @@ ## and @var{soft_partition} matrices, please see the documentation for function ## fcm. ## -## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, partition_entropy} +## @seealso{fcm, gustafson_kessel, partition_coeff, partition_entropy} ## ## @end deftypefn @@ -49,7 +49,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy xie beni cluster validity ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: xie_beni_index.m -## Last-Modified: 19 Aug 2012 +## Last-Modified: 26 Aug 2012 function vxb = xie_beni_index (input_data, cluster_centers, ... soft_partition) @@ -126,3 +126,77 @@ d_sqr_min = min (min (d_sqr_matrix)); endfunction + +##---------------------------------------------------------------------- +## Xie-Beni Index Demo #1 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## a small set of unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## 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). +%! +%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] +%! number_of_clusters = 2 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("Xie-Beni index: %f\n", ... +%! xie_beni_index (input_data, cluster_centers, soft_partition)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("Xie-Beni index: %f\n\n", ... +%! xie_beni_index (input_data, cluster_centers, soft_partition)); + +##---------------------------------------------------------------------- +## Xie-Beni Index Demo #2 +##---------------------------------------------------------------------- + +%!demo +%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify +%! ## three-dimensional unlabeled data points and evaluate the quality +%! ## of the resulting clusters. +%! +%! ## Note: The input_data was selected to form three areas of +%! ## different shapes. +%! +%! 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 +%! +%! ## Using fcm, classify the input data, print the cluster centers, +%! ## and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); +%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); +%! cluster_centers +%! printf ("Xie-Beni index: %f\n", ... +%! xie_beni_index (input_data, cluster_centers, soft_partition)); +%! +%! ## Using gustafson_kessel, classify the input data, print the cluster +%! ## centers, and calculate and print the partition coefficient. +%! [cluster_centers, soft_partition, obj_fcn_history] = ... +%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... +%! [NaN NaN NaN 0]); +%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); +%! cluster_centers +%! printf ("Xie-Beni index: %f\n\n", ... +%! xie_beni_index (input_data, cluster_centers, soft_partition)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lm...@us...> - 2012-10-03 00:38:17
|
Revision: 11097 http://octave.svn.sourceforge.net/octave/?rev=11097&view=rev Author: lmarkov Date: 2012-10-03 00:38:09 +0000 (Wed, 03 Oct 2012) Log Message: ----------- M inst/hamacher_product.m M inst/partition_coeff.m M inst/heart_disease_risk.fis M inst/einstein_product.m M inst/mamdani_tip_calculator.fis M inst/sugeno_tip_demo.m M inst/cubic_approx_demo.m M inst/drastic_product.m M inst/linear_tip_demo.m M inst/hamacher_sum.m M inst/rmmf.m M inst/einstein_sum.m M inst/fcm.m M inst/xie_beni_index.m M inst/sugeno_tip_calculator.fis M inst/drastic_sum.m M inst/investment_portfolio.fis M inst/gustafson_kessel.m M inst/cubic_approximator.fis M inst/linear_tip_calculator.fis M inst/heart_disease_demo_1.m M inst/heart_disease_demo_2.m M inst/partition_entropy.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_risk.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_calculator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_calculator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -41,7 +41,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Directory: fuzzy-logic-toolkit/inst ## Filename: cubic_approx_demo.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('cubic_approximator.fis'); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approximator.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,3 +1,27 @@ +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## 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' Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -44,7 +44,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy drastic_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: drastic_product.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = drastic_product (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -44,7 +44,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy drastic_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: drastic_sum.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = drastic_sum (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -39,7 +39,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy einstein_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: einstein_product.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = einstein_product (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -38,7 +38,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy einstein_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: einstein_sum.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = einstein_sum (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -25,10 +25,12 @@ ## @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. +## of a set of unlabeled data points. ## ## Also, if @var{display_intermediate_results} is true, display intermediate -## results after each iteration. +## 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 @@ -111,10 +113,10 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm.m -## Last-Modified: 26 Aug 2012 +## 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]) @@ -175,8 +177,8 @@ fcm_private (X, k, m, max_iterations, epsilon, ... display_intermediate_results) - ## Initialize the prototype and the calculation. - V = fcm_init_prototype (X, k); + ## Initialize the prototypes and the calculation. + V = init_cluster_prototypes (X, k); obj_fcn_history = zeros (max_iterations); convergence_criterion = epsilon + 1; iteration = 0; @@ -191,18 +193,18 @@ while (convergence_criterion > epsilon && ... ++iteration <= max_iterations) V_previous = V; - Mu = fcm_update_membership_fcn (V, X, m, k, n, sqr_dist); + Mu = update_cluster_membership (V, X, m, k, n, sqr_dist); Mu_m = Mu .^ m; - V = fcm_update_cluster_centers (Mu_m, X, k); + V = update_cluster_prototypes (Mu_m, X, k); sqr_dist = square_distance_matrix (X, V); obj_fcn_history(iteration) = ... - fcm_compute_objective_fcn (Mu_m, sqr_dist); + 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 = ... - fcm_compute_convergence_criterion (V, V_previous); + compute_cluster_convergence (V, V_previous); endwhile ## Remove extraneous entries from the tail of the objective @@ -219,15 +221,18 @@ %!demo %! ## This demo: -%! ## - classifies a small set of unlabeled data points using the -%! ## Fuzzy C-Means algorithm into two fuzzy clusters +%! ## - 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; @@ -241,14 +246,14 @@ %! '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 @@ -258,6 +263,15 @@ %! 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 @@ -265,19 +279,23 @@ %!demo %! ## This demo: -%! ## - classifies three-dimensional unlabeled data points using the -%! ## Fuzzy C-Means algorithm into three fuzzy clusters +%! ## - 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]; +%! 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]) @@ -291,8 +309,8 @@ %! hold on; %! endfor %! -%! ## Plot the cluster centers in two dimensions (using features 1 & 2) -%! ## as larger red *'s. +%! ## 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'); @@ -309,8 +327,8 @@ %! grid %! hold %! -%! ## Plot the data points in two dimensions (using features 1 & 3) -%! ## as small blue x's. +%! ## 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, ... @@ -318,8 +336,8 @@ %! hold on; %! endfor %! -%! ## Plot the cluster centers in two dimensions (using features 1 & 3) -%! ## as larger red *'s. +%! ## 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'); @@ -335,3 +353,12 @@ %! 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)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -27,10 +27,12 @@ ## @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. +## of a set of unlabeled data points. ## ## Also, if @var{display_intermediate_results} is true, display intermediate -## results after each iteration. +## 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 @@ -119,7 +121,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gustafson_kessel.m -## Last-Modified: 26 Aug 2012 +## Last-Modified: 5 Sep 2012 function [cluster_centers, soft_partition, obj_fcn_history] = ... gustafson_kessel (input_data, num_clusters, ... @@ -194,8 +196,8 @@ gustafson_kessel_private (X, k, cluster_volume, m, max_iterations, ... epsilon, display_intermediate_results) - ## Initialize the prototype and the calculation. - V = fcm_init_prototype (X, k); + ## Initialize the prototypes and the calculation. + V = init_cluster_prototypes (X, k); obj_fcn_history = zeros (max_iterations); convergence_criterion = epsilon + 1; iteration = 0; @@ -210,18 +212,18 @@ while (convergence_criterion > epsilon && ... ++iteration <= max_iterations) V_previous = V; - Mu = fcm_update_membership_fcn (V, X, m, k, n, sqr_dist); + Mu = update_cluster_membership (V, X, m, k, n, sqr_dist); Mu_m = Mu .^ m; - V = fcm_update_cluster_centers (Mu_m, X, k); + V = update_cluster_prototypes (Mu_m, X, k); sqr_dist = gk_square_distance_matrix (X, V, Mu_m, cluster_volume); obj_fcn_history(iteration) = ... - fcm_compute_objective_fcn (Mu_m, sqr_dist); + 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 = ... - fcm_compute_convergence_criterion (V, V_previous); + compute_cluster_convergence (V, V_previous); endwhile ## Remove extraneous entries from the tail of the objective ... @@ -289,9 +291,12 @@ %!demo %! ## This demo: -%! ## - classifies a small set of unlabeled data points using the -%! ## Gustafson-Kessel algorithm into two fuzzy clusters +%! ## - 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 @@ -314,8 +319,8 @@ %! %! ## 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'); +%! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... +%! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! @@ -328,26 +333,39 @@ %! 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 +%! ## - 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]; +%! 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], ... @@ -362,11 +380,11 @@ %! hold on; %! endfor %! -%! ## Plot the cluster centers in two dimensions (using features 1 & 2) -%! ## as larger red *'s. +%! ## 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'); +%! plot (cluster_centers(i, 1), cluster_centers(i, 2), ... +%! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! @@ -379,8 +397,8 @@ %! ylabel ('Feature 2'); %! grid %! -%! ## Plot the data points in two dimensions (using features 1 & 3) -%! ## as small blue x's. +%! ## 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, ... @@ -388,11 +406,11 @@ %! hold on; %! endfor %! -%! ## Plot the cluster centers in two dimensions (using features 1 & 3) -%! ## as larger red *'s. +%! ## 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'); +%! plot (cluster_centers(i, 1), cluster_centers(i, 3), ... +%! 'LineWidth', 4, 'marker', '*', 'color', 'r'); %! hold on; %! endfor %! @@ -405,3 +423,12 @@ %! 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)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -39,7 +39,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy hamacher_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: hamacher_product.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = hamacher_product (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -39,7 +39,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy hamacher_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: hamacher_sum.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 function retval = hamacher_sum (x, y = 0) if (nargin == 0 || nargin > 2 || Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -47,7 +47,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy tests demos ## Directory: fuzzy-logic-toolkit/inst ## Filename: heart_disease_demo_1.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 ## Create new FIS. a = newfis ('Heart-Disease-Risk', 'sugeno', ... Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -45,7 +45,7 @@ ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: heart_disease_demo_2.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. ## (Alternatively, to select heart_disease_risk.fis using the dialog, Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_risk.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_risk.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_risk.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,5 +1,29 @@ -# Heart Disease Risk FIS +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. +## 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' Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,3 +1,27 @@ +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## 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' Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_calculator.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_calculator.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_calculator.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,3 +1,27 @@ +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## 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' Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -43,7 +43,7 @@ ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: linear_tip_demo.m -## Last-Modified: 12 Nov 2011 +## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('linear_tip_calculator.fis'); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_calculator.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_calculator.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_calculator.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,3 +1,27 @@ +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## 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' Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -33,6 +33,12 @@ ## @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. ## @@ -44,7 +50,7 @@ ## Keywords: fuzzy-logic-toolkit partition coefficient cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_coeff.m -## Last-Modified: 26 Aug 2012 +## Last-Modified: 4 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.9 (corrected @@ -78,77 +84,3 @@ vpc = (sum (sum (soft_part_sqr))) / columns (soft_partition); endfunction - -##---------------------------------------------------------------------- -## Partition Coefficient Demo #1 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## a small set of unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## 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). -%! -%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] -%! number_of_clusters = 2 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("partition coefficient: %f\n", ... -%! partition_coeff (soft_partition)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("partition coefficient: %f\n\n", ... -%! partition_coeff (soft_partition)); - -##---------------------------------------------------------------------- -## Partition Coefficient Demo #2 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## three-dimensional unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## Note: The input_data was selected to form three areas of -%! ## different shapes. -%! -%! 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 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("partition coefficient: %f\n", ... -%! partition_coeff (soft_partition)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("partition coefficient: %f\n\n", ... -%! partition_coeff (soft_partition)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -35,6 +35,12 @@ ## @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. ## @@ -46,7 +52,7 @@ ## Keywords: fuzzy-logic-toolkit partition entropy cluster ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: partition_entropy.m -## Last-Modified: 26 Aug 2012 +## Last-Modified: 4 Sep 2012 ##---------------------------------------------------------------------- ## Note: This function is an implementation of Equation 13.10 in @@ -86,77 +92,3 @@ vpe = -(sum (sum (Mu .* log_a_Mu))) / n; endfunction - -##---------------------------------------------------------------------- -## Partition Entropy Demo #1 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## a small set of unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## 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). -%! -%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] -%! number_of_clusters = 2 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("partition entropy (with a = 2): %f\n", ... -%! partition_entropy (soft_partition, 2)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("partition entropy (with a = 2): %f\n\n", ... -%! partition_entropy (soft_partition, 2)); - -##---------------------------------------------------------------------- -## Partition Entropy Demo #2 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## three-dimensional unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## Note: The input_data was selected to form three areas of -%! ## different shapes. -%! -%! 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 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("partition entropy (with a = 2): %f\n", ... -%! partition_entropy (soft_partition, 2)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("partition entropy (with a = 2): %f\n\n", ... -%! partition_entropy (soft_partition, 2)); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmmf.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmmf.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -46,7 +46,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy membership ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: rmmf.m -## Last-Modified: 16 Jul 2011 +## Last-Modified: 20 Aug 2012 function fis = rmmf (fis, in_or_out, var_index, mf, mf_index) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_calculator.fis 2012-10-03 00:38:09 UTC (rev 11097) @@ -1,3 +1,27 @@ +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## 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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -49,7 +49,7 @@ ## Dr. Bruce Segee (University of Maine Dept. of ECE). ## Directory: fuzzy-logic-toolkit/inst ## Filename: sugeno_tip_demo.m -## Last-Modified: 10 Nov 2011 +## Last-Modified: 20 Aug 2012 ## Read the FIS structure from a file. fis = readfis ('sugeno_tip_calculator.fis'); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-10-03 00:37:18 UTC (rev 11096) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m 2012-10-03 00:38:09 UTC (rev 11097) @@ -37,6 +37,12 @@ ## @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. @@ -49,7 +55,7 @@ ## Keywords: fuzzy-logic-toolkit fuzzy xie beni cluster validity ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: xie_beni_index.m -## Last-Modified: 26 Aug 2012 +## Last-Modified: 4 Sep 2012 function vxb = xie_beni_index (input_data, cluster_centers, ... soft_partition) @@ -126,77 +132,3 @@ d_sqr_min = min (min (d_sqr_matrix)); endfunction - -##---------------------------------------------------------------------- -## Xie-Beni Index Demo #1 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## a small set of unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## 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). -%! -%! input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] -%! number_of_clusters = 2 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("Xie-Beni index: %f\n", ... -%! xie_beni_index (input_data, cluster_centers, soft_partition)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("Xie-Beni index: %f\n\n", ... -%! xie_beni_index (input_data, cluster_centers, soft_partition)); - -##---------------------------------------------------------------------- -## Xie-Beni Index Demo #2 -##---------------------------------------------------------------------- - -%!demo -%! ## Use the Fuzzy C-Means and Gustafson-Kessel algorithms to classify -%! ## three-dimensional unlabeled data points and evaluate the quality -%! ## of the resulting clusters. -%! -%! ## Note: The input_data was selected to form three areas of -%! ## different shapes. -%! -%! 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 -%! -%! ## Using fcm, classify the input data, print the cluster centers, -%! ## and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! fcm (input_data, number_of_clusters, [NaN NaN NaN 0]); -%! puts ("\nResults using the Fuzzy C-Means algorithm:\n\n"); -%! cluster_centers -%! printf ("Xie-Beni index: %f\n", ... -%! xie_beni_index (input_data, cluster_centers, soft_partition)); -%! -%! ## Using gustafson_kessel, classify the input data, print the cluster -%! ## centers, and calculate and print the partition coefficient. -%! [cluster_centers, soft_partition, obj_fcn_history] = ... -%! gustafson_kessel (input_data, number_of_clusters, [1 1 1], ... -%! [NaN NaN NaN 0]); -%! puts ("\nResults using the Gustafson-Kessel algorithm:\n\n"); -%! cluster_centers -%! printf ("Xie-Beni index: %f\n\n", ... -%! xie_beni_index (input_data, cluster_centers, soft_partition)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <lm...@us...> - 2012-07-09 13:17:26
|
Revision: 10739 http://octave.svn.sourceforge.net/octave/?rev=10739&view=rev Author: lmarkov Date: 2012-07-09 13:17:11 +0000 (Mon, 09 Jul 2012) Log Message: ----------- A inst/gustafson_kessel_demo_1.m A inst/gustafson_kessel_demo_2.m A inst/partition_coeff.m A inst/fcm.m A inst/xie_beni_index.m A inst/gustafson_kessel.m A inst/private/square_distance_matrix.m A inst/private/fcm_init_prototype.m A inst/private/fcm_update_cluster_centers.m A inst/private/fcm_compute_convergence_criterion.m A inst/private/fcm_update_membership_fcn.m A inst/private/fcm_compute_objective_fcn.m A inst/fcm_demo_1.m A inst/partition_entropy.m A inst/fcm_demo_2.m Added Paths: ----------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_convergence_criterion.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_objective_fcn.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_init_prototype.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_cluster_centers.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_membership_fcn.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/square_distance_matrix.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,204 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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}]) +## +## 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. +## +## 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{fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: fcm.m +## Last-Modified: 8 July 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 (optional) 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 prototype and the calculation. + V = fcm_init_prototype (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 = fcm_update_membership_fcn (V, X, m, k, n, sqr_dist); + Mu_m = Mu .^ m; + V = fcm_update_cluster_centers (Mu_m, X, k); + sqr_dist = square_distance_matrix (X, V); + obj_fcn_history(iteration) = fcm_compute_objective_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 = fcm_compute_convergence_criterion (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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,90 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Script File} {} fcm_demo_1 +## Use the Fuzzy C-Means algorithm to classify unlabeled data points and +## evaluate the quality of the resulting clusters. +## +## This demo: +## @itemize @minus +## @item +## classifies a small set of unlabeled data points using the Fuzzy C-Means +## algorithm into two fuzzy clusters +## @item +## calculates and prints (on standard output) three validity measures: +## the partition coefficient, the partition entropy, and the Xie-Beni +## validity index +## @item +## plots the input points together with the cluster centers +## @end itemize +## +## For a description of the data structures used in the script, see the +## documentation for fcm. +## +## @seealso{fcm, fcm_demo_2, partition_coeff, partition_entropy, xie_beni_index, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: fcm_demo_1.m +## Last-Modified: 8 July 2012 + +##------------------------------------------------------------------------------ +## 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 data in matrix x. +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) + +## 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)); + +## 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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,121 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Script File} {} fcm_demo_2 +## Use the Fuzzy C-Means algorithm to classify unlabeled data points and +## evaluate the quality of the resulting clusters. +## +## The demo: +## @itemize @minus +## @item +## classifies three-dimensional unlabeled data points using the Fuzzy +## C-Means algorithm into three fuzzy clusters +## @item +## calculates and prints (on standard output) three validity measures: +## the partition coefficient, the partition entropy, and the Xie-Beni +## validity index +## @item +## plots the input points together with the cluster centers +## @end itemize +## +## For a description of the data structures used in the script, see the +## documentation for fcm. +## +## @seealso{fcm, fcm_demo_1, partition_coeff, partition_entropy, xie_beni_index, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: fcm_demo_2.m +## Last-Modified: 8 July 2012 + +##------------------------------------------------------------------------------ +## Note: The input_data was selected to form three areas of different shapes. +##------------------------------------------------------------------------------ + +## Use fcm to classify the data in matrix x. +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]) + +## 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)); + +## Plot the data points in two dimensions (using features 1 and 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 and 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 and 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 and 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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,272 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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}]) +## +## 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. +## +## 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, fcm_demo_1, fcm_demo_2, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering gustafson_kessel +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: gustafson_kessel.m +## Last-Modified: 8 July 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 first argument must be matrix of real numbers\n"); + elseif (!(is_int (num_clusters) && (num_clusters > 1))) + puts ("Type 'help gustafson_kessel' for more information.\n"); + error ("gustafson_kessel's second argument must be an integer greater than 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 third (optional) argument must be a vector of real numbers\n"); + elseif (!(isreal (options) && isvector (options))) + puts ("Type 'help gustafson_kessel' for more information.\n"); + error ("gustafson_kessel's fourth (optional) argument must be a vector of real numbers\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 prototype and the calculation. + V = fcm_init_prototype (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 = fcm_update_membership_fcn (V, X, m, k, n, sqr_dist); + Mu_m = Mu .^ m; + V = fcm_update_cluster_centers (Mu_m, X, k); + sqr_dist = gk_square_distance_matrix (X, V, Mu_m, cluster_volume); + obj_fcn_history(iteration) = fcm_compute_objective_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 = fcm_compute_convergence_criterion (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 + Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,90 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Script File} {} gustafson_kessel_demo_1 +## Use the Gustafson-Kessel algorithm to classify unlabeled data points and +## evaluate the quality of the resulting clusters. +## +## The demo: +## @itemize @minus +## @item +## classifies a small set of unlabeled data points using the Gustafson-Kessel +## algorithm into two fuzzy clusters +## @item +## calculates and prints (on standard output) three validity measures: +## the partition coefficient, the partition entropy, and the Xie-Beni +## validity index +## @item +## plots the input points together with the cluster centers +## @end itemize +## +## For a description of the data structures used in the script, see the +## documentation for gustafson_kessel. +## +## @seealso{gustafson_kessel, gustafson_kessel_demo_2, partition_coeff, partition_entropy, xie_beni_index, fcm, fcm_demo_1, fcm_demo_2} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering gustafson_kessel demo +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: gustafson_kessel_demo_1.m +## Last-Modified: 8 July 2012 + +##------------------------------------------------------------------------------ +## 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 data in matrix x. +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) + +## 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)); + +## 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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,120 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Script File} {} gustafson_kessel_demo_2 +## Use the Gustafson-Kessel algorithm to classify unlabeled data points and +## evaluate the quality of the resulting clusters. +## +## The demo: +## @itemize @minus +## @item +## classifies three-dimensional unlabeled data points using the +## Gustafson-Kessel algorithm into three fuzzy clusters +## @item +## calculates and prints (on standard output) three validity measures: +## the partition coefficient, the partition entropy, and the Xie-Beni +## validity index +## @item +## plots the input points together with the cluster centers +## @end itemize +## +## For a description of the data structures used in the script, see the +## documentation for gustafson_kessel. +## +## @seealso{gustafson_kessel, gustafson_kessel_demo_1, partition_coeff, partition_entropy, xie_beni_index, fcm, fcm_demo_1, fcm_demo_2} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: gustafson_kessel_demo_2.m +## Last-Modified: 8 July 2012 + +##------------------------------------------------------------------------------ +## Note: The input_data was selected to form three areas of different shapes. +##------------------------------------------------------------------------------ + +## Use gustafson_kessel to classify the data in matrix x. +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]) + +## 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)); + +## Plot the data points in two dimensions (using features 1 and 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 and 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 and 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 and 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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,76 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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 more information about the @var{soft_partition} matrix, please see the +## documentation for function fcm. +## +## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_entropy, xie_beni_index} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition coefficient cluster validity +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: partition_coeff.m +## Last-Modified: 8 July 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"); + error ("partition_coeff's argument must be a matrix of real numbers mu, with 0 <= mu <= 1\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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,82 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{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 more information about the @var{soft_partition} matrix, please see the +## documentation for function fcm. +## +## @seealso{fcm, fcm_demo_1, fcm_demo_2, gustafson_kessel, gustafson_kessel_demo_1, gustafson_kessel_demo_2, partition_coeff, xie_beni_index} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition entropy cluster validity +## Directory: fuzzy-logic-toolkit/inst/ +## Filename: partition_entropy.m +## Last-Modified: 8 July 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"); + error ("partition_entropy's first argument must be a matrix of real numbers mu, with 0 <= mu <= 1\n"); + elseif (!(is_real (a) && a > 1)) + puts ("Type 'help partition_entropy' for more information.\n"); + error ("partition_entropy's second argument argument must be a real number a > 1\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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_convergence_criterion.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_convergence_criterion.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_convergence_criterion.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,40 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{convergence_criterion} =} fcm_compute_convergence_criterion (@var{V}, @var{V_previous}) +## +## Compute the sum of the changes in position (using the Euclidean +## distance) of the cluster centers. +## +## @seealso{fcm, fcm_init_prototype, fcm_update_membership_fcn, fcm_update_cluster_centers, fcm_compute_objective_fcn} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm private +## Directory: fuzzy-logic-toolkit/inst/private/ +## Filename: fcm_compute_convergence_criterion.m +## Last-Modified: 7 July 2012 + +function convergence_criterion = fcm_compute_convergence_criterion (V, V_previous) + + V_delta = V - V_previous; + convergence_criterion = sum (sqrt (sum (V_delta .* V_delta)')); + +endfunction Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_objective_fcn.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_objective_fcn.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_compute_objective_fcn.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,44 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{obj_fcn} =} fcm_compute_objective_fcn (@var{Mu_m}, @var{sqr_dist}) +## +## Compute the objective function for the current iteration. +## +## @seealso{fcm, fcm_init_prototype, fcm_update_membership_fcn, fcm_update_cluster_centers, fcm_compute_convergence_criterion} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm private +## Directory: fuzzy-logic-toolkit/inst/private/ +## Filename: fcm_compute_objective_fcn.m +## Last-Modified: 7 July 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 = fcm_compute_objective_fcn (Mu_m, sqr_dist) + + obj_fcn = sum (sum (Mu_m .* sqr_dist)); + +endfunction Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_init_prototype.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_init_prototype.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_init_prototype.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,47 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{V} =} fcm_init_prototype (@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, fcm_update_membership_fcn, fcm_update_cluster_centers, fcm_compute_objective_fcn, fcm_compute_convergence_criterion} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm private +## Directory: fuzzy-logic-toolkit/inst/private/ +## Filename: fcm_init_prototype.m +## Last-Modified: 7 July 2012 + +function V = fcm_init_prototype (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 Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_cluster_centers.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_cluster_centers.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_cluster_centers.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,54 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{V} =} fcm_update_cluster_centers (@var{Mu_m}, @var{X}, @var{k}) +## +## Update the cluster centers to correspond to the given membership +## function values. +## +## @seealso{fcm, fcm_init_prototype, fcm_update_membership_fcn, fcm_compute_objective_fcn, fcm_compute_convergence_criterion} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm private +## Directory: fuzzy-logic-toolkit/inst/private/ +## Filename: fcm_update_cluster_centers.m +## Last-Modified: 7 July 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 = fcm_update_cluster_centers (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 fcm_update_cluster_centers\n"); + endif + + for i = 1 : k + V(i, :) /= sum_Mu_m(i); + endfor + +endfunction Added: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_membership_fcn.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_membership_fcn.m (rev 0) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/private/fcm_update_membership_fcn.m 2012-07-09 13:17:11 UTC (rev 10739) @@ -0,0 +1,75 @@ +## Copyright (C) 2012 L. Markowsky <lm...@us...> +## +## This file is part of the fuzzy-logic-toolkit. +## +## The fuzzy-logic-toolkit is free software; you can redistribute it +## and/or modify it under the terms of the GNU General Public License +## as published by the Free Software Foundation; either version 3 of +## the License, or (at your option) any later version. +## +## The fuzzy-logic-toolkit is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the fuzzy-logic-toolkit; see the file COPYING. If not, +## see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{Mu} =} fcm_update_membership_fcn (@var{V}, @var{X}, @var{m}, @var{k}, @var{n}, @var{sqr_dist}) +## +## Compute Mu for each (cluster center, input point) pair. +## +## @seealso{fcm, fcm_init_prototype, fcm_update_cluster_centers, fcm_compute_objective_fcn, fcm_compute_convergence_criterion} +## +## @end deftypefn + +## Author: L. Markowsky +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm private +## Directory: fuzzy-logic-toolkit/inst/private/ +## Filename: fcm_update_membership_fcn.m +## Last-Modified: 7 July 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 = fcm_update_membership_fcn (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, ... [truncated message content] |
From: <lm...@us...> - 2012-08-24 16:13:17
|
Revision: 10909 http://octave.svn.sourceforge.net/octave/?rev=10909&view=rev Author: lmarkov Date: 2012-08-24 16:13:07 +0000 (Fri, 24 Aug 2012) Log Message: ----------- M inst/getfis.m M inst/psigmf.m M inst/smf.m M inst/rmvar.m M inst/partition_entropy.m M inst/trapmf.m M inst/bounded_difference.m M inst/newfis.m M inst/pimf.m M inst/zmf.m M inst/hamacher_sum.m M inst/setfis.m M inst/plotmf.m M inst/rmmf.m M inst/einstein_sum.m M inst/gustafson_kessel_demo_1.m M inst/gustafson_kessel_demo_2.m M inst/defuzz.m M inst/gbellmf.m M inst/gensurf.m M inst/algebraic_product.m M inst/xie_beni_index.m M inst/evalmf.m M inst/partition_coeff.m M inst/gustafson_kessel.m M inst/sugeno_tip_demo.m M inst/trimf.m M inst/cubic_approx_demo.m M inst/showfis.m M inst/heart_disease_demo_1.m M inst/heart_disease_demo_2.m M inst/mamdani_tip_demo.m M inst/gauss2mf.m M inst/drastic_product.m M inst/fcm_demo_1.m M inst/evalfis.m M inst/fcm_demo_2.m M inst/linear_tip_demo.m M inst/writefis.m M inst/algebraic_sum.m M inst/investment_portfolio_demo.m M inst/addvar.m M inst/bounded_sum.m M inst/gaussmf.m M inst/fcm.m M inst/sigmf.m M inst/hamacher_product.m M inst/showrule.m M inst/dsigmf.m M inst/addmf.m M inst/drastic_sum.m M inst/readfis.m M inst/einstein_product.m M inst/addrule.m Modified Paths: -------------- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/defuzz.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gustafson_kessel_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_product.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/hamacher_sum.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_1.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/heart_disease_demo_2.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/investment_portfolio_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/linear_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/mamdani_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/newfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_coeff.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/partition_entropy.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/pimf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/plotmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/psigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/readfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/rmvar.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/setfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/showfis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/showrule.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sigmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/smf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/sugeno_tip_demo.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/trapmf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/trimf.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/writefis.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/xie_beni_index.m trunk/octave-forge/main/fuzzy-logic-toolkit/inst/zmf.m Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addmf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -59,17 +59,18 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function membership +## 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: 28 Oct 2011 +## Last-Modified: 18 Aug 2012 -function fis = addmf (fis, in_or_out, var_index, mf_name, mf_type, mf_params) +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 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"); @@ -92,9 +93,11 @@ error ("addmf's sixth argument must be a vector of parameters\n"); endif - ## Create a new membership function struct and update the FIS structure. + ## Create a new membership function struct and update the + ## FIS structure. - new_mf = struct ('name', mf_name, 'type', mf_type, 'params', mf_params); + 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; @@ -119,9 +122,12 @@ %! ## 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, '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]); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addrule.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -84,12 +84,12 @@ ## Keywords: fuzzy-logic-toolkit fuzzy rule ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addrule.m -## Last-Modified: 11 Nov 2011 +## 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 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"); @@ -98,19 +98,20 @@ 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.\n"); - error ("addrule's second argument must be a matrix of real numbers\n"); + 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. + ## 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)); + 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, ... Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/addvar.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -46,12 +46,12 @@ ## Keywords: fuzzy-logic-toolkit fuzzy variable ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: addvar.m -## Last-Modified: 28 Oct 2011 +## 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 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"); @@ -74,7 +74,8 @@ ## Create a new variable struct and update the FIS input or output ## variable list. - new_variable = struct ('name', var_name, 'range', var_range, 'mf', []); + 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; Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_product.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -37,14 +37,17 @@ ## Keywords: fuzzy-logic-toolkit fuzzy algebraic_product ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: algebraic_product.m -## Last-Modified: 12 Nov 2011 +## 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 ("algebraic_product requires real scalar or matrix arguments\n"); + error ("invalid arguments to function algebraic_product\n"); elseif (nargin == 2 && ... - (isscalar (x) || isscalar (y) || isequal (size (x), size (y)))) + (isscalar (x) || isscalar (y) || ... + isequal (size (x), size (y)))) retval = x .* y; elseif (nargin == 1 && ndims (x) <= 2) retval = prod (x); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/algebraic_sum.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -37,14 +37,15 @@ ## Keywords: fuzzy-logic-toolkit fuzzy algebraic_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: algebraic_sum.m -## Last-Modified: 12 Nov 2011 +## 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)))) + (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); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_difference.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -38,14 +38,17 @@ ## Keywords: fuzzy-logic-toolkit fuzzy bounded_difference ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: bounded_difference.m -## Last-Modified: 12 Nov 2011 +## 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 ("bounded_difference requires real scalar or matrix arguments\n"); + error ("invalid arguments to function bounded_difference\n"); elseif (nargin == 2 && ... - (isscalar (x) || isscalar (y) || isequal (size (x), size (y)))) + (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); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/bounded_sum.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -37,14 +37,15 @@ ## Keywords: fuzzy-logic-toolkit fuzzy bounded_sum ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: bounded_sum.m -## Last-Modified: 12 Nov 2011 +## 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)))) + (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); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/cubic_approx_demo.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/defuzz.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/defuzz.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/defuzz.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -53,14 +53,14 @@ ## Keywords: fuzzy-logic-toolkit fuzzy defuzzification ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: defuzz.m -## Last-Modified: 16 Jul 2011 +## 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 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"); @@ -70,31 +70,31 @@ 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 second argument must be a real number or vector\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. + ## 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). +## (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. -##------------------------------------------------------------------------------ +## 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) @@ -102,7 +102,7 @@ endfunction -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- ## Usage: crisp_x = bisector (x, y) ## crisp_x = bisector ([x1 x2 ... xn], [y1 y2 ... yn]) ## @@ -111,15 +111,15 @@ ## 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. -##------------------------------------------------------------------------------ +## 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. + ## 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); @@ -145,18 +145,19 @@ 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. +## (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. -##------------------------------------------------------------------------------ +## 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) @@ -167,18 +168,19 @@ 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. +## (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. -##------------------------------------------------------------------------------ +## 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) @@ -189,18 +191,18 @@ 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. +## (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. -##------------------------------------------------------------------------------ +## 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) @@ -211,17 +213,17 @@ 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. +## 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) @@ -229,17 +231,17 @@ 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. +## 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) Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_product.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/drastic_sum.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/dsigmf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -65,15 +65,15 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function sigmoidal +## Keywords: fuzzy-logic-toolkit fuzzy membership sigmoidal ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: dsigmf.m -## Last-Modified: 28 Oct 2011 +## 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 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"); @@ -94,8 +94,9 @@ 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_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 Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_product.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/einstein_sum.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalfis.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -232,16 +232,17 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis +## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalfis.m -## Last-Modified: 12 Nov 2011 +## 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 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"); @@ -251,7 +252,7 @@ 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 first argument must be a matrix of input values\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"); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/evalmf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -58,15 +58,15 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function evaluate +## Keywords: fuzzy-logic-toolkit fuzzy membership evaluate ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: evalmf.m -## Last-Modified: 13 Nov 2011 +## Last-Modified: 19 Aug 2012 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 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"); @@ -85,8 +85,8 @@ 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. + ## Calculate and return the y values of the membership function on + ## the domain x. y = evalmf_private (x, params, mf_type, hedge, not_flag); @@ -97,7 +97,8 @@ %! params = [25 50 75]; %! mf_type = 'trimf'; %! y = evalmf(x, params, mf_type); -%! figure('NumberTitle', 'off', 'Name', "evalmf(0:100, [25 50 75], 'trimf')"); +%! 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'); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2012 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -114,13 +114,14 @@ ## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm.m -## Last-Modified: 10 July 2012 +## Last-Modified: 19 Aug 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. + ## 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"); @@ -133,17 +134,19 @@ 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 (optional) argument must be a vector of real numbers\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. + ## 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))) + if ((length (options) < i) || ... + isna (options(i)) || isnan (options(i))) options(i) = default_options(i); endif endfor @@ -160,16 +163,17 @@ 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. -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- +## 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) + fcm_private (X, k, m, max_iterations, epsilon, ... + display_intermediate_results) ## Initialize the prototype and the calculation. V = fcm_init_prototype (X, k); @@ -182,23 +186,27 @@ 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) + ## 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 = fcm_update_membership_fcn (V, X, m, k, n, sqr_dist); Mu_m = Mu .^ m; V = fcm_update_cluster_centers (Mu_m, X, k); sqr_dist = square_distance_matrix (X, V); - obj_fcn_history(iteration) = fcm_compute_objective_fcn (Mu_m, sqr_dist); + obj_fcn_history(iteration) = ... + fcm_compute_objective_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 = fcm_compute_convergence_criterion (V, V_previous); + convergence_criterion = ... + fcm_compute_convergence_criterion (V, V_previous); endwhile - ## Remove extraneous entries from the tail of the objective function history. + ## Remove extraneous entries from the tail of the objective + ## function history. if (convergence_criterion <= epsilon) obj_fcn_history = obj_fcn_history(1 : iteration); endif Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_1.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2012 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -42,16 +42,17 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm_demo_1.m -## Last-Modified: 10 July 2012 +## Last-Modified: 19 Aug 2012 -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- ## 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). -##------------------------------------------------------------------------------ +## Fuzzy Logic: Intelligence, Control and Information, by J. Yen +## and R. Langari, Prentice Hall, 1999, page 381 (International +## Edition). +##---------------------------------------------------------------------- ## Use fcm to classify the data in matrix x. input_data = [2 12; 4 9; 7 13; 11 5; 12 7; 14 4] @@ -60,22 +61,25 @@ fcm (input_data, number_of_clusters) ## 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)); +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)); ## 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'); + 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'); + plot (cluster_centers(i, 1), cluster_centers(i, 2), 'LineWidth', ... + 4, 'marker', '*', 'color', 'r'); hold on; endfor Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/fcm_demo_2.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2012 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -42,44 +42,48 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm demo +## Keywords: fuzzy-logic-toolkit fuzzy partition clustering fcm ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: fcm_demo_2.m -## Last-Modified: 10 July 2012 +## Last-Modified: 19 Aug 2012 -##------------------------------------------------------------------------------ -## Note: The input_data was selected to form three areas of different shapes. -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- +## Note: The input_data was selected to form three areas of different +## shapes. +##---------------------------------------------------------------------- ## Use fcm to classify the data in matrix x. -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] +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]) ## 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)); +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)); ## Plot the data points in two dimensions (using features 1 and 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'); + 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 and 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'); + plot (cluster_centers(i, 1), cluster_centers(i, 2), 'LineWidth', ... + 4, 'marker', '*', 'color', 'r'); hold on; endfor @@ -97,16 +101,16 @@ ## 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'); + 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 and 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'); + plot (cluster_centers(i, 1), cluster_centers(i, 3), 'LineWidth', ... + 4, 'marker', '*', 'color', 'r'); hold on; endfor Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gauss2mf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -64,15 +64,15 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function gaussian +## Keywords: fuzzy-logic-toolkit fuzzy membership gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gauss2mf.m -## Last-Modified: 28 Oct 2011 +## 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 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"); @@ -85,16 +85,17 @@ 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. + ## 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)) + ... + 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) + ... Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gaussmf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -60,15 +60,15 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function gaussian +## Keywords: fuzzy-logic-toolkit fuzzy membership gaussian ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gaussmf.m -## Last-Modified: 28 Oct 2011 +## 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 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"); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gbellmf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -64,15 +64,15 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy membership-function bell-shaped bell +## Keywords: fuzzy-logic-toolkit fuzzy membership bell-shaped bell ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gbellmf.m -## Last-Modified: 28 Oct 2011 +## 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 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"); Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/gensurf.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -70,7 +70,7 @@ ## sugeno_tip_demo.m ## @end itemize ## -## CURRENT LIMITATION: +## Current limitation: ## The form of gensurf that suppresses plotting (the final form above) is not yet ## implemented. ## @@ -78,16 +78,18 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis plot +## Keywords: fuzzy-logic-toolkit fuzzy inference system fis plot ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: gensurf.m -## Last-Modified: 11 Nov 2011 +## 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) +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 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"); @@ -103,32 +105,34 @@ 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 fourth argument must be a valid grid specification\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 fifth argument must specify reference input values\n"); - elseif ((nargin == 6) && !(is_pos_int (num_points) && (num_points >= 2))) + 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 to gensurf must be an integer >= 2\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); + 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); + 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) +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. @@ -163,14 +167,14 @@ endfunction -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- ## Function: generate_surface -## Purpose: Generate a surface representing one of the FIS outputs as a -## function of two of the FIS inputs. -##------------------------------------------------------------------------------ +## 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) +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. @@ -203,7 +207,8 @@ ## 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)); + z_matrix = reshape (output(:, output_axis), length (x_axis), ... + length (y_axis)); ## Plot the surface. Modified: trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m =================================================================== --- trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2012-08-24 16:11:37 UTC (rev 10908) +++ trunk/octave-forge/main/fuzzy-logic-toolkit/inst/getfis.m 2012-08-24 16:13:07 UTC (rev 10909) @@ -1,4 +1,4 @@ -## Copyright (C) 2011 L. Markowsky <lm...@us...> +## Copyright (C) 2011-2012 L. Markowsky <lm...@us...> ## ## This file is part of the fuzzy-logic-toolkit. ## @@ -90,15 +90,16 @@ ## @end deftypefn ## Author: L. Markowsky -## Keywords: fuzzy-logic-toolkit fuzzy fuzzy-inference-system fis +## Keywords: fuzzy-logic-toolkit fuzzy inference system fis ## Directory: fuzzy-logic-toolkit/inst/ ## Filename: getfis.m -## Last-Modified: 31 Oct 2011 +## Last-Modified: 20 Aug 2012 -##------------------------------------------------------------------------------ +##---------------------------------------------------------------------- function retval = getfis (fis, arg2 = 'dummy', arg3 = 'dummy', ... - arg4 = 'dummy', arg5 = 'dummy', arg6 = 'dummy') + arg4 = 'dummy', arg5 = 'dummy', ... + arg6 = 'dummy') switch (nargin) case 1 retval = getfis_one_arg (fis); @@ -106,7 +107,8 @@ 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); + 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"); @@ -114,11 +116,11 @@ 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. -##------------------------------------------------------------------------------ +## Purpose... [truncated message content] |