RALLY E (Help me, internet)
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?
The Rev said,
November 20, 2006 at 7:44 pm
Cam’s doing his master thesis on something related, IIRC. Get in touch with him.
Riz said,
November 20, 2006 at 8:02 pm
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.
Eve said,
November 20, 2006 at 8:32 pm
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)
Eve said,
November 20, 2006 at 8:34 pm
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.
Tavis said,
November 20, 2006 at 9:25 pm
Find all the strings that are giving you problems and have your program delete them. Problem solved!
Riz said,
November 20, 2006 at 10:26 pm
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 said,
November 21, 2006 at 4:11 pm
When I think about it, the internet is kind of like Ghostwriter. Sorry I am no help.
The Swamp » Solved! said,
November 23, 2006 at 9:32 am
[…] I solved my LISP problem. I was using a destructive function to mutate parts of my string. Certain structures were referencing each other within the population without my knowledge, which caused that descructive function to alter more than it should. I’ve rewritten the functions and there have been no more errors! Problem solved! […]