在哪里编写这个启发式代码?

发布于 2024-10-31 06:07:51 字数 265 浏览 4 评论 0原文

我想问一个复杂的问题。

我必须为我的论文编写启发式代码。我需要以下内容:

  • 评估一些积分函数
  • 在一个间隔内最小化函数
  • 这样做成千上万次。

所以我需要一种更快的编程语言来完成这些工作。您建议使用哪种语言?首先,我从 Java 开始,但是积分成为一个问题。而且我不确定速度。

连接 Java 和 MATLAB 等其他软件可能是个好主意。因为我不确定,所以想听听你们的意见。

谢谢!

I want to ask a complex question.

I have to code a heuristic for my thesis. I need followings:

  • Evaluate some integral functions
  • Minimize functions over an interval
  • Do this over thousand and thousand times.

So I need a faster programming language to do these jobs. Which language do you suggest? First, I started with Java, but taking integrals become a problem. And I'm not sure about speed.

Connecting Java and other softwares like MATLAB may be a good idea. Since I'm not sure, I want to take your opinions.

Thanks!

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

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

发布评论

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

评论(4

顾挽 2024-11-07 06:07:51

C、Java……都是图灵完备的语言。他们可以以相同的精度计算相同的函数。
如果您想实现性能目标,请使用 C,它是一种编译型高性能语言。可以减少计算时间,避免方法调用和 Java 等解释性语言中存在的高级功能。

无论如何请记住,您的实现可能比您选择的语言对性能的影响更大,因为增加输​​入维度是相关的计算复杂性( http://en.wikipedia.org/wiki/Computational_complexity_theory)。

C,Java, ... are all Turing complete languages. They can calculate the same functions with the same precision.
If you want achieve performance goals use C that is a compiled and high performances language . Can decrease your computation time avoiding method calls and high level features present in an interpreted language like Java.

Anyway remember that your implementation may impact the performances more than which language you choose, because for increasing input dimension is the computational complexity that is relevant ( http://en.wikipedia.org/wiki/Computational_complexity_theory ).

挽袖吟 2024-11-07 06:07:51

这不是编程语言,这可能是你的算法。确定算法的 big0 表示法。如果您在循环中使用循环(您可以在 Map 中使用哈希搜索来代替),那么您的算法可以快 n 倍。

注意:现代 JVM(JDK 1.5 或 1.6)本地即时编译(如未解释)到特定操作系统以及特定操作系统版本和特定硬件架构。您可以更积极地尝试使用-server进行JIT(以更长的初始化时间为代价)。

这样做成千上万次。

您确定不是更多,而是类似 10^1000 的东西吗?尝试准确计算需要运行该循环多少次,这可能会让您感到惊讶。使用启发式方法的问题类型往往具有很大的搜索空间。

It's not the programming language, it's probably your algorithm. Determine the big0 notation of your algorithm. If you use loops in loops, where you could use a search by a hash in a Map instead, your algorithm can be made n times faster.

Note: Modern JVM's (JDK 1.5 or 1.6) compile Just-In-Time natively (as in not-interpreted) to a specific OS and a specific OS version and a specific hardware architecture. You could try the -server to JIT even more aggressively (at the cost of an even longer initialization time).

Do this over thousand and thousand times.

Are you sure it's not more, something like 10^1000 instead? Try accurately calculating how many times you need to run that loop, it might surprise you. The type of problems on which heuristics are used, tend to have a really big search space.

七月上 2024-11-07 06:07:51

在开始切换语言之前,我首先尝试执行以下操作:

  1. 找到最佳的可用算法。
  2. 查找可用于您的语言的这些算法的可用实现。
    例如,有 Java 的科学库。尝试使用这些库。
  3. 如果他们不够快,请调查是否有任何措施可以采取。您的问题是否比图书馆假设的更具体?您能够根据这些知识改进算法吗?
  4. 到底是什么需要这么多/内存?这真的和你的语言有关吗?尽量避免观察 JVM 启动时间,而不是它为您执行计算的时间。
  5. 然后,我会考虑切换语言。但不要指望它能轻易击败 C 语言中优化的第三方 Java 库。

Before you start switching languages, I'd first try to do the following things:

  1. Find the best available algorithms.
  2. Find available implementations of those algorithms usable from your language.
    There are e.g. scientific libraries for Java. Try to use these libraries.
  3. If they are not fast enough investigate whether there is anything to be done about it. Is your problem more specific than what the library assumes. Are you able to improve the algorithm based on that knowledge.
  4. What is it that takes so much/memory? Is this realy related to your language? Try to avoid observing JVM start times instead of the time it performed calculation for you.
  5. Then, I'd consider switching languages. But don't expect it to be easy to beat optimized third party java libraries in c.
假装爱人 2024-11-07 06:07:51

算法的顺序

通常,在语言之间切换只会减少一个常数因子所需的时间。假设您可以使用 C 将速度加倍,但如果您的算法是 O(n^2),那么无论使用哪种语言,如果您将数据加倍,则需要四倍的时间来处理。

并且 JVM 可以优化很多东西并获得良好的结果。

Java 中的一些可能的优化

如果您的函数被多次调用,请将它们设为最终。整个班级也是如此。编译器将知道它可以内联方法代码,从而避免为该调用创建方法调用堆栈帧。

Order of the algorithm

Tipically switching between languages only reduce the time required by a constant factor. Let's say you can double the speed using C, but if your algorithm is O(n^2) it will take four times to process if you double the data no matter the language.

And the JVM can optimize a lot of things getting good results.

Some posible optimizations in Java

If you have functions that are called a lot of times make them final. And the same for entire classes. The compiler will know that it can inline the method code, avoiding creating method-call stack frames for that call.

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