Skip to content

Example of inference in documentation is incorrect #158

@nguiard

Description

@nguiard

Hi,
I was trying inference, following the example in the doc:

    bn = DiscreteBayesNet()
    push!(bn, DiscreteCPD(:a, [0.3,0.7]))
    push!(bn, DiscreteCPD(:b, [0.2,0.8]))
    push!(bn, DiscreteCPD(:c, [:a, :b], [2,2],
            [Categorical([0.1,0.9]),
            Categorical([0.2,0.8]),
            Categorical([1.0,0.0]),
            Categorical([0.4,0.6]),
            ]))
    ϕ = infer(bn, :c, evidence=Assignment(:b=>1))

While this compiles fine, the output produced is:

2 instantiations:
  c (2)

While the doc says that the output is supposed to be:

2×2 DataFrame
Row	c	potential
Int64	Float64
1	1	0.17
2	2	0.83

This can be easily fixed by doing:

ϕ = DataFrame(infer(bn, :c, evidence=Assignment(:b=>1)))

instead of what is written in the docs. At first sight for someone new, it is not at all clear that this is what you have to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions