2016:groups:g4:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
2016:groups:g4:start [2015/12/24 20:42] – [Introduction] medeiros | 2016:groups:g4:start [2024/01/09 18:45] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
- | Wiki site of the practical exercise of the [[http:// | + | Wiki site of the practical exercise of the [[http:// |
Here you will find the exercise assignment and the group' | Here you will find the exercise assignment and the group' | ||
Line 9: | Line 9: | ||
If you are a group member login to edit this page, create new pages from it, and upload files. | If you are a group member login to edit this page, create new pages from it, and upload files. | ||
- | ==== Introduction ==== | + | ===== Introduction |
- | Mimicry is an adaption | + | Mimicry is an adaptation |
- | {{: | + | {{: |
- | Ce n'est pas une fleur | + | ((Ce n'est pas une fleur)) |
===== Assignment ===== | ===== Assignment ===== | ||
- | Orchid | + | Propose a mathematical model that portrays the dynamics of the system composed by the orchid |
===== Proposed Questions ===== | ===== Proposed Questions ===== | ||
- | *How interaction intimacy affects population | + | *O' |
- | *Theory predicts that mimics | + | *The authors make no conclusions about which plant species is being mimicked. How would the dynamics of this system change if there were more than one plant species serving as model? |
+ | *Is it possible for orchid mantis to maintain higher population densities than their flower | ||
+ | |||
+ | ===== Proposed Model ===== | ||
+ | |||
+ | Our model is in this {{: | ||
+ | |||
+ | ===== For Testing the Model ===== | ||
+ | |||
+ | If you are in windows download you can just download unzip and run this file: | ||
+ | | ||
+ | |||
+ | For testing our model during the presentation you can copy and paste this python source code and run it for an interactive model simulator. | ||
+ | If it doesn' | ||
+ | |||
+ | If you already have python: | ||
+ | |||
+ | *Run in a console (this will download the packages needed and automatically install them): | ||
+ | <code bash> | ||
+ | pip install PyQt4 pyqtgraph | ||
+ | </ | ||
+ | |||
+ | Otherwise follow the instructions on the tutorials to install python. And then you should be able to run the line above. If the line above doesn' | ||
+ | |||
+ | To install pip (python package manager): | ||
+ | *In Ubuntu/ | ||
+ | <code bash> | ||
+ | sudo apt-get install python-pip | ||
+ | </ | ||
+ | *In another operating system you should find how to install pip and then follow the instructions above. | ||
+ | |||
+ | <file python model.py> | ||
+ | |||
+ | # | ||
+ | |||
+ | from scipy.integrate import odeint | ||
+ | import numpy as np | ||
+ | from PyQt4.QtCore import * | ||
+ | from PyQt4.QtGui import * | ||
+ | from pyqtgraph.widgets.PlotWidget import PlotWidget | ||
+ | from pyqtgraph.graphicsItems.InfiniteLine import InfiniteLine | ||
+ | from pyqtgraph.graphicsItems.ScatterPlotItem import ScatterPlotItem | ||
+ | from pyqtgraph import mkPen, mkBrush, setConfigOption | ||
+ | from pyqtgraph.parametertree import ParameterTree, | ||
+ | import pyqtgraph as pg | ||
+ | from pylab import plot, show, xlabel, ylabel, quiver | ||
+ | |||
+ | t_init, t_step, t_end = 0, 0.1, 10000 | ||
+ | t = t_init | ||
+ | t_values = np.arange(t_init, | ||
+ | |||
+ | |||
+ | class MyWidget(QWidget): | ||
+ | def __init__(self): | ||
+ | super(MyWidget, | ||
+ | self.parameter_tree = ParameterTree() | ||
+ | self.parameter_tree.setMaximumWidth(300) | ||
+ | |||
+ | self.k1, self.k2, self.k3, self.k4 = 0.4, 0.6, 0.1, 0.005 | ||
+ | |||
+ | self.alpha, self.beta = 0.01, 0.1 | ||
+ | self.Kf, self.Kp = 0, 0 | ||
+ | self.d1, self.d2, self.d3 = 0.3, 0.2, 0.044 | ||
+ | |||
+ | self.F, self.P, self.M = 100, 50, 2 | ||
+ | |||
+ | self.parameter = Parameter(name=' | ||
+ | | ||
+ | { ' | ||
+ | [{ ' | ||
+ | { ' | ||
+ | { ' | ||
+ | { ' | ||
+ | [{ ' | ||
+ | { ' | ||
+ | { ' | ||
+ | { ' | ||
+ | { ' | ||
+ | [{ ' | ||
+ | { ' | ||
+ | { ' | ||
+ | { ' | ||
+ | [{ ' | ||
+ | { ' | ||
+ | { ' | ||
+ | { ' | ||
+ | ] }] | ||
+ | ) | ||
+ | self.parameter_tree.setParameters(self.parameter) | ||
+ | self.plot_widget = PlotWidget() | ||
+ | self.plt = self.plot_widget.getPlotItem() | ||
+ | |||
+ | l = self.plt.addLegend(size=(100, | ||
+ | self.plt.showGrid(True, | ||
+ | |||
+ | res = self.solve() | ||
+ | self.f_plt = self.plt.plot(t_values, | ||
+ | self.f_plt.setPen(mkPen('# | ||
+ | self.p_plt = self.plt.plot(t_values, | ||
+ | self.p_plt.setPen(mkPen('# | ||
+ | self.m_plt = self.plt.plot(t_values, | ||
+ | self.m_plt.setPen(mkPen('# | ||
+ | print(' | ||
+ | |||
+ | self.fp_plt = PlotWidget() | ||
+ | fp_plt = self.fp_plt.getPlotItem() | ||
+ | fp_plt.showGrid(True, | ||
+ | l = fp_plt.addLegend(size=(100, | ||
+ | |||
+ | self.fp_f_plt = fp_plt.plot([], | ||
+ | self.fp_f_plt.setPen(mkPen('# | ||
+ | self.fp_p_plt = fp_plt.plot([], | ||
+ | self.fp_p_plt.setPen(mkPen('# | ||
+ | self.fp_m_plt = fp_plt.plot([], | ||
+ | self.fp_m_plt.setPen(mkPen('# | ||
+ | |||
+ | wid = QWidget() | ||
+ | l2 = QVBoxLayout() | ||
+ | self.min_value = QDoubleSpinBox() | ||
+ | self.max_value = QDoubleSpinBox() | ||
+ | self.parameter_name = QLineEdit(' | ||
+ | run_button = QPushButton(' | ||
+ | l3 = QHBoxLayout() | ||
+ | l3.addWidget(QLabel(' | ||
+ | l3.addWidget(self.parameter_name) | ||
+ | l3.addWidget(QLabel(' | ||
+ | l3.addWidget(self.min_value) | ||
+ | l3.addWidget(QLabel(' | ||
+ | l3.addWidget(self.max_value) | ||
+ | l3.addWidget(run_button) | ||
+ | l2.addLayout(l3) | ||
+ | l2.addWidget(self.fp_plt) | ||
+ | wid.setLayout(l2) | ||
+ | |||
+ | self.fpa_plt = PlotWidget() | ||
+ | fpa_plt = self.fpa_plt.getPlotItem() | ||
+ | fpa_plt.showGrid(True, | ||
+ | yaxis = fpa_plt.getAxis(' | ||
+ | yaxis.setTicks([[(1, | ||
+ | line1 = InfiniteLine(QPointF(0, | ||
+ | line2 = InfiniteLine(QPointF(0, | ||
+ | line3 = InfiniteLine(QPointF(0, | ||
+ | line4 = InfiniteLine(QPointF(0, | ||
+ | fpa_plt.addItem(line1) | ||
+ | fpa_plt.addItem(line2) | ||
+ | fpa_plt.addItem(line3) | ||
+ | fpa_plt.addItem(line4) | ||
+ | self.sc1 = ScatterPlotItem(antialias=True, | ||
+ | self.sc2 = ScatterPlotItem(antialias=True, | ||
+ | self.index = 0 | ||
+ | fpa_plt.addItem(self.sc1) | ||
+ | fpa_plt.addItem(self.sc2) | ||
+ | wid2 = QWidget() | ||
+ | l4 = QVBoxLayout() | ||
+ | l5 = QHBoxLayout() | ||
+ | self.min_fxa = QDoubleSpinBox() | ||
+ | self.max_fxa = QDoubleSpinBox() | ||
+ | self.param_fxa = QLineEdit(' | ||
+ | run_button_2 = QPushButton(' | ||
+ | l5.addWidget(QLabel(' | ||
+ | l5.addWidget(self.param_fxa) | ||
+ | l5.addWidget(QLabel(' | ||
+ | l5.addWidget(self.min_fxa) | ||
+ | l5.addWidget(QLabel(' | ||
+ | l5.addWidget(self.max_fxa) | ||
+ | l5.addWidget(run_button_2) | ||
+ | l4.addLayout(l5) | ||
+ | l4.addWidget(self.fpa_plt) | ||
+ | wid2.setLayout(l4) | ||
+ | |||
+ | lay = QHBoxLayout() | ||
+ | self.tab = QTabWidget() | ||
+ | |||
+ | l6 = QVBoxLayout() | ||
+ | l6.addWidget(self.parameter_tree) | ||
+ | phase_button = QPushButton(' | ||
+ | l6.addWidget(phase_button) | ||
+ | lay.addLayout(l6) | ||
+ | lay.addWidget(self.tab) | ||
+ | self.tab.addTab(self.plot_widget, | ||
+ | self.tab.addTab(wid, | ||
+ | self.tab.addTab(wid2, | ||
+ | |||
+ | self.setLayout(lay) | ||
+ | self.parameter.sigTreeStateChanged.connect(self.upd) | ||
+ | self.update_fp() | ||
+ | |||
+ | run_button.clicked.connect(self.run_a_lot) | ||
+ | run_button_2.clicked.connect(self.run_a_lot_of_points) | ||
+ | phase_button.clicked.connect(self.plot_phase) | ||
+ | |||
+ | def run_a_lot(self): | ||
+ | interval = self.min_value.value(), | ||
+ | values = np.linspace(interval[0], | ||
+ | parameter_name = self.parameter_name.text() | ||
+ | old_val = eval(str(' | ||
+ | f, p, m = [], [], [] | ||
+ | self.fp_plt.getPlotItem().setLabels(bottom=str(parameter_name), | ||
+ | for i in values: | ||
+ | exec (str(' | ||
+ | res = self.solve() | ||
+ | f.append(res[0][-1]) | ||
+ | p.append(res[1][-1]) | ||
+ | m.append(res[2][-1]) | ||
+ | l = len(f) | ||
+ | print(' | ||
+ | |||
+ | self.fp_f_plt.setData(values, | ||
+ | self.fp_p_plt.setData(values, | ||
+ | self.fp_m_plt.setData(values, | ||
+ | self.fp_plt.update() | ||
+ | exec (str(' | ||
+ | |||
+ | def run_a_lot_of_points(self): | ||
+ | interval = self.min_fxa.value(), | ||
+ | values = np.linspace(interval[0], | ||
+ | parameter_name = self.param_fxa.text() | ||
+ | old_val = eval(str(' | ||
+ | s1x, s1y, s2x, s2y = [], [], [], [] | ||
+ | self.sc1.clear() | ||
+ | self.sc2.clear() | ||
+ | self.index = 0 | ||
+ | |||
+ | for i in values: | ||
+ | exec (str(' | ||
+ | self.update_fp() | ||
+ | res = self.solve() | ||
+ | |||
+ | print(' | ||
+ | |||
+ | f, p, m = res[0][-1], res[1][-1], res[2][-1] | ||
+ | eps = 5 | ||
+ | if np.abs(f - self.fp0[0]) < eps and np.abs(p - self.fp0[1]) < eps and np.abs(m - self.fp0[2]) < eps: | ||
+ | val = 1 | ||
+ | elif np.abs(f - self.fp1[0]) < eps and np.abs(p - self.fp1[1]) < eps and np.abs(m - self.fp1[2]) < eps: | ||
+ | val = 2 | ||
+ | elif np.abs(f - self.fp2[0]) < eps and np.abs(p - self.fp2[1]) < eps and np.abs(m - self.fp2[2]) < eps: | ||
+ | val = 3 | ||
+ | elif np.abs(f - self.fp3[0]) < eps and np.abs(p - self.fp3[1]) < eps and np.abs(m - self.fp3[2]) < eps: | ||
+ | val = 4 | ||
+ | else: | ||
+ | val = 5 | ||
+ | if ((self.k4 / self.d3) - (self.k1 / self.d1)) < self.beta \ | ||
+ | and (self.k4 / self.d3) > self.beta \ | ||
+ | and (self.alpha * self.k1 * self.d2) / (self.d1 * self.k2) \ | ||
+ | < ((self.k4 / self.d3) - self.beta) * \ | ||
+ | (self.beta + (self.k1 / self.d1) - (self.k4 / self.d3)): | ||
+ | s2x.append(self.index) | ||
+ | s2y.append(val) | ||
+ | else: | ||
+ | s1x.append(self.index) | ||
+ | s1y.append(val) | ||
+ | show = (4 * self.alpha * self.d1 * self.d2) / (self.k1 * self.k2) | ||
+ | self.fpa_plt.setXRange(0, | ||
+ | self.index += 1 | ||
+ | |||
+ | self.sc1.setData(s1x, | ||
+ | self.sc2.setData(s2x, | ||
+ | |||
+ | def upd(self, *args): | ||
+ | exec (' | ||
+ | self.update_fp() | ||
+ | res = self.solve() | ||
+ | print(' | ||
+ | |||
+ | if self.tab.currentIndex() == 0: | ||
+ | self.f_plt.setData(t_values, | ||
+ | self.p_plt.setData(t_values, | ||
+ | self.m_plt.setData(t_values, | ||
+ | self.plot_widget.update() | ||
+ | |||
+ | def update_fp(self): | ||
+ | P0 = F0 = M0 = 0 | ||
+ | |||
+ | P1 = self.d3 / (self.k4 - self.d3 * self.beta) | ||
+ | F1 = (self.k1 * P1 - self.d1) / (self.alpha * P1 * self.d1) | ||
+ | M1 = ((self.k2 * F1) / (1 + self.alpha * P1 * F1) - self.d2) * ((1 + self.beta * P1) / self.k3) | ||
+ | |||
+ | M2 = 0 | ||
+ | P2 = (self.k1 * self.k2 | ||
+ | - np.sqrt(self.k1 * self.k2 * (-4 * self.alpha * self.d1 * self.d2 + self.k1 * self.k2))) \ | ||
+ | / (2 * self.alpha * self.d2 * self.k1) | ||
+ | F2 = (self.k1 * self.k2 | ||
+ | - np.sqrt(self.k1 * self.k2 * (-4 * self.alpha * self.d1 * self.d2 + self.k1 * self.k2))) \ | ||
+ | / (2 * self.alpha * self.d1 * self.k2) | ||
+ | M3 = 0 | ||
+ | P3 = (self.k1 * self.k2 | ||
+ | + np.sqrt(self.k1 * self.k2 * (-4 * self.alpha * self.d1 * self.d2 + self.k1 * self.k2))) \ | ||
+ | / (2 * self.alpha * self.d2 * self.k1) | ||
+ | F3 = (self.k1 * self.k2 | ||
+ | + np.sqrt(self.k1 * self.k2 * (-4 * self.alpha * self.d1 * self.d2 + self.k1 * self.k2))) \ | ||
+ | / (2 * self.alpha * self.d1 * self.k2) | ||
+ | self.fp0, self.fp1, self.fp2, self.fp3 = (F0, P0, M0), (F1, P1, M1), (F2, P2, M2), (F3, P3, M3) | ||
+ | print(' | ||
+ | .format(F0, P0, M0)) | ||
+ | print(' | ||
+ | .format(F1, P1, M1)) | ||
+ | print(' | ||
+ | .format(F2, P2, M2)) | ||
+ | print(' | ||
+ | .format(F3, P3, M3)) | ||
+ | print() | ||
+ | |||
+ | def solve(self): | ||
+ | res = odeint(self.func(), | ||
+ | return res | ||
+ | |||
+ | def func(self): | ||
+ | flower = lambda t, f, p, m:(self.k1 * p * f) / (1 + self.alpha * f * p) \ | ||
+ | - self.d1 * f \ | ||
+ | - self.Kf * f * f | ||
+ | |||
+ | polli = lambda t, f, p, m:(self.k2 * p * f) / (1 + self.alpha * f * p) \ | ||
+ | - (self.k3 * m * p) / (1 + self.beta * p) \ | ||
+ | - self.d2 * p \ | ||
+ | - self.Kp * p * p | ||
+ | |||
+ | mantis = lambda t, f, p, m:((self.k4 * m * p)) / (1 + self.beta * p) \ | ||
+ | - self.d3 * m | ||
+ | |||
+ | return lambda y, t: | ||
+ | |||
+ | def plot_phase(self): | ||
+ | # Equations without the mantis (simpler model for the phase space) | ||
+ | flower = lambda t, f, p:(self.k1 * p * f) / (1 + self.alpha * f * p) \ | ||
+ | - self.d1 * f | ||
+ | |||
+ | polli = lambda t, f, p:(self.k2 * p * f) / (1 + self.alpha * f * p) \ | ||
+ | - self.d2 * p | ||
+ | |||
+ | f = lambda y, t: | ||
+ | |||
+ | # res = odeint(f, (self.F, self.P), t_values).T | ||
+ | # plot(res[0], | ||
+ | res = odeint(f, (20, 20), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (150, 20), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (150, 350), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (200, 20), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (150, 20), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (150, 0), t_values).T | ||
+ | plot(res[0], | ||
+ | |||
+ | xlabel(' | ||
+ | ylabel(' | ||
+ | res = odeint(f, (0, 50), t_values).T | ||
+ | plot(res[0], | ||
+ | R, C = np.meshgrid(np.arange(-30, | ||
+ | dy = f(np.array([R, | ||
+ | plot([self.fp0[0]], | ||
+ | plot([self.fp2[0]], | ||
+ | plot([self.fp3[0]], | ||
+ | quiver(R, C, dy[0, :], dy[1, :], scale_units=' | ||
+ | show() | ||
+ | |||
+ | xlabel(' | ||
+ | ylabel(' | ||
+ | res = odeint(f, (0.5, 0.3), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (0.3, 0.8), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (.1, 1), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (0.3, 0.7), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (0.2, 0.75), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (0.2, 0.7), t_values).T | ||
+ | plot(res[0], | ||
+ | res = odeint(f, (0.334170, 0.75188), t_values).T | ||
+ | plot(res[0], | ||
+ | |||
+ | plot([self.fp0[0]], | ||
+ | plot([self.fp2[0]], | ||
+ | R, C = np.meshgrid(np.arange(-1, | ||
+ | dy = f(np.array([R, | ||
+ | quiver(R, C, dy[0, :], dy[1, :], scale_units=' | ||
+ | show() | ||
+ | |||
+ | |||
+ | app = QApplication([]) | ||
+ | |||
+ | wid = MyWidget() | ||
+ | wid.show() | ||
+ | |||
+ | app.exec_() | ||
+ | |||
+ | |||
+ | </ | ||
===== References ===== | ===== References ===== |
2016/groups/g4/start.1450989769.txt.gz · Last modified: 2024/01/09 18:45 (external edit)