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 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 admited by matplotlib.pyplot.subplots() fun. |
None
|
|
fname
|
if not None, save fig or movie to fname |
None
|
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)
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 |
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 admited by matplotlib.pyplot.subplots() fun. |
None
|
|
env
|
environment class for extra information |
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)
Plot environment with 1-D Box observation space.
Source code in neurogym/utils/plotting.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 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 |
|
plot_env_3dbox
¶
Plot environment with 3-D Box observation space.
Source code in neurogym/utils/plotting.py
random
¶
trunc_exp
¶
trunc_exp(rng, vmean, vmin=0, vmax=inf)
Function for generating period durations.
Source code in neurogym/utils/random.py
random_number_fn
¶
Return a random number generating function from a distribution.
Source code in neurogym/utils/random.py
random_number_name
¶
Return a string explaining the dist and args.
Source code in neurogym/utils/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.