• 0

Values of the function parameters are changing randomly (but they're not modified from the code)


Question

Hi, I have to implement an NBC (for finding clusters in the provided set of data) algorithm at my class project with a friend. We came across very strange issue. There are few helper functions, and the one with a problem is kNN (possibly kEN too) in the kNB.h file. After passing arguments to it from the main function of the program (for example k=3 and p=5), it goes to the kNN function and starts changing values of k and p randomly, even though function code is not supposed to do that anywhere as you can see below.

 

Also, while using debugging mode and going through this function step by step I noticed that it sometimes comes back before the first while which I think shouldn't happen. I guess it may be some trivial mistake, but I'm not very good at C++ (unfortunately we were ordered to use it). You can download entire Visual Studio 2013 solution from here: https://dl.dropboxusercontent.com/u/1561186/EDAMI.rar. So, does anyone have any idea why described situation is happening?

static vector<int> kNN(int k, int p, Dataset<V>* records)
{
	int b = p, f = p;
	bool backwardSearch, forwardSearch;
	vector<int> tmp;
	LengthMetric<V>* lengthMetric = records->getLengthMetric();

	backwardSearch = PrecedingPoint(records, b);

	forwardSearch = FollowingPoint(records, f);

	int i = 0;

	while (backwardSearch && forwardSearch && i < k)
	{

		if (records->getRecord(p)->getLength() - records->getRecord(b)->getLength() < records->getRecord(f)->getLength() - records->getRecord(p)->getLength())
		{
			i++;
			tmp.push_back(b);
			backwardSearch = PrecedingPoint(records, b);
		}
		else
		{
			i++;
			tmp.push_back(f);
			forwardSearch = FollowingPoint(records, f);
		}
	}

	while (backwardSearch && i < k)
	{

		i++;
		tmp.push_back(b);
		backwardSearch = PrecedingPoint(records, b);
	}

	while (forwardSearch && i < k)
	{
		i++;
		tmp.push_back(f);
		forwardSearch = FollowingPoint(records, f);
	}

	return tmp;
}

5 answers to this question

Recommended Posts

  • 0

its because you're debugging the release executable. turn optimizations off when you want to debug. configuration properties->c/c++->optimization set to disable. or just set the configuration type to debug instead of release when you want to debug. in your project,the active configuration currently is release,not debug.

3yA2sxi.png

  • 0

I ran your code and cannot observe the behavior you describe. The code cannot modify the values of k and p unless perhaps through stack corruption. How did you determine that the values change?

This topic is now closed to further replies.
  • Posts

    • This is the Superman film I had been waiting for. The tone was fine, yes a little more “fun” than previous outings but a lot of that came from supporting characters. Krypto was well handled, and somehow managed to not be an annoying distraction and actually a valid part of the story. Hoult was GREAT as Luthor. Genuinely so happy that this wasn’t crap. I personally enjoyed Superman Returns, despite its flaws (tried too much to hide behind the older movies, had no real fight to Superman). I enjoyed the Man Of Steel movies despite their flaws (totally that is NOT Superman). But this - this is the film I had wanted. In the UK we are far more reserved in cinemas than Americans. It’s rare that there is the whooping and hollering that we have seen from videos of US theatres, so when I say that the audience clapped at the end of this - it’s quite a big deal. As for all this “Superman has gone woke” BS - he is freaking Superman and if at any point in that movie you found yourself pooh-pooing his actions, you are just - you’re aligning your thinking with the problems and not the solutions. I adore how the movie addressed the modern world through thinly veiled allegory (Israel, online bots, perceptions of people, how they change on a dime) - that is maybe one of the greatest strengths of  comics, they rarely pull punches with that sort of thing, and look, THIS IS SUPERMAN, he’s meant to be the global boyscout and that is a strength and where he falls down sometimes, that’s just who he is and who he is meant to be. I also am glad there was no reference to the worldwide joke that is “Truth, Justice and the American way”.
    • People do it everywhere. Should be legal to be allowed to bitch slap people who put their phone on speaker in public places
    • Or Editpad 👍
    • They work like drug dealers. First we get free samples and when we like it they start charging for it. Wasn't there some uproar lately about the (possibly subbed) AI features in the new Nothing phones as well? Expect subs down the line, as AI cost a lot of money to run. And you're going to pay for it in the end 🤨
  • Recent Achievements

    • One Month Later
      Ricky Chan earned a badge
      One Month Later
    • First Post
      leoniDAM earned a badge
      First Post
    • Reacting Well
      Ian_ earned a badge
      Reacting Well
    • One Month Later
      Ian_ earned a badge
      One Month Later
    • Dedicated
      MacDaddyAz earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      504
    2. 2
      ATLien_0
      207
    3. 3
      Michael Scrip
      205
    4. 4
      Xenon
      141
    5. 5
      +FloatingFatMan
      115
  • Tell a friend

    Love Neowin? Tell a friend!