Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comprehension_expr for Categorical distributions #329

Open
cronburg opened this issue Nov 5, 2014 · 2 comments
Open

comprehension_expr for Categorical distributions #329

cronburg opened this issue Nov 5, 2014 · 2 comments

Comments

@cronburg
Copy link

cronburg commented Nov 5, 2014

I would be interested in seeing a list-comprehension-like syntax for categorical distributions. For instance:

Categorical({c -> foo(c) for Card c : bar(c) < limit})

would create a distribution over cards c satisfying bar(c) < limit with probabilities foo(c).

The only other way I can think of to do this right now is with meta-programming in a general purpose language to generate the exhaustive list of categorical values and probabilities in the existing BLOG syntax. Is there an alternative I'm missing?

I tried adding a rule like expression_pair:ep FOR type_var_lst:vars opt_colon_expr:condexpr to the comprehension_expr grammar rule, where:

expression_pair ::=
    expression:e1 RIGHTARROW expression:e2
    {: RESULT = new ExprTupleList(e1, e2, null); :}
  ;

but I couldn't get the compile & stage to notice my changes - I've never used sbt or jflex before, and don't really have time anytime soon to figure it out myself.

@lileicc
Copy link
Contributor

lileicc commented Nov 5, 2014

Very good suggestion!

It is not list-comprehension, but a dictionary-comprehension.

In blog, the list-comprehension is planned but not supported yet.
Dictionary-comprehension is not planned yet.

If you plan to work on this, we would very welcome your contribute.
Here are a few things you need to do.

  1. modify the parser, blog.cup file (you probably do not need to modify
    jflex)
  2. add/modify abstract syntax tree if needed.
  3. add appropriate semantic processing in blog.semant.Semant.java
  4. add/modify blog.model.MapSpec.java

Alternatively, you donot really need dictionary-comprehension if your type
is in closed domain (i.e. no number statement). You may use Discrete
combined with toInt etc.

Lei

On Tue, Nov 4, 2014 at 10:34 PM, Karl Cronburg notifications@github.com
wrote:

I would be interested in seeing a list-comprehension-like syntax for
categorical distributions. For instance:

Categorical({c -> foo(c) for Card c : bar(c) < limit})

would create a distribution over cards c satisfying bar(c) < limit with
probabilities foo(c).

The only other way I can think of to do this right now is with
meta-programming in a general purpose language to generate the exhaustive
list of categorical values and probabilities in the existing BLOG syntax.
Is there an alternative I'm missing?

I tried adding a rule like expression_pair:ep FOR type_var_lst:vars
opt_colon_expr:condexpr to the comprehension_expr grammar rule, where:

expression_pair ::=
expression:e1 RIGHTARROW expression:e2
{: RESULT = new ExprTupleList(e1, e2, null); :}
;

but I couldn't get the compile & stage to notice my changes - I've never
used sbt or jflex before, and don't really have time anytime soon to figure
it out myself.


Reply to this email directly or view it on GitHub
#329.

@cronburg
Copy link
Author

cronburg commented Nov 5, 2014

Thanks for the info!

The example I had in mind is definitely closed domain - foo(c) returns a fixed Integer in my example, so I'll look into Discrete first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants