Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
null-a opened this issue Sep 9, 2015 · 6 comments

Comments

@null-a
Copy link
Member

null-a commented Sep 9, 2015

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 null-a changed the title Marginals don't handle infinite numerical values in support Marginals incorrectly handle infinite numerical values in support Sep 9, 2015
@stuhlmueller
Copy link
Member

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)

@null-a
Copy link
Member Author

null-a commented Sep 9, 2015

Also see #108.

@stuhlmueller
Copy link
Member

Maybe we should use Map?

@null-a
Copy link
Member Author

null-a commented Sep 9, 2015

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
Copy link
Member Author

null-a commented Sep 9, 2015

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.

@stuhlmueller
Copy link
Member

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 stuhlmueller changed the title Marginals incorrectly handle infinite numerical values in support Marginals incorrectly merge some values due to use of JSON.stringify Jan 7, 2016
@null-a null-a changed the title Marginals incorrectly merge some values due to use of JSON.stringify Marginal/Categorical incorrectly merge some values due to use of JSON.stringify Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants