[Bug] r.fuzzy.system: incorrect output
Name of the addon
r.fuzzy.system
Describe the bug
The output of r.fuzzy.system does not label the raster correctly. The output result is a DCELL raster with values defined by the defuzzification rules, AND labels for each value that provide the fuzzy set values prior to the defuzzification. Those labels are incorrect. The numerical values may also be incorrect, but I need to dig into this further before I can be certain.
To Reproduce
Run a simple r.fuzzy.system and examine the outputs. Visually the output raster appears correct, but the labels assign the wrong fuzzy classes. I'm also concerned that the output is not just labeled incorrectly, but is also numerically incorrect.
Example to be run in nc_spm_08_grass7
# distance to major roads
g.region raster=roadsmajor
r.grow.distance -m input=roadsmajor distance=dist
# crisp result
cat << EOF | r.reclass rules=- input=dist output=crisp
0 thru 1500 = 1 near
1500 thru 99999 = 2 far
EOF
cat << EOF > fuzzy.map
# fuzzy maps for example
% dist
$ near {right; 1000, 2000; linear; 0; 1}
$ far {left; 1000, 2000; linear; 0; 1}
% _OUTPUT_
$ near {right; 40,60; linear; 0;1}
$ far {left; 40,60; linear; 0;1}
EOF
cat << EOF > fuzzy.rules
# fuzzy rules for example
$ near { dist = near }
$ far { dist = far }
EOF
r.fuzzy.system -m maps=fuzzy.map rules=fuzzy.rules output=fuzzy
Expected behavior Correct labeling
Screenshots
Crisp result

Fuzzy result

But, clicking near a road shows this:

Having both near=1.0 and far=1.0 is incorrect. That situation should never exist, because near = 1 output occurs when dist = near, which is defined as dist < 1000. From 1000 to 2000 dist is still near, but with membership < 1.0. Furthermore, output with far = 1 occurs when dist = far, which only occurs with full membeship (far = 1) for dist > 2000. The two do not overlap.
Examining the fuzzy_near and fuzzy_far maps made with the -m option to r.fuzzy.system verifies that the membership with fuzzy_far is 0 if you click near a road.
Finally, maximum fuzzy values are never equal to 1 (full membership) even when they should be - for example when fuzzy_near = 1 and fuzzy_far = 0, regardless of the implication, family, or defuz options selected. From this I question the correctness of the numerical results, not just the label results.
System description (please complete the following information): Linux, GRASS GIS 7.8.2
Rather than clicking to diagnose the bug, it can be seen via the CLI with r.what. Here we examine a few rasters twice - once on a road (dist = 0) and once > 3 km from a road.
r.what -fin map=dist,roadsmajor,fuzzy_near,fuzzy_far,fuzzy coordinates=633520,223730 |column -n -s"|" -t
r.what -fin map=dist,roadsmajor,fuzzy_near,fuzzy_far,fuzzy coordinates=642731,226221 |column -n -s"|" -t
Note in the output that both have near = 1.0 far = 1.0 as labels.
easting northing site_name dist dist_label roadsmajor roadsmajor_label fuzzy_near fuzzy_near_label fuzzy_far fuzzy_far_label fuzzy fuzzy_label
633520 223730 0 1 1 0 21 near=1.00 far=1.00
easting northing site_name dist dist_label roadsmajor roadsmajor_label fuzzy_near fuzzy_near_label fuzzy_far fuzzy_far_label fuzzy fuzzy_label
642731 226221 3824 * 0 1 78 near=1.00 far=1.00
I'm not sure what the link to #253 above is doing. Related to r.fuzzy, see #175.