Author Topic: Setting means and variances for continuous nodes  (Read 18757 times)

Offline jat465

  • Newbie
  • *
  • Posts: 2
    • View Profile
Setting means and variances for continuous nodes
« on: February 10, 2009, 03:44:21 »
Can I have an example of the code for building a continuous probability node and setting its means and variances? My continuous chance nodes have discrete node parents.

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: Setting means and variances for continuous nodes
« Reply #1 on: February 11, 2009, 10:29:20 »
Here is a simple example that shows how to set the means and variances for continuous nodes:
Code: [Select]
Sub cgnetwork()

Dim dom As Domain
Dim x, y, z As Node

On Errors GoTo errorhandler
' create domain
Set dom = GetNewDomain
Set x = dom.GetNewNode(hCategoryChance, hKindDiscrete)
Set y = dom.GetNewNode(hCategoryChance, hKindContinuous)
Set z = dom.GetNewNode(hCategoryChance, hKindContinuous)

x.NumberOfStates = 2
y.AddParent (x)
z.AddParent (y)

' Y|X=false ~ Normal (0,1), Y|X=true ~ Normal (-0.5,2)
y.Alpha(0) = 0
y.Gamma(0) = 1
y.Alpha(1) = -0.5
y.Gamma(1) = 2

' Z | y ~ N(1 + 2*y, 4)
z.Alpha(0) = 1
z.Beta(y, 0) = 2
z.Gamma(0) = 4

' save network in file
dom.SaveAsNet ("C:\cgnet.net")
Exit Sub
errorhandler:
    MsgBox (Err.Description)
End Sub
« Last Edit: February 11, 2009, 10:45:38 by Anders L Madsen »
HUGIN EXPERT A/S

Offline jat465

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Setting means and variances for continuous nodes
« Reply #2 on: February 11, 2009, 14:07:28 »
Thank you! If y had two discrete node parents, would I do something analogous to the column ordering code for a discrete node with multiple discrete parents in the API Reference Manual (at HAPI.Table.Data)?

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: Setting means and variances for continuous nodes
« Reply #3 on: February 11, 2009, 15:32:33 »
yes, you will have to specify the parameter values for each parent configuration. The index of a parent configuration can be computed using the order of the parent in the Table as described in Chapter 4 of the HUGIN API Reference Manual (The HUGIN C API Manual).

Notice that the API has functions to compute the index from a configuration of nodes and the configuration from an index. These methods are located on the Table Class Module and are referred to as "IndexFromConfiguration" and "GetConfigurationFromIndex".
HUGIN EXPERT A/S