Skip to content

Commit 1f4b9b0

Browse files
committed
Backup from old computer.
1 parent b6273b9 commit 1f4b9b0

File tree

9 files changed

+85
-76
lines changed

9 files changed

+85
-76
lines changed

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def deep_update(obj: dict, path: str, value: str):
2626
t = type(obj[key])
2727
obj[key] = t(value)
2828

29+
2930
def run_experiment(args):
3031
if args.slow_ode:
3132
pim.math.slow_solver = True

genpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pim.models.new.stone import trials
22
import pickle
33

4-
headings, velocities = trials.generate_route(T = 1500, vary_speed = True)
4+
headings, velocities = trials.generate_route(T=1500, vary_speed=True)
55

66
with open("../fastbee/path.pickle", "wb") as f:
77
pickle.dump((headings.tolist(), velocities.tolist()), f)

lib/pim/experiment.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def save(self, setup: str, timestamp: datetime, results_dir="results"):
3535
pickle.dump(output, f)
3636
logger.info("saved experiment results as {}", filename)
3737

38+
3839
class Experiment:
3940
@abstractmethod
4041
def run(self, name: str, config_id: str) -> ExperimentResults:

lib/pim/models/basic.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,31 @@
44
from ..network import InputLayer, Network, Output, RecurrentForwardNetwork, FunctionLayer, IdentityLayer, Layer
55
from .constants import *
66

7+
78
def cl1_output(inputs):
89
"Invert compass"
910
tl2, = inputs
1011
return tl2 + np.pi
1112

13+
1214
def tb1_output(inputs):
1315
"""Sinusoidal response to solar compass."""
1416
cl1, tb1 = inputs
1517
return (1.0 + np.cos(cl1 - column_angles)) / 2.0
1618

19+
1720
def tn1_output(inputs):
1821
"""Linearly inverse sensitive to forwards and backwards motion."""
1922
flow, = inputs
2023
return np.clip((1.0 - flow) / 2.0, 0, 1)
2124

25+
2226
def tn2_output(inputs):
2327
"""Linearly sensitive to forwards motion only."""
2428
flow, = inputs
2529
return np.clip(flow, 0, 1)
2630

31+
2732
class CPU4Layer(Layer):
2833
def __init__(self, TB1, TN1, TN2, gain):
2934
self.TB1 = TB1
@@ -64,6 +69,7 @@ def internal(self) -> Output:
6469
def output(self, dt: float) -> Output:
6570
return self.memory
6671

72+
6773
def cpu1_output(inputs):
6874
tb1, cpu4 = inputs
6975
"""Offset CPU4 columns by 1 column (45 degrees) left and right
@@ -74,6 +80,7 @@ def cpu1_output(inputs):
7480
np.roll(cpu4_reshaped[0], -1)])
7581
return cpu1.reshape(-1)
7682

83+
7784
def motor_output(inputs):
7885
cpu1, = inputs
7986
random_std=0.05

lib/pim/models/rate.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def output(self, network: Network) -> Output:
8383
mem_update -= np.dot(self.W_TB1, tb1)
8484
return np.clip(noisy_sigmoid(mem_update, self.slope, self.bias, self.noise) * self.gain + beta, 0, 1)
8585

86+
8687
class CPU4Layer(Layer):
8788
def __init__(self, TB1, TN1, TN2, W_TN, W_TB1, gain, slope, bias, noise, holonomic=False):
8889
self.TB1 = TB1
@@ -120,6 +121,7 @@ def output(self, network: Network) -> Output:
120121
return noisy_sigmoid(self.memory, self.slope,
121122
self.bias, self.noise)
122123

124+
123125
class CPU4PontineLayer(CPU4Layer):
124126
def internal(self):
125127
return [self.memory, self.memory]
@@ -148,6 +150,7 @@ def step(self, network: Network, dt: float):
148150
cpu4_mem_reshaped += self.gain * mem_update
149151
self.memory = np.clip(cpu4_mem_reshaped.reshape(-1), 0.0, 1.0)
150152

153+
151154
W_CL1_TB1 = np.tile(np.eye(N_TB1), 2)
152155
W_TB1_TB1 = gen_tb_tb_weights()
153156
W_TB1_CPU1a = np.tile(np.eye(N_TB1), (2, 1))[1:N_CPU1A+1, :]
@@ -206,6 +209,7 @@ def step(self, network: Network, dt: float):
206209
])
207210
W_CPU4_pontine = np.eye(N_CPU4)
208211

212+
209213
def tl2_output(noise):
210214
"""Just a dot product with preferred angle and current heading""" # bad description
211215
def f(inputs):
@@ -214,13 +218,15 @@ def f(inputs):
214218
return noisy_sigmoid(output, tl2_slope_tuned, tl2_bias_tuned, noise)
215219
return f
216220

221+
217222
def cl1_output(noise):
218223
"""Takes input from the TL2 neurons and gives output."""
219224
def f(inputs):
220225
tl2, = inputs
221226
return noisy_sigmoid(-tl2, cl1_slope_tuned, cl1_bias_tuned, noise)
222227
return f
223228

229+
224230
def tb1_output(noise):
225231
"""Ring attractor state on the protocerebral bridge."""
226232
def f(inputs):
@@ -232,6 +238,7 @@ def f(inputs):
232238
return noisy_sigmoid(output, tb1_slope_tuned, tb1_bias_tuned, noise)
233239
return f
234240

241+
235242
def tn1_output(noise):
236243
def f(inputs):
237244
flow, = inputs
@@ -241,6 +248,7 @@ def f(inputs):
241248
return np.clip(output, 0.0, 1.0)
242249
return f
243250

251+
244252
def tn2_output(noise):
245253
def f(inputs):
246254
flow, = inputs
@@ -250,6 +258,7 @@ def f(inputs):
250258
return np.clip(output, 0.0, 1.0)
251259
return f
252260

261+
253262
def cpu1a_output(noise):
254263
def f(inputs):
255264
"""The memory and direction used together to get population code for
@@ -259,6 +268,7 @@ def f(inputs):
259268
return noisy_sigmoid(inputs, cpu1_slope_tuned, cpu1_bias_tuned, noise)
260269
return f
261270

