Coder Social home page Coder Social logo

bayesianlogic / blog Goto Github PK

View Code? Open in Web Editor NEW
98.0 32.0 31.0 34.25 MB

The BLOG programming language

Home Page: http://bayesianlogic.github.io/

License: BSD 4-Clause "Original" or "Old" License

Shell 0.19% Scala 1.31% Python 1.08% CSS 0.28% Java 87.43% JavaScript 8.79% HTML 0.10% Batchfile 0.35% Lex 0.47%

blog's Introduction

BLOG overview

Build Status

Bayesian Logic (BLOG) is a probabilistic modeling language. It is designed for representing relations and uncertainties among real-world objects. For instance, tracking multiple targets in a video. BLOG makes it easy and concise to represent:

  • uncertainty about the existence (and the number) of underlying objects
  • uncertain relations among objects
  • dependencies among relations and functions
  • observed evidence.

Using BLOG

  • Requirements: Java 1.6 or above (1.7 or above preferred)
  • User manual

Compiling

  • For Linux/Mac:
  sbt/sbt compile
  sbt/sbt stage
  • For Windows:
  sbt\sbt compile
  sbt\sbt stage

Developer

Please read first: Developer's guide

Files

  • blog main execution file to run the engine
  • dblog main execution file to run the engine with particle filter (alternative can use blog)
  • parse.sh to check the syntax of a blog file (very useful for debugging)
  • docs/content/pages/release-note.md contains all release information and major changes

Syntax highligher for editors

  • sublime: see instruction under tools/blog-for-sublime
  • emacs: see tools/blog.el
  • vim: see tools/blog.vim
  • latex pdf: blog_py_lexer, requires a python library pygments, and a latex package minted

Working with Eclipse

  • Generate eclipse project files
  sbt/sbt eclipse

Package and Release

  sbt/sbt universal:package-bin

Web server

All files for web engine are under web. It requires python-webpy package. See web/README.md. To run the engine, please follow the instructions in web/README.md.

Readme Updated: July 2, 2014

blog's People

Contributors

akanata avatar amatsukawa avatar augustoproiete avatar cberzan avatar chengxiang avatar chrisdxie avatar chrisgioia64 avatar danwang avatar datang1992 avatar geraldfong avatar grumpyrabbit avatar jxwuyi avatar lileicc avatar rbharath avatar sharadmv avatar tejasvsrinivasan avatar williamcushing avatar xc9 avatar yberol 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  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  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  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

blog's Issues

MultivarGaussian can't take literal mu and sigma

This works:

fixed RealMatrix mu = [0.0; 0.0];
fixed RealMatrix sigma = [1.0, 0.0; 0.0, 2.0];
random RealMatrix x ~ MultivarGaussian(mu, sigma);
query x;

But this doesn't work:

random RealMatrix x ~ MultivarGaussian([0.0; 0.0], [1.0, 0.0; 0.0, 2.0]);
query x;

Error:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at blog.model.Clause.initCPD(Clause.java:358)
    at blog.model.Clause.compile(Clause.java:323)
    at blog.model.DependencyModel.compile(DependencyModel.java:262)
    at blog.model.RandomFunction.compile(RandomFunction.java:183)
    at blog.model.Model.compile(Model.java:566)
    at blog.Main.setup(Main.java:607)
    at blog.Main.main(Main.java:171)
Caused by: java.lang.ClassCastException: java.util.ArrayList cannot be cast to blog.common.numerical.MatrixLib
    at blog.distrib.MultivarGaussian.<init>(MultivarGaussian.java:88)
    ... 11 more
Error initializing CPD at 1: java.lang.ClassCastException (java.util.ArrayList cannot be cast to blog.common.numerical.MatrixLib)
Encountered 1 errors in compilation phase.

organize several scripts and makefile

I am going to rearrange a few scripts. Afterwards,

  1. makefile will contain all build commands, no need to have seperate compile.sh and gen_parser.sh
  2. make will compile the source
  3. make parser will re-generate the parser (only if you changed blog.flex or blog.cup)
  4. run.sh will be renamed to blog
  5. run_pf.sh will be renamed to dblog
  6. The makefile should work under linux and macosx.
    The scripts for windows (*.bat) will be kept.

