Utils
data
¶
Utilities for data.
Dataset
¶
Dataset(env, env_kwargs=None, batch_size=1, seq_len=None, max_batch=inf, batch_first=False, cache_len=None)
Make an environment into an iterable dataset for supervised learning.
Create an iterator that at each call returns inputs: numpy array (sequence_length, batch_size, input_units) target: numpy array (sequence_length, batch_size, output_units)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env
|
str for env id or gym.Env objects |
required | |
env_kwargs
|
dict, additional kwargs for environment, if env is str |
None
|
|
batch_size
|
int, batch size |
1
|
|
seq_len
|
int, sequence length |
None
|
|
max_batch
|
int, maximum number of batch for iterator, default infinite |
inf
|
|
batch_first
|
bool, if True, return (batch, seq_len, n_units), default False |
False
|
|
cache_len
|
int, default length of caching |
None
|
Source code in neurogym/utils/data.py
info
¶
Formatting information about envs and wrappers.
info
¶
Script to get envs info.
Source code in neurogym/utils/info.py
info_wrapper
¶
Script to get wrappers info.
Source code in neurogym/utils/info.py
all_tags
¶
Script to get all tags.
Source code in neurogym/utils/info.py
plotting
¶
Plotting functions.
plot_env
¶
plot_env(env, num_steps=200, num_trials=None, def_act=None, model=None, name=None, legend=True, ob_traces=None, fig_kwargs=None, fname=None, plot_performance=True)
Plot environment with agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
env
|
already built neurogym task or name of it |
required | |
num_steps
|
number of steps to run the task |
200
|
|
num_trials
|
if not None, the number of trials to run |
None
|
|
def_act
|
if not None (and model=None), the task will be run with the specified action |
None
|
|
model
|
if not None, the task will be run with the actions predicted by model, which so far is assumed to be created and trained with the stable-baselines3 toolbox: (https://stable-baselines3.readthedocs.io/en/master/) |
None
|
|
name
|
title to show on the rewards panel |
None
|
|
legend
|
whether to show the legend for actions panel or not |
True
|
|
ob_traces
|
if != [] observations will be plot as traces, with the labels specified by ob_traces |
None
|
|
fig_kwargs
|
figure properties admitted by matplotlib.pyplot.subplots() function |
None
|
|
fname
|
if not None, save fig or movie to fname |
None
|
|
plot_performance
|
whether to show the performance subplot (default: True) |
True
|
Source code in neurogym/utils/plotting.py
fig_
¶
fig_(ob, actions, gt=None, rewards=None, performance=None, states=None, legend=True, ob_traces=None, name='', fname=None, fig_kwargs=None, env=None, trial_starts=None)
Visualize a run in a simple environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ob
|
np array of observation (n_step, n_unit) |
required | |
actions
|
np array of action (n_step, n_unit) |
required | |
gt
|
np array of groud truth |
None
|
|
rewards
|
np array of rewards |
None
|
|
performance
|
np array of performance (if set to |
None
|
|
states
|
np array of network states |
None
|
|
name
|
title to show on the rewards panel and name to save figure |
''
|
|
fname
|
if != '', where to save the figure |
None
|
|
legend
|
whether to show the legend for actions panel or not |
True
|
|
ob_traces
|
None or list. If list, observations will be plot as traces, with the labels specified by ob_traces |
None
|
|
fig_kwargs
|
figure properties admitted by matplotlib.pyplot.subplots() function |
None
|
|
env
|
environment class for extra information |
None
|
|
trial_starts
|
list of trial start indices, 1-based |
None
|
Source code in neurogym/utils/plotting.py
plot_env_1dbox
¶
plot_env_1dbox(ob, actions, gt=None, rewards=None, performance=None, states=None, legend=True, ob_traces=None, name='', fname=None, fig_kwargs=None, env=None, trial_starts=None)
Plot environment with 1-D Box observation space.
Source code in neurogym/utils/plotting.py
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
|
plot_env_3dbox
¶
Plot environment with 3-D Box observation space.
Source code in neurogym/utils/plotting.py
ngym_random
¶
trunc_exp
¶
trunc_exp(rng, vmean, vmin=0, vmax=inf)
Function for generating period durations.
Source code in neurogym/utils/ngym_random.py
random_number_fn
¶
Return a random number generating function from a distribution.
Source code in neurogym/utils/ngym_random.py
random_number_name
¶
Return a string explaining the dist and args.
Source code in neurogym/utils/ngym_random.py
scheduler
¶
Trial scheduler class.
BaseSchedule
¶
Base schedule.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
int, number of conditions to schedule |
required |
Source code in neurogym/utils/scheduler.py
SequentialSchedule
¶
RandomSchedule
¶
SequentialBlockSchedule
¶
RandomBlockSchedule
¶
spaces
¶
Box
¶
Bases: Box
Thin wrapper of gymnasium.spaces.Box.
Allow the user to give names to each dimension of the Box.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
low,
|
(high, kwargs)
|
see gymnasium.spaces.Box |
required |
name
|
dict describing the name of different dimensions |
None
|
Example usage
observation_space = Box(low=0, high=1, name={'fixation': 0, 'stimulus': [1, 2]})
Source code in neurogym/utils/spaces.py
Discrete
¶
Bases: Discrete
Thin wrapper of gymnasium.spaces.Discrete.
Allow the user to give names to each dimension of the Discrete space.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
low,
|
(high, kwargs)
|
see gymnasium.spaces.Box |
required |
name
|
dict describing the name of different dimensions |
None
|
Example usage
observation_space = Discrete(n=3, name={'fixation': 0, 'stimulus': [1, 2]})
Source code in neurogym/utils/spaces.py
tasktools
¶
to_map
¶
get_idx
¶
get_periods_idx
¶
Function for defining task periods.
minmax_number
¶
Given input to the random_number_fn function, return min and max.