Exemplo n.º 1
0
def lol(aStoC, bCtoS, alpha, beta, population, color):

    xgraph = []
    ygraph = []
    y2graph= []

    for v in app.frange(0.01,1.01,0.01): #v -> parameter to be varied; for this case, alpha
        steady_nC_1 = app.steady_nC(aStoC, bCtoS, v, beta, N*M, 1)
        steady_nC_2 = app.steady_nC(aStoC, bCtoS, v, beta, N*M, -1)
        xgraph.append(v)
        ygraph.append(steady_nC_1)
        y2graph.append(steady_nC_2)
    
   
    plt.plot(xgraph,ygraph, color=color, label=beta)
    plt.plot(xgraph,y2graph, color=color)
    plt.axhline(app.steady_nC(aStoC, bCtoS, alpha, beta, N*M, 0), color='b')
Exemplo n.º 2
0
def vectorData(bCtoS, beta, x, y, z):
    abarRange = np.linspace(0, 1, x)
    startRange = np.linspace(0, 100, y)

    n = 0

    abar = np.zeros(len(abarRange) * len(startRange))
    start = np.zeros(len(abarRange) * len(startRange))
    dx = np.zeros(len(abarRange) * len(startRange))
    dy = np.zeros(len(abarRange) * len(startRange))
    rawHeat = np.zeros(len(abarRange) * len(startRange))

    for i in range(len(abarRange)):
        for j in range(len(startRange)):
            k = lastList(abarRange[i], bCtoS, alpha, beta, N, M, startRange[j],
                         time, t_1, z)
            abar[n] = (abarRange[i])
            start[n] = (startRange[j])
            if sum(k) / len(k) >= 0.5:
                if startRange[j] > np.floor(
                        app.steady_nC(abarRange[i], bCtoS, alpha, beta, N * M,
                                      1)):
                    dy[n] = -max(startRange) / (y - 1)
                elif startRange[j] == np.floor(
                        app.steady_nC(abarRange[i], bCtoS, alpha, beta, N * M,
                                      1)):
                    dy[n] = 0
                else:
                    dy[n] = max(startRange) / (y - 1)
            else:
                dy[n] = -max(startRange) / (y - 1)
            rawHeat[n] = abs(sum(k) / len(k) - 0.5) / 0.5
            n += 1
            print(t.time() - speed)

    #writes ilist,meanlist, and stdlist into a txt file
    filename = 'b = ' + str(bCtoS) + ', beta = ' + str(beta) + ', x = ' + str(
        x) + ', y = ' + str(y) + ', z = ' + str(z) + '.txt'
    with open(filename, 'w') as f:
        lis = [abar, start, dx, dy, rawHeat]
        for x in zip(*lis):
            f.write("{0}\t{1}\t{2}\t{3}\t{4}\n".format(*x))
Exemplo n.º 3
0
import applause_functions as app
import matplotlib.pyplot as plt
import numpy as np

N = 10
M = 10
population = N * M
time = 100
t_1 = 3
aStoC = 1.0
bCtoS = 0.5
alpha = 0.8
beta = 2

fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot(app.app_sim(aStoC, bCtoS, alpha, beta, N, M, time, t_1))
plt.axhline(app.steady_nC(aStoC, bCtoS, alpha, beta, population, 0), color='r')
ax.text(0.5 * time,
        app.steady_nC(aStoC, bCtoS, alpha, beta, population, -1) + 1,
        'Steady-state: ' +
        str(app.steady_nC(aStoC, bCtoS, alpha, beta, population, -1)),
        fontsize=20)
ax.text(90, 100, 'N = ' + str(population))
plt.title('a = ' + str(aStoC) + ' b = ' + str(bCtoS) + ' alpha = ' +
          str(alpha) + ' beta = ' + str(beta))
plt.xlabel('Time')
plt.ylabel('State C')
plt.savefig('a = ' + str(aStoC) + ' b = ' + str(bCtoS) + ' alpha = ' +
            str(alpha) + ' beta = ' + str(beta) + '.png')
plt.show()
Exemplo n.º 4
0
time = 500
t_1 = 2
C = 0
aStoC = 1
bCtoS = 0.8
alpha = 0.6
beta = 1

fig = plt.figure()
ax = fig.add_subplot(111)
sim = app.app_sim(aStoC, bCtoS, alpha, beta, N, M, C, time, t_1)
plt.plot(sim)
ax.text(0.45 * time,
        1,
        'Steady-state:' +
        str(round(app.steady_nC(aStoC, bCtoS, alpha, beta, population, 1), 0)),
        fontsize=20)
ax.text(0.45 * time,
        10,
        'Mean: ' + str(round(np.mean(sim), 1)) + '$\pm$' +
        str(round(np.std(sim), 2)),
        fontsize=20)
ax.text(10, 100, 'N = ' + str(population), fontsize=15)
plt.axhline(np.mean(sim), color='r')
plt.axhline(app.steady_nC(aStoC, bCtoS, alpha, beta, population, 1), color='g')
plt.title('$a = $' + str(aStoC) + ' $b = $' + str(bCtoS) + r' $\alpha=$' +
          str(alpha) + r' $\beta=$' + str(beta),
          fontsize=20)
plt.xlabel('Time', fontsize=18)
plt.ylabel('State' + r' $n_{c}$', fontsize=18)
plt.xlim(0, time)
from numpy import zeros, sqrt
import applause_functions as app

N = 10
M = 10
population = N * M
time = 300 #iterations
t_1 = 25 #iterations of forcing function
AGENT = zeros((N,M)) # agent is either clapping (1) or silent (0), agent starts silent
aStoC = 0.9 #probability to start
bCtoS = 0.25 #probability to stop
alpha = 0.5
beta = 0
xgraph = []
ygraph = []

steady_nC_2 =  population - (bCtoS * (population - 1)) / (aStoC * alpha) #equation 2 for steady state with fprime

for alpha in app.frange(0.01,1.0,0.01):
    steady_nC_2 = app.steady_nC(aStoC, bCtoS, i, beta, population, 1)
    xgraph.append(alpha)
    ygraph.append(steady_nC_2)
    

    
plt.plot(xgraph,ygraph)
plt.axhline(0, color='b')
plt.ylim(-100,100)
plt.show()