Skip to content

Defect in maximum calculation #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
michaldo opened this issue Mar 15, 2018 · 3 comments
Open

Defect in maximum calculation #3

michaldo opened this issue Mar 15, 2018 · 3 comments

Comments

@michaldo
Copy link

A standard pattern is used for maximum calculation:

double maxValue = Double.MIN_VALUE;
for (int nextAction : actionsFromState) {
  double value = Q[nextState][nextAction];
 
  if (value > maxValue) 
    maxValue = value;
}

But Double.MIN_VALUE in Java is not minimal double but minimal positive value. See https://stackoverflow.com/questions/3884793/why-is-double-min-value-in-not-negative for details.

Especially, if each value considered in for-loop is 0, calculated maximum is Double.MIN_VALUE, because Double.MIN_VALUE > 0.

However, replacing Double.MIN_VALUE with Double.NEGATIVE_INFINITY cause wrong calculation. In such case maxQ(8) is Double.NEGATIVE_INFINITY and whole calculation fails.

Summary: maximum calculation is implemented wrong or at least misleading. It hard to me to propose a solution because it is not clear to me what is expected to be maxQ(8)

@muhammad-ahsan
Copy link

muhammad-ahsan commented Jun 18, 2018

I checked the code and I found the same issue as described above. Please use double maxValue = Double.NEGATIVE_INFINITY otherwise condition is never satisfied when it should be
if (value > maxValue)
maxValue = value;

@technobium
Copy link
Owner

Thanks for the observation. I changed the code.

@SimonAsenime
Copy link

While testing your code, I found that having double maxValue = Double.NEGATIVE_INFINITY throws off the whole calculation. Using Double.MIN_VALUE should fix things. Well, it runs perfect using MIN_VALUE anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants