【发布时间】:2014-07-24 06:34:06
【问题描述】:
我正在创建一个简单的示例来展示模糊逻辑的真实性。 问题在于确定结果的真实性。
我的第一个担忧:通过测试高低目标之间的真实值,这真的使用模糊逻辑吗?
我的第二个担忧:真实性 % 似乎对于目标/阈值命中不正确。
结果:
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
类:
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");
}
}
}
}
【问题讨论】:
-
似乎 40 和 60 的命中率应该接近 0%(不是 80%),而 45 和 55 的命中率应该是 50%。
标签: java fuzzy-logic