Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
2432d7a
PMH: support for calculating PMH from a lognormal dist
michaeldickens Nov 21, 2023
e192e83
PMH: inv_fraction_of_ev has an analytic solution lol
michaeldickens Nov 21, 2023
512f892
implement (inv_)fraction_of_ev for PMH
michaeldickens Nov 21, 2023
1e1ef7e
delete unused expectile functions
michaeldickens Nov 21, 2023
38c9055
PMH: multiplication now works and is faster
michaeldickens Nov 21, 2023
6175066
ScaledBinHistogram basic implementation. It's worse across the board …
michaeldickens Nov 21, 2023
2a70478
refactor to pull shared code into PDHBase
michaeldickens Nov 21, 2023
ccd9a92
~55% performance improvement
michaeldickens Nov 22, 2023
16981e3
another ~30% performance improvement for dist product
michaeldickens Nov 22, 2023
670ae68
test PMH vs. Monte Carlo SD accuracy
michaeldickens Nov 22, 2023
10bb2e7
change default num_bins from 1000 to 100
michaeldickens Nov 22, 2023
b88e0a1
allow PMH to group bins by equal mass. it works but mean is inaccurat…
michaeldickens Nov 22, 2023
66353d5
implement (inv_)contribution_to_ev for normal distributions
michaeldickens Nov 23, 2023
cc00f6c
docs: init Sphinx docs
michaeldickens Nov 23, 2023
397a0e6
docs: generate using sphinx-apidoc
michaeldickens Nov 23, 2023
1446112
docs: write better index page and link to all docs from index
michaeldickens Nov 23, 2023
8c29e78
docs: move from docs to doc and fix docstring formatting
michaeldickens Nov 23, 2023
2224f7a
Merge branch 'sphinx-docs' into numeric-methods
michaeldickens Nov 23, 2023
f73be14
docs: update for numeric-methods
michaeldickens Nov 23, 2023
57ef85b
docs: update Poetry dependencies for Sphinx requirements
michaeldickens Nov 23, 2023
ffd5250
docs: support numpydoc docstring style
michaeldickens Nov 23, 2023
ffd5142
docs: don't track build/
michaeldickens Nov 23, 2023
dd38128
Merge branch 'sphinx-docs' into numeric-methods
michaeldickens Nov 23, 2023
c7a4722
fix tests
michaeldickens Nov 24, 2023
e95dc36
delete ScaledBinHistogram because I broke it and it's worse than PMH
michaeldickens Nov 24, 2023
943e335
PMH normal distributions pass basic tests
michaeldickens Nov 24, 2023
95b1239
PMH: support multiplication for normal distributions
michaeldickens Nov 24, 2023
3dc73d8
PMH: improve test coverage and docs
michaeldickens Nov 24, 2023
c9abbb4
PMH: trying to fix summation but variable-sized bins are a headache
michaeldickens Nov 24, 2023
5706b5f
PMH: Make extended_masses rectangular by adding zeros. This is simple…
michaeldickens Nov 25, 2023
2ce40d8
PMH: cleanup and performance optimizations
michaeldickens Nov 25, 2023
ba12e1b
PMH: Implement uniform bin sizing. it mostly works but some tests fai…
michaeldickens Nov 25, 2023
03d19df
PMH: fixing bugs in __add__ and elsewhere
michaeldickens Nov 26, 2023
4147b2f
PMH: set pos/neg bin sizes based on num extended bins, not EV
michaeldickens Nov 26, 2023
2d4a014
PMH: fix pos/neg binning edge cases
michaeldickens Nov 27, 2023
1742124
rename PMH -> NumericDistribution and delete base class
michaeldickens Nov 27, 2023
9b8e0fa
implement negation (took me 2 minutes lol)
michaeldickens Nov 27, 2023
beb2326
implement subtraction
michaeldickens Nov 27, 2023
cf1c7c3
rename files and improve methodology docstring
michaeldickens Nov 27, 2023
f59414b
put contribution_to_ev on new base class, not BaseDistribution
michaeldickens Nov 27, 2023
806c42c
numeric: implement uniform distributions
michaeldickens Nov 28, 2023
fad03e7
numeric: implement log-uniform bin sizing for lognorm dists
michaeldickens Nov 28, 2023
15951e2
numeric: implement cdf/ppf and reintroduce "mass" bin sizing
michaeldickens Nov 28, 2023
8dc524d
numeric: update docstrings and improve test coverage
michaeldickens Nov 28, 2023
3014c65
numeric: implement lclip/rclip and fix tests
michaeldickens Nov 28, 2023
d02cd60
numeric: implement lclip/rclip exact mean for lognormal
michaeldickens Nov 28, 2023
5c77fea
numeric: implement scaling, reciprocal, and division
michaeldickens Nov 29, 2023
9ddda7a
numeric: make get_percentiles work with NumericDistributions
michaeldickens Nov 29, 2023
4442485
numeric: fix mixtures; implement EV adjustment but it's not good
michaeldickens Nov 30, 2023
83216cd
numeric: fix clipping and remove EV adjustment
michaeldickens Nov 30, 2023
303ac68
numeric: fat-hybrid bin sizing and fix tests
michaeldickens Nov 30, 2023
2cc6134
numeric: improve fat-hybrid
michaeldickens Nov 30, 2023
eab6651
numeric: improve interpolation and bin sizing
michaeldickens Dec 1, 2023
f0fb30f
numeric: shrimp.py is functional but has some logic bugs
michaeldickens Dec 1, 2023
138dff1
numeric: refactor to make _resize_bins do both pos and neg
michaeldickens Dec 1, 2023
10a877d
numeric: fix incorrect behavior in mixture and contribution_to_ev
michaeldickens Dec 1, 2023
780342b
numeric: remove non-monotonic values
michaeldickens Dec 1, 2023
3a66a6b
numeric: cache lognorm CDFs
michaeldickens Dec 1, 2023
eb6dcdf
numeric: cache norm CDFs
michaeldickens Dec 2, 2023
4ab419f
numeric: fix caching and add edges at infinity for uniform+log-uni
michaeldickens Dec 2, 2023
2ed5e0f
numeric: improve bin sizing and start support on bin sizing for resiz…
michaeldickens Dec 2, 2023
4126872
numeric: support ev bin sizing when resizing
michaeldickens Dec 3, 2023
d4b6059
numeric: fix tests
michaeldickens Dec 4, 2023
7f7f592
numeric: improve performance
michaeldickens Dec 4, 2023
5869222
numeric: implement beta distributions
michaeldickens Dec 4, 2023
cf94856
numeric: implement gamma distributions
michaeldickens Dec 5, 2023
21d9f48
numeric: bugfix
michaeldickens Dec 5, 2023
be720fc
numeric: small change
michaeldickens Dec 5, 2023
9a9ba3b
numeric: exp/log/pow. naive method is surprisingly accurate
michaeldickens Dec 5, 2023
580efef
numeric: chi-square and exponential as special cases of gamma
michaeldickens Dec 6, 2023
5663ac7
numeric: pareto dist
michaeldickens Dec 6, 2023
7fd8b4d
numeric: tests for quantile accuracy
michaeldickens Dec 7, 2023
34f1878
numeric: log-uniform bin REsizing. but it's worse than bin-count
michaeldickens Dec 8, 2023
a31c409
numeric: fix warnings
michaeldickens Dec 8, 2023
91331e9
numeric: constant and bernoulli dists
michaeldickens Dec 8, 2023
eb14917
numeric: fix minor bugs and refactor
michaeldickens Dec 9, 2023
d54b305
numeric: improve docs
michaeldickens Dec 9, 2023
89bde93
numeric: PERT distribution
michaeldickens Dec 9, 2023
2a9e988
numeric: given_value_satisfies and probability_value_satisfies
michaeldickens Dec 9, 2023
2e2c1e8
numeric: Richardson extrapolation for mul (WIP)
michaeldickens Dec 13, 2023
b259377
numeric: attempting to make pos and neg bin counts equal
michaeldickens Dec 13, 2023
ca31737
Revert "numeric: attempting to make pos and neg bin counts equal"
michaeldickens Dec 13, 2023
405af63
numeric: interpolating Richardson adjustments but it works badly
michaeldickens Dec 13, 2023
17ed36f
Revert "numeric: interpolating Richardson adjustments but it works ba…
michaeldickens Dec 13, 2023
7bbe5e7
numeric: trying to fix Richardson (WIP)
michaeldickens Dec 15, 2023
00ef56d
numeric: fix Richardson by running on masses and values separately
michaeldickens Dec 16, 2023
5fb3d6b
numeric: Richardson extrapolation for more functions. some edge cases…
michaeldickens Dec 16, 2023
22a3b81
numeric: fix some Richardson edge cases by forcing 2 bins per side an…
michaeldickens Dec 18, 2023
c427fd8
numeric: resize_pos_bins works for ev
michaeldickens Dec 19, 2023
7cd9f7e
numeric: attempt to not split pos/neg bins (it doesn't work)
michaeldickens Dec 19, 2023
75b6236
Revert "numeric: attempt to not split pos/neg bins (it doesn't work)"
michaeldickens Dec 19, 2023
384db1a
numeric: fix Richardson by bailing out on edge cases. all tests pass
michaeldickens Dec 20, 2023
31e8dd8
numeric: Richardson on exp and log. it's sorta better
michaeldickens Dec 30, 2023
e4c7093
numeric: interpolate when clipping instead of chopping whole bins
michaeldickens Jan 1, 2024
7b1f488
numeric: implement uniform inv_contribution_to_ev and fix bug in
michaeldickens Jan 1, 2024
28515ab
numeric: update docs
michaeldickens Jan 1, 2024
18dd819
numeric: fix linter and floating point rounding in normal.CEV
michaeldickens Jan 2, 2024
683e5d1
numeric: turn off MC accuracy tests to avoid rare flakes
michaeldickens Jan 2, 2024
e5e816e
numeric: allow more tolerance on SD for gamma dist
michaeldickens Jan 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/*
dist/*
doc/build/*
*.egg-info
__pycache__
.ruff_cache
Expand Down
24 changes: 24 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

buildapi:
sphinx-apidoc -efM ../squigglepy -o source/reference
@echo "Auto-generation of API documentation finished. " \
"The generated files are in 'api/'"
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%

:end
popd
181 changes: 181 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

project = "Squigglepy"
copyright = "2023, Peter Wildeford"
author = "Peter Wildeford"

# The short X.Y version
version = ""
# The full version, including alpha/beta/rc tags
release = ""


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.imgmath",
"sphinx.ext.viewcode",
"numpydoc",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"

# The master toctree document.
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = "en"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "pydata_sphinx_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = "Squigglepydoc"


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, "Squigglepy.tex", "Squigglepy Documentation", "Peter Wildeford", "manual"),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [(master_doc, "squigglepy", "Squigglepy Documentation", [author], 1)]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(
master_doc,
"Squigglepy",
"Squigglepy Documentation",
author,
"Squigglepy",
"One line description of project.",
"Miscellaneous",
),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]


# -- Extension configuration -------------------------------------------------

numpydoc_class_members_toctree = False
52 changes: 52 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
Squigglepy: Implementation of Squiggle in Python
================================================

`Squiggle <https://www.squiggle-language.com/>`__ is a "simple
programming language for intuitive probabilistic estimation". It serves
as its own standalone programming language with its own syntax, but it
is implemented in JavaScript. I like the features of Squiggle and intend
to use it frequently, but I also sometimes want to use similar
functionalities in Python, especially alongside other Python statistical
programming packages like Numpy, Pandas, and Matplotlib. The
**squigglepy** package here implements many Squiggle-like
functionalities in Python.

.. toctree::
:maxdepth: 2
:caption: Contents

Installation <installation>
Usage <usage>
Numeric Distributions <numeric_distributions>
API Reference <reference/modules>

Disclaimers
-----------

This package is unofficial and supported by Peter Wildeford and Rethink
Priorities. It is not affiliated with or associated with the Quantified
Uncertainty Research Institute, which maintains the Squiggle language
(in JavaScript).

This package is also new and not yet in a stable production version, so
you may encounter bugs and other errors. Please report those so they can
be fixed. It’s also possible that future versions of the package may
introduce breaking changes.

This package is available under an MIT License.

Acknowledgements
----------------

- The primary author of this package is Peter Wildeford. Agustín
Covarrubias and Bernardo Baron contributed several key features and
developments.
- Thanks to Ozzie Gooen and the Quantified Uncertainty Research
Institute for creating and maintaining the original Squiggle
language.
- Thanks to Dawn Drescher for helping me implement math between
distributions.
- Thanks to Dawn Drescher for coming up with the idea to use ``~`` as a
shorthand for ``sample``, as well as helping me implement it.

.. autosummary::
12 changes: 12 additions & 0 deletions doc/source/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Installation
============

.. code:: shell

pip install squigglepy

For plotting support, you can also use the ``plots`` extra:

.. code:: shell

pip install squigglepy[plots]
Loading