Skip to content

Commit

Permalink
Merge pull request #33 from AutoResearch/31-add-doctests-to-runner
Browse files Browse the repository at this point in the history
bug: add minimum examples to the runners, fix bugs
  • Loading branch information
younesStrittmatter authored Jul 24, 2024
2 parents 8fd9c33 + 40c9599 commit 003d302
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def expected_value_theory(
resolution:
minimum_value:
maximum_value:
Examples:
>>> s = expected_value_theory()
>>> s.run(np.array([[1,2,.1,.9]]), random_state=42)
V_A P_A V_B P_B choose_A
0 1.0 2.0 0.1 0.9 0.999938
"""

params = dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def prospect_theory(
Probability function according to:
A. Tversky, D. Kahneman, Advances in prospect theory: Cumulative representation of
uncertainty. J. Risk Uncertain. 5, 297–323 (1992). doi:10.1007/BF00122574
Examples:
>>> s = prospect_theory()
>>> s.run(np.array([[.9,.1,.1,.9]]), random_state=42)
V_A P_A V_B P_B choose_A
0 0.9 0.1 0.1 0.9 0.709777
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def task_switching(
temperature: temperature for softmax when computing performance of current task
constant: constant for task activation
minimum_task_control: minimum task control
Examples:
>>> s = task_switching()
>>> s.run(np.array([[.5,.7,0]]), random_state=42)
cur_task_strength alt_task_strength is_switch cur_task_performance
0 0.5 0.7 0.0 0.685351
"""

params = dict(
Expand Down Expand Up @@ -107,13 +112,13 @@ def run(
cur_task_strength
+ priming_default * (1 - is_switch)
+ cur_task_control
+ rng.random.normal(0, added_noise)
+ rng.normal(0, added_noise)
)

alt_task_input = (
alt_task_strength
+ priming_default * (is_switch)
+ rng.random.normal(0, added_noise)
+ rng.normal(0, added_noise)
)

cur_task_activation = 1 - np.exp(-constant * cur_task_input)
Expand All @@ -125,8 +130,10 @@ def run(
)

Y[idx] = cur_task_performance

return Y
experiment_data = pd.DataFrame(conditions)
experiment_data.columns = [v.name for v in variables.independent_variables]
experiment_data[variables.dependent_variables[0].name] = Y
return experiment_data

ground_truth = partial(run, added_noise=0.0)

Expand Down
12 changes: 10 additions & 2 deletions src/autora/experiment_runner/synthetic/psychology/exp_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def exp_learning(
minimum_trial: upper bound for exponential constant
name: name of the experiment
resolution: number of allowed values for stimulus
Examples:
>>> s = exp_learning()
>>> s.run(np.array([[.2,.1]]), random_state=42)
P_asymptotic trial performance
0 0.2 0.1 0.205444
"""

maximum_trial = resolution
Expand Down Expand Up @@ -98,11 +103,14 @@ def run(
y = (
p_asymptotic
- (p_asymptotic - p_initial_exp) * np.exp(-lr * trial_exp)
+ rng.random.normal(0, added_noise)
+ rng.normal(0, added_noise)
)
Y[idx] = y

return Y
experiment_data = pd.DataFrame(conditions)
experiment_data.columns = [v.name for v in variables.independent_variables]
experiment_data[variables.dependent_variables[0].name] = Y
return experiment_data

ground_truth = partial(run, added_noise=0.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ def stevens_power_law(
modality_constant: power constant
proportionality_constant: constant multiplier
maximum_stimulus_intensity: maximum value for stimulus
Examples:
>>> s = stevens_power_law()
>>> s.run(np.array([[.9]]), random_state=42)
S perceived_intensity
0 0.9 0.922213
"""

params = dict(
Expand Down Expand Up @@ -69,10 +74,12 @@ def run(
for idx, x in enumerate(X):
y = proportionality_constant * x[
0
] ** modality_constant + rng.random.normal(0, added_noise)
] ** modality_constant + rng.normal(0, added_noise)
Y[idx] = y

return Y
experiment_data = pd.DataFrame(conditions)
experiment_data.columns = [v.name for v in variables.independent_variables]
experiment_data[variables.dependent_variables[0].name] = Y
return experiment_data

ground_truth = partial(run, added_noise=0.0)

Expand Down

0 comments on commit 003d302

Please sign in to comment.