我正在创建一个展示模糊逻辑真实性的简单例子。 问题在于确定结果的真实性。
我的第一个问题:通过测试高目标和低目标之间的真值,这真的是使用模糊逻辑吗?
我的第二个问题:真实性%似乎不适合目标/阈值命中。
结果:
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");
}
}
}
}
答案 0 :(得分:2)
通过测试高目标和低目标之间的真值,这真的是使用模糊逻辑吗?
没有。它仍然是相同的布尔逻辑。要真正获得模糊值,必须从输入变量的模糊函数中获取模糊值。
模糊函数是一个接收实数值并返回0到1之间的值的函数。它表示该变量的真实程度。例如,在下面的图片中(取自维基百科关于模糊的文章),实际值温度将具有“冷”,“暖”和“热”的程度。这些价值观是你的真实性。
目标/阈值命中的真实%似乎不正确。
是的,这是不正确的。首先,因为模糊定义中的阈值实际上在0和1之间(因此,您已经有一个百分比)。第二,因为,如果你定义一个[0,100]的阈值,它不是模糊的。
如果您使用Java创建模糊系统(即使是简单的系统),我可以建议一个好的框架吗?尝试使用jFuzzyLogic。它将帮助您对模糊系统进行编程,并了解模糊的工作原理。
答案 1 :(得分:0)
尝试此操作以获得所需的值:
result.truthfullness = (int) (100.0 - (100.0 * Math.abs(target - valueIn)) / target);
它给出了这个结果:
Miss: 30
Hit: 40 at 80% true
Hit: 50 at 100% true
Hit: 60 at 80% true
Miss: 70