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 Deviate class that draws from an arbitrary P(x) distribution. #306

Closed
rmjarvis opened this issue Oct 19, 2012 · 6 comments
Closed

Add Deviate class that draws from an arbitrary P(x) distribution. #306

rmjarvis opened this issue Oct 19, 2012 · 6 comments
Assignees

Comments

@rmjarvis
Copy link
Member

Useful for when we have an arbitrary (e.g. realistic) P(e) function for the ellipticity.

@msimet
Copy link
Member

msimet commented Oct 19, 2012

I have C++ code for this--could adapt to or wrap in Python.

@ghost ghost assigned msimet Oct 19, 2012
@rmandelb
Copy link
Member

rmandelb commented Jan 8, 2013

@msimet Melanie, I wanted to point out two relatively new things in GalSim that should be useful for this:

  • A while ago, but possibly after this issue was opened, Mike made his 1d integrator accessible in python (integ1d; for an example of its use see galsim/lensing.py).
  • On the branch for Allow PowerSpectrum to accept tabular P(k) #305, Mike made it possible to interpolate a tabulated 1d function.

So I think the code for this issue #306 on drawing random numbers from an arbitrary distribution could be implemented in python by:
(1) reading in your x and P(x) as numpy arrays.
(2) Integrating P(x) with integ1d to get the cumulative probability distribution P(<x).
(3) Make a table out of x vs. P(<x)
(4) sample your uniform random numbers using our standard RNG procedures.
(5) interpolate on the table to get the value of x corresponding to that P(<x).

In practice I think that you might want to make a class called probdist (or something) that is initialized from numpy arrays and does steps (1)-(3), then it can have a method that draws random numbers by doing (4) and (5).

(For context, for anyone else reading this, Melanie mentioned that her code that does this is not in C/C++ after all, so she can't just adapt and wrap it. That's why I'm suggesting how to simply do this from scratch using these new tools in GalSim.)

@msimet
Copy link
Member

msimet commented Jan 15, 2013

Question for the group at large: what should we call this? I was thinking about UserDeviate, but knowing how people tend to abbreviate things I worry about confusion with UniformDeviate.

msimet added a commit that referenced this issue Jan 15, 2013
@rmandelb
Copy link
Member

I don't have a strong opinion. I agree there's potential for confusion with people referring to 'ud' but this is not a very big deal. Another option might be DistDeviate (i.e., deviate from a distribution).

On Jan 15, 2013, at 1:48 PM, msimet notifications@github.com wrote:

Question for the group at large: what should we call this? I was thinking about UserDeviate, but knowing how people tend to abbreviate things I worry about confusion with UniformDeviate.


Reply to this email directly or view it on GitHub.


Rachel Mandelbaum
rmandelb@andrew.cmu.edu
http://www.andrew.cmu.edu/~rmandelb/

@barnabytprowe
Copy link
Member

Either seems pretty good to me. Leave your mark! :)

On 16 Jan 2013, at 03:20, rmandelb wrote:

I don't have a strong opinion. I agree there's potential for
confusion with people referring to 'ud' but this is not a very big
deal. Another option might be DistDeviate (i.e., deviate from a
distribution).

On Jan 15, 2013, at 1:48 PM, msimet notifications@github.com wrote:

Question for the group at large: what should we call this? I was
thinking about UserDeviate, but knowing how people tend to
abbreviate things I worry about confusion with UniformDeviate.


Reply to this email directly or view it on GitHub.


Rachel Mandelbaum
rmandelb@andrew.cmu.edu
http://www.andrew.cmu.edu/~rmandelb/

Reply to this email directly or view it on GitHub.

msimet added a commit that referenced this issue Jan 17, 2013
msimet added a commit that referenced this issue Jan 22, 2013
Conflicts:
	pysrc/SBInterpolatedImage.cpp
	pysrc/module.cpp

Merging latest changes of #305
msimet added a commit that referenced this issue Jan 22, 2013
msimet added a commit that referenced this issue Jan 22, 2013
Conflicts:
	CHANGELOG.md
	galsim/base.py
	pysrc/files.txt
	pysrc/module.cpp
msimet added a commit that referenced this issue Jan 23, 2013
msimet added a commit that referenced this issue Jan 24, 2013
msimet added a commit that referenced this issue Jan 28, 2013
… self in seed() and reset(), min<=max check instead of max<=min) (#306)
msimet added a commit that referenced this issue Jan 28, 2013
…method now always uses equally-spaced abscissa points (#306)
msimet added a commit that referenced this issue Jan 28, 2013
…)==0 points, and touching up the documentation. (#306)
msimet added a commit that referenced this issue Jan 29, 2013
msimet added a commit that referenced this issue Jan 29, 2013
msimet added a commit that referenced this issue Jan 29, 2013
msimet added a commit that referenced this issue Jan 29, 2013
Conflicts:
	CHANGELOG.md
	galsim/base.py
msimet added a commit that referenced this issue Jan 30, 2013
rmandelb added a commit that referenced this issue Feb 1, 2013
msimet added a commit that referenced this issue Feb 4, 2013
msimet added a commit that referenced this issue Feb 4, 2013
…ow up, fixing some of the flat-probability-removal routine, minor bug fixing (#306)
rmjarvis added a commit that referenced this issue Feb 16, 2013
msimet added a commit that referenced this issue Feb 16, 2013
msimet added a commit that referenced this issue Feb 16, 2013
msimet added a commit that referenced this issue Feb 17, 2013
msimet added a commit that referenced this issue Feb 17, 2013
msimet added a commit that referenced this issue Feb 17, 2013
msimet added a commit that referenced this issue Feb 17, 2013
rmandelb added a commit that referenced this issue Feb 17, 2013
msimet added a commit that referenced this issue Feb 17, 2013
msimet added a commit that referenced this issue Feb 17, 2013
@rmjarvis rmjarvis mentioned this issue Feb 18, 2013
msimet added a commit that referenced this issue Feb 18, 2013
…e interpolant kwarg alongside callable functions (#306)
msimet added a commit that referenced this issue Feb 18, 2013
msimet added a commit that referenced this issue Feb 18, 2013
rmjarvis added a commit that referenced this issue Feb 19, 2013
Conflicts:
	CHANGELOG.md
	doc/GalSim_Quick_Reference.pdf
	doc/ref/GalSim_Quick_Reference.tex
	tests/test_random.py
rmjarvis added a commit that referenced this issue Feb 19, 2013
rmjarvis added a commit that referenced this issue Feb 19, 2013
rmjarvis added a commit that referenced this issue Feb 19, 2013
rmjarvis added a commit that referenced this issue Feb 19, 2013
rmjarvis added a commit that referenced this issue Feb 19, 2013
rmjarvis added a commit that referenced this issue Feb 20, 2013
rmjarvis added a commit that referenced this issue Feb 20, 2013
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

4 participants