Skip to content

Conversation

@Kucharssim
Copy link
Member

fixes #312

Example

def context():
    n = np.random.randint(10,100)
    return dict(n=n)

def prior(): 
    mu = np.random.normal(0,1)
    return dict(mu=mu)

def likelihood(mu, n):
    y = np.random.normal(mu,1,n)
    return dict(y=y)

simulator = bf.make_simulator([prior, likelihood], meta_fn=context)

simulator.sample(5, n=10, mu=100)

yields

{'n': 10,
 'mu': array([[100],
        [100],
        [100],
        [100],
        [100]]),
 'y': array([[ 98.90671933, 100.61462062, 100.42855418, 101.29272571,
          99.72418927,  99.37682655, 100.56386549, 100.6960222 ,
          99.68990492,  99.78906661],
        [ 98.30115229,  99.57536366, 100.8883384 ,  99.30972481,
          99.15394186,  99.50626826,  99.84819924,  99.34255664,
          99.72014674, 100.91778608],
        [100.14703062,  97.29856387, 100.26204114, 100.13075532,
          98.46860163,  99.74049941,  99.30891457,  97.92621077,
         100.65618885, 100.32520231],
        [ 99.40222488,  98.65323336, 100.45569538,  99.78072558,
          99.99451661,  99.14487046, 100.01430986, 102.46395478,
         100.37424699, 101.17221606],
        [ 99.82039995,  99.88639318,  98.72186382, 100.3090266 ,
          98.47726752, 100.42259135, 100.5953545 ,  98.9832539 ,
          98.12420365, 102.1115805 ]])}

@Kucharssim Kucharssim requested a review from LarsKue April 17, 2025 11:19
@codecov
Copy link

codecov bot commented Apr 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
bayesflow/simulators/sequential_simulator.py 100.00% <100.00%> (ø)

... and 3 files with indirect coverage changes

@paul-buerkner
Copy link
Contributor

Looks good to me, thank you! Would you mind adding a small test for the new feature?

@LarsKue would you mind quickly reviewing this PR too?

Copy link
Contributor

@LarsKue LarsKue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR!

@paul-buerkner
Copy link
Contributor

Great! Merging now :-)

@paul-buerkner paul-buerkner merged commit 8482926 into bayesflow-org:dev Apr 17, 2025
15 checks passed
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.

3 participants