@@ -52,10 +52,13 @@ class ContextGenerator:
5252 While the latter can also be considered batchable in principle, batching them would require non-Tensor
5353 (i.e., non-rectangular) data structures, which usually means inefficient computations.
5454
55+ Examples
56+ --------
5557 Example for a simulation context which will generate a random number of observations between 1 and 100 for
5658 each training batch:
5759
5860 >>> gen = ContextGenerator(non_batchable_context_fun=lambda : np.random.randint(1, 101))
61+
5962 """
6063
6164 def __init__ (
@@ -103,8 +106,8 @@ def __call__(self, batch_size, *args, **kwargs):
103106
104107 context_dict : dictionary
105108 A dictionary with context variables with the following keys:
106- `batchable_context` : value
107- `non_batchable_context` : value
109+ `` batchable_context` ` : value
110+ `` non_batchable_context` ` : value
108111
109112 Note, that the values of the context variables will be None, if the
110113 corresponding context-generating functions have not been provided when
@@ -210,7 +213,7 @@ def __init__(
210213 self .is_batched = False
211214
212215 def __call__ (self , batch_size , * args , ** kwargs ):
213- """Generates `batch_size` draws from the prior given optional context generator.
216+ """Generates `` batch_size` ` draws from the prior given optional context generator.
214217
215218 Parameters
216219 ----------
@@ -313,12 +316,12 @@ def __call__(self, batch_size, *args, **kwargs):
313316
314317 def plot_prior2d (self , ** kwargs ):
315318 """Generates a 2D plot representing bivariate prior ditributions. Uses the function
316- `bayesflow.diagnostics.plot_prior2d() internally for generating the plot.
319+ `` bayesflow.diagnostics.plot_prior2d()`` internally for generating the plot.
317320
318321 Parameters
319322 ----------
320323 **kwargs : dict
321- Optional keyword arguments passed to the `plot_prior2d` function.
324+ Optional keyword arguments passed to the `` plot_prior2d` ` function.
322325
323326 Returns
324327 -------
@@ -400,9 +403,10 @@ def __init__(
400403 An optional function (ideally an instance of ``ContextGenerator``) for generating control variables
401404 for the local_prior_fun.
402405
403- Example: Varying number of local factors (e.g., groups, participants) between 1 and 100:
406+ Examples
407+ --------
408+ Varying number of local factors (e.g., groups, participants) between 1 and 100::
404409
405- ``
406410 def draw_hyper():
407411 # Draw location for 2D conditional prior
408412 return np.random.normal(size=2)
@@ -415,6 +419,7 @@ def draw_prior(means, num_groups, sigma=1.):
415419 context = ContextGenerator(non_batchable_context_fun=lambda : np.random.randint(1, 101))
416420 prior = TwoLevelPrior(draw_hyper, draw_prior, local_context_generator=context)
417421 prior_dict = prior(batch_size=32)
422+
418423 """
419424
420425 self .hyper_prior = hyper_prior_fun
@@ -512,19 +517,19 @@ class Simulator:
512517
513518 An optional context generator (i.e., an instance of ContextGenerator) or a user-defined callable object
514519 implementing the following two methods can be provided:
515- - context_generator.batchable_context(batch_size)
516- - context_generator.non_batchable_context()
520+ - `` context_generator.batchable_context(batch_size)``
521+ - `` context_generator.non_batchable_context()``
517522 """
518523
519524 def __init__ (self , batch_simulator_fun = None , simulator_fun = None , context_generator = None ):
520525 """Instantiates a data generator which will perform randomized simulations given a set of parameters and optional context.
521- Either a batch_simulator_fun or simulator_fun, but not both, should be provided to instantiate a Simulator object.
526+ Either a `` batch_simulator_fun`` or `` simulator_fun`` , but not both, should be provided to instantiate a `` Simulator`` object.
522527
523- If a batch_simulator_fun is provided, the interface will assume that the function operates on batches of parameter
528+ If a `` batch_simulator_fun`` is provided, the interface will assume that the function operates on batches of parameter
524529 vectors and context variables and will pass the latter directly to the function. Power users should attempt to provide
525530 optimized batched simulators.
526531
527- If a simulator_fun is provided, the interface will assume thatthe function operates on single parameter vectors and
532+ If a `` simulator_fun`` is provided, the interface will assume thatthe function operates on single parameter vectors and
528533 context variables and will wrap the simulator internally to allow batched functionality.
529534
530535 Parameters
@@ -535,8 +540,8 @@ def __init__(self, batch_simulator_fun=None, simulator_fun=None, context_generat
535540 simulator_fun : callable
536541 A function (callable object) with optional control arguments responsible for generating a simulaiton given
537542 a single parameter vector and optional variables.
538- context generator : callable (default None, recommended instance of ContextGenerator)
539- An optional function (ideally an instance of ContextGenerator) for generating prior context variables.
543+ context_generator : callable (default None, recommended instance of ContextGenerator)
544+ An optional function (ideally an instance of `` ContextGenerator`` ) for generating prior context variables.
540545 """
541546
542547 if (batch_simulator_fun is None ) is (simulator_fun is None ):
@@ -562,9 +567,9 @@ def __call__(self, params, *args, **kwargs):
562567
563568 out_dict : dictionary
564569 An output dictionary with randomly simulated variables, the following keys are mandatory, if default keys not modified:
565- `sim_data` : value
566- `non_batchable_context` : value
567- `batchable_context` : value
570+ `` sim_data` ` : value
571+ `` non_batchable_context` ` : value
572+ `` batchable_context` ` : value
568573 """
569574
570575 # Always assume first dimension is batch dimension
@@ -728,8 +733,8 @@ def __init__(
728733 name : str (default - "anonoymous")
729734 An optional name for the generative model. If kept default (None), 'anonymous' is set as name.
730735
731- Important
732- ----------
736+ Notes
737+ -----
733738 If you are not using the provided ``Prior`` and ``Simulator`` wrappers for your prior and data generator,
734739 only functions returning a ``np.ndarray`` in the correct format will be accepted, since these will be
735740 wrapped internally. In addition, you need to indicate whether your simulator operates on batched of
@@ -761,7 +766,7 @@ def __init__(
761766 self ._test ()
762767
763768 def __call__ (self , batch_size , ** kwargs ):
764- """Carries out forward inference ' batch_size' times."""
769+ """Carries out forward inference `` batch_size`` times."""
765770
766771 # Forward inference
767772 prior_out = self .prior (batch_size , ** kwargs .pop ("prior_args" , {}))
@@ -780,7 +785,7 @@ def __call__(self, batch_size, **kwargs):
780785 return out_dict
781786
782787 def _config_custom_simulator (self , sim_fun , is_batched ):
783- """Only called if user has provided a custom simulator not using the Simulator wrapper."""
788+ """Only called if user has provided a custom simulator not using the `` Simulator`` wrapper."""
784789
785790 if is_batched is None :
786791 raise ConfigurationError (
@@ -796,8 +801,8 @@ def _config_custom_simulator(self, sim_fun, is_batched):
796801 def plot_pushforward (
797802 self , parameter_draws = None , funcs_list = None , funcs_labels = None , batch_size = 1000 , show_raw_sims = True
798803 ):
799- """Creates simulations from parameter_draws (generated from self.prior if they are not passed as an argument)
800- and plots visualizations for them.
804+ """Creates simulations from `` parameter_draws`` (generated from `` self.prior`` if they are not passed as
805+ an argument) and plots visualizations for them.
801806
802807 Parameters
803808 ----------
@@ -959,16 +964,16 @@ def presimulate_and_save(
959964 disable_user_input: bool, optional, default: False
960965 If True, user will not be asked if memory space is sufficient for presimulation.
961966
962- Important
963- ----------
967+ Notes
968+ -----
964969 One of the following pairs of parameters has to be provided:
965970
966971 - (iterations_per_epoch, epochs),
967972 - (total_iterations, iterations_per_epoch)
968973 - (total_iterations, epochs)
969974
970975 Providing all three of the parameters in these pairs leads to a consistency check,
971- since incompatible combinations are possible.
976+ since incompatible combinations are possible.
972977 """
973978 # Ensure that the combination of parameters provided is sufficient to perform presimulation
974979 # and does not contain internal contradictions
@@ -1117,6 +1122,7 @@ def presimulate_and_save(
11171122
11181123class TwoLevelGenerativeModel :
11191124 """Basic interface for a generative model in a simulation-based context.
1125+
11201126 Generally, a generative model consists of two mandatory components:
11211127 - MultilevelPrior : A randomized function returning random parameter draws from a two-level prior distribution;
11221128 - Simulator : A function which transforms the parameters into observables in a non-deterministic manner.
@@ -1149,8 +1155,8 @@ def __init__(
11491155 name : str (default - "anonymous")
11501156 An optional name for the generative model.
11511157
1152- Important
1153- ----------
1158+ Notes
1159+ -----
11541160 If you are not using the provided ``TwoLevelPrior`` and ``Simulator`` wrappers for your prior and data
11551161 generator, only functions returning a ``np.ndarray`` in the correct format will be accepted, since these will be
11561162 wrapped internally. In addition, you need to indicate whether your simulator operates on batched of
@@ -1205,7 +1211,7 @@ def __call__(self, batch_size, **kwargs):
12051211 return out_dict
12061212
12071213 def _config_custom_simulator (self , sim_fun , is_batched ):
1208- """Only called if user has provided a custom simulator not using the Simulator wrapper."""
1214+ """Only called if user has provided a custom simulator not using the `` Simulator`` wrapper."""
12091215
12101216 if is_batched is None :
12111217 raise ConfigurationError (
0 commit comments