VIBESVariational Inference for Bayesian Networks |
[Sourceforge project page] John Winn, January 2004 |
Overview | Tutorial | Examples | Help |
Online Help: Using VIBES from MatlabThis is BETA documentation Installing VIBES into MatlabDownload the VIBES Jar file (see the Overview page) and place it in ## VIBES classes [matlab directory]/vibes/Vibes2_0.jar To test the installation, run Matlab and type >> import cam.jmw39.app.vibes.matlab.*; This imports VIBES functionaility into Matlab and needs to be done once per session. Now type, >> Vibes.run This should cause VIBES to run normally from within Matlab. Of course, you will want to use VIBES programmatically instead, so read on! VIBES Matlab APIIn the beta, VIBES exposes an API which allows pre-defined networks to be loaded and inference to be performed. The following example outlines the API. If you want to work through it yourself, you need to download the Gaussian network file. Loading and displaying a networkTo load a VIBES network into Matlab, use: >> net = Vibes.read('Gaussian.xml') which will give a result like net = ModelNetwork Demo1 - Gaussian [3 nodes] ModelNode x [0 children] in (400x64) ModelNode beta [1 child] in (64) ModelNode mu [1 child] in (64) For debugging purposes, you can display the loaded network with >> Vibes.show(net) Setting observed values and performing inferenceYou can dynamically changes the size of plates in your network, according to the dimensionality of your data, for example >> N = 50; d= 3; >> net.getPlate('N').setSize(N) >> net.getPlate('d').setSize(d) Now you can attach observed data >> xdata = [randn(N,1) randn(N,1)+1 randn(N,1)+2]; >> net.getNode('x').setData(xdata) To perform inference, you use an inference algorithm object which may be obtained by initialising the network >> algorithm = Vibes.init(net); A number of iterations of variational inference (in this case 50) can be performed using >> algorithm.update(50); The indicated number is a maximum. If inference converges, the algorithm will stop earlier. If desired, the default update order can be overridden by calling >> Vibes.setUpdateOrder(algorithm,'mu,beta'); prior to calling Extracting or initialising the variational distribution momentsFollowing initialisation or inference, you can extract the moments of the variational
distribution for a given node using >> mu=Vibes.get(net,'mu'); mu = 0.1083 0.0270 1.0060 1.0273 1.9381 3.7764 The returned matrix has size d×2. As the mu node is contained in the d plate, there are d copies of it and the rows of this matrix contain the moments of the variational distribution for each copy. As mu is Gaussian, the first column gives <mu> and the second gives <mu×mu>. The supplied moments will be different for other distributions. Hence, to get the variance for each copy of mu, type >> mu(:,2) - mu(:,1).^2 Prior to performing inference (but after initialisation), you can directly modify the initial variational distribution of a node by setting its moments using >> Vibes.set(net,'mu', initial_mu); The matrix of moments supplied must have the same form as that returned by |