-
Notifications
You must be signed in to change notification settings - Fork 2
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
Noise generator file #55
base: main
Are you sure you want to change the base?
Conversation
vbjax/noise_generator.py
Outdated
import matplotlib.pyplot as plt | ||
import jax | ||
|
||
def noise_psd(shape, key, sigma=1, psd = lambda f: 1, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit like other APIs, could we do something like
psdgen = make_noise_psd(psd=lambda f: 1)
?
vbjax/noise_generator.py
Outdated
|
||
""" | ||
|
||
X_white = np.fft.rfft(jax.random.normal(key, shape)*sigma) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use a nested function here
def make_gen(..., psd):
def gen(key, shape):
X_white = ...
S = psd(...)
return ...
return gen
rainbow_gen = make_noise_gen(psd=lambda f: rainbow( f ) )
make issue is that you need to close over (i.e. use nested function which doesn't take the psd as an argument) in order for this to work well with the jit. the decorator works in this case.. but it's simpler to use the nested function and it's a pattern used elsewhere because it extends nicely to cases where you need the nested function to close & JIT over specific static arrays and functions. |
I'll try to rewrite, thank you for your comments!
Le mer. 24 janv. 2024, 14:08, marmaduke woodman ***@***.***>
a écrit :
… make issue is that you need to close over (i.e. use nested function which
doesn't take the psd as an argument) in order for this to work well with
the jit.
the decorator works in this case.. but it's simpler to use the nested
function and it's a pattern used elsewhere because it extends nicely to
cases where you need the nested function to close & JIT over specific
static arrays and functions.
—
Reply to this email directly, view it on GitHub
<#55 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZ3GWO5UOFEU6N2X5NHDOLYQEBU3AVCNFSM6AAAAABCITMCMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMBYGA4TAMZUG4>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
bump |
@@ -13,9 +13,9 @@ def heun_step(x, dfun, dt, *args, add=0, adhoc=None): | |||
""" | |||
adhoc = adhoc or (lambda x,*args: x) | |||
d1 = dfun(x, *args) | |||
xi = adhoc(x + dt*d1 + add, *args) | |||
xi = adhoc(x, dt*d1 + add, *args) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's going on here? the adhoc
function should have access to the value of xi = x + dt*d1
module to group noise related components.
Allows to generate different colors of noise of desired shape.