diff --git a/Agent_random.md b/Agent_random.md new file mode 100644 index 0000000..64b8b2b --- /dev/null +++ b/Agent_random.md @@ -0,0 +1,183 @@ + + +``` +import random +import numpy as np +import pandas as pd +``` + + +``` +random.seed(40) + +``` + + +``` +#simple payoff matrix +payoff_a = [(1,-1),(-2,2)] +payoff_b = [(-1, 1),(2,-2)] +``` + + +``` +class Agent: + def __init__(O, payoff, name="agent"): + O.payoff = payoff + O.allmove = [] + #O.tirage = [] + def move(O): + pass + #a=np.random.randint(0,1) + #O.tirage.append(a) + #return a + def take(O,a,b): + #m=O.move() + O.allmove.append(O.payoff[a][b]) + + + def set_move(O,strat): + O.move=strat +``` + + +``` +def at_random(): + if random.random()>0.5: a=1 + else: a=0 + return a +``` + + +``` +def weight_random(): + if random.random()>0.6666666666666666 : a=1 + else: a=0 + return a +``` + + +``` +a=Agent([(1,-1),(-2,2)], "A") +b=Agent([(-1, 1),(2,-2)],"B") +a.set_move(at_random) +b.set_move(at_random) + +for i in range(0,30000): + #a.move() + m_a,m_b = a.move(),b.move() + a.take(m_a,m_b) + b.take(m_a,m_b) + +_=plot(np.cumsum(a.allmove)) +_=plot(np.cumsum(b.allmove)) +``` + + +![png](output_6_0.png) + + + +``` +a=Agent([(1,-1),(-2,2)], "A") +b=Agent([(-1, 1),(2,-2)],"B") +a.set_move( lambda : 0) +b.set_move(lambda : 1) + +for i in range(0,30000): + #a.move() + m_a,m_b = a.move(),b.move() + a.take(m_a,m_b) + b.take(m_a,m_b) + +_=plot(np.cumsum(a.allmove),color="b") +_=plot(np.cumsum(b.allmove),color="r") + +``` + + +![png](output_7_0.png) + + + +``` +a=Agent([(1,-1),(-2,2)], "A") +b=Agent([(-1, 1),(2,-2)],"B") +a.set_move( weight_random) +b.set_move(at_random) + +for i in range(0,30000): + #a.move() + m_a,m_b = a.move(),b.move() + a.take(m_a,m_b) + b.take(m_a,m_b) + +_=plot(np.cumsum(a.allmove),color="b") +_=plot(np.cumsum(b.allmove),color="r") +#a.move() +``` + + + + + 0 + + + + +![png](output_8_1.png) + + + +``` +figsize(16,9) + +for i in range(300): + a=Agent([(1,-1),(-2,2)], "A") + b=Agent([(-1, 1),(2,-2)],"B") + a.set_move( weight_random) + b.set_move(at_random) + + for i in range(0,3000): + #a.move() + m_a,m_b = a.move(),b.move() + a.take(m_a,m_b) + b.take(m_a,m_b) + + _=plot(np.cumsum(a.allmove), color='r',alpha=0.01) + _=plot(np.cumsum(b.allmove),color='b', alpha=0.01) + +``` + + +![png](output_9_0.png) + + + +``` +figsize(16,9) +for i in range(300): + a=Agent([(1,-1),(-2,2)], "A") + b=Agent([(-1, 1),(2,-2)],"B") + a.set_move( at_random) + b.set_move(at_random) + + for i in range(0,3000): + #a.move() + m_a,m_b = a.move(),b.move() + a.take(m_a,m_b) + b.take(m_a,m_b) + + _=plot(np.cumsum(a.allmove), alpha=0.01, color='r') + _=plot(np.cumsum(b.allmove), alpha=0.01, color='b') + +``` + + +![png](output_10_0.png) + + + +``` + +``` diff --git a/README.md b/README.md new file mode 100644 index 0000000..38d8e56 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +test du rendering vi jupyter/ipython diff --git a/output_10_0.png b/output_10_0.png new file mode 100644 index 0000000..c885d52 Binary files /dev/null and b/output_10_0.png differ diff --git a/output_6_0.png b/output_6_0.png new file mode 100644 index 0000000..0b9c562 Binary files /dev/null and b/output_6_0.png differ diff --git a/output_7_0.png b/output_7_0.png new file mode 100644 index 0000000..b6e25ab Binary files /dev/null and b/output_7_0.png differ diff --git a/output_8_1.png b/output_8_1.png new file mode 100644 index 0000000..add760f Binary files /dev/null and b/output_8_1.png differ diff --git a/output_9_0.png b/output_9_0.png new file mode 100644 index 0000000..8da5315 Binary files /dev/null and b/output_9_0.png differ