什么是模糊逻辑?

发布于 2024-07-11 12:58:02 字数 225 浏览 7 评论 0原文

我在学校使用一些人工智能算法,我发现人们使用模糊逻辑这个词来解释他们可以通过几个案例解决的任何情况。 当我回到书本时,我只是读到了如何从开到关不是一种状态,而是一条对角线,并且某些东西可以处于两种状态,但处于不同的“级别”。

我已经阅读了维基百科条目和一些教程,甚至编写了“使用模糊逻辑”的东西(边缘检测器和单轮自控机器人),但我仍然发现从理论到代码非常令人困惑。对你来说,用不太复杂的定义来说,什么是模糊逻辑?

I'm working with a couple of AI algorithms at school and I find people use the words Fuzzy Logic to explain any situation that they can solve with a couple of cases. When I go back to the books I just read about how instead of a state going from On to Off it's a diagonal line and something can be in both states but in different "levels".

I've read the wikipedia entry and a couple of tutorials and even programmed stuff that "uses fuzzy logic" (an edge detector and a 1-wheel self-controlled robot) and still I find it very confusing going from Theory to Code... for you, in the less complicated definition, what is fuzzy logic?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

最冷一天 2024-07-18 12:58:02

模糊逻辑是一种逻辑,其中状态成员本质上是范围为 0..1 的浮点数,而不是整数 0 或 1。您从中获得的好处是,例如,您在控制系统中所做的更改比使用简单的二进制逻辑得到的结果自然更容易调整。

一个示例可能是基于活动 TCP 连接限制系统活动的逻辑。 假设您将计算机上的“有点太多”TCP 连接定义为 1000,将“太多”定义为 2000。在任何给定时间,您的系统都处于从 0 (<= 1000 ) 到 1 (>= 2000),您可以将其用作应用任何可用的限制机制的系数。 与只知道如何确定“太多”并完全节流或“不是太多”且根本不节流的朴素二进制逻辑相比,这对系统行为更加宽容和敏感。

Fuzzy logic is logic where state membership is, essentially, a float with range 0..1 instead of an int 0 or 1. The mileage you get out of it is that things like, for example, the changes you make in a control system are somewhat naturally more fine-tuned than what you'd get with naive binary logic.

An example might be logic that throttles back system activity based on active TCP connections. Say you define "a little bit too many" TCP connections on your machine as 1000 and "a lot too many" as 2000. At any given time, your system has a "too many TCP connections" state from 0 (<= 1000) to 1 (>= 2000), which you can use as a coefficient in applying whatever throttling mechanisms you have available. This is much more forgiving and responsive to system behavior than naive binary logic that only knows how to determine "too many", and throttle completely, or "not too many", and not throttle at all.

伪装你 2024-07-18 12:58:02

我想在答案(已修改)中补充一点,可视化模糊逻辑的一个好方法如下:

传统上,使用二元逻辑,您将拥有一个其隶属函数为 true 或 false 的图,而在模糊逻辑中系统中,隶属函数不是。

1|
 |   /\
 |  /  \
 | /    \
0|/      \
 ------------
   a  b c   d

假设该函数“像花生一样”。

a. kinda likes peanuts
b. really likes peanuts
c. kinda likes peanuts
d. doesn't like peanuts

该函数本身不必是三角形的,而且通常也不是(使用 ascii art 更容易)。

一个模糊系统可能会有很多这样的东西,有些甚至重叠(甚至相反),如下所示:

1|   A    B
 |   /\  /\      A = Likes Peanuts
 |  /  \/  \     B = Doesn't Like Peanuts
 | /   /\   \
0|/   /  \   \
 ------------
  a  b  c d

所以现在c是“有点喜欢花生,有点不喜欢花生”,而d是“真的不喜欢”不喜欢花生”

,您可以根据该信息进行相应的编程。

希望这对视觉学习者有所帮助。

I'd like to add to the answers (that have been modded up) that, a good way to visualize fuzzy logic is follows:

Traditionally, with binary logic you would have a graph whose membership function is true or false whereas in a fuzzy logic system, the membership function is not.

1|
 |   /\
 |  /  \
 | /    \
0|/      \
 ------------
   a  b c   d

Assume for a second that the function is "likes peanuts"

a. kinda likes peanuts
b. really likes peanuts
c. kinda likes peanuts
d. doesn't like peanuts

