noisy max node in jSMILE

The engine.
Post Reply
gertner
Posts: 1
Joined: Tue Oct 19, 2010 10:45 pm

noisy max node in jSMILE

Post by gertner »

Hello,

I am attempting to use jSMILE To create a network with a noisy max node. I am getting a "bad allocation" error when I call setNodeDefinition() on my noisy max node. After some testing I found that even if I set the node definition to the same array I get from calling getNodeDefinition() immediately after adding all of the nodes and arcs to the network I still get the "bad allocation" error.

For example, the following should give you this error:

Code: Select all


import smile.Network;
import smile.Network.NodeType;

public class SmileTest {
  public static void main(String[] args) { 
    Network net = new Network();
    int n = 6;
    
    net.addNode(NodeType.NoisyMax,"noisy_max");
    net.setOutcomeId("noisy_max", 0, "outcome"+n);
    net.setOutcomeId("noisy_max", 1, "outcome"+(n-1));
    for (int i = 2; i < n; i++) { 
      net.addOutcome("noisy_max", "outcome"+(n-i));
    }
    
    int nparents = 8;
    int nvalues = 10;
    for (int i = 0; i < nparents; i++) { 
      net.addNode(NodeType.Cpt,"parent"+i);
      net.addArc("parent"+i,"noisy_max");
      
      net.setOutcomeId("parent"+i, 0, "value"+nvalues);
      net.setOutcomeId("parent"+i, 1, "value"+(nvalues-1));
      for (int v = 2; v < nvalues; v++) {  
        net.addOutcome("parent"+i, "bin"+(nvalues-v));
      }
    }
    
    double[] defn = net.getNodeDefinition("noisy_max");
    net.setNodeDefinition("noisy_max", defn);
    
  }
}
Can you explain what I am doing wrong, or why this is happening?

Thank you
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: noisy max node in jSMILE

Post by shooltz[BayesFusion] »

After some testing I found that even if I set the node definition to the same array I get from calling getNodeDefinition() immediately after adding all of the nodes and arcs to the network I still get the "bad allocation" error.
Network.setNodeDefinition will expand noisy weights into full CPT (this is an implementation detail specific to jSMILE and Smile.NET). In your case, the CPT would require 6*(10^8)*sizeof(double)=4,800,000,000 contiguous bytes in RAM. This allocation request cannot be completed and C++ runtime library throws bad_alloc from new operator. This is later catched by native part of jSMILE and rethrown as SMILEException.
orzech
Posts: 51
Joined: Wed Aug 04, 2010 11:40 pm

Re: noisy max node in jSMILE

Post by orzech »

I see that this issue comes out quite often. Expanding noisy weights into full CPT when calling setNodeDefinition() is a bug in the jSMILE and Smile.NET wrappers. Why should weights be expanded when setting definition? What if someone wants to simply create and save an untrackable network and then pass it on to an independent optimization algorithm? Weights should be expanded only during network's update.

I've solved this issue by downloading the wrapper's source code and making my adjustments.
Post Reply