11

I asked a question https://stackoverflow.com/questions/42685998/why-does-this-dynamic-programming-function-not-return-optimal-results, which has votes to close on it although it hasn't yet been closed.

In Help Center > Asking, it says:

Some questions are still off-topic, even if they fit into one of the categories listed above:

"Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself."

In my post, I included what the desired behavior should be and a specific problem with the shortest code necessary to reproduce it (let me know if those should be specified here).

I don’t see anything else on that page that would qualify my post as being off-topic, but please let me know if I’m missing something so that I can either improve the post, remove it, or post it elsewhere.

12
  • 5
    It is a bit open ended. I don't understand what you want to have solved? Errors? Memory consumption? The algo itself? for the latter you'll need to provide a fixed test input set, expected outcome and actual outcome. Given that, in its current form I agree with the close votes.
    – rene
    Mar 9, 2017 at 9:04
  • 2
    I don't see anything about desired behavior. A proper MCVE would include test data, current behavior, and desired behavior.
    – tripleee
    Mar 9, 2017 at 13:25
  • Between this MSO post and the SO post in question, the word "performance" is mentioned only once - in the MSO title. For me, that's a good example of vagueness.
    – user7014451
    Mar 9, 2017 at 15:49
  • @dfd To clarify, I didn't include the word performance, as it was edited in by someone else. It was essentially a potential side issue to getting a consistent output value. Mar 10, 2017 at 4:34
  • @tripleee Although I thought the desired behavior was implied by stating "The first and main issue is that the closeness for the set of integers filtered from the larger list is not the same for each run" -- i.e. it should be the same for each run -- I'll make an edit in case that wasn't clear Mar 10, 2017 at 4:38
  • @tripleee but as Josh Caswell stated, I could probably be more detailed, although I thought that the first sentence in the post described it well (especially given how simply the "closeness" is being calculated) Mar 10, 2017 at 4:47
  • Thanks for the clarification. IMHO (this from someone who has yet to post a question but intend to soon) I'm grasping how difficult it is to ask something. Do you think you should have made two questions instead of a single one?
    – user7014451
    Mar 10, 2017 at 5:11
  • @dfd Yes. The second issue was sort of smuggled in. I was thinking that someone experienced with DP may see an obvious fix Mar 10, 2017 at 5:13
  • Last question - is it too late to edit things? Eliminate the second issue and focus solely on the first? I understand it won't likely change those close votes but in the interest of asking a quality question? (Funny, it really is one question but it took three question marks to write it.)
    – user7014451
    Mar 10, 2017 at 5:16
  • ...Not too late. I've made an edit, just not posting it yet; as stated in a comment on a different answer, generating a random list each time was the issue for not getting the same closeness -- a hasty mistake to get a working example up quickly... presently just determining whether it's giving optimal results Mar 10, 2017 at 5:21
  • I didn't intend to put words in your mouth; you should of course feel free to re-edit the title if you think it's inaccurate.
    – jscs
    Mar 10, 2017 at 16:27
  • I think I thought the title was edited with the word performance for the post in question. It isn't vague for this post, so the comment I was responding to about mentioning the term "performance" more seems muddled. Mar 11, 2017 at 3:47

3 Answers 3

23

Your title needed some work. As a rule of thumb, you shouldn't use phrases like "this function" if it can possibly be avoided. That means you're not describing the question; you're requiring people to open the page and examine the post before they have any idea whether they're interested or able to help. That's not in itself a reason to close, just a pointer. I just edited the title to make it actually describe what you're doing. It should probably be edited again, though, to reflect the other edits I'm about to suggest.

As for closing: you have stated that you have two issues.

The first issue is that [...]
The second issue is that [...]

A question on Stack Overflow should only be about one issue. Pick one. Ask about the other separately.

The main problem, though, is that neither one of these issues is all that clear.

The first one needs to be better defined: what, in detail, do you mean that the "closeness [...] is not the same"? How are you defining "closeness"? What part of the code is calculating it? Give some samples of the actual variation that you see.

The second seems to require a reader to examine your code, understand it intimately, and advise you on its performance and structure. This is a big task to casually ask of strangers who wander by. Help them get into the code: explain in small pieces what it is doing, why, and especially, which very specific bit you are concerned about (and why: you're talking about performance, so you measured it, right?)

1
  • 2
    Maybe also link to the MCVE help page although the link is there on the question now also because it was closed with this reason.
    – tripleee
    Mar 9, 2017 at 13:22
17

One problem with the example code given is that it's completely non-deterministic (the input values are generated randomly each run). It's a lot easier to explain what's wrong - and easier for others to identify the cause - if your example is reproducible. That means fixed inputs (which you could generate randomly, but once fixed, they are the same for everyone), the expected output result, and actual output result (also, if it's not obvious, what's different between the actual and expected). So I'd expect a question to be of the approximate form:

I wrote a function that's supposed to find the closest value in large for each element of small (where "closest" means smallest absolute difference):

def my_function(large, small):
    # (snip - but obviously write your code here!)

When I execute it with these inputs:

largeList = (2, 3, 5, 7, 11, 13, 17)
smallList = (5, 10)
print(my_function(largeList, smallList))

the output is

(3, 11)

I expected

(5, 11)

because 5 is closer to 5 than it is to 3.

Why am I getting 3 instead of 5 for the first element?

If you keep the input sets small, it will help tracking down your bug - in fact, it might even help you solve it yourself, without needing the help of SO!

5
  • 6
    I'd also want to see "I expected this because the function is supposed to do [yada yada]". The OP refers to distances between pairs of sets but neglects to explain the metric before simply pasting all the code.
    – Frank
    Mar 9, 2017 at 15:27
  • 2
    @Frank - absolutely agreed; I'll see how I can show that Mar 9, 2017 at 15:54
  • I don't think you meant "it's completely non-deterministic." I think you meant it needs a specific example input and output so that correctness can be determined. Non-deterministic would mean that for a set of inputs a, the output can be a, b, or anything (i.e. the output cannot be determined based on the input). A random input doesn't make an algorithm non-deterministic -- if that random input is captured and run again, and the same output is returned, then the algorithm is, by definition, deterministic. Mar 9, 2017 at 17:56
  • 1
    @Robert, the example in the question didn't accept any input - the code has lines such as smallList = sorted([random.randint(1, 101) for i in range(50)]). No indication of which sets of values could be captured and turned into an input. Mar 9, 2017 at 17:59
  • @Toby Speight, I just noticed the randomness issue, and was a hasty mistake in effort to get a working example running. I'm now getting the same (total) closeness value with each run, but am just determining whether it is optimal (and as you said, from smaller inputs) Mar 10, 2017 at 5:15
5

Visually, your question seems well-formatted. But I don't know anything about Python. From the comments/votes, it seems the code you provide is not enough to show your efforts or to reproduce the bug, or you didn't explain enough precisely what you are trying to achieve.

Klaud D. wrote a constructive comment on your question, so I link it here:

You have explained your problems, programming is actually solving such problems. On SO you will get help when you get stuck with your solution but you will have to give a very clear statement where you are having the problem, not just "I need a solution for...".

How could you improve?

The sample of code you provided is quite big, could you make it shorter?

Could you explain differently what you are trying to achieve? To be clearer, you can (for example) give a sample of the desired output/sample.

0

You must log in to answer this question.

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