The function itself doesn't have to be triangular and often isn't (it's just easier with ascii art).

A fuzzy system will likely have many of these, some even overlapping (even opposites) like so:

1|   A    B
 |   /\  /\      A = Likes Peanuts
 |  /  \/  \     B = Doesn't Like Peanuts
 | /   /\   \
0|/   /  \   \
 ------------
  a  b  c d

so now c is "kind likes peanuts, kinda doesn't like peanuts" and d is "really doesn't like peanuts"

And you can program accordingly based on that info.

Hope this helps for the visual learners out there.

巴黎盛开的樱花 2024-07-18 12:58:02

模糊逻辑的最佳定义是由其发明者 Lotfi Zadeh 给出的:

“模糊逻辑意味着以类似于人类解决问题的方式向计算机表示问题,模糊逻辑的本质是一切都是程度问题。”

用计算机以类似于人类解决问题的方式解决问题的意义可以通过篮球比赛中的一个简单例子来轻松解释; 如果一个球员想要防守另一个球员,他首先应该考虑他的身高和技术如何。 简单地说,如果他想要防守的球员很高,并且相对于他打得非常慢,那么他会利用自己的直觉来决定是否应该防守该球员,因为他存在不确定性。 在这个例子中,重要的一点是属性是相对于玩家的,并且对手玩家的身高和游戏技巧有一个程度。 模糊逻辑为这种不确定的情况提供了一种确定性的方法。

处理模糊逻辑有一些步骤(图-1)。 这些步骤是; 首先是模糊化,其中清晰的输入转换为模糊输入,其次是使用模糊规则处理这些输入以创建模糊输出,最后是去模糊化,它产生结果的程度,因为在模糊逻辑中可以有多个不同程度的结果。

img src="https://i.sstatic.net/ZbdwO.gif" alt="image004">

图 1 – 模糊过程步骤 (David M. Bourg P.192)

< 模糊处理步骤,可以利用之前篮球比赛的情况。 正如示例中提到的,对手球员身高 1.87 米,相对于我们的球员来说相当高,并且可以以 3 m/s 的速度运球,相对于我们的球员来说很慢。 除了这些数据之外,还需要考虑一些规则,这些规则称为模糊规则,例如:

if player is short but not fast then guard,
if player is fast but not short then don’t guard
If player is tall then don’t guard
If player is average tall and average fast guard

image005

图 2 – 多高

image007

图 3- 多快

根据规则和输入数据,模糊系统将创建输出,例如; 防护等级为 0.7,有时防护等级为 0.4,从不防护等级为 0.2。

image009

图 4-输出模糊集

最后一步,去模糊化 >,用于创建清晰的输出,该输出可以确定我们在游戏过程中用来保护玩家的能量。 质心是创建输出的常用方法。 在这个阶段,计算平均点的权重完全取决于实现。 在此应用中,考虑给予高权重以防护或不防护,但给予低权重以有时防护。 (David M. Bourg,2004)

image012

图 5-模糊输出(David M. Bourg P.204)

  Output = [0.7 * (-10) + 0.4 * 1 + 0.2 * 10] / (0.7 + 0.4 + 0.2) ≈ -3.5

因此,模糊逻辑就是在不确定的情况下使用模糊逻辑来做出决策并找出决策的程度。 模糊逻辑的问题是随着输入数量的增加,规则的数量呈指数增长。

有关更多信息及其在游戏中的可能应用,我写了一篇小文章看看这个

The best definition of fuzzy logic is given by its inventor Lotfi Zadeh:

“Fuzzy logic means of representing problems to computers in a way akin to the way human solve them and the essence of fuzzy logic is that everything is a matter of degree.”

The meaning of solving problems with computers akin to the way human solve can easily be explained with a simple example from a basketball game; if a player wants to guard another player firstly he should consider how tall he is and how his playing skills are. Simply if the player that he wants to guard is tall and plays very slow relative to him then he will use his instinct to determine to consider if he should guard that player as there is an uncertainty for him. In this example the important point is the properties are relative to the player and there is a degree for the height and playing skill for the rival player. Fuzzy logic provides a deterministic way for this uncertain situation.

There are some steps to process the fuzzy logic (Figure-1). These steps are; firstly fuzzification where crisp inputs get converted to fuzzy inputs secondly these inputs get processed with fuzzy rules to create fuzzy output and lastly defuzzification which results with degree of result as in fuzzy logic there can be more than one result with different degrees.

image004

Figure 1 – Fuzzy Process Steps (David M. Bourg P.192)

To exemplify the fuzzy process steps, the previous basketball game situation could be used. As mentioned in the example the rival player is tall with 1.87 meters which is quite tall relative to our player and can dribble with 3 m/s which is slow relative to our player. Addition to these data some rules are needed to consider which are called fuzzy rules such as;

if player is short but not fast then guard,
if player is fast but not short then don’t guard
If player is tall then don’t guard
If player is average tall and average fast guard

image005

Figure 2 – how tall

image007

Figure 3- how fast

According to the rules and the input data an output will be created by fuzzy system such as; the degree for guard is 0.7, degree for sometimes guard is 0.4 and never guard is 0.2.

image009

Figure 4-output fuzzy sets

On the last step, defuzzication, is using for creating a crisp output which is a number which may determine the energy that we should use to guard the player during game. The centre of mass is a common method to create the output. On this phase the weights to calculate the mean point is totally depends on the implementation. On this application it is considered to give high weight to guard or not guard but low weight given to sometimes guard. (David M. Bourg, 2004)

image012

Figure 5- fuzzy output (David M. Bourg P.204)

  Output = [0.7 * (-10) + 0.4 * 1 + 0.2 * 10] / (0.7 + 0.4 + 0.2) ≈ -3.5

As a result fuzzy logic is using under uncertainty to make a decision and to find out the degree of decision. The problem of fuzzy logic is as the number of inputs increase the number of rules increase exponential.

For more information and its possible application in a game I wrote a little article check this out

清晨说晚安 2024-07-18 12:58:02

也许举个例子就可以清楚地说明其好处:

假设您想要制造一个恒温器,并且希望其温度为 24 度。


这是使用布尔逻辑实现它的方式:

  • 规则 1:全功率加热
    气温低于 21 度。
  • 规则2:
    全功率冷却时
    温暖超过 27 度。

这样的系统只会偶尔出现24度,而且效率会非常低。


现在,使用模糊逻辑,它会像这样:

  • 规则 1:对于比 24 度低的每度,将加热器调高一个档次(24 度为 0)。
  • 规则 2:气温每比 24 度高一度,将较冷的温度调高一级(24 度为 0 度)。

这个系统总是在 24 度左右,而且只会偶尔进行一次微小的调整。 它还将更加节能。

Maybe an example clears up what the benefits can be:

Let's say you want to make a thermostat and you want it to be 24 degrees.


This is how you'd implement it using boolean logic:

  • Rule1: heat up at full power when
    it's colder than 21 degrees.
  • Rule2:
    cool down at full power when it's
    warmer than 27 degrees.

Such a system will only once and a while be 24 degrees, and it will be very inefficient.


Now, using fuzzy logic, it would be like something like this:

  • Rule1: For each degree that it's colder than 24 degrees, turn up the heater one notch (0 at 24).
  • Rule2: For each degree that it's warmer than 24 degress, turn up the cooler one notch (0 at 24).

This system will always be somewhere around 24 degrees, and it only once and will only once and a while make a tiny adjustment. It will also be more energy-efficient.

最美的太阳 2024-07-18 12:58:02

嗯,您可以阅读“开国元勋”之一 Bart Kosko 的作品。 1994 年的“模糊思维:模糊逻辑的新科学”可读(并且可以通过亚马逊以相当便宜的价格买到二手货)。 显然,他有一本 2006 年的新书 'Noise',这本书也相当不错平易近人。

基本上(用我的话说——我已经好几年没有读过第一本书了),模糊逻辑是关于如何处理这个世界,在这个世界中,某些东西可能有 10% 冷、50% 热和 10% 热,其中不同的东西可能会根据不同状态的真实程度做出决定(不,这些百分比加起来不等于 100% 并不完全是意外 - 尽管如果需要的话我会接受更正)。

Well, you could read the works of Bart Kosko, one of the 'founding fathers'. 'Fuzzy Thinking: The New Science of Fuzzy Logic' from 1994 is readable (and available quite cheaply secondhand via Amazon). Apparently, he has a newer book 'Noise' from 2006 which is also quite approachable.

Basically though (in my paraphrase - not having read the first of those books for several years now), fuzzy logic is about how to deal with the world where something is perhaps 10% cool, 50% warm, and 10% hot, where different decisions may be made on the degree to which the different states are true (and no, it wasn't entirely an accident that those percentages don't add up to 100% - though I'd accept correction if needed).

初相遇 2024-07-18 12:58:02

为了构建混沌的答案,形式逻辑只不过是一个归纳定义的集合,将句子映射到评估。 至少,模型理论家是这样看待逻辑的。 在句子布尔逻辑的情况下:

 (basis clause) For all A, v(A) in {0,1}
 (iterative) For the following connectives,
   v(!A) = 1 - v(A)
   v(A & B) = min{v(A), v(B)}
   v(A | B) = max{v(A), v(B)}
 (closure) All sentences in a boolean sentential logic are evaluated per above.

模糊逻辑变化将被归纳定义:

 (basis clause) For all A, v(A) between [0,1]
 (iterative) For the following connectives,
   v(!A) = 1 - v(A)
   v(A & B) = min{v(A), v(B)}
   v(A | B) = max{v(A), v(B)}
 (closure) All sentences in a fuzzy sentential logic are evaluated per above.

请注意,底层逻辑中的唯一区别是允许将句子评估为具有 0.5 的“真值”。 模糊逻辑模型的一个重要问题是真值满足的阈值。 这是要问:对于估值 v(A),对于什么值 D,v(A) > 的情况是? D表示A满足。

如果您确实想了解有关模糊逻辑等非经典逻辑的更多信息,我建议您 非经典逻辑简介:从 If 到 Is可能性和悖论

重新戴上我的程序员帽子,我会小心在现实世界编程中使用模糊逻辑,因为模糊逻辑往往是不可判定的。 也许它太复杂而收效甚微。 例如,超值逻辑可以很好地帮助程序模拟模糊性。 或者也许概率就足够了。 简而言之,我需要确信领域模型与模糊逻辑相吻合。

To build off of chaos' answer, a formal logic is nothing but an inductively defined set that maps sentences to a valuation. At least, that's how a model theorist thinks of logic. In the case of a sentential boolean logic:

 (basis clause) For all A, v(A) in {0,1}
 (iterative) For the following connectives,
   v(!A) = 1 - v(A)
   v(A & B) = min{v(A), v(B)}
   v(A | B) = max{v(A), v(B)}
 (closure) All sentences in a boolean sentential logic are evaluated per above.

A fuzzy logic changes would be inductively defined:

 (basis clause) For all A, v(A) between [0,1]
 (iterative) For the following connectives,
   v(!A) = 1 - v(A)
   v(A & B) = min{v(A), v(B)}
   v(A | B) = max{v(A), v(B)}
 (closure) All sentences in a fuzzy sentential logic are evaluated per above.

Notice the only difference in the underlying logic is the permission to evaluate a sentence as having the "truth value" of 0.5. An important question for a fuzzy logic model is the threshold that counts for truth satisfaction. This is to ask: for a valuation v(A), for what value D it is the case the v(A) > D means that A is satisfied.

If you really want to found out more about non-classical logics like fuzzy logic, I would recommend either An Introduction to Non-Classical Logic: From If to Is or Possibilities and Paradox

Putting my coder hat back on, I would be careful with the use of fuzzy logic in real world programming, because of the tendency for a fuzzy logic to be undecidable. Maybe it's too much complexity for little gain. For instance a supervaluational logic may do just fine to help a program model vagueness. Or maybe probability would be good enough. In short, I need to be convinced that the domain model dovetails with a fuzzy logic.

夜无邪 2024-07-18 12:58:02

模糊逻辑是一种解决问题的方法,适用于从简单、小型嵌入式微控制器到大型、网络化、多通道 PC 或基于工作站的数据采集和控制系统等系统。 它可以用硬件、软件或两者的组合来实现。 模糊逻辑提供了一种简单的方法,可以根据模糊、不明确、不精确、有噪声或缺失的输入信息得出明确的结论。 控制问题的模糊逻辑方法模仿了人如何做出决策,而且速度更快。

模糊逻辑已被证明在专家系统和其他人工智能应用中特别有用。 它也被用在一些拼写检查器中来建议可能的单词列表来替换拼写错误的单词。

要了解更多信息,请查看:http://en.wikipedia.org/wiki/Fuzzy_logic

Fuzzy Logic is a problem-solving methodology that lends itself to implementation in systems ranging from simple, small, embedded micro-controllers to large, networked, multi-channel PC or workstation-based data acquisition and control systems. It can be implemented in hardware, software, or a combination of both. Fuzzy Logic provides a simple way to arrive at a definite conclusion based upon vague, ambiguous, imprecise, noisy, or missing input information. Fuzzy Logic approach to control problems mimics how a person would make decisions, only much faster.

Fuzzy logic has proved to be particularly useful in expert system and other artificial intelligence applications. It is also used in some spell checkers to suggest a list of probable words to replace a misspelled one.

To learn more, just check out: http://en.wikipedia.org/wiki/Fuzzy_logic.

青春有你 2024-07-18 12:58:02

我知道你所说的从概念到代码的困难是什么意思。 我正在编写一个评分系统,该系统查看 Linux 系统上 sysinfo 和 /proc 的值,并得出 0 到 10 之间的数字,10 绝对是最差的。 一个简单的例子:

您有 3 个平均负载(1、5、15 分钟),具有(至少)三种可能的状态:好、变差、坏。 扩展一下,平均可以有六种可能的状态,在我刚才提到的三种状态中添加“大约”。 然而,所有18种可能的结果只能扣1分。 重复消耗的交换、实际虚拟机分配(提交)的内存和其他内容..,你就得到了一大碗条件意大利面:)

它既是一个定义,也是一门艺术,你如何实现决策过程总是更重要比范式本身更有趣..而在布尔世界中,它相当简单和干燥。

我很容易说如果 load1 < 2减1,但一点也不准确。

如果您可以教一个程序执行评估某些情况时会执行的操作并保持代码的可读性,那么您就实现了模糊逻辑的一个很好的示例。

I know what you mean about it being difficult to go from concept to code. I'm writing a scoring system that looks at the values of sysinfo and /proc on Linux systems and comes up with a number between 0 and 10, 10 being the absolute worst. A simple example:

You have 3 load averages (1, 5, 15 minute) with (at least) three possible states, good, getting bad, bad. Expanding that, you could have six possible states per average, adding 'about to' to the three that I just noted. Yet, the result of all 18 possibilities can only deduct 1 from the score. Repeat that with swap consumed, actual VM allocated (committed) memory and other stuff .. and you have one big bowl of conditional spaghetti :)

