]> git.armaanb.net Git - norepinephrine_wm.git/blob - norepinephrine_wm/newmodel.py
Update newmodel.py to python3
[norepinephrine_wm.git] / norepinephrine_wm / newmodel.py
1 import numpy as np
2 import matplotlib.pyplot as plt
3 from os import mkdir
4
5 # Refer to parameters.txt for documentation
6 dt = 0.001
7 t_cue = 1.0
8 cue_scale = 1.0
9 perceived = 0 # ???
10 time_scale = 0.4
11 steps = 100
12
13 class Alpha(object):
14     def __init__(self):
15         self.x = np.logspace(0, 3, steps)
16         self.y = 1 / (1 + (999 * np.exp(-0.1233 * (self.x / self.offset))))
17         
18         self.gain = []
19         self.bias = []
20         
21     def calcgb(self, gaind, biasd):
22         for i in range(steps):
23             y = self.y[i]
24             self.gain.append(1 + gaind * y)
25             self.bias.append(1 + biasd * y)
26
27     def plot(self):
28         try:
29             mkdir("./out")
30         except FileExistsError:
31             pass
32
33         out = f"./out/{self.__class__.__name__}"
34         plt.plot(self.x, self.y)
35
36         plt.xlabel("Norepinephrine concentration (nM)")
37         plt.ylabel("Activity (%)")
38         plt.title("Norepinepherine Concentration vs Neuron Activity in " +
39             self.pretty)
40
41         plt.vlines(self.ki, 0, 1, linestyles="dashed")
42         plt.text(1.1 * self.ki, 0.1, "Affinity")
43
44         plt.hlines(0.5, 0, 1000, linestyles="dashed")
45         plt.text(1, 0.51, "50%")
46
47         plt.xscale("log")
48         gc = plt.gca()
49         gc.set_yticklabels(['{:.0f}%'.format(x * 100) for x in gc.get_yticks()])
50
51         plt.draw()
52         plt.savefig(f"{out}-norep-activity.png", dpi=1000)
53         
54         #######################################################################
55         
56         plt.plot(self.x, self.gain)
57         
58         plt.xlabel("Norepinephrine concentration (nM)")
59         plt.ylabel("Gain")
60         plt.title(f"Concentration vs Gain in {self.pretty}")
61
62         plt.draw()
63         plt.savefig(f"{out}-concentration-gain.png", dpi=1000)
64         
65         #######################################################################
66         
67         plt.plot(self.x, self.bias)
68         
69         plt.xlabel("Norepinephrine concentration (nM)")
70         plt.ylabel("Bias")
71         plt.title("Concentration vs Bias in " + self.pretty)
72         
73         plt.draw()
74         plt.savefig(f"{out}-concentration-bias.png", dpi=1000)
75
76 class Alpha1(Alpha):
77     def __init__(self):
78         self.ki = 330
79         self.offset = 5.895
80         self.pretty = "α1 Receptor"
81         self.gaind = 0.1
82         self.biasd = 0.1
83         super().__init__()
84         
85     def calcgb(self):
86         super().calcgb(self.gaind, self.biasd)
87
88 class Alpha2(Alpha):
89     def __init__(self):
90         self.ki = 56
91         self.offset = 1
92         self.pretty = "α2 Receptor"
93         self.gaind = -0.04
94         self.biasd = -0.02
95         super().__init__()
96         
97     def calcgb(self):
98         super().calcgb(self.gaind, self.biasd)
99
100 def main():
101     plt.style.use("ggplot")
102     
103     a1 = Alpha1()
104     a1.calcgb()
105     a1.plot()
106
107     a2 = Alpha2()
108     a2.calcgb()
109     a2.plot()
110
111 if __name__ == "__main__":
112     main()