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

Add nengo.dists.ScatteredSimplex #1691

Open
carlosgmartin opened this issue Apr 10, 2023 · 0 comments
Open

Add nengo.dists.ScatteredSimplex #1691

carlosgmartin opened this issue Apr 10, 2023 · 0 comments

Comments

@carlosgmartin
Copy link

Is your feature request related to a problem? Please describe.

I'd like to use a quasirandom distribution over the standard simplex.

Describe the solution you'd like

Add a class nengo.dists.ScatteredSimplex analogous to nengo.dists.ScatteredHypersphere.

Describe alternatives you've considered

Example:

import numpy as np
from matplotlib import pyplot as plt
import mpltern

from nengo.dists import Distribution, QuasirandomSequence


class ScatteredSimplex(Distribution):

    def __init__(
        self,
        base=QuasirandomSequence()
    ):
        self.base = base

    def sample(self, n, d=1, rng=np.random):
        # uniform distribution
        u = self.base.sample(n, d, rng)
        # exponential distribution
        e = -np.log(u)
        # uniform simplex distribution
        x = e / e.sum(-1, keepdims=True)
        return x


def main():
    x = ScatteredSimplex().sample(10**5, 3)
    fig, ax = plt.subplots(subplot_kw={'projection': 'ternary'})
    ax.scatter(*x.T, lw=0, s=.5)
    plt.show()


if __name__ == '__main__':
    main()

Result:

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

No branches or pull requests

1 participant