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

rename experiment_runner to run #4

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ def equation_experiment(
1 2 3
2 3 4

Then to run the experiment, we pass that dataframe to the `.experiment_runner` function:
>>> experiment.experiment_runner(conditions)
Then to run the experiment, we pass that dataframe to the `.run` function:
>>> experiment.run(conditions)
x y z
0 1 2 1.003047
1 2 3 7.989600
2 3 4 81.007505

If the names the expression requires are not part of the dataframe, we get an error message:
>>> experiment.experiment_runner(
>>> experiment.run(
... pd.DataFrame({'z':[1, 2, 2], 'x': [1, 2, 3]})
... ) # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS
Traceback (most recent call last):
Expand All @@ -81,27 +81,27 @@ def equation_experiment(
Each time an experiment is initialized with the same random_state, it should produce the
same results:
>>> experiment = equation_experiment(expr, [iv_x, iv_y], dv_z, random_state=42)
>>> results42 = experiment.experiment_runner(conditions)
>>> results42 = experiment.run(conditions)
>>> results42
x y z
0 1 2 1.003047
1 2 3 7.989600
2 3 4 81.007505

We can specify the random_state for a particular run to reproduce it:
>>> results42_reproduced = experiment.experiment_runner(conditions, random_state=42)
>>> results42_reproduced = experiment.run(conditions, random_state=42)
>>> pd.DataFrame.equals(results42, results42_reproduced)
True

If we don't specify the random_state, it produces different values:
>>> experiment.experiment_runner(conditions)
>>> experiment.run(conditions)
x y z
0 1 2 1.009406
1 2 3 7.980490
2 3 4 80.986978

An alternative input format for the experiment runner is a numpy array (not recommended):
>>> experiment.experiment_runner(np.array([[1, 1], [2, 2], [2, 3]]))
>>> experiment.run(np.array([[1, 1], [2, 2], [2, 3]]))
x y z
0 1 1 1.001278
1 2 2 3.996838
Expand All @@ -111,7 +111,7 @@ def equation_experiment(
will be sorted alphabetically.
In the following case the first entry of the numpy array is still x:
>>> expr = y ** x
>>> experiment.experiment_runner(np.array([[1, 1], [2, 2] , [2, 3]]), random_state=42)
>>> experiment.run(np.array([[1, 1], [2, 2] , [2, 3]]), random_state=42)
x y z
0 1 1 1.003047
1 2 2 3.989600
Expand Down Expand Up @@ -147,7 +147,7 @@ def equation_experiment(
# Define experiment runner
rng = np.random.default_rng(random_state)

def experiment_runner(
def run(
conditions: Union[pd.DataFrame, np.ndarray, np.recarray],
added_noise=0.01,
random_state=None,
Expand Down Expand Up @@ -195,7 +195,7 @@ def experiment_runner(
res[y.name] = out
return res

ground_truth = partial(experiment_runner, added_noise_=0.0)
ground_truth = partial(run, added_noise_=0.0)
"""A function which simulates perfect observations"""

def domain():
Expand Down Expand Up @@ -247,7 +247,7 @@ def plotter(model=None):
name=name,
description=equation_experiment.__doc__,
variables=variables,
experiment_runner=experiment_runner,
run=run,
ground_truth=ground_truth,
domain=domain,
plotter=plotter,
Expand Down