Author Topic: VBA for Hugin  (Read 22026 times)

Offline yaseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
VBA for Hugin
« on: June 18, 2009, 12:10:12 »
Hello

i want to calculate Mean and Variance of a node in BN hugin by using Visual Basic.


any help please

?????????

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: VBA for Hugin
« Reply #1 on: June 21, 2009, 18:35:18 »
For continuous chance nodes the mean and variance can - in VBA - be accessed using the Mean and Variance properties on the Node Class Module.

For a discrete  numeric node, the StateValue and Belief properties on the  Node Class Module can be used to compute the mean and variance of the node.

Hope this is useful.
HUGIN EXPERT A/S

Offline yaseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: VBA for Hugin
« Reply #2 on: June 22, 2009, 09:43:34 »
Dear Anders,
Thank you very much for the answer, could you please show me a simple example to calculate mean and variance in VBA (some code in VBA).

I appreciate your help


Offline yaseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: VBA for Hugin
« Reply #3 on: June 22, 2009, 10:41:54 »
ok, i see the syntax of a Node class as:
Property Mean As Double

but this does not make sense for me.....
because as  i know the syntax should be like "Mean(....)"
now i am confusing, please help me.
 
Thanks in advance.


Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: VBA for Hugin
« Reply #4 on: June 23, 2009, 12:26:20 »
Here is a simple example illustrating the use of discrete and continuous nodes:

Code: [Select]
Sub sex_height()
Dim dom As Domain
Dim sex As Node
Dim height As Node

Set dom = LoadDomainFromNet("C:\ProgramData\Hugin\specs\sex_height.net", Nothing, 0)
dom.Compile

Set sex = dom.GetNodeByName("sex")
Set height = dom.GetNodeByName("height")


' uncomment this command and the next to enter and propagate evidence that the person is female
'sex.selectstate (sex.StateIndexFromLabel("female"))

' propagate evidence
'Call dom.Propagate(hEquilibriumSum, hModeNormal)

' show mean variance
Sheet1.Cells.Item(1, 2) = height.mean
Sheet1.Cells.Item(2, 2) = height.variance

' end
End Sub

The network is attached. You should make the necessary adjustments to the macro to have it run (e.g., setting the path of the file and adjusting the name of the sheet displaying the information).

Hope this helps.
« Last Edit: June 23, 2009, 15:53:36 by Anders L Madsen »
HUGIN EXPERT A/S

Offline yaseen

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: VBA for Hugin
« Reply #5 on: June 23, 2009, 16:21:46 »
Dear Anders,

Thank you very much for the example, and now it make sense for me.

Is there any guide tutorial for VBA with Hugin???? because i need to understand more about the functionality of each code in VBA related to Hugin.


I appreciate your help,


regards,

yaseen

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: VBA for Hugin
« Reply #6 on: June 30, 2009, 22:29:04 »
You may want to consult the HUGIN API Reference Manual for further information. It is also referred to as the HUGIN C API manual. It contains more detailed information on the functionality of the APIs.

There is no other documentation associated with the VBA API except for what can be found in the HTML manual.
HUGIN EXPERT A/S