Coder Social home page Coder Social logo

lotlib3's People

Contributors

gureckis avatar piantado avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

lotlib3's Issues

registering primitives to `builtins`

Awesome library, thank you!

I have a minor design suggestion that I think would make the library a bit more intuitive and easy to use. At the moment, primitive functions are registered by assigning them to builtins.__dict__. This makes it difficult to benchmark different grammars with different versions of the same primitive functions, especially when those functions are given the same name. Basically you can only use one grammar version per interpreter session.

One alternative would be to have register_primitive assign the primitive function to a specific grammar instance. You'd have to modify LOTHypothesis.compile_function() to somehow factor in self.grammar when evaluating the expression string.

Just a thought - perhaps this change is a little more nuanced than I imagine.

one questions about primitives

hi, great library. asking a question here in case it is useful to someone later. I'm not entirely clear on the advantages of using a string versus a LOTLib-provided primitive. For instance, both of these should work the same from the user/modeler perspective:

grammar.add_rule('EXPR', '(%s + %s)', ['EXPR', 'EXPR'], 1.0)

and

grammar.add_rule('EXPR', 'plus_', ['EXPR', 'EXPR'], 1.0)

with the later using the built-in 'plus_' primitive. I understand the registering new primitives is critical for adding custom functionality but unclear why LOTlib3 goes so far as to provide primitive things like addition if they would be interpreted correctly by the python interpreter just as a string.

thanks!

grammar.enumerate_at_depth seems to have bug

I tried this: a simple right branching grammar for binary sequences

grammar = Grammar(start='S')

# basic symbols
grammar.add_rule('S', '"0"', None, 0.5)
grammar.add_rule('S', '"1"', None, 0.5)

# concatenation
grammar.add_rule('S', 'concat_', ['"0"', 'S'], 1)
grammar.add_rule('S', 'concat_', ['"1"', 'S'], 1)
grammar.add_rule('S', 'concat_', ['"101"', 'S'], 1)

trees = grammar.enumerate_at_depth(1)

for t in trees:
    print(t)

get error

`RuntimeError Traceback (most recent call last)
/Users/hh7792/Desktop/Knitting/Knitting.ipynb Cell 6 line 1
16 trees = grammar.enumerate_at_depth(1)
18 # t = eval(str(formula))
---> 19 for t in trees:
20 print(t)

File ~/Desktop/Knitting/LOTlib3/Grammar.py:297, in Grammar.enumerate_at_depth(self, d, nt, leaves)
294 # BVRuleContextManager here makes us remove the rule BEFORE yielding,
295 # or else this will be incorrect. Wasteful but necessary.
296 with BVRuleContextManager(self, fn, recurse_up=False):
--> 297 yieldfn.args = next(myiter)
298 for a in yieldfn.argFunctionNodes():
299 # Update parents
...
--> 316 state[idx] = next(iterators[idx])
317 break # break the idx loop (which would process "carries")
318 except StopIteration:

RuntimeError: generator raised StopIteration`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.