piantado / LOTlib3

Language of thought library for python 3
42 stars 6 forks source link

RecursionError: maximum recursion depth exceeded while calling a Python object #7

Open paraschopra opened 3 weeks ago

paraschopra commented 3 weeks ago

I'm running into this for my custom grammar. (PS: Trying to reproduce list processing task of DreamCoder).

Any tips on how to approach grammar definition that avoids this?

piantado commented 3 weeks ago

Usually this happens because the grammar definition is improper, in the sense that the expected length is infinite. That happens when rules where nonterminals go to other nonterminals have too high of a value.

So, you can try increasing the probability of nonterminals expanding to terminals.

paraschopra commented 3 weeks ago

Thanks! I read that internally python recurses stack 999 times, so maybe this is what's happening.

paraschopra commented 3 weeks ago

btw @piantado do you have any tips on how to think of probabilities?

also, i noticed fleet has enumerator but lotlib3 doesn't have (it only has MCTS). Any reason? While trying to induce programs for given input/output, isn't enumeration better? I imagine MCTS wastes a lot of cycles iterating over same programs that don't fit the data

paraschopra commented 3 weeks ago

Can you guide me how to enumerate programs? I don't see any basic sampler other than Metropolis Hastings in the library.

piantado commented 3 weeks ago

Yes the error comes from python reaching its recursion limit, but the reason that happens is that the grammar assigns probability to infinitely big trees if the probability on terminals is too low. So if you increase the probability on terminals, your prior will put more mass on small trees, and eventually give zero mass to infinite ones.

paraschopra commented 3 weeks ago

Yep, I did that and now the error is no more.