Need a MapSpec that subclasses ArgSpec

Currently, maps are processed by a hack:

https://github.com/amatsukawa/dblog/blob/NewCategorical/src/blog/semant/Semant.java#L638

List<ArgSpec> transExprList(ExprList e, boolean allowRandom) {
    List<ArgSpec> args = new ArrayList<ArgSpec>();
    for (; e != null; e = e.next) {
        Object o = transExpr(e.head);
        if (o instanceof List)
            return (List<ArgSpec>) o;
        args.add((ArgSpec) o);
    }
    // TODO add checking for allowRandom

    return args;
}

The use of instanceof is temporary to make the Urn-Ball example work. Currently, the map {Blue -> 0.5, Green -> 0.5} gets mapped to a List<ArgSpec> = [0.5, 0.5] This is the way such arguments were processed, before we explicitly introduced the concept of a map in the syntax.

The current implementation makes it impossible to have a map along with other parameters (because the loop terminates as soon as it sees a List). I am currently working on adding a new ArgSpec subclass MapSpec to solve this issue.

Distribution definition in BLOG.

In BLOG, we define some library module with the following statement

distribution Real Gaussian(Real mu, Real std) = Gaussian(mu, std);

It defines a Gaussian distribution, with two Real parameters, and a Real return value. Its implementation is the Gaussian class (which is blog.distrib.Gaussian).
Equivalently, we could also state

distribution Real Gaussian(Real mu, Real std) = blog.distrib.Gaussian(mu, std);

Related to #136 .

Uniform Random Variable likelihood

@lileicc @cberzan
For a uniform random variable defined on Uniform[Range] the probability is 1/Range if in the range and zero else. This causes problem in the birds migration branch as all the features are defined as uniform random variables and their total log-probability becomes so low -240K which is lower than the negligible_log_weight constant in the sampler.

The solution is to change the uniform distribution getProb such that it returns 1 when in the range and zero else and for getLogProb it should be 0 when in the range and -Inf else.

requires immediate attention.

type checking error for list construction expression in random function

@tejasvsrinivasan @lileicc @cberzan

This one works fine:

fixed Real[] probs = [10.0; 5.0; 3.0; 1.0];
fixed RealMatrix initial_value = [100, 200, 300, 400];

random RealMatrix birds(Timestep t){
    if t==@0 then = initial_value
    else ~ Multinomial(1000, probs)
}; 

query birds(@0);
query birds(@1);
query birds(@2);

this one however fails:

fixed Real[] probs = [10.0; 5.0; 3.0; 1.0];
fixed RealMatrix initial_value = [100, 200, 300, 400];

random RealMatrix birds(Timestep t){
    if t==@0 then = [100, 200, 300, 400]
    else ~ Multinomial(1000, probs)
}; 

query birds(@0);
query birds(@1);
query birds(@2);
./run.sh ~/Desktop/DARPAchallenge/BirdMigration/code/blog_issue_ex.blog -n 1
Using fixed random seed for repeatability.
(no location): Illegal value for deterministic distribution: [100, 200, 300, 400]
/Users/yberol/Desktop/DARPAchallenge/BirdMigration/code/blog_issue_ex.blog::0.0: type checking failed

Fatal error: File interpretation halted due to error(s) in "/Users/yberol/Desktop/DARPAchallenge/BirdMigration/code/blog_issue_ex.blog".

diag function

@cberzan @lileicc

it would be useful to have the diag function which returns

diag([1 2 3]) ==> [1 0 0; 0 2 0; 0 0 3]

and maybe its complementary which is

diag( [1 0 0; 0 2 0; 0 0 3] ) ==> [ 1; 2; 3]

array expression after function application not working: birds(t)[0][0]

@lileicc & @cberzan

example bird migration code:

fixed Real[] probs = [10.0; 5.0; 3.0; 1.0];

random RealMatrix birds(Timestep t){
    if t==@0 then = [100 200 300 400]
    else = sum( TransferMat(Prev(t)) )
}; 

