Server and client code to have a multiplayer simulation of coin flipping. Demonstrates three algorithms: Thompson sampling, Upper Confidence Bound, and Naive Bayes. Problem is also called Multi-Armed Bandits. Notable crates: serde, actix, and mogwai.
Basic Actix server that manages coin flipping for clients. Takes three proportions corresponding to the probablity of head for each of three coins. Each time a coin is flipped by a client (via an HTTP GET request), the server sends a message to an Actix actor to run all three algorithms (Thompson sampling, Naive Bayes, and Upper Confidence Bound) and update their individual states. A POST request to /flush
causes the actor to dump its state, including the algorithm choices and the player choices, into dump.cbor
.
File | Description |
---|---|
app.rs | Logic for the actor. Includes messages, message handling, and algorithm update logic. |
cli.rs | Basic Clap struct for parsing the command line arguments |
handlers.rs | Handlers for HTTP requests (static files, flushing, sending messages to actor) |
main.rs | What do you think? It's main. |
dump.cbor | The output after flushing. Binary JSON file. |
cd server;
cargo run 0.3 0.2 0.9;
# open 0.0.0.0:8080
Login page using Mogwai's frontend framework. Styled and designed with Bootstrap Studio. Submits username for a cookie to be set then redirects to the Game page.
File | Description |
---|---|
lib.rs | The main file. Builds a component and runs it, with channels for changing username and submitting username. |
styles.css | Custom styling |
index.html | File that imports and runs the javascript shim for WebAssembly |
cd login;
wasm-pack build --target=web;
Game page also using Mogwai.
File | Description |
---|---|
lib.rs | Just like login page, main file. |
coin.rs | Declares a coin component and its messages. Used in lib.rs. |
styles.css | Custom styling again |
index.html | HTML document, imports javascript and runs the WebAssembly. |
cd game;
wasm-pack build --target=web;
A page also running with Mogwai that accepts a .cbor
file (generated from the Text CLI) and graphs it in an SVG. Demonstrates the evolution of the algorithms and shows the time-varying preferences of the top player and algorithms.
File | Description |
---|---|
lib.rs | Just like login page and game page, main file. |
styles.css | Custom styling again |
index.html | HTML file runs the WebAssembly compiled from Rust. |
cd view;
wasm-pack build --target=web;
CLI to generate images from dump.cbor
. Generates as many images as there are choices in the images directory.
File | Description |
---|---|
main.rs | Main file, runs functions from utils.rs |
utils.rs | Utils.rs, determines how algorithms would sample |
images | Output directory |
cd cli;
cargo run;
CLI to generate a rendered_dump.cbor
to be loaded and viewed via the view page. Limits the number of iterations to 100 or the number of iterations given. The resolution of the output path is, by default, 80 points per beta distribution. The output is placed in rendered_dump.cbor
.
File | Description |
---|---|
main.rs | Main file, runs functions from utils.rs. Reads the server dump and generates its own. Takes the maximum iterations on cli. |
utils.rs | Contains the default 80 points per beta distribution as a const . Determines how the algorithm would view the state. |
cd text_cli;
cargo run 500;