Its as much a definition as it is an art, how you implement the decision making process is always more interesting than the paradigm itself .. whereas in a boolean world, its rather cut and dry.

It would be very easy for me to say if load1 < 2 deduct 1, but not very accurate at all.

If you can teach a program to do what you would do when evaluating some set of circumstances and keep the code readable, you have implemented a good example of fuzzy logic.

你的背包 2024-07-18 12:58:02

模糊逻辑洗衣机的帮助下,这是一个非常好的解释。

A very good explanation, with a help of Fuzzy Logic Washing Machines.

盛装女皇 2024-07-18 12:58:02

模糊逻辑是基于类人思维方式的计算算法。 当有大量输入变量时,它特别有用。 给出了一个用于两个变量输入的在线模糊逻辑计算器:

http://www.cirvirlab.com/simulation /fuzzy_logic_calculator.php

Fuzzy logic is calculating algorithm based on human like way of thinking. It is particularly useful when there is a large number of input variables. One online fuzzy logic calculator for two variables input is given:

http://www.cirvirlab.com/simulation/fuzzy_logic_calculator.php

江南月 2024-07-18 12:58:02

以下是一个经验性的答案。

一个简单的(可能是简单的答案)是“模糊逻辑”是返回除直接真/假或 1/0 之外的值的任何逻辑。这方面有很多变体,并且它们往往是高度特定于领域的。

