simple_cnn
Builtin index · Statistics & ML
result = simple_cnn([height, width], n_classes, [seed=])
Input: height, width, n_classes, seed · Output: result
What it is
Builds an untrained conv → relu → maxpool → dense image classifier: [height, width] a 2-element vector giving the image size, n_classes a positive integer, and an optional integer seed=.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = simple_cnn([height, width], n_classes, [seed=]) | height, width vector, optionalnot documented yetn_classes vectornot documented yetseed vector, optionalnot documented yet | result Model, vector, or number | Returns a kind="simple_cnn" Model with .fit(images, labels, [epochs=], [lr=]), where images is a tuple of height x width matrices (one per sample) and labels a length-M integer vector, epochs an integer and lr a number (learning rate); .fit returns the trained Model, and .predict(images) on it returns a length-M vector of predicted classes. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
net = simple_cnn([6, 6], 2, seed = 3)
img1 = zeros(6, 6)
img1[2, 2] = 1.0
img1[2, 3] = 1.0
img1[3, 2] = 1.0
img1[3, 3] = 1.0
img2 = zeros(6, 6)
img2[1, 2] = 1.0
img2[2, 1] = 1.0
img2[2, 3] = 1.0
img2[3, 2] = 1.0
net = net.fit((img1, img2), [0, 1], epochs = 5, lr = 0.1)
print("simple_cnn predict rows: {rows(net.predict((img1, img2)))}")
rnn = simple_rnn_classifier(1, 6, 2, seed = 5)
seq1 = [0.1, 0.3, 0.5, 0.7, 0.9] as matrix(1, 5)
seq2 = [0.9, 0.7, 0.5, 0.3, 0.1] as matrix(1, 5)
rnn = rnn.fit((seq1, seq2), [0, 1], epochs = 5, lr = 0.1)
print("simple_rnn_classifier predict rows: {rows(rnn.predict((seq1, seq2)))}")
simple_cnn predict rows: 2 simple_rnn_classifier predict rows: 2
from statistics-ml
How it works
simple_cnn(input_shape, n_classes, [seed=]) — input_shape is [height, width] (single-channel images only, matching conv2d's own scope). Architecture: one conv2d (fixed 3x3 kernel, "valid" padding) -> relu -> maxpool2d (2x2, non-overlapping) -> a fully-connected softmax-ready readout — per-class sum(pooled .* w_c) + b_c, the exact "dense layer without a stack primitive" trick the CNN acceptance test's own doc comment works out, generalized from that test's binary case to n_classes independent weight maps. Deliberately tiny (this is a from-scratch interpreter, not meant to rival a real deep CNN) — see simple_cnn_init's own doc comment for the exact shape math and its error cases.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.