JavaScript 中的模糊逻辑?
有谁知道如何从 JavaScript 访问模糊逻辑?我有一个很好的 Java 和 C++ 模糊库,但我想要一些可以从 HTML5/javascript 运行的东西。
Does anyone know how one could access fuzzy logic from javascript? I have a good fuzzy library in Java and C++, but I wanted something I could run from HTML5/javascript.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有两个项目可用:
https://github.com/marcolanaro/JS-Fuzzy - 可以使用在浏览器中
There are two projects avaliable:
https://github.com/marcolanaro/JS-Fuzzy - ready to use in browser
https://github.com/sebs/node-fuzzylogic - nodejs module, could be used in browser
我对那些想在 NodeJS 中做的人的回答,因为它熟悉 javascript
请使用一个很棒的 nodejs-java 和一个用 Java 编写的奇迹 jFuzzylite 库。
节点java: https://www.npmjs.com/package/java
Fuzzylite:< a href="http://www.fuzzylite.com/" rel="nofollow noreferrer">http://www.fuzzylite.com/。它提供了jfuzzylite.jar,
我在Matlab中创建了一个隶属函数membership_function_pn.fis,它有两个输入和一个输出。在Matlab命令界面上输入mfedit,将会出现一个FIS编辑器,您可以在其中轻松制作模糊函数。
以下是我的代码,它完成了工作! (要了解代码在 Nodejs 中的工作原理,请先使用 jfuzzylite.jar 在 Java 中进行练习)。
My answer for those who want to do in NodeJS as it is familiar with javascript
Please use an awesome nodejs-java, and a miracle jFuzzylite library which is written in Java.
node-java: https://www.npmjs.com/package/java
Fuzzylite: http://www.fuzzylite.com/. It provides jfuzzylite.jar
I've created a membership function in Matlab membership_function_pn.fis, It has two inputs and one output. Type mfedit on the Matlab command interface, it will appear an FIS editor where you can easily make your fuzzy function.
The following is my code which did the work!! (To understand how the code works in Nodejs, do a practice in Java with jfuzzylite.jar first).
您不能直接在 HTML 页面的浏览器中运行 Java 或 C++。因此,您的选择是:
根据具体情况,选项 1) 或 2) 可以正常工作。
选项 3) 需要能够将代码重新编译为 WebAssembly。这对于某些 C++ 代码(仅使用可在浏览器中运行的库选项的代码)来说是可能的,并且有一些项目可以类似地将 Java 字节码编译为 WebAssembly。
选项 4) 通常是一个坏主意,除非它是一个非常专业的应用程序,并且在某种程度上值得处理插件的分发、维护、测试和用户难题。
对于具有重要本机代码的项目,完全用 Javascript 重写要么工作量太大,要么不切实际,最常见的解决方案是将代码放在服务器上(作为本机代码或 Java 代码),然后公开服务器上的 API 允许客户端向该代码发送参数,在服务器上运行代码,然后获取代码生成的任何响应。这使您能够在服务器上运行 C++ 和 Java 代码而无需重写它,同时仍将结果返回给客户端。
注意:如果您的问题是为了征求已经在浏览器中运行的替代库来执行模糊逻辑,那么此类问题在 stackoverflow 上被认为是离题的,并且可能适合 软件推荐。
You cannot run Java or C++ directly in the browser in an HTML page. As such, your options are:
Options 1) or 2) could work fine depending upon the details of the situation.
Option 3) requires the ability to recompile the code into WebAssembly. This is possible for some C++ code (code that uses only library options that can be run in the browser) and there are some projects to similarly compile Java bytecodes into WebAssembly.
Option 4) is generally a bad idea unless it's a very specialized application that somehow makes it worth dealing with the distribution, maintenance, testing and user headaches of a plug-in.
For projects with significant native code that it is either too much work to rewrite entirely in Javascript or it isn't practical, the most common solution would be to put the code on your server (as native code or Java code) and then expose an API on your server that allows the client to send parameters to that code, run the code on the server and then get whatever response the code generates. This gives you the full ability to run C++ and Java code on your server without rewriting it, while still getting the result back to the client.
Note: If your question was meant to solicit alternate libraries that already run in the browser for doing fuzzy logic, then that type of question is considered off-topic here on stackoverflow and could be appropriate in Software Recommendations.