def analyse_diffusion_rate_and_density(size, number_of_examples=150): """ Analiza tocke 1 Kakšen vpliv ima na oscilacije gostota populacije celic, hitrost difuzije in velikost prostora? D [10^-2, 10^2] velikost prostora: 10x10 gostota populacije: [0.01, 1] """ x = [] y = [] result = [] example_num = 0 """Vpliv hitrosti difuzije na oscilacije""" for density in np.linspace(start=.1, stop=1, num=number_of_examples): tmp = [] for d in np.linspace(start=.01, stop=1, num=number_of_examples): # .1 1 rep = r.Repressilator_S_PDE() rep.set_params(D1=d, density=density, size=size) # check if model oscillates [osc, freq, period, amplitude, damped] = rep.run() print( "#%d | density: %f, | oscillates: %d, frequency: %f, period: %f, amplitude: %f" % (example_num, density, osc, freq, period, amplitude)) example_num += 1 del rep y.append(d) x.append(density) tmp.append(osc) result.append(tmp) result = np.array(result) print(result) x = np.unique(x) x = list(np.around(x, decimals=2)) print(x) y = np.unique(y) y = list(np.around(y, decimals=2)) print(y) # draw heat map make_heatmap(x, y, result)
def analyse_diffusion_rate(size=10, number_of_examples=150): """ Vpliv hitrosti difuzije na oscilacije pri podani velikosti prostora :return: """ example_num = 0 x_per = [] y_per = [] x_amp = [] y_amp = [] for d in np.linspace(start=.01, stop=.8, num=number_of_examples): rep = r.Repressilator_S_PDE() rep.set_params(D1=d, density=0.4, size=size) [osc, freq, period, amplitude, damped] = rep.run() print( "#%d | d: %f, | oscillates: %d, frequency: %f, period: %f, amplitude: %f" % (example_num, d, osc, freq, period, amplitude)) if osc: # period graph x_per.append(period) y_per.append(d) # amplitude graph x_amp.append(amplitude) y_amp.append(d) example_num += 1 del rep # draw graph plt.subplot(2, 1, 1) plt.title('Vpliv hitrosti difuzije na amplitudo v prostoru %dx%d' % (size, size)) plt.plot(y_amp, x_amp) plt.ylabel('Amplituda') plt.xlabel('Hitrost difuzije') plt.subplot(2, 1, 2) plt.title('Vpliv hitrosti difuzije na periodo v prostoru %dx%d' % (size, size)) plt.plot(y_per, x_per) plt.ylabel('Perioda') plt.xlabel('Hitrost difuzije') plt.show()
def makeHeatmap(numberOfSamples=1): # merjenje casa timeMeasure = time.time() r = rep.Repressilator_S_PDE() results = [] # numberOfSamples --> USED FOR LOGSPACE function # GRAF fig = plt.figure(1) plt.rcParams.update({'font.size': 10}) plt.rcParams.update({'xtick.major.size': 6}) plt.rcParams.update({'ytick.major.size': 6}) params = ["", "alpha", "beta", "delta_m", "kappa"] paramsNumbers = [1, 2, 3, 4] counter = 1 for i in paramsNumbers: for j in xrange(i, 5): r.load_params_range() results = [] ax = plt.subplot(4, 4, counter) # if i == 1: # plt.xlabel('Alfa') # if i == 2: # plt.xlabel('Beta') # if i == 3: # plt.xlabel('Delta_m') # if i == 4: # plt.xlabel('Kappa') # if j == 1: # plt.ylabel('Alfa') # if j == 2: # plt.ylabel('Beta') # if j == 3: # plt.ylabel('Delta_m') # if j == 4: # plt.ylabel('Kappa') for FIRST_PARAM in np.logspace(start=-3, stop=1, num=numberOfSamples, base=10.0): helperArray = [] for SECOND_PARAM in np.logspace(start=-3, stop=1, num=numberOfSamples, base=10.0): print("%s: %f, %s: %f." % (params[i], FIRST_PARAM, params[j], SECOND_PARAM)) if i == 1: r.load_params_range_single(alpha=FIRST_PARAM) # plt.xlabel('Alfa') if i == 2: r.load_params_range_single(beta=FIRST_PARAM) # plt.xlabel('Beta') if i == 3: r.load_params_range_single(delta_m=FIRST_PARAM) # plt.xlabel('Delta_m') if i == 4: r.load_params_range_single(kappa=FIRST_PARAM) # plt.xlabel('Kappa') if j == 1: r.load_params_range_single(alpha=SECOND_PARAM) # plt.ylabel('Alfa') if j == 2: r.load_params_range_single(beta=SECOND_PARAM) # plt.ylabel('Beta') if j == 3: r.load_params_range_single(delta_m=SECOND_PARAM) # plt.ylabel('Delta_m') if j == 4: r.load_params_range_single(kappa=SECOND_PARAM) # plt.ylabel('Kappa') helperArray.append(r.run()[0]) results.append(helperArray) file = open( "results-k-params/44{}-{}.txt".format(counter, numberOfSamples), "w") file.write(str(results)) file.close() im = ax.imshow(results) ax.set_xscale('log') ax.set_yscale('log') # ax.set_title('Alfa in alfa') # plt.xlabel('Alfa') # plt.ylabel('Alfa') counter = counter + 1 counter = counter + i plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, wspace=0.35) plt.show() fig.savefig('results-k-params/final-{}.png'.format(numberOfSamples)) print("Porabljen cas: {} s.".format(time.time() - timeMeasure))
counter = counter + i plt.subplots_adjust(top=0.92, bottom=0.08, left=0.10, right=0.95, hspace=0.25, wspace=0.35) plt.show() fig.savefig('results-k-params/final-{}.png'.format(numberOfSamples)) print("Porabljen cas: {} s.".format(time.time() - timeMeasure)) if __name__ == "__main__": r = rep.Repressilator_S_PDE() results = [] # IMPORTANT: RUN ONLY 1 of following methods! # run makeHeatmap for plot with all subplots # samples = 15 # USED FOR LOGSPACE function # makeHeatmap(samples) # run makePlotFromData with filename to draw only 1 heatmap for specific run # filename = "results-k-params/443-15" #WITHOUT TXT! # samples = 15 # randomSeed = 1 # labelaX = "Alfa" # labelaY = "Delta_m" # makePlotFromData(filename, samples, randomSeed, labelx=labelaX, labely=labelaY)
def analyse_density(size=10, number_of_examples=150): """ Vpliv gostote celic na oscilacije pri podani velikosti prostora :return: """ example_num = 0 x_per = [] y_per = [] x_amp = [] y_amp = [] x_freq = [] y_freq = [] for density in np.linspace(start=.1, stop=1, num=number_of_examples): rep = r.Repressilator_S_PDE() rep.set_params(density=density, size=size) [osc, freq, period, amplitude, damped] = rep.run() print( "#%d | density: %f, | oscillates: %d, frequency: %f, period: %f, amplitude: %f" % (example_num, density, osc, freq, period, amplitude)) if osc: # period graph x_per.append(period) y_per.append(density) # amplitude graph x_amp.append(amplitude) y_amp.append(density) x_freq.append(freq) y_freq.append(density) example_num += 1 del rep plt.subplot(3, 1, 1) plt.title('Vpliv gostote celic na amplitudo v prostoru %dx%d' % (size, size)) # x_smooth = np.linspace(np.array(x_amp).max(), np.array(x_amp).min(), number_of_examples) # y_smooth = spline(x_amp, y_amp, x_smooth) y_smooth = gaussian_filter1d(y_amp, sigma=2) plt.plot(y_smooth, x_amp) plt.ylabel('Amplituda') plt.xlabel('Gostota') plt.subplot(3, 1, 2) plt.title('Vpliv gostote celic na periodo v prostoru %dx%d' % (size, size)) y_smooth = gaussian_filter1d(y_per, sigma=2) plt.plot(y_smooth, x_per) plt.ylabel('Perioda') plt.xlabel('Gostota') plt.subplot(3, 1, 3) plt.title('Vpliv gostote celic na frekvenco v prostoru %dx%d' % (size, size)) y_smooth = gaussian_filter1d(y_freq, sigma=2) plt.plot(y_smooth, x_freq) plt.ylabel('Frekvenca') plt.xlabel('Gostota') plt.show()