例如,在我的前世中,我使用“内容相似性搜索”而不是当时常见的“布尔搜索”的搜索引擎。 我们的相似性系统使用表示查询和文档的加权属性向量的余弦系数,并生成 0..1 范围内的值。 用户将提供“相关性反馈”,用于将查询向量转向所需文档的方向。 这在某种程度上与某些人工智能系统中进行的训练有关,在这些系统中,逻辑会根据试运行的结果获得“奖励”或“惩罚”。

目前 Netflix 正在举办一场竞赛,为他们的公司寻找更好的建议算法。 请参阅 http://www.netflixprize.com/。 实际上,所有算法都可以被描述为“模糊逻辑”

The following is sort of an empirical answer.

A simple (possibly simplistic answer) is that "fuzzy logic" is any logic that returns values other than straight true / false, or 1 / 0. There are a lot of variations on this and they tend to be highly domain specific.

For example, in my previous life I did search engines that used "content similarity searching" as opposed to then common "boolean search". Our similarity system used the Cosine Coefficient of weighted-attribute vectors representing the query and the documents and produced values in the range 0..1. Users would supply "relevance feedback" which was used to shift the query vector in the direction of desirable documents. This is somewhat related to the training done in certain AI systems where the logic gets "rewarded" or "punished" for results of trial runs.

Right now Netflix is running a competition to find a better suggestion algorithm for their company. See http://www.netflixprize.com/. Effectively all of the algorithms could be characterized as "fuzzy logic"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文