floor
result = floor(x)
Input: x · Output: result
What it is
Standard rounding functions, elementwise: floor toward negative infinity, ceil toward positive infinity, round to the nearest integer (half away from zero). x is a scalar, Vec, or Mat/Signal.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = floor(x) | x scalar, Vec, Mat, or Signalnot documented yet | result — | Returns exactly the same type and shape as x, rounded elementwise. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
n_per_class = 60
c0x = normal(0, 0.6, n_per_class, seed=1)
c0y = normal(0, 0.6, n_per_class, seed=2)
c1x = normal(4, 0.6, n_per_class, seed=3)
c1y = normal(4, 0.6, n_per_class, seed=4)
Xc0 = hstack(reshape(c0x, n_per_class, 1), reshape(c0y, n_per_class, 1))
Xc1 = hstack(reshape(c1x, n_per_class, 1), reshape(c1y, n_per_class, 1))
Xc = vstack(Xc0, Xc1) # (120, 2)
n = 2 * n_per_class
idx = 0 to n - 1
y = floor(idx / n_per_class) # 0 for the first 60 rows, 1 for the last 60
function one_hot(labels, rows, k)
m = zeros(rows, k)
for i = 0 to rows - 1
m[i, labels[i]] = 1
end for
return m
end function
Y = one_hot(y, n, 2)
net = mlp_classifier(2, [8], 2, seed=42)
trained = net.fit(Xc, Y, epochs=200, lr=0.1, loss="cross_entropy")
function accuracy(model, X, Ytrue, rows)
logits = model.predict(X)
correct = 0
for i = 0 to rows - 1
if argmax(logits[i, :]) == argmax(Ytrue[i, :]) then
correct = correct + 1
end if
end for
return correct / rows
end function
acc = accuracy(trained, Xc, Y, n)
print("training accuracy = {acc:.4f}")
output
training accuracy = 1.0000
from quickstart