random RealMatrix b1(Timestep t) ~ Multinomial(birds(t)[0][0], probs) ;
random RealMatrix b2(Timestep t) ~ Multinomial(birds(t)[0][1], probs) ;
random RealMatrix b3(Timestep t) ~ Multinomial(birds(t)[0][2], probs) ;
random RealMatrix b4(Timestep t) ~ Multinomial(birds(t)[0][3], probs) ;

random RealMatrix TransferMat(Timestep t) = vstack(vstack(vstack( transpose(b1(t)), transpose(b2(t)) ),  transpose(b3(t)) ),  transpose(b4(t)) ) ;

query birds(@1);
query birds(@2);

Add Array Support

Proposed Array Syntax

Definition

fixed NaturalNum[] zeros = [0, 0, 0, 0];

fixed NaturalNum[][] i2 = [[1, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 1]];

Indexing

fixed NaturalNum nil = zeros[0];

fixed NaturalNum one = i2[2][2];

Function Signatures

random Real[] aVector ~ Dirichlet(1.0, 5);

random Real magnitude(Real[] vector) = sqrt(dot(vector, vector));

random Real[] normalize(Real[] vector) = norm(vector);

simple progress bar

@lileicc @cberzan

it would be useful to print how many time steps the particle filter have processed.
See displayprogress of MATLAB.

function reverseStr = displayprogress(perc,reverseStr)
msg = sprintf('%3.1f', perc);
fprintf([reverseStr, msg, '%%']);
reverseStr = repmat(sprintf('\b'), 1, length(msg)+1);
end

comparison

The current way of handling comparison is through ComparisonFormula.java
However, there are several build-in functions LessThan, LessThanOrEqual, GreaterThan, GreaterThanOrEqual. We do not need both.

Bharath, would you please explain a bit why you introduced ComparisonFormula?

FAQ list

Use this issue to accumulate FAQs from first-time users. We will then put it on our website before the summer school.

General:

  • How is BLOG different from Church? (provide example of semantics difference)
  • How is BLOG different from Infer.net?
  • How is BLOG different from Markov Logic Nets?

How to do things with BLOG:

  • Why always get the same results? Use -r.
  • How is the number of samples determined? 10K by default; use -n.
  • Why doesn't fixed Integer foo(Integer a, Integer b) = a + b work? (Presumably we will fix this by the summer school.) (works now!๏ผ‰
  • How to debug the syntax of BLOG program? Use bloglint <filename>

Developers:

  • What is EqualsCPD and why is it necessary?
  • How to write fixed functions with Java interpretations? (@cberzan can write tutorial on this)
  • How to memory-profile a BLOG run? (@cberzan can write tutorial on this)

Imply operator, Mapping and Set operator

Please vote your preference.

  1. use imply with =>, mapping still use ->
    reason: scala uses -> for mapping
  2. use imply with ->, mapping still :
    reason: python uses : for mapping
  3. drop imply, mapping remains ->
    reason, imply can already be represented with not and or
  4. drop imply, mapping change to :
    reason: shorten the operator by 1 character

This Issue is also related to the use of braces {}. {} are used both as a Map and Set.
We may need to distinguish them as well.
which one do you think better:
a. keep as it is
b. use {} for Map, and use Set() for set.
c. use {} for Map, use {} for implicit set, but explicit set will dropped, replaced with list, and allow statement like
obs {Ball b} = [B1, B2, B3]
It will do automatic type conversion from list to set internally.

Web UI not running

There is no result produced by web UI.

Dan and ChengLai
Would you please have a look and fix the bug.

Thanks!
Lei

Easy Query for Tuple Set of Objects with Origin Function

In the Aircraft Detection problem, assume there are some number of distinct aircrafts. There should be a fast way of querying some property of the Blips that come from Aircraft a.

The tuple set query:

  {b for Blip b : Source(b) = a}

should be easily written as something like Blip(Source=a) or {Blip(Source=a)}

Handling For Operators +,-,*,/, <, > etc

Currently, only & and | are supported operators. A number of examples rely on other operators. For example, aircraft-wandering.dblog has code:

Blip(Source = a, Time = t)

