markovPredictGPU function
Predicts the probability distribution of the next states for a batch of histories.
Maps each sequence in the historyBatch to its corresponding row in the provided probTable
and outputs a matrix of shape [batchSize, numStates] containing the next-state probabilities.
The operations are appended to tape for execution.
Implementation
GPUTensor<Matrix> markovPredictGPU(
GPUTensor<Matrix> historyBatch, // Shape: [batch_size, order]
GPUTensor<Matrix> probTable, // Shape: [num_histories, num_states]
int numStates,
CommandBuffer tape,
{GPUTensor<Matrix>? outTensor}) {
int batchSize = historyBatch.shape[0];
int order = historyBatch.shape[1];
GPUTensor<Matrix> outProbs =
outTensor ?? GPUTensor<Matrix>.empty(<int>[batchSize, numStates]);
tape.putInt(OP_MARKOV_PREDICT);
tape.putString(historyBatch.id);
tape.putString(probTable.id);
tape.putString(outProbs.id);
tape.putInt(order);
tape.putInt(numStates);
outProbs.creator = GPUNode(<GPUTensor>[historyBatch, probTable],
(CommandBuffer bTape) {}, // Empty backward pass
opName: 'markovPredictGPU');
return outProbs;
}