Open cronburg opened 9 years ago
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.
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 https://github.com/BayesianLogic/blog/issues/329.
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.
I would be interested in seeing a list-comprehension-like syntax for categorical distributions. For instance:
would create a distribution over cards
c
satisfyingbar(c) < limit
with probabilitiesfoo(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 thecomprehension_expr
grammar rule, where: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.