So I've spent a couple of evenings debugging my code, trying it in different languages to see whether it was me or the built-in functions I used (it was me), so I ended up with the same model in R, Python, and GAMS. I figured I might as well post the code on the web.
Yes, I found the problem, and no, I'm not going to tell what it was because I find it too embarrassing.
Yes, I found the problem, and no, I'm not going to tell what it was because I find it too embarrassing.