def testDevelopment(initialNetwork, runs, steps_per_run):
    """Runs test iterations starting from an initial network
    
    Parameters:
    initialNetwork (jkNetwork): The initial network to start with
    runs (numeric): Number of simulations to be run
    steps_per_iterations (numeric): Number of time steps for the simulations

    Returns:
        Numpy Array: Array with two columns, one for time to collapse and one
            for integral, each row stands for one simulation
    """
    sample_paths = list()
    for i in range(runs):
        #Initialize with parent network
        testJain = jkN(parent=initialNetwork, Id=i)
        #Iterate fixed number of steps
        testJain.iterate(steps_per_run)
        #Analyse
        testJain.runAnalysis()
        sample_paths.append(testJain)
    return sample_paths
示例#2
0
for task_id in range(task_id_o * 20, (1 + task_id_o) * 20):
    m_min = 0.2
    m_stepsize = 0.05
    grown_per_m = 100  #how many grown networks exist for each parameter level
    runs_per_grown = 100  #how many runs are made per grown network
    grown_task_id = int(
        task_id /
        runs_per_grown)  # task_id of grown network which will be the parent
    m = np.round(m_min + int(grown_task_id / grown_per_m) * m_stepsize, 2)
    run = grown_task_id % grown_per_m  #run number of grown network

    if (os.path.isfile(
            f"jkNetworks/jkN G{str(m).replace('.','_')}-{run}-{task_id - runs_per_grown*grown_task_id}.jk"
    )):
        continue
    try:
        parentNetwork = jkN.loadCompletely(
            network_id=f"G{str(m).replace('.','_')}-{run}")
        runNetwork = jkN(parent=parentNetwork,
                         Id=f"{task_id - runs_per_grown*grown_task_id}",
                         seed=task_id)
        runNetwork.run_till_catastrophe_and_recovery(thres_p=0.1)
        runNetwork.runAnalysis(thresholds=[0.75, 0.5, 0.25, 0.1])
        #import pdb; pdb.set_trace()
        #jkN.plotNetwork(parentNetwork.C)
        #runNetwork.plotLogs(plotAna=[0,1])
        runNetwork.saveCompletely()
    except Exception as exep:
        print(exep)
def createGrownNetwork(s):
    jkN1 = jkN(s=s, Id="Grown")
    jkN1.run_growth_phase()
    return jkN1
def loadLog_and_Network(s, file):
    jkN1 = jkN(s=s)
    jkN1.loadLog(file)
    jkN1.loadNetwork(file)
    return jkN1
        lNetworks.append(loadLog_and_Network(nSpecies, f"Test1 Network {i}"))

    lLinks = [nw.linkLog[-1] for nw in lNetworks]

    sns.scatterplot(x=lLinks, y=dfT2Collapse.mean())
    np.std(lLinks) / np.mean(lLinks)
    np.std(dfT2Collapse.mean()) / np.mean(dfT2Collapse.mean())

    for s in range(50, 100):
        mat = np.ones((s, s), dtype=bool)
        np.fill_diagonal(mat, False)
        print(f"{s}: {np.round(jkN.getPFE(mat)[1],2)}")

    #testing

    Jain3 = jkN(parent=createGrownNetwork(50), Id=1)
    Jain3.run_till_catastrophe_and_recovery(thres_p=0.1)
    Jain3.runAnalysis([40, 20, 5])
    Jain3.plotLogs(plotS1=True,
                   plotLinks=True,
                   plotLambda1=True,
                   plotAna=[0, 1])

    Jain3.saveCompletely()

    Jain4 = jkN.loadCompletely("jkN Grown-1")

    jkN1 = jkN(s=100, m=0.25, Id="Grown")
    jkN1.run_growth_phase()
    jkN1.plotLogs(plotS1=True, plotLinks=True, plotLambda1=True)