-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate or include graphs for distributions in docs #131
Comments
I think this is a great idea and am currently looking into possible solutions. |
First, I tried searching for some graphs available online. Quickly I realised a few problems.
I think the graphs should be
Therefore I decided to try writing a script myself using Python. Matplotlib has great graphing support and Scipy has a wide range of probability density functions out of the box. This was generated from the following code: import numpy as np
from scipy.stats import chi2
from graphbutler import recipe, save_all, Graph, Parameterized
@recipe
def chi_squared_pdf():
g = Graph()
g.title = "Chi-squared probability density"
g.x = np.arange(0.0, 9.0, 0.01)
def y(k):
y = chi2.pdf(g.x, k)
# Value threshold because k=1 is unbounded
y[y > 0.5] = np.nan
return y
g.y = Parameterized("k", y, (1, 2, 3, 5, 9))
return g
if __name__ == "__main__":
save_all(format="png") Graphbutler is a simple wrapper around matplotlib I wrote to reduce boilerplate code. I could write a recipe for each of the distributions in this crate. It should then be easy to tweak and extend with potential new distributions. It's currently hard to include local images in rustdoc (issue). Therefore, I suggest the rendered graphs are hosted on the internet instead of in the crate itself. What do you think? |
Then there are cumulative distribution functions. Are those interesting as well? Personally, I find them harder to grasp. |
@steveklabnik: this sounds like a docs-related thing. Do you have a good approach to getting these kinds of generated graphs in our docs? |
@dhardy Do you have any opinions regarding the best place to put these graphs? From reading into the conversation above these options are immediately apparent to me:
Do you know of any best practices here, or of any other crates that have done something like this which we could take inspiration from? Also, any opinions about storing the (presumably Python) code which generates these diagrams, perhaps for future use or reproducibility? |
In my opinion, documentation should be stored within the repository, and these are documentation. The exception is things like tutorials and books which are more prose. So, I can see a few possible options:
If we go for API docs, we should add a sub-dir in the repo like |
Also horrible for diffs any time a plot is edited. No thanks! |
If it's a tiny amount of code, then in the same repository (we probably also want to store the output rather than require the build job regenerate them, although minimalism says otherwise). If it's a lot of code, we can use a new repository under https://github.com/rust-random/ |
I'm working on a PR right now. I wrote some Python code with numpy, scipy, and matplotlib to generate diagrams for different distributions (roughly 20 lines of code per distribution so far) and now I'm trying to use the embed-doc-image crate to inject these images as Base64 into the documentation during compilation. This last step is proving somewhat tricky, it seems the macro doesn't expand to include a div like it should. Still investigating, might have to open a PR in that crate first |
I would suggest simply linking the images instead of embedding. The catch is that building docs will then require copying these into |
So, do you mean something like this rust-lang/rust#32104 (comment)? I think it would be really nice if the diagrams would be viewable on docs.rs as well, and if I understand correctly then that would not be possible without embedding. But to be honest I'm open to just putting the images into a directory, referencing them in the docs, and calling it a day. This certainly isn't the most streamlined thing to do with rustdoc. |
You're right; it's not quite so simple for docs.rs. We could possibly get around this by copying image resources into The issue you linked discusses some other options. |
Those of us who aren't as well versed in probability theory (and that includes me), may not be able to immediately intuit the main properties of the distribution functions from their density functions.
I'm talking about something like this graph that Wikipedia has for the normal/gamma distribution article, either linked or inlined in the docs for the various relevant types in the
distributions
module.These graphs are probably available online under compatible licenses already, possibly in the whitepapers linked under the various types in this module. I haven't looked yet, but I don't think we can extract these graphs anyways as they are probably unlicensed or their copyright terms are not compatible with MIT/Apache-2.0.
The text was updated successfully, but these errors were encountered: