Make-Believe (R20): Submodel Cleanup

Tnodecontexthe focus in this version was cleaning up some of the rougher edges (and outright breakages) from the introduction of submodels. So, it’s now possible to move nodes between submodels from the node context menu. It’s possible to remove all the submodel information from a network using the Network -> Flatten Network command. And it’s possible to view arc strengths with BNs containing submodels (using a perhaps questionable approach to summarising the influence flowing into and out of a submodel).

DNE support has also been fixed, along with a bug from the past that prevented evidence being entered into certain types of DNE file. (There is almost certainly a very large number of other issues with DNE support still — it’s not a main focus.)

Changes:

  • Can (properly) flatten a network with submodels (but this is a non-reversible change, rather than a different view)
  • Can move nodes from one submodel to another, by changing it’s ‘path’
  • Made ‘type’ visible on context menu (need to make changeable … somehow)
  • Added ‘label’ to the context menu
  • Made context menus available on submodels
  • Possible to change ID and label on submodel nodes
  • Code: .submodelPath vs .path (the latter includes id of the submodel itself). Eliminated .path
  • Can view submodel path, and move submodels to different submodels from context menu
  • Show arc strengths fixed, and can be used with BNs containing submodels (I’m not clear that the approach I’ve chosen is sensible, though, which is sum(mi)/sum(child-entropies) for all applicable paths)
  • FIXED: Significant contextmenu dialog duplication. PART FIXED: Now fix node context menu
  • FIXED: Continuous nodes/networks seem to have broken.
  • FIXED: .dne support broken

Make-Believe (R19): ((Sub)Sub)Submodels

Submodels in Bunce's FarmSubmodels are now supported. Submodel nodes are rendered with thick borders to distinguish them from variable nodes. You need to double-click them (as per GeNIe) to open them up, and when you’re in a submodel, the parent model can be accessed by double-clicking the ‘..’ node (obviously inspired by command line navigation) in the top left corner. This is clearly not the final interface, but perfectly workable for the time-being. Also for the time-being, submodel nodes are very much view only — it’s not possible to do anything with them other than to move them about. And saving networks with submodels will simply ignore the submodel information, which I guess counts as one (temporary) way to flatten a network.

Submodels are the last major XDSL feature I was aiming to have some support for in Make-Believe. (Note that .dne support has been broken since R18, but will be revived soon.) I’ll be taking the opportunity over the next few months to focus on polish: trying to improve robustness, code legibility and ensuring that everything is properly CRUD-capable.

Changes:

  • Initial group support
    • Show only nodes from currently focused group
    • Show node for submodel, with arcs
    • Allow submodel navigation
    • Allow moving with submodel
    • |display()| function clean up
      • Fixed up pathsIn/pathsOut to store information as objects rather than arrays
    • Delete of variable nodes now working again
  • Context menus supported (minimally) on utility and decision nodes

Make-Believe (R18): Now in Colour

asia-colorsNode colours and formats are now fully supported (create/read/update/delete), however the behaviour deviates from GeNIe a little to allow for “default” (or unspecified) colours. This relies on assuming default colours are the intent if the formatting of a node has been left at GeNIe’s defaults. I’m not happy with this approach, but I can’t think of a better way to allow unspecified colours.

Other notable changes in this version include an expansion of some of the functions supported for compatibility with GeNIe’s functions, and the implementation of a simple probability of evidence function (Network -> Calculate Probability of Evidence). Worker-based inference is also back in this version. This involved cleaning up the compile step, which is a bit more robust (all of which is in the background only).

Changes:

  • Fixed worker-based inference, when changes have been made to network
  • Support for .dne comments
  • Fixed menu markers
  • Added support for node colours and formats
    • Read in from .xdsl files
    • Fix editing of formatting controls
    • Save format changes to .xdsl file
    • Added a simple regression test (requires visual verification)
  • Probability of Evidence (simple, slow version)
  • Added support for the same function-form logical operators as GeNIe (And, Or, etc.). No “Not”, because there’s none in GeNIe.
  • Support for further functions (arithmetic)

Make-Believe (R17): Resumption

