-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathValueGraphBalancing3_2values_2humans.py
795 lines (611 loc) · 27.9 KB
/
ValueGraphBalancing3_2values_2humans.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
#
# This code was developed based on research and ideas of Lenz
# https://github.com/ramennaut
#
# Coded by Roland
# https://github.com/levitation
#
# Repository: https://github.com/levitation-opensource/universal_value_interactions
import os
import numpy as np
from matplotlib import pyplot as plt
import yaml
import random
def init_matrix(negative_interaction_matrix_dict, positive_interaction_matrix_dict):
# check that each value_name is represented in the interaction matrix
for value_name in value_names:
assert negative_interaction_matrix_dict.get(value_name) is not None
assert positive_interaction_matrix_dict.get(value_name) is not None
# check the interaction matrices for consistency
for value1, value1_data in negative_interaction_matrix_dict.items():
for value2, interaction in value1_data.items():
assert negative_interaction_matrix_dict[value2][value1] == interaction
assert positive_interaction_matrix_dict[value1].get(value2) is None
for value1, value1_data in positive_interaction_matrix_dict.items():
for value2, interaction in value1_data.items():
assert positive_interaction_matrix_dict[value2][value1] == interaction
assert negative_interaction_matrix_dict[value1].get(value2) is None
# create numpy format interaction matrix
interaction_matrix = np.zeros([num_value_names, num_value_names])
positive_interaction_matrix = np.zeros([num_value_names, num_value_names])
negative_interaction_matrix = np.zeros([num_value_names, num_value_names])
for value1, value1_data in negative_interaction_matrix_dict.items():
index1 = value_names.index(value1) # do not use enumerate() here for case the value_names are in a different order
for value2, interaction in value1_data.items():
index2 = value_names.index(value2) # cannot use enumerate() here since not all keys are present
interaction_matrix[index1, index2] = interaction
negative_interaction_matrix[index1, index2] = interaction
for value1, value1_data in positive_interaction_matrix_dict.items():
index1 = value_names.index(value1) # do not use enumerate() here for case the value_names are in a different order
for value2, interaction in value1_data.items():
index2 = value_names.index(value2) # cannot use enumerate() here since not all keys are present
interaction_matrix[index1, index2] = interaction
positive_interaction_matrix[index1, index2] = interaction
assert np.array_equal(interaction_matrix, interaction_matrix.T) # check that the matrix was populated correctly - the matrix has to be symmetric
return interaction_matrix, positive_interaction_matrix, negative_interaction_matrix
#/ def init_matrix():
def init():
(
between_agents_interaction_matrix,
between_agents_positive_interaction_matrix,
between_agents_negative_interaction_matrix,
) = init_matrix(
between_agents_negative_interaction_matrix_dict,
between_agents_positive_interaction_matrix_dict,
)
(
self_feedback_interaction_matrix,
self_feedback_positive_interaction_matrix,
self_feedback_negative_interaction_matrix,
) = init_matrix(
self_feedback_negative_interaction_matrix_dict,
self_feedback_positive_interaction_matrix_dict,
)
return (
between_agents_interaction_matrix,
between_agents_positive_interaction_matrix,
between_agents_negative_interaction_matrix,
self_feedback_interaction_matrix,
self_feedback_positive_interaction_matrix,
self_feedback_negative_interaction_matrix,
)
#/ def init():
def prettyprint(data):
print(yaml.dump(data, allow_unicode=True, default_flow_style=False))
def custom_sigmoid10(data):
signs = np.sign(data)
logs = np.log10(np.abs(data) + 1) # offset by +1 to avoid negative logarithm values
return logs * signs
def custom_sigmoid(data):
signs = np.sign(data)
logs = np.log(np.abs(data) + 1) # offset by +1 to avoid negative logarithm values
return logs * signs
def tiebreaking_argmax(arr):
max_values_bitmap = np.isclose(arr, arr.max())
max_values_indexes = np.flatnonzero(max_values_bitmap)
if len(max_values_indexes) == 0: # Happens when all values are infinities or nans. This would cause np.random.choice to throw.
result = np.random.randint(0, len(arr))
else:
result = np.random.choice(max_values_indexes) # TODO: seed for this random generator
return result
def plot_agent_history(subplots, plots_column, agent_name, values_history, utilities_history):
linewidth = 0.75 # TODO: config
subplot = subplots[plots_column, 0]
for index, value_name in enumerate(value_names):
subplot.plot(
values_history[:, index],
label=value_name,
linewidth=linewidth,
)
subplot.set_title(f"{agent_name} - Value level evolution")
subplot.set(xlabel="step", ylabel="raw value level")
subplot.legend()
subplot = subplots[plots_column, 1]
for index, value_name in enumerate(value_names):
subplot.plot(
custom_sigmoid10(values_history[:, index]),
label=value_name,
linewidth=linewidth,
)
subplot.set_title(f"{agent_name} - Sigmoid10 of Value level")
subplot.set(xlabel="step", ylabel="custom_sigmoid10(raw value level)")
subplot.legend()
subplot = subplots[plots_column, 2]
for index, value_name in enumerate(value_names):
subplot.plot(
utilities_history[:, index],
label=value_name,
linewidth=linewidth,
)
subplot.set_title(f"{agent_name} - Utilities evolution")
subplot.set(xlabel="step", ylabel="utility level")
subplot.legend()
subplot = subplots[plots_column, 3]
for index, value_name in enumerate(value_names):
subplot.plot(
custom_sigmoid10(utilities_history[:, index]),
label=value_name,
linewidth=linewidth,
)
subplot.set_title(f"{agent_name} - Sigmoid10 of Utilities")
subplot.set(xlabel="step", ylabel="custom_sigmoid10(utility level)")
subplot.legend()
# TODO: std or gini index over values per timestep plot
#/ def plot_agent_history(values_history, utilities_history, utility_function_mode, rebalancing_mode):
def plot_history(values_history_dict, utilities_history_dict, utility_function_mode, rebalancing_mode):
fig, subplots = plt.subplots(2, 4)
fig.suptitle(f"Value graph balancing - utility function: {utility_function_mode} - rebalancing: {rebalancing_mode}")
agent_name = agent_names[0]
plot_agent_history(
subplots,
0, # plots_column
agent_name.upper(),
values_history_dict[agent_name],
utilities_history_dict[agent_name],
)
agent_name = agent_names[1]
plot_agent_history(
subplots,
1, # plots_column
agent_name.upper(),
values_history_dict[agent_name],
utilities_history_dict[agent_name],
)
plt.ion()
# maximise_plot()
fig.show()
plt.draw()
plt.pause(60) # render the plot. Usually the plot is rendered quickly but sometimes it may require up to 60 sec. Else you get just a blank window
wait_for_enter("Press enter to close the plot")
#/ def plot_history(history):
def wait_for_enter(message=None):
if os.name == "nt":
import msvcrt
if message is not None:
print(message)
msvcrt.getch() # Uses less CPU on Windows than input() function. This becomes perceptible when multiple console windows with Python are waiting for input. Note that the graph window will be frozen, but will still show graphs.
else:
if message is None:
message = ""
input(message)
def compute_utilities(prev_actual_values, updated_actual_values, prev_utilities, utility_function_mode):
value_changes = updated_actual_values - prev_actual_values
positive_actual_values = np.maximum(updated_actual_values, 0)
negative_actual_values = np.minimum(updated_actual_values, 0)
# NB! this is not same as *_interaction_value_changes since here we filter by the sign of the change, not sign of the interaction
positive_value_changes = np.maximum(value_changes, 0)
negative_value_changes = np.minimum(value_changes, 0)
if utility_function_mode == "linear":
utilities = updated_actual_values
elif utility_function_mode == "sigmoid":
utilities = custom_sigmoid(updated_actual_values)
elif utility_function_mode == "prospect_theory": # sigmoid is applied to value CHANGES not to RESULTING values. ALSO: negative side is amplified.
# NB! current logic amplifies LOSS, irrespective whether the resulting value is positive of negative.
change_utilities = custom_sigmoid(positive_value_changes) + custom_sigmoid(negative_value_changes) * 2 # TODO: config parameter
# utilities = prev_utilities + change_utilities
utilities = 0.5 * prev_utilities + change_utilities # TODO: parameter for past utilities discounting
elif utility_function_mode == "concave": # positive side is logarithmic similarly to sigmoid, but negative side is treated exponentially
# SFELLA formula: https://link.springer.com/article/10.1007/s10458-022-09586-2
positive_updated_utilities = np.log(positive_actual_values + 1)
negative_updated_utilities = 1 - np.exp(-negative_actual_values)
utilities = positive_updated_utilities + negative_updated_utilities
elif utility_function_mode == "linear_homeostasis": # too much of an actual value reduces the subjective value (utility)
diff_from_targets = np.abs(updated_actual_values - target_values)
# diff_from_targets = np.power(diff_from_targets, 2) # TODO: parameter
utilities = -0.1 * diff_from_targets # linear mode
elif utility_function_mode == "squared_homeostasis": # too much of an actual value reduces the subjective value (utility)
diff_from_targets = np.abs(updated_actual_values - target_values)
# diff_from_targets = np.power(diff_from_targets, 2) # TODO: parameter
utilities = -0.01 * diff_from_targets * diff_from_targets # squared error mode
else:
raise Exception("Unknown utility_function_mode")
return utilities
#/ def compute_utilities(actual_values):
def main(utility_function_mode, rebalancing_mode):
(
between_agents_interaction_matrix,
between_agents_positive_interaction_matrix,
between_agents_negative_interaction_matrix,
self_feedback_interaction_matrix,
self_feedback_positive_interaction_matrix,
self_feedback_negative_interaction_matrix,
) = init()
actual_values_dict = {}
utilities_dict = {}
values_history_dict = {}
utilities_history_dict = {}
for agent_name in agent_names:
# TODO!!!: init prev values and utilities to be equal to initial actuals and utilities? It is not like the world suddenly jumped into existence and there was nothing before.
prev_actual_values = np.zeros([num_value_names])
prev_utilities = np.zeros([num_value_names])
if utility_function_mode == "linear_homeostasis" or utility_function_mode == "squared_homeostasis": # NB! in case of homeostatic utilities, the initial values cannot be too far off targets, else the system never recovers
actual_values = homeostatic_utility_scenario_actual_values.copy() # NB! copy since this matrix might be modified in place later
else:
actual_values = initial_actual_values.copy() # NB! copy since this matrix might be modified in place later
utilities = compute_utilities(prev_actual_values, actual_values, prev_utilities, utility_function_mode)
values_history = np.zeros([experiment_length, num_value_names])
utilities_history = np.zeros([experiment_length, num_value_names])
actual_values_dict[agent_name] = actual_values
utilities_dict[agent_name] = utilities
values_history_dict[agent_name] = values_history
utilities_history_dict[agent_name] = utilities_history
#/ for agent_name in agent_names:
for step in range(0, experiment_length):
updated_utilities_dict = {}
updated_actual_values_dict = {}
for agent_index, agent_name in enumerate(agent_names):
other_agent_name = agent_names[1 - agent_index]
self_utilities = utilities_dict[agent_name]
other_utilities = utilities_dict[other_agent_name]
self_actual_values = actual_values_dict[agent_name]
# compute between-agent-interactions
interaction_matrix = between_agents_interaction_matrix
positive_interaction_matrix = between_agents_positive_interaction_matrix
negative_interaction_matrix = between_agents_negative_interaction_matrix
# NB! the raw value level changes are computed based on interactions with utilities, not on interactions between raw value levels
if not restrict_negative_interactions:
value_changes1 = np.matmul(other_utilities, interaction_matrix) * value_interaction_rate
else:
positive_interaction_value_changes = np.matmul(other_utilities, positive_interaction_matrix) * value_interaction_rate
negative_interaction_value_changes = np.matmul(np.maximum(other_utilities, 0), negative_interaction_matrix) * value_interaction_rate # np.maximum: in case of negative interactions, ignore negative actual values
value_changes1 = positive_interaction_value_changes + negative_interaction_value_changes
# compute self-feedback-interactions
interaction_matrix = self_feedback_interaction_matrix
positive_interaction_matrix = self_feedback_positive_interaction_matrix
negative_interaction_matrix = self_feedback_negative_interaction_matrix
# NB! the raw value level changes are computed based on interactions with utilities, not on interactions between raw value levels
if not restrict_negative_interactions:
value_changes2 = np.matmul(self_utilities, interaction_matrix) * value_interaction_rate
else:
positive_interaction_value_changes = np.matmul(self_utilities, positive_interaction_matrix) * value_interaction_rate
negative_interaction_value_changes = np.matmul(np.maximum(self_utilities, 0), negative_interaction_matrix) * value_interaction_rate # np.maximum: in case of negative interactions, ignore negative actual values
value_changes2 = positive_interaction_value_changes + negative_interaction_value_changes
# compute utilities from updated actual values
self_updated_actual_values = self_actual_values + value_changes1 + value_changes2
self_utilities = compute_utilities(
self_actual_values,
self_updated_actual_values,
self_utilities,
utility_function_mode,
)
self_actual_values = self_updated_actual_values
# do not broadcast the updates until both agents have computed their updates, until then store in updated_* variables
updated_utilities_dict[agent_name] = self_utilities
updated_actual_values_dict[agent_name] = self_actual_values
#/ for agent_name in agent_names:
# lets broadcast the updates now into the main dicts
utilities_dict = updated_utilities_dict
actual_values_dict = updated_actual_values_dict
# value rebalancing phase
# for time being, lets assume that the rebalancing mechanism can directly affect only the human's value levels
# the agent's value levels will be affected indirectly
# human is chosen as rebalancing target here because this simple logic below would not be able to rebalance the human through agent's value levels
# TODO: let an LLM or RL rebalance directly the agent's value levels only, while the actual rebalancing priority is on human value levels, which are affected then indirectly only
# TODO: optional setup for affecting both agent's and human's value levels directly during rebalancing
rebalanced_agent_name = random.choice(agent_names) # lets make the scenario more interesting by imposing a random constraint on who can be rebalanced
actual_values = actual_values_dict[rebalanced_agent_name]
# TODO: refactor this rebalancing code block into a separate function
rebalanced_actual_values = actual_values.copy()
# TODO: option to require removal or addition of resources to some other value when current most extreme value is adjusted, so that the sum total remains same
if rebalancing_mode == "none":
pass
elif rebalancing_mode == "llm":
pass # TODO: implement an LLM that does the rebalancing. Lets see whether LLM is at least as good as the simple fixed formulas below.
elif rebalancing_mode == "homeostatic":
# a simple agent that chooses one most extreme value (as compared to the value's target) and rebalances it at most by 1 unit.
# NB! This assumes that all values are homeostatic and THERE IS A DESIRED TARGET LEVEL FOR EACH VALUE.
deviations_from_targets = actual_values - target_values
absolute_deviations = np.abs(deviations_from_targets)
max_deviation_index = tiebreaking_argmax(absolute_deviations)
deviation = deviations_from_targets[max_deviation_index]
if deviation < 0:
balance_step = min(max_rebalancing_step_size, -deviation) # min(): if deviation magnitude is smaller than max_rebalancing_step_size then step by deviation magnitude only
else:
balance_step = -min(max_rebalancing_step_size, deviation) # min(): if deviation magnitude is smaller than max_rebalancing_step_size then step by deviation magnitude only
rebalanced_actual_values[max_deviation_index] += balance_step
elif rebalancing_mode == "homeostatic_boosting": # TODO: implement also naive boost mode which chooses a value with lowest level regardless of the target value
# a simple agent that chooses one least implemented value that is below the value's target level and rebalances it at most by 1 unit.
deviations_from_targets = actual_values - target_values
max_deviation_index = tiebreaking_argmax(-deviations_from_targets)
deviation = deviations_from_targets[max_deviation_index]
if deviation < 0:
balance_step = min(max_rebalancing_step_size, -deviation) # min(): if deviation magnitude is smaller than max_rebalancing_step_size then step by deviation magnitude only
else:
balance_step = 0
rebalanced_actual_values[max_deviation_index] += balance_step
elif rebalancing_mode == "homeostatic_throttling": # TODO: implement also naive throttling mode which chooses a value with highest level regardless of the target value
# a simple agent that chooses one most positive value above the value's target level and rebalances it at most by 1 unit.
deviations_from_targets = actual_values - target_values
max_deviation_index = tiebreaking_argmax(deviations_from_targets)
deviation = deviations_from_targets[max_deviation_index]
if deviation > 0:
balance_step = -min(max_rebalancing_step_size, deviation) # min(): if deviation magnitude is smaller than max_rebalancing_step_size then step by deviation magnitude only
else:
balance_step = 0
rebalanced_actual_values[max_deviation_index] += balance_step
else:
raise Exception("Unknown rebalancing_mode")
utilities = compute_utilities(actual_values, rebalanced_actual_values, utilities, utility_function_mode)
actual_values = rebalanced_actual_values
# lets broadcast the updates caused by rebalancing
actual_values_dict[rebalanced_agent_name] = actual_values
for agent_name in agent_names:
utilities = utilities_dict[agent_name]
actual_values = actual_values_dict[agent_name]
values_history_matrix = values_history_dict[agent_name]
utilities_history_matrix = utilities_history_dict[agent_name]
values_history_matrix[step, :] = actual_values
utilities_history_matrix[step, :] = utilities
if False:
for agent_name in agent_names:
utilities = utilities_dict[agent_name]
actual_values = actual_values_dict[agent_name]
actual_values_with_names_dict = {
value_name: "{:.3f}".format(actual_values[index])
for index, value_name in enumerate(
value_names
) # TODO: could also use zip instead of enumerate
}
utilities_with_names_dict = {
value_name: "{:.3f}".format(utilities[index])
for index, value_name in enumerate(
value_names
) # TODO: could also use zip instead of enumerate
}
print(f"{agent_name.upper()} raw value levels:")
prettyprint(actual_values_with_names_dict)
print(f"{agent_name.upper()} utilities:")
prettyprint(utilities_with_names_dict)
#/ for agent_name in agent_names:
print()
print()
#/ for step in range(0, experiment_length):
plot_history(values_history_dict, utilities_history_dict, utility_function_mode, rebalancing_mode)
#/ def main():
if __name__ == "__main__":
# values and interaction matrices
value_names = [
"Power",
# "Achievement",
# "Hedonism",
# "Stimulation",
# "Self-direction",
# "Universalism",
"Benevolence",
# "Tradition",
# "Conformity",
# "Security",
]
# TODO!!! Originally, between-agents and self-feedback interaction matrices were equal, but they probably should not be equal. Please adjust the numbers in the matrices to match the anthropological research.
# for clarity purposes, using separate matrices for negative and positive interactions
between_agents_negative_interaction_matrix_dict = {
"Power": {
"Power": -0.5, # the other agent might lose power, but not necessarily
# "Universalism": -1,
# "Benevolence": -1,
# "Tradition": -1, # TODO
},
# "Achievement": {
# "Universalism": -1,
# "Benevolence": -1,
# "Tradition": -1, # TODO
# },
# "Hedonism": {
# "Universalism": -1, # TODO
# "Benevolence": -1, # TODO
# "Tradition": -1,
# "Conformity": -1,
# },
# "Stimulation": {
# "Tradition": -1,
# "Conformity": -1,
# "Security": -1,
# },
# "Self-direction": {
# "Tradition": -1,
# "Conformity": -1,
# "Security": -1,
# },
# "Universalism": {
# "Power": -1,
# "Achievement": -1,
# "Hedonism": -1, # TODO
# },
"Benevolence": {
# "Power": -1,
# "Achievement": -1,
# "Hedonism": -1, # TODO
},
# "Tradition": {
# "Power": -1, # TODO
# "Achievement": -1, # TODO
# "Hedonism": -1,
# "Stimulation": -1,
# "Self-direction": -1,
# },
# "Conformity": {
# "Hedonism": -1,
# "Stimulation": -1,
# "Self-direction": -1,
# },
# "Security": {
# "Stimulation": -1,
# "Self-direction": -1,
# },
}
# for clarity purposes, using separate matrices for negative and positive interactions
between_agents_positive_interaction_matrix_dict = {
"Power": {
# "Achievement": 1,
# "Security": 1,
},
# "Achievement": {
# "Power": 1,
# "Hedonism": 1,
# },
# "Hedonism": {
# "Achievement": 1,
# "Stimulation": 1,
# },
# "Stimulation": {
# "Hedonism": 1,
# "Self-direction": 1,
# },
# "Self-direction": {
# "Stimulation": 1,
# "Universalism": 1,
# },
# "Universalism": {
# "Self-direction": 1,
# "Benevolence": 1,
# },
"Benevolence": {
# "Universalism": 1,
"Benevolence": 0.5, # the other agent might become more benevolent, but not necessarily
},
# "Tradition": {
# "Conformity": 1,
# },
# "Conformity": {
# "Tradition": 1,
# "Security": 1,
# },
# "Security": {
# "Power": 1,
# "Conformity": 1,
# },
}
# for clarity purposes, using separate matrices for negative and positive interactions
self_feedback_negative_interaction_matrix_dict = {
"Power": {
# "Universalism": -1,
"Benevolence": -1,
# "Tradition": -1, # TODO
},
# "Achievement": {
# "Universalism": -1,
# "Benevolence": -1,
# "Tradition": -1, # TODO
# },
# "Hedonism": {
# "Universalism": -1, # TODO
# "Benevolence": -1, # TODO
# "Tradition": -1,
# "Conformity": -1,
# },
# "Stimulation": {
# "Tradition": -1,
# "Conformity": -1,
# "Security": -1,
# },
# "Self-direction": {
# "Tradition": -1,
# "Conformity": -1,
# "Security": -1,
# },
# "Universalism": {
# "Power": -1,
# "Achievement": -1,
# "Hedonism": -1, # TODO
# },
"Benevolence": {
"Power": -1,
# "Achievement": -1,
# "Hedonism": -1, # TODO
},
# "Tradition": {
# "Power": -1, # TODO
# "Achievement": -1, # TODO
# "Hedonism": -1,
# "Stimulation": -1,
# "Self-direction": -1,
# },
# "Conformity": {
# "Hedonism": -1,
# "Stimulation": -1,
# "Self-direction": -1,
# },
# "Security": {
# "Stimulation": -1,
# "Self-direction": -1,
# },
}
# for clarity purposes, using separate matrices for negative and positive interactions
self_feedback_positive_interaction_matrix_dict = {
"Power": {
# "Achievement": 1,
# "Security": 1,
},
# "Achievement": {
# "Power": 1,
# "Hedonism": 1,
# },
# "Hedonism": {
# "Achievement": 1,
# "Stimulation": 1,
# },
# "Stimulation": {
# "Hedonism": 1,
# "Self-direction": 1,
# },
# "Self-direction": {
# "Stimulation": 1,
# "Universalism": 1,
# },
# "Universalism": {
# "Self-direction": 1,
# "Benevolence": 1,
# },
"Benevolence": {
# "Universalism": 1,
},
# "Tradition": {
# "Conformity": 1,
# },
# "Conformity": {
# "Tradition": 1,
# "Security": 1,
# },
# "Security": {
# "Power": 1,
# "Conformity": 1,
# },
}
# parameters
agent_names = [
"alice",
"bob",
]
experiment_length = 1000
value_interaction_rate = 0.0462 # the system becomes unstable and the power goes to negative range when value interaction rate is above that
restrict_negative_interactions = True
max_rebalancing_step_size = 0.1
num_value_names = len(value_names)
initial_actual_values = np.ones([num_value_names])
target_values = 50 * np.ones([num_value_names]) # used only by homeostasis and by rebalancing agent
homeostatic_utility_scenario_actual_values = target_values - 10 # NB! in case of homeostatic utilities, the initial values cannot be too far off targets, else the system never recovers
random.seed(0) # lets make the random number sequences used for rebalanced person selection reproducible
# utility function mode and rebalancing mode
# main(utility_function_mode="linear", rebalancing_mode="none")
# main(utility_function_mode="linear", rebalancing_mode="homeostatic_boosting")
# main(utility_function_mode="linear", rebalancing_mode="homeostatic")
# main(utility_function_mode="sigmoid", rebalancing_mode="none")
# main(utility_function_mode="sigmoid", rebalancing_mode="homeostatic_boosting")
main(utility_function_mode="sigmoid", rebalancing_mode="homeostatic")
# TODO: it is possible that my prospect theory implementation is incorrect.
# main(utility_function_mode="prospect_theory", rebalancing_mode="none")
# main(utility_function_mode="prospect_theory", rebalancing_mode="homeostatic_boosting")
# main(utility_function_mode="prospect_theory", rebalancing_mode="homeostatic")
# main(utility_function_mode="concave", rebalancing_mode="none")
# main(utility_function_mode="concave", rebalancing_mode="homeostatic_boosting")
# main(utility_function_mode="concave", rebalancing_mode="homeostatic")
# main(utility_function_mode="linear_homeostasis", rebalancing_mode="none")
# main(utility_function_mode="linear_homeostasis", rebalancing_mode="homeostatic_boosting")
# main(utility_function_mode="linear_homeostasis", rebalancing_mode="homeostatic")
# main(utility_function_mode="squared_homeostasis", rebalancing_mode="none")
# main(utility_function_mode="squared_homeostasis", rebalancing_mode="homeostatic_boosting")
# main(utility_function_mode="squared_homeostasis", rebalancing_mode="homeostatic")
#/ if __name__ == "__main__":