Learn R Programming

ggmlR (version 0.8.4)

pt_forward: Run a piece transformer

Description

Reads a state, or a batch of them, and returns a value per action.

Usage

pt_forward(model, state)

Value

For one state, a numeric vector of n_actions values, one per move. For a batch, a matrix with one row per state and one column per action.

Arguments

model

A pt_transformer, normally from pt_transformer_load.

state

Colours in 0..num_classes-1: an integer vector of state_size for one state, or a matrix with state_size columns --- one state per row --- for a batch. A solved 4x4x4 is rep(0:5, each = 16).

One state or many

A batch is not a convenience here, it is the way to get the work done quickly. Every layer but the attention treats a row on its own, so a batch of states is the same arithmetic on taller matrices --- and a tall matmul is what BLAS is good at, where a short one spends its time in the call rather than the multiply. Scoring the ten states of a beam in one call is several times faster than scoring them one after another.

See Also

pt_transformer_load

Examples

Run this code
if (FALSE) {
model <- pt_transformer_load("model.pth")
solved <- rep(0:5, each = 16)

pt_forward(model, solved)                       # 24 values
pt_forward(model, rbind(solved, solved))        # 2 x 24
}

Run the code above in your browser using DataLab