After a small (unexpected) break, I’m getting back to fortnightly updates of Make-Believe. While it’s been a while since the last post, I have been making changes to the code, so there’s a few extra things in this update. Firstly, there are some bug fixes to really silly regressions that had snuck in. As a consequence, there are also a first set of regression tests now to help make future versions a touch more reliable.

It’s possible to switch between belief bar and labelled box view. This is experimental, but should work fine. The main issue is I need to rework arrow drawing to handle different node shapes. (But it works pretty well nonetheless.)

It’s now possible to view and change node equations and comments. Changes are saved to .xdsl files.

Farcinfluenceinally, a very experimental and rough visualisation under View -> Show Arc Strengths. This shows the proportion of a child’s entropy that each parent would reduce if evidence in that parent were set. This is also conditional on the current evidence in the network, which is kind of neat, because you can see (for example) the effect of evidence on d-separation/d-connection. As mentioned, it’s still experimental, so things can get a little comical with oversized arrowheads and the like. (SVG markers are not as flexible as I’d like.)

One current issue is that I’ve had to disable worker-based inference, until I’ve cleaned up a few things.

Changes:

  • Fixed entering evidence in first state (should have been ‘if undefined’ not ‘if 0’)
  • TESTING: Created testing file (makeBelieveTests.js), and added an initial test
  • TESTING: Added click-to-update test. Accuracy may be an issue for reproducibility
  • TESTING: Added running tests to debug menu
  • For very small iterations, worker threads > iterations. Fixed to handle this properly
  • Auto-layout is now animated. (Using a slow method –can be much faster.)
  • Auto-layout animation with faster method. :)
  • Added a label-only view
  • Fixed: [bug] auto-layout, switching between distro/label view sometimes causes arrows to disappear
  • Prompt for node delete (in future, undo/redo makes this redundant/undesirable)
  • Allowed viewing of equation node definitions
  • Allowed setting the equation node definitions (with no validation)
  • Added comment reading/viewing from .xdsl file
  • Allow changing text in comments
  • Save comment to .xdsl file
  • Fixed decision network evaluation bustage (broken since had switched to worker threads as default)
  • TESTING: Added a simple regression test for decision networks
  • Very preliminary add node capability (backend only)
  • Arc weights based on % mutual info for children

 

Make-Believe (R16): Changes

cpt

Node context menu

Most of the changes in this version have to do with the ability to make changes to the network. So it’s now possible to rename nodes and delete nodes. This functionality can be found when right-clicking a node. Another change is that right-clicking brings up a menu relating to the node. I’m taking a slightly experimental approach with this. We’ll see how it works out. It’s certainly not settled.

One more thing added in this version is the ability to learn (CPT) parameters from data via counting. This works pretty straightforwardly, although only with tab delimited text files (.txt) at the moment. If it encounters a row with missing data, it can still learn a node’s CPT parameters, so long as there is complete data for the node and its parents in that row.

All of the above changes can be saved to file, though it’s all experimental as well, so I certainly wouldn’t rely on it!

Changes:

  • Initial right-click menu
  • Allow renaming nodes
  • Allow deleting nodes
  • Allow learning parameters from data via counting
  • Background changes to file organisation and small amount of cleanup

Make-Believe (R15): CPT Editing

A very small update this time, although in a way it’s one of the more substantial changes to the direction of the software.

In the past, when you double clicked an ordinary discrete node, a dialog would pop up with the probabilities in the CPT. This still happens, but the numbers are now actually labelled and you can edit them. There’s no validation there at the moment, so if you enter nonsense, it will still try to run the network with whatever you’ve entered. What you edit will also get saved to file — and again, if you enter nonsense, who knows what can happen! (Actually, it will probably just result in a file you can’t open.)

One thing I’ve implemented here is that as soon as you click ‘Save’, the network will try to run the inference again. This will no doubt be annoying for large networks, but for small networks it tightens the ‘try it and see’ loop. I’ll put in a setting at some later stage to control this.

Changes:

  • Added headers, parent state combination names to CPT view (double-click to view)
  • Allow editing of CPT

