RALLY E (Help me, internet)

FacebookTwitterTumblrPinterestGoogle+StumbleUponRedditDiggShare

So I’m writing a basic genetic algorithm using bit strings of length 16. I’m getting a weird error where some of my strings have an uneven number of 0s and 1s (and that’s after the check that I’ve built in, which always successfully corrects them). So I do a bunch of tests and fiddle around with print statments, and suddenly I find it. It is the stupidest bug I’ve ever seen my life. Stupider than june bugs, and — considering that at least 200 of them commit suicide in our lamps every year — that’s saying something.

So here’s the bug: for some reason, before and after a mapcar I’m getting this one string mysteriously changed every time. It is the same g*sh-d*rned string every single g*sh-d*rned time. Despite the fact that everything is completely random, if the string “(1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0)” is EVER generated then the mapcar FOR SOME HORRIBLE REASON THAT DEFIES MY IMAGINATION changes it to “(1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0).”

So before the mapcar it says:

(1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0)

But if I call it within the mapcar it says:

(1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0)

And once it’s spit out by the mapcar it is FOREVER CHANGED INTO THIS HORRIBLE STRING THAT HAS MORE ZEROS THAN ONES AND BREAKS MY ALGORITHM.

* weeps *

Seriously, if anyone knows what on earth is going on and can tell me, I will take you to Burger King. (That means you, Riz!)

PS: I’m sorry for yelling.

PPS: Turns out it does the same thing to a number of strings:

(1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0)
(1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0)

(1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 0)
(1 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0)

(1 0 0 1 1 1 0 0 1 1 0 1 0 0 0 1)
(1 0 0 1 1 1 0 0 1 1 0 1 0 0 0 0)

In later generations I sometimes get variants of the first error:

(1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0)
(1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 1)

Flips from 0 to 1 only seem to happen in later generations.

And it doesn’t do it to them all the time. Ideas?

FacebookTwitterTumblrPinterestGoogle+StumbleUponRedditDiggShare
  • The Rev

    Cam’s doing his master thesis on something related, IIRC. Get in touch with him.

  • http://www.tunerds.com Riz

    Without spending any real time looking at it, my initial guess is that it could be a endian issue or a 1′s/2′s compliment thingy. Those are usually the culprits I look for when I first run into some crazy bit pattern swapping. Of course if those are the issues then it should also be occurring with other bit patterns so they probably aren’t the cause.

    I’m assuming you’re talking Lisp (given the mapcar). What function are you trying to execute on the list?

    Verify the data type on the list?

    Sorry, I’m probably not helping much but if you have more info etc., e-mail me and I’ll take a look when I get a chance.

  • http://www.guzzlingcakes.com/ Eve

    The funny thing is that the function has nothing to do with it, unless the blame is on “print”. When I call the whole list outside the mapcar it’s fine, but as soon as I call the list directly it goes all wonky. (I also tried iterating through it recursively and got the same outcome.)

    Par example:

    ((0 (1 1 1 0 0 0 1 1 1 0 1 0 1 0 0 0))
    (0 (0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0))
    (0 (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1))
    (0 (0 1 0 0 1 0 1 1 0 1 0 0 0 1 1 1))
    (0 (0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0))
    (0 (0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0))
    (0 (0 1 1 0 0 1 0 1 0 0 0 0 1 1 1 1))
    (0 (0 1 1 0 0 1 0 1 0 0 0 0 1 1 1 1))
    (0 (1 1 0 0 0 1 1 0 1 0 1 0 1 1 0 0))
    (0 (1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0))
    (0 (1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 1))
    (0 (0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 0))
    (0 (1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 1))
    (0 (0 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0))
    (0 (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1))
    (0 (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1)))

    Above is the whole shebang, but when I call each one independently, I get:

    (1 1 1 0 0 0 1 1 1 0 1 0 1 0 0 0)
    (0 1 1 0 0 1 1 1 0 1 0 1 1 0 0 0)
    (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1)
    (0 1 0 0 1 0 1 1 0 1 0 0 0 1 1 1)
    (0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0)
    (0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0)
    (0 1 1 0 0 1 0 1 0 0 0 0 1 1 1 1)
    (0 1 1 0 0 1 0 1 0 0 0 0 1 1 1 1)
    (1 1 0 0 0 1 1 0 1 0 1 0 1 1 0 0)
    (1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0)

    (1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0) Error! :(

    (1 0 0 0 1 0 1 1 0 1 0 0 0 1 1 1)
    (0 1 1 0 0 0 1 0 0 1 0 1 1 1 1 0)
    (1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 1)
    (0 0 1 0 0 1 1 0 1 0 1 1 1 1 0 0)
    (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1)
    (1 0 1 0 1 0 1 0 0 0 1 0 0 1 1 1)

  • http://www.guzzlingcakes.com/ Eve

    On a side note, the first time I heard about big/little endian I thought it was called big/little “Indian” and that it was a racist throwback to when people make fun of Injuns.

  • http://muonproof.com Tavis

    Find all the strings that are giving you problems and have your program delete them. Problem solved!

  • http://www.tunerds.com Riz

    There appear to be a few other “errors” if I’m understanding everything correctly:

    (0 1 1 1 1 1 1 0 0 1 0 0 1 0 0 0) vs (0 1 1 1 1 1 1 1 0 0 0 0 1 0 0 0) –line 6
    (1 0 1 1 0 0 1 1 1 0 1 0 1 0 0 0) vs (1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0) –line 10
    and then there is an extra line in the 2nd output containing (1 0 1 1 0 0 1 0 1 0 1 0 1 0 0 0)

    The first output has 16 lines, the 2nd output has 17 lines.

    Hope that helps.

  • Shashi

    When I think about it, the internet is kind of like Ghostwriter. Sorry I am no help.

  • Pingback: The Swamp » Solved!