Scala中BAT算法的实现 [英] Implemetation of BAT algorithm in Scala

查看:81
本文介绍了Scala中BAT算法的实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Scala中实现了BAT算法(我对函数式编程风格很感兴趣).BAT算法涉及的步骤如下

I have implemented BAT Algorithm in Scala (I am interested in functional programming style).Steps involved in BAT algorithm are

BAT算法的参数是

  • x:BAT的位置

我的代码运行正常,没有任何错误,但由于指定的迭代后BAT的位置没有变化,因此不需要我的代码输出.我想知道代码中哪里出了问题.我的代码如下. 我还想删除while循环,以使代码在样式上变成纯功能.

My Code is working fine without any errors but its output is not desired one as there is no change in position of BAT's after specified iteration. I am wondering where things are wrong in code. My code is below. I also want to remove while loop so that code become pure functional in style.

推荐答案

我不知道为什么,但是当单步执行通过程序时,这些代码行重置了您的位置回到原始值:

I do not know why it is, but it appears that when single stepping through your program that these lines of code reset your positions back to their original values:

        if(math.random > j.PulseRate  ){
          j.position = j.BestPosition + (Bandwidth * sum / N) //sum/d is mean of Loudness , where N is number of BAT's
        }

如果您将此代码块注释掉,那么您的职位就会改变.由于我不是蝙蝠专家,所以我不知道更改是否正确,但是它们确实会更改.

If you comment this block of code out, then your positions do change. As I am not a bat expert, I have no idea if the change is correct or not, but they do change.

希望这足以正确调试算法.

Hopefully this is sufficient to debug your algorithm correctly.

这篇关于Scala中BAT算法的实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