-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_dist.py
35 lines (27 loc) · 893 Bytes
/
log_dist.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
# -*- coding: utf-8 -*-
"""
Created on Fri May 27 09:24:27 2022
Log Distribution
used to randomly draw empty field from neighbors of agent
"""
import numpy as np
def log_distribution(x, p):
return -p**x/x*(1/(np.log(1-p)))
def logistic(x):
return 1/(1 + np.exp(-x))
def log_random_index(num_array, risk_aversion):
num_array.sort()
indices = list(range(1,len(num_array)))
weight = 0.8 + (logistic(1/risk_aversion-1)-0.5)/2.5
log_dist = log_distribution(np.array(indices), weight)
p = log_dist +((1-log_dist.sum())/len(indices))
return np.random.choice(np.array(indices)-1, p = p)
def main():
from matplotlib import pyplot as plt
d = list()
a = np.random.random(10)
for _ in range(1000):
d.append(log_random_index(a, risk_aversion = 4))
plt.hist(d, bins = range(1,10,1))
if __name__ == "__main__":
main()