From 40c9599685940b2a16f559157da07cc49fb6e035 Mon Sep 17 00:00:00 2001 From: Younes Strittmatter Date: Wed, 24 Jul 2024 13:02:16 -0400 Subject: [PATCH] bug: add minimum examples to the runners, fix bugs --- .../synthetic/economics/expected_value_theory.py | 5 +++++ .../synthetic/economics/prospect_theory.py | 5 +++++ .../synthetic/neuroscience/task_switching.py | 15 +++++++++++---- .../synthetic/psychology/exp_learning.py | 12 ++++++++++-- .../synthetic/psychophysics/stevens_power_law.py | 13 ++++++++++--- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/autora/experiment_runner/synthetic/economics/expected_value_theory.py b/src/autora/experiment_runner/synthetic/economics/expected_value_theory.py index b8c1bced..828a6e4d 100644 --- a/src/autora/experiment_runner/synthetic/economics/expected_value_theory.py +++ b/src/autora/experiment_runner/synthetic/economics/expected_value_theory.py @@ -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( diff --git a/src/autora/experiment_runner/synthetic/economics/prospect_theory.py b/src/autora/experiment_runner/synthetic/economics/prospect_theory.py index c2ac20de..4dbd0c62 100644 --- a/src/autora/experiment_runner/synthetic/economics/prospect_theory.py +++ b/src/autora/experiment_runner/synthetic/economics/prospect_theory.py @@ -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 """ diff --git a/src/autora/experiment_runner/synthetic/neuroscience/task_switching.py b/src/autora/experiment_runner/synthetic/neuroscience/task_switching.py index cb12f517..bd95e922 100644 --- a/src/autora/experiment_runner/synthetic/neuroscience/task_switching.py +++ b/src/autora/experiment_runner/synthetic/neuroscience/task_switching.py @@ -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( @@ -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) @@ -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) diff --git a/src/autora/experiment_runner/synthetic/psychology/exp_learning.py b/src/autora/experiment_runner/synthetic/psychology/exp_learning.py index 24ed25dc..2c3d3c5e 100644 --- a/src/autora/experiment_runner/synthetic/psychology/exp_learning.py +++ b/src/autora/experiment_runner/synthetic/psychology/exp_learning.py @@ -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 @@ -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) diff --git a/src/autora/experiment_runner/synthetic/psychophysics/stevens_power_law.py b/src/autora/experiment_runner/synthetic/psychophysics/stevens_power_law.py index 7ebec869..b8a5e944 100644 --- a/src/autora/experiment_runner/synthetic/psychophysics/stevens_power_law.py +++ b/src/autora/experiment_runner/synthetic/psychophysics/stevens_power_law.py @@ -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( @@ -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)