Asexual_Discrete_Replicator.py
def Stability(A,p):
    """
    Check the stability of the interior point G 
    in the discrete replicator dynamics
    A is payoff matrix
    p is the frequency of three strategies
    """
    Ave=(p.dot(A)).dot(p.T)#mean fitness given p
    ev1=np.array([1,0,0]).T
    ev2=np.array([0,1,0]).T
    ev3=np.array([0,0,1]).T
    """
    L: Linearization of payoff A given p
    Then, check the stability of the interipor point G.
    Note: there is a proof of  the necessary and sufficient condition 
    that for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1.
    See Sato (2013), "On the necessary and sufficient condition that 
    for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1." , Network and Information, 21, pp87-92.
    But, this paper is written in Japanese.
    """
    L=np.zeros([3,3])
    L[0,0]=1+p[0]*(A[0,0]-(p.dot(A)).dot(ev1))/Ave
    L[0,1]=0+p[0]*(A[0,1]-(p.dot(A)).dot(ev2))/Ave
    L[0,2]=0+p[0]*(A[0,2]-(p.dot(A)).dot(ev3))/Ave
    L[1,0]=0+p[1]*(A[1,0]-(p.dot(A)).dot(ev1))/Ave
    L[1,1]=1+p[1]*(A[1,1]-(p.dot(A)).dot(ev2))/Ave
    L[1,2]=0+p[1]*(A[1,2]-(p.dot(A)).dot(ev3))/Ave
    L[2,0]=0+p[2]*(A[2,0]-(p.dot(A)).dot(ev1))/Ave
    L[2,1]=0+p[2]*(A[2,1]-(p.dot(A)).dot(ev2))/Ave
    L[2,2]=1+p[2]*(A[2,2]-(p.dot(A)).dot(ev3))/Ave
    trL=L.trace()
    detL=np.linalg.det(L)
    ML=(L[0,0]*L[1,1]-L[0,1]*L[1,0])\
       +(L[1,1]*L[2,2]-L[1,2]*L[2,1])+(L[2,2]*L[0,0]-L[0,2]*L[2,0])
    if abs(-trL)<3 and abs(-trL-detL)-1<ML and ML<1+(-trL)*(-detL)-(-detL)**2:
        stability="stable"
    else:
        stability="unstable"
    #numerical calculation of the eigenvalue of matrix L for double check
    (eig,v)=np.linalg.eig(L)
    return [stability,eig]

    Check the stability of the interior point G 
    in the discrete replicator dynamics
    A is payoff matrix
    p is the frequency of three strategies
    
Check the stability of the interior point G
in the discrete replicator dynamics
A is payoff matrix
p is the frequency of three strategies
Check the stability of the interior point G in the discrete replicator dynamics A is payoff matrix p is the frequency of three strategies
def Stability(A,p):
    Ave=(p.dot(A)).dot(p.T)
    ev1=np.array([1,0,0]).T
    ev2=np.array([0,1,0]).T
    ev3=np.array([0,0,1]).T
    L=np.zeros([3,3])
    L[0,0]=1+p[0]*(A[0,0]-(p.dot(A)).dot(ev1))/Ave
    L[0,1]=0+p[0]*(A[0,1]-(p.dot(A)).dot(ev2))/Ave
    L[0,2]=0+p[0]*(A[0,2]-(p.dot(A)).dot(ev3))/Ave
    L[1,0]=0+p[1]*(A[1,0]-(p.dot(A)).dot(ev1))/Ave
    L[1,1]=1+p[1]*(A[1,1]-(p.dot(A)).dot(ev2))/Ave
    L[1,2]=0+p[1]*(A[1,2]-(p.dot(A)).dot(ev3))/Ave
    L[2,0]=0+p[2]*(A[2,0]-(p.dot(A)).dot(ev1))/Ave
    L[2,1]=0+p[2]*(A[2,1]-(p.dot(A)).dot(ev2))/Ave
    L[2,2]=1+p[2]*(A[2,2]-(p.dot(A)).dot(ev3))/Ave
    trL=L.trace()
    detL=np.linalg.det(L)
    ML=(L[0,0]*L[1,1]-L[0,1]*L[1,0])\
       +(L[1,1]*L[2,2]-L[1,2]*L[2,1])+(L[2,2]*L[0,0]-L[0,2]*L[2,0])
    if abs(-trL)<3 and abs(-trL-detL)-1<ML and ML<1+(-trL)*(-detL)-(-detL)**2:
        stability="stable"
    else:
        stability="unstable"
    (eig,v)=np.linalg.eig(L)
    return [stability,eig]
