MCPcopy Create free account
hub / github.com/BindsNET/bindsnet / TensorboardAnalyzer

Class TensorboardAnalyzer

bindsnet/analysis/pipeline_analysis.py:295–405  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293
294
295class TensorboardAnalyzer(PipelineAnalyzer):
296 def __init__(self, summary_directory: str = "./logs"):
297 # language=rst
298 """
299 Initializes the analyzer.
300
301 :param summary_directory: Directory to save log files.
302 """
303 self.writer = SummaryWriter(summary_directory)
304
305 def finalize_step(self) -> None:
306 # language=rst
307 """
308 No-op for ``TensorboardAnalyzer``.
309 """
310
311 def plot_obs(self, obs: torch.Tensor, tag: str = "obs", step: int = None) -> None:
312 # language=rst
313 """
314 Pulls the observation off of torch and sets up for Matplotlib
315 plotting.
316
317 :param obs: A 2D array of floats depicting an input image.
318 :param tag: A unique tag to associate the data with.
319 :param step: The step of the pipeline.
320 """
321 obs_grid = make_grid(obs.float(), nrow=4, normalize=True)
322 self.writer.add_image(tag, obs_grid, step)
323
324 def plot_reward(
325 self,
326 reward_list: list,
327 reward_window: int = None,
328 tag: str = "reward",
329 step: int = None,
330 ) -> None:
331 # language=rst
332 """
333 Plot the accumulated reward for each episode.
334
335 :param reward_list: The list of recent rewards to be plotted.
336 :param reward_window: The length of the window to compute a moving average over.
337 :param tag: A unique tag to associate the data with.
338 :param step: The step of the pipeline.
339 """
340 self.writer.add_scalar(tag, reward_list[-1], step)
341
342 def plot_spikes(
343 self,
344 spike_record: Dict[str, torch.Tensor],
345 tag: str = "spike",
346 step: int = None,
347 ) -> None:
348 # language=rst
349 """
350 Plots all spike records inside of ``spike_record``. Keeps unique
351 plots for all unique tags that are given.
352

Callers 3

test_initMethod · 0.90
test_plot_runsMethod · 0.90
tensorboard.pyFile · 0.90

Calls

no outgoing calls

Tested by 2

test_initMethod · 0.72
test_plot_runsMethod · 0.72