271+
262272
def cpu1b_output(noise):
263273
def f(inputs):
264274
"""The memory and direction used together to get population code for
@@ -276,6 +286,7 @@ def f(inputs):
276286
# return np.hstack([cpu1b[-1], cpu1a, cpu1b[0]])
277287
# return f
278288

289+
279290
def motor_output(noise):
280291
"""outputs a scalar where sign determines left or right turn."""
281292
def f(inputs):
@@ -286,13 +297,15 @@ def f(inputs):
286297
return output
287298
return f
288299

300+
289301
def pontine_output(noise):
290302
def f(inputs):
291303
cpu4, = inputs
292304
inputs = np.dot(W_CPU4_pontine, cpu4)
293305
return noisy_sigmoid(inputs, pontine_slope_tuned, pontine_bias_tuned, noise)
294306
return f
295307

308+
296309
def cpu1a_pontine_output(noise):
297310
def f(inputs):
298311
"""The memory and direction used together to get population code for
@@ -307,6 +320,7 @@ def f(inputs):
307320
return noisy_sigmoid(inputs, cpu1_pontine_slope_tuned, cpu1_pontine_bias_tuned, noise)
308321
return f
309322

323+
310324
def cpu1b_pontine_output(noise):
311325
def f(inputs):
312326
"""The memory and direction used together to get population code for
@@ -322,7 +336,6 @@ def f(inputs):
322336
return f
323337

324338

325-
326339
def build_network(params, CPU4LayerClass = CPU4Layer) -> Network:
327340
noise = params.get("noise",0.1)
328341
cpu4_mem_gain = params.get("cpu4_mem_gain",0.005)
@@ -381,6 +394,7 @@ def build_network(params, CPU4LayerClass = CPU4Layer) -> Network:
381394
)
382395
})
383396

397+
384398
def build_network_pontine(params) -> Network:
385399
# TODO: allow noisy weights
386400
noise = params.get("noise",0.1)

lib/pim/network/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, layers: Dict[str, "Layer"]):
1313
some network types (such as the forward network) relies on the order of this dictionary,
1414
which is a reliable property of dictionaries since Python 3.7."""
1515
self.layers = layers
16-
self.context = None # type: Any
16+
self.context = None # type: Any
1717

1818
def reset(self):
1919
for name, layer in self.layers.items():
@@ -82,6 +82,7 @@ def postprocess_layers(self):
8282
def output(self, layer) -> Output:
8383
return self._previous_outputs[layer]
8484

85+
8586
class RecurrentForwardNetwork(Network):
8687
"""Forward network that allows backward connections."""
8788

@@ -144,7 +145,7 @@ def resolve(self, network: Network):
144145

145146

146147
class Layer:
147-
def __init__(self, initial = np.array([0.0])):
148+
def __init__(self, initial=np.array([0.0])):
148149
self.initial = initial
149150
self.reset()
150151

@@ -198,7 +199,7 @@ def IdentityLayer(input):
198199

199200

200201
class InputLayer(Layer):
201-
def __init__(self, initial = np.array([0.0])):
202+
def __init__(self, initial=np.array([0.0])):
202203
super().__init__(initial)
203204
self.input = Trap()
204205

0 commit comments

Comments
 (0)