-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Prophet algorithm in
augurs-prophet
crate (#118)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
- Loading branch information
1 parent
253f6d9
commit d9f79a7
Showing
27 changed files
with
5,438 additions
and
3 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/target | ||
/Cargo.lock | ||
.bacon-locations | ||
.vscode |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# This is a configuration file for the bacon tool | ||
# | ||
# Bacon repository: https://github.com/Canop/bacon | ||
# Complete help on configuration: https://dystroy.org/bacon/config/ | ||
# You can also check bacon's own bacon.toml file | ||
# as an example: https://github.com/Canop/bacon/blob/main/bacon.toml | ||
|
||
default_job = "clippy" | ||
summary = true | ||
|
||
[jobs.check] | ||
command = ["cargo", "check", "--color", "always"] | ||
need_stdout = false | ||
|
||
[jobs.check-all] | ||
command = ["cargo", "check", "--all-targets", "--color", "always"] | ||
need_stdout = false | ||
|
||
# Run clippy on the default target | ||
[jobs.clippy] | ||
command = [ | ||
"cargo", "clippy", | ||
"--color", "always", | ||
] | ||
need_stdout = false | ||
|
||
# Run clippy on all targets | ||
# To disable some lints, you may change the job this way: | ||
# [jobs.clippy-all] | ||
# command = [ | ||
# "cargo", "clippy", | ||
# "--all-targets", | ||
# "--color", "always", | ||
# "--", | ||
# "-A", "clippy::bool_to_int_with_if", | ||
# "-A", "clippy::collapsible_if", | ||
# "-A", "clippy::derive_partial_eq_without_eq", | ||
# ] | ||
# need_stdout = false | ||
[jobs.clippy-all] | ||
command = [ | ||
"cargo", "clippy", | ||
"--all-targets", | ||
"--color", "always", | ||
] | ||
need_stdout = false | ||
|
||
# This job lets you run | ||
# - all tests: bacon test | ||
# - a specific test: bacon test -- config::test_default_files | ||
# - the tests of a package: bacon test -- -- -p config | ||
[jobs.test] | ||
command = [ | ||
"cargo", "nextest", "--color", "always", | ||
"run", "--all-features", "--workspace", | ||
] | ||
need_stdout = true | ||
analyzer = "nextest" | ||
|
||
[jobs.doc-test] | ||
command = [ | ||
"cargo", "test", "--doc", "--color", "always", | ||
"--all-features", "--workspace", | ||
"--exclude", "augurs-js", | ||
"--exclude", "pyaugurs", | ||
] | ||
need_stdout = true | ||
|
||
[jobs.doc] | ||
command = ["cargo", "doc", "--color", "always", "--no-deps"] | ||
need_stdout = false | ||
|
||
# If the doc compiles, then it opens in your browser and bacon switches | ||
# to the previous job | ||
[jobs.doc-open] | ||
command = ["cargo", "doc", "--color", "always", "--no-deps", "--open"] | ||
need_stdout = false | ||
on_success = "back" # so that we don't open the browser at each change | ||
|
||
# You can run your application and have the result displayed in bacon, | ||
# *if* it makes sense for this crate. | ||
# Don't forget the `--color always` part or the errors won't be | ||
# properly parsed. | ||
# If your program never stops (eg a server), you may set `background` | ||
# to false to have the cargo run output immediately displayed instead | ||
# of waiting for program's end. | ||
[jobs.run] | ||
command = [ | ||
"cargo", "run", | ||
"--color", "always", | ||
# put launch parameters for your program behind a `--` separator | ||
] | ||
need_stdout = true | ||
allow_warnings = true | ||
background = true | ||
|
||
# This parameterized job runs the example of your choice, as soon | ||
# as the code compiles. | ||
# Call it as | ||
# bacon ex -- my-example | ||
[jobs.ex] | ||
command = ["cargo", "run", "--color", "always", "--example"] | ||
need_stdout = true | ||
allow_warnings = true | ||
|
||
# You may define here keybindings that would be specific to | ||
# a project, for example a shortcut to launch a specific job. | ||
# Shortcuts to internal functions (scrolling, toggling, etc.) | ||
# should go in your personal global prefs.toml file instead. | ||
[keybindings] | ||
# alt-m = "job:my-job" | ||
c = "job:clippy-all" # comment this to have 'c' run clippy on only the default target | ||
d = "job:doc-test" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[package] | ||
name = "augurs-prophet" | ||
license.workspace = true | ||
authors.workspace = true | ||
documentation.workspace = true | ||
repository.workspace = true | ||
version.workspace = true | ||
edition.workspace = true | ||
keywords.workspace = true | ||
|
||
[dependencies] | ||
anyhow.workspace = true | ||
bytemuck = { workspace = true, features = ["derive"], optional = true } | ||
itertools.workspace = true | ||
num-traits.workspace = true | ||
rand.workspace = true | ||
statrs.workspace = true | ||
thiserror.workspace = true | ||
|
||
[dev-dependencies] | ||
augurs-testing.workspace = true | ||
chrono.workspace = true | ||
pretty_assertions.workspace = true | ||
|
||
[features] | ||
bytemuck = ["dep:bytemuck"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE-APACHE |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../LICENSE-MIT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Prophet: forecasting at scale | ||
|
||
`augurs-prophet` contains an implementation of the [Prophet] | ||
time series forecasting library. | ||
|
||
This crate aims to be low-dependency to enable it to run in as | ||
many places as possible. With that said, we need to talk about | ||
optimizers… | ||
|
||
## Optimizers | ||
|
||
The original Prophet library uses [Stan] to handle optimization and MCMC sampling. | ||
Stan is a platform for statistical modeling which can perform Bayesian statistical | ||
inference as well as maximum likelihood estimation using optimizers such as L-BFGS. | ||
However, it is written in C++ and has non-trivial dependencies, which makes it | ||
difficult to interface with from Rust (or, indeed, Python). | ||
|
||
`augurs-prophet` (similar to the Python library) abstracts optimization | ||
and sampling implementations using the `Optimizer` and `Sampler` traits. | ||
These are yet to be implemented, but I have a few ideas: | ||
|
||
### `cmdstan` | ||
|
||
This is the approach now taken by the Python implementation, which uses | ||
the `cmdstanpy` package and compiles the Stan program into a standalone | ||
binary on installation. It then executes that binary during the fitting | ||
stage to perform optimization or sampling, passing the data and | ||
parameters between Stan and Python using files on the filesystem. | ||
|
||
This works fine if you're operating in a desktop or server environment, | ||
but poses issues when running in more esoteric environments such as | ||
WebAssembly. | ||
|
||
### `libstan` | ||
|
||
We could choose to write a `libstan` crate which uses [`cxx`][cxx] to | ||
interface directly with the C++ library generated by Stan. Since the | ||
model code is constant (unless we upgrade the version of `stanc` used to | ||
generate it), we could also write a small amount of C++ to make it | ||
possible for us to pass data directly to it from Rust. | ||
|
||
In theory this should work OK for any target which Stan can compile to. | ||
The problem I've noticed is that Stan isn't particularly careful about | ||
which headers it imports, so even just compiling the `model.hpp` library, | ||
you end up with a bunch of I/O and filesystem related headers imported, | ||
which aren't available when using standard WASM. | ||
|
||
Perhaps we could clean Stan up so it didn't import those things? We should | ||
be able to target most environments in that case. | ||
|
||
### WASM Components | ||
|
||
For WASM, we could abstract the C++ side of things behind a | ||
[WASM component] which exposes an `optimize` interface, | ||
and create a second Prophet component which imports that | ||
interface to implement the `Optimizer` trait of this crate. | ||
|
||
### A reimplementation of Stan | ||
|
||
We could re-implement Stan in a new Rust crate and use that | ||
here. This is likely to be by far the largest amount of work! | ||
|
||
## Credits | ||
|
||
This implementation is based heavily on the original [Prophet] Python | ||
package. Some changes have been made to make the APIs more idiomatic | ||
Rust or to take advantage of the type system. | ||
|
||
[Prophet]: https://facebook.github.io/prophet/ | ||
[Stan]: https://mc-stan.org/ | ||
[cxx]: https://cxx.rs/ | ||
[WASM component]: https://component-model.bytecodealliance.org/ |
Oops, something went wrong.