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

Belief constructors #12

Open
zsunberg opened this issue May 25, 2018 · 3 comments
Open

Belief constructors #12

zsunberg opened this issue May 25, 2018 · 3 comments

Comments

@zsunberg
Copy link
Member

It might be nice to have some constructors for the beliefs to answer questions like "how do I make a particle belief from a SparseCat". But, it's not 100% clear which way to do this.

Approach 1:

ParticleCollection(d, n::Integer; rng=Base.GLOBAL_RNG) = ParticleCollection([rand(rng, d) for i in 1:n])

(and similar for WeightedParticleBelief)

Approach 2:

function WeightedParticleBelief(d)
    pairs = collect(weighted_iterator(d))
    return WeightedParticleBelief([first(p) for p in pairs], [last(p) for p in pairs])
end

and a similar ParticleCollection(d, n::Integer=100) that allocates unweighted particles in proportion to their weight.


Approach 2 is nice because it's deterministic and low variance, but it won't work for some distributions (e.g. continuous ones).

@sharonzhou
Copy link

I have a slight preference for Approach 1 to consider continuous distributions. It may also be valuable to have a constructor in the other direction, e.g. ParticleCollection -> SparseCat using the pdf fcn for all states. In the previously deprecated ParticleBelief, there was a probs_dict that was essentially a SparseCat.

@MaximeBouton
Copy link
Contributor

Approach 1 seems more straightforward to me and more generic (apply to any distributions).
I don't see how you control the number of particles in Approach 2?
As you said, the fact that 2 is deterministic and low variance might be appealing, maybe it should be specific to converting SparseCat distribtions only?

@zsunberg
Copy link
Member Author

Yeah, SparseCat from ParticleCollection should be straightforward - we still have that probs_dict as _probs.

I don't see how you control the number of particles in Approach 2?

In the WeightedParticleBelief there is just one particle for each unique state

As you said, the fact that 2 is deterministic and low variance might be appealing, maybe it should be specific to converting SparseCat distribtions only?

I don't think it's a good idea to have the constructor do qualitatively different things based on the input type. That will just lead to confusion.

Probably the best way is to just use Approach 1 for the constructor, and then have another function called exact_particle_belief that does Approach 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants