webppl
webppl copied to clipboard
Marginal/Categorical incorrectly merge some values due to use of JSON.stringify
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.
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)
Also see #108.
Maybe we should use Map?
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?
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.
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.