Layers
Various neural network layer types
Apply
¶
Bases: Module
A torch module for applying an arithmetic operator on an input tensor
Source code in evotorch/neuroevolution/net/layers.py
__init__(operator, argument)
¶
__init__(...)
: Initialize the Apply module.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
operator
|
str
|
Must be '+', '-', '', '/', or '*'. Indicates which operation will be done on the input tensor. |
required |
argument
|
float
|
Expected as a float, represents the right-argument of the operation (the left-argument being the input tensor). |
required |
Source code in evotorch/neuroevolution/net/layers.py
Bin
¶
Bases: Module
A small torch module for binning the values of tensors.
In more details, considering a lower bound value lb, an upper bound value ub, and an input tensor x, each value within x closer to lb will be converted to lb and each value within x closer to ub will be converted to ub.
Source code in evotorch/neuroevolution/net/layers.py
__init__(lb, ub)
¶
__init__(...)
: Initialize the Clip operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lb
|
float
|
Lower bound |
required |
ub
|
float
|
Upper bound |
required |
Source code in evotorch/neuroevolution/net/layers.py
Clip
¶
Bases: Module
A small torch module for clipping the values of tensors
Source code in evotorch/neuroevolution/net/layers.py
__init__(lb, ub)
¶
__init__(...)
: Initialize the Clip operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lb
|
float
|
Lower bound. Values less than this will be clipped. |
required |
ub
|
float
|
Upper bound. Values greater than this will be clipped. |
required |
Source code in evotorch/neuroevolution/net/layers.py
FeedForwardNet
¶
Bases: Module
Representation of a feed forward neural network as a torch Module.
An example initialization of a FeedForwardNet is as follows:
net = drt.FeedForwardNet(4, [(8, 'tanh'), (6, 'tanh')])
which means that we would like to have a network which expects an input vector of length 4 and passes its input through 2 tanh-activated hidden layers (with neurons count 8 and 6, respectively). The output of the last hidden layer (of length 6) is the final output vector.
The string representation of the module obtained via the example above is:
FeedForwardNet(
(layer_0): Linear(in_features=4, out_features=8, bias=True)
(actfunc_0): Tanh()
(layer_1): Linear(in_features=8, out_features=6, bias=True)
(actfunc_1): Tanh()
)
Source code in evotorch/neuroevolution/net/layers.py
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 |
|
__init__(input_size, layers)
¶
__init__(...)
: Initialize the FeedForward network.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_size
|
int
|
Input size of the network, expected as an int. |
required |
layers
|
List[Union[LengthActTuple, LengthActBiasTuple]]
|
Expected as a list of tuples,
where each tuple is either of the form
|
required |
Source code in evotorch/neuroevolution/net/layers.py
LocomotorNet
¶
Bases: Module
This is a control network which consists of two components: one linear, and one non-linear. The non-linear component is an input-independent set of sinusoidals waves whose amplitudes, frequencies and phases are trainable. Upon execution of a forward pass, the output of the non-linear component is the sum of all these sinusoidal waves. The linear component is a linear layer (optionally with bias) whose weights (and biases) are trainable. The final output of the LocomotorNet at the end of a forward pass is the sum of the linear and the non-linear components.
Note that this is a stateful network, where the only state
is the timestep t, which starts from 0 and gets incremented by 1
at the end of each forward pass. The reset()
method resets
t back to 0.
Reference
Mario Srouji, Jian Zhang, Ruslan Salakhutdinov (2018). Structured Control Nets for Deep Reinforcement Learning.
Source code in evotorch/neuroevolution/net/layers.py
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
|
bias
property
¶
Get whether or not the linear component has bias
in_features
property
¶
Get the length of the input vector
num_sinusoids
property
¶
Get the number of sinusoidal waves of the non-linear component
out_features
property
¶
Get the length of the output vector
t
property
¶
The current timestep t
__init__(*, in_features, out_features, bias=True, num_sinusoids=16)
¶
__init__(...)
: Initialize the LocomotorNet.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_features
|
int
|
Length of the input vector |
required |
out_features
|
int
|
Length of the output vector |
required |
bias
|
bool
|
Whether or not the linear component is to have a bias |
True
|
num_sinusoids
|
Number of sinusoidal waves |
16
|
Source code in evotorch/neuroevolution/net/layers.py
forward(x)
¶
Execute a forward pass
Source code in evotorch/neuroevolution/net/layers.py
Round
¶
Bases: Module
A small torch module for rounding the values of an input tensor
Source code in evotorch/neuroevolution/net/layers.py
Slice
¶
Bases: Module
A small torch module for getting the slice of an input tensor
Source code in evotorch/neuroevolution/net/layers.py
__init__(from_index, to_index)
¶
__init__(...)
: Initialize the Slice operator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
from_index
|
int
|
The index from which the slice begins. |
required |
to_index
|
int
|
The exclusive index at which the slice ends. |
required |
Source code in evotorch/neuroevolution/net/layers.py
StructuredControlNet
¶
Bases: Module
Structured Control Net.
This is a control network consisting of two components: (i) a non-linear component, which is a feed-forward network; and (ii) a linear component, which is a linear layer. Both components take the input vector provided to the structured control network. The final output is the sum of the outputs of both components.
Reference
Mario Srouji, Jian Zhang, Ruslan Salakhutdinov (2018). Structured Control Nets for Deep Reinforcement Learning.
Source code in evotorch/neuroevolution/net/layers.py
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 |
|
bias
property
¶
hidden_size
property
¶
in_features
property
¶
nonlinearity
property
¶
num_layers
property
¶
out_features
property
¶
__init__(*, in_features, out_features, num_layers, hidden_size, bias=True, nonlinearity='tanh')
¶
__init__(...)
: Initialize the structured control net.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
in_features
|
int
|
Length of the input vector |
required |
out_features
|
int
|
Length of the output vector |
required |
num_layers
|
int
|
Number of hidden layers for the non-linear component |
required |
hidden_size
|
int
|
Number of neurons in a hidden layer of the non-linear component |
required |
bias
|
bool
|
Whether or not the linear component is to have bias |
True
|
nonlinearity
|
Union[str, Callable]
|
Activation function |
'tanh'
|