Reputation: 209
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");
}
}
}
}
Upvotes: 4
Views: 244
Reputation: 179
Try this to get the values you wanted:
result.truthfullness = (int) (100.0 - (100.0 * Math.abs(target - valueIn)) / target);
It gives this result:
Miss: 30
Hit: 40 at 80% true
Hit: 50 at 100% true
Hit: 60 at 80% true
Miss: 70
Upvotes: 0
Reputation: 521
By testing a value for truth between a high and low target, is this really using fuzzy logic?
No. It still the same boolean logic. To really get a fuzzy value, you must get the Fuzzy values from a Fuzzy function for your input variables.
A Fuzzy function is a function that receives an real value and returns a value between 0 and 1. Its states a degree of truth of that variable. For example, in the image below (taken from the wikipedia article about Fuzzy), a real value temperature will have a degree of 'cold', 'warm' and 'hot'. These values are your truthfulness.
Truthfulness % seems incorrect for target/threshold hits.
Yes, it is incorrect. First because your threshold is actually between 0 and 1 in the Fuzzy definition (so, you already have a percentage). Second because, if you are defining a threshold of [0, 100], its not Fuzzy.
If you are using Java to create a Fuzzy system (even a simple one), may I suggest a good framework to do it? Try to use jFuzzyLogic. It will help you to program your Fuzzy system and to understand how Fuzzy works.
Upvotes: 2