Author Topic: Expressions  (Read 4075 times)

Offline Therese

  • Newbie
  • *
  • Posts: 2
    • View Profile
Expressions
« on: December 16, 2014, 19:10:30 »
Hi,

I have some rather large probability tables, where the probabilities are slightly complicated to compute in that they involve evaluating the pdf and cdf of a standard (continuous) family of distributions, e.g. the normal, lognormal, and gamma distributions.

Would it be possible for me to specify this by expressions rather than manually specifying the tables?
I suspect that perhaps not judging from the the set of building blocks for expressions that are given in C API and the GUI help pages, but I may have overlooked something.

All the best,
Therese

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 575
    • View Profile
Re: Expressions
« Reply #1 on: December 16, 2014, 23:01:06 »
Hi Therese,

You can use Normal, LogNormal, and Gamma in expressions, see section 6.7.1 in the Hugin API Reference Manual.

But I suspect that it is not as simple as that.  Can you elaborate on the "slightly complicated to compute" part of your post?

Regards,
Frank

Offline Therese

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Expressions
« Reply #2 on: December 17, 2014, 13:02:27 »
Here is an example:

I have a discrete binary node X, and an observation y which has a continuous distribution with density f(y | z) given a discrete network variable Z. I want to define the distribution of X | Z using the distribution of y. We may think of y as a fixed quantity that is used when building the network.

If I simply want

P(X = 1 | Z = z) = P(Y < y | Z = z),

I think that this could perhaps be done by instead making X an interval node with states [-inf, y] and [y, inf].

Now, sometimes I want to let

P(X = 1 | Z = z) = f(y | z)/k

and then P(X = 0 | Z = z) = 1 - P(X = 1 | Z = z).

This is more difficult for two reasons.

The first reason is the essence of my question: I need to be able to evaluate the density f in this arbitrary point y.

The other reason is that I need to identify a constant k so that f(y | z)/k becomes a well defined probability. When I create tables by hand, I may do this simply by taking k to be max_z{f(y | z)}. I suspect that this will not be possible, because the expression is naturally defined for only one state z of Z.

I hope that my question makes sense. Hugin already computes everything I need like a charm. I'm simply exploring other ways of doing the same thing ;)

Therese

Offline Frank Jensen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 575
    • View Profile
Re: Expressions
« Reply #3 on: December 18, 2014, 15:25:30 »
I don't think there is an elegant way to do this.

However, if we assume that "f(y|z)" can be expressed using Hugin expression syntax, and we know that Z assumes one of a finite number of states, say z1, z2, and z3, then you can write max_z{f(y|z)} as follows:

max (f(y|z1), f(y|z2), f(y|z3))

Clearly not pretty, but it should work.

Frank