I'm creating a simplistic example demonstrating fuzzy logic truthfulness. The problem is with determining result truthfulness.
My first concern: By testing a value for truth between a high and low target, is this really using fuzzy logic?
My second concern: Truthfulness % seems incorrect 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
Class:
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");
}
}
}
}