Author Topic: Setting continuous finding C++  (Read 18393 times)

Offline eb20

  • Newbie
  • *
  • Posts: 9
    • View Profile
Setting continuous finding C++
« on: August 22, 2011, 04:08:57 »
Hi,

I've modified the example LoadAndPropagate.cpp to instantiate the node e2 of the net I've attached with C++ API.
When setting the continuous finding with Hugin GUI, for example the value 5.2, I get H: Yes - 32.38 and No - 67.62, but with my C++ code it doesn't work.

What is wrong in the code I've modified?

I would appreciate any help

Offline Anders L Madsen

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 2295
    • View Profile
Re: Setting continuous finding C++
« Reply #1 on: August 22, 2011, 09:37:01 »
Hi,

Could you please be more specific on the type of error you get? Please notice that the file name passed to LoadAndPropagate should not include suffix ".net".

This the output produced by your modified LoadAndPropagate example (with a line to print p included):

Quote
C:\Users\anders\Desktop>test_vc10_alm.bat
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

LoadAndPropagate.cpp
LoadAndPropagate.cpp(142) : warning C4101: 'e' : unreferenced local variable
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:LoadAndPropagate.exe
"/LIBPATH:c:\Program files (x86)\Hugin Expert\Hugin Researcher 7.4\Test\..\HDE7.
4CPP\Lib\VC10\Release"
hugincpp-7.4-VC10.lib
LoadAndPropagate.obj
0.323848
0.676152
Prior beliefs:

[C]  (e2)
  - Mean : 6.03177
  - SD   : 3.47226

[C]  (H)
  - Yes 0.5
  - No 0.5

[C]  (e1)
  - Mean : 5.9754
  - SD   : 3.46986


Propagating the evidence specified in "Example_e2.hcs"

P(evidence) = 0.101097

Updated beliefs:

[C]  (e2)
  - Mean : 5.2
  - SD   : 0

[C]  (H)
  - Yes 0.323848
  - No 0.676152

[C]  (e1)
  - Mean : 5.31641
  - SD   : 1.37199

C:\Users\anders\Desktop>

This is the code:

Code: [Select]
/************************************************/

  ContinuousChanceNode  *E2 = dynamic_cast<ContinuousChanceNode*> (domain.getNodeByName("e2"));
  DiscreteChanceNode  *H = dynamic_cast<DiscreteChanceNode*> (domain.getNodeByName("H"));
     size_t nStates = H->getNumberOfStates ();

  double finding = 5.2;

  E2->enterValue(finding);
  domain.propagate(H_EQUILIBRIUM_SUM, H_MODE_NORMAL);

  for (size_t i = 0; i < nStates; i++)
  {
  Number prob = H->getBelief (i);
  double p = prob ;
cerr << p << endl;
  }


  E2->retractValue ();
  domain.initialize();

  /**************************************************/
HUGIN EXPERT A/S

Offline eb20

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Setting continuous finding C++
« Reply #2 on: August 22, 2011, 13:48:30 »
When I run the program I don't get any error but the a posteriori probabilities are wrong.
I think this is because the a priori probabilities of the node H can't be read,
it must be 0.5 and 0.5, and that's why the posteriori are wrong.
I'm using Microsoft Visual Studio 6.0 and Hugin Lite 7.4

I don't know why this happens. Any idea?

This is the output

Quote
0.00022197575828963
-1.4568160835477e+144

Prior beliefs:

[C]  (e2)
  - Mean : 6.03177
  - SD   : 3.47226

[C]  (H)
  - Yes 3.0516e-005
  - No -1.45682e+144


[C]  (e1)
  - Mean : 5.9754
  - SD   : 3.46986

Thank you in advance

Offline Martin

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 613
    • View Profile
Re: Setting continuous finding C++
« Reply #3 on: August 22, 2011, 15:23:34 »
After the evidence on e2 has been entered, the following two lines appear in your example code:
Code: [Select]
E2->retractValue ();
domain.initialize();

Remove these lines as they "undo" the evidence you just inserted - now the example should work as expected.

Hugin Expert A/S

Offline Martin

  • HUGIN Expert
  • Hero Member
  • *****
  • Posts: 613
    • View Profile
Re: Setting continuous finding C++
« Reply #4 on: August 22, 2011, 16:06:17 »
Looking closer at the output you posted, there is something very odd about these *impossible* numbers:

Code: [Select]
0.00022197575828963
-1.4568160835477e+144

Code: [Select]
[C]  (H)
  - Yes 3.0516e-005
  - No -1.45682e+144

Can you perhaps post the example code, compiler options and the names of HUGIN library files used to produce this output?
Hugin Expert A/S

Offline eb20

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Setting continuous finding C++
« Reply #5 on: August 22, 2011, 17:38:26 »
Hi,

I have update Hugin Lite to version 7.5 and now it works.

Thanks for your help.