I am creating a simplified example demonstrating the veracity of fuzzy logic. The problem is determining the veracity of the result.
My first problem: checking the meaning of truth between a high and a low target, does it really use fuzzy logic?
My second problem: Truth% seems wrong for target / threshold hits.
Results:
Miss: 30
Hit: 40 at 100% true ( should be 80% ? )
Hit: 50 at 80% true ( should be 100% ? )
Hit: 60 at 66% true ( should be 80% ? )
Miss: 70
Grade:
public class FuzzyTest {
class Result {
int value;
int truthfullness;
}
Result evaluate(final int valueIn, final int target, final int threshold) {
Result result = null;
final boolean truth = (((target - threshold) <= valueIn) && (valueIn <= (target + threshold)));
if (truth) {
result = new Result();
result.value = valueIn;
result.truthfullness = (int) (100.0 - (100.0 * (valueIn - Math.abs(target - threshold)) / valueIn));
}
return result;
}
public static void main(final String[] args) {
final int[] arrayIn = new int[] { 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 };
final int threshold = 10;
final int target = 50;
final FuzzyTest fuzzy = new FuzzyTest();
for (final int x : arrayIn) {
final Result result = fuzzy.evaluate(x, target, threshold);
if (result == null) {
System.out.println("Miss: " + x);
}
else {
System.out.println("Hit: " + x + " at " + result.truthfullness + "% true");
}
}
}
}
source
share