-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigmf.m
99 lines (89 loc) · 3.04 KB
/
sigmf.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
## Copyright (C) 2011-2014 L. Markowsky <[email protected]>
##
## 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{y} =} sigmf (@var{x}, @var{params})
## @deftypefnx {Function File} {@var{y} =} sigmf (@var{[x1 x2 ... xn]}, @var{[a c]})
##
## For a given domain @var{x} and parameters @var{params} (or @var{[a c]}),
## return the corresponding @var{y} values for the sigmoidal membership
## function.
##
## The argument @var{x} must be a real number or a non-empty vector of strictly
## increasing real numbers, and @var{a} and @var{c} must be real numbers. This
## membership function satisfies the equation:
## @itemize @w
## @item
## f(x) = 1/(1 + exp(-a*(x - c)))
## @end itemize
##
## @noindent
## which always returns values in the range [0, 1].
##
## The parameters a and c specify:
## @itemize @w
## @item
## a == the slope at c
## @item
## c == the inflection point
## @end itemize
##
## @noindent
## and at the inflection point, the value of the function is 0.5:
## @itemize @w
## @item
## f(c) == 0.5.
## @end itemize
##
## @noindent
## To run the demonstration code, type @t{demo('sigmf')} at the Octave prompt.
##
## @seealso{dsigmf, gauss2mf, gaussmf, gbellmf, pimf, psigmf, smf, trapmf, trimf, zmf}
## @end deftypefn
## Author: L. Markowsky
## Keywords: fuzzy-logic-toolkit fuzzy membership sigmoidal
## Directory: fuzzy-logic-toolkit/inst/
## Filename: sigmf.m
## Last-Modified: 19 Aug 2012
function y = sigmf (x, params)
## If the caller did not supply 2 argument values with the correct
## types, print an error message and halt.
## Calculate and return the y values of the membership function on the
## domain x.
a = params(1);
c = params(2);
y_val = @(x_val) 1 / (1 + exp (-a * (x_val - c)));
y = arrayfun (y_val, x);
endfunction
%!demo
%! x = 0:100;
%! params = [0.3 40];
%! y1 = sigmf(x, params);
%! params = [0.2 40];
%! y2 = sigmf(x, params);
%! params = [0.1 40];
%! y3 = sigmf(x, params);
%! figure('NumberTitle', 'off', 'Name', 'sigmf demo');
%! plot(x, y1, 'r;params = [0.3 40];', 'LineWidth', 2)
%! hold on;
%! plot(x, y2, 'b;params = [0.2 40];', 'LineWidth', 2)
%! hold on;
%! plot(x, y3, 'g;params = [0.1 40];', 'LineWidth', 2)
%! ylim([-0.1 1.2]);
%! xlabel('Crisp Input Value', 'FontWeight', 'bold');
%! ylabel('Degree of Membership', 'FontWeight', 'bold');
%! grid;