Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Quick Java question re Double

  • 09-01-2009 2:10pm
    #1
    Registered Users, Registered Users 2 Posts: 1,712 ✭✭✭


    Hi Guys,

    Just a quick question i have here.

    I have a fairly complex equation that is being calculated and inserted into an array each iteration of a loop. The number of iterations could be infinite, but as i up the number of iterations from say 10000 to 100000, NaN (not a number) is being stored instead of the actual number. I was guessing that i was deciding by zero in certain circumstances of a particular iteration but I dont think that is it.

    I was just wondering what cause it to go from being a double of say 3.94548721857 in a certain iteration to being NaN in the next?

    Thanks in advance to any replies!!

    Neil


    EDIT: I was thinking the use of floats may fix this as the mantissa is growing too big??? but i dont know, said id ask yous first because it will be a lot of work to change it around.


Comments

  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    That depends on the equation and its inputs. Are you using the previous outcome of the equation as the input for the next iteration?

    Does it change to NaN after a particular number of iterations or is it random?


  • Registered Users, Registered Users 2 Posts: 1,712 ✭✭✭neil_hosey


    it is a 3D array that could after a number of iterations return to a particular location in the array and make multiple updates to the same location based on the previous double in that location if that makes sense :confused:

    The part of the equation where i think it is occuring is:

    array[1][1][1] = array[1][1][1] + .8 *( Reward + (gamma * anotherArrayValue)) - array[1][1][1]

    where gamma is a double between 0 and 1.

    And the reward can be any value from minus 100 or so to plus 100.

    Its been bugging the hell out of me for a few days now.


    I will do change the code now to see if i can see after how many interations at a particular point in the array is it turning to NaN.


  • Registered Users, Registered Users 2 Posts: 68,317 ✭✭✭✭seamus


    neil_hosey wrote: »
    I will do change the code now to see if i can see after how many interations at a particular point in the array is it turning to NaN.
    For debugging purposes, check the end value of the calculation for NaN. If it is NaN, then break out of the loop and print to the screen:

    The input to the equation
    The location in the array where it happened.
    The end resut

    Yes, breaking out of loops is bad practice, but for debugging purposes it's fine.

    If the loop never breaks, then you'll know that the calculation is working, but something is going weird when it's inserted into the array.


  • Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭Anima


    Any chance you could post a bit more of the code? Also 3 dimimensional arrays are a bad idea in my opinion.

    I may be reading this wrong but why are you adding array[1][1][1] and then subtracting it in the same line?


  • Registered Users, Registered Users 2 Posts: 1,712 ✭✭✭neil_hosey


    thanks for the input guys..

    Im kind of snookered with the 3d array. I could do without it, but the run time would be increased ten fold because of the search time that i get rid of using it.. hard to explain without going through the whole code.


    I am adding and taking away the same thing in the same iteration.. its part of the formula that i am using.. Its a reinforcement learning algorithm - Q Learning.

    will have another look later and get back. thanks again!!


  • Advertisement
Advertisement