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

Noise generator file #55

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

Noise generator file #55

wants to merge 6 commits into from

Conversation

mbreyt
Copy link

@mbreyt mbreyt commented Jan 24, 2024

module to group noise related components.
Allows to generate different colors of noise of desired shape.

import matplotlib.pyplot as plt
import jax

def noise_psd(shape, key, sigma=1, psd = lambda f: 1, **kwargs):
Copy link
Member

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)

?


"""

X_white = np.fft.rfft(jax.random.normal(key, shape)*sigma)
Copy link
Member

@maedoc maedoc Jan 24, 2024

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 ) )

@maedoc
Copy link
Member

maedoc commented Jan 24, 2024

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.

@mbreyt
Copy link
Author

mbreyt commented Jan 24, 2024 via email

@maedoc
Copy link
Member

maedoc commented Feb 23, 2024

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

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

@maedoc maedoc marked this pull request as draft April 17, 2024 14:49
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

Successfully merging this pull request may close these issues.

2 participants