nn
Table of contents
“nn” app contains implementation of neural network layers. Depends on nn-utils for helper functions. At the time of writing, scarpet 1.6 does not have proper support for exception raising and exception handling. Therefore, any error or invalid operation will cause the program to exit abruptly.
Functions
conv
Arguments
i_pos1
- Starting position of input tensori_pos2
- Ending position of input tensorw_pos1
- Starting position of weight tensorw_pos2
- Ending position of weight tensora_pos1
- Starting position of output activation tensora_pos2
- Ending position of output activation tensorkernel_size
- Kernel size of convolution filter (supports only square filters for now)stride
- Stride for convolution operationgame_tick_time
- Time (in ms) to delay between 2 consecutive block placements. Pass0
for instant answer. Passing any non zero value allows better visualizations.
Behavior
This function operates similar to torch.nn.Conv2d()
layer by applying 2D convolution over input signal composed of several input channels.
The calculation of input channels, number of convolution filters and output channels is decided by block position arguments (i_pos1
, i_pos2
for input and so on). Any invalid operation will cause the program to exit with proper error message indicating cause of error.
The function will read tensor block by block from bounding box specified by (i_pos1
, i_pos2
), apply convolution operation based on filters stored at bounding box specified by (w_pos1
, w_pos2
) and put the output tensor block by block at bounding box specified by (a_pos1
, a_pos2
).
The function will always consider *_pos1
as the starting point and *_pos2
as ending point of the bounding box and calculate proper directions required for looping.
fc
Arguments
i_pos1
- Starting position of input tensori_pos2
- Ending position of input tensorw_pos1
- Starting position of weight tensorw_pos2
- Ending position of weight tensora_pos1
- Starting position of output activation tensora_pos2
- Ending position of output activation tensorgame_tick_time
- Time (in ms) to delay between 2 consecutive block placements. Pass0
for instant answer. Passing any non zero value allows better visualizations.
Behavior
This function behaves similar to torch.nn.Linear()
layer.
The calculation of dimensions of output tensor will be done by the function and the function will exit with proper error message in case of invalid operation.
Internally, it’s a simple matrix multiplication. The function will read tensor block by block from bounding box specified by (i_pos1
, i_pos2
), multiply it with weight matrix stored at bounding box specified by (w_pos1
, w_pos2
) and put the output tensor block by block at bounding box specified by (a_pos1
, a_pos2
).
move
Arguments
i_pos1
- Starting position of input tensori_pos2
- Ending position of input tensoro_pos1
- Starting position of output tensoro_pos2
- Ending position of output tensorgame_tick_time
- Time (in ms) to delay between 2 consecutive block placements. Pass0
for instant answer. Passing any non zero value allows better visualizations.
Behavior
This function behaves similar to torch.Tensor.view()
operation.
The function will move the blocks from the volume specified by (i_pos1
and i_pos2
) to the volume specified by (o_pos1
, o_pos2
). The data values will not change.
Any error will be notified by the function before exiting due to some invalid operation.