Learned networks
Why a brain might ship a .oann, integer arithmetic, the layers, running one, oa-tool brain net, the limits, and what the Library shows.
This chapter summarises docs/brains/oabrain-standard.md, docs/brains/authoring.md and docs/playing-with-brains.md. Those docs are the normative text.
Why a brain might use one
A network is trained elsewhere and shipped in the package. The script calls it when it wants a learned decision. It is an author's choice. The engine's own computer player stays the default, and seating a brain that carries weights is still opt-in, one computer seat on the machine that runs it.
.oann and integer arithmetic
A network file is a format-1 .oann. A tensor type is int8, int16 or int32. A stored exponent is -48 to 16. Inputs and activations are int16. Outputs are int16, except an argmax output, which is int32. The same inputs give the same outputs on every machine.
The digest is checked when the package is packed, when it is installed, and again when a seat loads the brain, before the sandbox opens. A network that would take the seat past 64 MiB is refused before it is allocated. The seat is removed and the built-in computer player keeps it. The load is outside every phase.
The layers
The layer kinds, in this order. Inputs and activations are int16.
| Layer | What it does |
|---|---|
dense | The output is int16. |
conv2d | The output is int16. |
maxpool | The output is int16. |
relu | The output is int16. |
leaky_relu | The output is int16. |
tanh | The output is int16. |
sigmoid | The output is int16. |
add | The output is int16. |
concat | The output is int16. |
flatten | The output is int16. |
softmax | The output is int16. |
argmax | The output is int32. |
embedding | The output is int16. |
Running one
brain.network(id) returns the handle. brain.tensor builds an immutable tensor from 1 to 4,194,304 numbers. net:run takes a table with exactly the network's input names and returns a new table. An int16 output is a tensor. An argmax output is a Lua integer. brain.grid builds a square tensor from 1 to 10 of these layer names, at size 8, 16, 32, 64 or 128, and 64 is the default: sight, explored, water, height, metal, own, allies, enemies, threat and radar. The standard's example records one sample:
brain.record{
features = { sectors = brain.grid({"own", "explored"}, 8) },
decision = 0
}
features is 1 to 16 tensors. decision is an integer or a tensor. The call writes a training sample when the match is recording, and it checks and charges the same when no file is open. An option can leave a network unused: read me.options and skip the call when the player switches it off. The network is still loaded with the package.
Making one with oa-tool brain net
oa-tool brain net reads an ONNX model of opset 11 to 21 and writes a .oann. This is the command the guide prints:
oa-tool brain net MODEL.onnx --calibrate DATA [--out FILE] [--weights int8|int16] [--max-difference X] [--force] [--json]
Weights are int8 unless --weights int16 is set. --calibrate is a file of JSON lines. The report is the largest difference on each output, or the share of samples an argmax agrees on. --max-difference refuses a larger difference and writes nothing. List the file under networks with its sha256. The bytes have to hash to that digest.
The limits
A file, a run and a record stay inside these sizes.
| Limit | Value |
|---|---|
| The .oann file | at most 64 MiB |
| Tensors in one file | 2 to 4,096 |
| Layers in one file | 1 to 1,024 |
| A tensor's rank, and one dimension | rank 1 to 4; a dimension 1 to 65,535 |
| Elements in one file tensor | at most 16,777,216 |
| dense, conv2d and embedding weights together | at most 8,388,608 elements |
| Operations one run may perform | at most 268,435,456 |
| Network memory, separate from the Lua cap | 64 MiB (67,108,864 bytes) |
| Numbers in one brain.tensor | 1 to 4,194,304 |
| brain.grid | 1 to 10 layer names; size 8, 16, 32, 64 or 128. 64 is the default |
| One brain.record, and the record file | 1 to 16 tensors, at most 4,194,304 elements. The file stops at 1 GiB |
What a player sees
The Library labels a brain that carries weights with Network and the line Uses a learned network ({size}). The entry also shows the brain's levels, what it works with, and whether it has full awareness. The built-in computer player stays listed first, and it stays the default until a player chooses another.