Skip to content

Commit

Permalink
r.fuzzy.set: correction of sshape formula in fuzzy.c (#931)
Browse files Browse the repository at this point in the history
This PR corrects two issues with how the S-shape rescaling was implemented for negative values of the shape parameter. This includes the issue reported in #931.

In addition, in the manual page r.fuzzy.set.html, the description of the equations were updated to ensure that they match the equations as implemented in the code. And an issue with a wrongly formatted URL was corrected.
  • Loading branch information
ecodiv committed Sep 24, 2023
1 parent 3b32649 commit ebc612c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/raster/r.fuzzy.set/fuzzy.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <grass/glocale.h>
#include "local_proto.h"
#include <math.h>

float fuzzy(FCELL cell)
{
Expand Down Expand Up @@ -42,8 +43,8 @@ float fuzzy(FCELL cell)
}

if (type == SSHAPE) {
m = pow(2, exp(2 * abs(shape)));
return (shape < 0) ? pow(1 - cos(x * PI2), m) : pow(sin(x * PI2), m);
m = pow(2, exp(2 * fabs(shape)));
return (shape < 0) ? 1 - pow(cos(x * PI2), m) : pow(sin(x * PI2), m);
}

return -1; /* error */
Expand Down
33 changes: 19 additions & 14 deletions src/raster/r.fuzzy.set/r.fuzzy.set.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h4>Calculation of boundary shape</h4>
Depending on type of the boundary different equation are used to determine its
shape:
<p>
<b>Linear:</b> the membership is calculated according following equation:<br>
<b>Linear:</b> the membership is calculated according following equation:
<pre><code>
value <= A -> x = 0
A < value > B -> x = (value-A)/(B-A)
Expand All @@ -87,33 +87,38 @@ <h4>Calculation of boundary shape</h4>
</code></pre>

<p>
<b>S-shaped:</b> it use following equation:
<b>S-shaped:</b> the membership is calculated according following equation:
<pre><code>
sin(x * Pi/2)^m (for positive shape parameter)
1-cos(x * Pi/2)^m (for negative shape parameter)

where x: membership, and
m = 2^exp(2,shape) (for positive shape parameter)
m = 2^(1+shape) (for negative shape parameter)
where m: shape parameter.
m = 2^exp(2 * |shape|)
For default shape=0, m = 2 (most common parameter for that equation).
</code></pre>

For default shape parameter = 0 m is = 2 which is most common parameter for
that equation.
<p>
<b>G-shaped:</b> the membership is calculated according following equation:
<pre><code>
tan(x * Pi/4)^1/m

where x: membership, and
m = 2^exp(-2 * shape) (for negative shape parameter)
m = 2^(1-shape) (for positive shape parameter)
For default shape=0, m = 2 (most common parameter for that equation).
</code></pre>

<p>
<b>G-shaped and J shaped:</b> it use following equations:
<b>J shaped:</b> it use following equations:
<pre><code>
tan(x * Pi/4)^m (for J-shaped)
tan(x * Pi/4)^1/m (for G-shaped)
tan(x * Pi/4)^m

where x: membership, and
m = 2^exp(2,shape) (for positive shape parameter)
m = 2^exp(2 * shape) (for positive shape parameter)
m = 2^(1+shape) (for negative shape parameter)
where m: shape parameter.
For default shape=0, m = 2 (most common parameter for that equation).
</code></pre>


<h2>SEE ALSO</h2>

<em>
Expand All @@ -130,7 +135,7 @@ <h2>REFERENCES</h2>
Computers & Geosciences (37) 1525-1531. DOI <a href=https://doi.org/10.1016/j.cageo.2010.09.008>https://doi.org/10.1016/j.cageo.2010.09.008</a>

<li>Zadeh, L.A. (1965). "Fuzzy sets". Information and Control 8 (3): 338–353.
<a href="https://doi.org/10.1016/S0019-9958(65)90241-X"><a href="https://doi.org/10.1016/S0019-9958(65)90241-X"</a>.
<a href="https://doi.org/10.1016/S0019-9958(65)90241-X">https://doi.org/10.1016/S0019-9958(65)90241-X</a>.

<li>Novák, Vilém (1989). Fuzzy Sets and Their Applications. Bristol: Adam Hilger.
ISBN 0-85274-583-4.
Expand Down

0 comments on commit ebc612c

Please sign in to comment.