BayesianLogic / blog

The BLOG programming language
http://bayesianlogic.github.io/
BSD 4-Clause "Original" or "Old" License
98 stars 31 forks source link

Case expression #198

Closed lileicc closed 10 years ago

lileicc commented 10 years ago

Support the semantic translation of case expression (the syntax for case is already supported)

195

jxwuyi commented 10 years ago

@lileicc @cberzan

Fully support Case Expression. I remove Clause. Instead, I add distribSpec and caseSpec. Now every expression becomes an ArgSpec. IfExpr and CaseExpr will be translated to caseSpec.

Also, for caseSpec, I force that all the possible branches of case expression to return a distribSpec.

I have tested on Hurricane, Burglary and tugwar

Also, I tested the following example:

fixed Integer f(Integer x) = if x>1 then 1 else 2; random Integer X ~ UniformInt(1,3); random Integer Y ~ UniformInt(5,6); random Integer Z ~ UniformInt(X,Y);

query f(X); query Z;

lileicc commented 10 years ago

LGTM! :+1: Very good. Perhaps the best one can do within the time limit.

lileicc commented 10 years ago

will merge after the new-distrib-interface merged.

lileicc commented 10 years ago

@jxwuyi example/general-fixed-fun.blog doesnot work! Please fix!

lileicc commented 10 years ago

@jxwuyi There is a major bug! The way you are using cpd setParams is incorrect!

random Real x ~ UniformReal(1, 2);
random Real y ~Gaussian(0, 1);
random Real z ~ Gaussian(x, 1);
random Real a ~ Gaussian(1, x);
random Real b ~ Gaussian(y, x);

All these should work. Please see doc in CondProbDistrib.

for example, in Gaussian, setParam(Object[] params) should take Object[2]. always two parameters. at construction time, the fixed value will be passed, the rest will be null. At sampling time, random values will be passed, the rest will be null.

lileicc commented 10 years ago

Line 231 - 286 in DistribSpec is implemented incorrectly!

lileicc commented 10 years ago

@jxwuyi Pointed out that the error was due to FuncCallExpr. I tested example/hurricane-new.blog It works under the new case-expression.

I will merge this one. then create a new issue for FuncCallExpr.