if Position(t) > -7 & Position(t) < 7                                           
    then ~ TabularCPD({0 -> 0.0, 1 -> 1.0})                                     
    else ~ TabularCPD({0 -> 1.0, 1 -> 0.0});                                    

The extra operators will require adding a few more model classes to handle representation.

uniform vector issue

@lileicc @cberzan

type Location;
distinct Location l[16];

random RealMatrix F1(Location src) ~ UniformVector(-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5,-2.5,2.5); // windspeed feature 
obs F1(l[0]) = [1.410751850246407; 1.4976456434275582; 0.28166721933972383; -1.2139307163871753; -0.750881347576537; 1.9633685007549087; 0.7736194603537214; 0.5627808753445622; 2.0962147886425795; -0.2972131875614892; -2.2785014560321857; -0.026045724222645283; 0.7403013928912143; -0.1078053971031947; 2.2321671669701866; -1.6663925748672366];
query F1(l[0]);

throws the following error:

Exception in getProb for variable F1(l[0])
Fatal error: 
The value passed to the uniform vector distribution's getProb method must be a column vector.
java.lang.IllegalArgumentException: The value passed to the uniform vector distribution's getProb method must be a column vector.
    at blog.distrib.UniformVector.checkArgs(UniformVector.java:128)
    at blog.distrib.UniformVector.getLogProb(UniformVector.java:102)
    at blog.world.AbstractPartialWorld$DefaultInfoUpdater.updateVarInfo(AbstractPartialWorld.java:785)
    at blog.world.AbstractPartialWorld.updateParentsAndProbs(AbstractPartialWorld.java:893)
    at blog.world.AbstractPartialWorld.updateParentsAndProbs(AbstractPartialWorld.java:481)
    at blog.world.AbstractPartialWorld.getLogProbOfValue(AbstractPartialWorld.java:213)
    at blog.model.Evidence.getEvidenceLogProb(Evidence.java:328)
    at blog.model.Evidence.getEvidenceLogProb(Evidence.java:312)
    at blog.sample.LWSampler.supportEvidenceAndCalculateLogWeight(LWSampler.java:151)
    at blog.sample.LWSampler.nextSample(LWSampler.java:131)
    at blog.engine.SamplingEngine.answerQueries(SamplingEngine.java:165)
    at blog.Main.run(Main.java:215)
    at blog.Main.main(Main.java:173)
Exception in thread "main" java.lang.Error: Fatal error: 
    at blog.common.Util.fatalError(Util.java:516)
    at blog.common.Util.fatalError(Util.java:489)
    at blog.common.Util.fatalError(Util.java:473)
    at blog.world.AbstractPartialWorld$DefaultInfoUpdater.updateVarInfo(AbstractPartialWorld.java:795)
    at blog.world.AbstractPartialWorld.updateParentsAndProbs(AbstractPartialWorld.java:893)
    at blog.world.AbstractPartialWorld.updateParentsAndProbs(AbstractPartialWorld.java:481)
    at blog.world.AbstractPartialWorld.getLogProbOfValue(AbstractPartialWorld.java:213)
    at blog.model.Evidence.getEvidenceLogProb(Evidence.java:328)
    at blog.model.Evidence.getEvidenceLogProb(Evidence.java:312)
    at blog.sample.LWSampler.supportEvidenceAndCalculateLogWeight(LWSampler.java:151)
    at blog.sample.LWSampler.nextSample(LWSampler.java:131)
    at blog.engine.SamplingEngine.answerQueries(SamplingEngine.java:165)
    at blog.Main.run(Main.java:215)
    at blog.Main.main(Main.java:173)

arithmetic operations on timestep

@jxwuyi @lileicc @cberzan
instead of following

random Real a(Timestep t){
    if t==@0 then ~ Gaussian(0,1)
    else if t==@10 then ~ Gaussian(0,1)
    else if t==@20 then ~ Gaussian(0,1)
    else ~ Gaussian(100,1)
};
query a(@0);
query a(@13);
query a(@20);

we would like to have

random Real a(Timestep t){
    if mod(t,10) == 0 ~ Gaussian(0,1)
    else ~ Gaussian(100,1)
};

debug methods waste time and memory

