Prospect Theory¶
# Uncomment the following line when running on Google Colab
# !pip install "autora"
The prospect theory experiment has to be initialized with a specific formula and effects.
import numpy as np
from autora.experiment_runner.synthetic.economics.prospect_theory import prospect_theory
s = prospect_theory()
Check the docstring to get information about the model
help(prospect_theory)
Help on function prospect_theory in module autora.experiment_runner.synthetic.economics.prospect_theory: prospect_theory(name='Prospect Theory', choice_temperature=0.1, value_alpha=0.88, value_beta=0.88, value_lambda=2.25, probability_alpha=0.61, probability_beta=0.69, resolution=10, minimum_value=-1, maximum_value=1) Parameters from D. Kahneman, A. Tversky, Prospect theory: An analysis of decision under risk. Econometrica 47, 263–292 (1979). doi:10.2307/1914185 Power value 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 - I. Gilboa, Expected utility with purely subjective non-additive probabilities. J. Math. Econ. 16, 65–88 (1987). doi:10.1016/0304-4068(87)90022-X - D. Schmeidler, Subjective probability and expected utility without additivity. Econometrica 57, 571 (1989). doi:10.2307/1911053 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
... or use the describe function:
from autora.experiment_runner.synthetic.utilities import describe
print(describe(s))
Parameters from D. Kahneman, A. Tversky, Prospect theory: An analysis of decision under risk. Econometrica 47, 263–292 (1979). doi:10.2307/1914185 Power value 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 - I. Gilboa, Expected utility with purely subjective non-additive probabilities. J. Math. Econ. 16, 65–88 (1987). doi:10.1016/0304-4068(87)90022-X - D. Schmeidler, Subjective probability and expected utility without additivity. Econometrica 57, 571 (1989). doi:10.2307/1911053 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
The synthetic experiement s
has properties like the name of the experiment:
s.name
'Prospect Theory'
... a valid variables description:
s.variables
VariableCollection(independent_variables=[IV(name='V_A', value_range=(-1, 1), allowed_values=array([-1. , -0.77777778, -0.55555556, -0.33333333, -0.11111111, 0.11111111, 0.33333333, 0.55555556, 0.77777778, 1. ]), units='dollar', type=<ValueType.REAL: 'real'>, variable_label='Value of Option A', rescale=1, is_covariate=False), IV(name='P_A', value_range=(0, 1), allowed_values=array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444, 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ]), units='probability', type=<ValueType.REAL: 'real'>, variable_label='Probability of Option A', rescale=1, is_covariate=False), IV(name='V_B', value_range=(-1, 1), allowed_values=array([-1. , -0.77777778, -0.55555556, -0.33333333, -0.11111111, 0.11111111, 0.33333333, 0.55555556, 0.77777778, 1. ]), units='dollar', type=<ValueType.REAL: 'real'>, variable_label='Value of Option B', rescale=1, is_covariate=False), IV(name='P_B', value_range=(0, 1), allowed_values=array([0. , 0.11111111, 0.22222222, 0.33333333, 0.44444444, 0.55555556, 0.66666667, 0.77777778, 0.88888889, 1. ]), units='probability', type=<ValueType.REAL: 'real'>, variable_label='Probability of Option B', rescale=1, is_covariate=False)], dependent_variables=[DV(name='choose_A', value_range=(0, 1), allowed_values=None, units='probability', type=<ValueType.PROBABILITY: 'probability'>, variable_label='Probability of Choosing Option A', rescale=1, is_covariate=False)], covariates=[])
... now we can generate the full domain of the data
x = s.domain()
x
array([[-1. , 0. , -1. , 0. ], [-1. , 0.11111111, -1. , 0. ], [-1. , 0.22222222, -1. , 0. ], ..., [ 1. , 0.77777778, 1. , 1. ], [ 1. , 0.88888889, 1. , 1. ], [ 1. , 1. , 1. , 1. ]])
... the experiment_runner which can be called to generate experimental results:
experiment_data = s.run(x)
experiment_data
V_A | P_A | V_B | P_B | choose_A | |
---|---|---|---|---|---|
0 | -1.0 | 0.000000 | -1.0 | 0.0 | 0.557904 |
1 | -1.0 | 0.111111 | -1.0 | 0.0 | 0.015968 |
2 | -1.0 | 0.222222 | -1.0 | 0.0 | 0.002003 |
3 | -1.0 | 0.333333 | -1.0 | 0.0 | 0.000365 |
4 | -1.0 | 0.444444 | -1.0 | 0.0 | 0.000073 |
... | ... | ... | ... | ... | ... |
9995 | 1.0 | 0.555556 | 1.0 | 1.0 | 0.003957 |
9996 | 1.0 | 0.666667 | 1.0 | 1.0 | 0.007600 |
9997 | 1.0 | 0.777778 | 1.0 | 1.0 | 0.017028 |
9998 | 1.0 | 0.888889 | 1.0 | 1.0 | 0.049545 |
9999 | 1.0 | 1.000000 | 1.0 | 1.0 | 0.431814 |
10000 rows × 5 columns
... a function to plot the ground truth (no noise):
s.plotter()
... against a fitted model if it exists:
from sklearn.linear_model import LinearRegression
ivs = [iv.name for iv in s.variables.independent_variables]
dvs = [dv.name for dv in s.variables.dependent_variables]
X = experiment_data[ivs]
y = experiment_data[dvs]
model = LinearRegression().fit(X, y)
s.plotter(model)
/Users/younesstrittmatter/Documents/GitHub/AutoRA/autora-synthetic/venv/lib/python3.11/site-packages/sklearn/base.py:464: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names warnings.warn( /Users/younesstrittmatter/Documents/GitHub/AutoRA/autora-synthetic/venv/lib/python3.11/site-packages/sklearn/base.py:464: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names warnings.warn( /Users/younesstrittmatter/Documents/GitHub/AutoRA/autora-synthetic/venv/lib/python3.11/site-packages/sklearn/base.py:464: UserWarning: X does not have valid feature names, but LinearRegression was fitted with feature names warnings.warn(
We can wrap this functions to use with the state logic of AutoRA: First, we create the state with the variables:
from autora.state import StandardState, on_state, experiment_runner_on_state, estimator_on_state
from autora.experimentalist.grid import grid_pool
from autora.experimentalist.random import random_sample
# We can get the variables from the runner
variables = s.variables
# With the variables, we initialize a StandardState
state = StandardState(variables)
Wrap the experimentalists in on_state
function to use them on state:
# Wrap the functions to use on state
# Experimentalists:
pool_on_state = on_state(grid_pool, output=['conditions'])
sample_on_state = on_state(random_sample, output=['conditions'])
state = pool_on_state(state)
state = sample_on_state(state, num_samples=2)
print(state.conditions)
V_A P_A V_B P_B 7382 0.555556 0.333333 0.777778 0.222222 5411 0.111111 0.444444 -0.777778 0.111111
Wrap the runner with the experiment_runner_on_state
wrapper to use it on state:
# Runner:
run_on_state = experiment_runner_on_state(s.run)
state = run_on_state(state)
state.experiment_data
V_A | P_A | V_B | P_B | choose_A | |
---|---|---|---|---|---|
7382 | 0.555556 | 0.333333 | 0.777778 | 0.222222 | 0.477033 |
5411 | 0.111111 | 0.444444 | -0.777778 | 0.111111 | 0.979092 |
Wrap the regressor with the estimator_on_state
wrapper:
theorist = LinearRegression()
theorist_on_state = estimator_on_state(theorist)
state = theorist_on_state(state)
# Access the last model:
model = state.models[-1]
print(f"rt = "
f"{model.coef_[0][0]:.2f}*V_A "
f"{model.coef_[0][1]:.2f}*P_A "
f"{model.coef_[0][2]:.2f}*V_B "
f"{model.coef_[0][3]:.2f}*P_B "
f"{model.intercept_[0]:+.2f} ")
rt = -0.08*V_A 0.02*P_A -0.30*V_B -0.02*P_B +0.75