|
153 | 153 | }, |
154 | 154 | "outputs": [], |
155 | 155 | "source": [ |
156 | | - "shd_dl = spyx.data.SHD_loader(256,128,128)" |
| 156 | + "shd_dl = spyx.loaders.SHD_loader(256,128,128)" |
157 | 157 | ] |
158 | 158 | }, |
159 | 159 | { |
|
259 | 259 | "\n", |
260 | 260 | " # Haiku has the ability to stack multiple layers/recurrent modules as one entity\n", |
261 | 261 | " core = hk.DeepRNN([\n", |
262 | | - " snn.LIF((64,), activation=spyx.axn.Axon(spyx.axn.triangular())), #LIF neuron layer with triangular activation\n", |
| 262 | + " snn.LIF((64,), activation=spyx.axn.triangular()), #LIF neuron layer with triangular activation\n", |
263 | 263 | " hk.Linear(64, with_bias=False),\n", |
264 | | - " snn.LIF((64,), activation=spyx.axn.Axon(spyx.axn.triangular())),\n", |
| 264 | + " snn.LIF((64,), activation=spyx.axn.triangular()),\n", |
265 | 265 | " hk.Linear(20, with_bias=False),\n", |
266 | 266 | " snn.LI((20,)) # Non-spiking final layer\n", |
267 | 267 | " ])\n", |
|
312 | 312 | " # We use optax for our optimizer.\n", |
313 | 313 | " opt = optax.lion(learning_rate=schedule)\n", |
314 | 314 | "\n", |
| 315 | + " Loss = spyx.fn.integral_crossentropy()\n", |
| 316 | + " Acc = spyx.fn.integral_accuracy()\n", |
| 317 | + "\n", |
315 | 318 | " # create and initialize the optimizer\n", |
316 | 319 | " opt_state = opt.init(params)\n", |
317 | 320 | " grad_params = params\n", |
|
321 | 324 | " def net_eval(weights, events, targets):\n", |
322 | 325 | " readout = SNN.apply(weights, events)\n", |
323 | 326 | " traces, V_f = readout\n", |
324 | | - " return spyx.fn.integral_crossentropy(traces, targets)\n", |
| 327 | + " return Loss(traces, targets)\n", |
325 | 328 | "\n", |
326 | 329 | " # Use JAX to create a function that calculates the loss and the gradient!\n", |
327 | 330 | " surrogate_grad = jax.value_and_grad(net_eval)\n", |
|
357 | 360 | " # unpack the final layer outputs and end state of each SNN layer\n", |
358 | 361 | " traces, V_f = readout\n", |
359 | 362 | " # compute accuracy, predictions, and loss\n", |
360 | | - " acc, pred = spyx.fn.integral_accuracy(traces, targets)\n", |
361 | | - " loss = spyx.fn.integral_crossentropy(traces, targets)\n", |
| 363 | + " acc, pred = Acc(traces, targets)\n", |
| 364 | + " loss = Loss(traces, targets)\n", |
362 | 365 | " # we return the parameters here because of how jax.scan is structured.\n", |
363 | 366 | " return grad_params, jnp.array([acc, loss])\n", |
364 | 367 | "\n", |
|
421 | 424 | "source": [ |
422 | 425 | "def test_gd(SNN, params, dl):\n", |
423 | 426 | "\n", |
| 427 | + " Loss = spyx.fn.integral_crossentropy()\n", |
| 428 | + " Acc = spyx.fn.integral_accuracy()\n", |
| 429 | + "\n", |
424 | 430 | " @jax.jit\n", |
425 | 431 | " def test_step(params, data):\n", |
426 | 432 | " events, targets = data\n", |
427 | 433 | " events = jnp.unpackbits(events, axis=1)\n", |
428 | 434 | " readout = SNN.apply(params, events)\n", |
429 | 435 | " traces, V_f = readout\n", |
430 | | - " acc, pred = spyx.fn.integral_accuracy(traces, targets)\n", |
431 | | - " loss = spyx.fn.integral_crossentropy(traces, targets)\n", |
| 436 | + " acc, pred = Acc(traces, targets)\n", |
| 437 | + " loss = Loss(traces, targets)\n", |
432 | 438 | " return params, [acc, loss, pred, targets]\n", |
433 | 439 | "\n", |
434 | 440 | " test_data = dl.test_epoch()\n", |
|
0 commit comments