Make-Believe (R14): Initial Netica .dne support

For a little while, I’ve been wanting to add support for Netica .dne files, and I’ve managed to finally land something. The support is very crude (even cruder than for GeNIe .xdsl files) and probably very flaky. There’s only support for basic networks with discrete chance nodes — no support at all for deterministic nodes, equations, decision nodes, utility nodes or dynamic nodes (as there is for GeNIe files).

I included another one of my side-projects in order to get this support, namely a parser. I ought to write a separate post about the parser at some point, but in short, it’s meant to be a very quick way to use a grammar (with embedded regular expression support) to transform an input source into not just a syntax tree, but something that more closely represents the final desired object model. It’s not quite there yet, but it’s certainly good enough to do the parsing work needed here.

Anyway, here’s the 14th release of Make-Believe:

Changes:

  • Initial Netica .dne support for basic networks (discrete chance nodes only!)
  • Update beliefs immediately on BN loaded from query string

Make-Believe (R13): Working Workers

I finally have workers performing inference as quickly as on the main thread. This means workers now actually speed up the inference, with some substantial speed improvements as you move up to 4-8 cores. In fact, updating speed is no longer simply comparable to GeNIe, but can run quite a bit faster — OK, you should take that with a large grain of salt, because it’s BN-dependent, I’m not testing if the output variance is the same, and I’m just testing with the same number of sample iterations.

One nice side-effect of this is that I can finally unify the main-thread and worker-thread implementations. This may encourage me to clean the code organisation up a little bit. I hope.

2 workers are enabled by default for now. To change this number, go to the ‘Debug’ menu. It’s best to set the number equal to or slightly lower than the number of CPUs/cores that you have.

Changes:

  • Made worker-based belief update run as quickly as main thread update
    • (The solution was to recreate BNs on the worker side, rather than pass in via structured clone. I’m unaware as to why this is needed, since the structures (TypedArrays, etc.) were identical as far as I could tell. This was the case on both Firefox and Chrome, so it’s obviously something I missed.)
  • Enabled worker-based belief updating by default
  • Added a ‘Debug’ menu
    • (Mostly just performance-testing options.)
  • Performance tweaks to continuous variables

Make-Believe (R12): Continuous Improvement

Ack! The previous version I posted had broken the ability to enter evidence, and due to an extended period of busyness, I didn’t notice until now. (No regression tests yet — I do this for fun.) Oh well, thankfully no-one is paying attention.

Given the long period since the last update, I thought I’d try adding something a bit more interesting this time — initial support for continuous nodes. The support I’m providing will match what GeNIe supports as closely as possible. This release includes support for Uniform, Bernoulli, and Normal. It also supports arithmetic operators (e.g. +, *, etc.) as well as the ternary operator (i.e. <if-cond> ? <then> : <else>).  To be clear, that’s just because I’m handing things over to JavaScript. :) I’ll continue to do that because it’s probably the approach with the best performance, but I’ll validate inputs in future. (Just in case people do start loading .xdsl files from suspicious locations.)

It’s also worth pointing out how limited the overall support is at the moment. You can’t enter evidence into a net with continuous nodes. You can’t use the continuous nodes with worker threads. The Normal sampling is very crude. The distributions that are displayed are just histograms up to a maximum of 10 bins. I also haven’t thought about performance yet. As I’ve noted, I do this because I enjoy it, so I’m not rushing things — there’s no need to scoff down the whole dessert at once.

From now on, I’ll put each release in its own folder, so that there’s at least a working version to go back to if I break things again! Here’s Release 12:

Changes:

  • Fixed entering of evidence
  • Improved robustness of saving a bit (note: can’t save continuous nodes at all yet, and probably many other types of node)
  • Initial support for continuous nodes

Make-Believe (R11)

I’ve added a very crude view of node CPTs — just double-click a node. (No support for deterministic nodes yet.) I expect I’ll be improving this in the next iteration. Also, moving nodes around is no longer quite so awful, with arrows updating as you move.

Changes:

  • Arrows update continuously as you move nodes
  • Added viewing of a CPT by double-clicking node