Possible starter task for @chrisgioia64.

Profiler shows that the Util.debug() calls in AbstractPartialWorld.setValue() waste a lot of memory. Example:

        Util.debug("Setting var: " + var + " to " + value + ", replacing "
                + oldValue);

When BLOG is run in non-verbose mode, Util.debug() is a noop. But the string concatenation above is still performed, and it wastes time and allocates a lot of small String objects which are then never used. (In my profiler run, this was one of the top object-allocation hot spots.)

Possible solutions:

http://stackoverflow.com/a/2466662/744071
http://stackoverflow.com/a/6023505/744071
http://stackoverflow.com/a/6016955/744071

Binomial Distribution sampling

Efficient techniques for generating binomial variates exist:
http://delivery.acm.org/10.1145/50000/42381/p216-kachitvichyanukul.pdf?ip=128.32.46.192&id=42381&acc=ACTIVE%20SERVICE&key=CA367851C7E3CE77.3158474DDFAA3F10.4D4702B0C3E38B35.4D4702B0C3E38B35&CFID=328804659&CFTOKEN=39072998&__acm__=1398821672_e0569d312aa40e219748c14a4d8610d2

This paper should be studied, and in particular BTPE should be implemented, because it best fits the needs of BLOG concerning binomial variate generation.

observation is a ListSpec instead of RealMatrix

@lileicc

Problem found by @yberol : When we observe a list expression, it gets translated to a ListSpec instead of a RealMatrix. Not sure how to fix.

Minimal example:

random RealMatrix foo ~ UniformVector(1.0, 2.0, 3.0, 4.0);
query foo;

outputs

Distribution of values for foo
    1.0 [1.2245780056193871; 3.7836042999862167]

whereas

random RealMatrix foo ~ UniformVector(1.0, 2.0, 3.0, 4.0);
obs foo = [1.4; 3.4];
query foo;

outputs

Distribution of values for foo
    1.0 [[1.4], [3.4]]

(which means we cannot do transpose() et al)

BLOG query construction for summary statistics

It would be good to be able to query for summary statistics (e.g., log-likelihood of the observed data, MAP estimates of various parameters, etc.) from a BLOG program itself. Even better would be to combine the two. I appreciate any feedback on the following thoughts:

Some support already exists for summary statistics in BLOG models, e.g., https://github.com/lileicc/dblog/blob/master/src/blog/sample/LWSampler.java#L181, making use of it requires code changes. I think the user should be able to call a built-in function LogLikelihood and write something like

//parameters we wish to learn random Real[] theta ~ ...;

//let's say we have a 1000-dim array of dataPoints
obs ObsValue(dataPoint[0]) = ...;
...
obs ObsValue(dataPoint[999]) = ...;

//return log-likelihood of dataPoint[*]
query LogLikelihood();

One issue is: for what estimation of model parameters should we return LL? If we added ways to easily reference various estimates of parameters (e.g., MAP: query MAP(theta), the current sample: CURRENT(theta), or various other summarizations), we could make the LogLikelihood syntax slightly richer:

  • LogLikelihood([model parameters]): evaluate LL using the model parameters provided
  • LogLikelihood(): evaluate LL for all accepted model parameters

This brings up a number of issues to resolve:

  1. How to implement the estimation functions MAP, etc: My first thought would be to enrich the hierarchy in blog.model to include a BuiltInQuery type. This would need access to all variables.
  2. How should model parameters be represented? : Simplest might be a TabularInterp
  3. What should the convention be for built-in functions? As above, using a BLOG "namespace" (BLOG.LogLikelihood(...)), or something more Pythonic (__LogLikelihood__(...))?
  4. (More forward-thinking:) Do we allow people to override built-in functions?

features needed for PPAML

@lileicc CC @yberol

Use this issue to track features we need to add for PPAML. If you're working on something, add your name and relevant pull request here.

