7
\$\begingroup\$

One of the key requirements for posting here is

working code to the best of our knowledge

Where working means that the code compiles and returns correct results.

Where does that put Monte Carlo algorithms

whose output may be incorrect with a certain (typically small) probability.

Does that mean that they are by default off-topic? (Because they return the wrong result with a certain small probability.)

Is the definition of "working code" another one in this context and if so what should it be?

Update

Of course it is clear that we don't want to forbid Monte Carlo code from being reviewed. However, where is the line between off- and on-topic for Monte Carlo questions?

This is probably off-topic but why:

int add(int a, int b) { return rand(); }

And where do you draw the line?

\$\endgroup\$

2 Answers 2

13
\$\begingroup\$

No, they're on topic, as long as you specify that it is a monte-carlo algorithm. Ideally, you'd specify the probability of success, but doing so is optional.

Why? Because the code isn't broken; it's doing exactly as stated.

Asking us to fix a monte-carlo algorithm to be perfect is off-topic however.


Looking at your example: It's lacking context as to why you'd do that. That's why it's offtopic. As to whether it'd be off-topic with context? No. It'd be on-topic. I'd love to see someone explain to me why they'd need rand() for addition, and have it be a valid point.
Bottomline: For questions including Monte Carlo algorithms, you should state that it contains a Monte Carlo algorithm, as well as why you need it.

\$\endgroup\$
5
  • \$\begingroup\$ So it is off-topic if the code fails to hit the stated probability? Even worse: what if the OP has no idea about the probability? \$\endgroup\$ Aug 22, 2014 at 10:11
  • \$\begingroup\$ hadn't thought of that... I guess the probability is optional \$\endgroup\$
    – Pimgd
    Aug 22, 2014 at 10:14
  • \$\begingroup\$ I have updated the question a bit and pose the same question to you as to @Simon. \$\endgroup\$ Aug 22, 2014 at 10:21
  • 2
    \$\begingroup\$ Looks like a trivial task to me, why are you using monte-carlo for trivial tasks \$\endgroup\$
    – Pimgd
    Aug 22, 2014 at 10:22
  • \$\begingroup\$ It was just an example for a clearly off-topic Monte Carlo question to identify criteria that help determine whether a Monte Carlo question would be off-topic. \$\endgroup\$ Aug 22, 2014 at 10:24
10
\$\begingroup\$

Let's see:

  1. Is code included directly in my question? Yes
  2. Am I an owner or maintainer of the code? Yes
  3. Is it actual code from a project rather than pseudo-code or example code? Yes
  4. Do I want the code to be good code? Yes
  5. To the best of my knowledge, does the code work? (See below)
  6. Do I want feedback about any or all facets of the code? Yes

The culprit is: To the best of my knowledge, does the code work?

My definition of does the does work? is: Does it do what it is supposed to do and produce the expected results?

While Monte Carlo may produce some statistically inaccurate results, that's the point of the algorithm.

Let's assume that they were off-topic, then where would programmers go to have code for a Monte Carlo algorithm reviewed? My point exactly. Saying that it is off-topic just because it's Monte Carlo would be silly.


As for how you exactly formulate the question, such as:

  • I have this Monte Carlo algorithm, but I am not sure if it is correct or not
  • I have this Monte Carlo algorithm, is there a better algorithm to pick?
  • I have this Monte Carlo algorithm, how would you have solved it?
  • I have this Monte Carlo algorithm, how can the code be improved?
  • etc.

That's part of another discussion

\$\endgroup\$
2
  • \$\begingroup\$ Where is the line to an off-topic Monte Carlo algorithm then? \$\endgroup\$ Aug 22, 2014 at 10:15
  • \$\begingroup\$ @Nobody: Depends on what question(s) you're asking. If you aren't already confident that it works, it's off topic. If the code just needs a bit of refactoring/cleanup, it's probably on topic. The area in between is a big grey cloud, not a line. \$\endgroup\$
    – cHao
    Aug 27, 2014 at 20:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .