BayesianLogic / blog

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

syntax problem? #336

Open davidenitti opened 9 years ago

davidenitti commented 9 years ago

Dear, I am trying to implement a probabilistic version of the Wumpus world, but I have this error:

Exception in thread "main" java.lang.ClassCastException: java.util.ArrayList cannot be cast to blog.common.numerical.MatrixLib at blog.model.BuiltInFunctions$25.getValue(BuiltInFunctions.java:1053) at blog.model.FixedFunction.getValueInInterpretation(FixedFunction.java:193) at blog.model.FixedFunction.getValueInContext(FixedFunction.java:231) at blog.model.FuncAppTerm.evaluate(FuncAppTerm.java:156) at blog.model.FuncAppTerm.evaluate(FuncAppTerm.java:144) at blog.model.FuncAppTerm.evaluate(FuncAppTerm.java:144) at blog.model.EqualityFormula.evaluate(EqualityFormula.java:75) at blog.model.CaseSpec.evaluate(CaseSpec.java:55) at blog.model.CaseSpec.evaluate(CaseSpec.java:63) at blog.model.CaseSpec.evaluate(CaseSpec.java:63) at blog.model.DependencyModel.getDistrib(DependencyModel.java:151) at blog.model.DependencyModel.getDistribWithBinding(DependencyModel.java:140) at blog.bn.RandFuncAppVar.getDistrib(RandFuncAppVar.java:117) at blog.sample.ClassicInstantiatingEvalContext.instantiate(ClassicInstantiatingEvalContext.java:154) at blog.sample.ClassicInstantiatingEvalContext.getOrComputeValue(ClassicInstantiatingEvalContext.java:116) at blog.sample.ParentRecEvalContext.getValue(ParentRecEvalContext.java:75) at blog.bn.VarWithDistrib.ensureDetAndSupported(VarWithDistrib.java:129) at blog.BLOGUtil.ensureDetAndSupported(BLOGUtil.java:34) at blog.BLOGUtil.ensureDetAndSupported(BLOGUtil.java:44) at blog.engine.Particle.answer(Particle.java:84) at blog.engine.ParticleFilter.takeEvidenceAndAnswerQuery(ParticleFilter.java:174) at blog.engine.ParticleFilter.answerQueries(ParticleFilter.java:127) at blog.Main.run(Main.java:220) at blog.Main.main(Main.java:158)

the code is this:

type State;
distinct State Up, Down, Left, Right;

type Cell;
distinct Cell free, wall;

fixed State action(Timestep t) =
 if t==@0 then
 Up
 else if t==@1
 then Up;

random Cell Maze(Integer x,Integer y,Timestep t) ~
  if t == @0 then
    Categorical({free -> 0.6, wall -> 0.4}) 
  else Maze(x,y,prev(t))
;

random RealMatrix Agent(Timestep t) ~
  if t == @0 then
    Categorical({[0;0]-> 1})
    else
    if action(t) == Up then
        if Maze(toInt(Agent(prev(t))[0][0]),toInt(Agent(prev(t))[0][1]+1),prev(t))==free then
            Categorical({ [Agent(prev(t))[0][0];Agent(prev(t))[0][1]+1] -> 0.9, Agent(prev(t)) -> 0.1} )
        else
            Agent(prev(t))
    else 
            Agent(prev(t))
;

query Agent(@1);

I think the error is related to the line:

if Maze(toInt(Agent(prev(t))[0][0]),toInt(Agent(prev(t))[0][1]+1),prev(t))==free then

that is I need to check if the maze cell above the agent position is free. is there any error in this? thanks!

cberzan commented 9 years ago

Currently we have some issues with constructing literal matrices like [Agent(prev(t))[0][0]; Agent(prev(t))[0][1]+1], especially when the arguments are integers instead of reals.

I would recommend defining AgentRow and AgentColumn as separate scalar functions, instead of having the function Agent that returns a matrix.