Created
January 29, 2024 22:10
-
-
Save tynanbe/61fb7bc67506af4abad05fdd8659f787 to your computer and use it in GitHub Desktop.
Slide-friendly Argamak example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gleam/io | |
import gleam/list | |
import argamak/axis.{Axis, Infer} | |
import argamak/space | |
import argamak/tensor | |
const horses = ["Pony Express", "Hay Girl", "Low Rider"] | |
const day1 = [1.2, 1.3, 1.3, 1.0, 1.5, 0.9] | |
const day2 = [1.1, 1.0, 1.3] | |
pub fn main() -> String { | |
let assert Ok(s) = space.d2(Axis("Horse", 3), Infer("Lap")) | |
let assert Ok(day1) = tensor.from_floats(day1, into: s) | |
let assert Ok(day2) = tensor.from_floats(day2, into: s) | |
let lapwise = fn(a) { axis.name(a) == "Lap" } | |
let assert Ok(data) = tensor.concat([day1, day2], lapwise) | |
let means = tensor.mean(data, lapwise) | |
let all_axes = fn(_) { True } | |
let time = | |
tensor.min_over(means, all_axes) | |
|> tensor.to_string(tensor.Data, wrap_at: 0) | |
let assert Ok(index) = | |
tensor.arg_min(means, all_axes) | |
|> tensor.to_int | |
let assert Ok(horse) = list.at(in: horses, get: index) | |
io.debug(horse <> " won at ~" <> time <> " mins/lap") | |
} | |
// gleam run -t erl -m race | |
// "Hay Girl won at ~1.1 mins/lap" | |
// | |
// gleam run -t js -m race | |
// "Hay Girl won at ~1.1 mins/lap" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment