JavaScript 中的模糊逻辑?

发布于 2024-11-27 01:15:01 字数 89 浏览 1 评论 0原文

有谁知道如何从 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 技术交流群。

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

发布评论

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

评论(3

夜司空 2024-12-04 01:15:01

有两个项目可用:

  1. https://github.com/marcolanaro/JS-Fuzzy - 可以使用在浏览器中

  2. < p>https://github.com/sebs/node-fuzzylogic - Nodejs模块,可以在浏览器中使用

There are two projects avaliable:

  1. https://github.com/marcolanaro/JS-Fuzzy - ready to use in browser

  2. https://github.com/sebs/node-fuzzylogic - nodejs module, could be used in browser

梦途 2024-12-04 01:15:01

我对那些想在 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 中进行练习)。

var java = require("java");
var fs = require("fs");
java.classpath.push("commons-lang3-3.1.jar");
java.classpath.push("commons-io.jar");
java.classpath.push("jfuzzylite.jar");


var matlabString = fs.readFileSync("dataMatlab/membership_function_pn.fis", 'utf8');
var FisImporter = java.newInstanceSync("com.fuzzylite.imex.FisImporter");
var engineMatlab = java.callMethodSync(FisImporter, "fromString", matlabString);
var InputVariable = java.newInstanceSync('com.fuzzylite.imex.FisImporter');


var OutputVariable = java.callMethodSync(engineMatlab, "getOutputVariable", 0);
var bandwidthInputVariable = java.callMethodSync(engineMatlab, "getInputVariable", 0);
var timeInputVariable = java.callMethodSync(engineMatlab, "getInputVariable", 1);
java.callMethodSync(bandwidthInputVariable, "setInputValue", -0.5);
java.callMethodSync(timeInputVariable, "setInputValue", 0.5);
java.callMethodSync(engineMatlab, "process");
var resultFuzzy = java.callMethodSync(OutputVariable, "getOutputValue");

console.log("안녕하세요" + resultFuzzy);

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).

var java = require("java");
var fs = require("fs");
java.classpath.push("commons-lang3-3.1.jar");
java.classpath.push("commons-io.jar");
java.classpath.push("jfuzzylite.jar");


var matlabString = fs.readFileSync("dataMatlab/membership_function_pn.fis", 'utf8');
var FisImporter = java.newInstanceSync("com.fuzzylite.imex.FisImporter");
var engineMatlab = java.callMethodSync(FisImporter, "fromString", matlabString);
var InputVariable = java.newInstanceSync('com.fuzzylite.imex.FisImporter');


var OutputVariable = java.callMethodSync(engineMatlab, "getOutputVariable", 0);
var bandwidthInputVariable = java.callMethodSync(engineMatlab, "getInputVariable", 0);
var timeInputVariable = java.callMethodSync(engineMatlab, "getInputVariable", 1);
java.callMethodSync(bandwidthInputVariable, "setInputValue", -0.5);
java.callMethodSync(timeInputVariable, "setInputValue", 0.5);
java.callMethodSync(engineMatlab, "process");
var resultFuzzy = java.callMethodSync(OutputVariable, "getOutputValue");

console.log("안녕하세요" + resultFuzzy);
小鸟爱天空丶 2024-12-04 01:15:01

您不能直接在 HTML 页面的浏览器中运行 Java 或 C++。因此,您的选择是:

  1. 将逻辑放在服务器上,并使用 ajax http 请求发送到该服务器以从网页访问它。
  2. 用 javascript 重写代码并将其包含在您的页面中。
  3. 将代码编译为 WebAssembly,然后可以由现代浏览器运行。
  4. 将 C++ 和/或 Java 放入浏览器插件中并从 javascript 访问该插件。

根据具体情况,选项 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:

  1. Put the logic on a server and use ajax http request to that server to access it from a web page.
  2. Rewrite the code in javascript and include it in your page.
  3. Compile the code to WebAssembly which can then be run by a modern browser.
  4. Put the C++ and/or Java into a browser plugin and access the plugin from javascript.

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.

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