def Stability ( A , p ) : Ave = ( p . dot ( A ) ) . dot ( p . T ) ev1 = np . array ( [ 1 , 0 , 0 ] ) . T ev2 = np . array ( [ 0 , 1 , 0 ] ) . T ev3 = np . array ( [ 0 , 0 , 1 ] ) . T """
    L: Linearization of payoff A given p
    Then, check the stability of the interipor point G.
    Note: there is a proof of  the necessary and sufficient condition 
    that for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1.
    See Sato (2013), "On the necessary and sufficient condition that 
    for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1." , Network and Information, 21, pp87-92.
    But, this paper is written in Japanese.
    """ L = np . zeros ( [ 3 , 3 ] ) L [ 0 , 0 ] = 1 + p [ 0 ] * ( A [ 0 , 0 ] - ( p . dot ( A ) ) . dot ( ev1 ) ) / Ave L [ 0 , 1 ] = 0 + p [ 0 ] * ( A [ 0 , 1 ] - ( p . dot ( A ) ) . dot ( ev2 ) ) / Ave L [ 0 , 2 ] = 0 + p [ 0 ] * ( A [ 0 , 2 ] - ( p . dot ( A ) ) . dot ( ev3 ) ) / Ave L [ 1 , 0 ] = 0 + p [ 1 ] * ( A [ 1 , 0 ] - ( p . dot ( A ) ) . dot ( ev1 ) ) / Ave L [ 1 , 1 ] = 1 + p [ 1 ] * ( A [ 1 , 1 ] - ( p . dot ( A ) ) . dot ( ev2 ) ) / Ave L [ 1 , 2 ] = 0 + p [ 1 ] * ( A [ 1 , 2 ] - ( p . dot ( A ) ) . dot ( ev3 ) ) / Ave L [ 2 , 0 ] = 0 + p [ 2 ] * ( A [ 2 , 0 ] - ( p . dot ( A ) ) . dot ( ev1 ) ) / Ave L [ 2 , 1 ] = 0 + p [ 2 ] * ( A [ 2 , 1 ] - ( p . dot ( A ) ) . dot ( ev2 ) ) / Ave L [ 2 , 2 ] = 1 + p [ 2 ] * ( A [ 2 , 2 ] - ( p . dot ( A ) ) . dot ( ev3 ) ) / Ave trL = L . trace ( ) detL = np . linalg . det ( L ) ML = ( L [ 0 , 0 ] * L [ 1 , 1 ] - L [ 0 , 1 ] * L [ 1 , 0 ] ) + ( L [ 1 , 1 ] * L [ 2 , 2 ] - L [ 1 , 2 ] * L [ 2 , 1 ] ) + ( L [ 2 , 2 ] * L [ 0 , 0 ] - L [ 0 , 2 ] * L [ 2 , 0 ] ) if abs ( - trL ) < 3 and abs ( - trL - detL ) - 1 < ML and ML < 1 + ( - trL ) * ( - detL ) - ( - detL ) ** 2 : stability = "stable" else : stability = "unstable" ( eig , v ) = np . linalg . eig ( L ) return [ stability , eig ]
Check the stability of the interior point G
in the discrete replicator dynamics
A is payoff matrix
p is the frequency of three strategies
Check the stability of the interior point G in the discrete replicator dynamics A is payoff matrix p is the frequency of three strategies
"""
    Check the stability of the interior point G 
    in the discrete replicator dynamics
    A is payoff matrix
    p is the frequency of three strategies
    """ #mean fitness given p """
    L: Linearization of payoff A given p
    Then, check the stability of the interipor point G.
    Note: there is a proof of  the necessary and sufficient condition 
    that for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1.
    See Sato (2013), "On the necessary and sufficient condition that 
    for a cubic equation  all the absolute values of its solutions are
    less than or equal to 1." , Network and Information, 21, pp87-92.
    But, this paper is written in Japanese.
    """ #numerical calculation of the eigenvalue of matrix L for double check
A
p