C0 = readAttribute(experiment_path, ["C0"])["C0"] rescaleFactor = readAttribute(experiment_path, ["rescaleFactor"])["rescaleFactor"] output = results[modes.index("outputEqui")] output = np.reshape(output, (len(X1), len(X2))) X1 = X1 / (C0 * rescaleFactor) X2 = X2 / (C0 * rescaleFactor) otherActivInitialC = otherActivInitialC / (C0 * rescaleFactor) otherInhibInitialC = otherInhibInitialC / (C0 * rescaleFactor) # colorDiagram(X1,X2,output,"Initial concentration of X1","Initial concentration of X2","Equilibrium concentration of the output",figname=os.path.join(experiment_path, "neuralDiagramm.png"),equiPotential=False) neuronPlot(X1, X2, output, figname=os.path.join(experiment_path, "activationLogX1.png"), figname2=os.path.join(experiment_path, "activationLogX2.png"), useLogX=True, doShow=False) neuronPlot(X1, X2, output, figname=os.path.join(experiment_path, "activationX1.png"), figname2=os.path.join(experiment_path, "activationX2.png"), useLogX=False, doShow=False) df = pandas.DataFrame(X1) df.to_csv(os.path.join(experiment_path, "inputX1.csv")) df2 = pandas.DataFrame(X2) df2.to_csv(os.path.join(experiment_path, "inputX2.csv"))
for layer in range(1,len(masks)): ## the first layer need not to be initiliazed for node in range(masks[layer].shape[0]): initialization_dic["X_"+str(layer)+"_"+str(node)] = layerInit initialization_dic["E"] = enzymeInit initialization_dic["E2"] = enzymeInit results = executeODESimulation(f, name, x_test, initialization_dic, ["X_1_0"], leak, endTime=endTime, sparse=False, modes=modes) if("outputPlot" in modes): import matplotlib.pyplot as plt shapeP = len(X1)*len(X2) nameDic = results[-1] outArrayFullPlot = results[modes.index("output")] toObserve=range(0,shapeP,max(int(shapeP/100),1)) time = np.arange(0,endTime,0.1) for t in toObserve: plt.figure() for idx,k in enumerate(nameDic.keys()): if idx in [nameDic["X_1_0"]]: plt.plot(time,outArrayFullPlot[t,:,idx],label=k) print("the observed min value is "+str(np.min(outArrayFullPlot[t,:,idx]))+" for "+k) plt.legend() plt.show() if("outputEqui" in modes): experiment_path = name C0=readAttribute(experiment_path,["C0"])["C0"] output = results[modes.index("output")] colorDiagram(X1,X2,output,"Initial concentration of X1","Initial concentration of X2","Equilibrium concentration of the output",figname=os.path.join(experiment_path, "neuralDiagramm.png"),equiPotential=False) neuronPlot(X1/C0,X2/C0,output,figname=os.path.join(experiment_path, "activationX1.png"),figname2=os.path.join(experiment_path, "activationX2.png"))
def simulModelIndicator(name, nameFig, enzymeInit=10**(-6), activInit=10**(-8), inhibInit=10**(-8), x2val=None, x1val=None, indexSplit=10): """ Generate an indicator using the indicator function after simulating the model over a range of inputs. :param name: directory where the network is located :param nameFig: directory to store figure :param enzymeInit: initial concentration of the enzyme :param activInit: initial concentration of the activators :param inhibInit: initial concentration of the inhibitors :param x2val: if not none, define fix initial concentration value for inhibitors :param x1val: if not none, define fix initial concentration value for activators :param indexSplit: the size of the test will be two time indexSplit. :return: """ endTime = 10000 timeStep = 0.1 modes = ["verbose", "outputEqui"] leak = 10**(-10) layerInit = 10**(-13) #initial concentation value for species in layers initValue = 10**(-13) #initial concentration value for all species. endoInit = 10**(-5) #only used if useEndo == True #generate the first layer concentration: if x1val is not None: assert x2val is None X1 = np.array([x1val]) X2 = np.concatenate( (np.logspace(-8, -6, indexSplit), np.logspace(-6, -4, indexSplit))) else: assert x2val is not None X2 = np.array([x2val]) X1 = np.concatenate( (np.logspace(-8, -6, indexSplit), np.logspace(-6, -4, indexSplit))) # generate concentration for all different experiments: x_test = [] for x1 in X1: for x2 in X2: x_test += [[x1, x2]] x_test = np.array(x_test) initialization_dic = {} for layer in range( 0, len(masks)): ## the first layer need not to be initiliazed for node in range(masks[layer].shape[0]): initialization_dic["X_" + str(layer + 1) + "_" + str(node)] = layerInit inhibTemplateNames = obtainTemplateArray(masks=masks, activ=False) for k in inhibTemplateNames: initialization_dic[k] = inhibInit activTemplateNames = obtainTemplateArray(masks=masks, activ=True) for k in activTemplateNames: initialization_dic[k] = activInit initialization_dic["E"] = enzymeInit if complexity != "simple": initialization_dic["E2"] = enzymeInit if complexity != None and useEndo: initialization_dic["Endo"] = endoInit if useDerivativeLeak: results = executeODESimulation(f, name, x_test, initialization_dic, outputList=outputList, leak=leak, endTime=endTime, sparse=False, modes=modes, timeStep=timeStep, initValue=initValue) else: results = executeODESimulation(f, name, x_test, initialization_dic, outputList=outputList, leak=0, endTime=endTime, sparse=False, modes=modes, timeStep=timeStep, initValue=initValue) if ("outputEqui" in modes): experiment_path = name C0 = readAttribute(experiment_path, ["C0"])["C0"] rescaleFactor = readAttribute(experiment_path, ["rescaleFactor"])["rescaleFactor"] output = results[modes.index("outputEqui")] output = np.reshape(output, (len(X1), len(X2))) X1 = X1 / (C0 * rescaleFactor) X2 = X2 / (C0 * rescaleFactor) X1log = np.log(X1) X2log = np.log(X2) experiment_path = nameFig colorDiagram(X1, X2, output, "Initial concentration of X1", "Initial concentration of X2", "Equilibrium concentration of the output", figname=os.path.join(experiment_path, "neuralDiagramm.png"), equiPotential=False) neuronPlot(X1, X2, output, figname=os.path.join(experiment_path, "activationX1.png"), figname2=os.path.join(experiment_path, "activationX2.png"), doShow=False) df = pandas.DataFrame(X1) df.to_csv(os.path.join(experiment_path, "inputX1.csv")) df2 = pandas.DataFrame(X2) df2.to_csv(os.path.join(experiment_path, "inputX2.csv")) if x1val is None: indicatorValue = indicator(X1log, X1, output[:, 0], indexSplit) else: indicatorValue = indicator(X2log, X2, output[0, :], indexSplit, sens=-1, Xactiv=x1val / (C0 * rescaleFactor)) else: raise Exception("outputEqui should be in outputModes") return indicatorValue
df=pandas.read_csv(os.path.join(experiment_path, "neural_equilibrium.csv")) output = df.values[:,1:] df=pandas.read_csv(os.path.join(experiment_path, "neural_X1.csv")) X1 = np.transpose(df.values[:,1:])[0] df=pandas.read_csv(os.path.join(experiment_path, "neural_X2.csv")) X2 = np.transpose(df.values[:,1:])[0] C0 = 8.086075400626399e-07 #separate from bad values X1=X1[:164]/C0 output=output[:164] X2=X2[:164]/C0 colorDiagram(X1,X2,output,"Concentration of X1","Concentration of X2","Equilibrium concentration of the output",figname=os.path.join(experiment_path, "neuralDiagramm2.png"),equiPotential=False) # neuronPlot(X1/(8.086075400626399e-07),X2/(8.086075400626399e-07),output,figname=os.path.join(experiment_path, "activation2.png")) neuronPlot(X1,X2,output,figname=os.path.join(experiment_path, "activationX1.png"),figname2=os.path.join(experiment_path, "activationX2.png")) # Plotting time: colorDiagram(X1,X2,np.exp(output),"Concentration of X1","Concentration of X2","Equilibrium concentration of the output",figname=os.path.join(experiment_path, "neuralDiagramm2log.png"),equiPotential=False) # neuronPlot(X1/(8.086075400626399e-07),X2/(8.086075400626399e-07),output,figname=os.path.join(experiment_path, "activation2.png")) neuronPlot(X1,X2,np.exp(output),figname=os.path.join(experiment_path, "activationX1log.png"),figname2=os.path.join(experiment_path, "activationX2log.png")) ## Let us plot the frontier: coords=[] Xfrontier=[] X2frontier=[] for y in range(output.shape[1]): for x in range(output.shape[0]-1): if(output[x,y]<1 and 2<output[x+1,y]): #we have a discontinuity --> we are on the frontier coords+=[[X1[x],X2[y]]] Xfrontier+=[[X1[x],output[x+1,y]]] X2frontier+=[[X2[y], output[x + 1, y]]] break