Things that we're currently working on:

  • matrix type and operations on matrices (@lileicc #54, @cberzan #57)
  • need an integer vector / matrix type (@lileicc, waiting for review XXX what PR is this?)
  • support + - * transpose, det, inv on Integer matrices (@cberzan), accomplished through toInt()
  • sum func (@cberzan)
  • trig funcs (@cberzan)
  • diag function (@cberzan)
  • construct column matrix from variable concatenation (hstack)

Next steps:

  • concatenating values into vectors or vectors into matrices (vertical stack)
  • concatenating values into vectors or vectors into matrices (horizontal stack)
  • indexing to access individual elements in Real vectors / matrix, index might be random (@lileicc waiting review)
  • indexing to access individual elements in other type of arrays, e.g. Array of declared type.
  • support expressions in fixed function
  • apply fixed function to every element in a vector (e.g. a_i = 2 * b_i)
  • apply random function (e.g. a distribution) to every element in a vector (e.g. a_i ~ UnivarGaussian(b_i, eye))
  • directory for user to define their own distributions and fixed funcs (see -k flag)
  • tensors (lower priority)
  • syntactic sugar for assigning a_i = f(b_i) without writing each assignment by hand

vstack issue

@lileicc @cberzan @WilliamCushing
for the following

random RealMatrix beta1 ~ UniformReal(0, 30);
random RealMatrix beta2 ~ UniformReal(0, 30);
random RealMatrix a = vstack(beta1,beta2);
query beta1;
query beta2;
//query a;

get

Distribution of values for beta1
    1.0 6.737340168581614
Distribution of values for beta2
    1.0 23.508128999586503

but for

random RealMatrix beta1 ~ UniformReal(0, 30);
random RealMatrix beta2 ~ UniformReal(0, 30);
random RealMatrix a = vstack(beta1,beta2);
query beta1;
query beta2;
query a;

get the following error

Exception in thread "main" java.lang.ClassCastException: java.lang.Double cannot be cast to blog.common.numerical.MatrixLib
    at blog.model.BuiltInFunctions$39.getValue(BuiltInFunctions.java:1050)
    at blog.model.NonRandomFunction.getValue(NonRandomFunction.java:182)
    at blog.model.NonRandomFunction.getValueInContext(NonRandomFunction.java:219)
    at blog.model.FuncAppTerm.evaluate(FuncAppTerm.java:185)
    at blog.model.Clause.getDistrib(Clause.java:169)
    at blog.model.DependencyModel.getDistrib(DependencyModel.java:165)
    at blog.model.DependencyModel.getDistribWithBinding(DependencyModel.java:150)
    at blog.bn.RandFuncAppVar.getDistrib(RandFuncAppVar.java:117)
    at blog.sample.ClassicInstantiatingEvalContext.instantiate(ClassicInstantiatingEvalContext.java:168)
    at blog.sample.ClassicInstantiatingEvalContext.getOrComputeValue(ClassicInstantiatingEvalContext.java:117)
    at blog.sample.ParentRecEvalContext.getValue(ParentRecEvalContext.java:75)
    at blog.bn.VarWithDistrib.ensureDetAndSupported(VarWithDistrib.java:129)
    at blog.BLOGUtil.ensureDetAndSupported(BLOGUtil.java:49)
    at blog.BLOGUtil.ensureDetAndSupportedWithListener(BLOGUtil.java:80)
    at blog.sample.LWSampler.nextSample(LWSampler.java:132)
    at blog.engine.SamplingEngine.answerQueries(SamplingEngine.java:165)
    at blog.Main.run(Main.java:215)
    at blog.Main.main(Main.java:173)

Matrix Dimensions

@cberzan @lileicc

Not sure if this is an issue or if it has been reposted.

fixed RealMatrix a = [1.0; 2.0, 3.0];
query a;

Strips out the 3.0. Returns [1.0; 2.0]

fixed RealMatrix b = [1.0, 2.0; 3.0];
query b;

Throws error complaining matrix rows have unequal length.

construct a new random vector/realmatrix from a list of variables

random Real beta1 ~ Gaussian(0,1);
random Real beta2 ~ Gaussian(0,1);
random Real beta3 ~ Gaussian(0,1);
random Real beta4 ~ Gaussian(0,1);

random RealMatrix beta = [beta1, beta2, beta3, beta4];

throws the following error:

./run.sh ~/Desktop/DARPAchallenge/BirdMigration/code/agg_input.blog -n 1
Using fixed random seed for repeatability.
/Users/yberol/Desktop/DARPAchallenge/BirdMigration/code/agg_input.blog::9.48: invalid body of dependency clause

Fatal error: File interpretation halted due to error(s) in "/Users/yberol/Desktop/DARPAchallenge/BirdMigration/code/agg_input.blog".

double indexing type propagation bug

@lileicc @cberzan @WilliamCushing

this one works, the problem is we cannot handle double indexing something that has been relationally indexed.

this is good:
random RealMatrix b1_new = newbirds(time[1]);
random Real b1_new_0 = b1_new[0][0];

but this one
random Real c = newbirds(time[1])[0][0];
gives the following error:

Exception in thread "main" java.lang.ClassCastException: java.lang.Double cannot be cast to blog.common.numerical.MatrixLib
at blog.model.BuiltInFunctions$22.getValue(BuiltInFunctions.java:712)
at blog.model.NonRandomFunction.getValue(NonRandomFunction.java:182)
at blog.model.NonRandomFunction.getValueInContext(NonRandomFunction.java:219)
at blog.model.FuncAppTerm.evaluate(FuncAppTerm.java:185)
at blog.model.Clause.getDistrib(Clause.java:169)
at blog.model.DependencyModel.getDistrib(DependencyModel.java:165)
at blog.model.DependencyModel.getDistribWithBinding(DependencyModel.java:150)
at blog.bn.RandFuncAppVar.getDistrib(RandFuncAppVar.java:117)
at blog.sample.ClassicInstantiatingEvalContext.instantiate(ClassicInstantiatingEvalContext.java:168)
at blog.sample.ClassicInstantiatingEvalContext.getOrComputeValue(ClassicInstantiatingEvalContext.java:117)
at blog.sample.ParentRecEvalContext.getValue(ParentRecEvalContext.java:75)
at blog.bn.VarWithDistrib.ensureDetAndSupported(VarWithDistrib.java:129)
at blog.BLOGUtil.ensureDetAndSupported(BLOGUtil.java:49)
at blog.BLOGUtil.ensureDetAndSupportedWithListener(BLOGUtil.java:80)
at blog.sample.LWSampler.nextSample(LWSampler.java:132)
at blog.engine.SamplingEngine.answerQueries(SamplingEngine.java:165)
at blog.Main.run(Main.java:215)
at blog.Main.main(Main.java:173)

type T;

distinct T time[3];

random RealMatrix b1_old ~ Multinomial(100.0, probs);
random RealMatrix b2_old ~ Multinomial(200, probs);
random RealMatrix b3_old ~ Multinomial(400, probs);
random RealMatrix b4_old ~ Multinomial(300, probs);

random RealMatrix TransferMat = vstack(vstack(vstack(transpose(b1_old),transpose(b2_old) ),transpose(b3_old) ),transpose(b4_old) );fixed Real[] probs = [10.0; 5.0; 3.0; 1.0];

random RealMatrix newbirds(T t) = sum(TransferMat);

random RealMatrix b1_new = newbirds(time[1]);
random Real b1_new_0 = b1_new[0][0];
random RealMatrix b2_new = newbirds(time[1]);
random RealMatrix b3_new = newbirds(time[1]);
random RealMatrix b4_new = newbirds(time[1]);

query b1_old;
query b2_old;
query b3_old;
query b4_old;
query TransferMat;
query newbirds(time[1]);
query b1_new;
query b1_new_0;
query b2_new;
query b3_new;
query b4_new;

DBLOG Refactoring and Parallelization

I've written up some thoughts about the interface we can provide in blog to allow Andreas and Yanif to proceed on the parallelization effort and about the library refactoring in general:

At a high level, parallelization should proceed by allowing separate threads to create samples independently. The key ingredient should be the addition of a sampling class, Sample.java. The Sampler class will use the nextSample method to create a sample. Each thread will have its own Sampler object. A thread will repeatedly call sampler.makeSample() to obtain Samples. The Samples will be added to a SamplerManager Class which provides a thread safe queue to which generated Samples are added. Once N samples are generated, the SamplerManager signals all the Sampler threads to stop sampling. It then uses the gathered samples to answer the desired query. This setup is general enough to allow for LWSamplers and MHSamplers. Particle Filters could fit in this framework easily as well. Each particle will correspond to a sample. Samples will have associated PartialWorlds to store information.

To add the overall refactoring effort, we need better representations of BLOG programs. We should add a BlogBayesNet class. This class will serve as a repository for a number of functions currently in BLOGUtil, such as ensureDetAndSupported.The class will maintain a DGraph that represents the bayes net structure of the Random variables. This bayes net is currently in the partial world. By moving it to BlogBayesNet we can ensure that all functions touching the random variables are gathered together. The Evidence and Query variables should be part of this class as well. (A BlogBayesNet class would fulfill the purpose of the CBN class we discussed earlier; the issue is that CBN would not be the right name for the class, since CBN's can be infinite and event dependent, while BlogBayesNet's only hold concrete information). Each PartialWorld should have an associated BlogBayesNet.

The above discussion is a little long, so I've summarized the key points:

  1. Add a Sample class. Sampler objects make Sample objects and add them to a central Queue managed by SamplerManager
  2. Each thread has a Sampler. Samplers are managed by a SamplerManager class.
  3. Add BlogBayesNet class that explicitly represents the graphical structure of the random variables in a blog world.
  4. Each PartialWorld uses a BlogBayesNet to organize its random variables.
  5. Each Sample has a PartialWorld.

Integrate SymbolTerm's with codebase for Variable Handling.

Currently, dblog's semantics fail on function declarations of the type:

random Real Position(Timestep t)
if t == @0
then ~ UniformReal(-10, 10)
else ~ Gaussian(Position(Prev(t)), 2);

The reason is that there seems to be no provision to differentiate between variables and 0-ary function calls. For example, t is parsed as a 0-ary function call. Shortly afterwards, the semantic correctness checks fail since there is no function named t.

There are some comments in the code indicating that SymbolTerm's should be used in the abstract syntax tree to represent both variables and 0-ary function calls. However, SymbolTerms don't appear integrated with the rest of the code yet. Code needs to be added to do this integration.

make DBLOGUtil.getTimestepIndex() efficient

Possible starter task for @chrisgioia64.

Profiler run shows that DBLOGUtil.getTimestepIndex() indirectly does a lot of memory allocation. It converts the BayesNetVar to a String, and then does a regex match on the String to extract the timestep the variable refers to. Very inefficient. There should be an easier way to get the timestep out of a BayesNetVar.

~/= vstack does not handle

@lileicc @cberzan @WilliamCushing

this one with = works

random RealMatrix b1_old ~ Multinomial(100.0, probs);
random RealMatrix b2_old ~ Multinomial(200, probs);
random RealMatrix b3_old ~ Multinomial(400, probs);
random RealMatrix b4_old ~ Multinomial(300, probs);

random RealMatrix TransferMat = vstack(vstack(vstack(transpose(b1_old),transpose(b2_old) ),transpose(b3_old) ),transpose(b4_old) );

this one with ~ does not

random RealMatrix b1_old ~ Multinomial(100.0, probs);
random RealMatrix b2_old ~ Multinomial(200, probs);
random RealMatrix b3_old ~ Multinomial(400, probs);
random RealMatrix b4_old ~ Multinomial(300, probs);

random RealMatrix TransferMat ~ vstack(vstack(vstack(transpose(b1_old),transpose(b2_old) ),transpose(b3_old) ),transpose(b4_old) );

effective sample size

@lileicc @cberzan
I think we should only resample when effective sample size < N/2. This is not hard to implement and it is probably very beneficial as we generally use few particles and this way we can preserve some diversity.

ESS = 1/sum_{i=1}^N(W_i^2)

Confusing Error Message when Using Fixed Instead of Random

Say I misdeclared the semantic interpretation of this random variable to be a fixed variable rather than a random variable.
fixed Real y ~ Gaussian(0, 2);

I get the misleading error:
Syntax error at character 239 of input
example/ex1.dblog::15.0: unmatched statement, or possible missing semicolon

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.