Can anyone tell me why the 2 scripts that i attached are giving different outputs for the same inputs?
2 次查看(过去 30 天)
显示 更早的评论
Can anyone tell me why the 2 scripts that i attached are giving different outputs for the same inputs?
They should be doing exactly the same and it's crushing my brains.
The second script also seems to be slower and it's graph is less good than the first script, I have no clue why.
6 个评论
John D'Errico
2020-1-11
编辑:John D'Errico
2020-1-11
I'm not sure what I said that bothered the legend. But the point is, it can easily take far more time than just a few minutes to figure out what is being done, then digging deeply into the code, finally explaining what the problem is. When you make it difficult for someone to figure out what you are doing, that makes it just that less likely that someone will bother to make the effort to tackle your problem.
Make it easy for somone to help you. That means you need to tell them what you are trying to do, and what result you expect. In a case like this, you need to explain why you see a difference, and why you think it is significant. Is the difference just a difference in the least significant bits of a number (often the case) or is it something big?
One thing you should consider is that completely undocumented code is just a bunch of apparently random commands, doing whatever you decided to do. Figuring out what the code should do from just the code can be very difficult, especially when there are many functions involved calling each other.
Remember, you are asking someone (who is wholly unpaid to do this task) to invest potentially as much as an hour or more of their time on you. I can often spend more than an hour or more writing a response to a question, especially when followups are considered. By making it easy for someone to help you, you make it more likely that someone will invest that time in you.
Meg Noah
2020-1-11
I don't know if this will fix it, but when you run monte carlo operations twice, without reinitializing the random number stream seed, then the algorithms will be operating on two different data sets and necessarily will produce different results. Depending on where and how the random numbers are called, you want to be sure they are solving the same set of mazes. If the only place rand is called is in the generation of a new maze,then executing this once in the main program should result in getting the same set of mazes to solve - you need to check it. The monte carlo solution should have a seed value that is the same. Here, it is '1' but you can make it any number even 8675301 if you want.
s = RandStream('mt19937ar','Seed',1);
RandStream.setGlobalStream(s);
If there are other places where rand is called, then it's going to be more complicated because you want the two algorithms to solve the same maze. Ideally, have the maze generated in a main,, and then send it to the different solvers all in one program.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Labyrinth problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!