Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - DS

Pages: [1]
General Discussion / Chain graphs
« on: October 06, 2015, 02:32:45  »
I am working with chain graphs and have heard that there exists some implementation for handling these in Hugin. From your homepage I can see that it is shown as a  feature ( and there are also references to it when the .net format is explained in for example the API manual (example 13.5 to 13.7). The manual does however not explain how to set the data table for the potentials and when I play around with it myself I can't get it right. ???

So my questions are:
1. What functionality of chain graphs are supported by the Hugin GUI and the Hugin API?
2. If the API does not support direct adding and removing undirected edges (and setting corresponding potentials), how would one do this directly by manipulating the .net file. I.e. what would you write instead of dots in
Code: [Select]
potential (C3 C4 | C1 C2)
    data = ...
when handling a chain graph with the structure C1 -> C3 -- C4 <- C1 to get the right independence model and how can this model be used for inference using the Hugin inference engine?
3. Does it also exist support (in the inference engine etc.) for using continuous nodes when using chain graphs. I.e. for multivariate normal distributions over the nodes in the chain component?

Thanks beforehand for any answer! Great program!  :)

Java / Generate multiple simulations in the API
« on: September 15, 2015, 14:43:21  »
I have been trying to write a program that generates multiple simulations given some evidence. I.e. I want to sample a Bayesian network a number of times given some observations. I know this is possible to do using the GUI (with the "generate cases" button) and generally I think that the API is quite straightforward to use, but this time I have got stuck. It might be the case that I will have to write the entire sampling method myself, in which case I can probably do it, but it feels like it should be possible to do with the "saveCases(...)" method for the domain object straight away. I can however not get it to work and only get "NA" values in my output (like if the values are missing) so I guess I somehow need to set up the "cases" before-hand, but can't figure out how. Does anyone have an idea of what I do wrong or what I am missing?
I have attached my code below and I think it is quite straightforward to understand with the comments.
Code: [Select]
import java.awt.geom.Point2D;

import COM.hugin.HAPI.ContinuousChanceNode;
import COM.hugin.HAPI.Domain;
import COM.hugin.HAPI.ExceptionHugin;

public class exampleCase {

public static void main(String[] args) {
try {
Domain d;
d = new Domain ();
d.setNodeSize (new Point2D.Double (50, 30));

//set up the basic stucture with a collider over node3
ContinuousChanceNode node1 = new ContinuousChanceNode(d);
node1.setLabel ("node1");
node1.setName ("node1");
node1.setPosition(new Point2D.Double (50, 50));
ContinuousChanceNode node2 = new ContinuousChanceNode(d);
node2.setLabel ("node2");
node2.setName ("node2");
node2.setPosition(new Point2D.Double (150, 50));
ContinuousChanceNode node3 = new ContinuousChanceNode(d);
node3.setLabel ("node3");
node3.setName ("node3");
node3.setPosition(new Point2D.Double (100, 100));
d.compile ();

//set the parameters
node1.setAlpha(0.1, 0); //alpha = intercept
                node1.setGamma(10, 0); //variance
                node2.setAlpha(0.2, 0); //alpha = intercept
                node2.setGamma(10, 0); //variance
                node3.setBeta(0.3, node1, 0); //beta = weights
                node3.setBeta(0.4, node2, 0);
                node3.setGamma(0.5,0); //variance
d.saveAsNet ("");

//So what I want to do is to sample this BN 10 times with the evidence set below.
//Here I can also check that the network is updated correctly (which it is)
System.out.println("Name: "+node1.getName()+" val: "+node1.getMean());
System.out.println("Name: "+node2.getName()+" val: "+node2.getMean());
System.out.println("Name: "+node3.getName()+" val: "+node3.getMean());

//However, for the simulation (sampling)-part I am unsure how to do it .
//If I want to save the evidence of a single case I know I can simply write:
d.saveCase("Single_sample.dat"); //saves the set evidence
//but what if I want to save multiple (10) simulations given the evidence?
//Intuitively I would think that this code would do the trick:
d.saveCases("Multiple_samples.dat", d.getNodes(), null, false, ",", "NA");
//but unfortunately only NA-values are given in the output file
//like if all values are missing. So what do I need more?
//And what do the following methods do? Are they related to the simulation part?
d.newCase(); //is this if I want different evidence in the different cases?
d.enterCase(0); //does this select case 0 for altering the evidence in that case?
d.setCaseCount(0,3); //repeats the case 0 3 times or?
d.adapt(); //Is this related to the simulations?

} catch (ExceptionHugin e) {

Pages: [1]