webppl icon indicating copy to clipboard operation
webppl copied to clipboard

Marginal/Categorical incorrectly merge some values due to use of JSON.stringify

Open null-a opened this issue 9 years ago • 6 comments

At present:

Enumerate(function() { flip(0.5) ? -Infinity : Infinity }).support(); === [ -Infinity ]

Rather than [ -Infinity, Infinity].

This happens because in building the histogram JSON.stringify(Infinity) === JSON.stringify(-Infinity) === 'null'.

See discussion here.

null-a avatar Sep 09 '15 10:09 null-a

This is only one of a number of issues arising from the use of JSON.stringify:

For example, this returns an ERP with probability 1 on {}:

var f = function(){
  if (flip(.5)){
    return { x: undefined, y: function(){} };
  } else {
    return {};
  }
}
Enumerate(f)

stuhlmueller avatar Sep 09 '15 15:09 stuhlmueller

Also see #108.

null-a avatar Sep 09 '15 16:09 null-a

Maybe we should use Map?

stuhlmueller avatar Sep 09 '15 17:09 stuhlmueller

Maybe we should use Map?

I was thinking that.

One potential snag is the way it compares keys - I suspect this means it doesn't help with #108 for example. (And I don't think this is something which can be customized yet.) If we care about #108 perhaps we could extend Map though?

null-a avatar Sep 09 '15 17:09 null-a

I suspect this means it doesn't help with #108

Only identical objects are considered equal, so I think it would be problematic for stuff which currently works.

null-a avatar Sep 09 '15 17:09 null-a

Only identical objects are considered equal, so I think it's actually problematic for stuff which currently works.

Right. I think what we want is a hash table that uses _.isEqual for equality, and something reasonably efficient for hashing.

stuhlmueller avatar Sep 09 '15 17:09 stuhlmueller