Wednesday, March 13, 2013

Conditional Probability Tables in JSON

I have found myself in need of a JSON format to transmit and process Bayesian Conditional Probability Tables (CPTs).  While there are a few XML formats, none seem to be both simple and effective.  As such, I propose the following standard, (with the intent of using it in my future projects):


  • The CPT will be inclosed in a javascript object or python dictionary when not in string format.
  • One item labeled "nodeid" with the node ID of the node the CPT represents. (as booleans are acceptable values in JSON, if the CPT has only states true and false, which it should, they may be recorded as such rather than as strings)
  • One item labeled "index" with an array of the node IDs of parents of the represented node followed by the CPT states.
  • 2^p (where p = # of parents) arrays representing the states of the CPT with a label of the base 10 representation of the state (as a string)
  • The CPT may have a "reviewed" item of type "bool" representing whether the CPT has been manually reviewed.  (Set it to "false" if the CPT was auto-generated and "true" if someone manually updated/reviewed the CPT.)
For example:
{
"nodeid":4,
"index":[1,2,3,true,false],
"0":[0,0,0,0,1],
"1":[0,0,1,0.1,0.9],
"2":[0,1,0,0.1,0.9],
"3":[0,1,1,0.1,0.9],
"4":[1,0,0,0.1,0.9],
"5":[1,0,1,0.1,0.9],
"6":[1,1,0,0.1,0.9],
"7":[1,1,1,0.9,0.1]
}

1 comment:

  1. Add a value "reviewed". Set to 'false' when CPT is automatically generated and "true" when someone manually reviews it.

    ReplyDelete