在哪里编写这个启发式代码?
我想问一个复杂的问题。
我必须为我的论文编写启发式代码。我需要以下内容:
- 评估一些积分函数
- 在一个间隔内最小化函数
- 这样做成千上万次。
所以我需要一种更快的编程语言来完成这些工作。您建议使用哪种语言?首先,我从 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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 ).
这不是编程语言,这可能是你的算法。确定算法的 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).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.在开始切换语言之前,我首先尝试执行以下操作:
例如,有 Java 的科学库。尝试使用这些库。
Before you start switching languages, I'd first try to do the following things:
There are e.g. scientific libraries for Java. Try to use these libraries.
算法的顺序
通常,在语言之间切换只会减少一个常数因子所需的时间。假设您可以使用 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.